anatomist  5.0.5
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  {
171  TexExtrema();
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 
186  GLComponent();
187  virtual ~GLComponent();
188 
189  virtual const GLComponent* glAPI() const { return this; }
190  virtual GLComponent* glAPI() { return this; }
191  virtual const Sliceable* sliceableAPI() const { return 0; }
192  virtual Sliceable* sliceableAPI() { return 0; }
193 
194  virtual void glClearHasChangedFlags() const;
195  virtual void glSetChanged( glPart, bool = true ) const;
196  virtual bool glHasChanged( glPart ) const;
197 
198  void setShader(const Shader &shader);
199  void removeShader();
201  void setupShader();
202  const Shader *getShader() const;
203  Shader *getShader();
204  virtual void setShaderParameters(const Shader &shader,
205  const ViewState & state) const;
206 
207  virtual const Material *glMaterial() const;
208  virtual const AObjectPalette* glPalette( unsigned tex = 0 ) const;
209 
210  virtual unsigned glNumVertex( const ViewState & ) const;
211  virtual const GLfloat* glVertexArray( const ViewState & ) const;
213  virtual const GLfloat* glNormalArray( const ViewState & ) const;
215  virtual unsigned glPolygonSize( const ViewState & ) const;
216  virtual unsigned glNumPolygon( const ViewState & ) const;
217  virtual const GLuint* glPolygonArray( const ViewState & ) const;
220  virtual unsigned long glMaxNumDisplayedPolygons() const;
221  virtual void glSetMaxNumDisplayedPolygons( unsigned long n );
222  static unsigned long glGlobalMaxNumDisplayedPolygons();
223  static void glSetGlobalMaxNumDisplayedPolygons( unsigned long n );
224 
225  // Texturing functions
226  virtual void glSetTexImageChanged( bool x = true,
227  unsigned tex = 0 ) const ;
228  virtual void glSetTexEnvChanged( bool x = true, unsigned tex = 0 ) const;
229  virtual unsigned glNumTextures() const;
230  virtual unsigned glNumTextures( const ViewState & ) const;
231  virtual glTextureMode glTexMode( unsigned tex = 0 ) const;
232  virtual void glSetTexMode( glTextureMode mode, unsigned tex = 0 );
233  virtual float glTexRate( unsigned tex = 0 ) const;
234  virtual void glSetTexRate( float rate, unsigned tex = 0 );
235  virtual glTextureFiltering glTexFiltering( unsigned tex = 0 ) const;
236  virtual void glSetTexFiltering( glTextureFiltering x, unsigned tex = 0 );
237  virtual glAutoTexturingMode glAutoTexMode( unsigned tex = 0 ) const;
238  virtual void glSetAutoTexMode( glAutoTexturingMode mode,
239  unsigned tex = 0 );
240  virtual const float *glAutoTexParams( unsigned coord = 0,
241  unsigned tex = 0 ) const;
242  virtual void glSetAutoTexParams( const float* params, unsigned coord = 0,
243  unsigned tex = 0 );
244  virtual bool glTexImageChanged( unsigned tex = 0 ) const;
245  virtual bool glTexEnvChanged( unsigned tex = 0 ) const;
246  virtual GLint glGLTexMode( unsigned tex = 0) const;
247  virtual GLint glGLTexFiltering( unsigned tex = 0 ) const;
248  virtual void glSetTexRGBInterpolation( bool x, unsigned tex = 0 );
249  virtual bool glTexRGBInterpolation( unsigned tex = 0 ) const;
251  virtual unsigned glDimTex( const ViewState &, unsigned tex = 0 ) const;
253  virtual unsigned glTexCoordSize( const ViewState &,
254  unsigned tex = 0 ) const;
255  virtual const GLfloat* glTexCoordArray( const ViewState &,
256  unsigned tex = 0 ) const;
257  virtual const TexExtrema & glTexExtrema( unsigned tex = 0 ) const;
258  virtual TexExtrema & glTexExtrema( unsigned tex = 0 );
259 
260  virtual GLPrimitives glMainGLL( const ViewState & );
276  virtual void glGarbageCollector( int nkept = -1 );
280  unsigned glStateMemory() const;
281  virtual void glSetStateMemory( unsigned n );
282 
287  virtual bool glMakeBodyGLL( const ViewState & state,
288  const GLList & gllist ) const;
290  virtual void glBeforeBodyGLL( const ViewState & state,
291  GLPrimitives & pl ) const;
293  virtual void glAfterBodyGLL( const ViewState & state,
294  GLPrimitives & pl ) const;
309  const ViewState & state, unsigned tex, int dimx = -1,
310  int dimy = -1, bool useTexScale = true ) const;
319  virtual bool glMakeTexImage( const ViewState & state,
320  const GLTexture & gltex, unsigned tex ) const;
321  virtual bool glMakeTexEnvGLL( const ViewState & state,
322  const GLList & gllist, unsigned tex ) const;
323 
324  virtual GLPrimitives glBodyGLL( const ViewState & state ) const;
325  virtual GLPrimitives glMaterialGLL( const ViewState & state ) const;
326  virtual GLPrimitives glTexNameGLL( const ViewState &,
327  unsigned tex = 0 ) const;
328  virtual GLPrimitives glTexEnvGLL( const ViewState &,
329  unsigned tex = 0 ) const;
330  virtual void glSetMainGLL( const std::string & state, GLPrimitives x );
331  virtual void glSetBodyGLL( const std::string & state, RefGLItem x );
332  virtual void glSetMaterialGLL( const std::string & state, RefGLItem x );
333  virtual void glSetTexNameGLL( const std::string & state, RefGLItem x,
334  unsigned tex = 0 );
336  virtual std::set<glTextureMode>
337  glAllowedTexModes( unsigned tex = 0 ) const;
338  virtual std::set<glTextureFiltering>
339  glAllowedTexFilterings( unsigned tex = 0 ) const;
340  virtual std::set<glAutoTexturingMode>
341  glAllowedAutoTexModes( unsigned tex = 0 ) const;
342  virtual bool glAllowedTexRGBInterpolation( unsigned tex = 0 ) const;
343  virtual bool glAllowedTexRate( unsigned tex = 0 ) const;
344 
355  virtual std::string viewStateID( glPart part, const ViewState & ) const;
356  virtual carto::Object debugInfo() const;
357 
359  static GLPrimitives glHandleTransformation( const ViewState & vs,
360  const Referential* myref );
363  static GLPrimitives glPopTransformation( const ViewState & vs,
364  const Referential* myref );
365  int glObjectID() const;
366  virtual TexInfo & glTexInfo( unsigned tex = 0 ) const;
367 
368  protected:
369  void glAddTextures( unsigned ntex = 1 );
370 
371  private:
372  struct Private;
373  Private *d;
374  Shader *_shader;
375  };
376 
377 
378  inline void GLComponent::setShader(const Shader &shader)
379  {
380  if (_shader) delete _shader;
381  _shader = new Shader(shader);
383  }
384  inline void GLComponent::removeShader(void)
385  {
386  if (_shader)
387  {
388  delete _shader;
389  _shader = NULL;
391  }
392  }
393  inline const Material *GLComponent::glMaterial() const { return 0; }
394  inline const Shader *GLComponent::getShader() const { return _shader; }
395  inline Shader *GLComponent::getShader() { return _shader; }
396  inline void GLComponent::setShaderParameters(const Shader &shader, const ViewState & state) const { shader.setShaderParameters(*this, state); }
397  inline const AObjectPalette* GLComponent::glPalette( unsigned ) const
398  { return 0; }
399  inline unsigned GLComponent::glNumVertex( const ViewState & ) const
400  { return 0; }
401  inline const GLfloat* GLComponent::glVertexArray( const ViewState & ) const
402  { return 0; }
403  inline const GLfloat* GLComponent::glNormalArray( const ViewState & ) const
404  { return 0; }
405  inline unsigned GLComponent::glPolygonSize( const ViewState & ) const
406  { return 3; }
407  inline unsigned GLComponent::glNumPolygon( const ViewState & ) const
408  { return 0; }
409  inline const GLuint* GLComponent::glPolygonArray( const ViewState & ) const
410  { return 0; }
411 
412  inline unsigned GLComponent::glDimTex( const ViewState &, unsigned ) const
413  { return 1; }
414  inline unsigned GLComponent::glTexCoordSize( const ViewState &,
415  unsigned ) const
416  { return 0; }
417  inline const GLfloat* GLComponent::glTexCoordArray( const ViewState &,
418  unsigned ) const
419  { return 0; }
420 
421 }
422 
423 
424 #endif
425 
426 
virtual const AObjectPalette * glPalette(unsigned tex=0) const
Definition: glcomponent.h:397
ViewState::glSelectRenderMode glSelectRenderMode
Definition: glcomponent.h:167
virtual const Sliceable * sliceableAPI() const
Definition: glcomponent.h:191
ViewState holds information about how a view wants to see an object.
Definition: viewstate.h:66
static GLPrimitives glHandleTransformation(const ViewState &vs, const Referential *myref)
helper function used in AObject::render()
virtual glTextureFiltering glTexFiltering(unsigned tex=0) const
virtual bool glMakeTexEnvGLL(const ViewState &state, const GLList &gllist, unsigned tex) const
virtual void glSetStateMemory(unsigned n)
virtual TexInfo & glTexInfo(unsigned tex=0) const
virtual void glSetTexFiltering(glTextureFiltering x, unsigned tex=0)
virtual bool glAllowedTexRGBInterpolation(unsigned tex=0) const
virtual void glSetAutoTexMode(glAutoTexturingMode mode, unsigned tex=0)
virtual GLComponent * glAPI()
Definition: glcomponent.h:190
Texture environment part: activate texture units, bind textures, setup their properties.
Definition: glcomponent.h:146
virtual GLint glGLTexFiltering(unsigned tex=0) const
std::vector< float > maxquant
Definition: glcomponent.h:180
General list, this one calls the others, so should be rebuilt when any other part changes...
Definition: glcomponent.h:119
virtual void glSetTexNameGLL(const std::string &state, RefGLItem x, unsigned tex=0)
virtual glAutoTexturingMode glAutoTexMode(unsigned tex=0) const
virtual GLPrimitives glMaterialGLL(const ViewState &state) const
virtual unsigned long glMaxNumDisplayedPolygons() const
Limit to the number of displayed polygons (default: 0, unlimited or ) global default value) ...
glTEXENV_NUM + 2* texnum flags texture #texnum, reserved for Observable pattern
Definition: glcomponent.h:154
virtual void glAfterBodyGLL(const ViewState &state, GLPrimitives &pl) const
GL list to execute after the body is rendered.
virtual GLPrimitives glMainGLL(const ViewState &)
virtual const Material * glMaterial() const
Definition: glcomponent.h:393
virtual std::set< glTextureFiltering > glAllowedTexFilterings(unsigned tex=0) const
static void glSetGlobalMaxNumDisplayedPolygons(unsigned long n)
virtual void glClearHasChangedFlags() const
Material / coloring list.
Definition: glcomponent.h:124
void glAddTextures(unsigned ntex=1)
virtual bool glTexEnvChanged(unsigned tex=0) const
virtual void glSetMaterialGLL(const std::string &state, RefGLItem x)
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 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 void glSetTexRate(float rate, unsigned tex=0)
virtual float glTexRate(unsigned tex=0) const
Body part: gathers vertices, polygons, normals, textures alltogether.
Definition: glcomponent.h:121
This class has to be rewritten, it&#39;s really really a shame.......
Definition: Material.h:47
virtual GLPrimitives glTexNameGLL(const ViewState &, unsigned tex=0) const
virtual std::string viewStateID(glPart part, const ViewState &) const
Makes a unique ID from a viewstate.
virtual const TexExtrema & glTexExtrema(unsigned tex=0) const
virtual void glSetTexEnvChanged(bool x=true, unsigned tex=0) const
virtual glTextureMode glTexMode(unsigned tex=0) const
virtual const GLComponent * glAPI() const
Definition: glcomponent.h:189
virtual unsigned glNumPolygon(const ViewState &) const
Definition: glcomponent.h:407
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 unsigned glPolygonSize(const ViewState &) const
number of vertices per polygon (default = 3: triangles)
Definition: glcomponent.h:405
virtual const float * glAutoTexParams(unsigned coord=0, unsigned tex=0) const
virtual const GLfloat * glTexCoordArray(const ViewState &, unsigned tex=0) const
Definition: glcomponent.h:417
virtual GLint glGLTexMode(unsigned tex=0) const
virtual const GLfloat * glNormalArray(const ViewState &) const
normals array (optional), default=0 (no normals, flat shaded faces)
Definition: glcomponent.h:403
void setupShader()
create, setup, or remove the shader
virtual carto::Object debugInfo() const
virtual bool glHasChanged(glPart) const
virtual Sliceable * sliceableAPI()
Definition: glcomponent.h:192
Coordinates transformations list.
Definition: glcomponent.h:136
static unsigned long glGlobalMaxNumDisplayedPolygons()
virtual void glSetTexMode(glTextureMode mode, unsigned tex=0)
virtual void glSetAutoTexParams(const float *params, unsigned coord=0, unsigned tex=0)
virtual bool glTexRGBInterpolation(unsigned tex=0) const
virtual unsigned glDimTex(const ViewState &, unsigned tex=0) const
texture dimension (1, 2 [or 3])
Definition: glcomponent.h:412
std::list< RefGLItem > GLPrimitives
Definition: primitive.h:156
Base class for all OpenGL objects in Anatomist (with OpenGL display lists)
Definition: glcomponent.h:66
virtual void glSetTexRGBInterpolation(bool x, unsigned tex=0)
void setShaderParameters(const GLComponent &obj, const ViewState &state) const
virtual unsigned glTexCoordSize(const ViewState &, unsigned tex=0) const
texture array size (must be >= numVertex to work), defalut=0
Definition: glcomponent.h:414
virtual unsigned glNumVertex(const ViewState &) const
Definition: glcomponent.h:399
const Shader * getShader() const
Definition: glcomponent.h:394
virtual unsigned glNumTextures() const
glPart
GL object parts, each driving a GL list.
Definition: glcomponent.h:113
virtual bool glAllowedTexRate(unsigned tex=0) const
virtual void glSetMaxNumDisplayedPolygons(unsigned long n)
virtual void glSetTexImageChanged(bool x=true, unsigned tex=0) const
virtual const GLfloat * glVertexArray(const ViewState &) const
Definition: glcomponent.h:401
virtual std::set< glTextureMode > glAllowedTexModes(unsigned tex=0) const
List of actually allowed texturing modes for this particular object.
virtual void glSetMainGLL(const std::string &state, GLPrimitives x)
Geometry is the polygons, normals arrays.
Definition: glcomponent.h:130
void setShader(const Shader &shader)
Definition: glcomponent.h:378
virtual bool glTexImageChanged(unsigned tex=0) const
virtual GLPrimitives glBodyGLL(const ViewState &state) const
virtual void glSetChanged(glPart, bool=true) const
Referential: marker for transformations, with an associated color.
Definition: Referential.h:54
static GLPrimitives glPopTransformation(const ViewState &vs, const Referential *myref)
called after glHandleTransformation() and glMainGLL() to pop the transformation matrix ...
glTEXIMAGE_NUM + 2* texnum flags texture #texnum, reserved for Observable pattern ...
Definition: glcomponent.h:151
std::vector< float > minquant
Definition: glcomponent.h:178
unsigned glStateMemory() const
Number of unused display lists in different states kept in memory (default: 4)
virtual const GLuint * glPolygonArray(const ViewState &) const
Definition: glcomponent.h:409
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 void glGarbageCollector(int nkept=-1)
Frees unused display lists.
Sliceable objects can draw themselves in a 2D texture.
Definition: sliceable.h:58
virtual std::set< glAutoTexturingMode > glAllowedAutoTexModes(unsigned tex=0) const
virtual void setShaderParameters(const Shader &shader, const ViewState &state) const
Definition: glcomponent.h:396
virtual GLPrimitives glTexEnvGLL(const ViewState &, unsigned tex=0) const