anatomist 6.0.4
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
41namespace anatomist
42{
47 class AGraphIterator;
49 class Fusion2DIterator;
50 class const_Fusion2DIterator;
51 class Fusion3DIterator;
52 class const_Fusion3DIterator;
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
115 {
116 public:
117 AIterator();
118 AIterator( const AIterator & );
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;
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;
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;
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
281
284 virtual AObject* objectAt( const std::vector<float> & pos, float tol = 0 );
285 virtual const AObject* nearestVertex( const std::vector<float> & pos,
286 int *vertex, float *distance,
287 float tol = -1,
288 int *polygon = 0,
289 bool tex_only = false,
290 int target_poly = -1 ) const;
292
293
296
297 virtual std::list<AObject *> renderedSubObjects( const ViewState & ) const;
298 virtual bool render( PrimList &, const ViewState & );
299 virtual bool renderingIsObserverDependent() const;
301 virtual bool Is2DObject();
303 virtual bool Is3DObject();
304 virtual bool isTransparent() const;
306
307
310
313 virtual void update(const Observable* observable, void* arg);
315
316 virtual bool CanRemove( AObject *obj );
317
318
321 virtual void setContentChanged() const;
322 bool hasContentChanged() const;
328 virtual void clearHasChangedFlags() const;
330
331 virtual void SetMaterial( const Material & mat );
332 virtual void setPalette( const AObjectPalette & pal );
335 virtual bool shouldRemoveChildrenWithMe() const;
344 virtual std::list<AObject *> generativeChildren() const;
345
346 protected:
348 virtual void _insertObject( AObject* o );
350 virtual void _eraseObject( AObject* o );
351 virtual void updateSubObjectReferential( const AObject* o );
353
354 mutable bool _contentHasChanged;
355 };
356
357
359 {
360 _contentHasChanged = false;
361 }
362
363
364 inline void MObject::eraseObject( AObject * obj )
365 {
366 iterator i = find( obj );
367 if( i != end() )
368 {
369 erase( i );
370 _contentHasChanged = true;
371 setChanged();
372 }
373 else
374 {
375 std::cout << "unable to erase object " << obj->name()
376 << " from MObject "
377 << name() << " : object not found\n";
378 }
379 }
380
381
382
383 inline bool MObject::CanRemove( AObject * )
384 {
385 // always allowed by default
386 return( true );
387 }
388
389}
390
391
392#endif
Multi-object generic iterator.
Definition MObject.h:115
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
BaseIterator & subIterator()
Definition MObject.h:130
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:97
AObject(const std::string &filename="")
std::string name() const
Name shown in control window.
Definition Object.h:166
Textured surface iterator.
Definition texsurface.h:51
virtual bool operator!=(const BaseIterator &) const
Definition MObject.h:106
virtual AObject * operator*() const =0
virtual ~BaseIterator()
Definition MObject.h:63
virtual BaseIterator & operator++()=0
virtual BaseIterator * clone() const =0
virtual BaseIterator & operator--()=0
bool operator==(const BaseIterator &) const
Definition MObject.h:98
void eraseObject(AObject *obj)
Definition MObject.h:364
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 std::list< AObject * > generativeChildren() const
Children objects which have been used to build the current MObject.
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 iterator end()=0
virtual void insert(AObject *)=0
virtual void updateSubObjectReferential(const AObject *o)
AIterator iterator
Definition MObject.h:238
virtual const AObject * nearestVertex(const std::vector< float > &pos, int *vertex, float *distance, float tol=-1, int *polygon=0, bool tex_only=false, int target_poly=-1) const
Get the nearest vertex to a given position.
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 std::list< AObject * > renderedSubObjects(const ViewState &) const
lis of objects displayed in render() in a default implementation
virtual void clearHasChangedFlags() const
bool _contentHasChanged
Definition MObject.h:354
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 AObject * objectAt(const std::vector< float > &pos, float tol=0)
Find the object (sub-object) at given postion with a tolerence.
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:383
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:56
Textured surface const_iterator.
Definition texsurface.h:75
friend friend class ref
std::list< carto::rc_ptr< GLItem > > PrimList
Definition Object.h:74
ViewState holds information about how a view wants to see an object.
Definition viewstate.h:67