A.I.M.S algorithms


scaleLevel.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_PRIMALSKETCH_SCALELEVEL_H
36 #define AIMS_PRIMALSKETCH_SCALELEVEL_H
37 
38 #include <cstdlib>
40 #include <aims/texdata/texdata.h>
42 #include <aims/mesh/surface.h>
43 #include <aims/mesh/texture.h>
44 #include <aims/data/data.h>
45 #include <set>
46 #include <map>
47 #include <string>
48 
49 namespace aims
50 {
51 
52  // Scalelevel Is Templated With Respect To A Geometry And A Texture
53  // Same Mechanism Than Textureddata And Extractgreylevelblobs
54 
55  // A Scale Level
56 
57  template<typename Geom, typename Text> class ScaleLevel {
58 
59  public:
60 
61  typedef typename SiteType<Geom>::type Site;
62  typedef typename TexType<Text>::type Val;
63 
64  ScaleLevel(float scale) { _scale=scale; }
65 
67 
68  float Scale() { return _scale; }
69  std::map<int, GreyLevelBlob<Site> *> BlobList() { return blobs; }
70  std::list<SaddlePoint<Site> *> SaddlePointList() { return saddlePoints; }
71  std::list<MaximumPoint<Site> *> MaximumPointList() { return maximumPoints; }
72 
74  {
75  if (blobs.find(label) != blobs.end())
76  return blobs[label];
77  else
78  {
79  std::cerr << "looking for GLB that does not exist..." << std::endl;
80  exit(EXIT_FAILURE);
81  }
82  }
83 
85 
86  void DetectBlobs(TexturedData<Geom, Text> *mask, char *stats=0);
87  int nbBlobs() { return blobs.size(); }
88 
90  {_scale=other._scale; blobs=other.blobs;
91  saddlePoints=other.saddlePoints; maximumPoints=other.maximumPoints; return *this;}
92 
93  private:
94 
95  float _scale;
96 
97  std::map<int, GreyLevelBlob<Site> *> blobs;
98  std::list<SaddlePoint<Site> *> saddlePoints;
99  std::list<MaximumPoint<Site> *> maximumPoints;
100 
101  };
102 
103  // Scale Levels Image Partial Specialisation
104 
105  template<typename T> class ScaleLevel<AimsData<T>, AimsData<T> > {
106 
107  public:
108 
109  typedef typename SiteType<AimsData<T> >::type Site;
110 
111  ScaleLevel(float scale, AimsData<T> level) { _scale=scale; _level = level.clone(); _originallevel=NULL; }
112 
113  ScaleLevel(float scale, AimsData<T> level, AimsData<T> *originallevel)
114  { _scale=scale; _level = level.clone(); _originallevel=originallevel; }
115 
117 
118  AimsData<T> & Level() { return _level; }
119 
120 
121  // Essai
124 
125  float Scale() { return _scale; }
126  std::map<int, GreyLevelBlob<Site> *> BlobList() { return blobs; }
127  std::list<SaddlePoint<Site> *> SaddlePointList() { return saddlePoints; }
128  std::list<MaximumPoint<Site> *> MaximumPointList() { return maximumPoints; }
129 
130  GreyLevelBlob<Site> *Blob(int label) {if (blobs.find(label) != blobs.end())
131  return blobs[label];
132  else
133  {std::cerr << "looking for GLB " << label << " that does not exist at scale " << _scale << std::endl;
134  exit(EXIT_FAILURE);}}
135 
136  void DetectBlobs(TexturedData<AimsData<T>, AimsData<T> > *mask=0, char *stats=0);
137  int nbBlobs() { return blobs.size(); }
138 
140  {_scale=other._scale; _level=other._level; blobs=other.blobs;
141  saddlePoints=other.saddlePoints; maximumPoints=other.maximumPoints; return *this;}
142 
143  void WriteBlobImage(std::string fileBlob);
144 
145  private:
146 
147  float _scale;
148  AimsData<T> _level;
149  AimsData<T> *_originallevel;
150  std::map<int, GreyLevelBlob<Site> *> blobs;
151  std::list<SaddlePoint<Site> *> saddlePoints;
152  std::list<MaximumPoint<Site> *> maximumPoints;
153  };
154 
155  // Scale Levels Texture Partial Specialisation
156 
157  template<int D, typename T> class ScaleLevel<AimsSurface<D, Void>, Texture<T> >
158  {
159 
160  public:
161 
162  typedef typename SiteType<AimsSurface<D, Void> >::type Site;
163 
164  ScaleLevel(float scale, Texture<T> level, AimsSurface<D, Void> *mesh)
165  {
166  _scale=scale; _level=level; _mesh=mesh; _coordinates=NULL; _originallevel=NULL;
167  }
168  ScaleLevel(float scale, Texture<T> level, AimsSurface<D, Void> *mesh, std::vector<Point3df> *coords)
169  {
170  _scale=scale; _level=level; _mesh=mesh; _coordinates=coords; _originallevel=NULL;
171  }
173  {
174  (*this)._scale=other._scale; (*this)._level=other._level; (*this)._mesh=other._mesh; (*this)._coordinates=_coordinates; _originallevel=NULL;
175  }
176  ScaleLevel(float scale, Texture<T> level, AimsSurface<D, Void> *mesh, Texture<T> *originallevel)
177  {
178  _scale=scale; _level=level; _mesh=mesh; _coordinates=NULL; _originallevel=originallevel;
179  }
180  ScaleLevel(float scale, Texture<T> level, AimsSurface<D, Void> *mesh, std::vector<Point3df> *coords, Texture<T> *originallevel)
181  {
182  _scale=scale; _level=level; _mesh=mesh; _coordinates=coords; _originallevel=originallevel;
183  }
185  {
186  (*this)._scale=other._scale; (*this)._level=other._level; (*this)._mesh=other._mesh; (*this)._coordinates=_coordinates; _originallevel=originallevel;
187  }
188 
190 
191 
192  Texture<T> & Level() { return _level; }
195 
196 
197  float Scale() { return _scale; }
198  AimsSurface<D, Void> *Mesh() { return _mesh; }
199  std::map<int, GreyLevelBlob<Site> *> & BlobList() { return blobs; }
200  std::list<SaddlePoint<Site> *> & SaddlePointList()
201  { return saddlePoints; }
202  std::list<MaximumPoint<Site> *> & MaximumPointList()
203  { return maximumPoints; }
204 
205  GreyLevelBlob<Site> *Blob (int label) {
206  if (blobs.find(label) != blobs.end())
207  return blobs[label];
208  else
209  {
210  std::cerr << "looking for GLB " << label << " that does not exist..." << std::endl;
211  exit(EXIT_FAILURE);
212  }
213  }
214 
215  void DetectBlobs(TexturedData<AimsSurface<D, Void>, Texture<T> > *mask=0, char *stats=0);
216 
217  int nbBlobs() { return blobs.size(); }
218  void PutCoordinates ( std::vector<Point3df> *coord ) { _coordinates = coord; }
219 
220 
223  {
224  (*this)._scale=other._scale;(*this)._level=other._level;(*this)._mesh=other._mesh; (*this).blobs=other.blobs;
225  (*this).saddlePoints=other.saddlePoints; (*this).maximumPoints=other.maximumPoints; return *this;
226  }
227 
228  private:
229 
230  float _scale;
231  Texture<T> _level;
232  Texture<T> *_originallevel;
233  AimsSurface<D, Void> *_mesh;
234  std::vector<Point3df> *_coordinates;
235 
236  std::map<int, GreyLevelBlob<Site> *> blobs;
237  std::list<SaddlePoint<Site> *> saddlePoints;
238  std::list<MaximumPoint<Site> *> maximumPoints;
239  };
240 
241 
242  //---------------- METHOD/FUNCTION DEFINITIONS ------------------------------
243 
244  template<typename T>
246  {
247  TexturedData<AimsData<T>, AimsData<T> >textdata(&_level) ;
248  TexturedData<AimsData<T>, AimsData<T> >rawtextdata(_originallevel) ;
249 
250 
251  ExtractGreyLevelBlobs<AimsData<T>, AimsData<T> > extractor(&textdata, &rawtextdata, mask, stats);
252 
253  typename std::map<int, GreyLevelBlob<Site> *>::iterator itBlob;
254 
255  //std::cout << "DEBUG: starting detection" << std::endl;
256  if (blobs.size() == 0)
257  {
258  extractor.Run();
259  //std::cout << "DEBUG: ran" << std::endl;
260  blobs = extractor.GetBlobs();
261  saddlePoints = extractor.GetSaddleList();
262  maximumPoints = extractor.GetMaxList();
263  //std::cout << "DEBUG: Got lists" << std::endl;
264  itBlob=blobs.begin();
265  for ( ; itBlob != blobs.end(); ++itBlob)
266  ((*itBlob).second)->SetScale(_scale);
267  //std::cout << "DEBUG: Set scales" << std::endl;
268  }
269  }
270 
271  //-------------------------------------------------------------------
272 
273  template<int D, typename T>
275  {
276 
277  TexturedData<AimsSurface<D, Void>, Texture<T> > textdata(_mesh, &_level, _coordinates) ;
278  TexturedData<AimsSurface<D, Void>, Texture<T> > rawtextdata(_mesh, _originallevel, _coordinates) ;
279 
280  ExtractGreyLevelBlobs<AimsSurface<D, Void>, Texture<T> > extractor(&textdata, &rawtextdata, mask, stats);
281 
282  typename std::map<int, GreyLevelBlob<Site> *>::iterator itBlob;
283  if (blobs.size() == 0){
284  extractor.Run();
285  blobs=extractor.GetBlobs();
286  saddlePoints=extractor.GetSaddleList();
287  maximumPoints=extractor.GetMaxList();
288  itBlob=blobs.begin();
289  for ( ; itBlob != blobs.end(); ++itBlob)
290  ((*itBlob).second)->SetScale(_scale);
291  }
292 
293  }
294 
295  //-------------------------------------------------------------------
296 
297  template<typename T>
298  void ScaleLevel<AimsData<T>, AimsData<T> >::WriteBlobImage(std::string fileBlob)
299  {
300  int x,y,z;
301  int sx=_level.dimX(), sy=_level.dimY(), sz=_level.dimZ();
302  float dx=_level.sizeX(), dy=_level.sizeY(), dz=_level.sizeZ();
303  AimsData<float> imaBlob(sx,sy,sz);
304  typename std::map<int, GreyLevelBlob<Site> *>::iterator itBlob=blobs.begin();;
305  typename std::list<SaddlePoint<Site> *>::iterator itSaddle=saddlePoints.begin();
306  typename std::list<MaximumPoint<Site> *>::iterator itMax=maximumPoints.begin();
307  typename std::set<Site,ltstr_p3d<Site> >::iterator itPoints;
308  GreyLevelBlob<Site> *blobby;
309 
310  imaBlob.setSizeXYZT(dx,dy,dz);
311 
312  for (z=0; z<sz; z++)
313  for (y=0; y<sy; y++)
314  for (x=0; x<sx; x++)
315  imaBlob(x,y,z)=0.0;
316 
317  for (; itBlob!=blobs.end(); ++itBlob)
318  {
319  blobby=(*itBlob).second;
320  itPoints=blobby->GetListePoints().begin();
321  for (; itPoints!=blobby->GetListePoints().end(); ++itPoints)
322  {
323  x=int((*itPoints)[0]); y=int((*itPoints)[1]); z=int((*itPoints)[2]);
324  imaBlob(x,y,z)=255.0;
325  }
326  }
327 
328  for (; itSaddle!=saddlePoints.end(); ++itSaddle)
329  {
330  x=int((*itSaddle)->_node[0]); y=int((*itSaddle)->_node[1]); z=int((*itSaddle)->_node[2]);
331  imaBlob(x,y,z)=128.0;
332  }
333 
334  for (; itMax!=maximumPoints.end(); ++itMax)
335  {
336  x=int((*itMax)->_node[0]); y=int((*itMax)->_node[1]); z=int((*itMax)->_node[2]);
337  imaBlob(x,y,z)=128.0;
338  }
339  Writer<AimsData<float> > dataW(fileBlob);
340  dataW.write(imaBlob);
341  }
342 
343 }
344 
345 #endif
TexturedData< AimsData< T >, AimsData< T > > OriginalData()
Definition: scaleLevel.h:123
SiteType< Geom >::type Site
Definition: scaleLevel.h:61
std::map< int, GreyLevelBlob< Site > * > BlobList()
Definition: scaleLevel.h:69
ScaleLevel(float scale, AimsData< T > level)
Definition: scaleLevel.h:111
TexturedData< Geom, Text > Data()
Definition: scaleLevel.h:84
BucketMap< Void > * mask(const BucketMap< Void > &src, const BucketMap< Void > &m, bool intersect=true)
std::list< SaddlePoint< Site > * > & SaddlePointList()
Definition: scaleLevel.h:200
std::set< T, ltstr_p3d< T > > & GetListePoints()
int dimX() const
ScaleLevel(const ScaleLevel< AimsSurface< D, Void >, Texture< T > > &other)
Definition: scaleLevel.h:172
GreyLevelBlob< Site > * Blob(int label)
Definition: scaleLevel.h:73
std::list< MaximumPoint< Site > * > & MaximumPointList()
Definition: scaleLevel.h:202
std::list< MaximumPoint< Site > * > MaximumPointList()
Definition: scaleLevel.h:128
std::map< int, GreyLevelBlob< Site > * > & BlobList()
Definition: scaleLevel.h:199
std::list< SaddlePoint< Site > * > SaddlePointList()
Definition: scaleLevel.h:70
ScaleLevel(float scale, Texture< T > level, AimsSurface< D, Void > *mesh)
Definition: scaleLevel.h:164
ScaleLevel(float scale)
Definition: scaleLevel.h:64
SiteType< AimsSurface< D, Void > >::type Site
Definition: scaleLevel.h:162
std::map< int, GreyLevelBlob< Site > * > BlobList()
Definition: scaleLevel.h:126
ScaleLevel(float scale, Texture< T > level, AimsSurface< D, Void > *mesh, Texture< T > *originallevel)
Definition: scaleLevel.h:176
TexturedData< AimsSurface< D, Void >, Texture< T > > OriginalData()
Definition: scaleLevel.h:194
ScaleLevel(const ScaleLevel< AimsSurface< D, Void >, Texture< T > > &other, Texture< T > *originallevel)
Definition: scaleLevel.h:184
SiteType< AimsData< T > >::type Site
Definition: scaleLevel.h:109
ScaleLevel(float scale, AimsData< T > level, AimsData< T > *originallevel)
Definition: scaleLevel.h:113
void PutCoordinates(std::vector< Point3df > *coord)
Definition: scaleLevel.h:218
ScaleLevel< Geom, Text > & operator=(const ScaleLevel< Geom, Text > &other)
Definition: scaleLevel.h:89
virtual bool write(const T &obj, bool ascii=false, const std::string *format=0)
TexturedData< AimsSurface< D, Void >, Texture< T > > Data()
Definition: scaleLevel.h:193
AimsData< T > clone() const
TexType< Text >::type Val
Definition: scaleLevel.h:62
TexturedData< AimsData< T >, AimsData< T > > Data()
Definition: scaleLevel.h:122
std::list< SaddlePoint< Site > * > SaddlePointList()
Definition: scaleLevel.h:127
std::list< MaximumPoint< Site > * > GetMaxList()
ScaleLevel(float scale, Texture< T > level, AimsSurface< D, Void > *mesh, std::vector< Point3df > *coords)
Definition: scaleLevel.h:168
std::map< int, GreyLevelBlob< Site > * > GetBlobs()
void setSizeXYZT(float sizex=1.0f, float sizey=1.0f, float sizez=1.0f, float sizet=1.0f)
GreyLevelBlob< Site > * Blob(int label)
Definition: scaleLevel.h:130
ScaleLevel(float scale, Texture< T > level, AimsSurface< D, Void > *mesh, std::vector< Point3df > *coords, Texture< T > *originallevel)
Definition: scaleLevel.h:180
void DetectBlobs(TexturedData< Geom, Text > *mask, char *stats=0)
std::list< SaddlePoint< Site > * > GetSaddleList()
std::list< MaximumPoint< Site > * > MaximumPointList()
Definition: scaleLevel.h:71