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 // SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
23 // File : SALOME_Actor.cxx
24 // Author : Nicolas REJNERI
29 \class SALOME_Actor SALOME_Actor.h
30 \brief Abstract class of SALOME Objects in VTK.
34 #include "VTKViewer_Actor.h"
36 #include "VTKViewer_Transform.h"
37 #include "VTKViewer_TransformFilter.h"
38 #include "VTKViewer_GeometryFilter.h"
42 #include <vtkPolyData.h>
43 #include <vtkObjectFactory.h>
44 #include <vtkDataSetMapper.h>
45 #include <vtkPolyDataMapper.h>
46 #include <vtkProperty.h>
47 #include <vtkRenderer.h>
48 #include <vtkPassThroughFilter.h>
58 int VTKViewer_POINT_SIZE = 5;
59 int VTKViewer_LINE_WIDTH = 3;
62 vtkStandardNewMacro(VTKViewer_Actor);
69 myIsHighlighted(false),
70 myIsPreselected(false),
71 myRepresentation(VTK_SURFACE),
73 myProperty(vtkProperty::New()),
74 PreviewProperty(NULL),
76 myIsResolveCoincidentTopology(true),
77 myStoreMapping(false),
78 myGeomFilter(VTKViewer_GeometryFilter::New()),
79 myTransformFilter(VTKViewer_TransformFilter::New())
81 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
82 myPolygonOffsetUnits);
84 for(int i = 0; i < 6; i++)
85 myPassFilter.push_back(vtkPassThroughFilter::New());
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();
114 return myName.c_str();
119 \param theName - new name
123 ::setName(const char* theName)
129 To publish the actor an all its internal devices
133 ::AddToRender(vtkRenderer* theRenderer)
135 theRenderer->AddActor(this);
139 To remove the actor an all its internal devices
143 ::RemoveFromRender(vtkRenderer* theRenderer)
145 theRenderer->RemoveActor(this);
149 Used to obtain all dependent actors
153 ::GetChildActors(vtkActorCollection*)
157 Apply view transformation
158 \param theTransform - view transformation
162 ::SetTransform(VTKViewer_Transform* theTransform)
164 myTransformFilter->SetTransform(theTransform);
169 To insert some additional filters and then sets the given #vtkMapper
173 ::SetMapper(vtkMapper* theMapper)
175 InitPipeLine(theMapper);
183 ::InitPipeLine(vtkMapper* theMapper)
187 myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
188 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
191 myGeomFilter->SetStoreMapping( myStoreMapping );
192 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
195 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
196 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
199 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
202 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
203 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
206 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
207 aMapper->SetInput(myPassFilter[anId]->GetOutput());
208 }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
209 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
212 Superclass::SetMapper(theMapper);
220 ::Render(vtkRenderer *ren, vtkMapper* m)
222 if(vtkDataSet* aDataSet = GetInput()){
223 static vtkFloatingPointType PERCENTS_OF_DETAILS = 0.50;
224 vtkIdType aNbOfPoints = vtkIdType(aDataSet->GetNumberOfPoints()*PERCENTS_OF_DETAILS);
226 SetNumberOfCloudPoints(aNbOfPoints);
229 if(myIsResolveCoincidentTopology){
230 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
231 vtkFloatingPointType aFactor, aUnit;
232 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
234 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
235 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
236 myPolygonOffsetUnits);
237 Superclass::Render(ren,m);
239 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
240 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
242 Superclass::Render(ren,m);
247 Set ResolveCoincidentTopology flag
248 \param theIsResolve - new flag value
252 ::SetResolveCoincidentTopology(bool theIsResolve)
254 myIsResolveCoincidentTopology = theIsResolve;
258 Set polygon offset parameters
259 \param factor, units - Opengl polygon offset parameters
263 ::SetPolygonOffsetParameters(vtkFloatingPointType factor,
264 vtkFloatingPointType units)
266 myPolygonOffsetFactor = factor;
267 myPolygonOffsetUnits = units;
271 Get polygon offset parameters
272 \param factor, units - Opengl polygon offset parameters
276 ::GetPolygonOffsetParameters(vtkFloatingPointType& factor,
277 vtkFloatingPointType& units)
279 factor = myPolygonOffsetFactor;
280 units = myPolygonOffsetUnits;
284 \return shrink factor
294 \return true if the actor is shrunkable
304 \return true if the actor is shrunk
314 Insert shrink filter into pipeline
322 Remove shrink filter from pipeline
330 Allows to get initial #vtkDataSet
336 return myPassFilter.front()->GetOutput();
340 To calculatate last modified time
346 unsigned long mTime = this->Superclass::GetMTime();
347 unsigned long time = myTransformFilter->GetMTime();
348 mTime = ( time > mTime ? time : mTime );
349 if(vtkDataSet *aDataSet = dynamic_cast<vtkDataSet*>(myPassFilter[0]->GetInput())){ // bad usage of GetInput
350 time = aDataSet->GetMTime();
351 mTime = ( time > mTime ? time : mTime );
357 Set representation (VTK_SURFACE, VTK_POINTS, VTK_WIREFRAME and so on)
358 param theMode - new mode
362 ::SetRepresentation(int theMode)
364 switch(myRepresentation){
367 myProperty->SetAmbient(GetProperty()->GetAmbient());
368 myProperty->SetDiffuse(GetProperty()->GetDiffuse());
369 myProperty->SetSpecular(GetProperty()->GetSpecular());
376 GetProperty()->SetAmbient(myProperty->GetAmbient());
377 GetProperty()->SetDiffuse(myProperty->GetDiffuse());
378 GetProperty()->SetSpecular(myProperty->GetSpecular());
381 GetProperty()->SetAmbient(1.0);
382 GetProperty()->SetDiffuse(0.0);
383 GetProperty()->SetSpecular(0.0);
388 myGeomFilter->SetInside(true);
389 myGeomFilter->SetWireframeMode(true);
390 GetProperty()->SetRepresentation(VTK_WIREFRAME);
393 GetProperty()->SetPointSize(VTKViewer_POINT_SIZE);
394 GetProperty()->SetRepresentation(theMode);
395 myGeomFilter->SetWireframeMode(false);
396 myGeomFilter->SetInside(false);
399 GetProperty()->SetRepresentation(theMode);
400 myGeomFilter->SetWireframeMode(true);
401 myGeomFilter->SetInside(false);
404 GetProperty()->SetRepresentation(theMode);
405 myGeomFilter->SetWireframeMode(false);
406 myGeomFilter->SetInside(false);
410 myRepresentation = theMode;
414 \return current representation mode
418 ::GetRepresentation()
420 return myRepresentation;
424 Maps VTK index of a node to corresponding object index
428 ::GetNodeObjId(int theVtkID)
434 Get coordinates of a node for given object index
436 vtkFloatingPointType*
438 ::GetNodeCoord(int theObjID)
440 return GetInput()->GetPoint(theObjID);
444 Get corresponding #vtkCell for given object index
448 ::GetElemCell(int theObjID)
450 return GetInput()->GetCell(theObjID);
454 Maps VTK index of a cell to corresponding object index
458 ::GetElemObjId(int theVtkID)
465 \return object dimension. Virtual method should be redifined by derived classes
469 ::GetObjDimension( const int theObjId )
471 if ( vtkCell* aCell = GetElemCell(theObjId) )
472 return aCell->GetCellDimension();
477 Infinitive means actor without size (point for example),
478 which is not taken into account in calculation of boundaries of the scene
482 ::SetInfinitive(bool theIsInfinite)
484 myIsInfinite = theIsInfinite;
488 \return infinive flag
497 static vtkFloatingPointType MAX_DISTANCE = 0.9*VTK_LARGE_FLOAT;
498 vtkFloatingPointType aBounds[6];
500 for(int i = 0; i < 6; i++)
501 if(fabs(aBounds[i]) > MAX_DISTANCE)
504 static vtkFloatingPointType MIN_DISTANCE = 1.0/VTK_LARGE_FLOAT;
505 if(GetLength() < MIN_DISTANCE)
512 \return current bounding box
514 vtkFloatingPointType*
518 return Superclass::GetBounds();
523 \return current bounding box
527 ::GetBounds(vtkFloatingPointType theBounds[6])
529 Superclass::GetBounds(theBounds);
535 ::IsSetCamera() const
542 ::IsResizable() const
549 ::SetSize( const vtkFloatingPointType )
555 ::SetCamera( vtkCamera* )
561 ::SetOpacity(vtkFloatingPointType theOpacity)
563 myOpacity = theOpacity;
564 GetProperty()->SetOpacity(theOpacity);
580 ::SetColor(vtkFloatingPointType r,
581 vtkFloatingPointType g,
582 vtkFloatingPointType b)
584 GetProperty()->SetColor(r,g,b);
592 ::SetColor(const vtkFloatingPointType theRGB[3])
594 SetColor(theRGB[0],theRGB[1],theRGB[2]);
602 ::GetColor(vtkFloatingPointType& r,
603 vtkFloatingPointType& g,
604 vtkFloatingPointType& b)
606 vtkFloatingPointType aColor[3];
607 GetProperty()->GetColor(aColor);
621 return myDisplayMode;
629 ::setDisplayMode(int theMode)
631 SetRepresentation(theMode + 1);
632 myDisplayMode = GetRepresentation() - 1;
637 \return true if the descendant of the VTKViewer_Actor will implement its own highlight or not
647 \return true if the VTKViewer_Actor is already highlighted
653 return myIsHighlighted;
657 Set preselection mode
661 ::SetPreSelected(bool thePreselect)
663 myIsPreselected = thePreselect;
667 Just to update visibility of the highlight devices
671 ::highlight(bool theIsHighlight)
673 myIsHighlighted = theIsHighlight;
676 vtkCxxSetObjectMacro(VTKViewer_Actor,PreviewProperty,vtkProperty);