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 // SVTK OBJECT : interactive object for SVTK visualization
24 // File : SVTK_DeviceActor.cxx
27 #include "SVTK_DeviceActor.h"
29 #include "VTKViewer_Transform.h"
30 #include "VTKViewer_TransformFilter.h"
31 #include "VTKViewer_GeometryFilter.h"
34 #include <vtkObjectFactory.h>
35 #include <vtkShrinkFilter.h>
36 #include <vtkFeatureEdges.h>
38 #include <vtkPolyData.h>
39 #include <vtkUnstructuredGrid.h>
41 #include <VTKViewer_PolyDataMapper.h>
42 #include <VTKViewer_DataSetMapper.h>
44 #include <vtkPassThroughFilter.h>
46 vtkStandardNewMacro(SVTK_DeviceActor);
55 myIsShrinkable = true;
57 myIsFeatureEdgesAllowed = false;
58 myIsFeatureEdgesEnabled = false;
61 myProperty = vtkProperty::New();
62 myRepresentation = VTKViewer::Representation::Surface;
64 myIsResolveCoincidentTopology = true;
65 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
66 myPolygonOffsetUnits);
68 myMapper = VTKViewer_DataSetMapper::New();
70 myShrinkFilter = vtkShrinkFilter::New();
72 myFeatureEdges = vtkFeatureEdges::New();
74 myGeomFilter = VTKViewer_GeometryFilter::New();
76 myTransformFilter = VTKViewer_TransformFilter::New();
78 for(int i = 0; i < 6; i++)
79 myPassFilter.push_back(vtkPassThroughFilter::New());
92 myGeomFilter->Delete();
94 myTransformFilter->Delete();
96 myShrinkFilter->Delete();
98 myFeatureEdges->Delete();
100 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
101 myPassFilter[i]->Delete();
105 To insert some additional filters and then sets the given vtkMapper
109 ::SetMapper(vtkMapper* theMapper)
111 InitPipeLine(theMapper);
115 To initialize internal pipeline
119 ::InitPipeLine(vtkMapper* theMapper)
123 myPassFilter[ anId ]->SetInputConnection( theMapper->GetInputConnection( 0, 0 ) );
124 myPassFilter[ anId + 1]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
127 myGeomFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
130 myPassFilter[ anId ]->SetInputConnection( myGeomFilter->GetOutputPort() );
131 myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
134 myTransformFilter->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
137 myPassFilter[ anId ]->SetInputConnection( myTransformFilter->GetOutputPort() );
138 myPassFilter[ anId + 1 ]->SetInputConnection( myPassFilter[ anId ]->GetOutputPort() );
141 theMapper->SetInputConnection(myPassFilter[anId]->GetOutputPort());
143 Superclass::SetMapper(theMapper);
147 Allows to get initial vtkDataSet
153 return myPassFilter.front()->GetOutput();
157 Allows to set initial vtkDataSet
161 ::SetInputData(vtkDataSet* theDataSet)
163 myMapper->SetInputData(theDataSet);
164 InitPipeLine(myMapper);
168 Allows to set initial vtkDataSet
172 ::SetInputConnection(vtkAlgorithmOutput* theAlgorithmOutput)
174 myMapper->SetInputConnection(theAlgorithmOutput);
175 InitPipeLine(myMapper);
179 To provide VTK to Object and backward mapping
183 SetStoreMapping(bool theStoreMapping)
185 myGeomFilter->SetStoreMapping(theStoreMapping);
190 \return time of modification
196 vtkMTimeType mTime = this->Superclass::GetMTime();
198 mTime = std::max(mTime,myGeomFilter->GetMTime());
200 mTime = std::max(mTime,myTransformFilter->GetMTime());
203 mTime = std::max(mTime,myShrinkFilter->GetMTime());
205 if(myIsFeatureEdgesEnabled)
206 mTime = std::max(mTime,myFeatureEdges->GetMTime());
208 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
209 std::max(mTime,myPassFilter[i]->GetMTime());
215 Apply a view transformation
216 \param theTransform - transformation
220 ::SetTransform(VTKViewer_Transform* theTransform)
222 myTransformFilter->SetTransform(theTransform);
226 \return true if actor is shrinkable
232 return myIsShrinkable;
236 Changes shrinkable state of actor
237 theIsShrinkable - new shrinkable state
241 ::SetShrinkable(bool theIsShrinkable)
243 myIsShrinkable = theIsShrinkable;
247 \return true if actor is shrunkable
257 Insert shrink filter into pipeline
263 if ( !myIsShrinkable )
266 if ( vtkAlgorithmOutput* anOutput = myPassFilter[ 0 ]->GetOutputPort() )
268 myPassFilter[ 0 ]->Update();
269 if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
271 int numCells=aDataSet->GetNumberOfCells();
272 int numPts = aDataSet->GetNumberOfPoints();
273 //It's impossible to use to apply "shrink" for "empty" dataset
274 if (numCells < 1 || numPts < 1)
277 myShrinkFilter->SetInputConnection( anOutput );
278 myPassFilter[ 1 ]->SetInputConnection( myShrinkFilter->GetOutputPort() );
284 Remove shrink filter from pipeline
290 if ( !myIsShrunk ) return;
291 if ( vtkAlgorithmOutput* anOutput = myPassFilter[ 0 ]->GetOutputPort() )
293 myPassFilter[ 1 ]->SetInputConnection( anOutput );
299 \return shrink factor
305 return myShrinkFilter->GetShrinkFactor();
309 Changes shrink factor
310 \param theValue - new shrink factor
314 ::SetShrinkFactor(double theValue)
316 myShrinkFilter->SetShrinkFactor(theValue);
320 \return true if feature edges are allowed for this actor
324 ::IsFeatureEdgesAllowed()
326 return myIsFeatureEdgesAllowed;
330 Allows feature edges for this actor on or off
331 \param theIsFeatureEdgesAllowed - flag which allows feature edges for this actor on or off
335 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
337 myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
341 \return true if feature edges are enabled
345 ::IsFeatureEdgesEnabled()
347 return myIsFeatureEdgesEnabled;
351 Enables feature edges on or off
352 \param theIsFeatureEdgesEnabled - flag which enables feature edges on or off
356 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
358 if ( !myIsFeatureEdgesAllowed || myIsFeatureEdgesEnabled == theIsFeatureEdgesEnabled )
361 if ( vtkAlgorithmOutput* aPolyData = myPassFilter[ 2 ]->GetOutputPort() )
363 if( theIsFeatureEdgesEnabled )
365 myPassFilter[ 2 ]->Update();
366 myFeatureEdges->SetInputConnection( aPolyData );
367 myPassFilter[ 3 ]->SetInputConnection( myFeatureEdges->GetOutputPort() );
368 myIsFeatureEdgesEnabled = true;
372 myPassFilter[3]->SetInputConnection( aPolyData );
373 myIsFeatureEdgesEnabled = false;
375 myIsFeatureEdgesEnabled = theIsFeatureEdgesEnabled;
380 \return angle of feature edges' filter
384 ::GetFeatureEdgesAngle()
386 return myFeatureEdges->GetFeatureAngle();
390 Sets angle of feature edges' filter
391 \param theAngle angle of feature edges' filter
395 ::SetFeatureEdgesAngle(double theAngle)
397 myFeatureEdges->SetFeatureAngle(theAngle);
401 Gets information about kinds of edges which are displayed by feature edges' filter
402 \param theIsFeatureEdges flag which shows whether feature edges are displayed
403 \param theIsBoundaryEdges flag which shows whether boundary edges are displayed
404 \param theIsManifoldEdges flag which shows whether manifold edges are displayed
405 \param theIsNonManifoldEdges flag which shows whether non-manifold edges are displayed
409 ::GetFeatureEdgesFlags(bool& theIsFeatureEdges,
410 bool& theIsBoundaryEdges,
411 bool& theIsManifoldEdges,
412 bool& theIsNonManifoldEdges)
414 theIsFeatureEdges = myFeatureEdges->GetFeatureEdges();
415 theIsBoundaryEdges = myFeatureEdges->GetBoundaryEdges();
416 theIsManifoldEdges = myFeatureEdges->GetManifoldEdges();
417 theIsNonManifoldEdges = myFeatureEdges->GetNonManifoldEdges();
421 Sets different kinds of edges to be displayed by feature edges' filter
422 \param theIsFeatureEdges flag which displays feature edges
423 \param theIsBoundaryEdges flag which displays boundary edges
424 \param theIsManifoldEdges flag which displays manifold edges
425 \param theIsNonManifoldEdges flag which displays non-manifold edges
429 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
430 bool theIsBoundaryEdges,
431 bool theIsManifoldEdges,
432 bool theIsNonManifoldEdges)
434 myFeatureEdges->SetFeatureEdges(theIsFeatureEdges);
435 myFeatureEdges->SetBoundaryEdges(theIsBoundaryEdges);
436 myFeatureEdges->SetManifoldEdges(theIsManifoldEdges);
437 myFeatureEdges->SetNonManifoldEdges(theIsNonManifoldEdges);
441 \return feature edges' coloring flag
445 ::GetFeatureEdgesColoring()
447 return myFeatureEdges->GetColoring();
451 Sets feature edges' coloring flag
452 \param theIsColoring feature edges' coloring flag
456 ::SetFeatureEdgesColoring(bool theIsColoring)
458 myFeatureEdges->SetColoring(theIsColoring);
462 Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
463 param theMode - new mode
467 ::SetRepresentation(VTKViewer::Representation::Type theMode)
469 using namespace VTKViewer::Representation;
471 switch(myRepresentation){
474 case SurfaceWithEdges :
475 myProperty->SetAmbient(GetProperty()->GetAmbient());
476 myProperty->SetDiffuse(GetProperty()->GetDiffuse());
477 myProperty->SetSpecular(GetProperty()->GetSpecular());
483 case SurfaceWithEdges :
484 GetProperty()->SetAmbient(myProperty->GetAmbient());
485 GetProperty()->SetDiffuse(myProperty->GetDiffuse());
486 GetProperty()->SetSpecular(myProperty->GetSpecular());
489 GetProperty()->SetAmbient(1.0);
490 GetProperty()->SetDiffuse(0.0);
491 GetProperty()->SetSpecular(0.0);
497 myGeomFilter->SetInside(true);
498 myGeomFilter->SetWireframeMode(true);
499 GetProperty()->SetRepresentation(VTK_WIREFRAME);
502 GetProperty()->SetPointSize(GetDefaultPointSize());
503 GetProperty()->SetRepresentation(VTK_POINTS);
504 myGeomFilter->SetWireframeMode(false);
505 myGeomFilter->SetInside(false);
508 GetProperty()->SetRepresentation(VTK_WIREFRAME);
509 myGeomFilter->SetWireframeMode(true);
510 myGeomFilter->SetInside(false);
513 case SurfaceWithEdges :
514 GetProperty()->SetRepresentation(VTK_SURFACE);
515 myGeomFilter->SetWireframeMode(false);
516 myGeomFilter->SetInside(false);
520 SetMarkerEnabled( theMode == Points );
522 myRepresentation = theMode;
526 \return current representation mode
528 VTKViewer::Representation::Type
530 ::GetRepresentation()
532 return myRepresentation;
536 \return default point size
540 ::GetDefaultPointSize()
546 \return default line width
550 ::GetDefaultLineWidth()
556 \return true if actor is shaded
566 Sets shaded state of actor
567 \param theShaded - new shaded state
571 ::SetShaded(bool theShaded)
573 myIsShaded = theShaded;
577 Maps VTK index of a node to corresponding object index
581 ::GetNodeObjId(int theVtkID)
587 Get coordinates of a node for given object index
591 ::GetNodeCoord(int theObjID)
593 return GetInput()->GetPoint(theObjID);
598 Get corresponding #vtkCell for given object index
602 ::GetElemCell(int theObjID)
604 return GetInput()->GetCell(theObjID);
608 Maps VTK index of a cell to corresponding object index
612 ::GetElemObjId(int theVtkID)
622 ::Render(vtkRenderer *ren, vtkMapper* m)
624 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
625 if(myIsResolveCoincidentTopology){
626 double aFactor, aUnit;
627 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
629 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
630 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
631 myPolygonOffsetUnits);
632 Superclass::Render(ren,m);
634 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
636 vtkMapper::SetResolveCoincidentTopologyToOff();
637 Superclass::Render(ren,m);
639 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
643 Set polygon offset parameters
644 \param factor, units - Opengl polygon offset parameters
648 ::SetPolygonOffsetParameters(double factor,
651 myPolygonOffsetFactor = factor;
652 myPolygonOffsetUnits = units;
656 Get polygon offset parameters
657 \param factor, units - Opengl polygon offset parameters
661 ::GetPolygonOffsetParameters(double& factor,
664 factor = myPolygonOffsetFactor;
665 units = myPolygonOffsetUnits;
668 VTKViewer_DataSetMapper* SVTK_DeviceActor::GetDataSetMapper()
674 * On/Off representation 2D quadratic element as arked polygon
676 void SVTK_DeviceActor::SetQuadraticArcMode(bool theFlag){
677 myGeomFilter->SetQuadraticArcMode(theFlag);
681 * Return true if 2D quadratic element displayed as arked polygon
683 bool SVTK_DeviceActor::GetQuadraticArcMode(){
684 return myGeomFilter->GetQuadraticArcMode();
687 * Set Max angle for representation 2D quadratic element as arked polygon
689 void SVTK_DeviceActor::SetQuadraticArcAngle(double theMaxAngle){
690 myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
694 * Return Max angle of the representation 2D quadratic element as arked polygon
696 double SVTK_DeviceActor::GetQuadraticArcAngle(){
697 return myGeomFilter->GetQuadraticArcAngle();
701 * Set ball drawing enabled
702 * \param theBallEnabled flag to enable/disable balls
704 void SVTK_DeviceActor::SetBallEnabled( bool theBallEnabled ) {
705 myMapper->SetBallEnabled( theBallEnabled );
708 * Set ball scale factor
709 * \param theBallScale double value a scale factor of ball element
711 void SVTK_DeviceActor::SetBallScale( double theBallScale ) {
712 myMapper->SetBallScale( theBallScale );
716 * Set point marker enabled
717 * \param theMarkerEnabled flag to enable/disable point marker
719 void SVTK_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
721 myMapper->SetMarkerEnabled( theMarkerEnabled );
725 * Set standard point marker
726 * \param theMarkerType type of the marker
727 * \param theMarkerScale scale of the marker
729 void SVTK_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
731 myMapper->SetMarkerStd( theMarkerType, theMarkerScale );
735 * Set custom point marker
736 * \param theMarkerId id of the marker texture
737 * \param theMarkerTexture marker texture
739 void SVTK_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
741 myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
745 * Get type of the point marker
746 * \return type of the point marker
748 VTK::MarkerType SVTK_DeviceActor::GetMarkerType()
750 return myMapper->GetMarkerType();
754 Get scale of the point marker
755 \return scale of the point marker
757 VTK::MarkerScale SVTK_DeviceActor::GetMarkerScale()
759 return myMapper->GetMarkerScale();
763 * Get texture identifier of the point marker
764 * \return texture identifier of the point marker
766 int SVTK_DeviceActor::GetMarkerTexture()
768 return myMapper->GetMarkerTexture();
771 void SVTK_DeviceActor::SetCoincident3DAllowed(bool theFlag) {
772 myGeomFilter->SetAppendCoincident3D(theFlag);
775 bool SVTK_DeviceActor::IsCoincident3DAllowed() const {
776 return myGeomFilter->GetAppendCoincident3D();
781 ::SetResolveCoincidentTopology(bool theIsResolve)
783 myIsResolveCoincidentTopology = theIsResolve;