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_TransformFilter.h"
37 #include "SALOME_PassThroughFilter.h"
38 #include "SALOME_GeometryFilter.h"
41 #include "utilities.h"
44 #include <vtkObjectFactory.h>
45 #include <vtkDataSetMapper.h>
46 #include <vtkPolyDataMapper.h>
47 #include <vtkTransformPolyDataFilter.h>
50 #include <vtkMapperCollection.h>
51 #include "vtkTimerLog.h"
55 int SALOME_POINT_SIZE = 3;
58 vtkStandardNewMacro(SALOME_Actor);
60 void SALOME_Actor::AddToRender(vtkRenderer* theRenderer){
61 theRenderer->AddActor(this);
63 void SALOME_Actor::RemoveFromRender(vtkRenderer* theRenderer){
64 theRenderer->RemoveActor(this);
68 vtkPolyData* SALOME_Actor::GetPolyDataInput(){
69 return myPassFilter[3]->GetPolyDataOutput();
72 void SALOME_Actor::SetMapper(vtkMapper* theMapper){
74 myPassFilter[0]->SetInput(theMapper->GetInput());
75 myPassFilter[1]->SetInput(myPassFilter[0]->GetPolyDataOutput());
76 myTransformFilter->SetInput(myPassFilter[1]->GetPolyDataOutput());
77 myPassFilter[2]->SetInput(myTransformFilter->GetOutput());
78 myPassFilter[3]->SetInput(myPassFilter[2]->GetPolyDataOutput());
79 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper))
80 aMapper->SetInput(myPassFilter[3]->GetPolyDataOutput());
81 else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper))
82 aMapper->SetInput(myPassFilter[3]->GetPolyDataOutput());
84 vtkLODActor::SetMapper(theMapper);
87 void SALOME_Actor::SetTransform(SALOME_Transform* theTransform){
88 myTransformFilter->SetTransform(theTransform);
92 unsigned long int SALOME_Actor::GetMTime(){
93 unsigned long mTime = this->Superclass::GetMTime();
94 unsigned long time = myTransformFilter->GetMTime();
95 mTime = ( time > mTime ? time : mTime );
100 void SALOME_Actor::SetRepresentation(int theMode) {
101 switch(myRepresentation){
104 myProperty->DeepCopy(GetProperty());
109 GetProperty()->DeepCopy(myProperty);
112 GetProperty()->SetAmbient(1.0);
113 GetProperty()->SetDiffuse(0.0);
114 GetProperty()->SetSpecular(0.0);
118 myPassFilter[0]->SetInside(true);
119 GetProperty()->SetRepresentation(1);
122 GetProperty()->SetPointSize(SALOME_POINT_SIZE);
124 GetProperty()->SetRepresentation(theMode);
125 myPassFilter[0]->SetInside(false);
127 myRepresentation = theMode;
129 int SALOME_Actor::GetRepresentation(){
130 return myRepresentation;
134 SALOME_Actor::SALOME_Actor(){
135 PreviewProperty = NULL;
136 ispreselected = Standard_False;
137 myProperty = vtkProperty::New();
138 myRepresentation = 2;
139 myTransformFilter = SALOME_TransformFilter::New();
140 myPassFilter.push_back(SALOME_PassThroughFilter::New());
141 myPassFilter.push_back(SALOME_PassThroughFilter::New());
142 myPassFilter.push_back(SALOME_PassThroughFilter::New());
143 myPassFilter.push_back(SALOME_PassThroughFilter::New());
146 SALOME_Actor::~SALOME_Actor(){
147 myTransformFilter->Delete();
148 SetPreviewProperty(NULL);
149 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
150 if(myPassFilter[i] != NULL){
151 myPassFilter[i]->UnRegisterAllOutputs();
152 myPassFilter[i]->Delete();
154 myProperty->Delete();