anatomist  4.7.0
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 
238  Referential* getReferential() const;
240  AObject *referentialInheritance() const;
241  virtual void setReferentialInheritance( AObject* ao );
242  virtual void setReferential( Referential* ref );
244  virtual AObject* fallbackReferentialInheritance() const;
250  const Referential* previousReferential() const;
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;
275  virtual bool textured2D() const { return false; }
276  virtual bool isTransparent() const;
281  virtual bool renderingIsObserverDependent() const;
285  virtual int CanBeDestroyed();
286 
287  virtual void setReferenceChanged();
288  bool hasReferenceChanged() const;
291  virtual void setInternalsChanged();
298  virtual void clearHasChangedFlags() const;
299 
303  virtual AObject* objectAt( const std::vector<float> & pos, float tol = 0 );
306  virtual AObject* objectAt( const std::vector<float> & pos,
307  float tol, const Referential* orgref,
308  const Point3df & orggeom );
309 
311  virtual void setGeomExtrema() {}
313  virtual void SetExtrema() {}
315  virtual bool hasTexture() const { return( false ); }
317  virtual unsigned dimTexture() const { return( 1 ); }
329  virtual float mixedTexValue( const std::vector<float> & pos,
330  const Referential* orgRef ) const;
333  virtual float mixedTexValue( const std::vector<float> & pos ) const;
342  virtual std::vector<float> texValues( const std::vector<float> & pos,
343  const Referential* orgRef ) const;
344  virtual std::vector<float>
345  texValues( const std::vector<float> & pos ) const;
346 
347  virtual bool loadable() const { return false; }
348  virtual bool savable() const { return false; }
359  virtual bool reload( const std::string & filename );
360 
366  virtual std::string objectFullTypeName(void) const
367  { return objectTypeName(_type); };
369  virtual bool save( const std::string & filename );
371  virtual bool printTalairachCoord( const Point3df &,
372  const Referential* ) const
373  { return( false ); }
376  void setHeaderOptions();
378  virtual void setProperties( carto::Object options );
385  virtual void storeHeaderOptions();
388  virtual carto::Object makeHeaderOptions() const;
390  long loadDate() const;
391  void setLoadDate( long t );
392  virtual void update( const Observable *observable, void *arg );
393  bool isCopy() const;
394  void setCopyFlag( bool x = true );
399  virtual std::string toolTip() const;
400 
402  static std::list<AObject *> load( const std::string & filename );
404  static bool reload( AObject* object, bool onlyoutdated = false );
406  static int registerObjectType( const std::string & id );
407  static std::string objectTypeName( int type );
408  static void setObjectMenu(std::string type, carto::rc_ptr<ObjectMenu> om)
409  {
410  _objectmenu_map[type] = om;
411  }
412  static carto::rc_ptr<ObjectMenu> getObjectMenu(std::string type)
413  {
414  return _objectmenu_map[type];
415  }
416  static std::map<std::string, carto::rc_ptr<ObjectMenu> >
418  {
419  return _objectmenu_map;
420  }
421  static void addObjectMenuRegistration( ObjectMenuRegistrerFunction );
422  static void addObjectMenuRegistration( ObjectMenuRegistrerClass * );
423 
425  static void cleanStatic();
426 
428  carto::Object aimsMeshFromGLComponent();
429 
430  protected:
431  const PrimList & primitives() const;
432  PrimList & primitives();
435  virtual void cleanup();
437  virtual void clearReferentialInheritance();
439  AObject *& _referentialInheritance();
440  virtual void unregisterObservable( Observable * );
442  AObject( const AObject & );
443 
445  int _type;
446  int _id;
447  std::string _name;
448  std::string _filename;
449 
450  std::set<AWindow*> _winList;
452  int _visible;
453  ParentList _parents;
454 
460  mutable bool _referenceHasChanged;
461 
464 
466  static std::map<std::string, int> _objectTypes;
468  static std::map<int,std::string> _objectTypeNames;
469 
471  static std::map<std::string, carto::rc_ptr<ObjectMenu> >
473 
474  friend class StaticInitializers;
475 
476  private:
477  struct Private;
478  Private *d;
479  };
480 
481 }
482 
483 
484 inline float
485 anatomist::AObject::mixedTexValue( const std::vector<float> & ) const
486 {
487  return 0;
488 }
489 
490 
491 inline std::vector<float>
492 anatomist::AObject::texValues( const std::vector<float> & ) const
493 {
494  std::vector<float> t;
495  return t;
496 }
497 
498 
499 namespace carto
500 {
502  DECLARE_GENERIC_OBJECT_TYPE( std::set<anatomist::AObject *> )
503  DECLARE_GENERIC_OBJECT_TYPE( std::vector<anatomist::AObject *> )
504  DECLARE_GENERIC_OBJECT_TYPE( std::list<anatomist::AObject *> )
506 }
507 
508 #endif
509 
#define DECLARE_GENERIC_OBJECT_TYPE(T)
virtual Material & GetMaterial()
Definition: Object.h:234
std::string _name
Definition: Object.h:447
virtual unsigned dimTexture() const
Number of texture values for a point.
Definition: Object.h:317
bool _referenceHasChanged
Reference has-changed flag.
Definition: Object.h:460
virtual void UnregisterParent(MObject *pob)
Definition: Object.h:267
ViewState holds information about how a view wants to see an object.
Definition: viewstate.h:66
virtual AObjectPalette * palette()
Normally, getOrCreatePalette() should be used instead of this function in most cases.
Definition: Object.h:224
Base Anatomist object (abstract)
Definition: Object.h:95
std::string _filename
Definition: Object.h:448
static std::map< std::string, carto::rc_ptr< ObjectMenu > > & getObjectMenuMap()
Definition: Object.h:417
const std::set< AWindow * > & WinList()
List of windows showing this object.
Definition: Object.h:269
std::string fileName() const
File name (if any) for loaded objects.
Definition: Object.h:167
std::list< carto::rc_ptr< GLItem > > PrimList
Definition: Object.h:72
A class can implement the Observer interface when it wants to be informed of changes in observable ob...
Definition: Observer.h:54
virtual void RegisterParent(MObject *pob)
Definition: Object.h:266
Multi-object : base abstract class for objects that contain others.
Definition: MObject.h:234
Abstract base class Anatomist window.
Definition: Window.h:57
const ParentList & parents() const
List of multi-objects containing this one.
Definition: Object.h:265
static void setObjectMenu(std::string type, carto::rc_ptr< ObjectMenu > om)
Definition: Object.h:408
virtual bool hasTexture() const
Textured objects have values associated with a geometric coordinate.
Definition: Object.h:315
static carto::rc_ptr< ObjectMenu > getObjectMenu(std::string type)
Definition: Object.h:412
virtual void adjustPalette()
Creates or updates object palette according to object values (if needed)
Definition: Object.h:221
virtual void setGeomExtrema()
Scans the object internals and determines its geometry extrema.
Definition: Object.h:311
This class can be subclassed to represent an object that the programmer wants to have observed...
Definition: Observable.h:67
virtual const GLComponent * glAPI() const
OpenGL objects const API.
Definition: Object.h:150
std::string name() const
Name shown in control window.
Definition: Object.h:165
static std::map< int, std::string > _objectTypeNames
type-to-name map
Definition: Object.h:468
void setType(int type)
Method to set type id, because type() is not virtual.
Definition: Object.h:161
char * data
Definition: Object.h:84
void SetVisibility(int v)
Definition: Object.h:259
This class has to be rewritten, it&#39;s really really a shame.......
Definition: Material.h:47
std::set< AWindow * > _winList
Definition: Object.h:450
virtual const MObject * mObjectAPI() const
Definition: Object.h:153
virtual float mixedTexValue(const std::vector< float > &pos, const Referential *orgRef) const
Gets a "mixed" texture value at a given space / time location.
virtual GLComponent * glAPI()
OpenGL objects API.
Definition: Object.h:152
int id() const
Unique ID assigned upon construction, but somewhat unused now...
Definition: Object.h:163
ParentList _parents
Definition: Object.h:453
int effectiveWidth
Definition: Object.h:82
virtual MObject * mObjectAPI()
Definition: Object.h:154
virtual int isMultiObject() const
maybe not necessary ?: we can use dynamic_cast instead
Definition: Object.h:172
virtual bool textured2D() const
true if 2D rendering uses a textured plane (not a full openGL object)
Definition: Object.h:275
ParentList & parents()
List of multi-objects containing this one.
Definition: Object.h:263
virtual bool printTalairachCoord(const Point3df &, const Referential *) const
should be replaced by a real referential
Definition: Object.h:371
int Visible() const
Visibility in control window.
Definition: Object.h:258
ParentList & Parents()
List of multi-objects containing this one. Obsolete: use parents()
Definition: Object.h:261
#define ANATOMIST_API
Base class for all OpenGL objects in Anatomist (with OpenGL display lists)
Definition: glcomponent.h:66
AObjectPalette * _palette
Palette.
Definition: Object.h:463
ObjectType
Base object type identifiers.
Definition: Object.h:105
virtual std::vector< float > texValues(const std::vector< float > &pos, const Referential *orgRef) const
Gets the array of texture values at a given location.
std::set< MObject * > ParentList
Storage type for parent objects (multi-objects containing this one)
Definition: Object.h:99
virtual const AObjectPalette * palette() const
Definition: Object.h:225
Material _material
Should be a pointer: some objects don&#39;t have a material (2D objects)
Definition: Object.h:456
static std::map< std::string, int > _objectTypes
name-to-type map
Definition: Object.h:466
static std::map< std::string, carto::rc_ptr< ObjectMenu > > _objectmenu_map
Object Menu Map.
Definition: Object.h:472
virtual bool loadable() const
Definition: Object.h:347
virtual void SetExtrema()
Scans the object internals and determines its (texture) extrema values.
Definition: Object.h:313
int type() const
Object type identifier.
Definition: Object.h:158
int effectiveHeight
Definition: Object.h:83
virtual const Material & material() const
Definition: Object.h:235
int _type
Should be static in each object class.
Definition: Object.h:445
virtual bool savable() const
Definition: Object.h:348
Referential: marker for transformations, with an associated color.
Definition: Referential.h:54
int InMemory() const
For objects loading only when needed (not used yet...)
Definition: Object.h:256
Referential * _referential
Referentiel.
Definition: Object.h:458
virtual std::string objectFullTypeName(void) const
Get Object Full Type Name.
Definition: Object.h:366
virtual void setVoxelSize(const std::vector< float > &)
Definition: Object.h:213
reference_wrapper< T > ref(T &ref)