anatomist  5.1.2
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 <cartobase/smart/rcptr.h>
45 #include <aims/vector/vector.h>
46 
47 #include <string>
48 #include <list>
49 #include <set>
50 #include <map>
51 #include <vector>
52 
53 
54 class ColorMap;
55 class Tree;
56 
57 namespace aims
58 {
59  class Quaternion;
60 }
61 
62 namespace anatomist
63 {
64 
65  class AWindow;
66  class Referential;
67  class Geometry;
68  class AObjectPalette;
69  class MObject;
70  class GLItem;
71  class GLComponent;
72  struct ViewState;
73  typedef std::list<carto::rc_ptr<GLItem> > PrimList;
75 
76 
77  struct AImage
78  {
79  int width;
80  int height;
81  int depth;
84  char *data;
85  };
86 
87  /*
88  TODO:
89  remove:
90  MinT(), MaxT()
91  */
92 
95  class ANATOMIST_API AObject : public Observable, public Observer
96  {
97  public:
99  typedef std::set<MObject*> ParentList;
100 
106  {
113  MAP,
114  SET,
130  OTHER
131  };
132 
134  typedef ObjectMenu* (*ObjectMenuRegistrerFunction)
135  ( const AObject* objtype, ObjectMenu* menu );
136 
137  AObject( const std::string & filename = "" );
139  virtual ~AObject();
140 
147  virtual AObject* clone( bool shallow = true );
148 
150  virtual const GLComponent* glAPI() const { return 0; }
152  virtual GLComponent* glAPI() { return 0; }
153  virtual const MObject* mObjectAPI() const { return 0; }
154  virtual MObject* mObjectAPI() { return 0; }
155 
158  int type() const { return( _type ); }
161  void setType(int type) { _type = type; };
163  int id() const { return( _id ); }
165  std::string name() const { return( _name ); }
167  std::string fileName() const { return( _filename ); }
168  void setName( const std::string & n );
169  void setFileName( const std::string & filename );
170  void setId( int id );
172  virtual int isMultiObject() const { return( false ); }
173 
175  virtual float MinT() const;
177  virtual float MaxT() const;
178 
186  virtual bool boundingBox2D( std::vector<float> & bmin,
187  std::vector<float> & bmax ) const;
188 
203  virtual bool boundingBox( std::vector<float> & bmin,
204  std::vector<float> & bmax ) const;
205 
210  virtual bool render( PrimList &, const ViewState & );
212  virtual std::vector<float> voxelSize() const;
213  virtual void setVoxelSize( const std::vector<float> & ) {}
217  virtual void internalUpdate();
218 
221  virtual void adjustPalette() {}
224  virtual AObjectPalette* palette() { return( _palette ); }
225  virtual const AObjectPalette* palette() const { return( _palette ); }
226  virtual void setPalette( const AObjectPalette & palette );
228  virtual const AObjectPalette* getOrCreatePalette() const;
231  virtual void createDefaultPalette( const std::string & name = "" );
232 
233  virtual void SetMaterial( const Material & mat );
234  virtual Material & GetMaterial() { return _material; }
235  virtual const Material & material() const
236  { return const_cast<AObject *>(this)->GetMaterial(); }
237 
241  virtual void setReferentialInheritance( AObject* ao );
242  virtual void setReferential( Referential* ref );
251 
253  virtual Tree* optionTree() const;
254  virtual ObjectMenu* optionMenu() const;
256  int InMemory() const { return _inMemory; }
258  int Visible() const { return _visible; }
259  void SetVisibility( int v ) { _visible = v; }
261  ParentList & Parents() { return _parents; }
263  ParentList & parents() { return _parents; }
265  const ParentList & parents() const { return _parents; }
266  virtual void RegisterParent( MObject *pob ) { _parents.insert( pob ); }
267  virtual void UnregisterParent( MObject *pob ) { _parents.erase( pob ); }
269  const std::set<AWindow*> & WinList() { return _winList; }
270  virtual void registerWindow(AWindow* window);
271  virtual void unregisterWindow(AWindow* window);
272  virtual bool Is2DObject() = 0;
273  virtual bool Is3DObject() = 0;
274  virtual bool IsFusion2DAllowed();
276  virtual bool textured2D() const { return false; }
277  virtual bool isTransparent() const;
282  virtual bool renderingIsObserverDependent() const;
286  virtual int CanBeDestroyed();
287 
288  virtual void setReferenceChanged();
289  bool hasReferenceChanged() const;
292  virtual void setInternalsChanged();
299  virtual void clearHasChangedFlags() const;
300 
302  bool userModified() const;
304  void setUserModified( bool state = true );
305 
309  virtual AObject* objectAt( const std::vector<float> & pos, float tol = 0 );
312  virtual AObject* objectAt( const std::vector<float> & pos,
313  float tol, const Referential* orgref,
314  const Point3df & orggeom );
315 
317  virtual void setGeomExtrema() {}
319  virtual void SetExtrema() {}
321  virtual bool hasTexture() const { return( false ); }
323  virtual unsigned dimTexture() const { return( 1 ); }
335  virtual float mixedTexValue( const std::vector<float> & pos,
336  const Referential* orgRef ) const;
339  virtual float mixedTexValue( const std::vector<float> & pos ) const;
348  virtual std::vector<float> texValues( const std::vector<float> & pos,
349  const Referential* orgRef ) const;
350  virtual std::vector<float>
351  texValues( const std::vector<float> & pos ) const;
352 
353  virtual bool loadable() const { return false; }
354  virtual bool savable() const { return false; }
365  virtual bool reload( const std::string & filename );
366 
372  virtual std::string objectFullTypeName(void) const
373  { return objectTypeName(_type); };
375  bool save( const std::string & filename, bool onlyIfModified );
377  virtual bool save( const std::string & filename );
379  virtual bool printTalairachCoord( const Point3df &,
380  const Referential* ) const
381  { return( false ); }
386  virtual void setProperties( carto::Object options );
393  virtual void storeHeaderOptions();
398  long loadDate() const;
399  void setLoadDate( long t );
400  virtual void update( const Observable *observable, void *arg );
401  bool isCopy() const;
402  void setCopyFlag( bool x = true );
407  virtual std::string toolTip() const;
408 
410  static std::list<AObject *> load( const std::string & filename );
412  static bool reload( AObject* object, bool onlyoutdated = false );
414  static int registerObjectType( const std::string & id );
415  static std::string objectTypeName( int type );
416  static void setObjectMenu(std::string type, carto::rc_ptr<ObjectMenu> om)
417  {
418  _objectmenu_map[type] = om;
419  }
420  static carto::rc_ptr<ObjectMenu> getObjectMenu(std::string type)
421  {
422  return _objectmenu_map[type];
423  }
424  static std::map<std::string, carto::rc_ptr<ObjectMenu> >
426  {
427  return _objectmenu_map;
428  }
429  static void addObjectMenuRegistration( ObjectMenuRegistrerFunction );
431 
433  static void cleanStatic();
434 
437 
438  protected:
439  const PrimList & primitives() const;
443  virtual void cleanup();
448  virtual void unregisterObservable( Observable * );
450  AObject( const AObject & );
451 
453  int _type;
454  int _id;
455  std::string _name;
456  std::string _filename;
457 
458  std::set<AWindow*> _winList;
460  int _visible;
462 
468  mutable bool _referenceHasChanged;
469 
472 
474  static std::map<std::string, int> _objectTypes;
476  static std::map<int,std::string> _objectTypeNames;
477 
479  static std::map<std::string, carto::rc_ptr<ObjectMenu> >
481 
482  friend class StaticInitializers;
483 
484  private:
485  struct Private;
486  Private *d;
487  };
488 
489 }
490 
491 
492 inline float
493 anatomist::AObject::mixedTexValue( const std::vector<float> & ) const
494 {
495  return 0;
496 }
497 
498 
499 inline std::vector<float>
500 anatomist::AObject::texValues( const std::vector<float> & ) const
501 {
502  std::vector<float> t;
503  return t;
504 }
505 
506 
507 namespace carto
508 {
510  DECLARE_GENERIC_OBJECT_TYPE( std::set<anatomist::AObject *> )
511  DECLARE_GENERIC_OBJECT_TYPE( std::vector<anatomist::AObject *> )
512  DECLARE_GENERIC_OBJECT_TYPE( std::list<anatomist::AObject *> )
514 }
515 
516 #endif
517 
#define ANATOMIST_API
Base Anatomist object (abstract)
Definition: Object.h:96
void setFileName(const std::string &filename)
const Referential * previousReferential() const
Referential that the object was in before the last change.
virtual AObject * clone(bool shallow=true)
Makes a copy of the object, with a duplicated object structure, palette and material,...
const PrimList & primitives() const
virtual bool hasTexture() const
Textured objects have values associated with a geometric coordinate.
Definition: Object.h:321
void setId(int id)
virtual Material & GetMaterial()
Definition: Object.h:234
void setType(int type)
Method to set type id, because type() is not virtual.
Definition: Object.h:161
virtual MObject * mObjectAPI()
Definition: Object.h:154
bool hasReferenceChanged() const
virtual bool Is2DObject()=0
virtual bool savable() const
Definition: Object.h:354
static std::map< std::string, carto::rc_ptr< ObjectMenu > > _objectmenu_map
Object Menu Map.
Definition: Object.h:480
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:323
Material _material
Should be a pointer: some objects don't have a material (2D objects)
Definition: Object.h:464
int Visible() const
Visibility in control window.
Definition: Object.h:258
virtual bool loadable() const
Definition: Object.h:353
AObject *& _referentialInheritance()
provide access to derived classes
virtual void adjustPalette()
Creates or updates object palette according to object values (if needed)
Definition: Object.h:221
virtual const AObjectPalette * getOrCreatePalette() const
User normally calls this function.
virtual GLComponent * glAPI()
OpenGL objects API.
Definition: Object.h:152
virtual AObject * objectAt(const std::vector< float > &pos, float tol, const Referential *orgref, const Point3df &orggeom)
Same with origin window referential.
AObject(const AObject &)
copy constructor, protected and used only to reimplement clone()
const ParentList & parents() const
List of multi-objects containing this one.
Definition: Object.h:265
virtual const Material & material() const
Definition: Object.h:235
virtual void SetMaterial(const Material &mat)
static std::list< AObject * > load(const std::string &filename)
Static object loader: creates an objects, loads its contents.
AObjectPalette * _palette
Palette.
Definition: Object.h:471
std::set< AWindow * > _winList
Definition: Object.h:458
carto::Object aimsMeshFromGLComponent()
virtual AObjectPalette * palette()
Normally, getOrCreatePalette() should be used instead of this function in most cases.
Definition: Object.h:224
virtual bool save(const std::string &filename)
virtual bool IsFusion2DAllowed()
virtual std::string toolTip() const
tooltip displayed in 3D views (HTML).
static void addObjectMenuRegistration(ObjectMenuRegistrerFunction)
ParentList & Parents()
List of multi-objects containing this one. Obsolete: use parents()
Definition: Object.h:261
void setLoadDate(long t)
virtual float MaxT() const
Obsolete, deprecated.
virtual Tree * optionTree() const
Menu tree for new options, see object/optionMatcher.h.
virtual AObject * fallbackReferentialInheritance() const
object to take referential from when no ref is assigned
int type() const
Object type identifier.
Definition: Object.h:158
static std::map< std::string, int > _objectTypes
name-to-type map
Definition: Object.h:474
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.
static std::map< std::string, carto::rc_ptr< ObjectMenu > > & getObjectMenuMap()
Definition: Object.h:425
virtual void registerWindow(AWindow *window)
virtual void update(const Observable *observable, void *arg)
This method is called whenever the observed object is changed.
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...
virtual AObject * objectAt(const std::vector< float > &pos, float tol=0)
Find the object (sub-object) at given postion with a tolerence.
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:276
std::set< MObject * > ParentList
Storage type for parent objects (multi-objects containing this one)
Definition: Object.h:99
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:163
Referential * getReferential() const
virtual std::string objectFullTypeName(void) const
Get Object Full Type Name.
Definition: Object.h:372
virtual bool reload(const std::string &filename)
Re-reads objects from disk.
virtual void UnregisterParent(MObject *pob)
Definition: Object.h:267
ObjectType
Base object type identifiers.
Definition: Object.h:106
virtual ObjectMenu * optionMenu() const
const std::set< AWindow * > & WinList()
List of windows showing this object.
Definition: Object.h:269
bool _referenceHasChanged
Reference has-changed flag.
Definition: Object.h:468
virtual void setReferenceChanged()
AObject(const std::string &filename="")
virtual bool boundingBox2D(std::vector< float > &bmin, std::vector< float > &bmax) const
Bounding box in 2D views mode.
virtual const GLComponent * glAPI() const
OpenGL objects const API.
Definition: Object.h:150
AObject * referentialInheritance() const
if not null, the object referential is inherited from this object
virtual std::vector< float > texValues(const std::vector< float > &pos, const Referential *orgRef) const
Gets the array of texture values at a given location.
virtual void setPalette(const AObjectPalette &palette)
std::string _filename
Definition: Object.h:456
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:379
virtual void unregisterObservable(Observable *)
Called when an observable is destroyed, only called by Observable: don't use this function directly.
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:266
void setCopyFlag(bool x=true)
virtual const AObjectPalette * palette() const
Definition: Object.h:225
virtual void setGeomExtrema()
Scans the object internals and determines its geometry extrema.
Definition: Object.h:317
int _type
Should be static in each object class.
Definition: Object.h:453
virtual void unregisterWindow(AWindow *window)
virtual const MObject * mObjectAPI() const
Definition: Object.h:153
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:167
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 carto::rc_ptr< ObjectMenu > getObjectMenu(std::string type)
Definition: Object.h:420
static void addObjectMenuRegistration(ObjectMenuRegistrerClass *)
ParentList _parents
Definition: Object.h:461
virtual std::vector< float > voxelSize() const
Returns at least 4 sizes. For 3D objects, returns (1, 1, 1, 1)
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:172
void SetVisibility(int v)
Definition: Object.h:259
virtual bool isTransparent() const
virtual void setVoxelSize(const std::vector< float > &)
Definition: Object.h:213
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:476
virtual void createDefaultPalette(const std::string &name="")
function called by getOrCreatePalette() - overloadable, need not be called directly
PrimList & primitives()
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:455
int InMemory() const
For objects loading only when needed (not used yet...)
Definition: Object.h:256
virtual float mixedTexValue(const std::vector< float > &pos, const Referential *orgRef) const
Gets a "mixed" texture value at a given space / time location.
Referential * _referential
Referentiel.
Definition: Object.h:466
ParentList & parents()
List of multi-objects containing this one.
Definition: Object.h:263
std::string name() const
Name shown in control window.
Definition: Object.h:165
virtual void SetExtrema()
Scans the object internals and determines its (texture) extrema values.
Definition: Object.h:319
static void setObjectMenu(std::string type, carto::rc_ptr< ObjectMenu > om)
Definition: Object.h:416
bool isCopy() const
Abstract base class Anatomist window.
Definition: Window.h:58
Base class for all OpenGL objects in Anatomist (with OpenGL display lists)
Definition: glcomponent.h:67
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
This class can be subclassed to represent an object that the programmer wants to have observed.
Definition: Observable.h:68
A class can implement the Observer interface when it wants to be informed of changes in observable ob...
Definition: Observer.h:55
Referential: marker for transformations, with an associated color.
Definition: Referential.h:55
std::list< carto::rc_ptr< GLItem > > PrimList
Definition: Object.h:72
#define DECLARE_GENERIC_OBJECT_TYPE(T)
int effectiveHeight
Definition: Object.h:83
char * data
Definition: Object.h:84
int effectiveWidth
Definition: Object.h:82
ViewState holds information about how a view wants to see an object.
Definition: viewstate.h:67