anatomist  5.1.2
3D neuroimaging data viewer
dynsegmentaction.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_DYNSEGMENT_ACTION_H
34 #define ROI_DYNSEGMENT_ACTION_H
35 
42 
43 #include <aims/bucket/bucketMap.h>
44 #include <queue>
45 
46 #include <QWidget>
47 
48 namespace anatomist
49 {
50 
51  class Bucket ;
52  class AObject ;
53  class AGraphObject ;
54  class RoiDynSegmentActionView_Private ;
55 
56  class RoiDynSegmentAction : public Action, public Observer, public Observable {
57  public:
60  THREED
61  } ;
62 
65  virtual void update( const anatomist::Observable *, void * ) ;
66 
67  virtual std::string name() const ;
68 
69  virtual QWidget * actionView( QWidget * ) ;
70  virtual bool viewableAction( ) const { return true ; }
71 
72  static Action* creator() ;
73 
74  int dimensionMode() const { return myDimensionMode ; }
75  int order() const { return myOrder ; }
76  int faithInterval() const { return myFaithInterval ; }
77  int refineMode() const { return int( myRefineMode) ; }
78  int findNearestMinimum() const { return int( myFindNearestMinimumMode ) ; }
79  float meanValue() const { return myInsideMeanError ; }
80  float sigmaValue() const { return myInsideSigmaError ; }
81  bool displayResults() const { return myDisplayResults ; }
82 
83  void replaceRegion( int x, int y, int , int ) ;
84  void setPointToSegmentByDiscriminatingAnalyse( int x, int y, int, int ) ;
85  void changeOrder( int newOrder ) ;
86  void increaseOrder( ) { changeOrder(myOrder+1) ; }
87  void decreaseOrder( ) { changeOrder(myOrder-1) ; }
88  void changeFaithInterval( int newFaithInterval ) ;
90  { changeFaithInterval( myFaithInterval+1 ) ; }
92  { changeFaithInterval( myFaithInterval-1 ) ; }
93  void refineModeOn() { myRefineMode = true ; }
94  void refineModeOff() { myRefineMode = false ; }
95  void findNearestMinimumModeOn() { myFindNearestMinimumMode = true ; }
96  void findNearestMinimumModeOff() { myFindNearestMinimumMode = false ; }
98  {
99  myDimensionMode = TWOD ;
100  std::cout << "Dymension Mode set to 2D" << std::endl ;
101  }
103  {
104  myDimensionMode = THREED ;
105  std::cout << "Dymension Mode set to 3D" << std::endl ;
106  }
107 
108  protected:
110 
111  private:
112  AObject * getCurrentImage() ;
113  bool in( const Point3d& dims, Point3d p ) ;
114 
115  struct PointLess : public std::binary_function< Point3d, Point3d , bool>
116  {
117  bool operator () ( const Point3d & p1, const Point3d & p2 ) const
118  {
119  return( p1[2] < p2[2]
120  || ( (p1[2] == p2[2]) && (p1[1] < p2[1]) )
121  || ( (p1[2] == p2[2])
122  && (p1[1] == p2[1]) && (p1[0] < p2[0]) ) ) ;
123  }
124  };
125 
126  bool findLocalBestSeed( const Point3d& dims, const Point3d& halfSize ) ;
127  bool evaluateError( const Point3d& p, const Point3d& halfSize,
128  const Point3d& dims,
129  carto::VolumeRef<float>& errorMatrix,
130  std::vector<float>& meanSignal,
131  float& mean, float& var,
132  bool forceComputing = false ) ;
133  void pcaRegionGrowth( ) ;
134  void growth( std::list< std::pair< Point3d, ChangesItem> >* changes ) ;
135  void refinePCA( std::list< std::pair< Point3d, ChangesItem> >* changes ) ;
136  void computeErrorMatrix( carto::VolumeRef<float>& matriceIndiv,
137  carto::VolumeRef<float>& errorMatrix,
138  std::vector<float>& meanSignal ) ;
139  float error( const anatomist::AObject* data,
140  const Point3df& p, const std::vector<float>& meanSignal,
141  carto::VolumeRef<float>& errorMatrix ) ;
142  bool valid( const anatomist::AObject* data, const Point3df& p ) ;
143  Point3d maskHalfSize( const anatomist::AObject * vol, int nbIndiv ) ;
144 
145  AObject * myCurrentImage ;
146  Point3d mySeed ;
147 /* Point3d myPreviousSeed ; */
148  bool mySeedChanged ;
149  bool myOrderChanged ;
150  bool myRefineMode ;
151  bool myFindNearestMinimumMode ;
152  bool myDisplayResults ;
153  DimensionMode myDimensionMode ;
154  int myFaithInterval ;
155  int myOrder ;
156  carto::VolumeRef<float> myErrorMatrix ;
157  float myInsideMeanError ;
158  float myInsideSigmaError ;
159  std::vector<float> myMeanSignal ;
160  std::map<Point3d, float, PointLess> myPreviousComputing ;
161 
162  Point3d myXAxis ;
163  Point3d myYAxis ;
164  Point3d myZAxis ;
165  } ;
166 } ;
167 
168 inline
169 bool
170 anatomist::RoiDynSegmentAction::valid( const anatomist::AObject* data, const Point3df& p )
171 {
172  std::vector<float> vpos( 4 );
173  vpos[0] = p[0];
174  vpos[1] = p[1];
175  vpos[2] = p[2];
176 
177  for( int t = 0; t <= data->MaxT(); ++t )
178  {
179  vpos[3] = t;
180  if( data->mixedTexValue( vpos ) <= 0. )
181  return false ;
182  }
183  return true ;
184 }
185 
186 inline
187 float
188 anatomist::RoiDynSegmentAction::error( const anatomist::AObject* data,
189  const Point3df& p,
190  const std::vector<float>& meanSignal,
191  carto::VolumeRef<float>& errorMatrix )
192 {
193  carto::VolumeRef<float> indiv( 1, int(data->MaxT()+1.1) ),
194  indivTr( int(data->MaxT()+1.1 ) );
195  float norm2 = 0. ;
196  std::vector<float> vpos( 4 );
197  vpos[0] = p[0];
198  vpos[1] = p[1];
199  vpos[2] = p[2];
200 
201  for ( int t = 0 ; t < data->MaxT()+1 ; ++t )
202  {
203  vpos[3] = t;
204  float dt = data->mixedTexValue( vpos );
205  indiv(0,t) = dt - meanSignal[t];
206  indivTr(t,0) = dt - meanSignal[t];
207  norm2 += dt*dt ;
208  }
209  if( norm2 == 0. )
210  {
211  return 100. ;
212  }
213  return carto::matrix_product(
214  indiv, carto::matrix_product( errorMatrix, indivTr ) )(0,0) / norm2 ;
215 }
216 
217 
218 class RoiDynSegmentActionView : public QWidget, public anatomist::Observer
219 {
220  Q_OBJECT
221 
222 public:
224  QWidget * parent ) ;
226 
227  virtual void update( const anatomist::Observable *, void * ) ;
228 
229 public slots:
230  void faithIntervalChanged( int nSigma ) ;
231  void orderChanged( int order ) ;
232  void dimensionModeChanged( int newDimensionMode ) ;
233  void computeModeChanged( int growthMode ) ;
234  void findNearestMinimumModeChanged( int findLocalMinimum ) ;
235  //void maskChanged( const QString& mask ) ;
236  void refineModeChanged( int mode ) ;
237 private:
238  float myChangingFlag ;
239  float myUpdatingFlag ;
240  anatomist::RoiDynSegmentActionView_Private * _private ;
241 };
242 
243 #endif
#define slots
void faithIntervalChanged(int nSigma)
void computeModeChanged(int growthMode)
void refineModeChanged(int mode)
void orderChanged(int order)
virtual void update(const anatomist::Observable *, void *)
This method is called whenever the observed object is changed.
void findNearestMinimumModeChanged(int findLocalMinimum)
virtual ~RoiDynSegmentActionView()
RoiDynSegmentActionView(anatomist::RoiDynSegmentAction *myAction, QWidget *parent)
void dimensionModeChanged(int newDimensionMode)
Base Anatomist object (abstract)
Definition: Object.h:96
virtual float MaxT() const
Obsolete, deprecated.
virtual float mixedTexValue(const std::vector< float > &pos, const Referential *orgRef) const
Gets a "mixed" texture value at a given space / time location.
This class can be subclassed to represent an object that the programmer wants to have observed.
Definition: Observable.h:68
A class can implement the Observer interface when it wants to be informed of changes in observable ob...
Definition: Observer.h:55
void changeFaithInterval(int newFaithInterval)
void changeOrder(int newOrder)
virtual QWidget * actionView(QWidget *)
void setPointToSegmentByDiscriminatingAnalyse(int x, int y, int, int)
virtual bool viewableAction() const
virtual std::string name() const
virtual void unregisterObservable(anatomist::Observable *)
Called when an observable is destroyed, only called by Observable: don't use this function directly.
void replaceRegion(int x, int y, int, int)
virtual void update(const anatomist::Observable *, void *)
This method is called whenever the observed object is changed.
VolumeRef< T > matrix_product(const Volume< T > &v1, const Volume< T > &v2)
float norm2(const AimsVector< T, D > &v1)