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