anatomist  5.0.5
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 );
254  virtual void setReferentialInheritance( AObject* );
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 
290  virtual bool render( PrimList &, const ViewState & );
291  virtual bool renderingIsObserverDependent() const;
293  virtual bool Is2DObject();
295  virtual bool Is3DObject();
296  virtual bool isTransparent() const;
298 
299 
305  virtual void update(const Observable* observable, void* arg);
307 
308  virtual bool CanRemove( AObject *obj );
309 
310 
313  virtual void setContentChanged() const;
314  bool hasContentChanged() const;
320  virtual void clearHasChangedFlags() const;
322 
323  virtual void SetMaterial( const Material & mat );
324  virtual void setPalette( const AObjectPalette & pal );
327  virtual bool shouldRemoveChildrenWithMe() const;
336  virtual std::list<AObject *> generativeChildren() const;
337 
338  protected:
340  virtual void _insertObject( AObject* o );
342  virtual void _eraseObject( AObject* o );
343  virtual void updateSubObjectReferential( const AObject* o );
344  virtual void clearReferentialInheritance();
345 
346  mutable bool _contentHasChanged;
347  };
348 
349 
351  {
352  _contentHasChanged = false;
353  }
354 
355 
356  inline void MObject::eraseObject( AObject * obj )
357  {
358  iterator i = find( obj );
359  if( i != end() )
360  {
361  erase( i );
362  _contentHasChanged = true;
363  setChanged();
364  }
365  else
366  {
367  std::cout << "unable to erase object " << obj->name()
368  << " from MObject "
369  << name() << " : object not found\n";
370  }
371  }
372 
373 
374 
375  inline bool MObject::CanRemove( AObject * )
376  {
377  // always allowed by default
378  return( true );
379  }
380 
381 }
382 
383 
384 #endif
virtual AObject * operator*() const =0
virtual bool operator!=(const BaseIterator &) const
Definition: MObject.h:106
ViewState holds information about how a view wants to see an object.
Definition: viewstate.h:66
Base Anatomist object (abstract)
Definition: Object.h:95
Multi-object generic iterator.
Definition: MObject.h:114
virtual iterator end()=0
std::list< carto::rc_ptr< GLItem > > PrimList
Definition: Object.h:72
BaseIterator * _iterator
Underlying specific iterator.
Definition: MObject.h:137
Multi-object : base abstract class for objects that contain others.
Definition: MObject.h:234
void datatype
Data storage type, to be redefined by children classes.
Definition: MObject.h:133
This class can be subclassed to represent an object that the programmer wants to have observed...
Definition: Observable.h:67
void eraseObject(AObject *obj)
Definition: MObject.h:356
std::string name() const
Name shown in control window.
Definition: Object.h:165
This class has to be rewritten, it&#39;s really really a shame.......
Definition: Material.h:47
virtual bool CanRemove(AObject *obj)
Definition: MObject.h:375
AIterator & operator++()
Definition: MObject.h:191
virtual BaseIterator & operator--()=0
virtual const_iterator find(const AObject *) const =0
AIterator const_iterator
Definition: MObject.h:239
Textured surface iterator.
Definition: texsurface.h:50
Textured surface const_iterator.
Definition: texsurface.h:74
void setChanged() const
Indicates that this object has changed.
Definition: Observable.h:184
bool operator==(const AIterator &) const
Definition: MObject.h:176
bool operator==(const BaseIterator &) const
Definition: MObject.h:98
virtual void erase(iterator &)=0
AIterator & operator--()
Definition: MObject.h:209
AIterator iterator
Definition: MObject.h:238
virtual BaseIterator & operator++()=0
int isMultiObject() const
maybe not necessary ?: we can use dynamic_cast instead
Definition: MObject.h:249
Referential: marker for transformations, with an associated color.
Definition: Referential.h:54
bool operator!=(const AIterator &) const
Definition: MObject.h:184
virtual ~BaseIterator()
Definition: MObject.h:63
bool _contentHasChanged
Definition: MObject.h:346
virtual BaseIterator * clone() const =0
AIterator & operator=(const AIterator &)
Definition: MObject.h:166
BaseIterator & subIterator()
Definition: MObject.h:130
AObject * operator*() const
Definition: MObject.h:226
reference_wrapper< T > ref(T &ref)