1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, 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.cxx
25 // Author : Nicolas REJNERI
28 \class SALOME_Actor SALOME_Actor.h
29 \brief Abstract class of SALOME Objects in VTK.
32 #include "VTKViewer_Actor.h"
34 #include "VTKViewer_Transform.h"
35 #include "VTKViewer_TransformFilter.h"
36 #include "VTKViewer_GeometryFilter.h"
40 #include <vtkPolyData.h>
41 #include <vtkObjectFactory.h>
42 #include <vtkDataSetMapper.h>
43 #include <vtkPolyDataMapper.h>
44 #include <vtkRenderer.h>
45 #include <vtkPassThroughFilter.h>
53 int VTKViewer_POINT_SIZE = 5;
54 int VTKViewer_LINE_WIDTH = 3;
57 vtkStandardNewMacro(VTKViewer_Actor);
64 myIsResolveCoincidentTopology(true),
68 myStoreMapping(false),
69 myGeomFilter(VTKViewer_GeometryFilter::New()),
70 myTransformFilter(VTKViewer_TransformFilter::New()),
71 myRepresentation(VTKViewer::Representation::Surface),
72 myProperty(vtkProperty::New()),
73 PreviewProperty(NULL),
74 myIsPreselected(false),
75 myIsHighlighted(false)
77 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
78 myPolygonOffsetUnits);
80 for(int i = 0; i < 6; i++)
81 myPassFilter.push_back(vtkPassThroughFilter::New());
90 SetPreviewProperty(NULL);
92 myGeomFilter->Delete();
94 myTransformFilter->Delete();
96 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
98 myPassFilter[i]->Delete();
100 myProperty->Delete();
110 return myName.c_str();
115 \param theName - new name
119 ::setName(const char* theName)
125 To publish the actor an all its internal devices
129 ::AddToRender(vtkRenderer* theRenderer)
131 theRenderer->AddActor(this);
135 To remove the actor an all its internal devices
139 ::RemoveFromRender(vtkRenderer* theRenderer)
141 theRenderer->RemoveActor(this);
145 Used to obtain all dependent actors
149 ::GetChildActors(vtkActorCollection*)
153 Apply view transformation
154 \param theTransform - view transformation
158 ::SetTransform(VTKViewer_Transform* theTransform)
160 myTransformFilter->SetTransform(theTransform);
165 To insert some additional filters and then sets the given #vtkMapper
169 ::SetMapper(vtkMapper* theMapper)
171 InitPipeLine(theMapper);
179 ::InitPipeLine(vtkMapper* theMapper)
183 myPassFilter[ anId ]->SetInputData( theMapper->GetInput() );
184 myPassFilter[ anId + 1]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
187 myGeomFilter->SetStoreMapping( myStoreMapping );
188 myGeomFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
191 myPassFilter[ anId ]->SetInputConnection( myGeomFilter->GetOutputPort() );
192 myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
195 myTransformFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
198 myPassFilter[ anId ]->SetInputConnection( myTransformFilter->GetOutputPort() );
199 myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
202 theMapper->SetInputConnection(myPassFilter[anId]->GetOutputPort());
204 Superclass::SetMapper(theMapper);
212 ::Render(vtkRenderer *ren, vtkMapper* m)
214 if(vtkDataSet* aDataSet = GetInput()){
215 static double PERCENTS_OF_DETAILS = 0.50;
216 vtkIdType aNbOfPoints = vtkIdType(aDataSet->GetNumberOfPoints()*PERCENTS_OF_DETAILS);
218 SetNumberOfCloudPoints(aNbOfPoints);
221 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
222 if(myIsResolveCoincidentTopology){
223 double aFactor, aUnit;
224 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
226 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
227 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
228 myPolygonOffsetUnits);
229 Superclass::Render(ren,m);
231 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
233 vtkMapper::SetResolveCoincidentTopologyToOff();
234 Superclass::Render(ren,m);
236 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
240 Set ResolveCoincidentTopology flag
241 \param theIsResolve - new flag value
245 ::SetResolveCoincidentTopology(bool theIsResolve)
247 myIsResolveCoincidentTopology = theIsResolve;
251 Set polygon offset parameters
252 \param factor, units - Opengl polygon offset parameters
256 ::SetPolygonOffsetParameters(double factor,
259 myPolygonOffsetFactor = factor;
260 myPolygonOffsetUnits = units;
264 Get polygon offset parameters
265 \param factor, units - Opengl polygon offset parameters
269 ::GetPolygonOffsetParameters(double& factor,
272 factor = myPolygonOffsetFactor;
273 units = myPolygonOffsetUnits;
277 \return shrink factor
287 \return true if the actor is shrunkable
297 \return true if the actor is shrunk
307 Insert shrink filter into pipeline
315 Remove shrink filter from pipeline
323 Allows to get initial #vtkDataSet
329 return myPassFilter.front()->GetOutput();
333 To calculatate last modified time
339 vtkMTimeType mTime = this->Superclass::GetMTime();
340 vtkMTimeType time = myTransformFilter->GetMTime();
341 mTime = ( time > mTime ? time : mTime );
342 if(vtkDataSet *aDataSet = dynamic_cast<vtkDataSet*>(myPassFilter[0]->GetInput())){ // bad usage of GetInput
343 time = aDataSet->GetMTime();
344 mTime = ( time > mTime ? time : mTime );
350 Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
351 param theMode - new mode
355 ::SetRepresentation(int theMode)
357 using namespace VTKViewer::Representation;
358 switch(myRepresentation){
361 case SurfaceWithEdges :
362 myProperty->SetAmbient(GetProperty()->GetAmbient());
363 myProperty->SetDiffuse(GetProperty()->GetDiffuse());
364 myProperty->SetSpecular(GetProperty()->GetSpecular());
371 case SurfaceWithEdges :
372 GetProperty()->SetAmbient(myProperty->GetAmbient());
373 GetProperty()->SetDiffuse(myProperty->GetDiffuse());
374 GetProperty()->SetSpecular(myProperty->GetSpecular());
377 GetProperty()->SetAmbient(1.0);
378 GetProperty()->SetDiffuse(0.0);
379 GetProperty()->SetSpecular(0.0);
384 myGeomFilter->SetInside(true);
385 myGeomFilter->SetWireframeMode(true);
386 GetProperty()->SetRepresentation(VTK_WIREFRAME);
389 GetProperty()->SetPointSize(VTKViewer_POINT_SIZE);
390 GetProperty()->SetRepresentation(theMode);
391 myGeomFilter->SetWireframeMode(false);
392 myGeomFilter->SetInside(false);
395 GetProperty()->SetRepresentation(theMode);
396 myGeomFilter->SetWireframeMode(true);
397 myGeomFilter->SetInside(false);
400 case SurfaceWithEdges :
401 GetProperty()->SetRepresentation(theMode);
402 myGeomFilter->SetWireframeMode(false);
403 myGeomFilter->SetInside(false);
407 myRepresentation = theMode;
411 \return current representation mode
415 ::GetRepresentation()
417 return myRepresentation;
421 Maps VTK index of a node to corresponding object index
425 ::GetNodeObjId(int theVtkID)
431 Get coordinates of a node for given object index
435 ::GetNodeCoord(int theObjID)
437 return GetInput()->GetPoint(theObjID);
441 Get corresponding #vtkCell for given object index
445 ::GetElemCell(int theObjID)
447 return GetInput()->GetCell(theObjID);
451 Maps VTK index of a cell to corresponding object index
455 ::GetElemObjId(int theVtkID)
462 \return object dimension. Virtual method should be redifined by derived classes
466 ::GetObjDimension( const int theObjId )
468 if ( vtkCell* aCell = GetElemCell(theObjId) )
469 return aCell->GetCellDimension();
474 Infinitive means actor without size (point for example),
475 which is not taken into account in calculation of boundaries of the scene
479 ::SetInfinitive(bool theIsInfinite)
481 myIsInfinite = theIsInfinite;
485 \return infinive flag
494 static double MAX_DISTANCE = 0.9*VTK_FLOAT_MAX;
497 for(int i = 0; i < 6; i++)
498 if(fabs(aBounds[i]) > MAX_DISTANCE)
501 static double MIN_DISTANCE = 1.0/VTK_FLOAT_MAX;
502 if(GetLength() < MIN_DISTANCE)
509 \return current bounding box
515 return Superclass::GetBounds();
520 \return current bounding box
524 ::GetBounds(double theBounds[6])
526 Superclass::GetBounds(theBounds);
532 ::IsSetCamera() const
539 ::IsResizable() const
546 ::SetSize( const double )
552 ::SetCamera( vtkCamera* )
558 ::SetOpacity(double theOpacity)
560 myOpacity = theOpacity;
561 GetProperty()->SetOpacity(theOpacity);
581 GetProperty()->SetColor(r,g,b);
589 ::SetColor(const double theRGB[3])
591 SetColor(theRGB[0],theRGB[1],theRGB[2]);
599 ::GetColor(double& r,
604 GetProperty()->GetColor(aColor);
616 ::SetMaterial(std::vector<vtkProperty*> theProps)
621 Get current front material
\r
625 ::GetFrontMaterial()
\r
631 Get current back material
\r
635 ::GetBackMaterial()
\r
647 return myDisplayMode;
655 ::setDisplayMode(int theMode)
657 SetRepresentation(theMode + 1);
658 myDisplayMode = GetRepresentation() - 1;
663 \return true if the descendant of the VTKViewer_Actor will implement its own highlight or not
673 \return true if the VTKViewer_Actor is already highlighted
679 return myIsHighlighted;
683 \return true if the VTKViewer_Actor is already preselected
689 return myIsPreselected;
693 Set preselection mode
697 ::SetPreSelected(bool thePreselect)
699 myIsPreselected = thePreselect;
703 Just to update visibility of the highlight devices
707 ::highlight(bool theIsHighlight)
709 myIsHighlighted = theIsHighlight;
713 * On/Off representation 2D quadratic element as arked polygon
715 void VTKViewer_Actor::SetQuadraticArcMode(bool theFlag){
716 myGeomFilter->SetQuadraticArcMode(theFlag);
720 * Return true if 2D quadratic element displayed as arked polygon
722 bool VTKViewer_Actor::GetQuadraticArcMode() const{
723 return myGeomFilter->GetQuadraticArcMode();
726 * Set Max angle for representation 2D quadratic element as arked polygon
728 void VTKViewer_Actor::SetQuadraticArcAngle(double theMaxAngle){
729 myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
733 * Return Max angle of the representation 2D quadratic element as arked polygon
735 double VTKViewer_Actor::GetQuadraticArcAngle() const{
736 return myGeomFilter->GetQuadraticArcAngle();
740 * Return pointer to the dataset, which used to calculation of the bounding box of the actor.
741 * By default it is the input dataset.
743 vtkDataSet* VTKViewer_Actor::GetHighlightedDataSet() {
749 vtkCxxSetObjectMacro(VTKViewer_Actor,PreviewProperty,vtkProperty);