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>
51 int SALOME_POINT_SIZE = 3;
53 void SALOME_Actor::Render(vtkRenderer *ren, vtkMapper *Mapper )
55 if (this->Mapper == NULL) {
56 MESSAGE ("No mapper for actor.")
60 vtkMapper *bestMapper;
61 bestMapper = this->Mapper;
63 /* render the property */
64 if (!this->Property) {
65 // force creation of a property
69 this->Property->Render(this, ren);
70 if (this->BackfaceProperty) {
71 this->BackfaceProperty->BackfaceRender(this, ren);
72 this->Device->SetBackfaceProperty(this->BackfaceProperty);
74 this->Device->SetProperty(this->Property);
77 /* render the texture */
79 this->Texture->Render(ren);
83 // Store information on time it takes to render.
84 // We might want to estimate time from the number of polygons in mapper.
85 this->Device->Render(ren,bestMapper);
86 this->EstimatedRenderTime = bestMapper->GetTimeToDraw();
89 int SALOME_Actor::RenderOpaqueGeometry(vtkViewport *vp)
91 int renderedSomething = 0;
92 vtkRenderer *ren = (vtkRenderer *)vp;
94 if ( ! this->Mapper ) {
98 // make sure we have a property
99 if (!this->Property) {
100 // force creation of a property
104 // is this actor opaque ?
105 if (this->GetIsOpaque()) {
106 this->Property->Render(this, ren);
108 // render the backface property
109 if (this->BackfaceProperty) {
110 this->BackfaceProperty->BackfaceRender(this, ren);
113 // render the texture
115 this->Texture->Render(ren);
117 this->Render(ren,this->Mapper);
119 renderedSomething = 1;
122 return renderedSomething;
125 void SALOME_Actor::ReleaseGraphicsResources(vtkWindow *renWin)
127 vtkActor::ReleaseGraphicsResources(renWin);
128 this->Mapper->ReleaseGraphicsResources(renWin);
132 void SALOME_Actor::AddToRender(vtkRenderer* theRenderer){
133 theRenderer->AddActor(this);
135 void SALOME_Actor::RemoveFromRender(vtkRenderer* theRenderer){
136 theRenderer->RemoveActor(this);
140 vtkPolyData* SALOME_Actor::GetPolyDataInput(){
141 return myPassFilter[3]->GetPolyDataOutput();
144 void SALOME_Actor::SetMapper(vtkMapper* theMapper){
146 myPassFilter[0]->SetInput(theMapper->GetInput());
147 myPassFilter[1]->SetInput(myPassFilter[0]->GetPolyDataOutput());
148 myTransformFilter->SetInput(myPassFilter[1]->GetPolyDataOutput());
149 myPassFilter[2]->SetInput(myTransformFilter->GetOutput());
150 myPassFilter[3]->SetInput(myPassFilter[2]->GetPolyDataOutput());
151 if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper))
152 aMapper->SetInput(myPassFilter[3]->GetPolyDataOutput());
153 else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper))
154 aMapper->SetInput(myPassFilter[3]->GetPolyDataOutput());
156 vtkLODActor::SetMapper(theMapper);
159 void SALOME_Actor::SetTransform(SALOME_Transform* theTransform){
160 myTransformFilter->SetTransform(theTransform);
161 myTransformFilter->Modified();
165 void SALOME_Actor::SetRepresentation(int theMode) {
166 myRepresentation = theMode;
169 myPassFilter[0]->SetInside(true);
170 GetProperty()->SetRepresentation(1);
173 GetProperty()->SetPointSize(SALOME_POINT_SIZE);
175 GetProperty()->SetRepresentation(myRepresentation);
176 myPassFilter[0]->SetInside(false);
179 int SALOME_Actor::GetRepresentation(){
180 return myRepresentation;
184 SALOME_Actor::SALOME_Actor(){
185 PreviewProperty = NULL;
186 myRepresentation = 2;
187 myTransformFilter = SALOME_TransformFilter::New();
188 myPassFilter.push_back(SALOME_PassThroughFilter::New());
189 myPassFilter.push_back(SALOME_PassThroughFilter::New());
190 myPassFilter.push_back(SALOME_PassThroughFilter::New());
191 myPassFilter.push_back(SALOME_PassThroughFilter::New());
194 SALOME_Actor::~SALOME_Actor(){
195 myTransformFilter->Delete();
196 SetPreviewProperty(NULL);
197 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
198 if(myPassFilter[i] != NULL)
199 myPassFilter[i]->Delete();