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