Salome HOME
Copyright update 2020
[modules/gui.git] / src / VTKViewer / VTKViewer_PolyDataMapper.h
1 // Copyright (C) 2007-2020  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 #ifdef __APPLE__
33 #include <OpenGL/gl.h>
34 #else
35 #include <GL/gl.h>
36 #endif
37
38 #include <vtkSmartPointer.h>
39
40 class vtkImageData;
41
42 #ifndef VTK_IMPLEMENT_MESA_CXX
43 #include <vtkOpenGLPolyDataMapper.h>
44 #define MAPPER_SUPERCLASS vtkOpenGLPolyDataMapper
45 #else
46 #include <vtkMesaPolyDataMapper.h>
47 #define MAPPER_SUPERCLASS vtkMesaPolyDataMapper
48 #endif
49
50 #include "VTKViewer_OpenGLHelper.h"
51
52 //----------------------------------------------------------------------------
53 //! OpenGL Point Sprites PolyData Mapper.
54 /*!
55  * VTKViewer_PolyDataMapper is a class that maps polygonal data 
56  * (i.e., vtkPolyData) to graphics primitives. It is performing the mapping
57  * to the rendering/graphics hardware/software. It is now possible to set a 
58  * memory limit for the pipeline in the mapper. If the total estimated memory 
59  * usage of the pipeline is larger than this limit, the mapper will divide 
60  * the data into pieces and render each in a for loop.
61  */
62 class VTKVIEWER_EXPORT VTKViewer_PolyDataMapper : public MAPPER_SUPERCLASS
63 {
64 public:
65   enum ExtensionsState { ES_None = 0, ES_Error, ES_Ok };
66
67 public:
68   static VTKViewer_PolyDataMapper* New();
69   vtkTypeMacro( VTKViewer_PolyDataMapper, MAPPER_SUPERCLASS );
70
71   //! Set point marker enabled
72   void SetMarkerEnabled( bool );
73
74   //! Set point ball enabled
75   void SetBallEnabled( bool );
76   
77   bool GetBallEnabled( );
78
79   //! Set ball scale factor
80   void SetBallScale( double );
81
82   double GetBallScale( );
83
84   //! Set standard point marker
85   void SetMarkerStd( VTK::MarkerType, VTK::MarkerScale );
86
87   //! Set custom point marker
88   void SetMarkerTexture( int, VTK::MarkerTexture );
89
90   //! Get type of the point marker
91   VTK::MarkerType GetMarkerType();
92
93   //! Get scale of the point marker
94   VTK::MarkerScale GetMarkerScale();
95
96   //! Get texture identifier of the point marker
97   int GetMarkerTexture();
98
99   //! Implement superclass render method.
100   virtual void RenderPiece( vtkRenderer*, vtkActor* );
101   //! Draw method for OpenGL.
102 #ifndef VTK_OPENGL2
103   virtual int Draw( vtkRenderer*, vtkActor* );
104 #else
105   virtual void RenderPieceDraw( vtkRenderer*, vtkActor* );
106 #endif    
107
108 protected:
109   VTKViewer_PolyDataMapper();
110   ~VTKViewer_PolyDataMapper();
111
112   //! Initializing OpenGL extensions.
113   int               InitExtensions();
114
115   //! Activate Point Sprites.
116   void              InitPointSprites();
117
118   //! Deactivate Point Sprites.
119   void              CleanupPointSprites();
120
121   //! Initializing textures for Point Sprites.
122   void              InitTextures();
123
124   //! Initializing of the Vertex Shader.
125   int               InitShader();
126
127   void              InternalDraw(vtkRenderer*, vtkActor*);
128
129 private:
130   int               ExtensionsInitialized;
131
132   GLuint            PointSpriteTexture;
133
134   vtkSmartPointer<vtkImageData> ImageData;
135
136   VTKViewer_OpenGLHelper OpenGLHelper;
137   GLhandleARB PointProgram;
138 #ifdef VTK_OPENGL2
139   GLhandleARB VertexShader;
140   GLhandleARB FragmentShader;
141   GLuint      VertexArrayObject;
142 #endif
143
144   struct Locations {
145     static const GLint INVALID_LOCATION = -1;
146
147     GLint ModelViewProjection;
148     GLint Projection;
149     GLint GeneralPointSize;
150     GLint PointSprite;
151
152     Locations()
153     : ModelViewProjection (INVALID_LOCATION),
154       Projection          (INVALID_LOCATION),
155       GeneralPointSize    (INVALID_LOCATION),
156       PointSprite         (INVALID_LOCATION)
157     {
158           //
159     }
160   } myLocations;
161
162   bool              MarkerEnabled;
163   bool              BallEnabled;
164   double            BallScale;
165   VTK::MarkerType   MarkerType;
166   VTK::MarkerScale  MarkerScale;
167   int               MarkerId;
168
169   typedef std::map< int, vtkSmartPointer<vtkImageData> > ImageDataMap;
170   ImageDataMap      StandardTextures;
171   ImageDataMap      CustomTextures;
172   ImageDataMap      SpecialTextures;  //special predefined textures, used to draw point sprites.
173 };
174
175 #endif