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 //----------------------------------------------------------------------------
50 vtkStandardNewMacro(SVTK_DeviceActor);
53 //----------------------------------------------------------------------------
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());
81 //----------------------------------------------------------------------------
89 myGeomFilter->Delete();
91 myTransformFilter->Delete();
93 myShrinkFilter->Delete();
95 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
96 myPassFilter[i]->Delete();
100 //----------------------------------------------------------------------------
103 ::SetMapper(vtkMapper* theMapper)
105 InitPipeLine(theMapper);
110 ::InitPipeLine(vtkMapper* theMapper)
114 myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
115 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
118 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
121 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
122 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
125 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
128 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
129 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
132 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
133 aMapper->SetInput(myPassFilter[anId]->GetOutput());
134 }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
135 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
138 myPassFilter[ 0 ]->SetInput( NULL );
139 Superclass::SetMapper(theMapper);
142 //----------------------------------------------------------------------------
147 return myPassFilter.front()->GetOutput();
152 ::SetInput(vtkDataSet* theDataSet)
154 myMapper->SetInput(theDataSet);
155 InitPipeLine(myMapper);
158 //----------------------------------------------------------------------------
161 SetStoreMapping(bool theStoreMapping)
163 myGeomFilter->SetStoreMapping(theStoreMapping);
168 //----------------------------------------------------------------------------
173 unsigned long mTime = this->Superclass::GetMTime();
175 mTime = max(mTime,myGeomFilter->GetMTime());
177 mTime = max(mTime,myTransformFilter->GetMTime());
180 mTime = max(mTime,myShrinkFilter->GetMTime());
182 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
183 max(mTime,myPassFilter[i]->GetMTime());
189 //----------------------------------------------------------------------------
192 ::SetTransform(VTKViewer_Transform* theTransform)
194 myTransformFilter->SetTransform(theTransform);
198 //----------------------------------------------------------------------------
203 return myIsShrinkable;
208 ::SetShrinkable(bool theIsShrinkable)
210 myIsShrinkable = theIsShrinkable;
224 if ( !myIsShrinkable )
226 if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
228 myShrinkFilter->SetInput( aDataSet );
229 myPassFilter[ 1 ]->SetInput( myShrinkFilter->GetOutput() );
238 if ( !myIsShrunk ) return;
239 if ( vtkDataSet* aDataSet = myPassFilter[ 0 ]->GetOutput() )
241 myPassFilter[ 1 ]->SetInput( aDataSet );
250 return myShrinkFilter->GetShrinkFactor();
255 ::SetShrinkFactor(float theValue)
257 myShrinkFilter->SetShrinkFactor(theValue);
262 //----------------------------------------------------------------------------
265 ::SetRepresentation(SVTK::Representation::Type theMode)
267 using namespace SVTK::Representation;
269 switch(myRepresentation){
272 myProperty->DeepCopy(GetProperty());
278 GetProperty()->DeepCopy(myProperty);
281 GetProperty()->SetAmbient(1.0);
282 GetProperty()->SetDiffuse(0.0);
283 GetProperty()->SetSpecular(0.0);
289 myGeomFilter->SetInside(true);
290 myGeomFilter->SetWireframeMode(true);
291 GetProperty()->SetRepresentation(VTK_WIREFRAME);
294 GetProperty()->SetPointSize(GetDefaultPointSize());
295 GetProperty()->SetRepresentation(VTK_POINTS);
296 myGeomFilter->SetWireframeMode(false);
297 myGeomFilter->SetInside(false);
300 GetProperty()->SetRepresentation(VTK_WIREFRAME);
301 myGeomFilter->SetWireframeMode(true);
302 myGeomFilter->SetInside(false);
305 GetProperty()->SetRepresentation(VTK_SURFACE);
306 myGeomFilter->SetWireframeMode(false);
307 myGeomFilter->SetInside(false);
311 myRepresentation = theMode;
314 SVTK::Representation::Type
316 ::GetRepresentation()
318 return myRepresentation;
323 ::GetDefaultPointSize()
330 ::GetDefaultLineWidth()
345 ::SetShaded(bool theShaded)
347 myIsShaded = theShaded;
351 //----------------------------------------------------------------------------
354 ::GetNodeObjId(int theVtkID)
361 ::GetNodeCoord(int theObjID)
363 return GetInput()->GetPoint(theObjID);
369 ::GetElemCell(int theObjID)
371 return GetInput()->GetCell(theObjID);
376 ::GetElemObjId(int theVtkID)
382 //----------------------------------------------------------------------------
385 ::Render(vtkRenderer *ren, vtkMapper* m)
387 if(myIsResolveCoincidentTopology){
388 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
389 float aFactor, aUnit;
390 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
392 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
393 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
394 myPolygonOffsetUnits);
395 Superclass::Render(ren,m);
397 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
398 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
400 Superclass::Render(ren,m);
407 ::SetPolygonOffsetParameters(float factor, float units)
409 myPolygonOffsetFactor = factor;
410 myPolygonOffsetUnits = units;
415 ::GetPolygonOffsetParameters(float& factor, float& units)
417 factor = myPolygonOffsetFactor;
418 units = myPolygonOffsetUnits;