Salome HOME
d7e3783105c16bc14c60eb11cd2a34422a0c1979
[modules/gui.git] / src / VTKViewer / VTKViewer_PolyDataMapper.h
1 // Copyright (C) 2007-2013  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.
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 WNT
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 //----------------------------------------------------------------------------
47 //! OpenGL Point Sprites PolyData Mapper.
48 /*!
49  * VTKViewer_PolyDataMapper is a class that maps polygonal data 
50  * (i.e., vtkPolyData) to graphics primitives. It is performing the mapping
51  * to the rendering/graphics hardware/software. It is now possible to set a 
52  * memory limit for the pipeline in the mapper. If the total estimated memory 
53  * usage of the pipeline is larger than this limit, the mapper will divide 
54  * the data into pieces and render each in a for loop.
55  */
56 class VTKVIEWER_EXPORT VTKViewer_PolyDataMapper : public MAPPER_SUPERCLASS
57 {
58 public:
59   enum ExtensionsState { ES_None = 0, ES_Error, ES_Ok };
60
61 public:
62   static VTKViewer_PolyDataMapper* New();
63   vtkTypeMacro( VTKViewer_PolyDataMapper, MAPPER_SUPERCLASS );
64
65   //! Set point marker enabled
66   void SetMarkerEnabled( bool );
67
68   //! Set point ball enabled
69   void SetBallEnabled( bool );
70   
71   bool GetBallEnabled( );
72
73   //! Set standard point marker
74   void SetMarkerStd( VTK::MarkerType, VTK::MarkerScale );
75
76   //! Set custom point marker
77   void SetMarkerTexture( int, VTK::MarkerTexture );
78
79   //! Get type of the point marker
80   VTK::MarkerType GetMarkerType();
81
82   //! Get scale of the point marker
83   VTK::MarkerScale GetMarkerScale();
84
85   //! Get texture identifier of the point marker
86   int GetMarkerTexture();
87
88   //! Implement superclass render method.
89   virtual void RenderPiece( vtkRenderer*, vtkActor* );
90
91   //! Draw method for OpenGL.
92   virtual int Draw( vtkRenderer*, vtkActor* );
93
94 protected:
95   VTKViewer_PolyDataMapper();
96   ~VTKViewer_PolyDataMapper();
97
98   //! Initializing OpenGL extensions.
99   int               InitExtensions();
100
101   //! Activate Point Sprites.
102   void              InitPointSprites();
103
104   //! Deactivate Point Sprites.
105   void              CleanupPointSprites();
106
107   //! Initializing textures for Point Sprites.
108   void              InitTextures();
109
110   //! Initializing of the Vertex Shader.
111   void              InitShader();
112
113 private:
114   int               ExtensionsInitialized;
115
116   GLuint            PointSpriteTexture;
117
118   vtkSmartPointer<vtkImageData> ImageData;
119   
120   GLhandleARB       VertexProgram;
121
122   bool              MarkerEnabled;
123   bool              BallEnabled;  
124   VTK::MarkerType   MarkerType;
125   VTK::MarkerScale  MarkerScale;
126   int               MarkerId;
127
128   typedef std::map< int, vtkSmartPointer<vtkImageData> > ImageDataMap;
129   ImageDataMap      StandardTextures;
130   ImageDataMap      CustomTextures;
131   ImageDataMap      SpecialTextures;  //special predefined textures, used to draw point sprites.
132 };
133
134 #endif