Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Spectre.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 #ifndef SPECTRE_H
17 #define SPECTRE_H
18 
19 #include <vector>
20 
24 class Spectre
25 {
26 
27 public:
30  {
31  freqs = std::vector<std::pair<int, decimal>>();
32  }
34  Spectre(const Spectre& other)
35  {
36  for (unsigned int i = 0; i < other.freqs.size(); i++)
37  {
38  freqs.push_back(freqs.at(i));
39  }
40  }
42  virtual ~Spectre() {}
43 
45  size_t getSizeSpectre()
46  {
47  return freqs.size();
48  }
49 
51  void getFrequencies(std::vector<int>& r)
52  {
53  for (unsigned int i = 0; i < freqs.size(); i++)
54  {
55  r.push_back(freqs.at(i).first);
56  }
57  }
59  void getFrequencies(int* r)
60  {
61  for (unsigned int i = 0; i < freqs.size(); i++)
62  {
63  r[i] = freqs.at(i).first;
64  }
65  }
67  int getFrequencie(unsigned int i)
68  {
69  if (i < 0 || i >= freqs.size())
70  {
71  return -1;
72  }
73  return freqs.at(i).first;
74  }
76  void getPowers(std::vector<decimal>& r)
77  {
78  for (unsigned int i = 0; i < freqs.size(); i++)
79  {
80  r.push_back(freqs.at(i).second);
81  }
82  }
84  void getPowers(decimal* r)
85  {
86  for (unsigned int i = 0; i < freqs.size(); i++)
87  {
88  r[i] = freqs.at(i).second;
89  }
90  }
92  decimal getPower(unsigned int i)
93  {
94  if (i < 0 || i >= freqs.size())
95  {
96  return -200.;
97  }
98  return freqs.at(i).second;
99  }
101  void addFrequencie(int freq, decimal power)
102  {
103  freqs.push_back(std::pair<int, decimal>(freq, power));
104  }
105 
106 protected:
107  std::vector<std::pair<int, decimal>> freqs;
108 };
109 
110 #endif
Spectrum class.
Definition: Spectre.h:25
void getPowers(decimal *r)
Return into an array (sized before) all the power values of the spectrum.
Definition: Spectre.h:84
Spectre()
Default constructor.
Definition: Spectre.h:29
std::vector< std::pair< int, decimal > > freqs
Vector of pairs (Frequency,Power)
Definition: Spectre.h:107
virtual ~Spectre()
Destructor.
Definition: Spectre.h:42
void addFrequencie(int freq, decimal power)
Add a new pair (frequency,power)
Definition: Spectre.h:101
int getFrequencie(unsigned int i)
Get a the ith frequency of the spectrum.
Definition: Spectre.h:67
void getPowers(std::vector< decimal > &r)
Return into a vector all the power values of the spectrum.
Definition: Spectre.h:76
void getFrequencies(int *r)
Return into an array (sized before) all the frequency values of the spectrum.
Definition: Spectre.h:59
Spectre(const Spectre &other)
Copy constructor.
Definition: Spectre.h:34
size_t getSizeSpectre()
Get the size of the vector storing the spectrum.
Definition: Spectre.h:45
void getFrequencies(std::vector< int > &r)
Return into a vector all the frequency values of the spectrum.
Definition: Spectre.h:51
decimal getPower(unsigned int i)
Get the power for a frequency given by its index.
Definition: Spectre.h:92
float decimal
Definition: mathlib.h:45