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 "SALOME_Actor.h"
37 #include "VTKViewer_Transform.h"
38 #include "VTKViewer_TransformFilter.h"
39 #include "VTKViewer_PassThroughFilter.h"
40 #include "VTKViewer_GeometryFilter.h"
43 //#include "utilities.h"
47 #include <vtkRenderer.h>
48 #include <vtkPolyData.h>
49 #include <vtkObjectFactory.h>
50 #include <vtkDataSetMapper.h>
51 #include <vtkPolyDataMapper.h>
52 #include <vtkProperty.h>
54 //using namespace std;
63 int SALOME_POINT_SIZE = 3;
66 vtkStandardNewMacro(SALOME_Actor);
69 SALOME_Actor::SALOME_Actor(){
70 myIsHighlighted = myIsPreselected = false;
73 myDisplayMode = myRepresentation - 1;
75 myProperty = vtkProperty::New();
76 PreviewProperty = NULL;
80 myIsResolveCoincidentTopology = true;
82 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
83 myPolygonOffsetUnits);
84 myStoreMapping = false;
85 myGeomFilter = VTKViewer_GeometryFilter::New();
87 myTransformFilter = VTKViewer_TransformFilter::New();
89 for(int i = 0; i < 6; i++)
90 myPassFilter.push_back(VTKViewer_PassThroughFilter::New());
94 SALOME_Actor::~SALOME_Actor(){
95 SetPreviewProperty(NULL);
97 myGeomFilter->UnRegisterAllOutputs();
98 myGeomFilter->Delete();
100 myTransformFilter->UnRegisterAllOutputs();
101 myTransformFilter->Delete();
103 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){
105 myPassFilter[i]->UnRegisterAllOutputs();
106 myPassFilter[i]->Delete();
110 myProperty->Delete();
114 void SALOME_Actor::AddToRender(vtkRenderer* theRenderer){
115 theRenderer->AddActor(this);
118 void SALOME_Actor::RemoveFromRender(vtkRenderer* theRenderer){
119 theRenderer->RemoveActor(this);
123 void SALOME_Actor::SetTransform(VTKViewer_Transform* theTransform){
124 myTransformFilter->SetTransform(theTransform);
128 void SALOME_Actor::SetMapper(vtkMapper* theMapper){
129 InitPipeLine(theMapper);
132 void SALOME_Actor::InitPipeLine(vtkMapper* theMapper){
135 myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
136 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
139 myGeomFilter->SetStoreMapping( myStoreMapping );
140 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
143 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
144 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
147 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
150 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
151 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
154 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
155 aMapper->SetInput(myPassFilter[anId]->GetOutput());
156 }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
157 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
160 vtkLODActor::SetMapper(theMapper);
164 void SALOME_Actor::Render(vtkRenderer *ren, vtkMapper* m){
165 if(myIsResolveCoincidentTopology){
166 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
167 float aFactor, aUnit;
168 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
170 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
171 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
172 myPolygonOffsetUnits);
173 vtkLODActor::Render(ren,m);
175 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
176 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
178 vtkLODActor::Render(ren,m);
183 void SALOME_Actor::SetResolveCoincidentTopology(bool theIsResolve) {
184 myIsResolveCoincidentTopology = theIsResolve;
187 void SALOME_Actor::SetPolygonOffsetParameters(float factor, float units){
188 myPolygonOffsetFactor = factor;
189 myPolygonOffsetUnits = units;
192 void SALOME_Actor::GetPolygonOffsetParameters(float& factor, float& units){
193 factor = myPolygonOffsetFactor;
194 units = myPolygonOffsetUnits;
198 vtkDataSet* SALOME_Actor::GetInput(){
199 return myPassFilter.front()->GetOutput();
203 unsigned long int SALOME_Actor::GetMTime(){
204 unsigned long mTime = this->Superclass::GetMTime();
205 unsigned long time = myTransformFilter->GetMTime();
206 mTime = ( time > mTime ? time : mTime );
207 if(vtkDataSet *aDataSet = myPassFilter[0]->GetInput()){
208 time = aDataSet->GetMTime();
209 mTime = ( time > mTime ? time : mTime );
215 void SALOME_Actor::SetRepresentation(int theMode) {
216 switch(myRepresentation){
219 myProperty->DeepCopy(GetProperty());
224 GetProperty()->DeepCopy(myProperty);
227 GetProperty()->SetAmbient(1.0);
228 GetProperty()->SetDiffuse(0.0);
229 GetProperty()->SetSpecular(0.0);
233 myGeomFilter->SetInside(true);
234 GetProperty()->SetRepresentation(1);
237 GetProperty()->SetPointSize(SALOME_POINT_SIZE);
239 GetProperty()->SetRepresentation(theMode);
240 myGeomFilter->SetInside(false);
242 myRepresentation = theMode;
245 int SALOME_Actor::GetRepresentation(){
246 return myRepresentation;
250 vtkCell* SALOME_Actor::GetElemCell(int theObjID){
251 return GetInput()->GetCell(theObjID);
255 float* SALOME_Actor::GetNodeCoord(int theObjID){
256 return GetInput()->GetPoint(theObjID);
260 //=================================================================================
261 // function : GetObjDimension
262 // purpose : Return object dimension.
263 // Virtual method shoulb be redifined by derived classes
264 //=================================================================================
265 int SALOME_Actor::GetObjDimension( const int theObjId )
267 if ( vtkCell* aCell = GetElemCell(theObjId) )
268 return aCell->GetCellDimension();
273 bool SALOME_Actor::IsInfinitive(){
278 void SALOME_Actor::SetOpacity(float theOpacity){
279 myOpacity = theOpacity;
280 GetProperty()->SetOpacity(theOpacity);
283 float SALOME_Actor::GetOpacity(){
288 void SALOME_Actor::SetColor(float r,float g,float b){
289 GetProperty()->SetColor(r,g,b);
292 void SALOME_Actor::GetColor(float& r,float& g,float& b){
294 GetProperty()->GetColor(aColor);
301 int SALOME_Actor::getDisplayMode(){
302 return myDisplayMode;
305 void SALOME_Actor::setDisplayMode(int theMode){
306 SetRepresentation(theMode+1);
307 myDisplayMode = GetRepresentation() - 1;