1 // VISU OBJECT : interactive object for VISU entities implementation
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 : VISU_MeshAct.cxx
25 // Author : Laurent CORNABE with the help of Nicolas REJNERI
29 #include "VISU_MeshAct.h"
30 #include "VTKViewer_PassThroughFilter.h"
32 #include <vtkObjectFactory.h>
33 #include <vtkRenderer.h>
34 #include <vtkTexture.h>
36 #include <vtkFeatureEdges.h>
37 #include <vtkDataSetMapper.h>
38 #include <vtkDataSet.h>
39 #include <vtkMatrix4x4.h>
40 #include <vtkMapperCollection.h>
42 vtkStandardNewMacro(VISU_MeshAct);
44 VISU_MeshAct::VISU_MeshAct(){
47 m = vtkMatrix4x4::New();
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
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
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
74 SetRepresentation(2); //SURFACE
77 VISU_MeshAct::~VISU_MeshAct(){
78 mySurfaceActor->Delete();
79 myEdgeActor->Delete();
80 myNodeActor->Delete();
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);
90 void VISU_MeshAct::SetPrs3d(VISU::Prs3d_i* thePrs3d){
92 VISU_Actor::SetPrs3d(thePrs3d);
93 mySurfaceActor->SetPrs3d(thePrs3d);
94 myEdgeActor->SetPrs3d(thePrs3d);
95 myNodeActor->SetPrs3d(thePrs3d);
99 void VISU_MeshAct::AddToRender(vtkRenderer* theRenderer){
100 VISU_Actor::AddToRender(theRenderer);
101 theRenderer->AddActor(myEdgeActor);
104 void VISU_MeshAct::RemoveFromRender(vtkRenderer* theRenderer){
105 VISU_Actor::RemoveFromRender(theRenderer);
106 theRenderer->RemoveActor(myEdgeActor);
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);
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);
123 void VISU_MeshAct::SetShrinkable(bool theIsShrinkable){
124 VISU_Actor::SetShrinkable(theIsShrinkable);
125 mySurfaceActor->SetShrinkable(theIsShrinkable);
126 myEdgeActor->SetShrinkable(theIsShrinkable);
127 myNodeActor->SetShrinkable(theIsShrinkable);
130 void VISU_MeshAct::SetShrinkFactor(float theValue){
131 VISU_Actor::SetShrinkFactor(theValue);
132 mySurfaceActor->SetShrinkFactor(theValue);
133 myEdgeActor->SetShrinkFactor(theValue);
136 vtkProperty* VISU_MeshAct::GetSurfaceProperty(){
137 return mySurfaceActor->GetProperty();
140 void VISU_MeshAct::SetSurfaceProperty(vtkProperty* theProperty){
141 mySurfaceActor->SetProperty(theProperty);
144 vtkProperty* VISU_MeshAct::GetEdgeProperty(){
145 return myEdgeActor->GetProperty();
148 void VISU_MeshAct::SetEdgeProperty(vtkProperty* theProperty){
149 myEdgeActor->SetProperty(theProperty);
152 vtkProperty* VISU_MeshAct::GetNodeProperty(){
153 return myNodeActor->GetProperty();
156 void VISU_MeshAct::SetNodeProperty(vtkProperty* theProperty){
157 myNodeActor->SetProperty(theProperty);
160 void VISU_MeshAct::SetOpacity(float theValue){
161 GetSurfaceProperty()->SetOpacity(theValue);
164 float VISU_MeshAct::GetOpacity(){
165 return GetSurfaceProperty()->GetOpacity();
168 void VISU_MeshAct::SetLineWidth(float theLineWidth){
169 GetEdgeProperty()->SetLineWidth(theLineWidth);
172 float VISU_MeshAct::GetLineWidth(){
173 return GetEdgeProperty()->GetLineWidth();
176 void VISU_MeshAct::SetShrink(){
177 if(myRepresentation == VTK_POINTS)
179 VISU_Actor::SetShrink();
180 mySurfaceActor->SetShrink();
181 myEdgeActor->SetShrink();
182 //SetRepresentation(GetRepresentation());
185 void VISU_MeshAct::UnShrink(){
186 VISU_Actor::UnShrink();
187 mySurfaceActor->UnShrink();
188 myEdgeActor->UnShrink();
189 //SetRepresentation(GetRepresentation());
192 void VISU_MeshAct::SetRepresentation(int theMode)
194 SALOME_Actor::SetRepresentation(theMode);
196 if (!GetVisibility()) return; // Fix IPAL9555
198 mySurfaceActor->VisibilityOff();
199 myEdgeActor->VisibilityOff();
200 myNodeActor->VisibilityOff();
201 myEdgeActor->PickableOff();
202 myNodeActor->PickableOff();
205 myNodeActor->VisibilityOn();
206 myNodeActor->PickableOn();
209 myEdgeActor->VisibilityOn();
210 myEdgeActor->SetRepresentation(1);
211 myEdgeActor->PickableOn();
214 mySurfaceActor->VisibilityOn();
216 case 3: //INSIDEFRAME
217 myEdgeActor->VisibilityOn();
218 myEdgeActor->SetRepresentation(3);
219 myEdgeActor->PickableOn();
221 case 4: //SURFACEFRAME
222 myEdgeActor->VisibilityOn();
223 myEdgeActor->SetRepresentation(1);
224 mySurfaceActor->VisibilityOn();
227 if (myRepresentation == VTK_POINTS)
231 void VISU_MeshAct::SetVisibility(int theMode){
232 VISU_Actor::SetVisibility(theMode);
234 SetRepresentation(GetRepresentation());
236 myNodeActor->VisibilityOff();
237 myEdgeActor->VisibilityOff();
238 mySurfaceActor->VisibilityOff();
243 void VISU_MeshAct::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m))
245 float myTime, bestTime, tempTime;
246 vtkMatrix4x4 *matrix;
247 vtkMapper *mapper, *bestMapper;
249 if (this->Mapper == NULL)
251 vtkErrorMacro("No mapper for actor.");
255 // first time through create lods if non have been added
256 if (this->LODMappers->GetNumberOfItems() == 0)
258 this->CreateOwnLODs();
261 // If the actor has changed or the primary mapper has changed ...
262 // Is this the correct test?
263 if (this->MediumMapper)
265 if (this->GetMTime() > this->BuildTime ||
266 this->Mapper->GetMTime() > this->BuildTime)
268 this->UpdateOwnLODs();
272 // figure out how much time we have to render
273 myTime = this->AllocatedRenderTime;
275 // Figure out which resolution to use
276 // none is a valid resolution. Do we want to have a lowest:
277 // bbox, single point, ...
278 // There is no order to the list, so it is assumed that mappers that take
279 // longer to render are better quality.
280 // Timings might become out of date, but we rely on
282 bestMapper = this->Mapper;
283 bestTime = bestMapper->GetTimeToDraw();
284 if (bestTime > myTime)
286 this->LODMappers->InitTraversal();
287 while ((mapper = this->LODMappers->GetNextItem()) != NULL &&
290 tempTime = mapper->GetTimeToDraw();
292 // If the LOD has never been rendered, select it!
300 if (bestTime > myTime && tempTime < bestTime)
305 if (tempTime > bestTime && tempTime < myTime)
314 switch(GetRepresentation()){
316 myNodeActor->GetProperty()->Render(this, ren);
319 //PAL5268: myEdgeActor->GetProperty()->Render(this, ren);
322 mySurfaceActor->GetProperty()->Render(this, ren);
324 case 3: //INSIDEFRAME
325 //PAL5268: myEdgeActor->GetProperty()->Render(this, ren);
327 case 4: //SURFACEFRAME
328 //PAL5268: myEdgeActor->GetProperty()->Render(this, ren);
329 mySurfaceActor->GetProperty()->Render(this, ren);
333 // render the texture
336 this->Texture->Render(ren);
339 switch(GetRepresentation()){
341 matrix = myNodeActor->GetUserMatrix();
344 matrix = myEdgeActor->GetUserMatrix();
347 matrix = mySurfaceActor->GetUserMatrix();
349 case 3: //INSIDEFRAME
350 matrix = myEdgeActor->GetUserMatrix();
352 case 4: //SURFACEFRAME
353 matrix = myEdgeActor->GetUserMatrix();
354 this->GetMatrix(matrix);
355 matrix = mySurfaceActor->GetUserMatrix();
358 this->GetMatrix(matrix);
360 switch(GetRepresentation()){
362 myNodeActor->Render(ren,bestMapper);
365 //PAL5268: myEdgeActor->Render(ren,bestMapper);
368 mySurfaceActor->Render(ren,bestMapper);
370 case 3: //INSIDEFRAME
371 //PAL5268: myEdgeActor->Render(ren,bestMapper);
373 case 4: //SURFACEFRAME
374 //PAL5268: myEdgeActor->Render(ren,bestMapper);
375 mySurfaceActor->Render(ren,bestMapper);
379 this->EstimatedRenderTime = bestMapper->GetTimeToDraw();
383 void VISU_MeshAct::Modified()
385 myNodeActor->Modified();
386 //PAL5268: myEdgeActor->Modified();
387 mySurfaceActor->Modified();
388 this->vtkActor::Modified();