aimsalgo  5.0.5
Neuroimaging image processing
topoClassifier.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 
35 #ifndef AIMS_TOPOLOGY_TOPOCLASSIFIER_H
36 #define AIMS_TOPOLOGY_TOPOCLASSIFIER_H
37 
38 #include <aims/data/data.h>
41 #include <aims/bucket/bucketMap.h>
43 
44 
45 template< typename T >
47 {
48 public:
49  class ResultRcType;
50  class ResultType;
51 
53  virtual ~TopologicalClassifier() { }
54 
55  ResultRcType doit( const T & );
56  ResultType & takeResult( ResultRcType & d ) { return d; }
57 };
58 
59 
60 template< typename T >
62 {
63 public:
66 
68  virtual ~TopologicalClassifier() { }
69 
70  ResultRcType doit( const AimsData< T >& );
71  ResultType & takeResult( ResultRcType & d ) { return d; }
72 };
73 
74 
75 template< typename T >
76 class TopologicalClassifier< aims::BucketMap<T> >
77 {
78 public:
81 
83  virtual ~TopologicalClassifier() { }
84 
85  ResultRcType doit( const aims::BucketMap< T >& );
86  ResultType & takeResult( ResultRcType & d ) { return *d; }
87 };
88 
89 
90 template< typename T > inline
92 {
93  int x, y, z;
94  T label;
95 
96  int dx = d.dimX();
97  int dy = d.dimY();
98  int dz = d.dimZ();
99 
100  AimsData< short > res( dx, dy, dz );
101  res.setSizeXYZT( d.sizeX(), d.sizeY(), d.sizeZ() );
102 
105 
106  for ( z=0; z<dz; z++ )
107  for ( y=0; y<dy; y++ )
108  for ( x=0; x<dx; x++ )
109  if( ( label = d( x, y, z ) ) )
110  {
111  Point3d pt( x, y, z );
112  topo.computeLocalCCNumbers( pt, (int)label );
113  res( x, y, z ) = (short)topoMean.classification( topo.Cstar(),
114  topo.Cbar() );
115  }
116 
117  return res;
118 }
119 
120 
121 template< typename T > inline
124  const aims::BucketMap< T >& d )
125 {
126  typename aims::BucketMap<T>::const_iterator ibm, ebm = d.end();
128 
130  res->setSizeXYZT( d.sizeX(), d.sizeY(), d.sizeZ(), d.sizeT() );
131 
132  AimsData<int16_t> *dc;
134  dc = conv( d );
135  TopologicalClassification< T > topo( *dc );
137 
138  for( ibm=d.begin(); ibm!=ebm; ++ibm )
139  {
140  aims::BucketMap<int16_t>::Bucket & bk = (*res)[ ibm->first ];
141  for( ib=ibm->second.begin(), eb=ibm->second.end(); ib!=eb; ++ib )
142  {
143  topo.computeLocalCCNumbers( ib->first, ib->second );
144  bk[ ib->first ] = (short)topoMean.classification( topo.Cstar(),
145  topo.Cbar() );
146  }
147  }
148  delete dc;
149 
151 }
152 
153 
154 template<> inline
157  const aims::BucketMap<Void>& d )
158 {
159  aims::BucketMap<Void>::const_iterator ibm, ebm = d.end();
161 
163  res->setSizeXYZT( d.sizeX(), d.sizeY(), d.sizeZ(), d.sizeT() );
164 
165  AimsData<int16_t> *dc;
167  dc = conv( d );
170 
171  for( ibm=d.begin(); ibm!=ebm; ++ibm )
172  {
173  aims::BucketMap<int16_t>::Bucket & bk = (*res)[ ibm->first ];
174  for( ib=ibm->second.begin(), eb=ibm->second.end(); ib!=eb; ++ib )
175  {
176  topo.computeLocalCCNumbers( ib->first, 1 );
177  bk[ ib->first ] = (short)topoMean.classification( topo.Cstar(),
178  topo.Cbar() );
179  }
180  }
181  delete dc;
182 
184 }
185 
186 #endif
int dimZ() const
float sizeY() const
void computeLocalCCNumbers(const Point3d &, int)
float sizeZ() const
ResultType & takeResult(ResultRcType &d)
float sizeZ() const
int dimY() const
float sizeX() const
virtual ~TopologicalClassifier()
static int classification(int, int)
float sizeX() const
std::map< Point3d, T, BucketMapLess > Bucket
ResultRcType doit(const T &)
carto::rc_ptr< aims::BucketMap< int16_t > > ResultRcType
void setSizeXYZT(float sizex, float sizey, float sizez, float sizet)
float sizeY() const
ResultType & takeResult(ResultRcType &d)
float sizeT() const
std::map< int, Bucket >::const_iterator const_iterator
ResultType & takeResult(ResultRcType &d)
void setSizeXYZT(float sizex=1.0f, float sizey=1.0f, float sizez=1.0f, float sizet=1.0f)
int dimX() const