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 ]->SetInput( theMapper->GetInput() );
124 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
127 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
130 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
131 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
134 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
137 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
138 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
141 if(VTKViewer_DataSetMapper* aMapper = dynamic_cast<VTKViewer_DataSetMapper*>(theMapper)){
142 aMapper->SetInput(myPassFilter[anId]->GetOutput());
143 }else if(VTKViewer_PolyDataMapper* aMapper = dynamic_cast<VTKViewer_PolyDataMapper*>(theMapper)){
144 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
147 Superclass::SetMapper(theMapper);
151 Allows to get initial vtkDataSet
157 return myPassFilter.front()->GetOutput();
161 Allows to set initial vtkDataSet
165 ::SetInput(vtkDataSet* theDataSet)
167 myMapper->SetInput(theDataSet);
168 InitPipeLine(myMapper);
172 To provide VTK to Object and backward mapping
176 SetStoreMapping(bool theStoreMapping)
178 myGeomFilter->SetStoreMapping(theStoreMapping);
183 \return time of modification
189 unsigned long mTime = this->Superclass::GetMTime();
191 mTime = std::max(mTime,myGeomFilter->GetMTime());
193 mTime = std::max(mTime,myTransformFilter->GetMTime());
196 mTime = std::max(mTime,myShrinkFilter->GetMTime());
198 if(myIsFeatureEdgesEnabled)
199 mTime = std::max(mTime,myFeatureEdges->GetMTime());
201 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
202 std::max(mTime,myPassFilter[i]->GetMTime());
208 Apply a view transformation
209 \param theTransform - transformation
213 ::SetTransform(VTKViewer_Transform* theTransform)
215 myTransformFilter->SetTransform(theTransform);
219 \return true if actor is shrinkable
225 return myIsShrinkable;
229 Changes shrinkable state of actor
230 theIsShrinkable - new shrinkable state
234 ::SetShrinkable(bool theIsShrinkable)
236 myIsShrinkable = theIsShrinkable;
240 \return true if actor is shrunkable
250 Insert shrink filter into pipeline
256 if ( !myIsShrinkable )
259 if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
262 int numCells=aDataSet->GetNumberOfCells();
263 int numPts = aDataSet->GetNumberOfPoints();
264 //It's impossible to use to apply "shrink" for "empty" dataset
265 if (numCells < 1 || numPts < 1)
267 myShrinkFilter->SetInput( aDataSet );
268 myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() );
274 Remove shrink filter from pipeline
280 if ( !myIsShrunk ) return;
281 if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
283 myPassFilter[ 1 ]->SetInput( aDataSet );
289 \return shrink factor
295 return myShrinkFilter->GetShrinkFactor();
299 Changes shrink factor
300 \param theValue - new shrink factor
304 ::SetShrinkFactor(vtkFloatingPointType theValue)
306 myShrinkFilter->SetShrinkFactor(theValue);
310 \return true if feature edges are allowed for this actor
314 ::IsFeatureEdgesAllowed()
316 return myIsFeatureEdgesAllowed;
320 Allows feature edges for this actor on or off
321 \param theIsFeatureEdgesAllowed - flag which allows feature edges for this actor on or off
325 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
327 myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
331 \return true if feature edges are enabled
335 ::IsFeatureEdgesEnabled()
337 return myIsFeatureEdgesEnabled;
341 Enables feature edges on or off
342 \param theIsFeatureEdgesEnabled - flag which enables feature edges on or off
346 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
348 if ( !myIsFeatureEdgesAllowed || myIsFeatureEdgesEnabled == theIsFeatureEdgesEnabled )
351 if ( vtkPolyData* aPolyData = myPassFilter[ 2 ]->GetPolyDataOutput() )
353 if( theIsFeatureEdgesEnabled )
356 myFeatureEdges->SetInput( aPolyData );
357 myPassFilter[ 3 ]->SetInput( myFeatureEdges->GetOutput() );
358 myIsFeatureEdgesEnabled = true;
362 myPassFilter[3]->SetInput( aPolyData );
363 myIsFeatureEdgesEnabled = false;
365 myIsFeatureEdgesEnabled = theIsFeatureEdgesEnabled;
370 \return angle of feature edges' filter
374 ::GetFeatureEdgesAngle()
376 return myFeatureEdges->GetFeatureAngle();
380 Sets angle of feature edges' filter
381 \param theAngle angle of feature edges' filter
385 ::SetFeatureEdgesAngle(vtkFloatingPointType theAngle)
387 myFeatureEdges->SetFeatureAngle(theAngle);
391 Gets information about kinds of edges which are displayed by feature edges' filter
392 \param theIsFeatureEdges flag which shows whether feature edges are displayed
393 \param theIsBoundaryEdges flag which shows whether boundary edges are displayed
394 \param theIsManifoldEdges flag which shows whether manifold edges are displayed
395 \param theIsNonManifoldEdges flag which shows whether non-manifold edges are displayed
399 ::GetFeatureEdgesFlags(bool& theIsFeatureEdges,
400 bool& theIsBoundaryEdges,
401 bool& theIsManifoldEdges,
402 bool& theIsNonManifoldEdges)
404 theIsFeatureEdges = myFeatureEdges->GetFeatureEdges();
405 theIsBoundaryEdges = myFeatureEdges->GetBoundaryEdges();
406 theIsManifoldEdges = myFeatureEdges->GetManifoldEdges();
407 theIsNonManifoldEdges = myFeatureEdges->GetNonManifoldEdges();
411 Sets different kinds of edges to be displayed by feature edges' filter
412 \param theIsFeatureEdges flag which displays feature edges
413 \param theIsBoundaryEdges flag which displays boundary edges
414 \param theIsManifoldEdges flag which displays manifold edges
415 \param theIsNonManifoldEdges flag which displays non-manifold edges
419 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
420 bool theIsBoundaryEdges,
421 bool theIsManifoldEdges,
422 bool theIsNonManifoldEdges)
424 myFeatureEdges->SetFeatureEdges(theIsFeatureEdges);
425 myFeatureEdges->SetBoundaryEdges(theIsBoundaryEdges);
426 myFeatureEdges->SetManifoldEdges(theIsManifoldEdges);
427 myFeatureEdges->SetNonManifoldEdges(theIsNonManifoldEdges);
431 \return feature edges' coloring flag
435 ::GetFeatureEdgesColoring()
437 return myFeatureEdges->GetColoring();
441 Sets feature edges' coloring flag
442 \param theIsColoring feature edges' coloring flag
446 ::SetFeatureEdgesColoring(bool theIsColoring)
448 myFeatureEdges->SetColoring(theIsColoring);
452 Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
453 param theMode - new mode
457 ::SetRepresentation(VTKViewer::Representation::Type theMode)
459 using namespace VTKViewer::Representation;
461 switch(myRepresentation){
464 case SurfaceWithEdges :
465 myProperty->SetAmbient(GetProperty()->GetAmbient());
466 myProperty->SetDiffuse(GetProperty()->GetDiffuse());
467 myProperty->SetSpecular(GetProperty()->GetSpecular());
473 case SurfaceWithEdges :
474 GetProperty()->SetAmbient(myProperty->GetAmbient());
475 GetProperty()->SetDiffuse(myProperty->GetDiffuse());
476 GetProperty()->SetSpecular(myProperty->GetSpecular());
479 GetProperty()->SetAmbient(1.0);
480 GetProperty()->SetDiffuse(0.0);
481 GetProperty()->SetSpecular(0.0);
487 myGeomFilter->SetInside(true);
488 myGeomFilter->SetWireframeMode(true);
489 GetProperty()->SetRepresentation(VTK_WIREFRAME);
492 GetProperty()->SetPointSize(GetDefaultPointSize());
493 GetProperty()->SetRepresentation(VTK_POINTS);
494 myGeomFilter->SetWireframeMode(false);
495 myGeomFilter->SetInside(false);
498 GetProperty()->SetRepresentation(VTK_WIREFRAME);
499 myGeomFilter->SetWireframeMode(true);
500 myGeomFilter->SetInside(false);
503 case SurfaceWithEdges :
504 GetProperty()->SetRepresentation(VTK_SURFACE);
505 myGeomFilter->SetWireframeMode(false);
506 myGeomFilter->SetInside(false);
510 SetMarkerEnabled( theMode == Points );
512 myRepresentation = theMode;
516 \return current representation mode
518 VTKViewer::Representation::Type
520 ::GetRepresentation()
522 return myRepresentation;
526 \return default point size
530 ::GetDefaultPointSize()
536 \return default line width
540 ::GetDefaultLineWidth()
546 \return true if actor is shaded
556 Sets shaded state of actor
557 \param theShaded - new shaded state
561 ::SetShaded(bool theShaded)
563 myIsShaded = theShaded;
567 Maps VTK index of a node to corresponding object index
571 ::GetNodeObjId(int theVtkID)
577 Get coordinates of a node for given object index
579 vtkFloatingPointType*
581 ::GetNodeCoord(int theObjID)
583 return GetInput()->GetPoint(theObjID);
588 Get corresponding #vtkCell for given object index
592 ::GetElemCell(int theObjID)
594 return GetInput()->GetCell(theObjID);
598 Maps VTK index of a cell to corresponding object index
602 ::GetElemObjId(int theVtkID)
612 ::Render(vtkRenderer *ren, vtkMapper* m)
614 if(myIsResolveCoincidentTopology){
615 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
616 vtkFloatingPointType aFactor, aUnit;
617 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
619 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
620 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
621 myPolygonOffsetUnits);
622 Superclass::Render(ren,m);
624 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
625 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
627 Superclass::Render(ren,m);
632 Set polygon offset parameters
633 \param factor, units - Opengl polygon offset parameters
637 ::SetPolygonOffsetParameters(vtkFloatingPointType factor,
638 vtkFloatingPointType units)
640 myPolygonOffsetFactor = factor;
641 myPolygonOffsetUnits = units;
645 Get polygon offset parameters
646 \param factor, units - Opengl polygon offset parameters
650 ::GetPolygonOffsetParameters(vtkFloatingPointType& factor,
651 vtkFloatingPointType& units)
653 factor = myPolygonOffsetFactor;
654 units = myPolygonOffsetUnits;
657 VTKViewer_DataSetMapper* SVTK_DeviceActor::GetDataSetMapper()
663 * On/Off representation 2D quadratic element as arked polygon
665 void SVTK_DeviceActor::SetQuadraticArcMode(bool theFlag){
666 myGeomFilter->SetQuadraticArcMode(theFlag);
670 * Return true if 2D quadratic element displayed as arked polygon
672 bool SVTK_DeviceActor::GetQuadraticArcMode(){
673 return myGeomFilter->GetQuadraticArcMode();
676 * Set Max angle for representation 2D quadratic element as arked polygon
678 void SVTK_DeviceActor::SetQuadraticArcAngle(vtkFloatingPointType theMaxAngle){
679 myGeomFilter->SetQuadraticArcAngle(theMaxAngle);
683 * Return Max angle of the representation 2D quadratic element as arked polygon
685 vtkFloatingPointType SVTK_DeviceActor::GetQuadraticArcAngle(){
686 return myGeomFilter->GetQuadraticArcAngle();
690 * Set point marker enabled
691 * \param theMarkerEnabled flag to enable/disable point marker
693 void SVTK_DeviceActor::SetMarkerEnabled( bool theMarkerEnabled )
695 myMapper->SetMarkerEnabled( theMarkerEnabled );
699 * Set standard point marker
700 * \param theMarkerType type of the marker
701 * \param theMarkerScale scale of the marker
703 void SVTK_DeviceActor::SetMarkerStd( VTK::MarkerType theMarkerType, VTK::MarkerScale theMarkerScale )
705 myMapper->SetMarkerStd( theMarkerType, theMarkerScale );
709 * Set custom point marker
710 * \param theMarkerId id of the marker texture
711 * \param theMarkerTexture marker texture
713 void SVTK_DeviceActor::SetMarkerTexture( int theMarkerId, VTK::MarkerTexture theMarkerTexture )
715 myMapper->SetMarkerTexture( theMarkerId, theMarkerTexture );
719 * Get type of the point marker
720 * \return type of the point marker
722 VTK::MarkerType SVTK_DeviceActor::GetMarkerType()
724 return myMapper->GetMarkerType();
728 Get scale of the point marker
729 \return scale of the point marker
731 VTK::MarkerScale SVTK_DeviceActor::GetMarkerScale()
733 return myMapper->GetMarkerScale();
737 * Get texture identifier of the point marker
738 * \return texture identifier of the point marker
740 int SVTK_DeviceActor::GetMarkerTexture()
742 return myMapper->GetMarkerTexture();
745 void SVTK_DeviceActor::SetCoincident3DAllowed(bool theFlag) {
746 myGeomFilter->SetAppendCoincident3D(theFlag);
749 bool SVTK_DeviceActor::IsCoincident3DAllowed() const {
750 return myGeomFilter->GetAppendCoincident3D();
755 ::SetResolveCoincidentTopology(bool theIsResolve)
757 myIsResolveCoincidentTopology = theIsResolve;