aimsdata 6.0.0
Neuroimaging data handling
volumemanip.h
Go to the documentation of this file.
1/* This software and supporting documentation are distributed by
2 * Institut Federatif de Recherche 49
3 * CEA/NeuroSpin, Batiment 145,
4 * 91191 Gif-sur-Yvette cedex
5 * France
6 *
7 * This software is governed by the CeCILL-B license under
8 * French law and abiding by the rules of distribution of free software.
9 * You can use, modify and/or redistribute the software under the
10 * terms of the CeCILL-B license as circulated by CEA, CNRS
11 * and INRIA at the following URL "http://www.cecill.info".
12 *
13 * As a counterpart to the access to the source code and rights to copy,
14 * modify and redistribute granted by the license, users are provided only
15 * with a limited warranty and the software's author, the holder of the
16 * economic rights, and the successive licensors have only limited
17 * liability.
18 *
19 * In this respect, the user's attention is drawn to the risks associated
20 * with loading, using, modifying and/or developing or reproducing the
21 * software by the user in light of its specific status of free software,
22 * that may mean that it is complicated to manipulate, and that also
23 * therefore means that it is reserved for developers and experienced
24 * professionals having in-depth computer knowledge. Users are therefore
25 * encouraged to load and test the software's suitability as regards their
26 * requirements in conditions enabling the security of their systems and/or
27 * data to be ensured and, more generally, to use and operate it in the
28 * same conditions as regards security.
29 *
30 * The fact that you are presently reading this means that you have had
31 * knowledge of the CeCILL-B license and that you accept its terms.
32 */
33
34#ifndef AIMS_DATA_VOLUMEMANIP_H
35#define AIMS_DATA_VOLUMEMANIP_H
36
38
39namespace aims
40{
41
42 template < typename T >
43 inline
45 {
46 ASSERT( thing.dimT() == 1 && thing.dimZ() == 1 );
47
48 // allocate the new thingrix
49 AimsData<T> m( thing.dimY(), thing.dimX() );
50 // do the operations
51 for ( int y = 0; y < thing.dimY(); y++ )
52 for ( int x = 0; x < thing.dimX(); x++ )
53 m( y, x ) = thing( x, y );
54
55 return m;
56 }
57
58
59 template < typename T >
60 inline
61 void incSorting( AimsData<T>& thing )
62 {
63 ASSERT( thing.dimY() == 1 && thing.dimZ() == 1 && thing.dimT() == 1 );
64
65 int i,j;
66 T tmp;
67
68 for ( j = 1; j < thing.dimX(); j++ )
69 {
70 tmp = thing( j );
71 i = j - 1;
72 while ( i >= 0L && thing( i ) > tmp )
73 {
74 thing( i + 1 ) = thing( i );
75 i--;
76 }
77 thing( i + 1 ) = tmp;
78 }
79 }
80
81
82 template < typename T >
83 inline
84 void decSorting( AimsData<T>& thing )
85 {
86 ASSERT( thing.dimY() == 1 && thing.dimZ() == 1 && thing.dimT() == 1 );
87
88 int i,j;
89 T tmp;
90
91 for ( j= 1 ; j < thing.dimX(); j++ )
92 {
93 tmp = thing( j );
94 i = j - 1;
95 while ( i >= 0L && thing( i ) < tmp )
96 {
97 thing( i + 1 ) = thing( i );
98 i--;
99 }
100 thing( i + 1 ) = tmp;
101 }
102 }
103
104
105 template < typename T >
106 inline
108 {
109 ASSERT( thing.dimY() == 1 && thing.dimZ() == 1 && thing.dimT() == 1 );
110
111 AimsData<T> temp = thing.clone();
112 AimsData<int32_t> order( thing.dimX() );
113 int i,j;
114 T tmp1, tmp2;
115
116 for ( i = 0; i < order.dimX(); i++ )
117 order( i ) = i;
118
119 for ( j = 1; j < temp.dimX(); j++ )
120 {
121 tmp1 = temp( j );
122 tmp2 = order( j );
123 i = j - 1;
124 while( i >= 0L && temp( i ) > tmp1 )
125 {
126 temp( i + 1 ) = temp( i );
127 order( i + 1 ) = order( i );
128 i--;
129 }
130 temp( i + 1 ) = tmp1;
131 order( i + 1 ) = tmp2;
132 }
133
134 return order;
135 }
136
137
138 template < typename T >
139 inline
141 {
142 ASSERT( thing.dimY() == 1 && thing.dimZ() == 1 && thing.dimT() == 1 );
143
144 AimsData<T> temp = thing.clone();
145 AimsData<int32_t> order( thing.dimX() );
146 int i,j;
147 T tmp1, tmp2;
148
149 for ( i = 0; i < order.dimX(); i++ )
150 order( i ) = i;
151
152 for ( j = 1; j < temp.dimX(); j++ )
153 {
154 tmp1 = temp( j );
155 tmp2 = order( j );
156 i = j - 1;
157 while( i >= 0L && temp( i ) < tmp1 )
158 {
159 temp( i + 1 ) = temp( i );
160 order( i + 1 ) = order( i );
161 i--;
162 }
163 temp( i + 1 ) = tmp1;
164 order( i + 1 ) = tmp2;
165 }
166
167 return order;
168 }
169
170
171 template<typename T>
172 inline
173 bool hasSameDim( const AimsData<T> & v1, const AimsData<T> & v2 )
174 {
175 return isSameVolumeSize( v1.volume(), v2.volume() );
176 }
177
178
179 template<typename T>
180 inline
181 bool hasSameSize( const AimsData<T> & v1, const AimsData<T> & v2 )
182 {
183 return v1.sizeX() == v2.sizeX()
184 && v1.sizeY() == v2.sizeY()
185 && v1.sizeZ() == v2.sizeZ()
186 && v1.sizeT() == v2.sizeT();
187 }
188
189
190 template < typename T >
191 inline
193 {
194 ASSERT( thing.dimT() == 1 && thing.dimZ() == 1 );
195
196 // allocate the new thing
197 AimsData<T> m( thing.dimX(), thing.dimY(), thing.borderWidth() );
198 m = T( 0 );
199 // do the operations
200 for ( int y = 0; y < thing.dimY(); y++ )
201 for ( int x = 0; x < thing.dimX(); x++ )
202 if ( x <= y)
203 m( x, y ) = thing( x, y );
204
205 return m;
206 }
207
208
209 template < typename T >
210 inline
212 {
213 ASSERT( thing.dimT() == 1 && thing.dimZ() == 1 );
214
215 // allocate the new thing
216 AimsData<T> m( thing.dimX(), thing.dimY(), thing.borderWidth() );
217 m = T( 0 );
218 // do the operations
219 for ( int y = 0; y < thing.dimY(); y++ )
220 for ( int x = 0; x < thing.dimX(); x++ )
221 if ( x >= y )
222 m( x, y ) = thing( x, y );
223
224 return m;
225 }
226
227} // namespace aims
228
229
230template < typename T >
231inline
232std::ostream& operator << ( std::ostream& os, const AimsData<T> & thing )
233{
234 int dimx = thing.dimX();
235 int dimy = thing.dimY();
236 int dimz = thing.dimZ();
237 int dimt = thing.dimT();
238
239 os << "[";
240
241 for ( int t = 0; t < dimt; t++ )
242 {
243 os << "[";
244 for ( int z = 0; z < dimz; z++ )
245 {
246 os << "[";
247 for ( int y = 0; y < dimy; y++ )
248 {
249 os << "[";
250 for ( int x = 0; x < dimx; x++ )
251 {
252 os << thing( x, y, z, t );
253 if ( x != dimx - 1 )
254 os << ", ";
255 if ( x == dimx - 1 && y != dimy - 1 )
256 os << "]," << std::endl << " ";
257 if ( x == dimx - 1 && y == dimy - 1 && z != dimz - 1 )
258 os << "]]," << std::endl << " ";
259 if ( x == dimx - 1 && y == dimy - 1 && z == dimz - 1 &&
260 t != dimt - 1 )
261 os << "]]]," << std::endl << " ";
262 if ( x == dimx - 1 && y == dimy - 1 && z == dimz - 1 &&
263 t == dimt - 1 )
264 os << "]]]";
265 }
266 }
267 }
268 }
269
270 return os << "]";
271}
272
273
274template < typename T >
275inline
276std::istream& operator >> ( std::istream& is, AimsData<T>& thing )
277{
278 char c=0;
279 int dimx = thing.dimX();
280 int dimy = thing.dimY();
281 int dimz = thing.dimZ();
282 int dimt = thing.dimT();
283
284 is >> c;
285 for ( int t = 0; t < dimt; t++ )
286 {
287 is >> c;
288 for ( int z = 0; z < dimz; z++ )
289 {
290 is >> c;
291 for ( int y = 0; y < dimy; y++ )
292 {
293 is >> c;
294 for ( int x = 0; x < dimx; x++ )
295 {
296 is >> thing( x, y, z, t );
297 if ( x != dimx - 1 )
298 is >> c;
299 if ( x == dimx - 1 && y != dimy - 1 )
300 {
301 is >> c;
302 is >> c;
303 }
304 if ( x == dimx - 1 && y == dimy - 1 && z != dimz - 1 )
305 {
306 is >> c;
307 is >> c;
308 is >> c;
309 }
310 if ( x == dimx - 1 && y == dimy - 1 && z == dimz - 1 &&
311 t != dimt - 1 )
312 {
313 is >> c;
314 is >> c;
315 is >> c;
316 is >> c;
317 }
318 if ( x == dimx - 1 && y == dimy - 1 && z == dimz - 1 &&
319 t == dimt - 1 )
320 {
321 is >> c;
322 is >> c;
323 is >> c;
324 is >> c;
325 }
326 }
327 }
328 }
329 }
330
331 return is;
332}
333
334#endif
335
#define ASSERT(EX)
int borderWidth() const
Size of the border.
carto::VolumeRef< T > & volume()
float sizeX() const
float sizeT() const
AimsData< T > clone() const
int dimY() const
int dimX() const
int dimT() const
float sizeZ() const
float sizeY() const
int dimZ() const
The class for EcatSino data write operation.
bool hasSameDim(const AimsData< T > &v1, const AimsData< T > &v2)
AimsData< T > triInf(const AimsData< T > &thing)
bool hasSameSize(const AimsData< T > &v1, const AimsData< T > &v2)
void incSorting(AimsData< T > &thing)
Definition volumemanip.h:61
AimsData< T > triSup(const AimsData< T > &thing)
AimsData< T > transpose(const AimsData< T > &thing)
Definition volumemanip.h:44
AimsData< int32_t > decOrder(const AimsData< T > &thing)
AimsData< int32_t > incOrder(const AimsData< T > &thing)
void decSorting(AimsData< T > &thing)
Definition volumemanip.h:84
std::istream & operator>>(std::istream &is, AimsData< T > &thing)
std::ostream & operator<<(std::ostream &os, const AimsData< T > &thing)