anatomist  5.1.2
3D neuroimaging data viewer
glcomponent.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 #ifndef ANA_SURFACE_GLCOMPONENT_H
35 #define ANA_SURFACE_GLCOMPONENT_H
36 
41 #include <aims/rgb/rgb.h>
44 #include <vector>
45 #include <set>
46 
47 
48 namespace anatomist
49 {
50 
51  class Material;
52  class AObjectPalette;
53  class Sliceable;
54  class Referential;
55 
56 
67  {
68  public:
70  {
97  };
98 
100  {
103  };
104 
113  enum glPart
114  {
147 
155  };
156 
158  {
165  };
166 
168 
169  struct TexExtrema
170  {
172 
173  // min of data in memory (for OpenGL: between 0 and 1)
174  std::vector<float> min;
175  // max of data in memory (for OpenGL: between 0 and 1)
176  std::vector<float> max;
177  // min of initial (quantified) data
178  std::vector<float> minquant;
179  // max of initial (quantified) data
180  std::vector<float> maxquant;
181  bool scaled;
182  };
183 
184  struct TexInfo;
185 
187  virtual ~GLComponent();
188 
189  void clearLists();
190 
191  virtual const GLComponent* glAPI() const { return this; }
192  virtual GLComponent* glAPI() { return this; }
193  virtual const Sliceable* sliceableAPI() const { return 0; }
194  virtual Sliceable* sliceableAPI() { return 0; }
195 
196  virtual void glClearHasChangedFlags() const;
197  virtual void glSetChanged( glPart, bool = true ) const;
198  virtual bool glHasChanged( glPart ) const;
199 
200  void setShader(const Shader &shader);
201  void removeShader();
203  void setupShader();
204  const Shader *getShader() const;
205  Shader *getShader();
206  virtual void setShaderParameters(const Shader &shader,
207  const ViewState & state) const;
208 
209  virtual const Material *glMaterial() const;
210  virtual const AObjectPalette* glPalette( unsigned tex = 0 ) const;
211 
212  virtual unsigned glNumVertex( const ViewState & ) const;
213  virtual const GLfloat* glVertexArray( const ViewState & ) const;
215  virtual const GLfloat* glNormalArray( const ViewState & ) const;
217  virtual unsigned glPolygonSize( const ViewState & ) const;
218  virtual unsigned glNumPolygon( const ViewState & ) const;
219  virtual const GLuint* glPolygonArray( const ViewState & ) const;
222  virtual unsigned long glMaxNumDisplayedPolygons() const;
223  virtual void glSetMaxNumDisplayedPolygons( unsigned long n );
224  static unsigned long glGlobalMaxNumDisplayedPolygons();
225  static void glSetGlobalMaxNumDisplayedPolygons( unsigned long n );
226 
227  // Texturing functions
228  virtual void glSetTexImageChanged( bool x = true,
229  unsigned tex = 0 ) const ;
230  virtual void glSetTexEnvChanged( bool x = true, unsigned tex = 0 ) const;
231  virtual unsigned glNumTextures() const;
232  virtual unsigned glNumTextures( const ViewState & ) const;
233  virtual glTextureMode glTexMode( unsigned tex = 0 ) const;
234  virtual void glSetTexMode( glTextureMode mode, unsigned tex = 0 );
235  virtual float glTexRate( unsigned tex = 0 ) const;
236  virtual void glSetTexRate( float rate, unsigned tex = 0 );
237  virtual glTextureFiltering glTexFiltering( unsigned tex = 0 ) const;
238  virtual void glSetTexFiltering( glTextureFiltering x, unsigned tex = 0 );
239  virtual glAutoTexturingMode glAutoTexMode( unsigned tex = 0 ) const;
241  unsigned tex = 0 );
242  virtual const float *glAutoTexParams( unsigned coord = 0,
243  unsigned tex = 0 ) const;
244  virtual void glSetAutoTexParams( const float* params, unsigned coord = 0,
245  unsigned tex = 0 );
246  virtual bool glTexImageChanged( unsigned tex = 0 ) const;
247  virtual bool glTexEnvChanged( unsigned tex = 0 ) const;
248  virtual GLint glGLTexMode( unsigned tex = 0) const;
249  virtual GLint glGLTexFiltering( unsigned tex = 0 ) const;
250  virtual void glSetTexRGBInterpolation( bool x, unsigned tex = 0 );
251  virtual bool glTexRGBInterpolation( unsigned tex = 0 ) const;
253  virtual unsigned glDimTex( const ViewState &, unsigned tex = 0 ) const;
255  virtual unsigned glTexCoordSize( const ViewState &,
256  unsigned tex = 0 ) const;
257  virtual const GLfloat* glTexCoordArray( const ViewState &,
258  unsigned tex = 0 ) const;
259  virtual const TexExtrema & glTexExtrema( unsigned tex = 0 ) const;
260  virtual TexExtrema & glTexExtrema( unsigned tex = 0 );
261 
262  virtual GLPrimitives glMainGLL( const ViewState & );
278  virtual void glGarbageCollector( int nkept = -1 );
282  unsigned glStateMemory() const;
283  virtual void glSetStateMemory( unsigned n );
284 
289  virtual bool glMakeBodyGLL( const ViewState & state,
290  const GLList & gllist ) const;
292  virtual void glBeforeBodyGLL( const ViewState & state,
293  GLPrimitives & pl ) const;
295  virtual void glAfterBodyGLL( const ViewState & state,
296  GLPrimitives & pl ) const;
311  const ViewState & state, unsigned tex, int dimx = -1,
312  int dimy = -1, bool useTexScale = true ) const;
321  virtual bool glMakeTexImage( const ViewState & state,
322  const GLTexture & gltex, unsigned tex ) const;
323  virtual bool glMakeTexEnvGLL( const ViewState & state,
324  const GLList & gllist, unsigned tex ) const;
325 
326  virtual GLPrimitives glBodyGLL( const ViewState & state ) const;
327  virtual GLPrimitives glMaterialGLL( const ViewState & state ) const;
329  unsigned tex = 0 ) const;
330  virtual GLPrimitives glTexEnvGLL( const ViewState &,
331  unsigned tex = 0 ) const;
332  virtual void glSetMainGLL( const std::string & state, GLPrimitives x );
333  virtual void glSetBodyGLL( const std::string & state, RefGLItem x );
334  virtual void glSetMaterialGLL( const std::string & state, RefGLItem x );
335  virtual void glSetTexNameGLL( const std::string & state, RefGLItem x,
336  unsigned tex = 0 );
338  virtual std::set<glTextureMode>
339  glAllowedTexModes( unsigned tex = 0 ) const;
340  virtual std::set<glTextureFiltering>
341  glAllowedTexFilterings( unsigned tex = 0 ) const;
342  virtual std::set<glAutoTexturingMode>
343  glAllowedAutoTexModes( unsigned tex = 0 ) const;
344  virtual bool glAllowedTexRGBInterpolation( unsigned tex = 0 ) const;
345  virtual bool glAllowedTexRate( unsigned tex = 0 ) const;
346 
357  virtual std::string viewStateID( glPart part, const ViewState & ) const;
358  virtual carto::Object debugInfo() const;
359 
362  const Referential* myref );
366  const Referential* myref );
367  int glObjectID() const;
368  virtual TexInfo & glTexInfo( unsigned tex = 0 ) const;
369 
370  protected:
371  void glAddTextures( unsigned ntex = 1 );
372 
373  private:
374  struct Private;
375  Private *d;
376  Shader *_shader;
377  };
378 
379 
380  inline void GLComponent::setShader(const Shader &shader)
381  {
382  if (_shader) delete _shader;
383  _shader = new Shader(shader);
385  }
386  inline void GLComponent::removeShader(void)
387  {
388  if (_shader)
389  {
390  delete _shader;
391  _shader = NULL;
393  }
394  }
395  inline const Material *GLComponent::glMaterial() const { return 0; }
396  inline const Shader *GLComponent::getShader() const { return _shader; }
397  inline Shader *GLComponent::getShader() { return _shader; }
398  inline void GLComponent::setShaderParameters(const Shader &shader, const ViewState & state) const { shader.setShaderParameters(*this, state); }
399  inline const AObjectPalette* GLComponent::glPalette( unsigned ) const
400  { return 0; }
401  inline unsigned GLComponent::glNumVertex( const ViewState & ) const
402  { return 0; }
403  inline const GLfloat* GLComponent::glVertexArray( const ViewState & ) const
404  { return 0; }
405  inline const GLfloat* GLComponent::glNormalArray( const ViewState & ) const
406  { return 0; }
407  inline unsigned GLComponent::glPolygonSize( const ViewState & ) const
408  { return 3; }
409  inline unsigned GLComponent::glNumPolygon( const ViewState & ) const
410  { return 0; }
411  inline const GLuint* GLComponent::glPolygonArray( const ViewState & ) const
412  { return 0; }
413 
414  inline unsigned GLComponent::glDimTex( const ViewState &, unsigned ) const
415  { return 1; }
416  inline unsigned GLComponent::glTexCoordSize( const ViewState &,
417  unsigned ) const
418  { return 0; }
419  inline const GLfloat* GLComponent::glTexCoordArray( const ViewState &,
420  unsigned ) const
421  { return 0; }
422 
423 }
424 
425 
426 #endif
427 
428 
Base class for all OpenGL objects in Anatomist (with OpenGL display lists)
Definition: glcomponent.h:67
virtual void glSetBodyGLL(const std::string &state, RefGLItem x)
virtual void glBeforeBodyGLL(const ViewState &state, GLPrimitives &pl) const
GL list to execute before the body is rendered.
virtual bool glTexEnvChanged(unsigned tex=0) const
void setupShader()
create, setup, or remove the shader
glPart
GL object parts, each driving a GL list.
Definition: glcomponent.h:114
@ glGENERAL
General list, this one calls the others, so should be rebuilt when any other part changes.
Definition: glcomponent.h:119
@ glTEXENV_NUM
glTEXENV_NUM + 2* texnum flags texture #texnum, reserved for Observable pattern
Definition: glcomponent.h:154
@ glPALETTE
Palette settings.
Definition: glcomponent.h:134
@ glGEOMETRY
Geometry is the polygons, normals arrays.
Definition: glcomponent.h:130
@ glTEXENV
Texture environment part: activate texture units, bind textures, setup their properties.
Definition: glcomponent.h:146
@ glBODY
Body part: gathers vertices, polygons, normals, textures alltogether.
Definition: glcomponent.h:121
@ glMATERIAL
Material / coloring list.
Definition: glcomponent.h:124
@ glTEXIMAGE
Texture image part.
Definition: glcomponent.h:142
@ glREFERENTIAL
Coordinates transformations list.
Definition: glcomponent.h:136
@ glTEXIMAGE_NUM
glTEXIMAGE_NUM + 2* texnum flags texture #texnum, reserved for Observable pattern
Definition: glcomponent.h:151
virtual const AObjectPalette * glPalette(unsigned tex=0) const
Definition: glcomponent.h:399
virtual TexInfo & glTexInfo(unsigned tex=0) const
virtual void glSetTexRGBInterpolation(bool x, unsigned tex=0)
virtual void glSetAutoTexParams(const float *params, unsigned coord=0, unsigned tex=0)
virtual const GLfloat * glTexCoordArray(const ViewState &, unsigned tex=0) const
Definition: glcomponent.h:419
void setShader(const Shader &shader)
Definition: glcomponent.h:380
virtual bool glAllowedTexRate(unsigned tex=0) const
virtual unsigned glDimTex(const ViewState &, unsigned tex=0) const
texture dimension (1, 2 [or 3])
Definition: glcomponent.h:414
virtual std::set< glTextureFiltering > glAllowedTexFilterings(unsigned tex=0) const
virtual GLPrimitives glMainGLL(const ViewState &)
unsigned glStateMemory() const
Number of unused display lists in different states kept in memory (default: 4)
virtual bool glHasChanged(glPart) const
virtual unsigned glPolygonSize(const ViewState &) const
number of vertices per polygon (default = 3: triangles)
Definition: glcomponent.h:407
virtual bool glTexImageChanged(unsigned tex=0) const
virtual void glSetMaxNumDisplayedPolygons(unsigned long n)
virtual void setShaderParameters(const Shader &shader, const ViewState &state) const
Definition: glcomponent.h:398
virtual std::string viewStateID(glPart part, const ViewState &) const
Makes a unique ID from a viewstate.
virtual void glSetAutoTexMode(glAutoTexturingMode mode, unsigned tex=0)
virtual void glSetTexMode(glTextureMode mode, unsigned tex=0)
virtual bool glMakeBodyGLL(const ViewState &state, const GLList &gllist) const
If you want to make a non-standard GL display list for the body geometry, overload this function to f...
virtual GLComponent * glAPI()
Definition: glcomponent.h:192
virtual void glSetMainGLL(const std::string &state, GLPrimitives x)
virtual const Material * glMaterial() const
Definition: glcomponent.h:395
static void glSetGlobalMaxNumDisplayedPolygons(unsigned long n)
virtual glAutoTexturingMode glAutoTexMode(unsigned tex=0) const
virtual void glClearHasChangedFlags() const
virtual const GLfloat * glNormalArray(const ViewState &) const
normals array (optional), default=0 (no normals, flat shaded faces)
Definition: glcomponent.h:405
virtual Sliceable * sliceableAPI()
Definition: glcomponent.h:194
void glAddTextures(unsigned ntex=1)
virtual glTextureMode glTexMode(unsigned tex=0) const
virtual GLint glGLTexFiltering(unsigned tex=0) const
virtual bool glMakeTexImage(const ViewState &state, const GLTexture &gltex, unsigned tex) const
If you make non-standard textures (ie not from a palette), overload this function to fill gltex.
virtual bool glTexRGBInterpolation(unsigned tex=0) const
static unsigned long glGlobalMaxNumDisplayedPolygons()
virtual GLint glGLTexMode(unsigned tex=0) const
virtual void glSetTexEnvChanged(bool x=true, unsigned tex=0) const
static GLPrimitives glPopTransformation(const ViewState &vs, const Referential *myref)
called after glHandleTransformation() and glMainGLL() to pop the transformation matrix
virtual carto::Object debugInfo() const
virtual GLPrimitives glTexNameGLL(const ViewState &, unsigned tex=0) const
virtual GLPrimitives glBodyGLL(const ViewState &state) const
virtual void glSetStateMemory(unsigned n)
virtual bool glAllowedTexRGBInterpolation(unsigned tex=0) const
virtual const TexExtrema & glTexExtrema(unsigned tex=0) const
virtual void glSetMaterialGLL(const std::string &state, RefGLItem x)
virtual void glSetTexImageChanged(bool x=true, unsigned tex=0) const
virtual std::set< glAutoTexturingMode > glAllowedAutoTexModes(unsigned tex=0) const
virtual GLPrimitives glMaterialGLL(const ViewState &state) const
virtual unsigned glNumPolygon(const ViewState &) const
Definition: glcomponent.h:409
virtual unsigned glNumTextures(const ViewState &) const
virtual void glAfterBodyGLL(const ViewState &state, GLPrimitives &pl) const
GL list to execute after the body is rendered.
virtual const float * glAutoTexParams(unsigned coord=0, unsigned tex=0) const
virtual GLPrimitives glTexEnvGLL(const ViewState &, unsigned tex=0) const
virtual const Sliceable * sliceableAPI() const
Definition: glcomponent.h:193
virtual carto::VolumeRef< AimsRGBA > glBuildTexImage(const ViewState &state, unsigned tex, int dimx=-1, int dimy=-1, bool useTexScale=true) const
If you make non-standard textures (ie not from a palette), overload this function.
virtual glTextureFiltering glTexFiltering(unsigned tex=0) const
virtual std::set< glTextureMode > glAllowedTexModes(unsigned tex=0) const
List of actually allowed texturing modes for this particular object.
virtual const GLComponent * glAPI() const
Definition: glcomponent.h:191
ViewState::glSelectRenderMode glSelectRenderMode
Definition: glcomponent.h:167
virtual unsigned long glMaxNumDisplayedPolygons() const
Limit to the number of displayed polygons (default: 0, unlimited or ) global default value)
virtual bool glMakeTexEnvGLL(const ViewState &state, const GLList &gllist, unsigned tex) const
virtual void glSetTexFiltering(glTextureFiltering x, unsigned tex=0)
virtual float glTexRate(unsigned tex=0) const
virtual void glSetTexNameGLL(const std::string &state, RefGLItem x, unsigned tex=0)
virtual void glGarbageCollector(int nkept=-1)
Frees unused display lists.
virtual const GLuint * glPolygonArray(const ViewState &) const
Definition: glcomponent.h:411
virtual TexExtrema & glTexExtrema(unsigned tex=0)
static GLPrimitives glHandleTransformation(const ViewState &vs, const Referential *myref)
helper function used in AObject::render()
virtual const GLfloat * glVertexArray(const ViewState &) const
Definition: glcomponent.h:403
virtual void glSetTexRate(float rate, unsigned tex=0)
const Shader * getShader() const
Definition: glcomponent.h:396
virtual unsigned glNumTextures() const
virtual unsigned glTexCoordSize(const ViewState &, unsigned tex=0) const
texture array size (must be >= numVertex to work), defalut=0
Definition: glcomponent.h:416
virtual unsigned glNumVertex(const ViewState &) const
Definition: glcomponent.h:401
virtual void glSetChanged(glPart, bool=true) const
This class has to be rewritten, it's really really a shame.......
Definition: Material.h:48
Referential: marker for transformations, with an associated color.
Definition: Referential.h:55
void setShaderParameters(const GLComponent &obj, const ViewState &state) const
Sliceable objects can draw themselves in a 2D texture.
Definition: sliceable.h:59
std::list< RefGLItem > GLPrimitives
Definition: primitive.h:156
std::vector< float > minquant
Definition: glcomponent.h:178
std::vector< float > maxquant
Definition: glcomponent.h:180
ViewState holds information about how a view wants to see an object.
Definition: viewstate.h:67