Salome HOME
Bug PAL7444 - display mesh takes a lot of more memory in 2.1.0 than in 2.0.0.
[modules/smesh.git] / src / OBJECT / SMESH_ActorDef.h
1 //  SMESH OBJECT : interactive object for SMESH visualization
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_ActorDef.h
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 #ifndef SMESH_ACTORDEF_H
30 #define SMESH_ACTORDEF_H
31
32 #include "SMESH_Actor.h"
33 #include "SMESH_Object.h"
34
35 #include <vtkSmartPointer.h>
36
37 template <class T>
38 class TVTKSmartPtr: public vtkSmartPointer<T>
39 {
40 public:
41   TVTKSmartPtr() {}
42   TVTKSmartPtr(T* r, bool theIsOwner = false): vtkSmartPointer<T>(r) { 
43     if(r && theIsOwner) 
44       r->Delete();
45   }
46   TVTKSmartPtr& operator()(T* r, bool theIsOwner = false){ 
47     vtkSmartPointer<T>::operator=(r); 
48     if(r && theIsOwner) 
49       r->Delete();
50     return *this;
51   }
52   TVTKSmartPtr& operator=(T* r){ vtkSmartPointer<T>::operator=(r); return *this;}
53   T* Get() const { return GetPointer();}
54 };
55
56
57 class vtkProperty;
58 class vtkShrinkFilter;
59 class vtkPolyDataMapper;
60 class vtkUnstructuredGrid;
61 class vtkMergeFilter;
62 class vtkPolyData;
63
64 class vtkMapper;
65 class vtkActor2D;
66 class vtkMaskPoints;
67 class vtkCellCenters;
68 class vtkLabeledDataMapper;
69 class vtkSelectVisiblePoints;
70
71 class vtkScalarBarActor;
72 class vtkLookupTable;
73
74 class vtkPlane;
75 class vtkImplicitBoolean;
76
77 class vtkTimeStamp;
78
79 class SMESH_DeviceActor;
80
81
82 class SMESH_ActorDef : public SMESH_Actor{
83   friend class SMESH_VisualObj;
84   friend class SMESH_Actor;
85
86  public:
87   vtkTypeMacro(SMESH_ActorDef,SMESH_Actor);
88   
89   virtual void ReleaseGraphicsResources(vtkWindow *renWin);
90   virtual int RenderOpaqueGeometry(vtkViewport *viewport);
91   virtual int RenderTranslucentGeometry(vtkViewport *viewport);
92   virtual void Render(vtkRenderer *ren);
93
94   virtual void AddToRender(vtkRenderer* theRenderer); 
95   virtual void RemoveFromRender(vtkRenderer* theRenderer);
96
97   virtual bool hasHighlight() { return true; }  
98   virtual void highlight(bool theHighlight);  
99   virtual void SetPreSelected(bool thePreselect = false);
100
101   virtual bool IsInfinitive();  
102
103   virtual void SetOpacity(float theValue);
104   virtual float GetOpacity();
105
106   virtual void SetSufaceColor(float r,float g,float b);
107   virtual void GetSufaceColor(float& r,float& g,float& b);
108
109   virtual void SetBackSufaceColor(float r,float g,float b);
110   virtual void GetBackSufaceColor(float& r,float& g,float& b);
111
112   virtual void SetEdgeColor(float r,float g,float b);
113   virtual void GetEdgeColor(float& r,float& g,float& b);
114
115   virtual void SetNodeColor(float r,float g,float b);
116   virtual void GetNodeColor(float& r,float& g,float& b);
117
118   virtual void SetHighlightColor(float r,float g,float b);
119   virtual void GetHighlightColor(float& r,float& g,float& b);
120
121   virtual void SetPreHighlightColor(float r,float g,float b);
122   virtual void GetPreHighlightColor(float& r,float& g,float& b);
123  
124   virtual float GetLineWidth();
125   virtual void SetLineWidth(float theVal);
126
127   virtual void SetNodeSize(float size) ;
128   virtual float GetNodeSize() ;
129
130   virtual int GetNodeObjId(int theVtkID);
131   virtual float* GetNodeCoord(int theObjID);
132
133   virtual int GetElemObjId(int theVtkID);
134   virtual vtkCell* GetElemCell(int theObjID);
135
136   virtual int GetObjDimension( const int theObjId );
137
138   virtual void SetVisibility(int theMode);
139   void SetVisibility(int theMode, bool theIsUpdateRepersentation);
140
141   virtual void SetRepresentation(int theMode);
142   
143   virtual unsigned int GetEntityMode() const { return myEntityMode;}
144   virtual void SetEntityMode(unsigned int theMode);
145
146   virtual void SetPointRepresentation(bool theIsPointsVisible);
147   virtual bool GetPointRepresentation();
148
149   virtual float* GetBounds();
150   virtual void SetTransform(SALOME_Transform* theTransform); 
151
152   virtual vtkUnstructuredGrid* GetUnstructuredGrid();
153   virtual vtkDataSet* GetInput();
154   virtual vtkMapper* GetMapper();
155
156   virtual float GetShrinkFactor();
157   virtual void SetShrinkFactor(float theValue);
158
159   virtual bool IsShrunkable() { return myIsShrinkable;}
160   virtual bool IsShrunk() { return myIsShrunk;}
161   virtual void SetShrink(); 
162   virtual void UnShrink(); 
163
164   virtual void SetPointsLabeled(bool theIsPointsLabeled);
165   virtual bool GetPointsLabeled(){ return myIsPointsLabeled;}
166
167   virtual void SetCellsLabeled(bool theIsCellsLabeled);
168   virtual bool GetCellsLabeled(){ return myIsCellsLabeled;}
169
170   virtual void SetControlMode(eControl theMode);
171   virtual eControl GetControlMode(){ return myControlMode;}
172
173   virtual vtkScalarBarActor* GetScalarBarActor(){ return myScalarBarActor;}
174
175   virtual void SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane);
176   virtual void GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane);
177
178   virtual void RemoveAllClippingPlanes();
179   virtual vtkIdType GetNumberOfClippingPlanes();
180   virtual vtkPlane* GetClippingPlane(vtkIdType theID);
181   virtual vtkIdType AddClippingPlane(vtkPlane* thePlane); 
182
183   virtual TVisualObjPtr GetObject() { return myVisualObj;}
184
185   virtual void SetControlsPrecision( const long p ) { myControlsPrecision = p; }
186   virtual long GetControlsPrecision() const { return myControlsPrecision; }
187
188  protected:
189   void SetControlMode(eControl theMode, bool theCheckEntityMode);
190   void SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed);
191   bool IsImplicitFunctionUsed() const;
192
193   TVisualObjPtr myVisualObj;
194   vtkTimeStamp* myTimeStamp;
195
196   vtkScalarBarActor* myScalarBarActor;
197   vtkLookupTable* myLookupTable;
198
199   vtkProperty* mySurfaceProp;
200   vtkProperty* myBackSurfaceProp;
201   vtkProperty* myEdgeProp;
202   vtkProperty* myNodeProp;
203
204   SMESH_DeviceActor* myBaseActor;
205   SMESH_DeviceActor* myNodeActor;
206   SMESH_DeviceActor* myPickableActor;
207
208   vtkProperty* myHighlightProp;
209   vtkProperty* myPreselectProp;
210   SMESH_DeviceActor* myHighlitableActor;
211
212   eControl myControlMode;
213   SMESH_DeviceActor* my2DActor;
214   SMESH_DeviceActor* my3DActor;
215   SMESH_DeviceActor* myControlActor;
216
217   vtkProperty* my1DProp;
218   SMESH_DeviceActor* my1DActor;
219   vtkProperty* my1DExtProp;
220   SMESH_DeviceActor* my1DExtActor;
221
222   unsigned int myEntityMode;
223   unsigned int myEntityState;
224   bool myIsPointsVisible;
225
226   bool myIsShrinkable;
227   bool myIsShrunk;
228   
229   bool myIsPointsLabeled;
230   vtkUnstructuredGrid* myPointsNumDataSet;
231   vtkActor2D *myPointLabels;
232   vtkMaskPoints* myPtsMaskPoints;
233   vtkLabeledDataMapper* myPtsLabeledDataMapper;
234   vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
235
236   bool myIsCellsLabeled;
237   vtkUnstructuredGrid* myCellsNumDataSet;
238   vtkActor2D *myCellsLabels;
239   vtkMaskPoints* myClsMaskPoints;
240   vtkCellCenters* myCellCenters;
241   vtkLabeledDataMapper* myClsLabeledDataMapper;
242   vtkSelectVisiblePoints* myClsSelectVisiblePoints;
243
244   vtkImplicitBoolean* myImplicitBoolean;
245   typedef TVTKSmartPtr<vtkPlane> TPlanePtr;
246   typedef std::vector<TPlanePtr> TCippingPlaneCont;
247   TCippingPlaneCont myCippingPlaneCont;
248   long myControlsPrecision;
249
250   SMESH_ActorDef();
251   ~SMESH_ActorDef();
252
253   bool Init(TVisualObjPtr theVisualObj, 
254             const char* theEntry, 
255             const char* theName,
256             int theIsClear);
257
258   void SetIsShrunkable(bool theShrunkable);
259   void UpdateHighlight();
260   void Update();
261
262  private:
263   // hide the two parameter Render() method from the user and the compiler.
264   virtual void Render(vtkRenderer *, vtkMapper *) {};
265   virtual void ShallowCopy(vtkProp *prop);
266   virtual void SetMapper(vtkMapper *);
267   static SMESH_ActorDef* New();
268
269   // Not implemented.
270   SMESH_ActorDef(const SMESH_ActorDef&);  
271   void operator=(const SMESH_ActorDef&);
272 };
273
274
275 #endif //SMESH_ACTORDEF_H