1 // SVTK OBJECT : interactive object for SVTK visualization
3 // Copyright (C) 2003 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
24 // File : SVTK_DeviceActor.cxx
30 #include "SVTK_DeviceActor.h"
32 #include "VTKViewer_Transform.h"
33 #include "VTKViewer_TransformFilter.h"
34 #include "VTKViewer_GeometryFilter.h"
37 #include <vtkObjectFactory.h>
38 #include <vtkShrinkFilter.h>
40 #include <vtkPolyData.h>
41 #include <vtkUnstructuredGrid.h>
43 #include <vtkPolyDataMapper.h>
44 #include <vtkDataSetMapper.h>
46 #include <vtkPassThroughFilter.h>
50 vtkStandardNewMacro(SVTK_DeviceActor);
59 myIsShrinkable = true;
62 myProperty = vtkProperty::New();
63 myRepresentation = SVTK::Representation::Surface;
65 myIsResolveCoincidentTopology = true;
66 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
67 myPolygonOffsetUnits);
69 myMapper = vtkDataSetMapper::New();
71 myShrinkFilter = vtkShrinkFilter::New();
73 myGeomFilter = VTKViewer_GeometryFilter::New();
75 myTransformFilter = VTKViewer_TransformFilter::New();
77 for(int i = 0; i < 6; i++)
78 myPassFilter.push_back(vtkPassThroughFilter::New());
91 myGeomFilter->Delete();
93 myTransformFilter->Delete();
95 myShrinkFilter->Delete();
97 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
98 myPassFilter[i]->Delete();
102 To insert some additional filters and then sets the given vtkMapper
106 ::SetMapper(vtkMapper* theMapper)
108 InitPipeLine(theMapper);
112 To initialize internal pipeline
116 ::InitPipeLine(vtkMapper* theMapper)
120 myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
121 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
124 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
127 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
128 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
131 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
134 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
135 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
138 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
139 aMapper->SetInput(myPassFilter[anId]->GetOutput());
140 }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
141 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
144 Superclass::SetMapper(theMapper);
148 Allows to get initial vtkDataSet
154 return myPassFilter.front()->GetOutput();
158 Allows to set initial vtkDataSet
162 ::SetInput(vtkDataSet* theDataSet)
164 myMapper->SetInput(theDataSet);
165 InitPipeLine(myMapper);
169 To provide VTK to Object and backward mapping
173 SetStoreMapping(bool theStoreMapping)
175 myGeomFilter->SetStoreMapping(theStoreMapping);
180 \return time of modification
186 unsigned long mTime = this->Superclass::GetMTime();
188 mTime = max(mTime,myGeomFilter->GetMTime());
190 mTime = max(mTime,myTransformFilter->GetMTime());
193 mTime = max(mTime,myShrinkFilter->GetMTime());
195 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
196 max(mTime,myPassFilter[i]->GetMTime());
202 Apply a view transformation
203 \param theTransform - transformation
207 ::SetTransform(VTKViewer_Transform* theTransform)
209 myTransformFilter->SetTransform(theTransform);
213 \return true if actor is shrinkable
219 return myIsShrinkable;
223 Changes shrinkable state of actor
224 theIsShrinkable - new shrinkable state
228 ::SetShrinkable(bool theIsShrinkable)
230 myIsShrinkable = theIsShrinkable;
234 \return true if actor is shrunkable
244 Insert shrink filter into pipeline
250 if ( !myIsShrinkable )
253 if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
256 int numCells=aDataSet->GetNumberOfCells();
257 int numPts = aDataSet->GetNumberOfPoints();
258 //It's impossible to use to apply "shrink" for "empty" dataset
259 if (numCells < 1 || numPts < 1)
261 myShrinkFilter->SetInput( aDataSet );
262 myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() );
268 Remove shrink filter from pipeline
274 if ( !myIsShrunk ) return;
275 if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
277 myPassFilter[ 1 ]->SetInput( aDataSet );
283 \return shrink factor
289 return myShrinkFilter->GetShrinkFactor();
293 Changes shrink factor
294 \param theValue - new shrink factor
298 ::SetShrinkFactor(vtkFloatingPointType theValue)
300 myShrinkFilter->SetShrinkFactor(theValue);
304 Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
305 param theMode - new mode
309 ::SetRepresentation(SVTK::Representation::Type theMode)
311 using namespace SVTK::Representation;
313 switch(myRepresentation){
316 myProperty->SetAmbient(GetProperty()->GetAmbient());
317 myProperty->SetDiffuse(GetProperty()->GetDiffuse());
318 myProperty->SetSpecular(GetProperty()->GetSpecular());
324 GetProperty()->SetAmbient(myProperty->GetAmbient());
325 GetProperty()->SetDiffuse(myProperty->GetDiffuse());
326 GetProperty()->SetSpecular(myProperty->GetSpecular());
329 GetProperty()->SetAmbient(1.0);
330 GetProperty()->SetDiffuse(0.0);
331 GetProperty()->SetSpecular(0.0);
337 myGeomFilter->SetInside(true);
338 myGeomFilter->SetWireframeMode(true);
339 GetProperty()->SetRepresentation(VTK_WIREFRAME);
342 GetProperty()->SetPointSize(GetDefaultPointSize());
343 GetProperty()->SetRepresentation(VTK_POINTS);
344 myGeomFilter->SetWireframeMode(false);
345 myGeomFilter->SetInside(false);
348 GetProperty()->SetRepresentation(VTK_WIREFRAME);
349 myGeomFilter->SetWireframeMode(true);
350 myGeomFilter->SetInside(false);
353 GetProperty()->SetRepresentation(VTK_SURFACE);
354 myGeomFilter->SetWireframeMode(false);
355 myGeomFilter->SetInside(false);
359 myRepresentation = theMode;
363 \return current representation mode
365 SVTK::Representation::Type
367 ::GetRepresentation()
369 return myRepresentation;
373 \return default point size
377 ::GetDefaultPointSize()
383 \return default line width
387 ::GetDefaultLineWidth()
393 \return true if actor is shaded
403 Sets shaded state of actor
404 \param theShaded - new shaded state
408 ::SetShaded(bool theShaded)
410 myIsShaded = theShaded;
414 Maps VTK index of a node to corresponding object index
418 ::GetNodeObjId(int theVtkID)
424 Get coordinates of a node for given object index
426 vtkFloatingPointType*
428 ::GetNodeCoord(int theObjID)
430 return GetInput()->GetPoint(theObjID);
435 Get corresponding #vtkCell for given object index
439 ::GetElemCell(int theObjID)
441 return GetInput()->GetCell(theObjID);
445 Maps VTK index of a cell to corresponding object index
449 ::GetElemObjId(int theVtkID)
459 ::Render(vtkRenderer *ren, vtkMapper* m)
461 if(myIsResolveCoincidentTopology){
462 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
463 vtkFloatingPointType aFactor, aUnit;
464 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
466 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
467 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
468 myPolygonOffsetUnits);
469 Superclass::Render(ren,m);
471 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
472 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
474 Superclass::Render(ren,m);
479 Set polygon offset parameters
480 \param factor, units - Opengl polygon offset parameters
484 ::SetPolygonOffsetParameters(vtkFloatingPointType factor,
485 vtkFloatingPointType units)
487 myPolygonOffsetFactor = factor;
488 myPolygonOffsetUnits = units;
492 Get polygon offset parameters
493 \param factor, units - Opengl polygon offset parameters
497 ::GetPolygonOffsetParameters(vtkFloatingPointType& factor,
498 vtkFloatingPointType& units)
500 factor = myPolygonOffsetFactor;
501 units = myPolygonOffsetUnits;
504 vtkDataSetMapper* SVTK_DeviceActor::GetDataSetMapper()