anatomist  5.1.2
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 
44 #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:
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 
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  carto::VolumeRef<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 carto::VolumeRef<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.get() )
159  return true;
160  p -= offset;
161  if ( p[0] < 0 || p[0] > o->getSizeX() - 1 ||
162  p[1] < 0 || p[1] > o->getSizeY() - 1 ||
163  p[2] < 0 || p[2] > o->getSizeZ() - 1 )
164  return false ;
165 
166  return true ;
167  }
168 
169 
171  {
172  public:
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  carto::VolumeRef<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:
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  carto::VolumeRef<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 
218  {
219  public:
221  virtual ~DiskPaintStrategy() ;
222  virtual PaintType paintType() ;
223 
224  virtual void paint( AWindow3D * win,
225  Transformation * transf, const Point3df& point,
226  const AObject * originalLabel, AObject * finalLabel,
227  float brushSize, bool lineMode,
228  carto::VolumeRef<AObject*> & volumeOfLabels,
229  const Point3df & vlOffset,
230  aims::BucketMap<Void>::Bucket & deltaModifications,
231  std::list< std::pair< Point3d, ChangesItem> > & changes,
232  const Point3df& voxelSize,
233  bool line,
234  bool replace,
235  bool mm ) ;
236 
237  virtual void brushPainter( const Point3df& diskCenter,
238  const Point3df& n,
239  const AObject * originalLabel,
240  AObject * finalLabel,
241  float brushSize,
242  carto::VolumeRef<AObject*> & volumeOfLabels,
243  const Point3df & voxelSize,
244  const Point3df & vlOffset,
245  aims::BucketMap<Void>::Bucket & deltaModifications,
246  std::list< std::pair< Point3d, ChangesItem> > & changes,
247  bool replace,
248  bool mm ) ;
249  private :
250  } ;
251 
253  {
254  public:
256  virtual ~BallPaintStrategy() ;
257  virtual PaintType paintType() ;
258 
259  virtual void paint( AWindow3D * win,
260  Transformation * transf, const Point3df& point,
261  const AObject * originalLabel, AObject * finalLabel,
262  float brushSize, bool lineMode,
263  carto::VolumeRef<AObject*> & volumeOfLabels,
264  const Point3df & vlOffset,
265  aims::BucketMap<Void>::Bucket & deltaModifications,
266  std::list< std::pair< Point3d, ChangesItem> > & changes,
267  const Point3df& voxelSize,
268  bool line,
269  bool replace,
270  bool mm ) ;
271 
272  virtual void brushPainter( const Point3d& pToInt,
273  const AObject * originalLabel,
274  AObject * finalLabel,
275  float brushSize,
276  carto::VolumeRef<AObject*> & volumeOfLabels,
277  const Point3df & voxelSize,
278  const Point3df & vlOffset,
279  aims::BucketMap<Void>::Bucket & deltaModifications,
280  std::list< std::pair< Point3d, ChangesItem> > & changes,
281  bool replace,
282  bool mm ) ;
283  private :
284  const std::vector<Point3d>& brush( int size ) ;
285  } ;
286 
287 
289  {
290  public:
293  void noMoreUndoable() ;
294 
295  bool replaceMode() const { return myReplaceMode ; }
296  virtual void update (const Observable *observable, void *arg) ;
297 
298  private:
299  friend class PaintAction ;
300 
302  static PaintActionSharedData * _instance ;
303 
304  // Attributes
305  float myBrushSize ;
306  bool myLineMode ;
307  bool myReplaceMode ;
308  bool myFollowingLinkedCursor ;
309  bool myMmMode ;
310 
311  anatomist::PaintStrategy * myPainter ;
312 
313  bool myIsChangeValidated ;
314  bool myPainting ;
315  bool myValidRegion ;
316 
317  std::list< std::pair< Point3d, ChangesItem> > * myCurrentChanges ;
318 
319  anatomist::Bucket * myDeltaModifications ;
320  anatomist::Bucket * myCurrentModifiedRegion ;
321  anatomist::Bucket * myCursor;
322  Point3df myCursorPos;
323  bool myCursorShapeChanged;
324  Referential *myCursorRef;
325  };
326 
327 
329  {
330  public:
332  virtual ~PaintAction() ;
333 
334  virtual std::string name() const;
335 
336  // Action inputs
339  void setSize( float i ) ;
340  float brushSize() ;
342 
343  void changeRegionTransparency( float alpha ) ;
344  void lineOn() ;
345  void lineOff() ;
346  bool lineMode() { return _sharedData->myLineMode ; }
347 
348  void replaceOn( ) ;
349  void replaceOff( ) ;
350  bool replaceMode() { return _sharedData->myReplaceMode ; }
351 
354  bool followingLinkedCursorMode() { return _sharedData->myFollowingLinkedCursor ; }
355 
356  void brushToSquare( ) ;
357  void brushToDisk( ) ;
358  void brushToBall( ) ;
359  // Beware, size doesn't matter in this mode.
360  void brushToPoint( ) ;
361  void brushToMm() ;
362  bool mmMode() { return _sharedData->myMmMode ;}
363  void brushToVoxel() ;
364 
365 
366  void paintStart( int x, int y, int globalX, int globalY ) ;
367  void paint( int x, int y, int globalX, int globalY ) ;
368 
369  void eraseStart( int x, int y, int globalX, int globalY ) ;
370  void erase( int x, int y, int globalX, int globalY ) ;
371 
372  void clearRegion() ;
373  void fill( int x, int y, int globalX, int globalY ) ;
374  void fillRegion2D( const Point3d& seed,
375  const Point3d& bmin,
376  const Point3d& bmax,
377  Point3d neighbour[],
378  carto::VolumeRef<AObject*>& volumeOfLabels,
379  AObject * final,
380  std::list< std::pair< Point3d,
381  ChangesItem> > & changes ) ;
382  void validateChange( int x = 0, int y = 0, int globalX = 0,
383  int globalY = 0 ) ;
384  void undo( ) ;
386  void redo( ) ;
388 
389  void moveCursor( int x, int y, int globalX, int globalY );
390  void updateCursor();
391  void hideCursor();
392 
393  static Action * creator() ;
394 
395  void change( bool forward ) ;
396  virtual QWidget * actionView( QWidget *) ;
397  virtual bool viewableAction( ) const ;
398 /* void refreshWindow() ; */
399 
400  void addObserver (Observer *observer) { _sharedData->addObserver(observer) ; }
401  void deleteObserver (Observer *observer) { _sharedData->deleteObserver(observer) ;}
402  void notifyObservers (void *arg=0) { _sharedData->notifyObservers(arg) ; }
404  bool hasChanged () const { return _sharedData->hasChanged() ; }
405  void setChanged () { _sharedData->setChanged() ; }
406  void changeCursor( bool cross) ;
411 
412  private:
413  PaintActionSharedData * _sharedData ;
414  std::list<AWindow3D*> myLinkedWindows ;
415 
416  void copySlice( bool wholeSession, int sliceIncrement ) ;
417 
418 // bool getCurrentRegion( ) ;
419 // anatomist::AGraph *getGraph( ) ;
420 // anatomist::AGraphObject * getGraphObject( ) ;
421 // std::set<anatomist::AObject*> selectedObjectsInWindow() ;
422  };
423 }
424 #endif
#define slots
3D window, OpenGL rendering
Definition: window3D.h:74
PaintActionView(anatomist::PaintAction *, QWidget *)
virtual void update(const anatomist::Observable *observable, void *arg)
This method is called whenever the observed object is changed.
A private class: slider with specific data storage (for callbacks client data), no use for it anywher...
Definition: wMaterial.h:102
std::map< Point3d, T, BucketMapLess > Bucket
Base Anatomist object (abstract)
Definition: Object.h:96
virtual void brushPainter(const Point3d &pToInt, const AObject *originalLabel, AObject *finalLabel, float brushSize, carto::VolumeRef< AObject * > &volumeOfLabels, const Point3df &voxelSize, const Point3df &vlOffset, aims::BucketMap< Void >::Bucket &deltaModifications, std::list< std::pair< Point3d, ChangesItem > > &changes, bool replace, bool mm)
virtual void paint(AWindow3D *win, Transformation *transf, const Point3df &point, const AObject *originalLabel, AObject *finalLabel, float brushSize, bool lineMode, carto::VolumeRef< AObject * > &volumeOfLabels, const Point3df &vlOffset, aims::BucketMap< Void >::Bucket &deltaModifications, std::list< std::pair< Point3d, ChangesItem > > &changes, const Point3df &voxelSize, bool line, bool replace, bool mm)
Draw.
virtual PaintType paintType()
Bucket class.
Definition: Bucket.h:56
virtual void brushPainter(const Point3df &diskCenter, const Point3df &n, const AObject *originalLabel, AObject *finalLabel, float brushSize, carto::VolumeRef< AObject * > &volumeOfLabels, const Point3df &voxelSize, const Point3df &vlOffset, aims::BucketMap< Void >::Bucket &deltaModifications, std::list< std::pair< Point3d, ChangesItem > > &changes, bool replace, bool mm)
virtual PaintType paintType()
virtual void paint(AWindow3D *win, Transformation *transf, const Point3df &point, const AObject *originalLabel, AObject *finalLabel, float brushSize, bool lineMode, carto::VolumeRef< AObject * > &volumeOfLabels, const Point3df &vlOffset, aims::BucketMap< Void >::Bucket &deltaModifications, std::list< std::pair< Point3d, ChangesItem > > &changes, const Point3df &voxelSize, bool line, bool replace, bool mm)
Draw.
This class can be subclassed to represent an object that the programmer wants to have observed.
Definition: Observable.h:68
void addObserver(Observer *observer)
Adds an observer to the set of observers for this object.
void setChanged() const
Indicates that this object has changed.
Definition: Observable.h:184
bool hasChanged() const
Tests if this object has changed.
Definition: Observable.h:176
virtual void notifyUnregisterObservers()
Notifies observable destruction to all observers and unregisters them.
void deleteObserver(Observer *observer)
Deletes an observer from the set of observers of this object.
virtual void notifyObservers(void *arg=0)
If this object has changed, as indicated by the hasChanged method, then notify all of its observers.
A class can implement the Observer interface when it wants to be informed of changes in observable ob...
Definition: Observer.h:55
virtual void update(const Observable *observable, void *arg)
This method is called whenever the observed object is changed.
static PaintActionSharedData * instance()
void fillRegion2D(const Point3d &seed, const Point3d &bmin, const Point3d &bmax, Point3d neighbour[], carto::VolumeRef< AObject * > &volumeOfLabels, AObject *final, std::list< std::pair< Point3d, ChangesItem > > &changes)
void copyPreviousSliceCurrentRegion()
void notifyUnregisterObservers()
Definition: paintaction.h:403
enum PaintStrategy::PaintType paintType()
void moveCursor(int x, int y, int globalX, int globalY)
void notifyObservers(void *arg=0)
Definition: paintaction.h:402
virtual QWidget * actionView(QWidget *)
void copyPreviousSliceWholeSession()
virtual bool viewableAction() const
void eraseStart(int x, int y, int globalX, int globalY)
void addObserver(Observer *observer)
Definition: paintaction.h:400
void change(bool forward)
void fill(int x, int y, int globalX, int globalY)
static Action * creator()
bool hasChanged() const
Definition: paintaction.h:404
bool followingLinkedCursorMode()
Definition: paintaction.h:354
void erase(int x, int y, int globalX, int globalY)
void deleteObserver(Observer *observer)
Definition: paintaction.h:401
void changeCursor(bool cross)
void paint(int x, int y, int globalX, int globalY)
void changeRegionTransparency(float alpha)
void setSize(float i)
void paintStart(int x, int y, int globalX, int globalY)
void validateChange(int x=0, int y=0, int globalX=0, int globalY=0)
virtual std::string name() const
bool in(const carto::VolumeRef< AObject * > &o, Point3df p, const Point3df &offset)
Definition: paintaction.h:155
static std::list< Point3d > drawFastLine(const Point3d &from, const Point3d &dep)
virtual PaintType paintType()=0
static std::list< Point3df > drawLine(const Point3df &from, const Point3df &dep)
static void brushPainter()
virtual void paint(AWindow3D *win, Transformation *transf, const Point3df &point, const AObject *originalLabel, AObject *finalLabel, float brushSize, bool lineMode, carto::VolumeRef< AObject * > &volumeOfLabels, const Point3df &vlOffset, aims::BucketMap< Void >::Bucket &deltaModifications, std::list< std::pair< Point3d, ChangesItem > > &changes, const Point3df &voxelSize, bool line, bool replace, bool mm)=0
Draw.
virtual PaintType paintType()
virtual void paint(AWindow3D *win, Transformation *transf, const Point3df &point, const AObject *originalLabel, AObject *finalLabel, float brushSize, bool lineMode, carto::VolumeRef< AObject * > &volumeOfLabels, const Point3df &vlOffset, aims::BucketMap< Void >::Bucket &deltaModifications, std::list< std::pair< Point3d, ChangesItem > > &changes, const Point3df &voxelSize, bool line, bool replace, bool mm)
Draw.
Referential: marker for transformations, with an associated color.
Definition: Referential.h:55
static RoiChangeProcessor * instance()
virtual PaintType paintType()
virtual void paint(AWindow3D *win, Transformation *transf, const Point3df &point, const AObject *originalLabel, AObject *finalLabel, float brushSize, bool lineMode, carto::VolumeRef< AObject * > &volumeOfLabels, const Point3df &vlOffset, aims::BucketMap< Void >::Bucket &deltaModifications, std::list< std::pair< Point3d, ChangesItem > > &changes, const Point3df &voxelSize, bool line, bool replace, bool mm)
Draw.
Transformation between two referentials.
int getSizeZ() const
int getSizeY() const
int getSizeX() const
T * get() const