anatomist 6.0.4
3D neuroimaging data viewer
Object.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_OBJECT_OBJECT_H
36#define ANA_OBJECT_OBJECT_H
37
43#include <cartodata/volume/volume.h>
44#include <cartobase/smart/rcptr.h>
45#include <cartobase/object/object.h>
46#include <aims/vector/vector.h>
47
48#include <string>
49#include <list>
50#include <set>
51#include <map>
52#include <vector>
53
54
55class ColorMap;
56class Tree;
57
58namespace aims
59{
60 class Quaternion;
61}
62
63namespace anatomist
64{
65
66 class AWindow;
67 class Referential;
68 class Geometry;
69 class AObjectPalette;
70 class MObject;
71 class GLItem;
72 class GLComponent;
73 struct ViewState;
74 typedef std::list<carto::rc_ptr<GLItem> > PrimList;
76
77
78 struct AImage
79 {
80 int width;
81 int height;
82 int depth;
85 char *data;
86 };
87
88 /*
89 TODO:
90 remove:
91 MinT(), MaxT()
92 */
93
97 {
98 public:
100 typedef std::set<MObject*> ParentList;
101
133
135 typedef ObjectMenu* (*ObjectMenuRegistrerFunction)
136 ( const AObject* objtype, ObjectMenu* menu );
137
138 AObject( const std::string & filename = "" );
140 virtual ~AObject();
141
148 virtual AObject* clone( bool shallow = true );
149
151 virtual const GLComponent* glAPI() const { return 0; }
153 virtual GLComponent* glAPI() { return 0; }
154 virtual const MObject* mObjectAPI() const { return 0; }
155 virtual MObject* mObjectAPI() { return 0; }
156
159 int type() const { return( _type ); }
162 void setType(int type) { _type = type; };
164 int id() const { return( _id ); }
166 std::string name() const { return( _name ); }
168 std::string fileName() const { return( _filename ); }
169 void setName( const std::string & n );
170 void setFileName( const std::string & filename );
171 void setId( int id );
173 virtual int isMultiObject() const { return( false ); }
174
176 virtual float MinT() const;
178 virtual float MaxT() const;
179
187 virtual bool boundingBox2D( std::vector<float> & bmin,
188 std::vector<float> & bmax ) const;
189
204 virtual bool boundingBox( std::vector<float> & bmin,
205 std::vector<float> & bmax ) const;
206
211 virtual bool render( PrimList &, const ViewState & );
213 virtual std::vector<float> voxelSize() const;
214 virtual void setVoxelSize( const std::vector<float> & ) {}
218 virtual void internalUpdate();
219
222 virtual void adjustPalette();
225 virtual AObjectPalette* palette() { return( _palette ); }
226 virtual const AObjectPalette* palette() const { return( _palette ); }
227 virtual void setPalette( const AObjectPalette & palette );
229 virtual const AObjectPalette* getOrCreatePalette() const;
232 virtual void createDefaultPalette( const std::string & name = "" );
233
234 virtual void SetMaterial( const Material & mat );
235 virtual Material & GetMaterial() { return _material; }
236 virtual const Material & material() const
237 { return const_cast<AObject *>(this)->GetMaterial(); }
238
252
254 virtual Tree* optionTree() const;
255 virtual ObjectMenu* optionMenu() const;
257 int InMemory() const { return _inMemory; }
259 int Visible() const { return _visible; }
260 void SetVisibility( int v ) { _visible = v; }
266 const ParentList & parents() const { return _parents; }
267 virtual void RegisterParent( MObject *pob ) { _parents.insert( pob ); }
268 virtual void UnregisterParent( MObject *pob ) { _parents.erase( pob ); }
270 const std::set<AWindow*> & WinList() { return _winList; }
271 virtual void registerWindow(AWindow* window);
272 virtual void unregisterWindow(AWindow* window);
273 virtual bool Is2DObject() = 0;
274 virtual bool Is3DObject() = 0;
275 virtual bool IsFusion2DAllowed();
277 virtual bool textured2D() const { return false; }
278 virtual bool isTransparent() const;
283 virtual bool renderingIsObserverDependent() const;
287 virtual int CanBeDestroyed();
288
289 virtual void setReferenceChanged();
293 virtual void setInternalsChanged();
300 virtual void clearHasChangedFlags() const;
301
303 bool userModified() const;
305 void setUserModified( bool state = true );
306
310 virtual AObject* objectAt( const std::vector<float> & pos, float tol = 0 );
313 virtual AObject* objectAt( const std::vector<float> & pos,
314 float tol, const Referential* orgref,
315 const Point3df & orggeom );
336 virtual const AObject* nearestVertex( const std::vector<float> & pos,
337 int *vertex, float *distance,
338 float tol = -1,
339 int *polygon = 0,
340 bool tex_only = false,
341 int target_poly = -1 ) const;
342
344 virtual void setGeomExtrema() {}
346 virtual void SetExtrema() {}
348 virtual bool hasTexture() const { return( false ); }
350 virtual unsigned dimTexture() const { return( 1 ); }
362 virtual float mixedTexValue( const std::vector<float> & pos,
363 const Referential* orgRef,
364 int poly = -1 ) const;
367 virtual float mixedTexValue( const std::vector<float> & pos,
368 int poly = -1 ) const;
385 virtual std::vector<float> texValues( const std::vector<float> & pos,
386 const Referential* orgRef,
387 int poly = -1 ) const;
388 virtual std::vector<float>
389 texValues( const std::vector<float> & pos, int poly = -1 ) const;
391 const std::vector<float> & pos, int axis, const Referential* orgRef,
392 int poly = -1 ) const;
394 const std::vector<float> & pos, int axis, int poly = -1 ) const;
395 virtual void
396 getTextureLabels( const std::vector<float> & texvalues,
397 std::vector<std::string> & texlabels,
398 std::string & textype ) const;
399
400 virtual bool loadable() const { return false; }
401 virtual bool savable() const { return false; }
412 virtual bool reload( const std::string & filename );
413
419 virtual std::string objectFullTypeName(void) const
420 { return objectTypeName(_type); };
424 bool save( const std::string & filename, bool onlyIfModified );
426 virtual bool save( const std::string & filename );
428 virtual bool printTalairachCoord( const Point3df &,
429 const Referential* ) const
430 { return( false ); }
431
435 virtual void setProperties( carto::Object options );
442 virtual void storeHeaderOptions();
447 long loadDate() const;
448 void setLoadDate( long t );
449 virtual void update( const Observable *observable, void *arg );
450 bool isCopy() const;
451 void setCopyFlag( bool x = true );
456 virtual std::string toolTip() const;
457
459 static std::list<AObject *> load( const std::string & filename );
461 static bool reload( AObject* object, bool onlyoutdated = false );
463 static int registerObjectType( const std::string & id );
464 static std::string objectTypeName( int type );
465 static void setObjectMenu(std::string type, carto::rc_ptr<ObjectMenu> om)
466 {
467 _objectmenu_map[type] = om;
468 }
470 {
471 return _objectmenu_map[type];
472 }
473 static std::map<std::string, carto::rc_ptr<ObjectMenu> >
475 {
476 return _objectmenu_map;
477 }
480
482 static void cleanStatic();
483
486
487 protected:
488 const PrimList & primitives() const;
492 virtual void cleanup();
499 AObject( const AObject & );
500
502 int _type;
503 int _id;
504 std::string _name;
505 std::string _filename;
506
507 std::set<AWindow*> _winList;
511
518
521
523 static std::map<std::string, int> _objectTypes;
525 static std::map<int,std::string> _objectTypeNames;
526
528 static std::map<std::string, carto::rc_ptr<ObjectMenu> >
530
531 friend class StaticInitializers;
532
533 private:
534 struct Private;
535 Private *d;
536 };
537
538}
539
540
541inline float
542anatomist::AObject::mixedTexValue( const std::vector<float> & pos,
543 int poly ) const
544{
545 std::vector<float> tval = texValues( pos, poly );
546 if( tval.empty() )
547 return 0;
548 float sum = 0.;
549 std::vector<float>::const_iterator i, e = tval.end();
550 for( i=tval.begin(); i!=e; ++i )
551 sum += *i;
552 return sum / tval.size();
553}
554
555
556namespace carto
557{
559 DECLARE_GENERIC_OBJECT_TYPE( std::set<anatomist::AObject *> )
560 DECLARE_GENERIC_OBJECT_TYPE( std::vector<anatomist::AObject *> )
561 DECLARE_GENERIC_OBJECT_TYPE( std::list<anatomist::AObject *> )
563}
564
565#endif
566
#define ANATOMIST_API
Base Anatomist object (abstract)
Definition Object.h:97
void setFileName(const std::string &filename)
virtual const MObject * mObjectAPI() const
Definition Object.h:154
virtual bool hasTexture() const
Textured objects have values associated with a geometric coordinate.
Definition Object.h:348
ObjectMenu *(* ObjectMenuRegistrerFunction)(const AObject *objtype, ObjectMenu *menu)
dynamic menu registration function
Definition Object.h:136
void setId(int id)
void setType(int type)
Method to set type id, because type() is not virtual.
Definition Object.h:162
virtual AObjectPalette * palette()
Normally, getOrCreatePalette() should be used instead of this function in most cases.
Definition Object.h:225
virtual std::vector< float > voxelSize() const
Returns at least 4 sizes. For 3D objects, returns (1, 1, 1, 1)
bool hasReferenceChanged() const
virtual bool Is2DObject()=0
virtual bool savable() const
Definition Object.h:401
static std::map< std::string, carto::rc_ptr< ObjectMenu > > _objectmenu_map
Object Menu Map.
Definition Object.h:529
static std::map< std::string, carto::rc_ptr< ObjectMenu > > & getObjectMenuMap()
Definition Object.h:474
virtual const AObjectPalette * getOrCreatePalette() const
User normally calls this function.
virtual float mixedTexValue(const std::vector< float > &pos, const Referential *orgRef, int poly=-1) const
Gets a "mixed" texture value at a given space / time location.
AObject * referentialInheritance() const
if not null, the object referential is inherited from this object
static bool reload(AObject *object, bool onlyoutdated=false)
Reads from disk again.
virtual unsigned dimTexture() const
Number of texture values for a point.
Definition Object.h:350
Material _material
Should be a pointer: some objects don't have a material (2D objects)
Definition Object.h:513
int Visible() const
Visibility in control window.
Definition Object.h:259
virtual bool loadable() const
Definition Object.h:400
virtual AObject * objectAt(const std::vector< float > &pos, float tol, const Referential *orgref, const Point3df &orggeom)
Same with origin window referential.
virtual const Material & material() const
Definition Object.h:236
virtual carto::rc_ptr< carto::Volume< float > > texValuesSeries(const std::vector< float > &pos, int axis, const Referential *orgRef, int poly=-1) const
virtual void adjustPalette()
Creates or updates object palette according to object values (if needed)
AObject(const AObject &)
copy constructor, protected and used only to reimplement clone()
virtual void SetMaterial(const Material &mat)
Referential * getReferential() const
AObjectPalette * _palette
Palette.
Definition Object.h:520
virtual const AObjectPalette * palette() const
Definition Object.h:226
std::set< AWindow * > _winList
Definition Object.h:507
virtual void getTextureLabels(const std::vector< float > &texvalues, std::vector< std::string > &texlabels, std::string &textype) const
carto::Object aimsMeshFromGLComponent()
const std::set< AWindow * > & WinList()
List of windows showing this object.
Definition Object.h:270
static carto::rc_ptr< ObjectMenu > getObjectMenu(std::string type)
Definition Object.h:469
virtual bool save(const std::string &filename)
virtual AObject * clone(bool shallow=true)
Makes a copy of the object, with a duplicated object structure, palette and material,...
virtual bool IsFusion2DAllowed()
virtual carto::rc_ptr< carto::Volume< float > > texValuesSeries(const std::vector< float > &pos, int axis, int poly=-1) const
virtual std::string toolTip() const
tooltip displayed in 3D views (HTML).
static void addObjectMenuRegistration(ObjectMenuRegistrerFunction)
void setLoadDate(long t)
virtual float MaxT() const
Obsolete, deprecated.
static std::list< AObject * > load(const std::string &filename)
Static object loader: creates an objects, loads its contents.
int type() const
Object type identifier.
Definition Object.h:159
const Referential * previousReferential() const
Referential that the object was in before the last change.
static std::map< std::string, int > _objectTypes
name-to-type map
Definition Object.h:523
static void cleanStatic()
cleanup static global variables (called when quitting anatomist)
virtual int CanBeDestroyed()
Allows / unallows destruction of object.
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.
friend class StaticInitializers
Definition Object.h:531
virtual MObject * mObjectAPI()
Definition Object.h:155
virtual Tree * optionTree() const
Menu tree for new options, see object/optionMatcher.h.
virtual void registerWindow(AWindow *window)
virtual void update(const Observable *observable, void *arg)
This method is called whenever the observed object is changed.
void setAllowsOverwriteOnSave(bool x)
virtual void clearReferentialInheritance()
sets the object to get referential from to null, unregister it
bool save(const std::string &filename, bool onlyIfModified)
long loadDate() const
Time the object was created, loaded or reloaded.
static int registerObjectType(const std::string &id)
Creates a new object type number and returns it.
virtual void storeHeaderOptions()
Store some object properties into the header (.minf), such as material, palette etc before saving the...
ParentList & Parents()
List of multi-objects containing this one. Obsolete: use parents()
Definition Object.h:262
PrimList & primitives()
virtual const GLComponent * glAPI() const
OpenGL objects const API.
Definition Object.h:151
bool userModified() const
if the object has been modified by user interaction, and needs saving
virtual carto::Object makeHeaderOptions() const
get object properties into a generic object, such as material, palette etc before saving the object
virtual bool Is3DObject()=0
virtual void setReferentialInheritance(AObject *ao)
virtual bool renderingIsObserverDependent() const
true only if the rendering (openGL) of the object changes with the observer position/orientation of t...
virtual bool textured2D() const
true if 2D rendering uses a textured plane (not a full openGL object)
Definition Object.h:277
std::set< MObject * > ParentList
Storage type for parent objects (multi-objects containing this one)
Definition Object.h:100
virtual bool render(PrimList &, const ViewState &)
rendering (generally 2D or 3D using OpenGL).
virtual void clearHasChangedFlags() const
Reset has-changed flags.
int id() const
Unique ID assigned upon construction, but somewhat unused now...
Definition Object.h:164
virtual std::string objectFullTypeName(void) const
Get Object Full Type Name.
Definition Object.h:419
virtual bool reload(const std::string &filename)
Re-reads objects from disk.
virtual AObject * objectAt(const std::vector< float > &pos, float tol=0)
Find the object (sub-object) at given postion with a tolerence.
virtual void UnregisterParent(MObject *pob)
Definition Object.h:268
ObjectType
Base object type identifiers.
Definition Object.h:107
@ OTHER
External object type (unknown from the base anatomist library)
Definition Object.h:131
virtual GLComponent * glAPI()
OpenGL objects API.
Definition Object.h:153
bool _referenceHasChanged
Reference has-changed flag.
Definition Object.h:517
virtual void setReferenceChanged()
const ParentList & parents() const
List of multi-objects containing this one.
Definition Object.h:266
AObject(const std::string &filename="")
virtual bool boundingBox2D(std::vector< float > &bmin, std::vector< float > &bmax) const
Bounding box in 2D views mode.
virtual AObject * fallbackReferentialInheritance() const
object to take referential from when no ref is assigned
virtual std::vector< float > texValues(const std::vector< float > &pos, int poly=-1) const
virtual void setPalette(const AObjectPalette &palette)
std::string _filename
Definition Object.h:505
virtual void setProperties(carto::Object options)
Same as setHeaderOptions() and used by it, allows passing a dictionary.
virtual bool printTalairachCoord(const Point3df &, const Referential *) const
should be replaced by a real referential
Definition Object.h:428
virtual void unregisterObservable(Observable *)
Called when an observable is destroyed, only called by Observable: don't use this function directly.
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 void cleanup()
must be called by objects destructors - Must be explicitly called by each object destructor since it ...
virtual void RegisterParent(MObject *pob)
Definition Object.h:267
void setCopyFlag(bool x=true)
virtual void setGeomExtrema()
Scans the object internals and determines its geometry extrema.
Definition Object.h:344
int _type
Should be static in each object class.
Definition Object.h:502
virtual void unregisterWindow(AWindow *window)
virtual void setInternalsChanged()
Notifies some underlying lower-level objects have changed.
std::string fileName() const
File name (if any) for loaded objects.
Definition Object.h:168
static std::string objectTypeName(int type)
void setHeaderOptions()
Set some object properties according to the header (.minf), such as material, palette etc.
void setName(const std::string &n)
static void addObjectMenuRegistration(ObjectMenuRegistrerClass *)
ParentList _parents
Definition Object.h:510
void setUserModified(bool state=true)
if the object has been modified by user interaction, and needs saving
virtual int isMultiObject() const
maybe not necessary ?: we can use dynamic_cast instead
Definition Object.h:173
void SetVisibility(int v)
Definition Object.h:260
virtual bool isTransparent() const
virtual void setVoxelSize(const std::vector< float > &)
Definition Object.h:214
virtual float MinT() const
Obsolete, deprecated.
virtual void setReferential(Referential *ref)
static std::map< int, std::string > _objectTypeNames
type-to-name map
Definition Object.h:525
virtual void createDefaultPalette(const std::string &name="")
function called by getOrCreatePalette() - overloadable, need not be called directly
ParentList & parents()
List of multi-objects containing this one.
Definition Object.h:264
virtual Material & GetMaterial()
Definition Object.h:235
AObject *& _referentialInheritance()
provide access to derived classes
virtual ObjectMenu * optionMenu() const
virtual void internalUpdate()
Updates the state of the object.
virtual ~AObject()
AObject subclasses must call cleanup() in their destructor.
std::string _name
Definition Object.h:504
const PrimList & primitives() const
int InMemory() const
For objects loading only when needed (not used yet...)
Definition Object.h:257
Referential * _referential
Referentiel.
Definition Object.h:515
virtual std::vector< float > texValues(const std::vector< float > &pos, const Referential *orgRef, int poly=-1) const
Gets the array of texture values at a given location.
bool allowsOverwriteOnSave() const
std::string name() const
Name shown in control window.
Definition Object.h:166
virtual void SetExtrema()
Scans the object internals and determines its (texture) extrema values.
Definition Object.h:346
static void setObjectMenu(std::string type, carto::rc_ptr< ObjectMenu > om)
Definition Object.h:465
bool isCopy() const
Abstract base class Anatomist window.
Definition Window.h:59
Base class for all OpenGL objects in Anatomist (with OpenGL display lists)
Definition glcomponent.h:67
OpenGL item (display list, texture, ...) with reference counter and cleanup upon destruction.
Definition primitive.h:48
Multi-object : base abstract class for objects that contain others.
Definition MObject.h:235
This class has to be rewritten, it's really really a shame.......
Definition Material.h:48
A class can implement the Observer interface when it wants to be informed of changes in observable ob...
Definition Observer.h:55
friend class Observable
Definition Observer.h:90
Referential: marker for transformations, with an associated color.
Definition Referential.h:56
friend friend class ref
std::list< carto::rc_ptr< GLItem > > PrimList
Definition Object.h:74
DataTypeTraits< T >::LongType sum(const Volume< T > &vol)
#define DECLARE_GENERIC_OBJECT_TYPE(T)
int effectiveHeight
Definition Object.h:84
ViewState holds information about how a view wants to see an object.
Definition viewstate.h:67
AimsVector< float, 3 > Point3df