aimsdata  4.7.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 
39 namespace aims
40 {
41 
42  template < typename T >
43  inline
44  AimsData<T> diag( const AimsData<T>& thing )
45  {
46  ASSERT( thing.dimT() == 1 && thing.dimZ() == 1 && thing.dimY() == 1 );
47 
48  // allocate the new thing
49  AimsData<T> m( thing.dimX(), thing.dimX() );
50  // do the operations
51  for ( int x = 0; x < thing.dimX(); x++ )
52  m( x, x ) = thing( x );
53 
54  return m;
55  }
56 
57 
58  template < typename T >
59  inline
60  AimsData<T> undiag( const AimsData<T>& thing )
61  {
62  ASSERT( thing.dimT() == 1 && thing.dimZ() == 1 );
63 
64  // allocate the new thing
65  AimsData<T> m( std::min( thing.dimX(), thing.dimY() ) , 1 );
66  // do the operations
67  for ( int x = 0; x < std::min( thing.dimX(), thing.dimY() ); x++ )
68  m( x, 0 ) = thing( x, x );
69 
70  return m;
71  }
72 
73 
74  template < typename T >
75  inline
77  {
78  ASSERT( thing.dimT() == 1 && thing.dimZ() == 1 );
79 
80  // allocate the new thingrix
81  AimsData<T> m( thing.dimY(), thing.dimX() );
82  // do the operations
83  for ( int y = 0; y < thing.dimY(); y++ )
84  for ( int x = 0; x < thing.dimX(); x++ )
85  m( y, x ) = thing( x, y );
86 
87  return m;
88  }
89 
90 
91  template < typename T >
92  inline
93  void incSorting( AimsData<T>& thing )
94  {
95  ASSERT( thing.dimY() == 1 && thing.dimZ() == 1 && thing.dimT() == 1 );
96 
97  int i,j;
98  T tmp;
99 
100  for ( j = 1; j < thing.dimX(); j++ )
101  {
102  tmp = thing( j );
103  i = j - 1;
104  while ( i >= 0L && thing( i ) > tmp )
105  {
106  thing( i + 1 ) = thing( i );
107  i--;
108  }
109  thing( i + 1 ) = tmp;
110  }
111  }
112 
113 
114  template < typename T >
115  inline
116  void decSorting( AimsData<T>& thing )
117  {
118  ASSERT( thing.dimY() == 1 && thing.dimZ() == 1 && thing.dimT() == 1 );
119 
120  int i,j;
121  T tmp;
122 
123  for ( j= 1 ; j < thing.dimX(); j++ )
124  {
125  tmp = thing( j );
126  i = j - 1;
127  while ( i >= 0L && thing( i ) < tmp )
128  {
129  thing( i + 1 ) = thing( i );
130  i--;
131  }
132  thing( i + 1 ) = tmp;
133  }
134  }
135 
136 
137  template < typename T >
138  inline
140  {
141  ASSERT( thing.dimY() == 1 && thing.dimZ() == 1 && thing.dimT() == 1 );
142 
143  AimsData<T> temp = thing.clone();
144  AimsData<int32_t> order( thing.dimX() );
145  int i,j;
146  T tmp1, tmp2;
147 
148  for ( i = 0; i < order.dimX(); i++ )
149  order( i ) = i;
150 
151  for ( j = 1; j < temp.dimX(); j++ )
152  {
153  tmp1 = temp( j );
154  tmp2 = order( j );
155  i = j - 1;
156  while( i >= 0L && temp( i ) > tmp1 )
157  {
158  temp( i + 1 ) = temp( i );
159  order( i + 1 ) = order( i );
160  i--;
161  }
162  temp( i + 1 ) = tmp1;
163  order( i + 1 ) = tmp2;
164  }
165 
166  return order;
167  }
168 
169 
170  template < typename T >
171  inline
173  {
174  ASSERT( thing.dimY() == 1 && thing.dimZ() == 1 && thing.dimT() == 1 );
175 
176  AimsData<T> temp = thing.clone();
177  AimsData<int32_t> order( thing.dimX() );
178  int i,j;
179  T tmp1, tmp2;
180 
181  for ( i = 0; i < order.dimX(); i++ )
182  order( i ) = i;
183 
184  for ( j = 1; j < temp.dimX(); j++ )
185  {
186  tmp1 = temp( j );
187  tmp2 = order( j );
188  i = j - 1;
189  while( i >= 0L && temp( i ) < tmp1 )
190  {
191  temp( i + 1 ) = temp( i );
192  order( i + 1 ) = order( i );
193  i--;
194  }
195  temp( i + 1 ) = tmp1;
196  order( i + 1 ) = tmp2;
197  }
198 
199  return order;
200  }
201 
202 
203  template<typename T>
204  inline
205  bool hasSameDim( const AimsData<T> & v1, const AimsData<T> & v2 )
206  {
207  return v1.dimX() == v2.dimX()
208  && v1.dimY() == v2.dimY()
209  && v1.dimZ() == v2.dimZ()
210  && v1.dimT() == v2.dimT();
211  }
212 
213 
214  template<typename T>
215  inline
216  bool hasSameSize( const AimsData<T> & v1, const AimsData<T> & v2 )
217  {
218  return v1.sizeX() == v2.sizeX()
219  && v1.sizeY() == v2.sizeY()
220  && v1.sizeZ() == v2.sizeZ()
221  && v1.sizeT() == v2.sizeT();
222  }
223 
224 
225  template < typename T >
226  inline
228  {
229  ASSERT( thing.dimT() == 1 && thing.dimZ() == 1 );
230 
231  // allocate the new thing
232  AimsData<T> m( thing.dimX(), thing.dimY(), thing.borderWidth() );
233  m = T( 0 );
234  // do the operations
235  for ( int y = 0; y < thing.dimY(); y++ )
236  for ( int x = 0; x < thing.dimX(); x++ )
237  if ( x <= y)
238  m( x, y ) = thing( x, y );
239 
240  return m;
241  }
242 
243 
244  template < typename T >
245  inline
247  {
248  ASSERT( thing.dimT() == 1 && thing.dimZ() == 1 );
249 
250  // allocate the new thing
251  AimsData<T> m( thing.dimX(), thing.dimY(), thing.borderWidth() );
252  m = T( 0 );
253  // do the operations
254  for ( int y = 0; y < thing.dimY(); y++ )
255  for ( int x = 0; x < thing.dimX(); x++ )
256  if ( x >= y )
257  m( x, y ) = thing( x, y );
258 
259  return m;
260  }
261 
262 } // namespace aims
263 
264 
265 template < typename T >
266 inline
267 std::ostream& operator << ( std::ostream& os, const AimsData<T> & thing )
268 {
269  int dimx = thing.dimX();
270  int dimy = thing.dimY();
271  int dimz = thing.dimZ();
272  int dimt = thing.dimT();
273 
274  os << "[";
275 
276  for ( int t = 0; t < dimt; t++ )
277  {
278  os << "[";
279  for ( int z = 0; z < dimz; z++ )
280  {
281  os << "[";
282  for ( int y = 0; y < dimy; y++ )
283  {
284  os << "[";
285  for ( int x = 0; x < dimx; x++ )
286  {
287  os << thing( x, y, z, t );
288  if ( x != dimx - 1 )
289  os << ", ";
290  if ( x == dimx - 1 && y != dimy - 1 )
291  os << "]," << std::endl << " ";
292  if ( x == dimx - 1 && y == dimy - 1 && z != dimz - 1 )
293  os << "]]," << std::endl << " ";
294  if ( x == dimx - 1 && y == dimy - 1 && z == dimz - 1 &&
295  t != dimt - 1 )
296  os << "]]]," << std::endl << " ";
297  if ( x == dimx - 1 && y == dimy - 1 && z == dimz - 1 &&
298  t == dimt - 1 )
299  os << "]]]";
300  }
301  }
302  }
303  }
304 
305  return os << "]";
306 }
307 
308 
309 template < typename T >
310 inline
311 std::istream& operator >> ( std::istream& is, AimsData<T>& thing )
312 {
313  char c=0;
314  int dimx = thing.dimX();
315  int dimy = thing.dimY();
316  int dimz = thing.dimZ();
317  int dimt = thing.dimT();
318 
319  is >> c;
320  for ( int t = 0; t < dimt; t++ )
321  {
322  is >> c;
323  for ( int z = 0; z < dimz; z++ )
324  {
325  is >> c;
326  for ( int y = 0; y < dimy; y++ )
327  {
328  is >> c;
329  for ( int x = 0; x < dimx; x++ )
330  {
331  is >> thing( x, y, z, t );
332  if ( x != dimx - 1 )
333  is >> c;
334  if ( x == dimx - 1 && y != dimy - 1 )
335  {
336  is >> c;
337  is >> c;
338  }
339  if ( x == dimx - 1 && y == dimy - 1 && z != dimz - 1 )
340  {
341  is >> c;
342  is >> c;
343  is >> c;
344  }
345  if ( x == dimx - 1 && y == dimy - 1 && z == dimz - 1 &&
346  t != dimt - 1 )
347  {
348  is >> c;
349  is >> c;
350  is >> c;
351  is >> c;
352  }
353  if ( x == dimx - 1 && y == dimy - 1 && z == dimz - 1 &&
354  t == dimt - 1 )
355  {
356  is >> c;
357  is >> c;
358  is >> c;
359  is >> c;
360  }
361  }
362  }
363  }
364  }
365 
366  return is;
367 }
368 
369 #endif
370 
GenesisReader< T > & operator>>(GenesisReader< T > &reader, AimsData< T > &thing)
Definition: genesisR.h:70
void decSorting(AimsData< T > &thing)
Definition: volumemanip.h:116
int dimZ() const
AimsData< int32_t > decOrder(const AimsData< T > &thing)
Definition: volumemanip.h:172
float sizeZ() const
int dimY() const
float sizeT() const
The class for EcatSino data write operation.
Definition: border.h:42
float sizeX() const
bool hasSameSize(const AimsData< T > &v1, const AimsData< T > &v2)
Definition: volumemanip.h:216
void incSorting(AimsData< T > &thing)
Definition: volumemanip.h:93
AimsData< T > clone() const
AimsData< T > triSup(const AimsData< T > &thing)
Definition: volumemanip.h:246
bool hasSameDim(const AimsData< T > &v1, const AimsData< T > &v2)
Definition: volumemanip.h:205
AimsData< T > undiag(const AimsData< T > &thing)
Definition: volumemanip.h:60
AimsData< T > triInf(const AimsData< T > &thing)
Definition: volumemanip.h:227
float sizeY() const
int dimT() const
AimsData< int32_t > incOrder(const AimsData< T > &thing)
Definition: volumemanip.h:139
#define ASSERT(EX)
AimsData< T > diag(const AimsData< T > &thing)
Definition: volumemanip.h:44
int dimX() const
int borderWidth() const
Usefull offsets for A.I.M.S.
Definition: border.h:135
AimsData< T > transpose(const AimsData< T > &thing)
Definition: volumemanip.h:76