Salome HOME
7e8262c326d2c11aa98191bb17973f4d1caa051c
[modules/gui.git] / src / VTKViewer / VTKViewer_PolyDataMapper.h
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef VTKViewer_POLYDATAMAPPER_H
21 #define VTKViewer_POLYDATAMAPPER_H
22
23 #include "VTKViewer.h"
24 #include "VTKViewer_MarkerDef.h"
25
26 #ifdef WIN32
27 #include <windows.h>
28 #endif
29
30 #include <map>
31
32 #include <GL/gl.h>
33
34 #include <vtkSmartPointer.h>
35
36 class vtkImageData;
37
38 #ifndef VTK_IMPLEMENT_MESA_CXX
39 #include <vtkOpenGLPolyDataMapper.h>
40 #define MAPPER_SUPERCLASS vtkOpenGLPolyDataMapper
41 #else
42 #include <vtkMesaPolyDataMapper.h>
43 #define MAPPER_SUPERCLASS vtkMesaPolyDataMapper
44 #endif
45
46 #ifndef GL_ARB_shader_objects
47 typedef GLuint GLhandleARB;
48 #endif
49
50
51 //----------------------------------------------------------------------------
52 //! OpenGL Point Sprites PolyData Mapper.
53 /*!
54  * VTKViewer_PolyDataMapper is a class that maps polygonal data 
55  * (i.e., vtkPolyData) to graphics primitives. It is performing the mapping
56  * to the rendering/graphics hardware/software. It is now possible to set a 
57  * memory limit for the pipeline in the mapper. If the total estimated memory 
58  * usage of the pipeline is larger than this limit, the mapper will divide 
59  * the data into pieces and render each in a for loop.
60  */
61 class VTKVIEWER_EXPORT VTKViewer_PolyDataMapper : public MAPPER_SUPERCLASS
62 {
63 public:
64   enum ExtensionsState { ES_None = 0, ES_Error, ES_Ok };
65
66 public:
67   static VTKViewer_PolyDataMapper* New();
68   vtkTypeMacro( VTKViewer_PolyDataMapper, MAPPER_SUPERCLASS );
69
70   //! Set point marker enabled
71   void SetMarkerEnabled( bool );
72
73   //! Set point ball enabled
74   void SetBallEnabled( bool );
75   
76   bool GetBallEnabled( );
77
78   //! Set standard point marker
79   void SetMarkerStd( VTK::MarkerType, VTK::MarkerScale );
80
81   //! Set custom point marker
82   void SetMarkerTexture( int, VTK::MarkerTexture );
83
84   //! Get type of the point marker
85   VTK::MarkerType GetMarkerType();
86
87   //! Get scale of the point marker
88   VTK::MarkerScale GetMarkerScale();
89
90   //! Get texture identifier of the point marker
91   int GetMarkerTexture();
92
93   //! Implement superclass render method.
94   virtual void RenderPiece( vtkRenderer*, vtkActor* );
95
96   //! Draw method for OpenGL.
97   virtual int Draw( vtkRenderer*, vtkActor* );
98
99 protected:
100   VTKViewer_PolyDataMapper();
101   ~VTKViewer_PolyDataMapper();
102
103   //! Initializing OpenGL extensions.
104   int               InitExtensions();
105
106   //! Activate Point Sprites.
107   void              InitPointSprites();
108
109   //! Deactivate Point Sprites.
110   void              CleanupPointSprites();
111
112   //! Initializing textures for Point Sprites.
113   void              InitTextures();
114
115   //! Initializing of the Vertex Shader.
116   void              InitShader();
117
118 private:
119   int               ExtensionsInitialized;
120
121   GLuint            PointSpriteTexture;
122
123   vtkSmartPointer<vtkImageData> ImageData;
124   
125   GLhandleARB       VertexProgram;
126
127   bool              MarkerEnabled;
128   bool              BallEnabled;  
129   VTK::MarkerType   MarkerType;
130   VTK::MarkerScale  MarkerScale;
131   int               MarkerId;
132
133   typedef std::map< int, vtkSmartPointer<vtkImageData> > ImageDataMap;
134   ImageDataMap      StandardTextures;
135   ImageDataMap      CustomTextures;
136   ImageDataMap      SpecialTextures;  //special predefined textures, used to draw point sprites.
137 };
138
139 #endif