Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/kernel.git] / src / OBJECT / SALOME_Actor.cxx
1 //  SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_Actor.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 /*!
31   \class SALOME_Actor SALOME_Actor.h
32   \brief Abstract class of SALOME Objects in VTK.
33 */
34
35 #include "SALOME_Actor.h"
36  
37 // SALOME Includes
38 #include "utilities.h"
39
40 // VTK Includes
41 #include <vtkObjectFactory.h>
42 #include <vtkDataSetMapper.h>
43 #include <vtkPolyDataMapper.h>
44 #include <vtkGeometryFilter.h>
45 #include <vtkTransformPolyDataFilter.h>
46
47 void SALOME_Actor::Render(vtkRenderer *ren, vtkMapper *Mapper )
48 {
49   if (this->Mapper == NULL) {
50     MESSAGE ("No mapper for actor.")
51     return;
52   }
53   
54   vtkMapper *bestMapper;
55   bestMapper = this->Mapper;
56
57   /* render the property */
58   if (!this->Property) {
59     // force creation of a property
60     this->GetProperty();
61   }
62
63   this->Property->Render(this, ren);
64   if (this->BackfaceProperty) {
65     this->BackfaceProperty->BackfaceRender(this, ren);
66     this->Device->SetBackfaceProperty(this->BackfaceProperty);
67   }
68   this->Device->SetProperty(this->Property);
69   
70   
71   /* render the texture */
72   if (this->Texture) {
73     this->Texture->Render(ren);
74   }
75   
76   
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();
81 }
82
83 int SALOME_Actor::RenderOpaqueGeometry(vtkViewport *vp)
84 {
85   int renderedSomething = 0; 
86   vtkRenderer      *ren = (vtkRenderer *)vp;
87
88   if ( ! this->Mapper ) {
89     return 0;
90   }
91
92   // make sure we have a property
93   if (!this->Property) {
94     // force creation of a property
95     this->GetProperty();
96   }
97
98   // is this actor opaque ?
99   if (this->GetIsOpaque()) {
100     this->Property->Render(this, ren);
101     
102     // render the backface property
103     if (this->BackfaceProperty) {
104       this->BackfaceProperty->BackfaceRender(this, ren);
105     }
106     
107     // render the texture 
108     if (this->Texture) {
109       this->Texture->Render(ren);
110     }
111     this->Render(ren,this->Mapper);
112     
113     renderedSomething = 1;
114   }
115   
116   return renderedSomething; 
117 }
118
119 void SALOME_Actor::ReleaseGraphicsResources(vtkWindow *renWin)
120 {
121   vtkActor::ReleaseGraphicsResources(renWin);
122   this->Mapper->ReleaseGraphicsResources(renWin);
123 }
124
125 void SALOME_Actor::AddToRender(vtkRenderer* theRenderer){
126   theRenderer->AddActor(this);
127 }
128
129 void SALOME_Actor::RemoveFromRender(vtkRenderer* theRenderer){
130   theRenderer->RemoveActor(this);
131 }
132
133 vtkPolyData* SALOME_Actor::GetPolyDataInput(){
134   return myPassFilter[3]->GetPolyDataOutput();
135 }
136
137 void SALOME_Actor::SetMapper(vtkMapper* theMapper){
138   if(theMapper){
139     myPassFilter[0]->SetInput(theMapper->GetInput());
140     // myPassFilter[0]->Update();  -------- This and other three lines must be comment or removed to fix the regression in SMESH
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());
152   }
153   vtkLODActor::SetMapper(theMapper);
154 }
155
156 void SALOME_Actor::SetTransform(SALOME_Transform* theTransform){
157   myTransformFilter->SetTransform(theTransform);
158   myTransformFilter->Modified();
159 }
160
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());
168 }
169
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();
175 }