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>
53 int SALOME_POINT_SIZE = 3;
56 vtkStandardNewMacro(SALOME_Actor);
59 SALOME_Actor::SALOME_Actor(){
60 myIsHighlighted = myIsPreselected = false;
62 myRepresentation = VTK_WIREFRAME;
63 myDisplayMode = myRepresentation - 1;
65 myProperty = vtkProperty::New();
66 PreviewProperty = NULL;
70 myIsResolveCoincidentTopology = true;
72 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
73 myPolygonOffsetUnits);
74 myStoreMapping = false;
75 myGeomFilter = SALOME_GeometryFilter::New();
77 myTransformFilter = SALOME_TransformFilter::New();
79 for(int i = 0; i < 6; i++)
80 myPassFilter.push_back(SALOME_PassThroughFilter::New());
84 SALOME_Actor::~SALOME_Actor(){
85 SetPreviewProperty(NULL);
87 myGeomFilter->UnRegisterAllOutputs();
88 myGeomFilter->Delete();
90 myTransformFilter->UnRegisterAllOutputs();
91 myTransformFilter->Delete();
93 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){
95 myPassFilter[i]->UnRegisterAllOutputs();
96 myPassFilter[i]->Delete();
100 myProperty->Delete();
104 void SALOME_Actor::AddToRender(vtkRenderer* theRenderer){
105 theRenderer->AddActor(this);
108 void SALOME_Actor::RemoveFromRender(vtkRenderer* theRenderer){
109 theRenderer->RemoveActor(this);
113 void SALOME_Actor::SetTransform(SALOME_Transform* theTransform){
114 myTransformFilter->SetTransform(theTransform);
118 void SALOME_Actor::SetMapper(vtkMapper* theMapper){
119 InitPipeLine(theMapper);
122 void SALOME_Actor::InitPipeLine(vtkMapper* theMapper){
125 myPassFilter[ anId ]->SetInput( theMapper->GetInput() );
126 myPassFilter[ anId + 1]->SetInput( myPassFilter[ anId ]->GetOutput() );
129 myGeomFilter->SetStoreMapping( myStoreMapping );
130 myGeomFilter->SetInput( myPassFilter[ anId ]->GetOutput() );
133 myPassFilter[ anId ]->SetInput( myGeomFilter->GetOutput() );
134 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
137 myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
140 myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
141 myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
144 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper)){
145 aMapper->SetInput(myPassFilter[anId]->GetOutput());
146 }else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper)){
147 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
150 vtkLODActor::SetMapper(theMapper);
154 void SALOME_Actor::Render(vtkRenderer *ren, vtkMapper* m){
155 if(myIsResolveCoincidentTopology){
156 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
157 float aFactor, aUnit;
158 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
160 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
161 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
162 myPolygonOffsetUnits);
163 vtkLODActor::Render(ren,m);
165 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
166 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
168 vtkLODActor::Render(ren,m);
173 void SALOME_Actor::SetResolveCoincidentTopology(bool theIsResolve) {
174 myIsResolveCoincidentTopology = theIsResolve;
177 void SALOME_Actor::SetPolygonOffsetParameters(float factor, float units){
178 myPolygonOffsetFactor = factor;
179 myPolygonOffsetUnits = units;
182 void SALOME_Actor::GetPolygonOffsetParameters(float& factor, float& units){
183 factor = myPolygonOffsetFactor;
184 units = myPolygonOffsetUnits;
188 vtkDataSet* SALOME_Actor::GetInput(){
189 return myPassFilter.front()->GetOutput();
193 unsigned long int SALOME_Actor::GetMTime(){
194 unsigned long mTime = this->Superclass::GetMTime();
195 unsigned long time = myTransformFilter->GetMTime();
196 mTime = ( time > mTime ? time : mTime );
197 if(vtkDataSet *aDataSet = myPassFilter[0]->GetInput()){
198 time = aDataSet->GetMTime();
199 mTime = ( time > mTime ? time : mTime );
205 void SALOME_Actor::SetRepresentation(int theMode) {
206 switch(myRepresentation){
209 myProperty->DeepCopy(GetProperty());
214 GetProperty()->DeepCopy(myProperty);
217 GetProperty()->SetAmbient(1.0);
218 GetProperty()->SetDiffuse(0.0);
219 GetProperty()->SetSpecular(0.0);
223 myGeomFilter->SetInside(true);
224 GetProperty()->SetRepresentation(1);
227 GetProperty()->SetPointSize(SALOME_POINT_SIZE);
229 GetProperty()->SetRepresentation(theMode);
230 myGeomFilter->SetInside(false);
232 myRepresentation = theMode;
235 int SALOME_Actor::GetRepresentation(){
236 return myRepresentation;
240 vtkCell* SALOME_Actor::GetElemCell(int theObjID){
241 return GetInput()->GetCell(theObjID);
245 float* SALOME_Actor::GetNodeCoord(int theObjID){
246 return GetInput()->GetPoint(theObjID);
250 //=================================================================================
251 // function : GetObjDimension
252 // purpose : Return object dimension.
253 // Virtual method shoulb be redifined by derived classes
254 //=================================================================================
255 int SALOME_Actor::GetObjDimension( const int theObjId )
257 if ( vtkCell* aCell = GetElemCell(theObjId) )
258 return aCell->GetCellDimension();
263 bool SALOME_Actor::IsInfinitive(){
268 void SALOME_Actor::SetOpacity(float theOpacity){
269 myOpacity = theOpacity;
270 GetProperty()->SetOpacity(theOpacity);
273 float SALOME_Actor::GetOpacity(){
278 void SALOME_Actor::SetColor(float r,float g,float b){
279 GetProperty()->SetColor(r,g,b);
282 void SALOME_Actor::GetColor(float& r,float& g,float& b){
284 GetProperty()->GetColor(aColor);
291 int SALOME_Actor::getDisplayMode(){
292 return myDisplayMode;
295 void SALOME_Actor::setDisplayMode(int theMode){
296 SetRepresentation(theMode+1);
297 myDisplayMode = GetRepresentation() - 1;