]> SALOME platform Git repositories - modules/visu.git/blob - src/OBJECT/VISU_MeshAct.cxx
Salome HOME
SMH: 3.0.0 preparation - merged and adopted version (POLYWORK+HEAD)
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VISU_MeshAct.cxx
25 //  Author : Laurent CORNABE with the help of Nicolas REJNERI
26 //  Module : VISU
27 //  $Header$
28
29 #include "VISU_MeshAct.h"
30 #include "VTKViewer_PassThroughFilter.h"
31
32 #include <vtkObjectFactory.h>
33 #include <vtkRenderer.h>
34 #include <vtkTexture.h>
35
36 #include <vtkFeatureEdges.h>
37 #include <vtkDataSetMapper.h>
38 #include <vtkDataSet.h>
39 #include <vtkMatrix4x4.h>
40 #include <vtkMapperCollection.h> 
41
42 vtkStandardNewMacro(VISU_MeshAct);
43
44 VISU_MeshAct::VISU_MeshAct(){
45   
46   vtkMatrix4x4 *m;
47   m = vtkMatrix4x4::New();
48
49   mySurfaceActor = VISU_Actor::New();
50   mySurfaceActor->SetParent(this);
51   mySurfaceActor->GetProperty()->FrontfaceCullingOff();
52   mySurfaceActor->GetProperty()->BackfaceCullingOff();
53   mySurfaceActor->SetUserMatrix(m);
54   mySurfaceActor->SetRepresentation(2); //SURFACE
55  
56   myEdgeActor = VISU_Actor::New();
57   myEdgeActor->SetParent(this);
58   myEdgeActor->PickableOff();
59   myEdgeActor->GetProperty()->FrontfaceCullingOff();
60   myEdgeActor->GetProperty()->BackfaceCullingOff();
61   myEdgeActor->SetUserMatrix(m);
62   myEdgeActor->SetRepresentation(1); //WIREFRAME
63  
64   myNodeActor = VISU_Actor::New();
65   myNodeActor->SetParent(this);
66   myNodeActor->PickableOff();
67   myNodeActor->GetProperty()->SetPointSize(SALOME_POINT_SIZE);
68   myNodeActor->GetProperty()->FrontfaceCullingOff();
69   myNodeActor->GetProperty()->BackfaceCullingOff();
70   myNodeActor->SetUserMatrix(m);
71   myNodeActor->SetRepresentation(0); //POINT
72
73   m->Delete();
74   SetRepresentation(2); //SURFACE
75 }
76
77 VISU_MeshAct::~VISU_MeshAct(){
78   mySurfaceActor->Delete();
79   myEdgeActor->Delete();
80   myNodeActor->Delete();
81 }
82
83 void VISU_MeshAct::setIO(const Handle(SALOME_InteractiveObject)& theIO){
84   VISU_Actor::setIO(theIO);
85   mySurfaceActor->setIO(theIO);
86   myEdgeActor->setIO(theIO);
87   myNodeActor->setIO(theIO);
88 }
89
90 void VISU_MeshAct::SetPrs3d(VISU::Prs3d_i* thePrs3d){ 
91   if(thePrs3d){
92     VISU_Actor::SetPrs3d(thePrs3d);
93     mySurfaceActor->SetPrs3d(thePrs3d);
94     myEdgeActor->SetPrs3d(thePrs3d);
95     myNodeActor->SetPrs3d(thePrs3d);
96   }
97 }
98
99 void VISU_MeshAct::AddToRender(vtkRenderer* theRenderer){
100   theRenderer->AddActor(this);
101   theRenderer->AddActor(myEdgeActor);
102 }
103
104 void VISU_MeshAct::RemoveFromRender(vtkRenderer* theRenderer){
105   theRenderer->RemoveActor(this);
106   theRenderer->RemoveActor(myEdgeActor);
107 }
108
109 void VISU_MeshAct::SetPipeLine(VISU_PipeLine* thePipeLine) {
110   VISU_Actor::SetPipeLine(thePipeLine);
111   mySurfaceActor->SetPipeLine(thePipeLine);
112   myEdgeActor->SetPipeLine(thePipeLine);
113   myNodeActor->SetPipeLine(thePipeLine);
114 }
115
116 void VISU_MeshAct::SetTransform(VTKViewer_Transform* theTransform){
117   VISU_Actor::SetTransform(theTransform);
118   mySurfaceActor->SetTransform(theTransform);
119   myEdgeActor->SetTransform(theTransform);
120   myNodeActor->SetTransform(theTransform);
121 }
122
123 void VISU_MeshAct::SetShrinkable(bool theIsShrinkable){
124   VISU_Actor::SetShrinkable(theIsShrinkable);
125   mySurfaceActor->SetShrinkable(theIsShrinkable);
126   myEdgeActor->SetShrinkable(theIsShrinkable);
127   myNodeActor->SetShrinkable(theIsShrinkable);
128 }
129
130 void VISU_MeshAct::SetShrinkFactor(float theValue){
131   VISU_Actor::SetShrinkFactor(theValue);
132   mySurfaceActor->SetShrinkFactor(theValue);
133   myEdgeActor->SetShrinkFactor(theValue);
134 }
135
136 vtkProperty* VISU_MeshAct::GetSurfaceProperty(){ 
137   return mySurfaceActor->GetProperty();
138
139
140 void VISU_MeshAct::SetSurfaceProperty(vtkProperty* theProperty){ 
141   mySurfaceActor->SetProperty(theProperty);
142 }
143
144 vtkProperty* VISU_MeshAct::GetEdgeProperty(){ 
145   return myEdgeActor->GetProperty();
146
147
148 void VISU_MeshAct::SetEdgeProperty(vtkProperty* theProperty){ 
149   myEdgeActor->SetProperty(theProperty);
150 }
151
152 vtkProperty* VISU_MeshAct::GetNodeProperty(){ 
153   return myNodeActor->GetProperty();
154
155
156 void VISU_MeshAct::SetNodeProperty(vtkProperty* theProperty){ 
157   myNodeActor->SetProperty(theProperty);
158 }
159
160 void VISU_MeshAct::SetOpacity(float theValue){
161   GetSurfaceProperty()->SetOpacity(theValue);
162 }
163
164 float VISU_MeshAct::GetOpacity(){ 
165   return GetSurfaceProperty()->GetOpacity();
166 }
167
168 void VISU_MeshAct::SetLineWidth(float theLineWidth){
169   GetEdgeProperty()->SetLineWidth(theLineWidth);
170 }
171
172 float VISU_MeshAct::GetLineWidth(){
173   return GetEdgeProperty()->GetLineWidth();
174 }
175
176 void VISU_MeshAct::SetShrink(){
177   if(myRepresentation == VTK_POINTS)
178     return;
179   VISU_Actor::SetShrink();
180   mySurfaceActor->SetShrink();
181   myEdgeActor->SetShrink();
182   //SetRepresentation(GetRepresentation());
183 }
184
185 void VISU_MeshAct::UnShrink(){
186   VISU_Actor::UnShrink();
187   mySurfaceActor->UnShrink();
188   myEdgeActor->UnShrink();
189   //SetRepresentation(GetRepresentation());
190 }
191
192 void VISU_MeshAct::SetRepresentation(int theMode){
193   SALOME_Actor::SetRepresentation(theMode);
194   mySurfaceActor->VisibilityOff();
195   myEdgeActor->VisibilityOff();
196   myNodeActor->VisibilityOff();
197   myEdgeActor->PickableOff();
198   myNodeActor->PickableOff();
199   switch(theMode){
200   case VTK_POINTS:
201     myNodeActor->VisibilityOn();
202     myNodeActor->PickableOn();
203     break;
204   case VTK_WIREFRAME:
205     myEdgeActor->VisibilityOn();
206     myEdgeActor->SetRepresentation(1);
207     myEdgeActor->PickableOn();
208     break;
209   case VTK_SURFACE:
210     mySurfaceActor->VisibilityOn();
211     break;
212   case 3: //INSIDEFRAME
213     myEdgeActor->VisibilityOn();
214     myEdgeActor->SetRepresentation(3);
215     myEdgeActor->PickableOn();
216     break;
217   case 4: //SURFACEFRAME
218     myEdgeActor->VisibilityOn();
219     myEdgeActor->SetRepresentation(1);
220     mySurfaceActor->VisibilityOn();
221     break;
222   }
223   if(myRepresentation == VTK_POINTS)
224     UnShrink();
225 }
226
227 void VISU_MeshAct::SetVisibility(int theMode){
228   VISU_Actor::SetVisibility(theMode);
229   if(GetVisibility())
230     SetRepresentation(GetRepresentation());
231   else{
232     myNodeActor->VisibilityOff();
233     myEdgeActor->VisibilityOff();
234     mySurfaceActor->VisibilityOff();
235   }
236 }
237
238 // From vtkLODActor
239 void VISU_MeshAct::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m))
240 {
241   float myTime, bestTime, tempTime;
242   vtkMatrix4x4 *matrix;
243   vtkMapper *mapper, *bestMapper;
244   
245   if (this->Mapper == NULL)
246     {
247     vtkErrorMacro("No mapper for actor.");
248     return;
249     }
250   
251   // first time through create lods if non have been added
252   if (this->LODMappers->GetNumberOfItems() == 0)
253     {
254     this->CreateOwnLODs();
255     }
256   
257   // If the actor has changed or the primary mapper has changed ...
258   // Is this the correct test?
259   if (this->MediumMapper)
260     {
261     if (this->GetMTime() > this->BuildTime || 
262         this->Mapper->GetMTime() > this->BuildTime)
263       {
264       this->UpdateOwnLODs();
265       }
266     }
267   
268   // figure out how much time we have to render
269   myTime = this->AllocatedRenderTime;
270
271   // Figure out which resolution to use 
272   // none is a valid resolution. Do we want to have a lowest:
273   // bbox, single point, ...
274   // There is no order to the list, so it is assumed that mappers that take
275   // longer to render are better quality.
276   // Timings might become out of date, but we rely on 
277
278   bestMapper = this->Mapper;
279   bestTime = bestMapper->GetTimeToDraw();
280   if (bestTime > myTime)
281     {
282     this->LODMappers->InitTraversal();
283     while ((mapper = this->LODMappers->GetNextItem()) != NULL && 
284            bestTime != 0.0)
285       {
286       tempTime = mapper->GetTimeToDraw();
287       
288       // If the LOD has never been rendered, select it!
289       if (tempTime == 0.0)
290         { 
291         bestMapper = mapper;
292         bestTime = 0.0;
293         }
294       else
295         {
296         if (bestTime > myTime && tempTime < bestTime)
297           {
298           bestMapper = mapper;
299           bestTime = tempTime;
300           }
301         if (tempTime > bestTime && tempTime < myTime)
302           { 
303           bestMapper = mapper;
304           bestTime = tempTime;
305           }
306         }
307       }
308     }
309     
310   switch(GetRepresentation()){
311   case 0: //POINTS
312     myNodeActor->GetProperty()->Render(this, ren);
313     break;
314   case 1: //WIREFRAME
315     //PAL5268: myEdgeActor->GetProperty()->Render(this, ren);
316     break;
317   case 2: //SURFACE
318     mySurfaceActor->GetProperty()->Render(this, ren);
319     break;
320   case 3: //INSIDEFRAME
321     //PAL5268: myEdgeActor->GetProperty()->Render(this, ren);
322     break;
323   case 4: //SURFACEFRAME
324     //PAL5268: myEdgeActor->GetProperty()->Render(this, ren);
325     mySurfaceActor->GetProperty()->Render(this, ren);
326     break;
327   }
328    
329   // render the texture
330   if (this->Texture)
331     {
332     this->Texture->Render(ren);
333     }
334      
335   switch(GetRepresentation()){
336   case 0: //POINTS
337     matrix = myNodeActor->GetUserMatrix();
338     break;
339   case 1: //WIREFRAME
340     matrix = myEdgeActor->GetUserMatrix();
341     break;
342   case 2: //SURFACE
343     matrix = mySurfaceActor->GetUserMatrix();
344     break;
345   case 3: //INSIDEFRAME
346     matrix = myEdgeActor->GetUserMatrix();
347     break;
348   case 4: //SURFACEFRAME
349     matrix = myEdgeActor->GetUserMatrix();
350     this->GetMatrix(matrix);
351     matrix = mySurfaceActor->GetUserMatrix();
352     break;
353   }
354   this->GetMatrix(matrix);
355  
356   switch(GetRepresentation()){
357   case 0: //POINTS
358     myNodeActor->Render(ren,bestMapper);
359     break;
360   case 1: //WIREFRAME
361     //PAL5268: myEdgeActor->Render(ren,bestMapper);
362     break;
363   case 2: //SURFACE
364     mySurfaceActor->Render(ren,bestMapper);
365     break;
366   case 3: //INSIDEFRAME
367     //PAL5268: myEdgeActor->Render(ren,bestMapper);
368     break;
369   case 4: //SURFACEFRAME
370     //PAL5268: myEdgeActor->Render(ren,bestMapper);
371     mySurfaceActor->Render(ren,bestMapper);
372     break;
373   }
374   
375   this->EstimatedRenderTime = bestMapper->GetTimeToDraw();
376 }
377
378 // From vtkLODActor
379 void VISU_MeshAct::Modified()
380 {
381   myNodeActor->Modified();
382   //PAL5268: myEdgeActor->Modified();
383   mySurfaceActor->Modified();
384   this->vtkActor::Modified();
385 }