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"
44 #include <vtkObjectFactory.h>
45 #include <vtkDataSetMapper.h>
46 #include <vtkPolyDataMapper.h>
56 int SALOME_POINT_SIZE = 3;
59 vtkStandardNewMacro(SALOME_Actor);
62 SALOME_Actor::SALOME_Actor(){
63 PreviewProperty = NULL;
64 ispreselected = Standard_False;
65 myProperty = vtkProperty::New();
71 myStoreMapping = false;
72 myGeomFilter = SALOME_GeometryFilter::New();
74 myTransformFilter = SALOME_TransformFilter::New();
76 for(int i = 0; i < 6; i++)
77 myPassFilter.push_back(SALOME_PassThroughFilter::New());
81 SALOME_Actor::~SALOME_Actor(){
82 SetPreviewProperty(NULL);
84 myGeomFilter->UnRegisterAllOutputs();
85 myGeomFilter->Delete();
87 myTransformFilter->UnRegisterAllOutputs();
88 myTransformFilter->Delete();
90 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){
92 myPassFilter[i]->UnRegisterAllOutputs();
93 myPassFilter[i]->Delete();
101 void SALOME_Actor::AddToRender(vtkRenderer* theRenderer){
102 theRenderer->AddActor(this);
105 void SALOME_Actor::RemoveFromRender(vtkRenderer* theRenderer){
106 theRenderer->RemoveActor(this);
110 void SALOME_Actor::SetTransform(SALOME_Transform* theTransform){
111 myTransformFilter->SetTransform(theTransform);
114 void SALOME_Actor::SetMapper(vtkMapper* theMapper){
117 #if defined __GNUC_2__
118 myPassFilter[anId]->SetInput(theMapper->GetInput());
120 myPassFilter.at(anId)->SetInput(theMapper->GetInput());
122 myGeomFilter->SetStoreMapping(myStoreMapping);
123 #if defined __GNUC_2__
124 myGeomFilter->SetInput(myPassFilter[anId]->GetOutput());
126 myGeomFilter->SetInput(myPassFilter.at(anId)->GetOutput());
131 #if defined __GNUC_2__
132 myPassFilter[anId]->SetInput(myGeomFilter->GetOutput());
133 myPassFilter[anId+1]->SetInput(myPassFilter[anId]->GetOutput());
135 myPassFilter.at(anId)->SetInput(myGeomFilter->GetOutput());
136 myPassFilter.at(anId+1)->SetInput(myPassFilter.at(anId)->GetOutput());
140 #if defined __GNUC_2__
141 myPassFilter[anId+1]->SetInput(myPassFilter[anId]->GetOutput());
143 myPassFilter.at(anId+1)->SetInput(myPassFilter.at(anId)->GetOutput());
147 #if defined __GNUC_2__
148 myTransformFilter->SetInput(myPassFilter[anId]->GetPolyDataOutput());
150 myTransformFilter->SetInput(myPassFilter.at(anId)->GetPolyDataOutput());
154 #if defined __GNUC_2__
155 myPassFilter[anId]->SetInput(myTransformFilter->GetOutput());
156 myPassFilter[anId+1]->SetInput(myPassFilter[anId]->GetOutput());
158 myPassFilter.at(anId)->SetInput(myTransformFilter->GetOutput());
159 myPassFilter.at(anId+1)->SetInput(myPassFilter.at(anId)->GetOutput());
163 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper))
164 #if defined __GNUC_2__
165 aMapper->SetInput(myPassFilter[anId]->GetOutput());
167 aMapper->SetInput(myPassFilter.at(anId)->GetOutput());
169 else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper))
170 #if defined __GNUC_2__
171 aMapper->SetInput(myPassFilter[anId]->GetPolyDataOutput());
173 aMapper->SetInput(myPassFilter.at(anId)->GetPolyDataOutput());
176 vtkLODActor::SetMapper(theMapper);
179 vtkPolyData* SALOME_Actor::GetPolyDataInput(){
180 return myPassFilter.back()->GetPolyDataOutput();
184 unsigned long int SALOME_Actor::GetMTime(){
185 unsigned long mTime = this->Superclass::GetMTime();
186 unsigned long time = myTransformFilter->GetMTime();
187 mTime = ( time > mTime ? time : mTime );
188 if(vtkDataSet *aDataSet = myPassFilter[0]->GetInput()){
189 time = aDataSet->GetMTime();
190 mTime = ( time > mTime ? time : mTime );
196 void SALOME_Actor::SetRepresentation(int theMode) {
197 switch(myRepresentation){
200 myProperty->DeepCopy(GetProperty());
205 GetProperty()->DeepCopy(myProperty);
209 GetProperty()->SetAmbient(1.0);
210 GetProperty()->SetDiffuse(0.0);
211 GetProperty()->SetSpecular(0.0);
215 myGeomFilter->SetInside(true);
216 GetProperty()->SetRepresentation(1);
219 GetProperty()->SetPointSize(SALOME_POINT_SIZE);
221 GetProperty()->SetRepresentation(theMode);
222 myGeomFilter->SetInside(false);
224 myRepresentation = theMode;
227 int SALOME_Actor::GetRepresentation(){
228 return myRepresentation;
231 //=================================================================================
232 // function : GetObjDimension
233 // purpose : Return object dimension.
234 // Virtual method shoulb be redifined by derived classes
235 //=================================================================================
236 int SALOME_Actor::GetObjDimension( const int theObjId )
241 std::vector<int> aVtkList = GetVtkId( theObjId );
242 int nbVtk = aVtkList.size();
246 else if ( nbVtk > 1 )
250 if ( vtkDataSet* aGrid = GetMapper()->GetInput() )
252 if ( vtkCell* aCell = aGrid->GetCell( aVtkList.front() ) )
253 return aCell->GetCellDimension();