anatomist  5.0.5
3D neuroimaging data viewer
paintaction.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 PAINTACTION_H
36 #define PAINTACTION_H
37 
41 #include <aims/data/data.h>
42 #include <aims/bucket/bucket.h>
46 #include <qobject.h>
47 #include <QWidget>
48 #include <string>
49 #include <vector>
50 #include <stack>
51 
52 class AWindow3D ;
53 class QANumSlider ;
54 
55 namespace anatomist
56 {
57  class AObject ;
58  class Transformation ;
59  class AGraph ;
60  class AGraphObject ;
61 
62  class PaintStrategy ;
63  class PaintAction ;
64  class PaintActionSharedData ;
65  struct PaintActionView_Private ;
66 }
67 
68 
69 class PaintActionView : public QWidget, public anatomist::Observer
70 {
71 
72  Q_OBJECT
73 
74 public:
75  PaintActionView( anatomist::PaintAction *, QWidget * ) ;
76  ~PaintActionView() ;
77 
78  virtual void update( const anatomist::Observable * observable, void * arg ) ;
79 
80 private slots :
81  void brushSelection( int id ) ;
82  void brushSizeChange( int size ) ;
83  void regionTransparencyChange( int alpha ) ;
84  //void transparencyChanged( int alpha ) ;
85  void lineModeOn() ;
86  void lineModeOff() ;
87  void mmModeOn() ;
88  void voxelModeOn() ;
89  void replaceModeOn() ;
90  void replaceModeOff() ;
91  void linkedCursorModeOn() ;
92  void linkedCursorModeOff() ;
93  void undoAction() ;
94  void redoAction() ;
95  void fillAction() ;
96  void clearRegionAction() ;
97 
98 private:
99  bool myUpdatingFlag ;
100  anatomist::PaintActionView_Private * _private ;
101 } ;
102 
103 namespace anatomist {
104 
106  {
107  public:
109  {
110  POINT =0,
112  // CUBE,
114  BALL
115  } ;
116 
117  PaintStrategy( ) ;
118  virtual ~PaintStrategy() ;
119  virtual PaintType paintType() = 0 ;
124  virtual void paint( AWindow3D * win,
125  Transformation * transf, const Point3df& point,
126  const AObject * originalLabel, AObject * finalLabel,
127  float brushSize, bool lineMode,
128  AimsData<AObject*> *volumeOfLabels,
129  const Point3df & vlOffset,
130  aims::BucketMap<Void>::Bucket & deltaModifications,
131  std::list< std::pair< Point3d, ChangesItem> > & changes,
132  const Point3df& voxelSize,
133  bool line,
134  bool replace,
135  bool mm ) = 0 ;
136 
137  static std::list< Point3df > drawLine( const Point3df& from,
138  const Point3df& dep ) ;
139  static std::list< Point3d > drawFastLine( const Point3d& from,
140  const Point3d& dep ) ;
141  void reset() ;
142  bool in( const AimsData<AObject*> *o, Point3df p,
143  const Point3df & offset ) ;
144 
145  private:
146 
147  protected:
150 
151  static void brushPainter( ) ;
152  } ;
153 
154  inline bool
156  const Point3df & offset )
157  {
158  if( !o )
159  return true;
160  p -= offset;
161  if ( p[0] < 0 || p[0] > o->dimX() - 1 ||
162  p[1] < 0 || p[1] > o->dimY() - 1 ||
163  p[2] < 0 || p[2] > o->dimZ() - 1 )
164  return false ;
165 
166  return true ;
167  }
168 
169 
171  {
172  public:
174  virtual ~PointPaintStrategy() ;
175  virtual PaintType paintType() ;
176 
177  virtual void paint( AWindow3D * win,
178  Transformation * transf, const Point3df& point,
179  const AObject * originalLabel, AObject * finalLabel,
180  float brushSize, bool lineMode,
181  AimsData<AObject*> *volumeOfLabels,
182  const Point3df & vlOffset,
183  aims::BucketMap<Void>::Bucket & deltaModifications,
184  std::list< std::pair< Point3d, ChangesItem> > & changes,
185  const Point3df& voxelSize,
186  bool line,
187  bool replace,
188  bool mm ) ;
189 
190  private:
191 
192  } ;
193 
195  public:
197  virtual ~SquarePaintStrategy() ;
198  virtual PaintType paintType() ;
199 
200  virtual void paint( AWindow3D * win,
201  Transformation * transf, const Point3df& point,
202  const AObject * originalLabel, AObject * finalLabel,
203  float brushSize, bool lineMode,
204  AimsData<AObject*> *volumeOfLabels,
205  const Point3df & vlOffset,
206  aims::BucketMap<Void>::Bucket & deltaModifications,
207  std::list< std::pair< Point3d, ChangesItem> > & changes,
208  const Point3df& voxelSize,
209  bool line,
210  bool replace,
211  bool mm ) ;
212 
213 
214  } ;
215 
216  // class CubePaintStrategy : public PaintStrategy {
217  // public:
218  // CubePaintStrategy() ;
219  // virtual ~CubePaintStrategy() ;
220  // virtual PaintType paintType() ;
221 
222  // virtual void paint( AWindow3D * win,
223 // Transformation * transf, const Point3df& point,
224  // const AObject * originalLabel, AObject * finalLabel,
225  // float brushSize, bool lineMode,
226  // AimsData<AObject*>& volumeOfLabels,
227  // Bucket& deltaModifications,
228  // const Point3df& voxelSize,
229  // bool line ) ;
230 
231 
232  // } ;
233 
235  {
236  public:
238  virtual ~DiskPaintStrategy() ;
239  virtual PaintType paintType() ;
240 
241  virtual void paint( AWindow3D * win,
242  Transformation * transf, const Point3df& point,
243  const AObject * originalLabel, AObject * finalLabel,
244  float brushSize, bool lineMode,
245  AimsData<AObject*> *volumeOfLabels,
246  const Point3df & vlOffset,
247  aims::BucketMap<Void>::Bucket & deltaModifications,
248  std::list< std::pair< Point3d, ChangesItem> > & changes,
249  const Point3df& voxelSize,
250  bool line,
251  bool replace,
252  bool mm ) ;
253 
254  virtual void brushPainter( const Point3df& diskCenter,
255  const Point3df& n,
256  const AObject * originalLabel,
257  AObject * finalLabel,
258  float brushSize,
259  AimsData<AObject*> *volumeOfLabels,
260  const Point3df & voxelSize,
261  const Point3df & vlOffset,
262  aims::BucketMap<Void>::Bucket & deltaModifications,
263  std::list< std::pair< Point3d, ChangesItem> > & changes,
264  bool replace,
265  bool mm ) ;
266  private :
267  } ;
268 
270  {
271  public:
273  virtual ~BallPaintStrategy() ;
274  virtual PaintType paintType() ;
275 
276  virtual void paint( AWindow3D * win,
277  Transformation * transf, const Point3df& point,
278  const AObject * originalLabel, AObject * finalLabel,
279  float brushSize, bool lineMode,
280  AimsData<AObject*> *volumeOfLabels,
281  const Point3df & vlOffset,
282  aims::BucketMap<Void>::Bucket & deltaModifications,
283  std::list< std::pair< Point3d, ChangesItem> > & changes,
284  const Point3df& voxelSize,
285  bool line,
286  bool replace,
287  bool mm ) ;
288 
289  virtual void brushPainter( const Point3d& pToInt,
290  const AObject * originalLabel,
291  AObject * finalLabel,
292  float brushSize,
293  AimsData<AObject*> *volumeOfLabels,
294  const Point3df & voxelSize,
295  const Point3df & vlOffset,
296  aims::BucketMap<Void>::Bucket & deltaModifications,
297  std::list< std::pair< Point3d, ChangesItem> > & changes,
298  bool replace,
299  bool mm ) ;
300  private :
301  const std::vector<Point3d>& brush( int size ) ;
302  } ;
303 
304 
306  {
307  public:
308  virtual ~PaintActionSharedData() ;
309  static PaintActionSharedData* instance() ;
310  void noMoreUndoable() ;
311 
312  bool replaceMode() const { return myReplaceMode ; }
313  virtual void update (const Observable *observable, void *arg) ;
314 
315  private:
316  friend class PaintAction ;
317 
319  static PaintActionSharedData * _instance ;
320 
321  // Attributes
322  float myBrushSize ;
323  bool myLineMode ;
324  bool myReplaceMode ;
325  bool myFollowingLinkedCursor ;
326  bool myMmMode ;
327 
328  anatomist::PaintStrategy * myPainter ;
329 
330  bool myIsChangeValidated ;
331  bool myPainting ;
332  bool myValidRegion ;
333 
334  std::list< std::pair< Point3d, ChangesItem> > * myCurrentChanges ;
335 
336  anatomist::Bucket * myDeltaModifications ;
337  anatomist::Bucket * myCurrentModifiedRegion ;
338  anatomist::Bucket * myCursor;
339  Point3df myCursorPos;
340  bool myCursorShapeChanged;
341  Referential *myCursorRef;
342  };
343 
344 
346  {
347  public:
348  PaintAction() ;
349  virtual ~PaintAction() ;
350 
351  virtual std::string name() const;
352 
353  // Action inputs
354  void increaseBrushSize( ) ;
355  void decreaseBrushSize( ) ;
356  void setSize( float i ) ;
357  float brushSize() ;
358  enum PaintStrategy::PaintType paintType() ;
359 
360  void changeRegionTransparency( float alpha ) ;
361  void lineOn() ;
362  void lineOff() ;
363  bool lineMode() { return _sharedData->myLineMode ; }
364 
365  void replaceOn( ) ;
366  void replaceOff( ) ;
367  bool replaceMode() { return _sharedData->myReplaceMode ; }
368 
369  void followingLinkedCursorOn( ) ;
370  void followingLinkedCursorOff( ) ;
371  bool followingLinkedCursorMode() { return _sharedData->myFollowingLinkedCursor ; }
372 
373  void brushToSquare( ) ;
374  void brushToDisk( ) ;
375  void brushToBall( ) ;
376  // Beware, size doesn't matter in this mode.
377  void brushToPoint( ) ;
378  void brushToMm() ;
379  bool mmMode() { return _sharedData->myMmMode ;}
380  void brushToVoxel() ;
381 
382 
383  void paintStart( int x, int y, int globalX, int globalY ) ;
384  void paint( int x, int y, int globalX, int globalY ) ;
385 
386  void eraseStart( int x, int y, int globalX, int globalY ) ;
387  void erase( int x, int y, int globalX, int globalY ) ;
388 
389  void clearRegion() ;
390  void fill( int x, int y, int globalX, int globalY ) ;
391  void fillRegion2D( const Point3d& seed,
392  const Point3d& bmin,
393  const Point3d& bmax,
394  Point3d neighbour[],
395  AimsData<AObject*>& volumeOfLabels,
396  AObject * final,
397  std::list< std::pair< Point3d,
398  ChangesItem> > & changes ) ;
399  void validateChange( int x = 0, int y = 0, int globalX = 0,
400  int globalY = 0 ) ;
401  void undo( ) ;
403  void redo( ) ;
405 
406  void moveCursor( int x, int y, int globalX, int globalY );
407  void updateCursor();
408  void hideCursor();
409 
410  static Action * creator() ;
411 
412  void change( bool forward ) ;
413  virtual QWidget * actionView( QWidget *) ;
414  virtual bool viewableAction( ) const ;
415 /* void refreshWindow() ; */
416 
417  void addObserver (Observer *observer) { _sharedData->addObserver(observer) ; }
418  void deleteObserver (Observer *observer) { _sharedData->deleteObserver(observer) ;}
419  void notifyObservers (void *arg=0) { _sharedData->notifyObservers(arg) ; }
420  void notifyUnregisterObservers () { _sharedData->notifyUnregisterObservers() ; }
421  bool hasChanged () const { return _sharedData->hasChanged() ; }
422  void setChanged () { _sharedData->setChanged() ; }
423  void changeCursor( bool cross) ;
424  void copyPreviousSliceWholeSession( ) ;
425  void copyPreviousSliceCurrentRegion( ) ;
426  void copyNextSliceWholeSession( ) ;
427  void copyNextSliceCurrentRegion( ) ;
428 
429  private:
430  PaintActionSharedData * _sharedData ;
431  std::list<AWindow3D*> myLinkedWindows ;
432 
433  void copySlice( bool wholeSession, int sliceIncrement ) ;
434 
435 // bool getCurrentRegion( ) ;
436 // anatomist::AGraph *getGraph( ) ;
437 // anatomist::AGraphObject * getGraphObject( ) ;
438 // std::set<anatomist::AObject*> selectedObjectsInWindow() ;
439  };
440 }
441 #endif
int dimZ() const
Base Anatomist object (abstract)
Definition: Object.h:95
void deleteObserver(Observer *observer)
Definition: paintaction.h:418
static RoiChangeProcessor * instance()
A class can implement the Observer interface when it wants to be informed of changes in observable ob...
Definition: Observer.h:54
int dimY() const
3D window, OpenGL rendering
Definition: window3D.h:69
This class can be subclassed to represent an object that the programmer wants to have observed...
Definition: Observable.h:67
#define slots
bool followingLinkedCursorMode()
Definition: paintaction.h:371
std::map< Point3d, T, BucketMapLess > Bucket
void addObserver(Observer *observer)
Definition: paintaction.h:417
bool in(const AimsData< AObject *> *o, Point3df p, const Point3df &offset)
Definition: paintaction.h:155
void notifyUnregisterObservers()
Definition: paintaction.h:420
A private class: slider with specific data storage (for callbacks client data), no use for it anywher...
Definition: wMaterial.h:101
bool hasChanged() const
Definition: paintaction.h:421
Referential: marker for transformations, with an associated color.
Definition: Referential.h:54
Transformation between two referentials.
void notifyObservers(void *arg=0)
Definition: paintaction.h:419
Bucket class.
Definition: Bucket.h:55
int dimX() const