]> SALOME platform Git repositories - modules/visu.git/blob - src/OBJECT/VISU_MeshAct.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / OBJECT / VISU_MeshAct.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : VISU_MeshAct.cxx
25 //  Author : 
26 //  Module : VISU
27 //  $Header$
28
29 #include "VISU_MeshAct.h"
30
31 #include <vtkObjectFactory.h>
32 #include <vtkRenderer.h>
33 #include <vtkTexture.h>
34
35 #include <vtkFeatureEdges.h>
36 #include <vtkDataSetMapper.h>
37 #include <vtkDataSet.h>
38 #include <vtkMatrix4x4.h>
39 #include <vtkMapperCollection.h>
40
41
42 //----------------------------------------------------------------------------
43 vtkStandardNewMacro(VISU_MeshAct);
44
45
46 //----------------------------------------------------------------------------
47 VISU_MeshAct
48 ::VISU_MeshAct()
49 {
50   vtkMatrix4x4 *m;
51   m = vtkMatrix4x4::New();
52
53   mySurfaceActor = SVTK_DeviceActor::New();
54   mySurfaceActor->SetRepresentation(SVTK::Representation::Surface);
55   mySurfaceActor->SetUserMatrix(m);
56
57   myEdgeActor = SVTK_DeviceActor::New();
58   myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
59   myEdgeActor->SetUserMatrix(m);
60
61   myNodeActor = SVTK_DeviceActor::New();
62   myNodeActor->SetRepresentation(SVTK::Representation::Points);
63   myNodeActor->SetUserMatrix(m);
64
65   m->Delete();
66   SetRepresentation(SVTK::Representation::Surface);
67 }
68
69 VISU_MeshAct
70 ::~VISU_MeshAct()
71 {
72   mySurfaceActor->Delete();
73   myEdgeActor->Delete();
74   myNodeActor->Delete();
75 }
76
77
78 //----------------------------------------------------------------------------
79 void
80 VISU_MeshAct
81 ::DeepCopy(VISU_Actor *theActor)
82 {
83   if(VISU_MeshAct* anActor = dynamic_cast<VISU_MeshAct*>(theActor)){
84     Superclass::DeepCopy(theActor);
85     GetSurfaceProperty()->DeepCopy(anActor->GetSurfaceProperty());
86     GetEdgeProperty()->DeepCopy(anActor->GetEdgeProperty());
87     GetNodeProperty()->DeepCopy(anActor->GetNodeProperty());
88   }
89 }
90
91
92 //----------------------------------------------------------------------------
93 void
94 VISU_MeshAct
95 ::SetMapperInput(vtkDataSet* theDataSet)
96 {
97   Superclass::SetMapperInput(theDataSet);
98
99   mySurfaceActor->SetInput(theDataSet);
100   myEdgeActor->SetInput(theDataSet);
101   myNodeActor->SetInput(theDataSet);
102 }
103
104
105 //----------------------------------------------------------------------------
106 void
107 VISU_MeshAct
108 ::SetTransform(VTKViewer_Transform* theTransform)
109 {
110   Superclass::SetTransform(theTransform);
111
112   mySurfaceActor->SetTransform(theTransform);
113   myEdgeActor->SetTransform(theTransform);
114   myNodeActor->SetTransform(theTransform);
115 }
116
117
118 //----------------------------------------------------------------------------
119 void
120 VISU_MeshAct
121 ::SetShrinkable(bool theIsShrinkable)
122 {
123   Superclass::SetShrinkable(theIsShrinkable);
124
125   mySurfaceActor->SetShrinkable(theIsShrinkable);
126   myEdgeActor->SetShrinkable(theIsShrinkable);
127 }
128
129 void
130 VISU_MeshAct
131 ::SetShrinkFactor(vtkFloatingPointType theValue)
132 {
133   Superclass::SetShrinkFactor(theValue);
134
135   mySurfaceActor->SetShrinkFactor(theValue);
136   myEdgeActor->SetShrinkFactor(theValue);
137 }
138
139
140 //----------------------------------------------------------------------------
141 vtkProperty* 
142 VISU_MeshAct
143 ::GetSurfaceProperty()
144 {
145   return mySurfaceActor->GetProperty();
146 }
147
148 vtkProperty* 
149 VISU_MeshAct
150 ::GetEdgeProperty()
151 {
152   return myEdgeActor->GetProperty();
153 }
154
155 vtkProperty* 
156 VISU_MeshAct
157 ::GetNodeProperty()
158 {
159   return myNodeActor->GetProperty();
160 }
161
162 //----------------------------------------------------------------------------
163 void
164 VISU_MeshAct
165 ::SetOpacity(vtkFloatingPointType theValue)
166 {
167   GetSurfaceProperty()->SetOpacity(theValue);
168 }
169
170 vtkFloatingPointType
171 VISU_MeshAct
172 ::GetOpacity()
173 {
174   return GetSurfaceProperty()->GetOpacity();
175 }
176
177 //----------------------------------------------------------------------------
178 void
179 VISU_MeshAct
180 ::SetLineWidth(vtkFloatingPointType theLineWidth)
181 {
182   GetEdgeProperty()->SetLineWidth(theLineWidth);
183 }
184
185 vtkFloatingPointType
186 VISU_MeshAct::GetLineWidth()
187 {
188   return GetEdgeProperty()->GetLineWidth();
189 }
190
191 //----------------------------------------------------------------------------
192 void
193 VISU_MeshAct
194 ::SetShrink()
195 {
196   if(myRepresentation == VTK_POINTS)
197     return;
198
199   Superclass::SetShrink();
200
201   mySurfaceActor->SetShrink();
202   myEdgeActor->SetShrink();
203 }
204
205 void
206 VISU_MeshAct
207 ::UnShrink()
208 {
209   Superclass::UnShrink();
210
211   mySurfaceActor->UnShrink();
212   myEdgeActor->UnShrink();
213 }
214
215
216 //----------------------------------------------------------------------------
217 void 
218 VISU_MeshAct
219 ::SetRepresentation(int theMode)
220 {
221   Superclass::SetRepresentation(theMode);
222
223   if(theMode == SVTK::Representation::Insideframe)
224     myEdgeActor->SetRepresentation(SVTK::Representation::Insideframe);
225   else
226     myEdgeActor->SetRepresentation(SVTK::Representation::Wireframe);
227 }
228
229 //----------------------------------------------------------------------------
230 unsigned long int
231 VISU_MeshAct
232 ::GetMemorySize()
233 {
234   vtkDataSet* aDataSet;
235   unsigned long int aSize = Superclass::GetMemorySize();
236   {
237     aDataSet = mySurfaceActor->GetInput();
238     aSize += aDataSet->GetActualMemorySize() * 1024;
239
240     aDataSet = mySurfaceActor->GetMapper()->GetInput();
241     aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
242   }
243   {
244     aDataSet = myEdgeActor->GetInput();
245     aSize += aDataSet->GetActualMemorySize() * 1024;
246
247     aDataSet = myEdgeActor->GetMapper()->GetInput();
248     aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
249   }
250   {
251     aDataSet = myNodeActor->GetInput();
252     aSize += aDataSet->GetActualMemorySize() * 1024;
253
254     aDataSet = myNodeActor->GetMapper()->GetInput();
255     aSize += aDataSet->GetActualMemorySize() * 1024 * 2;
256   }
257   return aSize;
258 }
259
260 //----------------------------------------------------------------------------
261 int
262 VISU_MeshAct
263 ::RenderOpaqueGeometry(vtkViewport *ren)
264 {
265   GetMatrix(myNodeActor->GetUserMatrix());
266   GetMatrix(myEdgeActor->GetUserMatrix());
267   GetMatrix(mySurfaceActor->GetUserMatrix());
268
269   using namespace SVTK::Representation;
270   switch(GetRepresentation()){
271   case Points : 
272     myNodeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
273     myNodeActor->RenderOpaqueGeometry(ren);
274     break;
275   case Wireframe : 
276   case Insideframe : 
277     myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
278     myEdgeActor->RenderOpaqueGeometry(ren);
279     break;
280   case Surface : 
281     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
282     mySurfaceActor->RenderOpaqueGeometry(ren);
283     break;
284   case Surfaceframe : 
285     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
286     mySurfaceActor->RenderOpaqueGeometry(ren);
287
288     myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
289     myEdgeActor->RenderOpaqueGeometry(ren);
290     break;
291   }
292   return 1;
293 }
294
295 int
296 VISU_MeshAct
297 ::RenderTranslucentGeometry(vtkViewport *ren)
298 {
299   GetMatrix(myNodeActor->GetUserMatrix());
300   GetMatrix(myEdgeActor->GetUserMatrix());
301   GetMatrix(mySurfaceActor->GetUserMatrix());
302
303   using namespace SVTK::Representation;
304   switch(GetRepresentation()){
305   case Points : 
306     myNodeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
307     myNodeActor->RenderTranslucentGeometry(ren);
308     break;
309   case Wireframe : 
310   case Insideframe : 
311     myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
312     myEdgeActor->RenderTranslucentGeometry(ren);
313     break;
314   case Surface : 
315     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
316     mySurfaceActor->RenderTranslucentGeometry(ren);
317     break;
318   case Surfaceframe : 
319     mySurfaceActor->SetAllocatedRenderTime(this->AllocatedRenderTime,ren);
320     mySurfaceActor->RenderTranslucentGeometry(ren);
321
322     myEdgeActor->SetAllocatedRenderTime(this->AllocatedRenderTime/2.0,ren);
323     myEdgeActor->RenderTranslucentGeometry(ren);
324     break;
325   }
326   return 1;
327 }