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 theRenderer->AddActor(this);
101 theRenderer->AddActor(myEdgeActor);
104 void VISU_MeshAct::RemoveFromRender(vtkRenderer* theRenderer){
105 theRenderer->RemoveActor(this);
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){
193 SALOME_Actor::SetRepresentation(theMode);
194 mySurfaceActor->VisibilityOff();
195 myEdgeActor->VisibilityOff();
196 myNodeActor->VisibilityOff();
197 myEdgeActor->PickableOff();
198 myNodeActor->PickableOff();
201 myNodeActor->VisibilityOn();
202 myNodeActor->PickableOn();
205 myEdgeActor->VisibilityOn();
206 myEdgeActor->SetRepresentation(1);
207 myEdgeActor->PickableOn();
210 mySurfaceActor->VisibilityOn();
212 case 3: //INSIDEFRAME
213 myEdgeActor->VisibilityOn();
214 myEdgeActor->SetRepresentation(3);
215 myEdgeActor->PickableOn();
217 case 4: //SURFACEFRAME
218 myEdgeActor->VisibilityOn();
219 myEdgeActor->SetRepresentation(1);
220 mySurfaceActor->VisibilityOn();
223 if(myRepresentation == VTK_POINTS)
227 void VISU_MeshAct::SetVisibility(int theMode){
228 VISU_Actor::SetVisibility(theMode);
230 SetRepresentation(GetRepresentation());
232 myNodeActor->VisibilityOff();
233 myEdgeActor->VisibilityOff();
234 mySurfaceActor->VisibilityOff();
239 void VISU_MeshAct::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m))
241 float myTime, bestTime, tempTime;
242 vtkMatrix4x4 *matrix;
243 vtkMapper *mapper, *bestMapper;
245 if (this->Mapper == NULL)
247 vtkErrorMacro("No mapper for actor.");
251 // first time through create lods if non have been added
252 if (this->LODMappers->GetNumberOfItems() == 0)
254 this->CreateOwnLODs();
257 // If the actor has changed or the primary mapper has changed ...
258 // Is this the correct test?
259 if (this->MediumMapper)
261 if (this->GetMTime() > this->BuildTime ||
262 this->Mapper->GetMTime() > this->BuildTime)
264 this->UpdateOwnLODs();
268 // figure out how much time we have to render
269 myTime = this->AllocatedRenderTime;
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
278 bestMapper = this->Mapper;
279 bestTime = bestMapper->GetTimeToDraw();
280 if (bestTime > myTime)
282 this->LODMappers->InitTraversal();
283 while ((mapper = this->LODMappers->GetNextItem()) != NULL &&
286 tempTime = mapper->GetTimeToDraw();
288 // If the LOD has never been rendered, select it!
296 if (bestTime > myTime && tempTime < bestTime)
301 if (tempTime > bestTime && tempTime < myTime)
310 switch(GetRepresentation()){
312 myNodeActor->GetProperty()->Render(this, ren);
315 //PAL5268: myEdgeActor->GetProperty()->Render(this, ren);
318 mySurfaceActor->GetProperty()->Render(this, ren);
320 case 3: //INSIDEFRAME
321 //PAL5268: myEdgeActor->GetProperty()->Render(this, ren);
323 case 4: //SURFACEFRAME
324 //PAL5268: myEdgeActor->GetProperty()->Render(this, ren);
325 mySurfaceActor->GetProperty()->Render(this, ren);
329 // render the texture
332 this->Texture->Render(ren);
335 switch(GetRepresentation()){
337 matrix = myNodeActor->GetUserMatrix();
340 matrix = myEdgeActor->GetUserMatrix();
343 matrix = mySurfaceActor->GetUserMatrix();
345 case 3: //INSIDEFRAME
346 matrix = myEdgeActor->GetUserMatrix();
348 case 4: //SURFACEFRAME
349 matrix = myEdgeActor->GetUserMatrix();
350 this->GetMatrix(matrix);
351 matrix = mySurfaceActor->GetUserMatrix();
354 this->GetMatrix(matrix);
356 switch(GetRepresentation()){
358 myNodeActor->Render(ren,bestMapper);
361 //PAL5268: myEdgeActor->Render(ren,bestMapper);
364 mySurfaceActor->Render(ren,bestMapper);
366 case 3: //INSIDEFRAME
367 //PAL5268: myEdgeActor->Render(ren,bestMapper);
369 case 4: //SURFACEFRAME
370 //PAL5268: myEdgeActor->Render(ren,bestMapper);
371 mySurfaceActor->Render(ren,bestMapper);
375 this->EstimatedRenderTime = bestMapper->GetTimeToDraw();
379 void VISU_MeshAct::Modified()
381 myNodeActor->Modified();
382 //PAL5268: myEdgeActor->Modified();
383 mySurfaceActor->Modified();
384 this->vtkActor::Modified();