1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
24 // File : SALOME_Actor.h
25 // Author : Nicolas REJNERI
27 #ifndef VTKVIEVER_ACTOR_H
28 #define VTKVIEVER_ACTOR_H
30 #include "VTKViewer.h"
36 #include <NCollection_IndexedMap.hxx>
37 #include <NCollection_Map.hxx>
39 #include <vtkLODActor.h>
40 #include <vtkProperty.h>
51 class VTKViewer_Transform;
52 class VTKViewer_GeometryFilter;
53 class VTKViewer_TransformFilter;
55 extern int VTKViewer_POINT_SIZE;
56 extern int VTKViewer_LINE_WIDTH;
60 namespace Representation
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;
72 #pragma warning ( disable:4251 )
75 /*! \class vtkLODActor
76 * \brief For more information see <a href="http://www.vtk.org/">VTK documentation</a>
78 class VTKVIEWER_EXPORT VTKViewer_Actor : public vtkLODActor
81 static VTKViewer_Actor* New();
83 vtkTypeMacro(VTKViewer_Actor,vtkLODActor)
85 //----------------------------------------------------------------------------
91 //! Name the #VTKViewer_Actor
94 setName(const char* theName);
96 //----------------------------------------------------------------------------
100 SetOpacity(double theOpacity);
102 //! Get current opacity
114 //! Get current color
124 SetColor(const double theRGB[3]);
129 SetMaterial(std::vector<vtkProperty*> theProps);
131 //! Get current front material
136 //! Get current back material
141 //----------------------------------------------------------------------------
142 // For selection mapping purpose
143 //! Maps VTK index of a node to corresponding object index
146 GetNodeObjId(vtkIdType theVtkID);
148 //! Get coordinates of a node for given object index
151 GetNodeCoord(vtkIdType theObjID);
153 //! Maps object index of a node to corresponding VTK index
156 GetNodeVtkId(vtkIdType theObjID);
158 //! Maps VTK index of a cell to corresponding object index
161 GetElemObjId(vtkIdType theVtkID);
163 //! Get corresponding #vtkCell for given object index
166 GetElemCell(vtkIdType theObjID);
168 //----------------------------------------------------------------------------
169 //! Get dimension of corresponding mesh element
172 GetObjDimension( const vtkIdType theObjId );
174 //! To insert some additional filters and then sets the given #vtkMapper
177 SetMapper(vtkMapper* theMapper);
179 //! Allows to get initial #vtkDataSet
184 //! Apply view transformation
187 SetTransform(VTKViewer_Transform* theTransform);
189 //! To calculatate last modified time
194 //----------------------------------------------------------------------------
195 //! Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
198 SetRepresentation(int theMode);
200 //! Get current representation mode
205 //! Get current display mode (obsolete)
210 //! Set display mode (obsolete)
213 setDisplayMode(int theMode);
215 //----------------------------------------------------------------------------
216 //! Set infinive flag
218 Infinitive means actor without size (point for example),
219 which is not taken into account in calculation of boundaries of the scene
222 SetInfinitive(bool theIsInfinite);
224 //! Get infinive flag
229 //! To calcualte current bounding box
234 //! To calcualte current bounding box
236 GetBounds(double bounds[6]);
238 //----------------------------------------------------------------------------
249 SetSize( const double );
253 SetCamera( vtkCamera* );
255 //----------------------------------------------------------------------------
256 //! Set ResolveCoincidentTopology flag
258 SetResolveCoincidentTopology(bool theIsResolve);
260 //! Set ResolveCoincidentTopology parameters
262 SetPolygonOffsetParameters(double factor,
265 //! Get current ResolveCoincidentTopology parameters
267 GetPolygonOffsetParameters(double& factor,
270 //! Get default ResolveCoincidentTopology parameters
273 GetDefaultPolygonOffsetParameters(double& factor,
278 Render(vtkRenderer *, vtkMapper *);
280 //----------------------------------------------------------------------------
281 //! Get current shrink factor
286 //! Is the actor is shrunkable
291 //! Is the actor is shrunk
296 //! Insert shrink filter into pipeline
301 //! Remove shrink filter from pipeline
306 //----------------------------------------------------------------------------
307 //! To publish the actor an all its internal devices
310 AddToRender(vtkRenderer* theRendere);
312 //! To remove the actor an all its internal devices
315 RemoveFromRender(vtkRenderer* theRendere);
317 //! Used to obtain all dependent actors
320 GetChildActors(vtkActorCollection*);
322 //----------------------------------------------------------------------------
323 //! Is notified on enabling/disabling selection
326 EnableSelection( bool /*enable*/ ) {}
328 //! Ask, if the descendant of the VTKViewer_Actor will implement its own highlight or not
333 //! Ask, if the VTKViewer_Actor is already highlighted
338 //! Ask, if the VTKViewer_Actor is already preselected
343 //! Set preselection mode
346 SetPreSelected(bool thePreselect = false);
348 //----------------------------------------------------------------------------
349 //! Just to update visibility of the highlight devices
352 highlight(bool theHighlight);
355 SetPreviewProperty(vtkProperty* theProperty);
357 //----------------------------------------------------------------------------
358 //! Setting for displaying quadratic elements
359 virtual void SetQuadraticArcMode(bool theFlag);
360 virtual bool GetQuadraticArcMode() const;
362 virtual void SetQuadraticArcAngle(double theMaxAngle);
363 virtual double GetQuadraticArcAngle() const;
365 //----------------------------------------------------------------------------
366 //! Return pointer to the dataset, which used to calculation of the bounding box of the actor
367 virtual vtkDataSet* GetHighlightedDataSet();
370 //----------------------------------------------------------------------------
371 bool myIsResolveCoincidentTopology;
372 double myPolygonOffsetFactor;
373 double myPolygonOffsetUnits;
382 VTKViewer_GeometryFilter *myGeomFilter;
383 VTKViewer_TransformFilter *myTransformFilter;
384 std::vector<vtkPassThrough*> myPassFilter;
386 int myRepresentation;
387 vtkProperty *myProperty;
390 InitPipeLine(vtkMapper* theMapper);
396 vtkProperty *PreviewProperty;
397 bool myIsPreselected;
398 bool myIsHighlighted;
403 static int HashCode(const vtkIdType theValue, const int theUpperBound)
405 return static_cast<int> ((theValue & (std::numeric_limits<vtkIdType>::max)()) % theUpperBound + 1);
408 static bool IsEqual( const vtkIdType& id1, const vtkIdType& id2 )
414 typedef NCollection_Map< vtkIdType, vtkIdHasher > TVtkIDsMap;
415 typedef NCollection_IndexedMap<vtkIdType,vtkIdHasher> TIndexedMapOfVtkId;
418 #pragma warning ( default:4251 )
421 #endif // VTKVIEVER_ACTOR_H