aimsdata  5.0.5
Neuroimaging data handling
minmax.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_UTILITY_MINMAX_H
35 #define AIMS_UTILITY_MINMAX_H
36 
37 #include <aims/data/data.h>
38 
39 namespace aims
40 {
41 
42  //-----------------------------------//
43  // minmax< ObjectType, ValueType > //
44 //-----------------------------------//
45 template <typename ObjectType, typename ValueType>
46 void minmax( const ObjectType &, ValueType &min, ValueType &max );
47 
48 //-----------------------------------------------------------------------------
49 template <typename ObjectType, typename ValueType>
50 void minmax( const ObjectType &, ValueType &min, ValueType &max )
51 {
52  ObjectType::error_minmax_not_specialized;
53 }
54 
55 
56  //--------------------------------------------//
57  // minmax< AimsData<ValueType>, ValueType > //
58 //--------------------------------------------//
59 template <typename ValueType>
60 void minmax( const AimsData<ValueType> &volume, ValueType &min,
61  ValueType &max )
62 {
64  volume.begin() + volume.oFirstPoint();
65 
66  min = max = *it;
67  for ( int t = 0; t < volume.dimT(); t++ ) {
68  for ( int z = 0; z < volume.dimZ(); z++ ) {
69  for ( int y = 0; y < volume.dimY(); y++ ) {
70  for ( int x = 0; x < volume.dimX(); x++ ) {
71  if ( *it < min ) min = *it;
72  if ( *it > max ) max = *it;
73  it++;
74  }
75  it += volume.oPointBetweenLine();
76  }
77  it += volume.oLineBetweenSlice();
78  }
79  it += volume.oSliceBetweenVolume();
80  }
81 }
82 
83 
84  //-------------------------------------------------//
85  // minmax< carto::Volume<ValueType>, ValueType > //
86 //-------------------------------------------------//
87 template <typename ValueType>
88 void minmax( const carto::Volume<ValueType> &volume, ValueType &min,
89  ValueType &max )
90 {
91  const ValueType *it;
92  int dx = volume.getSizeX();
93  int dy = volume.getSizeY();
94  int dz = volume.getSizeZ();
95  int dt = volume.getSizeT();
96 
97  min = max = volume.at( 0 );
98  for ( int t = 0; t < dt; t++ )
99  {
100  for ( int z = 0; z < dz; z++ )
101  {
102  for ( int y = 0; y < dy; y++ )
103  {
104  it = &volume.at( 0, y, z, t );
105  for ( int x = 0; x < dx; x++ )
106  {
107  if ( *it < min ) min = *it;
108  if ( *it > max ) max = *it;
109  it++;
110  }
111  }
112  }
113  }
114 }
115 
116 
117  //-----------------------------------------------------------------//
118  // minmax< carto::rc_prr<carto::Volume<ValueType> >, ValueType > //
119 //-----------------------------------------------------------------//
120 template <typename ValueType>
122  ValueType &min, ValueType &max )
123 {
124  minmax( *volume, min, max );
125 }
126 
127 
128  //----------------------------------------------------//
129  // minmax< carto::VolumeRef<ValueType>, ValueType > //
130 //----------------------------------------------------//
131 template <typename ValueType>
133  ValueType &min, ValueType &max )
134 {
135  minmax( *volume, min, max );
136 }
137 
138 
139 } // namespace aims
140 
141 #endif // ifndef AIMS_UTILITY_MINMAX_H
int oLineBetweenSlice() const
Number of lines between 2 consecutive slices.
Definition: border.h:250
const T * const_iterator
basic constant iterator
int dimZ() const
int getSizeZ() const
const T & at(long x, long y=0, long z=0, long t=0) const
int oPointBetweenLine() const
Offset between the end of a line and the start of the consecutive line.
Definition: border.h:236
iterator begin()
int dimY() const
The class for EcatSino data write operation.
Definition: border.h:44
int getSizeX() const
int dimT() const
int getSizeY() const
int oSliceBetweenVolume() const
Number of slices between 2 consecutive volumes.
Definition: border.h:264
int getSizeT() const
void minmax(const ObjectType &, ValueType &min, ValueType &max)
Definition: minmax.h:50
int oFirstPoint() const
Offset from the start of the allocated memory to the first point.
Definition: border.h:215
int dimX() const