Salome HOME
Merge from OCC_development_generic_2006
[modules/gui.git] / src / VTKViewer / VTKViewer_Actor.h
1 //  SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
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   : SALOME_Actor.h
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef VTKVIEVER_ACTOR_H
30 #define VTKVIEVER_ACTOR_H
31
32 #include "VTKViewer.h"
33
34 #include <string>
35 #include <vector>
36
37 #include <vtkLODActor.h>
38
39 class vtkCell;
40 class vtkPointPicker;
41 class vtkCellPicker;
42 class vtkDataSet;
43 class vtkCamera;
44 class vtkProperty;
45 class vtkRenderer;
46
47 class VTKViewer_Transform;
48 class VTKViewer_GeometryFilter;
49 class VTKViewer_TransformFilter;
50 class VTKViewer_PassThroughFilter;
51
52 extern int VTKViewer_POINT_SIZE;
53 extern int VTKViewer_LINE_WIDTH;
54
55 /*! \class vtkLODActor
56  * \brief For more information see <a href="http://www.vtk.org/">VTK documentation</a>
57  */
58 class VTKVIEWER_EXPORT VTKViewer_Actor : public vtkLODActor 
59 {
60  public:
61   static VTKViewer_Actor* New();
62   
63   vtkTypeMacro(VTKViewer_Actor,vtkLODActor);
64
65   //----------------------------------------------------------------------------
66   //! Get its name
67   virtual 
68   const char* 
69   getName();
70
71   //! Name the #VTKViewer_Actor
72   virtual
73   void
74   setName(const char* theName);
75
76   //----------------------------------------------------------------------------
77   //! Change opacity
78   virtual
79   void
80   SetOpacity(float theOpacity);
81
82   //! Get current opacity
83   virtual
84   float 
85   GetOpacity();
86
87   //! Change color
88   virtual
89   void
90   SetColor(float r,float g,float b);
91
92   //! Get current color
93   virtual
94   void
95   GetColor(float& r,float& g,float& b);
96
97   //! Change color
98   virtual
99   void
100   SetColor(const float theRGB[3]);
101
102   //----------------------------------------------------------------------------
103   // For selection mapping purpose
104   //! Maps VTK index of a node to corresponding object index
105   virtual
106   int 
107   GetNodeObjId(int theVtkID);
108
109   //! Get coordinates of a node for given object index
110   virtual
111   float*
112   GetNodeCoord(int theObjID);
113
114   //! Maps VTK index of a cell to corresponding object index
115   virtual 
116   int
117   GetElemObjId(int theVtkID);
118
119   //! Get corresponding #vtkCell for given object index
120   virtual
121   vtkCell* 
122   GetElemCell(int theObjID);
123
124   //----------------------------------------------------------------------------
125   //! Get dimension of corresponding mesh element
126   virtual
127   int
128   GetObjDimension( const int theObjId );
129
130   //! To insert some additional filters and then sets the given #vtkMapper
131   virtual
132   void
133   SetMapper(vtkMapper* theMapper); 
134
135   //! Allows to get initial #vtkDataSet
136   virtual
137   vtkDataSet* 
138   GetInput(); 
139
140   //! Apply view transformation
141   virtual
142   void
143   SetTransform(VTKViewer_Transform* theTransform); 
144
145   //! To calculatate last modified time
146   virtual
147   unsigned long int
148   GetMTime();
149
150   //----------------------------------------------------------------------------
151   //! Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
152   virtual
153   void
154   SetRepresentation(int theMode);
155
156   //! Get current representation mode
157   virtual
158   int
159   GetRepresentation();
160
161   //! Get current display mode (obsolete)
162   virtual
163   int
164   getDisplayMode();
165
166   //! Set display mode (obsolete)
167   virtual
168   void
169   setDisplayMode(int theMode);
170
171   //----------------------------------------------------------------------------
172   //! Set infinive flag
173   /*!
174     Infinitive means actor without size (point for example),
175     which is not taken into account in calculation of boundaries of the scene
176   */
177   void
178   SetInfinitive(bool theIsInfinite);
179
180   //! Get infinive flag
181   virtual
182   bool
183   IsInfinitive();
184     
185   //! To calcualte current bounding box
186   virtual
187   float* 
188   GetBounds();
189
190   //! To calcualte current bounding box
191   void
192   GetBounds(float bounds[6]);
193
194   //----------------------------------------------------------------------------
195   virtual
196   bool
197   IsSetCamera() const;
198
199   virtual
200   bool
201   IsResizable() const;
202
203   virtual
204   void
205   SetSize( const float );
206
207   virtual
208   void 
209   SetCamera( vtkCamera* );
210
211   //----------------------------------------------------------------------------
212   //! Set ResolveCoincidentTopology flag
213   void
214   SetResolveCoincidentTopology(bool theIsResolve);
215
216   //! Set ResolveCoincidentTopology parameters
217   void
218   SetPolygonOffsetParameters(float factor, float units);
219
220   //! Get current ResolveCoincidentTopology parameters
221   void
222   GetPolygonOffsetParameters(float& factor, float& units);
223
224   virtual
225   void
226   Render(vtkRenderer *, vtkMapper *);
227
228   //----------------------------------------------------------------------------
229   //! Get current shrink factor
230   virtual
231   float
232   GetShrinkFactor();
233
234   //! Is the actor is shrunkable
235   virtual
236   bool
237   IsShrunkable();
238
239   //! Is the actor is shrunk
240   virtual
241   bool
242   IsShrunk();
243
244   //! Insert shrink filter into pipeline
245   virtual
246   void
247   SetShrink();
248
249   //! Remove shrink filter from pipeline
250   virtual
251   void
252   UnShrink();
253
254   //----------------------------------------------------------------------------
255   //! To publish the actor an all its internal devices
256   virtual
257   void
258   AddToRender(vtkRenderer* theRendere); 
259
260   //! To remove the actor an all its internal devices
261   virtual
262   void
263   RemoveFromRender(vtkRenderer* theRendere);
264
265   //! Used to obtain all dependent actors
266   virtual
267   void
268   GetChildActors(vtkActorCollection*);
269
270   //----------------------------------------------------------------------------
271   //! Ask, if the descendant of the VTKViewer_Actor will implement its own highlight or not
272   virtual
273   bool
274   hasHighlight(); 
275
276   //! Ask, if the VTKViewer_Actor is already highlighted
277   virtual
278   bool
279   isHighlighted();
280
281   //! Set preselection mode
282   virtual
283   void
284   SetPreSelected(bool thePreselect = false);
285
286   //----------------------------------------------------------------------------
287   //! Just to update visibility of the highlight devices
288   virtual
289   void
290   highlight(bool theHighlight);  
291
292   void
293   SetPreviewProperty(vtkProperty* theProperty);
294
295  protected:
296   //----------------------------------------------------------------------------
297   bool myIsResolveCoincidentTopology;
298   float myPolygonOffsetFactor;
299   float myPolygonOffsetUnits;
300
301   std::string myName;
302
303   float myOpacity;
304   int myDisplayMode;
305   bool myIsInfinite;
306
307   bool myStoreMapping;
308   VTKViewer_GeometryFilter *myGeomFilter;
309   VTKViewer_TransformFilter *myTransformFilter;
310   std::vector<VTKViewer_PassThroughFilter*> myPassFilter;
311
312   int myRepresentation;
313   vtkProperty *myProperty;
314
315   void
316   InitPipeLine(vtkMapper* theMapper); 
317
318   VTKViewer_Actor();
319   ~VTKViewer_Actor();
320
321  protected:
322   vtkProperty *PreviewProperty;
323   bool myIsPreselected;
324   bool myIsHighlighted;
325 };
326
327 #endif // VTKVIEVER_ACTOR_H