anatomist  5.1.2
3D neuroimaging data viewer
MObject.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 ANA_MOBJECT_MOBJECT_H
36 #define ANA_MOBJECT_MOBJECT_H
37 
39 
40 
41 namespace anatomist
42 {
43  class ObjectListIterator;
44  class const_ObjectListIterator;
45  class ObjectVectorIterator;
46  class const_ObjectVectorIterator;
47  class AGraphIterator;
48  class const_AGraphIterator;
49  class Fusion2DIterator;
50  class const_Fusion2DIterator;
51  class Fusion3DIterator;
52  class const_Fusion3DIterator;
53  class ATexSurfaceIterator;
54  class const_ATexSurfaceIterator;
55  class Referential;
56  class Geometry;
57 
61  {
62  public:
63  virtual ~BaseIterator() {}
64  virtual BaseIterator* clone() const = 0;
65  bool operator == ( const BaseIterator & ) const;
66  virtual bool operator != ( const BaseIterator & ) const;
67  virtual bool operator != ( const ObjectListIterator & ) const
68  { return( true ); }
69  virtual bool operator != ( const const_ObjectListIterator & ) const
70  { return( true ); }
71  virtual bool operator != ( const ObjectVectorIterator & ) const
72  { return( true ); }
73  virtual bool operator != ( const const_ObjectVectorIterator & ) const
74  { return( true ); }
75  virtual bool operator != ( const AGraphIterator & ) const
76  { return( true ); }
77  virtual bool operator != ( const const_AGraphIterator & ) const
78  { return( true ); }
79  virtual bool operator != ( const Fusion2DIterator & ) const
80  { return( true ); }
81  virtual bool operator != ( const const_Fusion2DIterator & ) const
82  { return( true ); }
83  virtual bool operator != ( const Fusion3DIterator & ) const
84  { return( true ); }
85  virtual bool operator != ( const const_Fusion3DIterator & ) const
86  { return( true ); }
87  virtual bool operator != ( const ATexSurfaceIterator & ) const
88  { return( true ); }
89  virtual bool operator != ( const const_ATexSurfaceIterator & ) const
90  { return( true ); }
91  virtual AObject* operator * () const = 0;
92  virtual BaseIterator & operator ++ () = 0;
93  virtual BaseIterator & operator -- () = 0;
94  };
95 
96 
97  inline bool BaseIterator::operator ==
98  ( const BaseIterator & x ) const
99  {
100  //cout << "BaseIterator::operator == ( const BaseIterator & x )\n";
101  return( ! (operator != (x)) );
102  }
103 
104 
105  inline bool BaseIterator::operator !=
106  ( const BaseIterator & i ) const
107  {
108  return( i.operator != ( *this ) );
109  }
110 
111 
114  class AIterator
115  {
116  public:
117  AIterator();
118  AIterator( const AIterator & );
119  AIterator( BaseIterator * );
120  ~AIterator();
121 
122  AIterator & operator = ( const AIterator & );
123  bool operator == (const AIterator & ) const;
124  bool operator != ( const AIterator & ) const;
126  AIterator operator ++ ( int );
128  AIterator operator -- ( int );
129  AObject *operator *() const;
130  BaseIterator & subIterator() { return( *_iterator ); }
131 
133  typedef void datatype;
134 
135  protected:
138  };
139 
140 
142  : _iterator( 0 )
143  {
144  }
145 
146 
147  inline AIterator::AIterator( const AIterator & x )
148  : _iterator( x._iterator->clone() )
149  {
150  }
151 
152 
154  : _iterator( i )
155  {
156  }
157 
158 
160  {
161  if( _iterator ) delete _iterator;
162  }
163 
164 
165  inline AIterator &
167  {
168  if( this == &i ) return( *this );
169  if( _iterator ) delete _iterator;
170  _iterator = i._iterator->clone();
171  return( *this );
172  }
173 
174 
175  inline bool
177  {
178  //cout << "AIterator::operator ==\n";
179  return( *_iterator == *i._iterator );
180  }
181 
182 
183  inline bool
185  {
186  return( *_iterator != *i._iterator );
187  }
188 
189 
190  inline AIterator &
192  {
193  ++ *_iterator;
194  return( *this );
195  }
196 
197 
198  inline AIterator
200  {
201  AIterator tmp = _iterator->clone();
202 
203  ++ *_iterator;
204  return( tmp );
205  }
206 
207 
208  inline AIterator &
210  {
211  -- *_iterator;
212  return( *this );
213  }
214 
215 
216  inline AIterator
218  {
219  AIterator tmp = _iterator->clone();
220 
221  -- *_iterator;
222  return( tmp );
223  }
224 
225 
227  {
228  return( **_iterator );
229  }
230 
231 
234  class MObject : public AObject
235  {
236  public:
237 
240 
241  MObject();
242  virtual ~MObject();
243 
244  virtual const MObject* mObjectAPI() const;
245  virtual MObject* mObjectAPI();
246 
249  int isMultiObject() const { return( true ); }
251  virtual int MType() const = 0;
253  virtual void setReferential( Referential* ref );
255 
258  virtual size_t size() const = 0;
259  virtual iterator begin() = 0;
260  virtual const_iterator begin() const = 0;
261  virtual iterator end() = 0;
262  virtual const_iterator end() const = 0;
263  virtual void insert( AObject * ) = 0;
264  virtual const_iterator find( const AObject * ) const = 0;
265  virtual void erase( iterator & ) = 0;
266  void eraseObject( AObject *obj );
268 
269  virtual float MinT() const;
270  virtual float MaxT() const;
271 
272  virtual bool boundingBox2D( std::vector<float> & bmin,
273  std::vector<float> & bmax ) const;
274 
275  virtual std::vector<float> voxelSize() const;
276  virtual bool boundingBox( std::vector<float> & bmin,
277  std::vector<float> & bmax ) const;
278 
284  virtual AObject* objectAt( const std::vector<float> & pos, float tol = 0 );
286 
287 
291  virtual std::list<AObject *> renderedSubObjects( const ViewState & ) const;
292  virtual bool render( PrimList &, const ViewState & );
293  virtual bool renderingIsObserverDependent() const;
295  virtual bool Is2DObject();
297  virtual bool Is3DObject();
298  virtual bool isTransparent() const;
300 
301 
307  virtual void update(const Observable* observable, void* arg);
309 
310  virtual bool CanRemove( AObject *obj );
311 
312 
315  virtual void setContentChanged() const;
316  bool hasContentChanged() const;
322  virtual void clearHasChangedFlags() const;
324 
325  virtual void SetMaterial( const Material & mat );
326  virtual void setPalette( const AObjectPalette & pal );
329  virtual bool shouldRemoveChildrenWithMe() const;
338  virtual std::list<AObject *> generativeChildren() const;
339 
340  protected:
342  virtual void _insertObject( AObject* o );
344  virtual void _eraseObject( AObject* o );
345  virtual void updateSubObjectReferential( const AObject* o );
347 
348  mutable bool _contentHasChanged;
349  };
350 
351 
353  {
354  _contentHasChanged = false;
355  }
356 
357 
358  inline void MObject::eraseObject( AObject * obj )
359  {
360  iterator i = find( obj );
361  if( i != end() )
362  {
363  erase( i );
364  _contentHasChanged = true;
365  setChanged();
366  }
367  else
368  {
369  std::cout << "unable to erase object " << obj->name()
370  << " from MObject "
371  << name() << " : object not found\n";
372  }
373  }
374 
375 
376 
377  inline bool MObject::CanRemove( AObject * )
378  {
379  // always allowed by default
380  return( true );
381  }
382 
383 }
384 
385 
386 #endif
Multi-object generic iterator.
Definition: MObject.h:115
BaseIterator & subIterator()
Definition: MObject.h:130
void datatype
Data storage type, to be redefined by children classes.
Definition: MObject.h:133
AIterator & operator++()
Definition: MObject.h:191
AObject * operator*() const
Definition: MObject.h:226
AIterator & operator--()
Definition: MObject.h:209
AIterator & operator=(const AIterator &)
Definition: MObject.h:166
bool operator!=(const AIterator &) const
Definition: MObject.h:184
bool operator==(const AIterator &) const
Definition: MObject.h:176
BaseIterator * _iterator
Underlying specific iterator.
Definition: MObject.h:137
Base Anatomist object (abstract)
Definition: Object.h:96
std::string name() const
Name shown in control window.
Definition: Object.h:165
Textured surface iterator.
Definition: texsurface.h:51
virtual BaseIterator & operator--()=0
virtual bool operator!=(const BaseIterator &) const
Definition: MObject.h:106
virtual ~BaseIterator()
Definition: MObject.h:63
virtual BaseIterator & operator++()=0
virtual AObject * operator*() const =0
virtual BaseIterator * clone() const =0
bool operator==(const BaseIterator &) const
Definition: MObject.h:98
Multi-object : base abstract class for objects that contain others.
Definition: MObject.h:235
void eraseObject(AObject *obj)
Definition: MObject.h:358
AIterator const_iterator
Definition: MObject.h:239
virtual bool isTransparent() const
virtual void SetMaterial(const Material &mat)
virtual std::vector< float > voxelSize() const
Returns at least 4 sizes. For 3D objects, returns (1, 1, 1, 1)
virtual const MObject * mObjectAPI() const
virtual iterator begin()=0
virtual AObject * objectAt(const std::vector< float > &pos, float tol=0)
Find the object (sub-object) at given postion with a tolerence.
virtual void setReferential(Referential *ref)
virtual void update(const Observable *observable, void *arg)
This class is an Observer of each of the AObject it groups.
virtual bool Is3DObject()
Can be display in 3D windows.
virtual bool Is2DObject()
Can be display in 2D windows.
virtual std::list< AObject * > generativeChildren() const
Children objects which have been used to build the current MObject.
virtual iterator end()=0
virtual void insert(AObject *)=0
virtual void updateSubObjectReferential(const AObject *o)
AIterator iterator
Definition: MObject.h:238
virtual int MType() const =0
Precise type of multi-object.
int isMultiObject() const
maybe not necessary ?: we can use dynamic_cast instead
Definition: MObject.h:249
virtual void _eraseObject(AObject *o)
must be called by all subclasses if they reimplement erase()
virtual const_iterator find(const AObject *) const =0
bool hasContentChanged() const
virtual bool boundingBox(std::vector< float > &bmin, std::vector< float > &bmax) const
Fills bmin and bmax with the N-D bounding box extrema in the object's referential coordinates.
virtual bool renderingIsObserverDependent() const
true only if the rendering (openGL) of the object changes with the observer position/orientation of t...
virtual MObject * mObjectAPI()
virtual void setContentChanged() const
virtual void clearReferentialInheritance()
sets the object to get referential from to null, unregister it
virtual float MaxT() const
Obsolete, deprecated.
virtual void clearHasChangedFlags() const
bool _contentHasChanged
Definition: MObject.h:348
virtual bool boundingBox2D(std::vector< float > &bmin, std::vector< float > &bmax) const
Bounding box in 2D views mode.
virtual size_t size() const =0
virtual const_iterator begin() const =0
virtual void _insertObject(AObject *o)
must be called by all subclasses in their insert() implementation
virtual bool render(PrimList &, const ViewState &)
rendering (generally 2D or 3D using OpenGL).
virtual void setReferentialInheritance(AObject *)
virtual bool shouldRemoveChildrenWithMe() const
tells whether children objects should be removed from views when this MObject is removed from a view.
virtual bool CanRemove(AObject *obj)
Definition: MObject.h:377
virtual std::list< AObject * > renderedSubObjects(const ViewState &) const
lis of objects displayed in render() in a default implementation
virtual const_iterator end() const =0
virtual float MinT() const
Obsolete, deprecated.
virtual void erase(iterator &)=0
virtual void setPalette(const AObjectPalette &pal)
This class has to be rewritten, it's really really a shame.......
Definition: Material.h:48
This class can be subclassed to represent an object that the programmer wants to have observed.
Definition: Observable.h:68
void setChanged() const
Indicates that this object has changed.
Definition: Observable.h:184
Referential: marker for transformations, with an associated color.
Definition: Referential.h:55
Textured surface const_iterator.
Definition: texsurface.h:75
friend friend class ref
std::list< carto::rc_ptr< GLItem > > PrimList
Definition: Object.h:72
ViewState holds information about how a view wants to see an object.
Definition: viewstate.h:67