STIR  6.2.0
stir_NumericalRecipes.h
Go to the documentation of this file.
1 //
2 //
3 
12 /*
13  Copyright (C) 2003- 2009, Hammersmith Imanet Ltd
14  This file is part of STIR.
15 
16  SPDX-License-Identifier: Apache-2.0
17 
18  See STIR/LICENSE.txt for details
19 */
20 #ifndef __stir_numerics_stir_NumericalRecipes_h__
21 #define __stir_numerics_stir_NumericalRecipes_h__
22 
23 #include "stir/VectorWithOffset.h"
24 #include "stir/Array.h"
25 #include <complex>
26 
27 START_NAMESPACE_STIR
28 
34 
35 inline void
36 stir_to_nr(const VectorWithOffset<std::complex<float>>& c, VectorWithOffset<float>& nr_data)
37 {
38  for (int i = 0; i < c.get_length(); ++i)
39  {
40  nr_data[2 * i + 1] = c[i].real();
41  nr_data[2 * i + 2] = c[i].imag();
42  }
43 }
44 
45 inline void
46 stir_to_nr(const Array<2, std::complex<float>>& c2d, VectorWithOffset<float>& nr_data)
47 {
48 
49  VectorWithOffset<float>::iterator nr_iter = nr_data.begin();
50 
51  Array<2, std::complex<float>>::const_full_iterator iter = c2d.begin_all();
52 
53  while (iter != c2d.end_all())
54  {
55  *nr_iter++ = iter->real();
56  *nr_iter++ = iter->imag();
57  ++iter;
58  }
59 }
60 
61 inline void
62 stir_to_nr(const VectorWithOffset<Array<1, std::complex<float>>>& c2d, VectorWithOffset<float>& nr_data)
63 {
64 
65  VectorWithOffset<float>::iterator nr_iter = nr_data.begin();
66 
67  VectorWithOffset<Array<1, std::complex<float>>>::const_iterator iter = c2d.begin();
68  while (iter != c2d.end())
69  {
70  Array<1, std::complex<float>>::const_iterator row_iter = iter->begin();
71  while (row_iter != iter->end())
72  {
73  *nr_iter++ = row_iter->real();
74  *nr_iter++ = row_iter->imag();
75  ++row_iter;
76  }
77  ++iter;
78  }
79 }
80 
81 void
82 nr_to_stir(const VectorWithOffset<float>& nr_data, VectorWithOffset<std::complex<float>>& c)
83 {
84  for (int i = 0; i < c.get_length(); ++i)
85  {
86  c[i] = std::complex<float>(nr_data[2 * i + 1], nr_data[2 * i + 2]);
87  }
88 }
89 
90 inline void
91 nr_to_stir(const VectorWithOffset<float>& nr_data, Array<2, std::complex<float>>& c2d)
92 {
93  VectorWithOffset<float>::const_iterator nr_iter = nr_data.begin();
94  Array<2, std::complex<float>>::full_iterator iter = c2d.begin_all();
95  while (iter != c2d.end_all())
96  {
97  *iter = std::complex<float>(*nr_iter, *(nr_iter + 1));
98  nr_iter += 2;
99  ++iter;
100  }
101 }
102 
103 inline void
104 nr_to_stir(const VectorWithOffset<float>& nr_data, VectorWithOffset<Array<1, std::complex<float>>>& c2d)
105 {
106  VectorWithOffset<float>::const_iterator nr_iter = nr_data.begin();
107  VectorWithOffset<Array<1, std::complex<float>>>::iterator iter = c2d.begin();
108  while (iter != c2d.end())
109  {
110  Array<1, std::complex<float>>::iterator row_iter = iter->begin();
111  while (row_iter != iter->end())
112  {
113  *row_iter = std::complex<float>(*nr_iter, *(nr_iter + 1));
114  nr_iter += 2;
115  ++row_iter;
116  }
117  ++iter;
118  }
119 }
120 
121 #if 0
122 void real_to_complex(const VectorWithOffset< std::complex<float> >& c,
123  VectorWithOffset<float>& nr_data)
124 {
125  Array<2,std::complex<float> >::const_full_iterator iter=
126  c2d.begin_all();
127 
128  while(iter != c2d.end_all())
129  {
130  *nr_iter++ = iter->real();
131  *nr_iter++ = iter->imag();
132  ++iter;
133  }
134  for (int i=0; i<c.get_length(); ++i)
135  {
136  nr_data[2*i+1] = c[i].real();
137  nr_data[2*i+2] = c[i].imag();
138  }
139 }
140 #endif
141 
143 
144 END_NAMESPACE_STIR
145 #endif
defines the Array class for multi-dimensional (numeric) arrays
defines the stir::VectorWithOffset class