1 // SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
3 // Copyright (C) 2003 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.
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
24 // File : SALOME_Actor.cxx
25 // Author : Nicolas REJNERI
30 \class SALOME_Actor SALOME_Actor.h
31 \brief Abstract class of SALOME Objects in VTK.
35 #include "VTKViewer_Actor.h"
37 #include "VTKViewer_Transform.h"
38 #include "VTKViewer_TransformFilter.h"
39 #include "VTKViewer_PassThroughFilter.h"
40 #include "VTKViewer_GeometryFilter.h"
44 #include <vtkPolyData.h>
45 #include <vtkObjectFactory.h>
46 #include <vtkDataSetMapper.h>
47 #include <vtkPolyDataMapper.h>
48 #include <vtkProperty.h>
49 #include <vtkRenderer.h>
59 int VTKViewer_POINT_SIZE = 5;
60 int VTKViewer_LINE_WIDTH = 3;
63 vtkStandardNewMacro(VTKViewer_Actor);
70 myIsHighlighted(false),
71 myIsPreselected(false),
72 myRepresentation(VTK_SURFACE),
74 myProperty(vtkProperty::New()),
75 PreviewProperty(NULL),
77 myIsResolveCoincidentTopology(true),
78 myStoreMapping(false),
79 myGeomFilter(VTKViewer_GeometryFilter::New()),
80 myTransformFilter(VTKViewer_TransformFilter::New())
82 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
83 myPolygonOffsetUnits);
85 for(int i = 0; i < 6; i++)
86 myPassFilter.push_back(VTKViewer_PassThroughFilter::New());
95 SetPreviewProperty(NULL);
97 myGeomFilter->Delete();
99 myTransformFilter->Delete();
101 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
103 myPassFilter[i]->Delete();
105 myProperty->Delete();
115 return myName.c_str();
120 \param theName - new name
124 ::setName(const char* theName)
130 To publish the actor an all its internal devices
134 ::AddToRender(vtkRenderer* theRenderer)
136 theRenderer->AddActor(this);
140 To remove the actor an all its internal devices
144 ::RemoveFromRender(vtkRenderer* theRenderer)
146 theRenderer->RemoveActor(this);
150 Used to obtain all dependent actors
154 ::GetChildActors(vtkActorCollection*)
158 Apply view transformation
159 \param theTransform - view transformation
163 ::SetTransform(VTKViewer_Transform* theTransform)
165 myTransformFilter->SetTransform(theTransform);
170 To insert some additional filters and then sets the given #vtkMapper
174 ::SetMapper(vtkMapper* theMapper)
176 InitPipeLine(theMapper);
184 ::InitPipeLine(vtkMapper* theMapper)
188 myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
189 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
192 myGeomFilter->SetStoreMapping( myStoreMapping );
193 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
196 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
197 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
200 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
203 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
204 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
207 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
208 aMapper->SetInput(myPassFilter[anId]->GetOutput());
209 }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
210 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
213 Superclass::SetMapper(theMapper);
221 ::Render(vtkRenderer *ren, vtkMapper* m)
223 if(vtkDataSet* aDataSet = GetInput()){
224 static vtkFloatingPointType PERCENTS_OF_DETAILS = 0.50;
225 vtkIdType aNbOfPoints = vtkIdType(aDataSet->GetNumberOfPoints()*PERCENTS_OF_DETAILS);
227 SetNumberOfCloudPoints(aNbOfPoints);
230 if(myIsResolveCoincidentTopology){
231 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
232 vtkFloatingPointType aFactor, aUnit;
233 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
235 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
236 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
237 myPolygonOffsetUnits);
238 Superclass::Render(ren,m);
240 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
241 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
243 Superclass::Render(ren,m);
248 Set ResolveCoincidentTopology flag
249 \param theIsResolve - new flag value
253 ::SetResolveCoincidentTopology(bool theIsResolve)
255 myIsResolveCoincidentTopology = theIsResolve;
259 Set polygon offset parameters
260 \param factor, units - Opengl polygon offset parameters
264 ::SetPolygonOffsetParameters(vtkFloatingPointType factor,
265 vtkFloatingPointType units)
267 myPolygonOffsetFactor = factor;
268 myPolygonOffsetUnits = units;
272 Get polygon offset parameters
273 \param factor, units - Opengl polygon offset parameters
277 ::GetPolygonOffsetParameters(vtkFloatingPointType& factor,
278 vtkFloatingPointType& units)
280 factor = myPolygonOffsetFactor;
281 units = myPolygonOffsetUnits;
285 \return shrink factor
295 \return true if the actor is shrunkable
305 \return true if the actor is shrunk
315 Insert shrink filter into pipeline
323 Remove shrink filter from pipeline
331 Allows to get initial #vtkDataSet
337 return myPassFilter.front()->GetOutput();
341 To calculatate last modified time
347 unsigned long mTime = this->Superclass::GetMTime();
348 unsigned long time = myTransformFilter->GetMTime();
349 mTime = ( time > mTime ? time : mTime );
350 if(vtkDataSet *aDataSet = myPassFilter[0]->GetInput()){
351 time = aDataSet->GetMTime();
352 mTime = ( time > mTime ? time : mTime );
358 Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
359 param theMode - new mode
363 ::SetRepresentation(int theMode)
365 switch(myRepresentation){
368 myProperty->SetAmbient(GetProperty()->GetAmbient());
369 myProperty->SetDiffuse(GetProperty()->GetDiffuse());
370 myProperty->SetSpecular(GetProperty()->GetSpecular());
377 GetProperty()->SetAmbient(myProperty->GetAmbient());
378 GetProperty()->SetDiffuse(myProperty->GetDiffuse());
379 GetProperty()->SetSpecular(myProperty->GetSpecular());
382 GetProperty()->SetAmbient(1.0);
383 GetProperty()->SetDiffuse(0.0);
384 GetProperty()->SetSpecular(0.0);
389 myGeomFilter->SetInside(true);
390 myGeomFilter->SetWireframeMode(true);
391 GetProperty()->SetRepresentation(VTK_WIREFRAME);
394 GetProperty()->SetPointSize(VTKViewer_POINT_SIZE);
395 GetProperty()->SetRepresentation(theMode);
396 myGeomFilter->SetWireframeMode(false);
397 myGeomFilter->SetInside(false);
400 GetProperty()->SetRepresentation(theMode);
401 myGeomFilter->SetWireframeMode(true);
402 myGeomFilter->SetInside(false);
405 GetProperty()->SetRepresentation(theMode);
406 myGeomFilter->SetWireframeMode(false);
407 myGeomFilter->SetInside(false);
411 myRepresentation = theMode;
415 \return current representation mode
419 ::GetRepresentation()
421 return myRepresentation;
425 Maps VTK index of a node to corresponding object index
429 ::GetNodeObjId(int theVtkID)
435 Get coordinates of a node for given object index
437 vtkFloatingPointType*
439 ::GetNodeCoord(int theObjID)
441 return GetInput()->GetPoint(theObjID);
445 Get corresponding #vtkCell for given object index
449 ::GetElemCell(int theObjID)
451 return GetInput()->GetCell(theObjID);
455 Maps VTK index of a cell to corresponding object index
459 ::GetElemObjId(int theVtkID)
466 \return object dimension. Virtual method should be redifined by derived classes
470 ::GetObjDimension( const int theObjId )
472 if ( vtkCell* aCell = GetElemCell(theObjId) )
473 return aCell->GetCellDimension();
478 Infinitive means actor without size (point for example),
479 which is not taken into account in calculation of boundaries of the scene
483 ::SetInfinitive(bool theIsInfinite)
485 myIsInfinite = theIsInfinite;
489 \return infinive flag
498 static vtkFloatingPointType MAX_DISTANCE = 0.9*VTK_LARGE_FLOAT;
499 vtkFloatingPointType aBounds[6];
501 for(int i = 0; i < 6; i++)
502 if(fabs(aBounds[i]) > MAX_DISTANCE)
505 static vtkFloatingPointType MIN_DISTANCE = 1.0/VTK_LARGE_FLOAT;
506 if(GetLength() < MIN_DISTANCE)
513 \return current bounding box
515 vtkFloatingPointType*
519 return Superclass::GetBounds();
524 \return current bounding box
528 ::GetBounds(vtkFloatingPointType theBounds[6])
530 Superclass::GetBounds(theBounds);
536 ::IsSetCamera() const
543 ::IsResizable() const
550 ::SetSize( const vtkFloatingPointType )
556 ::SetCamera( vtkCamera* )
562 ::SetOpacity(vtkFloatingPointType theOpacity)
564 myOpacity = theOpacity;
565 GetProperty()->SetOpacity(theOpacity);
581 ::SetColor(vtkFloatingPointType r,
582 vtkFloatingPointType g,
583 vtkFloatingPointType b)
585 GetProperty()->SetColor(r,g,b);
593 ::SetColor(const vtkFloatingPointType theRGB[3])
595 SetColor(theRGB[0],theRGB[1],theRGB[2]);
603 ::GetColor(vtkFloatingPointType& r,
604 vtkFloatingPointType& g,
605 vtkFloatingPointType& b)
607 vtkFloatingPointType aColor[3];
608 GetProperty()->GetColor(aColor);
622 return myDisplayMode;
630 ::setDisplayMode(int theMode)
632 SetRepresentation(theMode + 1);
633 myDisplayMode = GetRepresentation() - 1;
638 \return true if the descendant of the VTKViewer_Actor will implement its own highlight or not
648 \return true if the VTKViewer_Actor is already highlighted
654 return myIsHighlighted;
658 Set preselection mode
662 ::SetPreSelected(bool thePreselect)
664 myIsPreselected = thePreselect;
668 Just to update visibility of the highlight devices
672 ::highlight(bool theIsHighlight)
674 myIsHighlighted = theIsHighlight;
677 vtkCxxSetObjectMacro(VTKViewer_Actor,PreviewProperty,vtkProperty);