anatomist  5.0.5
3D neuroimaging data viewer
labelnaming.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 #ifndef ROI_LABELNAMING_ACTION_H
34 #define ROI_LABELNAMING_ACTION_H
35 
39 
40 #include <aims/bucket/bucketMap.h>
41 
42 #include <queue>
43 
44 
45 namespace anatomist
46 {
47  class Bucket ;
48  class AObject ;
49  class AGraphObject ;
50  class RoiLabelNamingActionView_Private ;
51 
53  {
54  public:
56  virtual ~RoiLabelNamingAction() ;
57 
58  virtual std::string name() const;
59 
60  void addWholeLabelToRegion( int x, int y, int globalX, int globalY ) ;
61  void addConnecCompToRegion( int x, int y, int globalX, int globalY ) ;
62  void removeConnecCompFromRegion( int x, int y, int globalX, int globalY ) ;
63  void removeWholeLabelFromRegion( int x, int y, int globalX, int globalY ) ;
64 
65  static Action* creator() ;
66 
67  void setModeTo2D() {
68  myTwoDMode = 1 ;
69  std::cout << "Setting label naming mode to 2D" << std::endl ;
70  }
71  void setModeTo3D() {
72  myTwoDMode = 0 ;
73  std::cout << "Setting label naming mode to 3D" << std::endl ;
74  }
75 
76 
77  private:
78  AObject * getCurrentImage() ;
79  void fillRegion( int x, int y, anatomist::AGraphObject * region,
80  std::list< std::pair< Point3d, ChangesItem> >& changes,
81  bool add, bool wholeImage ) ;
82  bool fillPoint( const Point3d& pc, int t,
83  AimsData<anatomist::AObject*>& volumeOfLabels,
84  anatomist::AGraphObject * region, short label,
85  anatomist::AObject** toChange,
86  std::queue<Point3d>& trialPoints, bool replace = false, bool add = true ) ;
87  bool in( const Point3d&, const Point3d& p ) ;
88  template <class T> void computeImageValueMap(const anatomist::AVolume<T>& avol, int timePos ) ;
89  static anatomist::AObject * myCurrentImage ;
90 
91  static std::vector< std::map< int16_t, int32_t> > myCurrentImageValues ;
92  static std::vector<bool> myComputeCurrentImageValueMap ;
93  static int32_t myNbOfPointsToSegmentLimit ;
94  bool myTwoDMode ;
95 
96  struct PointLess : public std::binary_function< Point3d, Point3d , bool>
97  {
98  bool operator () ( const Point3d & p1, const Point3d & p2 ) const
99  {
100  return( p1[2] < p2[2]
101  || ( (p1[2] == p2[2]) && (p1[1] < p2[1]) )
102  || ( (p1[2] == p2[2])
103  && (p1[1] == p2[1]) && (p1[0] < p2[0]) ) ) ;
104  }
105  };
106  };
107 }
108 
109 
110 inline bool
111 anatomist::RoiLabelNamingAction::fillPoint( const Point3d& pc, int t,
112  AimsData<anatomist::AObject*>& volumeOfLabels,
113  anatomist::AGraphObject * region, short label,
114  anatomist::AObject** toChange,
115  std::queue<Point3d>& trialPoints, bool replace, bool add )
116 {
117  Point3d dims( volumeOfLabels.dimX(), volumeOfLabels.dimY(), volumeOfLabels.dimZ()) ;
118  if( in( dims, pc ) )
119  {
120  std::vector<float> vpos( 4 );
121  vpos[0] = pc[0];
122  vpos[1] = pc[1];
123  vpos[2] = pc[2];
124  vpos[3] = t;
125  float val = myCurrentImage->mixedTexValue( vpos );
126  if (add)
127  {
128  if( (volumeOfLabels( pc ) != region)
129  && (short(rint(val) == label)
130  && ( replace || ( (!replace) && volumeOfLabels( pc ) == 0 )) ) )
131  {
132  /* if( (volumeOfLabels( pc ) != region) && (val >= realLowLevel) && (val <= realHighLevel) ){ */
133  trialPoints.push(pc) ;
134  *toChange = volumeOfLabels( pc ) ;
135 
136  volumeOfLabels( pc ) = region ;
137  return true ;
138  }
139  }
140  else
141  {
142  if( (volumeOfLabels( pc ) != 0 ) && (short(rint(val) == label)
143  && ( replace || ( (!replace) && volumeOfLabels( pc ) == region ) ) ) )
144  {
145  /* if( (volumeOfLabels( pc ) != region) && (val >= realLowLevel) && (val <= realHighLevel) ){ */
146  trialPoints.push(pc) ;
147  *toChange = volumeOfLabels( pc ) ;
148 
149  volumeOfLabels( pc ) = 0 ;
150  return true ;
151  }
152  }
153  }
154  return false ;
155 }
156 
157 
158 inline bool
159 anatomist::RoiLabelNamingAction::in( const Point3d& dims, const Point3d& p )
160 {
161  if ( p[0] < 0 || p[0] > dims[0] - 1 ||
162  p[1] < 0 || p[1] > dims[1] - 1 ||
163  p[2] < 0 || p[2] > dims[2] - 1 )
164  return false ;
165 
166  return true ;
167 }
168 
169 
170 
171 #endif
Anatomist graph object: a list that manages destruction of its sub-elements.
Definition: GraphObject.h:52
int dimZ() const
void removeConnecCompFromRegion(int x, int y, int globalX, int globalY)
Base Anatomist object (abstract)
Definition: Object.h:95
void addConnecCompToRegion(int x, int y, int globalX, int globalY)
int dimY() const
void removeWholeLabelFromRegion(int x, int y, int globalX, int globalY)
void addWholeLabelToRegion(int x, int y, int globalX, int globalY)
virtual std::string name() const
Volume object.
Definition: Volume.h:64
int dimX() const