anatomist 6.0.4
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
45namespace anatomist
46{
47 class Bucket ;
48 class AObject ;
49 class AGraphObject ;
50 class RoiLabelNamingActionView_Private ;
51
53 {
54 public:
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,
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
110inline bool
111anatomist::RoiLabelNamingAction::fillPoint( const Point3d& pc, int t,
113 anatomist::AGraphObject * region, short label,
114 anatomist::AObject** toChange,
115 std::queue<Point3d>& trialPoints, bool replace, bool add )
116{
117 Point3d dims( volumeOfLabels.getSizeX(), volumeOfLabels.getSizeY(),
118 volumeOfLabels.getSizeZ() );
119 if( in( dims, pc ) )
120 {
121 std::vector<float> vpos( 4 );
122 vpos[0] = pc[0];
123 vpos[1] = pc[1];
124 vpos[2] = pc[2];
125 vpos[3] = t;
126 float val = myCurrentImage->mixedTexValue( vpos );
127 if (add)
128 {
129 if( (volumeOfLabels->at( pc ) != region)
130 && (short(rint(val) == label)
131 && ( replace || ( (!replace) && volumeOfLabels->at( pc ) == 0 )) ) )
132 {
133 /* if( (volumeOfLabels->at( pc ) != region) && (val >= realLowLevel) && (val <= realHighLevel) ){ */
134 trialPoints.push(pc) ;
135 *toChange = volumeOfLabels->at( pc ) ;
136
137 volumeOfLabels->at( pc ) = region ;
138 return true ;
139 }
140 }
141 else
142 {
143 if( (volumeOfLabels->at( pc ) != 0 ) && (short(rint(val) == label)
144 && ( replace || ( (!replace) && volumeOfLabels->at( pc ) == region ) ) ) )
145 {
146 /* if( (volumeOfLabels->at( pc ) != region) && (val >= realLowLevel) && (val <= realHighLevel) ){ */
147 trialPoints.push(pc) ;
148 *toChange = volumeOfLabels->at( pc ) ;
149
150 volumeOfLabels->at( pc ) = 0 ;
151 return true ;
152 }
153 }
154 }
155 return false ;
156}
157
158
159inline bool
160anatomist::RoiLabelNamingAction::in( const Point3d& dims, const Point3d& p )
161{
162 if ( p[0] < 0 || p[0] > dims[0] - 1 ||
163 p[1] < 0 || p[1] > dims[1] - 1 ||
164 p[2] < 0 || p[2] > dims[2] - 1 )
165 return false ;
166
167 return true ;
168}
169
170
171
172#endif
Anatomist graph object: a list that manages destruction of its sub-elements.
Definition GraphObject.h:53
Base Anatomist object (abstract)
Definition Object.h:97
Volume object.
Definition Volume.h:67
Bucket class.
Definition Bucket.h:56
void removeWholeLabelFromRegion(int x, int y, int globalX, int globalY)
void addWholeLabelToRegion(int x, int y, int globalX, int globalY)
void removeConnecCompFromRegion(int x, int y, int globalX, int globalY)
void addConnecCompToRegion(int x, int y, int globalX, int globalY)
virtual std::string name() const
int getSizeZ() const
const T & at(long x, long y=0, long z=0, long t=0) const
int getSizeY() const
int getSizeX() const
AimsVector< int16_t, 3 > Point3d