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
31 \class SALOME_Actor SALOME_Actor.h
32 \brief Abstract class of SALOME Objects in VTK.
35 #include "SALOME_Actor.h"
38 #include "utilities.h"
41 #include <vtkObjectFactory.h>
42 #include <vtkDataSetMapper.h>
43 #include <vtkPolyDataMapper.h>
44 #include <vtkGeometryFilter.h>
45 #include <vtkTransformPolyDataFilter.h>
47 void SALOME_Actor::Render(vtkRenderer *ren, vtkMapper *Mapper )
49 if (this->Mapper == NULL) {
50 MESSAGE ("No mapper for actor.")
54 vtkMapper *bestMapper;
55 bestMapper = this->Mapper;
57 /* render the property */
58 if (!this->Property) {
59 // force creation of a property
63 this->Property->Render(this, ren);
64 if (this->BackfaceProperty) {
65 this->BackfaceProperty->BackfaceRender(this, ren);
66 this->Device->SetBackfaceProperty(this->BackfaceProperty);
68 this->Device->SetProperty(this->Property);
71 /* render the texture */
73 this->Texture->Render(ren);
77 // Store information on time it takes to render.
78 // We might want to estimate time from the number of polygons in mapper.
79 this->Device->Render(ren,bestMapper);
80 this->EstimatedRenderTime = bestMapper->GetTimeToDraw();
83 int SALOME_Actor::RenderOpaqueGeometry(vtkViewport *vp)
85 int renderedSomething = 0;
86 vtkRenderer *ren = (vtkRenderer *)vp;
88 if ( ! this->Mapper ) {
92 // make sure we have a property
93 if (!this->Property) {
94 // force creation of a property
98 // is this actor opaque ?
99 if (this->GetIsOpaque()) {
100 this->Property->Render(this, ren);
102 // render the backface property
103 if (this->BackfaceProperty) {
104 this->BackfaceProperty->BackfaceRender(this, ren);
107 // render the texture
109 this->Texture->Render(ren);
111 this->Render(ren,this->Mapper);
113 renderedSomething = 1;
116 return renderedSomething;
119 void SALOME_Actor::ReleaseGraphicsResources(vtkWindow *renWin)
121 vtkActor::ReleaseGraphicsResources(renWin);
122 this->Mapper->ReleaseGraphicsResources(renWin);
125 void SALOME_Actor::AddToRender(vtkRenderer* theRenderer){
126 theRenderer->AddActor(this);
129 void SALOME_Actor::RemoveFromRender(vtkRenderer* theRenderer){
130 theRenderer->RemoveActor(this);
133 vtkPolyData* SALOME_Actor::GetPolyDataInput(){
134 return myPassFilter[3]->GetPolyDataOutput();
137 void SALOME_Actor::SetMapper(vtkMapper* theMapper){
139 myPassFilter[0]->SetInput(theMapper->GetInput());
140 myPassFilter[0]->Update();
141 myPassFilter[1]->SetInput(myPassFilter[0]->GetPolyDataOutput());
142 myPassFilter[1]->Update();
143 myTransformFilter->SetInput(myPassFilter[1]->GetPolyDataOutput());
144 myPassFilter[2]->SetInput(myTransformFilter->GetOutput());
145 myPassFilter[2]->Update();
146 myPassFilter[3]->SetInput(myPassFilter[2]->GetPolyDataOutput());
147 myPassFilter[3]->Update();
148 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper))
149 aMapper->SetInput(myPassFilter[3]->GetOutput());
150 else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper))
151 aMapper->SetInput(myPassFilter[3]->GetPolyDataOutput());
153 vtkLODActor::SetMapper(theMapper);
156 void SALOME_Actor::SetTransform(SALOME_Transform* theTransform){
157 myTransformFilter->SetTransform(theTransform);
158 myTransformFilter->Modified();
161 SALOME_Actor::SALOME_Actor(){
162 PreviewProperty = NULL;
163 myTransformFilter = SALOME_TransformFilter::New();
164 myPassFilter.push_back(SALOME_PassThroughFilter::New());
165 myPassFilter.push_back(SALOME_PassThroughFilter::New());
166 myPassFilter.push_back(SALOME_PassThroughFilter::New());
167 myPassFilter.push_back(SALOME_PassThroughFilter::New());
170 SALOME_Actor::~SALOME_Actor(){
171 SetPreviewProperty(NULL);
172 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
173 if(myPassFilter[i] != NULL)
174 myPassFilter[i]->Delete();