1 // SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
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 : SALOME_Actor.cxx
25 // Author : Nicolas REJNERI
30 \class SALOME_Actor SALOME_Actor.h
31 \brief Abstract class of SALOME Objects in VTK.
35 #include "VTKViewer_Actor.h"
37 #include "VTKViewer_Transform.h"
38 #include "VTKViewer_TransformFilter.h"
39 #include "VTKViewer_PassThroughFilter.h"
40 #include "VTKViewer_GeometryFilter.h"
44 #include <vtkPolyData.h>
45 #include <vtkObjectFactory.h>
46 #include <vtkDataSetMapper.h>
47 #include <vtkPolyDataMapper.h>
48 #include <vtkProperty.h>
49 #include <vtkRenderer.h>
59 int VTKViewer_POINT_SIZE = 5;
60 int VTKViewer_LINE_WIDTH = 3;
63 //----------------------------------------------------------------------------
64 vtkStandardNewMacro(VTKViewer_Actor);
67 //----------------------------------------------------------------------------
70 myIsHighlighted(false),
71 myIsPreselected(false),
72 myRepresentation(VTK_SURFACE),
74 myProperty(vtkProperty::New()),
75 PreviewProperty(NULL),
77 myIsResolveCoincidentTopology(true),
78 myStoreMapping(false),
79 myGeomFilter(VTKViewer_GeometryFilter::New()),
80 myTransformFilter(VTKViewer_TransformFilter::New())
82 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
83 myPolygonOffsetUnits);
85 for(int i = 0; i < 6; i++)
86 myPassFilter.push_back(VTKViewer_PassThroughFilter::New());
90 //----------------------------------------------------------------------------
94 SetPreviewProperty(NULL);
96 myGeomFilter->Delete();
98 myTransformFilter->Delete();
100 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
102 myPassFilter[i]->Delete();
104 myProperty->Delete();
108 //----------------------------------------------------------------------------
113 return myName.c_str();
118 ::setName(const char* theName)
124 //----------------------------------------------------------------------------
127 ::AddToRender(vtkRenderer* theRenderer)
129 theRenderer->AddActor(this);
134 ::RemoveFromRender(vtkRenderer* theRenderer)
136 theRenderer->RemoveActor(this);
141 ::GetChildActors(vtkActorCollection*)
145 //----------------------------------------------------------------------------
148 ::SetTransform(VTKViewer_Transform* theTransform)
150 myTransformFilter->SetTransform(theTransform);
156 ::SetMapper(vtkMapper* theMapper)
158 InitPipeLine(theMapper);
163 ::InitPipeLine(vtkMapper* theMapper)
167 myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
168 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
171 myGeomFilter->SetStoreMapping( myStoreMapping );
172 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
175 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
176 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
179 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
182 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
183 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
186 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
187 aMapper->SetInput(myPassFilter[anId]->GetOutput());
188 }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
189 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
192 Superclass::SetMapper(theMapper);
196 //----------------------------------------------------------------------------
199 ::Render(vtkRenderer *ren, vtkMapper* m)
201 if(myIsResolveCoincidentTopology){
202 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
203 float aFactor, aUnit;
204 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
206 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
207 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
208 myPolygonOffsetUnits);
209 Superclass::Render(ren,m);
211 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
212 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
214 Superclass::Render(ren,m);
221 ::SetResolveCoincidentTopology(bool theIsResolve)
223 myIsResolveCoincidentTopology = theIsResolve;
228 ::SetPolygonOffsetParameters(float factor, float units)
230 myPolygonOffsetFactor = factor;
231 myPolygonOffsetUnits = units;
236 ::GetPolygonOffsetParameters(float& factor, float& units)
238 factor = myPolygonOffsetFactor;
239 units = myPolygonOffsetUnits;
243 //----------------------------------------------------------------------------
276 //----------------------------------------------------------------------------
281 return myPassFilter.front()->GetOutput();
289 unsigned long mTime = this->Superclass::GetMTime();
290 unsigned long time = myTransformFilter->GetMTime();
291 mTime = ( time > mTime ? time : mTime );
292 if(vtkDataSet *aDataSet = myPassFilter[0]->GetInput()){
293 time = aDataSet->GetMTime();
294 mTime = ( time > mTime ? time : mTime );
300 //----------------------------------------------------------------------------
303 ::SetRepresentation(int theMode)
305 switch(myRepresentation){
308 myProperty->DeepCopy(GetProperty());
313 GetProperty()->DeepCopy(myProperty);
316 GetProperty()->SetAmbient(1.0);
317 GetProperty()->SetDiffuse(0.0);
318 GetProperty()->SetSpecular(0.0);
322 myGeomFilter->SetInside(true);
323 myGeomFilter->SetWireframeMode(true);
324 GetProperty()->SetRepresentation(VTK_WIREFRAME);
327 GetProperty()->SetPointSize(VTKViewer_POINT_SIZE);
328 GetProperty()->SetRepresentation(theMode);
329 myGeomFilter->SetWireframeMode(false);
330 myGeomFilter->SetInside(false);
333 GetProperty()->SetRepresentation(theMode);
334 myGeomFilter->SetWireframeMode(true);
335 myGeomFilter->SetInside(false);
338 GetProperty()->SetRepresentation(theMode);
339 myGeomFilter->SetWireframeMode(false);
340 myGeomFilter->SetInside(false);
343 myRepresentation = theMode;
348 ::GetRepresentation()
350 return myRepresentation;
354 //----------------------------------------------------------------------------
357 ::GetNodeObjId(int theVtkID)
364 ::GetNodeCoord(int theObjID)
366 return GetInput()->GetPoint(theObjID);
371 ::GetElemCell(int theObjID)
373 return GetInput()->GetCell(theObjID);
378 ::GetElemObjId(int theVtkID)
384 //=================================================================================
385 // function : GetObjDimension
386 // purpose : Return object dimension.
387 // Virtual method shoulb be redifined by derived classes
388 //=================================================================================
391 ::GetObjDimension( const int theObjId )
393 if ( vtkCell* aCell = GetElemCell(theObjId) )
394 return aCell->GetCellDimension();
401 ::SetInfinitive(bool theIsInfinite)
403 myIsInfinite = theIsInfinite;
411 static float MIN_DISTANCE = 1.0 / VTK_LARGE_FLOAT;
413 if(myIsInfinite || GetLength() < MIN_DISTANCE)
424 return Superclass::GetBounds();
430 ::GetBounds(float theBounds[6])
432 Superclass::GetBounds(theBounds);
436 //----------------------------------------------------------------------------
439 ::IsSetCamera() const
446 ::IsResizable() const
453 ::SetSize( const float )
459 ::SetCamera( vtkCamera* )
462 //----------------------------------------------------------------------------
465 ::SetOpacity(float theOpacity)
467 myOpacity = theOpacity;
468 GetProperty()->SetOpacity(theOpacity);
481 ::SetColor(float r,float g,float b)
483 GetProperty()->SetColor(r,g,b);
488 ::SetColor(const float theRGB[3])
490 SetColor(theRGB[0],theRGB[1],theRGB[2]);
495 ::GetColor(float& r,float& g,float& b)
498 GetProperty()->GetColor(aColor);
505 //----------------------------------------------------------------------------
510 return myDisplayMode;
515 ::setDisplayMode(int theMode)
517 SetRepresentation(theMode + 1);
518 myDisplayMode = GetRepresentation() - 1;
522 //----------------------------------------------------------------------------
534 return myIsHighlighted;
539 ::SetPreSelected(bool thePreselect)
541 myIsPreselected = thePreselect;
545 //----------------------------------------------------------------
548 ::highlight(bool theIsHighlight)
550 myIsHighlighted = theIsHighlight;
553 vtkCxxSetObjectMacro(VTKViewer_Actor,PreviewProperty,vtkProperty);