JEMRIS  2.8.1
open-source MRI simulations
Signal.h
Go to the documentation of this file.
1 
5 /*
6  * JEMRIS Copyright (C)
7  * 2006-2015 Tony Stoecker
8  * 2007-2015 Kaveh Vahedipour
9  * 2009-2015 Daniel Pflugfelder
10  *
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  */
26 
27 #ifndef SIGNAL_H_
28 #define SIGNAL_H_
29 
30 #include "rng.h"
31 
32 #include <string>
33 #include <assert.h>
34 using namespace std;
35 
36 
40 struct Repository {
41 
43  int m_noofcompartments;
44  std::vector<double> m_times;
45  std::vector<double> m_data;
52 
53  m_noofcompartments = 1;
54  m_noofsamples = 0;
55 
56  };
57 
58 
63  }
64 
65 
71  long Size() {
72 
73  return m_noofsamples * (long) NProps();
74 
75  };
76 
77 
83  double* Data () {
84 
85  return &m_data[0];
86 
87  };
88 
89 
95  double* Times () {
96 
97  return &m_times[0];
98 
99  };
100 
101 
107  inline const long Samples () const {
108 
109  return m_noofsamples;
110 
111  };
112 
113 
119  inline const int Compartments () const {
120 
121  return m_noofcompartments;
122 
123  };
124 
125 
131  inline const int NProps () const {
132 
133  return 3 * m_noofcompartments;
134 
135  };
136 
137 
143  inline const double TP (long l) const {
144 
145  return m_times[l];
146 
147  };
148 
149 
155  inline double& TP (long l) {
156 
157  return m_times[l];
158 
159  };
160 
161 
165  inline const long Position (long l) const {
166 
167  return l*NProps();
168 
169  };
170 
171 
175  inline const void Initialize (long samples, int compartments) {
176 
177  assert (samples);
178  assert (compartments);
179 
180  m_noofcompartments = compartments;
181  m_noofsamples = samples;
182 
183  m_data.resize(Size());
184  m_times.resize(Samples());
185 
186  };
187 
188 
194  inline double
195  &operator[] (long pos) {
196 
197  assert(pos >= 0);
198  assert(pos < Size());
199 
200  return m_data[pos];
201 
202  };
203 
209  inline const double
210  operator[] (long pos) const {
211 
212  return m_data[pos];
213 
214  };
215 
221  inline double&
222  at (long pos) {
223 
224  assert(pos >= 0);
225  assert(pos < Size());
226 
227  return m_data[pos];
228 
229  };
230 
236  inline const double
237  at (long pos) const {
238 
239  return m_data[pos];
240 
241  };
242 
243 
244 };
245 
249 class Signal {
250 
251 
252  public:
253 
254 
258  Signal () {};
259 
260 
264  ~Signal () {};
265 
266 
272  Signal (long size);
273 
274 
281  Signal (long size, int compartments);
282 
288  void ReadFrom (char* fname);
289 
290 
296  const long GetSize() {
297  return m_repository.Samples();
298  };
299 
300 
307  return &m_repository;
308  };
309 
310 
316  void InitRandGenerator (int val=1) {
317  m_rng = RNG( val * (long ) clock() );
318  };
319 
325  RNG* Noise () {
326  return &m_rng;
327  };
328 
329 private:
330 
331  RNG m_rng;
334 };
335 
336 #endif /*SIGNAL_H_*/
const int Compartments() const
Number of compartments.
Definition: Signal.h:119
long m_noofsamples
Definition: Signal.h:42
~Repository()
Destruct.
Definition: Signal.h:62
~Signal()
Default destructor.
Definition: Signal.h:264
Signal repository structure.
Definition: Signal.h:40
long Size()
Size of bulk data (i.e. number of elemments of m_data)
Definition: Signal.h:71
Repository m_repository
Signal repository.
Definition: Signal.h:332
std::vector< double > m_data
Definition: Signal.h:45
const long Samples() const
Number of samples.
Definition: Signal.h:107
double & at(long pos)
Value at position in store.
Definition: Signal.h:222
double * Data()
Reference to data repository.
Definition: Signal.h:83
Repository()
Construct.
Definition: Signal.h:51
const double TP(long l) const
Time of given sample index.
Definition: Signal.h:143
Repository * Repo()
Definition: Signal.h:306
RNG m_rng
random number generator
Definition: Signal.h:327
const long Position(long l) const
Reference to data of given sample index.
Definition: Signal.h:165
std::vector< double > m_times
Definition: Signal.h:44
const long GetSize()
Definition: Signal.h:296
const int NProps() const
Number of properties per compartment.
Definition: Signal.h:131
void InitRandGenerator(int val=1)
Definition: Signal.h:316
double * Times()
Reference to time point repository.
Definition: Signal.h:95
double & TP(long l)
Reference to time of given sample index.
Definition: Signal.h:155
Signal()
Default constructor.
Definition: Signal.h:258
const void Initialize(long samples, int compartments)
Occupy RAM and set some dimensions.
Definition: Signal.h:175
const double at(long pos) const
Access to position in store.
Definition: Signal.h:237
The signal store and IO.
Definition: Signal.h:249
RNG * Noise()
Definition: Signal.h:325

-- last change 17.06.2016 | Tony Stoecker | Imprint --