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.
34 #include "SALOME_Actor.h"
35 #include "SALOME_Transform.h"
36 #include "SALOME_GeometryFilter.h"
37 #include "SALOME_TransformFilter.h"
38 #include "SALOME_PassThroughFilter.h"
41 #include "utilities.h"
45 #include <vtkRenderer.h>
46 #include <vtkPolyData.h>
47 #include <vtkObjectFactory.h>
48 #include <vtkDataSetMapper.h>
49 #include <vtkPolyDataMapper.h>
59 int SALOME_POINT_SIZE = 3;
62 vtkStandardNewMacro(SALOME_Actor);
65 SALOME_Actor::SALOME_Actor(){
66 myIsHighlighted = myIsPreselected = false;
69 myDisplayMode = myRepresentation - 1;
71 myProperty = vtkProperty::New();
72 PreviewProperty = NULL;
76 myIsResolveCoincidentTopology = true;
78 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
79 myPolygonOffsetUnits);
80 myStoreMapping = false;
81 myGeomFilter = SALOME_GeometryFilter::New();
83 myTransformFilter = SALOME_TransformFilter::New();
85 for(int i = 0; i < 6; i++)
86 myPassFilter.push_back(SALOME_PassThroughFilter::New());
90 SALOME_Actor::~SALOME_Actor(){
91 SetPreviewProperty(NULL);
93 myGeomFilter->UnRegisterAllOutputs();
94 myGeomFilter->Delete();
96 myTransformFilter->UnRegisterAllOutputs();
97 myTransformFilter->Delete();
99 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){
101 myPassFilter[i]->UnRegisterAllOutputs();
102 myPassFilter[i]->Delete();
106 myProperty->Delete();
110 void SALOME_Actor::AddToRender(vtkRenderer* theRenderer){
111 theRenderer->AddActor(this);
114 void SALOME_Actor::RemoveFromRender(vtkRenderer* theRenderer){
115 theRenderer->RemoveActor(this);
119 void SALOME_Actor::SetTransform(SALOME_Transform* theTransform){
120 myTransformFilter->SetTransform(theTransform);
124 void SALOME_Actor::SetMapper(vtkMapper* theMapper){
125 InitPipeLine(theMapper);
128 void SALOME_Actor::InitPipeLine(vtkMapper* theMapper){
131 myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
132 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
135 myGeomFilter->SetStoreMapping( myStoreMapping );
136 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
139 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
140 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
143 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
146 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
147 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
150 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
151 aMapper->SetInput(myPassFilter[anId]->GetOutput());
152 }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
153 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
156 vtkLODActor::SetMapper(theMapper);
160 void SALOME_Actor::Render(vtkRenderer *ren, vtkMapper* m){
161 if(myIsResolveCoincidentTopology){
162 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
163 float aFactor, aUnit;
164 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
166 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
167 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
168 myPolygonOffsetUnits);
169 vtkLODActor::Render(ren,m);
171 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
172 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
174 vtkLODActor::Render(ren,m);
179 void SALOME_Actor::SetResolveCoincidentTopology(bool theIsResolve) {
180 myIsResolveCoincidentTopology = theIsResolve;
183 void SALOME_Actor::SetPolygonOffsetParameters(float factor, float units){
184 myPolygonOffsetFactor = factor;
185 myPolygonOffsetUnits = units;
188 void SALOME_Actor::GetPolygonOffsetParameters(float& factor, float& units){
189 factor = myPolygonOffsetFactor;
190 units = myPolygonOffsetUnits;
194 vtkDataSet* SALOME_Actor::GetInput(){
195 return myPassFilter.front()->GetOutput();
199 unsigned long int SALOME_Actor::GetMTime(){
200 unsigned long mTime = this->Superclass::GetMTime();
201 unsigned long time = myTransformFilter->GetMTime();
202 mTime = ( time > mTime ? time : mTime );
203 if(vtkDataSet *aDataSet = myPassFilter[0]->GetInput()){
204 time = aDataSet->GetMTime();
205 mTime = ( time > mTime ? time : mTime );
211 void SALOME_Actor::SetRepresentation(int theMode) {
212 switch(myRepresentation){
215 myProperty->DeepCopy(GetProperty());
220 GetProperty()->DeepCopy(myProperty);
223 GetProperty()->SetAmbient(1.0);
224 GetProperty()->SetDiffuse(0.0);
225 GetProperty()->SetSpecular(0.0);
229 myGeomFilter->SetInside(true);
230 GetProperty()->SetRepresentation(1);
233 GetProperty()->SetPointSize(SALOME_POINT_SIZE);
235 GetProperty()->SetRepresentation(theMode);
236 myGeomFilter->SetInside(false);
238 myRepresentation = theMode;
241 int SALOME_Actor::GetRepresentation(){
242 return myRepresentation;
246 vtkCell* SALOME_Actor::GetElemCell(int theObjID){
247 return GetInput()->GetCell(theObjID);
251 float* SALOME_Actor::GetNodeCoord(int theObjID){
252 return GetInput()->GetPoint(theObjID);
256 //=================================================================================
257 // function : GetObjDimension
258 // purpose : Return object dimension.
259 // Virtual method shoulb be redifined by derived classes
260 //=================================================================================
261 int SALOME_Actor::GetObjDimension( const int theObjId )
263 if ( vtkCell* aCell = GetElemCell(theObjId) )
264 return aCell->GetCellDimension();
269 bool SALOME_Actor::IsInfinitive(){
274 void SALOME_Actor::SetOpacity(float theOpacity){
275 myOpacity = theOpacity;
276 GetProperty()->SetOpacity(theOpacity);
279 float SALOME_Actor::GetOpacity(){
284 void SALOME_Actor::SetColor(float r,float g,float b){
285 GetProperty()->SetColor(r,g,b);
288 void SALOME_Actor::GetColor(float& r,float& g,float& b){
290 GetProperty()->GetColor(aColor);
297 int SALOME_Actor::getDisplayMode(){
298 return myDisplayMode;
301 void SALOME_Actor::setDisplayMode(int theMode){
302 SetRepresentation(theMode+1);
303 myDisplayMode = GetRepresentation() - 1;