1 // Copyright (C) 2007-2008 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
22 // SVTK OBJECT : interactive object for SVTK visualization
23 // File : SVTK_DeviceActor.cxx
28 #include "SVTK_DeviceActor.h"
30 #include "VTKViewer_Transform.h"
31 #include "VTKViewer_TransformFilter.h"
32 #include "VTKViewer_GeometryFilter.h"
35 #include <vtkObjectFactory.h>
36 #include <vtkShrinkFilter.h>
37 #include <vtkFeatureEdges.h>
39 #include <vtkPolyData.h>
40 #include <vtkUnstructuredGrid.h>
42 #include <vtkPolyDataMapper.h>
43 #include <vtkDataSetMapper.h>
45 #include <vtkPassThroughFilter.h>
49 vtkStandardNewMacro(SVTK_DeviceActor);
58 myIsShrinkable = true;
60 myIsFeatureEdgesAllowed = false;
61 myIsFeatureEdgesEnabled = false;
64 myProperty = vtkProperty::New();
65 myRepresentation = SVTK::Representation::Surface;
67 myIsResolveCoincidentTopology = true;
68 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
69 myPolygonOffsetUnits);
71 myMapper = vtkDataSetMapper::New();
73 myShrinkFilter = vtkShrinkFilter::New();
75 myFeatureEdges = vtkFeatureEdges::New();
77 myGeomFilter = VTKViewer_GeometryFilter::New();
79 myTransformFilter = VTKViewer_TransformFilter::New();
81 for(int i = 0; i < 6; i++)
82 myPassFilter.push_back(vtkPassThroughFilter::New());
95 myGeomFilter->Delete();
97 myTransformFilter->Delete();
99 myShrinkFilter->Delete();
101 myFeatureEdges->Delete();
103 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
104 myPassFilter[i]->Delete();
108 To insert some additional filters and then sets the given vtkMapper
112 ::SetMapper(vtkMapper* theMapper)
114 InitPipeLine(theMapper);
118 To initialize internal pipeline
122 ::InitPipeLine(vtkMapper* theMapper)
126 myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
127 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
130 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
133 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
134 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
137 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
140 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
141 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
144 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
145 aMapper->SetInput(myPassFilter[anId]->GetOutput());
146 }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
147 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
150 Superclass::SetMapper(theMapper);
154 Allows to get initial vtkDataSet
160 return myPassFilter.front()->GetOutput();
164 Allows to set initial vtkDataSet
168 ::SetInput(vtkDataSet* theDataSet)
170 myMapper->SetInput(theDataSet);
171 InitPipeLine(myMapper);
175 To provide VTK to Object and backward mapping
179 SetStoreMapping(bool theStoreMapping)
181 myGeomFilter->SetStoreMapping(theStoreMapping);
186 \return time of modification
192 unsigned long mTime = this->Superclass::GetMTime();
194 mTime = max(mTime,myGeomFilter->GetMTime());
196 mTime = max(mTime,myTransformFilter->GetMTime());
199 mTime = max(mTime,myShrinkFilter->GetMTime());
201 if(myIsFeatureEdgesEnabled)
202 mTime = max(mTime,myFeatureEdges->GetMTime());
204 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
205 max(mTime,myPassFilter[i]->GetMTime());
211 Apply a view transformation
212 \param theTransform - transformation
216 ::SetTransform(VTKViewer_Transform* theTransform)
218 myTransformFilter->SetTransform(theTransform);
222 \return true if actor is shrinkable
228 return myIsShrinkable;
232 Changes shrinkable state of actor
233 theIsShrinkable - new shrinkable state
237 ::SetShrinkable(bool theIsShrinkable)
239 myIsShrinkable = theIsShrinkable;
243 \return true if actor is shrunkable
253 Insert shrink filter into pipeline
259 if ( !myIsShrinkable )
262 if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
265 int numCells=aDataSet->GetNumberOfCells();
266 int numPts = aDataSet->GetNumberOfPoints();
267 //It's impossible to use to apply "shrink" for "empty" dataset
268 if (numCells < 1 || numPts < 1)
270 myShrinkFilter->SetInput( aDataSet );
271 myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() );
277 Remove shrink filter from pipeline
283 if ( !myIsShrunk ) return;
284 if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
286 myPassFilter[ 1 ]->SetInput( aDataSet );
292 \return shrink factor
298 return myShrinkFilter->GetShrinkFactor();
302 Changes shrink factor
303 \param theValue - new shrink factor
307 ::SetShrinkFactor(vtkFloatingPointType theValue)
309 myShrinkFilter->SetShrinkFactor(theValue);
313 \return true if feature edges are allowed for this actor
317 ::IsFeatureEdgesAllowed()
319 return myIsFeatureEdgesAllowed;
323 Allows feature edges for this actor on or off
324 \param theIsFeatureEdgesAllowed - flag which allows feature edges for this actor on or off
328 ::SetFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
330 myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
334 \return true if feature edges are enabled
338 ::IsFeatureEdgesEnabled()
340 return myIsFeatureEdgesEnabled;
344 Enables feature edges on or off
345 \param theIsFeatureEdgesEnabled - flag which enables feature edges on or off
349 ::SetFeatureEdgesEnabled(bool theIsFeatureEdgesEnabled)
351 if ( !myIsFeatureEdgesAllowed || myIsFeatureEdgesEnabled == theIsFeatureEdgesEnabled )
354 if ( vtkPolyData* aPolyData = myPassFilter[ 2 ]->GetPolyDataOutput() )
356 if( theIsFeatureEdgesEnabled )
359 myFeatureEdges->SetInput( aPolyData );
360 myPassFilter[ 3 ]->SetInput( myFeatureEdges->GetOutput() );
361 myIsFeatureEdgesEnabled = true;
365 myPassFilter[3]->SetInput( aPolyData );
366 myIsFeatureEdgesEnabled = false;
368 myIsFeatureEdgesEnabled = theIsFeatureEdgesEnabled;
373 \return angle of feature edges' filter
377 ::GetFeatureEdgesAngle()
379 return myFeatureEdges->GetFeatureAngle();
383 Sets angle of feature edges' filter
384 \param theAngle angle of feature edges' filter
388 ::SetFeatureEdgesAngle(vtkFloatingPointType theAngle)
390 myFeatureEdges->SetFeatureAngle(theAngle);
394 Gets information about kinds of edges which are displayed by feature edges' filter
395 \param theIsFeatureEdges flag which shows whether feature edges are displayed
396 \param theIsBoundaryEdges flag which shows whether boundary edges are displayed
397 \param theIsManifoldEdges flag which shows whether manifold edges are displayed
398 \param theIsNonManifoldEdges flag which shows whether non-manifold edges are displayed
402 ::GetFeatureEdgesFlags(bool& theIsFeatureEdges,
403 bool& theIsBoundaryEdges,
404 bool& theIsManifoldEdges,
405 bool& theIsNonManifoldEdges)
407 theIsFeatureEdges = myFeatureEdges->GetFeatureEdges();
408 theIsBoundaryEdges = myFeatureEdges->GetBoundaryEdges();
409 theIsManifoldEdges = myFeatureEdges->GetManifoldEdges();
410 theIsNonManifoldEdges = myFeatureEdges->GetNonManifoldEdges();
414 Sets different kinds of edges to be displayed by feature edges' filter
415 \param theIsFeatureEdges flag which displays feature edges
416 \param theIsBoundaryEdges flag which displays boundary edges
417 \param theIsManifoldEdges flag which displays manifold edges
418 \param theIsNonManifoldEdges flag which displays non-manifold edges
422 ::SetFeatureEdgesFlags(bool theIsFeatureEdges,
423 bool theIsBoundaryEdges,
424 bool theIsManifoldEdges,
425 bool theIsNonManifoldEdges)
427 myFeatureEdges->SetFeatureEdges(theIsFeatureEdges);
428 myFeatureEdges->SetBoundaryEdges(theIsBoundaryEdges);
429 myFeatureEdges->SetManifoldEdges(theIsManifoldEdges);
430 myFeatureEdges->SetNonManifoldEdges(theIsNonManifoldEdges);
434 \return feature edges' coloring flag
438 ::GetFeatureEdgesColoring()
440 return myFeatureEdges->GetColoring();
444 Sets feature edges' coloring flag
445 \param theIsColoring feature edges' coloring flag
449 ::SetFeatureEdgesColoring(bool theIsColoring)
451 myFeatureEdges->SetColoring(theIsColoring);
455 Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
456 param theMode - new mode
460 ::SetRepresentation(SVTK::Representation::Type theMode)
462 using namespace SVTK::Representation;
464 switch(myRepresentation){
467 myProperty->SetAmbient(GetProperty()->GetAmbient());
468 myProperty->SetDiffuse(GetProperty()->GetDiffuse());
469 myProperty->SetSpecular(GetProperty()->GetSpecular());
475 GetProperty()->SetAmbient(myProperty->GetAmbient());
476 GetProperty()->SetDiffuse(myProperty->GetDiffuse());
477 GetProperty()->SetSpecular(myProperty->GetSpecular());
480 GetProperty()->SetAmbient(1.0);
481 GetProperty()->SetDiffuse(0.0);
482 GetProperty()->SetSpecular(0.0);
488 myGeomFilter->SetInside(true);
489 myGeomFilter->SetWireframeMode(true);
490 GetProperty()->SetRepresentation(VTK_WIREFRAME);
493 GetProperty()->SetPointSize(GetDefaultPointSize());
494 GetProperty()->SetRepresentation(VTK_POINTS);
495 myGeomFilter->SetWireframeMode(false);
496 myGeomFilter->SetInside(false);
499 GetProperty()->SetRepresentation(VTK_WIREFRAME);
500 myGeomFilter->SetWireframeMode(true);
501 myGeomFilter->SetInside(false);
504 GetProperty()->SetRepresentation(VTK_SURFACE);
505 myGeomFilter->SetWireframeMode(false);
506 myGeomFilter->SetInside(false);
510 myRepresentation = theMode;
514 \return current representation mode
516 SVTK::Representation::Type
518 ::GetRepresentation()
520 return myRepresentation;
524 \return default point size
528 ::GetDefaultPointSize()
534 \return default line width
538 ::GetDefaultLineWidth()
544 \return true if actor is shaded
554 Sets shaded state of actor
555 \param theShaded - new shaded state
559 ::SetShaded(bool theShaded)
561 myIsShaded = theShaded;
565 Maps VTK index of a node to corresponding object index
569 ::GetNodeObjId(int theVtkID)
575 Get coordinates of a node for given object index
577 vtkFloatingPointType*
579 ::GetNodeCoord(int theObjID)
581 return GetInput()->GetPoint(theObjID);
586 Get corresponding #vtkCell for given object index
590 ::GetElemCell(int theObjID)
592 return GetInput()->GetCell(theObjID);
596 Maps VTK index of a cell to corresponding object index
600 ::GetElemObjId(int theVtkID)
610 ::Render(vtkRenderer *ren, vtkMapper* m)
612 if(myIsResolveCoincidentTopology){
613 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
614 vtkFloatingPointType aFactor, aUnit;
615 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
617 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
618 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
619 myPolygonOffsetUnits);
620 Superclass::Render(ren,m);
622 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
623 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
625 Superclass::Render(ren,m);
630 Set polygon offset parameters
631 \param factor, units - Opengl polygon offset parameters
635 ::SetPolygonOffsetParameters(vtkFloatingPointType factor,
636 vtkFloatingPointType units)
638 myPolygonOffsetFactor = factor;
639 myPolygonOffsetUnits = units;
643 Get polygon offset parameters
644 \param factor, units - Opengl polygon offset parameters
648 ::GetPolygonOffsetParameters(vtkFloatingPointType& factor,
649 vtkFloatingPointType& units)
651 factor = myPolygonOffsetFactor;
652 units = myPolygonOffsetUnits;
655 vtkDataSetMapper* SVTK_DeviceActor::GetDataSetMapper()