Salome HOME
4c9f73eba001d95b2b7d684bfe1a3c5c53446c5c
[modules/gui.git] / src / VTKViewer / VTKViewer_Actor.h
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
24 //  File   : SALOME_Actor.h
25 //  Author : Nicolas REJNERI
26
27 #ifndef VTKVIEVER_ACTOR_H
28 #define VTKVIEVER_ACTOR_H
29
30 #include "VTKViewer.h"
31
32 #include <string>
33 #include <vector>
34 #include <limits>
35
36 #include <NCollection_IndexedMap.hxx>
37 #include <NCollection_Map.hxx>
38
39 #include <vtkLODActor.h>
40 #include <vtkProperty.h>
41
42 class vtkCell;
43 class vtkPointPicker;
44 class vtkCellPicker;
45 class vtkDataSet;
46 class vtkCamera;
47 class vtkProperty;
48 class vtkRenderer;
49 class vtkPassThroughFilter;
50
51 class VTKViewer_Transform;
52 class VTKViewer_GeometryFilter;
53 class VTKViewer_TransformFilter;
54
55 extern int VTKViewer_POINT_SIZE;
56 extern int VTKViewer_LINE_WIDTH;
57
58 namespace VTKViewer
59 {
60   namespace Representation
61   {
62     typedef int Type;
63     const Type Points = VTK_POINTS;
64     const Type Wireframe = VTK_WIREFRAME;
65     const Type Surface = VTK_SURFACE;
66     const Type Insideframe = Surface + 1;
67     const Type SurfaceWithEdges = Insideframe + 1;
68   }
69 }
70
71 #ifdef WIN32
72 #pragma warning ( disable:4251 )
73 #endif
74
75 /*! \class vtkLODActor
76  * \brief For more information see <a href="http://www.vtk.org/">VTK documentation</a>
77  */
78 class VTKVIEWER_EXPORT VTKViewer_Actor : public vtkLODActor 
79 {
80  public:
81   static VTKViewer_Actor* New();
82   
83   vtkTypeMacro(VTKViewer_Actor,vtkLODActor)
84
85   //----------------------------------------------------------------------------
86   //! Get its name
87   virtual 
88   const char* 
89   getName();
90
91   //! Name the #VTKViewer_Actor
92   virtual
93   void
94   setName(const char* theName);
95
96   //----------------------------------------------------------------------------
97   //! Change opacity
98   virtual
99   void
100   SetOpacity(double theOpacity);
101
102   //! Get current opacity
103   virtual
104   double 
105   GetOpacity();
106
107   //! Change color
108   virtual
109   void
110   SetColor(double r,
111            double g,
112            double b);
113
114   //! Get current color
115   virtual
116   void
117   GetColor(double& r,
118            double& g,
119            double& b);
120
121   //! Change color
122   virtual
123   void
124   SetColor(const double theRGB[3]);
125
126   //! Change material
127   virtual
128   void
129   SetMaterial(std::vector<vtkProperty*> theProps);
130
131   //! Get current front material
132   virtual
133   vtkProperty* 
134   GetFrontMaterial();
135
136   //! Get current back material
137   virtual
138   vtkProperty* 
139   GetBackMaterial();
140
141   //----------------------------------------------------------------------------
142   // For selection mapping purpose
143   //! Maps VTK index of a node to corresponding object index
144   virtual
145   vtkIdType 
146   GetNodeObjId(vtkIdType theVtkID);
147
148   //! Get coordinates of a node for given object index
149   virtual
150   double*
151   GetNodeCoord(vtkIdType theObjID);
152
153   //! Maps object index of a node to corresponding VTK index
154   virtual
155   vtkIdType 
156   GetNodeVtkId(vtkIdType theObjID);
157
158   //! Maps VTK index of a cell to corresponding object index
159   virtual 
160   vtkIdType
161   GetElemObjId(vtkIdType theVtkID);
162
163   //! Get corresponding #vtkCell for given object index
164   virtual
165   vtkCell* 
166   GetElemCell(vtkIdType theObjID);
167
168   //----------------------------------------------------------------------------
169   //! Get dimension of corresponding mesh element
170   virtual
171   int
172   GetObjDimension( const vtkIdType theObjId );
173
174   //! To insert some additional filters and then sets the given #vtkMapper
175   virtual
176   void
177   SetMapper(vtkMapper* theMapper); 
178
179   //! Allows to get initial #vtkDataSet
180   virtual
181   vtkDataSet* 
182   GetInput(); 
183
184   //! Apply view transformation
185   virtual
186   void
187   SetTransform(VTKViewer_Transform* theTransform); 
188
189   //! To calculatate last modified time
190   virtual
191   vtkMTimeType
192   GetMTime();
193
194   //----------------------------------------------------------------------------
195   //! Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
196   virtual
197   void
198   SetRepresentation(int theMode);
199
200   //! Get current representation mode
201   virtual
202   int
203   GetRepresentation();
204
205   //! Get current display mode (obsolete)
206   virtual
207   int
208   getDisplayMode();
209
210   //! Set display mode (obsolete)
211   virtual
212   void
213   setDisplayMode(int theMode);
214
215   //----------------------------------------------------------------------------
216   //! Set infinive flag
217   /*!
218     Infinitive means actor without size (point for example),
219     which is not taken into account in calculation of boundaries of the scene
220   */
221   void
222   SetInfinitive(bool theIsInfinite);
223
224   //! Get infinive flag
225   virtual
226   bool
227   IsInfinitive();
228     
229   //! To calcualte current bounding box
230   virtual
231   double* 
232   GetBounds();
233
234   //! To calcualte current bounding box
235   void
236   GetBounds(double bounds[6]);
237
238   //----------------------------------------------------------------------------
239   virtual
240   bool
241   IsSetCamera() const;
242
243   virtual
244   bool
245   IsResizable() const;
246
247   virtual
248   void
249   SetSize( const double );
250
251   virtual
252   void 
253   SetCamera( vtkCamera* );
254
255   //----------------------------------------------------------------------------
256   //! Set ResolveCoincidentTopology flag
257   void
258   SetResolveCoincidentTopology(bool theIsResolve);
259
260   //! Set ResolveCoincidentTopology parameters
261   void
262   SetPolygonOffsetParameters(double factor, 
263                              double units);
264
265   //! Get current ResolveCoincidentTopology parameters
266   void
267   GetPolygonOffsetParameters(double& factor, 
268                              double& units);
269   
270   //! Get default ResolveCoincidentTopology parameters
271   static 
272   void
273   GetDefaultPolygonOffsetParameters(double& factor, 
274                                     double& units);
275
276   virtual
277   void
278   Render(vtkRenderer *, vtkMapper *);
279
280   //----------------------------------------------------------------------------
281   //! Get current shrink factor
282   virtual
283   double
284   GetShrinkFactor();
285
286   //! Is the actor is shrunkable
287   virtual
288   bool
289   IsShrunkable();
290
291   //! Is the actor is shrunk
292   virtual
293   bool
294   IsShrunk();
295
296   //! Insert shrink filter into pipeline
297   virtual
298   void
299   SetShrink();
300
301   //! Remove shrink filter from pipeline
302   virtual
303   void
304   UnShrink();
305
306   //----------------------------------------------------------------------------
307   //! To publish the actor an all its internal devices
308   virtual
309   void
310   AddToRender(vtkRenderer* theRendere); 
311
312   //! To remove the actor an all its internal devices
313   virtual
314   void
315   RemoveFromRender(vtkRenderer* theRendere);
316
317   //! Used to obtain all dependent actors
318   virtual
319   void
320   GetChildActors(vtkActorCollection*);
321
322   //----------------------------------------------------------------------------
323   //! Is notified on enabling/disabling selection
324   virtual
325   void
326   EnableSelection( bool /*enable*/ ) {}
327
328   //! Ask, if the descendant of the VTKViewer_Actor will implement its own highlight or not
329   virtual
330   bool
331   hasHighlight(); 
332
333   //! Ask, if the VTKViewer_Actor is already highlighted
334   virtual
335   bool
336   isHighlighted();
337
338   //! Ask, if the VTKViewer_Actor is already preselected
339   virtual
340   bool
341   isPreselected();
342
343   //! Set preselection mode
344   virtual
345   void
346   SetPreSelected(bool thePreselect = false);
347
348   //----------------------------------------------------------------------------
349   //! Just to update visibility of the highlight devices
350   virtual
351   void
352   highlight(bool theHighlight);  
353
354   void
355   SetPreviewProperty(vtkProperty* theProperty);
356
357   //----------------------------------------------------------------------------
358   //! Setting for displaying quadratic elements
359   virtual void SetQuadraticArcMode(bool theFlag);
360   virtual bool GetQuadraticArcMode() const;
361
362   virtual void   SetQuadraticArcAngle(double theMaxAngle);
363   virtual double GetQuadraticArcAngle() const;
364
365   //----------------------------------------------------------------------------
366   //! Return pointer to the dataset, which used to calculation of the bounding box of the actor
367   virtual vtkDataSet* GetHighlightedDataSet();
368
369  protected:
370   //----------------------------------------------------------------------------
371   bool myIsResolveCoincidentTopology;
372   double myPolygonOffsetFactor;
373   double myPolygonOffsetUnits;
374
375   std::string myName;
376
377   double myOpacity;
378   int myDisplayMode;
379   bool myIsInfinite;
380
381   bool myStoreMapping;
382   VTKViewer_GeometryFilter *myGeomFilter;
383   VTKViewer_TransformFilter *myTransformFilter;
384   std::vector<vtkPassThroughFilter*> myPassFilter;
385
386   int myRepresentation;
387   vtkProperty *myProperty;
388
389   void
390   InitPipeLine(vtkMapper* theMapper); 
391
392   VTKViewer_Actor();
393   ~VTKViewer_Actor();
394
395  protected:
396   vtkProperty *PreviewProperty;
397   bool myIsPreselected;
398   bool myIsHighlighted;
399 };
400
401 struct vtkIdHasher
402 {
403   static int HashCode(const vtkIdType theValue,  const int theUpperBound)
404   {
405     return static_cast<int> ((theValue & (std::numeric_limits<vtkIdType>::max)()) % theUpperBound + 1);
406   }
407
408   static bool IsEqual( const vtkIdType& id1, const vtkIdType& id2 )
409   {
410     return id1 == id2;
411   }
412 };
413
414 typedef NCollection_Map< vtkIdType, vtkIdHasher > TVtkIDsMap;
415 typedef NCollection_IndexedMap<vtkIdType,vtkIdHasher> TIndexedMapOfVtkId;
416
417 #ifdef WIN32
418 #pragma warning ( default:4251 )
419 #endif
420
421 #endif // VTKVIEVER_ACTOR_H