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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SVTK_DeviceActor.cxx
30 #include "SVTK_DeviceActor.h"
32 #include "VTKViewer_Transform.h"
33 #include "VTKViewer_TransformFilter.h"
34 #include "VTKViewer_PassThroughFilter.h"
35 #include "VTKViewer_GeometryFilter.h"
38 #include <vtkObjectFactory.h>
39 #include <vtkShrinkFilter.h>
41 #include <vtkPolyData.h>
42 #include <vtkUnstructuredGrid.h>
44 #include <vtkPolyDataMapper.h>
45 #include <vtkDataSetMapper.h>
49 vtkStandardNewMacro(SVTK_DeviceActor);
58 myIsShrinkable = true;
61 myProperty = vtkProperty::New();
62 myRepresentation = SVTK::Representation::Surface;
64 myIsResolveCoincidentTopology = false;
65 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
66 myPolygonOffsetUnits);
68 myMapper = vtkDataSetMapper::New();
70 myShrinkFilter = vtkShrinkFilter::New();
72 myGeomFilter = VTKViewer_GeometryFilter::New();
74 myTransformFilter = VTKViewer_TransformFilter::New();
76 for(int i = 0; i < 6; i++)
77 myPassFilter.push_back(VTKViewer_PassThroughFilter::New());
90 myGeomFilter->Delete();
92 myTransformFilter->Delete();
94 myShrinkFilter->Delete();
96 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
97 myPassFilter[i]->Delete();
101 To insert some additional filters and then sets the given vtkMapper
105 ::SetMapper(vtkMapper* theMapper)
107 InitPipeLine(theMapper);
111 To initialize internal pipeline
115 ::InitPipeLine(vtkMapper* theMapper)
119 myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
120 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
123 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
126 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
127 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
130 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
133 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
134 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
137 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
138 aMapper->SetInput(myPassFilter[anId]->GetOutput());
139 }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
140 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
143 myPassFilter[ 0 ]->SetInput( NULL );
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 )
252 if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
254 myShrinkFilter->SetInput( aDataSet );
255 myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() );
261 Remove shrink filter from pipeline
267 if ( !myIsShrunk ) return;
268 if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
270 myPassFilter[ 1 ]->SetInput( aDataSet );
276 \return shrink factor
282 return myShrinkFilter->GetShrinkFactor();
286 Changes shrink factor
287 \param theValue - new shrink factor
291 ::SetShrinkFactor(vtkFloatingPointType theValue)
293 myShrinkFilter->SetShrinkFactor(theValue);
298 Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
299 param theMode - new mode
303 ::SetRepresentation(SVTK::Representation::Type theMode)
305 using namespace SVTK::Representation;
307 switch(myRepresentation){
310 myProperty->DeepCopy(GetProperty());
316 GetProperty()->DeepCopy(myProperty);
319 GetProperty()->SetAmbient(1.0);
320 GetProperty()->SetDiffuse(0.0);
321 GetProperty()->SetSpecular(0.0);
327 myGeomFilter->SetInside(true);
328 myGeomFilter->SetWireframeMode(true);
329 GetProperty()->SetRepresentation(VTK_WIREFRAME);
332 GetProperty()->SetPointSize(GetDefaultPointSize());
333 GetProperty()->SetRepresentation(VTK_POINTS);
334 myGeomFilter->SetWireframeMode(false);
335 myGeomFilter->SetInside(false);
338 GetProperty()->SetRepresentation(VTK_WIREFRAME);
339 myGeomFilter->SetWireframeMode(true);
340 myGeomFilter->SetInside(false);
343 GetProperty()->SetRepresentation(VTK_SURFACE);
344 myGeomFilter->SetWireframeMode(false);
345 myGeomFilter->SetInside(false);
349 myRepresentation = theMode;
353 \return current representation mode
355 SVTK::Representation::Type
357 ::GetRepresentation()
359 return myRepresentation;
363 \return default point size
367 ::GetDefaultPointSize()
373 \return default line width
377 ::GetDefaultLineWidth()
383 \return true if actor is shaded
393 Sets shaded state of actor
394 \param theShaded - new shaded state
398 ::SetShaded(bool theShaded)
400 myIsShaded = theShaded;
404 Maps VTK index of a node to corresponding object index
408 ::GetNodeObjId(int theVtkID)
414 Get coordinates of a node for given object index
416 vtkFloatingPointType*
418 ::GetNodeCoord(int theObjID)
420 return GetInput()->GetPoint(theObjID);
425 Get corresponding #vtkCell for given object index
429 ::GetElemCell(int theObjID)
431 return GetInput()->GetCell(theObjID);
435 Maps VTK index of a cell to corresponding object index
439 ::GetElemObjId(int theVtkID)
449 ::Render(vtkRenderer *ren, vtkMapper* m)
451 if(myIsResolveCoincidentTopology){
452 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
453 vtkFloatingPointType aFactor, aUnit;
454 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
456 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
457 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
458 myPolygonOffsetUnits);
459 Superclass::Render(ren,m);
461 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
462 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
464 Superclass::Render(ren,m);
469 Set polygon offset parameters
470 \param factor, units - Opengl polygon offset parameters
474 ::SetPolygonOffsetParameters(vtkFloatingPointType factor,
475 vtkFloatingPointType units)
477 myPolygonOffsetFactor = factor;
478 myPolygonOffsetUnits = units;
482 Get polygon offset parameters
483 \param factor, units - Opengl polygon offset parameters
487 ::GetPolygonOffsetParameters(vtkFloatingPointType& factor,
488 vtkFloatingPointType& units)
490 factor = myPolygonOffsetFactor;
491 units = myPolygonOffsetUnits;