1 // Copyright (C) 2007-2012 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.
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 ]->SetInputData( theMapper->GetInput() );
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 ::SetInput(vtkDataSet* theDataSet)
163 myMapper->SetInputData(theDataSet);
164 InitPipeLine(myMapper);
168 To provide VTK to Object and backward mapping
172 SetStoreMapping(bool theStoreMapping)
174 myGeomFilter->SetStoreMapping(theStoreMapping);
179 \return time of modification
185 unsigned long mTime = this->Superclass::GetMTime();
187 mTime = std::max(mTime,myGeomFilter->GetMTime());
189 mTime = std::max(mTime,myTransformFilter->GetMTime());
192 mTime = std::max(mTime,myShrinkFilter->GetMTime());
194 if(myIsFeatureEdgesEnabled)
195 mTime = std::max(mTime,myFeatureEdges->GetMTime());
197 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
198 std::max(mTime,myPassFilter[i]->GetMTime());
204 Apply a view transformation
205 \param theTransform - transformation
209 ::SetTransform(VTKViewer_Transform* theTransform)
211 myTransformFilter->SetTransform(theTransform);
215 \return true if actor is shrinkable
221 return myIsShrinkable;
225 Changes shrinkable state of actor
226 theIsShrinkable - new shrinkable state
230 ::SetShrinkable(bool theIsShrinkable)
232 myIsShrinkable = theIsShrinkable;
236 \return true if actor is shrunkable
246 Insert shrink filter into pipeline
252 if ( !myIsShrinkable )
255 if ( vtkAlgorithmOutput* anOutput = myPassFilter[ 0 ]->GetOutputPort() )
257 myPassFilter[ 0 ]->Update();
258 if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
260 int numCells=aDataSet->GetNumberOfCells();
261 int numPts = aDataSet->GetNumberOfPoints();
262 //It's impossible to use to apply "shrink" for "empty" dataset
263 if (numCells < 1 || numPts < 1)
266 myShrinkFilter->SetInputConnection( anOutput );
267 myPassFilter[ 1 ]->SetInputConnection( myShrinkFilter->GetOutputPort() );
273 Remove shrink filter from pipeline
279 if ( !myIsShrunk ) return;
280 if ( vtkAlgorithmOutput* anOutput = myPassFilter[ 0 ]->GetOutputPort() )
282 myPassFilter[ 1 ]->SetInputConnection( anOutput );
288 \return shrink factor
294 return myShrinkFilter->GetShrinkFactor();
298 Changes shrink factor
299 \param theValue - new shrink factor
303 ::SetShrinkFactor(double theValue)
305 myShrinkFilter->SetShrinkFactor(theValue);
309 \return true if feature edges are allowed for this actor
313 ::IsFeatureEdgesAllowed()
315 return myIsFeatureEdgesAllowed;
319 Allows feature edges for this actor on or off
320 \param theIsFeatureEdgesAllowed - flag which allows feature edges for this actor on or off
324 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
326 myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
330 \return true if feature edges are enabled
334 ::IsFeatureEdgesEnabled()
336 return myIsFeatureEdgesEnabled;
340 Enables feature edges on or off
341 \param theIsFeatureEdgesEnabled - flag which enables feature edges on or off
345 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
347 if ( !myIsFeatureEdgesAllowed || myIsFeatureEdgesEnabled == theIsFeatureEdgesEnabled )
350 if ( vtkAlgorithmOutput* aPolyData = myPassFilter[ 2 ]->GetOutputPort() )
352 if( theIsFeatureEdgesEnabled )
354 myPassFilter[ 2 ]->Update();
355 myFeatureEdges->SetInputConnection( aPolyData );
356 myPassFilter[ 3 ]->SetInputConnection( myFeatureEdges->GetOutputPort() );
357 myIsFeatureEdgesEnabled = true;
361 myPassFilter[3]->SetInputConnection( aPolyData );
362 myIsFeatureEdgesEnabled = false;
364 myIsFeatureEdgesEnabled = theIsFeatureEdgesEnabled;
369 \return angle of feature edges' filter
373 ::GetFeatureEdgesAngle()
375 return myFeatureEdges->GetFeatureAngle();
379 Sets angle of feature edges' filter
380 \param theAngle angle of feature edges' filter
384 ::SetFeatureEdgesAngle(double theAngle)
386 myFeatureEdges->SetFeatureAngle(theAngle);
390 Gets information about kinds of edges which are displayed by feature edges' filter
391 \param theIsFeatureEdges flag which shows whether feature edges are displayed
392 \param theIsBoundaryEdges flag which shows whether boundary edges are displayed
393 \param theIsManifoldEdges flag which shows whether manifold edges are displayed
394 \param theIsNonManifoldEdges flag which shows whether non-manifold edges are displayed
398 ::GetFeatureEdgesFlags(bool& theIsFeatureEdges,
399 bool& theIsBoundaryEdges,
400 bool& theIsManifoldEdges,
401 bool& theIsNonManifoldEdges)
403 theIsFeatureEdges = myFeatureEdges->GetFeatureEdges();
404 theIsBoundaryEdges = myFeatureEdges->GetBoundaryEdges();
405 theIsManifoldEdges = myFeatureEdges->GetManifoldEdges();
406 theIsNonManifoldEdges = myFeatureEdges->GetNonManifoldEdges();
410 Sets different kinds of edges to be displayed by feature edges' filter
411 \param theIsFeatureEdges flag which displays feature edges
412 \param theIsBoundaryEdges flag which displays boundary edges
413 \param theIsManifoldEdges flag which displays manifold edges
414 \param theIsNonManifoldEdges flag which displays non-manifold edges
418 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
419 bool theIsBoundaryEdges,
420 bool theIsManifoldEdges,
421 bool theIsNonManifoldEdges)
423 myFeatureEdges->SetFeatureEdges(theIsFeatureEdges);
424 myFeatureEdges->SetBoundaryEdges(theIsBoundaryEdges);
425 myFeatureEdges->SetManifoldEdges(theIsManifoldEdges);
426 myFeatureEdges->SetNonManifoldEdges(theIsNonManifoldEdges);
430 \return feature edges' coloring flag
434 ::GetFeatureEdgesColoring()
436 return myFeatureEdges->GetColoring();
440 Sets feature edges' coloring flag
441 \param theIsColoring feature edges' coloring flag
445 ::SetFeatureEdgesColoring(bool theIsColoring)
447 myFeatureEdges->SetColoring(theIsColoring);
451 Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
452 param theMode - new mode
456 ::SetRepresentation(VTKViewer::Representation::Type theMode)
458 using namespace VTKViewer::Representation;
460 switch(myRepresentation){
463 case SurfaceWithEdges :
464 myProperty->SetAmbient(GetProperty()->GetAmbient());
465 myProperty->SetDiffuse(GetProperty()->GetDiffuse());
466 myProperty->SetSpecular(GetProperty()->GetSpecular());
472 case SurfaceWithEdges :
473 GetProperty()->SetAmbient(myProperty->GetAmbient());
474 GetProperty()->SetDiffuse(myProperty->GetDiffuse());
475 GetProperty()->SetSpecular(myProperty->GetSpecular());
478 GetProperty()->SetAmbient(1.0);
479 GetProperty()->SetDiffuse(0.0);
480 GetProperty()->SetSpecular(0.0);
486 myGeomFilter->SetInside(true);
487 myGeomFilter->SetWireframeMode(true);
488 GetProperty()->SetRepresentation(VTK_WIREFRAME);
491 GetProperty()->SetPointSize(GetDefaultPointSize());
492 GetProperty()->SetRepresentation(VTK_POINTS);
493 myGeomFilter->SetWireframeMode(false);
494 myGeomFilter->SetInside(false);
497 GetProperty()->SetRepresentation(VTK_WIREFRAME);
498 myGeomFilter->SetWireframeMode(true);
499 myGeomFilter->SetInside(false);
502 case SurfaceWithEdges :
503 GetProperty()->SetRepresentation(VTK_SURFACE);
504 myGeomFilter->SetWireframeMode(false);
505 myGeomFilter->SetInside(false);
509 SetMarkerEnabled( theMode == Points );
511 myRepresentation = theMode;
515 \return current representation mode
517 VTKViewer::Representation::Type
519 ::GetRepresentation()
521 return myRepresentation;
525 \return default point size
529 ::GetDefaultPointSize()
535 \return default line width
539 ::GetDefaultLineWidth()
545 \return true if actor is shaded
555 Sets shaded state of actor
556 \param theShaded - new shaded state
560 ::SetShaded(bool theShaded)
562 myIsShaded = theShaded;
566 Maps VTK index of a node to corresponding object index
570 ::GetNodeObjId(int theVtkID)
576 Get coordinates of a node for given object index
580 ::GetNodeCoord(int theObjID)
582 return GetInput()->GetPoint(theObjID);
587 Get corresponding #vtkCell for given object index
591 ::GetElemCell(int theObjID)
593 return GetInput()->GetCell(theObjID);
597 Maps VTK index of a cell to corresponding object index
601 ::GetElemObjId(int theVtkID)
611 ::Render(vtkRenderer *ren, vtkMapper* m)
613 if(myIsResolveCoincidentTopology){
614 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
615 double aFactor, aUnit;
616 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
618 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
619 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
620 myPolygonOffsetUnits);
621 Superclass::Render(ren,m);
623 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
624 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
626 Superclass::Render(ren,m);
631 Set polygon offset parameters
632 \param factor, units - Opengl polygon offset parameters
636 ::SetPolygonOffsetParameters(double factor,
639 myPolygonOffsetFactor = factor;
640 myPolygonOffsetUnits = units;
644 Get polygon offset parameters
645 \param factor, units - Opengl polygon offset parameters
649 ::GetPolygonOffsetParameters(double& factor,
652 factor = myPolygonOffsetFactor;
653 units = myPolygonOffsetUnits;
656 VTKViewer_DataSetMapper* SVTK_DeviceActor::GetDataSetMapper()
662 * On/Off representation 2D quadratic element as arked polygon
664 void SVTK_DeviceActor::SetQuadraticArcMode(bool theFlag){
665 myGeomFilter->SetQuadraticArcMode(theFlag);
669 * Return true if 2D quadratic element displayed as arked polygon
671 bool SVTK_DeviceActor::GetQuadraticArcMode(){
672 return myGeomFilter->GetQuadraticArcMode();
675 * Set Max angle for representation 2D quadratic element as arked polygon
677 void SVTK_DeviceActor::SetQuadraticArcAngle(double theMaxAngle){
678 myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
682 * Return Max angle of the representation 2D quadratic element as arked polygon
684 double SVTK_DeviceActor::GetQuadraticArcAngle(){
685 return myGeomFilter->GetQuadraticArcAngle();
689 * Set point marker enabled
690 * \param theMarkerEnabled flag to enable/disable point marker
692 void SVTK_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
694 myMapper->SetMarkerEnabled( theMarkerEnabled );
698 * Set standard point marker
699 * \param theMarkerType type of the marker
700 * \param theMarkerScale scale of the marker
702 void SVTK_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
704 myMapper->SetMarkerStd( theMarkerType, theMarkerScale );
708 * Set custom point marker
709 * \param theMarkerId id of the marker texture
710 * \param theMarkerTexture marker texture
712 void SVTK_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
714 myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
718 * Get type of the point marker
719 * \return type of the point marker
721 VTK::MarkerType SVTK_DeviceActor::GetMarkerType()
723 return myMapper->GetMarkerType();
727 Get scale of the point marker
728 \return scale of the point marker
730 VTK::MarkerScale SVTK_DeviceActor::GetMarkerScale()
732 return myMapper->GetMarkerScale();
736 * Get texture identifier of the point marker
737 * \return texture identifier of the point marker
739 int SVTK_DeviceActor::GetMarkerTexture()
741 return myMapper->GetMarkerTexture();
744 void SVTK_DeviceActor::SetCoincident3DAllowed(bool theFlag) {
745 myGeomFilter->SetAppendCoincident3D(theFlag);
748 bool SVTK_DeviceActor::IsCoincident3DAllowed() const {
749 return myGeomFilter->GetAppendCoincident3D();
754 ::SetResolveCoincidentTopology(bool theIsResolve)
756 myIsResolveCoincidentTopology = theIsResolve;