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 "SALOME_PassThroughFilter.h"
32 #include <vtkFeatureEdges.h>
33 #include <vtkDataSetMapper.h>
34 #include <vtkDataSet.h>
35 #include <vtkMatrix4x4.h>
36 #include <vtkMapperCollection.h>
38 vtkStandardNewMacro(VISU_MeshAct);
40 VISU_MeshAct::VISU_MeshAct(){
43 m = vtkMatrix4x4::New();
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
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
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
70 SetRepresentation(2); //SURFACE
73 VISU_MeshAct::~VISU_MeshAct(){
74 mySurfaceActor->Delete();
75 myEdgeActor->Delete();
76 myNodeActor->Delete();
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);
86 void VISU_MeshAct::SetPrs3d(VISU::Prs3d_i* thePrs3d){
88 VISU_Actor::SetPrs3d(thePrs3d);
89 mySurfaceActor->SetPrs3d(thePrs3d);
90 myEdgeActor->SetPrs3d(thePrs3d);
91 myNodeActor->SetPrs3d(thePrs3d);
95 void VISU_MeshAct::AddToRender(vtkRenderer* theRenderer){
96 theRenderer->AddActor(this);
97 theRenderer->AddActor(myEdgeActor);
100 void VISU_MeshAct::RemoveFromRender(vtkRenderer* theRenderer){
101 theRenderer->RemoveActor(this);
102 theRenderer->RemoveActor(myEdgeActor);
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);
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);
119 void VISU_MeshAct::SetShrinkable(bool theIsShrinkable){
120 VISU_Actor::SetShrinkable(theIsShrinkable);
121 mySurfaceActor->SetShrinkable(theIsShrinkable);
122 myEdgeActor->SetShrinkable(theIsShrinkable);
123 myNodeActor->SetShrinkable(theIsShrinkable);
126 vtkProperty* VISU_MeshAct::GetSurfaceProperty(){
127 mySurfaceActor->GetProperty();
130 void VISU_MeshAct::SetSurfaceProperty(vtkProperty* theProperty){
131 mySurfaceActor->SetProperty(theProperty);
134 vtkProperty* VISU_MeshAct::GetEdgeProperty(){
135 myEdgeActor->GetProperty();
138 void VISU_MeshAct::SetEdgeProperty(vtkProperty* theProperty){
139 myEdgeActor->SetProperty(theProperty);
142 vtkProperty* VISU_MeshAct::GetNodeProperty(){
143 myNodeActor->GetProperty();
146 void VISU_MeshAct::SetNodeProperty(vtkProperty* theProperty){
147 myNodeActor->SetProperty(theProperty);
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);
157 void VISU_MeshAct::SetOpacity(float theValue){
158 GetSurfaceProperty()->SetOpacity(theValue);
161 float VISU_MeshAct::GetOpacity(){
162 return GetSurfaceProperty()->GetOpacity();
165 void VISU_MeshAct::SetLineWidth(float theLineWidth){
166 GetEdgeProperty()->SetLineWidth(theLineWidth);
169 float VISU_MeshAct::GetLineWidth(){
170 return GetEdgeProperty()->GetLineWidth();
173 void VISU_MeshAct::SetShrink(float theFactor){
174 VISU_Actor::SetShrink(theFactor);
175 mySurfaceActor->SetShrink(theFactor);
176 myEdgeActor->SetShrink(theFactor);
177 SetRepresentation(GetRepresentation());
180 void VISU_MeshAct::UnShrink(){
181 VISU_Actor::UnShrink();
182 mySurfaceActor->UnShrink();
183 myEdgeActor->UnShrink();
184 SetRepresentation(GetRepresentation());
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();
196 myNodeActor->VisibilityOn();
197 myNodeActor->PickableOn();
200 myEdgeActor->VisibilityOn();
201 myEdgeActor->SetRepresentation(1);
202 myEdgeActor->PickableOn();
205 mySurfaceActor->VisibilityOn();
207 case 3: //INSIDEFRAME
208 myEdgeActor->VisibilityOn();
209 myEdgeActor->SetRepresentation(3);
210 myEdgeActor->PickableOn();
212 case 4: //SURFACEFRAME
213 myEdgeActor->VisibilityOn();
214 myEdgeActor->SetRepresentation(1);
215 mySurfaceActor->VisibilityOn();
220 void VISU_MeshAct::SetVisibility(int theMode){
221 VISU_Actor::SetVisibility(theMode);
223 SetRepresentation(GetRepresentation());
225 myNodeActor->VisibilityOff();
226 myEdgeActor->VisibilityOff();
227 mySurfaceActor->VisibilityOff();
232 void VISU_MeshAct::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m))
234 float myTime, bestTime, tempTime;
235 vtkMatrix4x4 *matrix;
236 vtkMapper *mapper, *bestMapper;
238 if (this->Mapper == NULL)
240 vtkErrorMacro("No mapper for actor.");
244 // first time through create lods if non have been added
245 if (this->LODMappers->GetNumberOfItems() == 0)
247 this->CreateOwnLODs();
250 // If the actor has changed or the primary mapper has changed ...
251 // Is this the correct test?
252 if (this->MediumMapper)
254 if (this->GetMTime() > this->BuildTime ||
255 this->Mapper->GetMTime() > this->BuildTime)
257 this->UpdateOwnLODs();
261 // figure out how much time we have to render
262 myTime = this->AllocatedRenderTime;
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
271 bestMapper = this->Mapper;
272 bestTime = bestMapper->GetTimeToDraw();
273 if (bestTime > myTime)
275 this->LODMappers->InitTraversal();
276 while ((mapper = this->LODMappers->GetNextItem()) != NULL &&
279 tempTime = mapper->GetTimeToDraw();
281 // If the LOD has never been rendered, select it!
289 if (bestTime > myTime && tempTime < bestTime)
294 if (tempTime > bestTime && tempTime < myTime)
303 switch(GetRepresentation()){
305 myNodeActor->GetProperty()->Render(this, ren);
308 //PAL5268: myEdgeActor->GetProperty()->Render(this, ren);
311 mySurfaceActor->GetProperty()->Render(this, ren);
313 case 3: //INSIDEFRAME
314 //PAL5268: myEdgeActor->GetProperty()->Render(this, ren);
316 case 4: //SURFACEFRAME
317 //PAL5268: myEdgeActor->GetProperty()->Render(this, ren);
318 mySurfaceActor->GetProperty()->Render(this, ren);
322 // render the texture
325 this->Texture->Render(ren);
328 switch(GetRepresentation()){
330 matrix = myNodeActor->GetUserMatrix();
333 matrix = myEdgeActor->GetUserMatrix();
336 matrix = mySurfaceActor->GetUserMatrix();
338 case 3: //INSIDEFRAME
339 matrix = myEdgeActor->GetUserMatrix();
341 case 4: //SURFACEFRAME
342 matrix = myEdgeActor->GetUserMatrix();
343 this->GetMatrix(matrix);
344 matrix = mySurfaceActor->GetUserMatrix();
347 this->GetMatrix(matrix);
349 switch(GetRepresentation()){
351 myNodeActor->Render(ren,bestMapper);
354 //PAL5268: myEdgeActor->Render(ren,bestMapper);
357 mySurfaceActor->Render(ren,bestMapper);
359 case 3: //INSIDEFRAME
360 //PAL5268: myEdgeActor->Render(ren,bestMapper);
362 case 4: //SURFACEFRAME
363 //PAL5268: myEdgeActor->Render(ren,bestMapper);
364 mySurfaceActor->Render(ren,bestMapper);
368 this->EstimatedRenderTime = bestMapper->GetTimeToDraw();
372 void VISU_MeshAct::Modified()
374 myNodeActor->Modified();
375 //PAL5268: myEdgeActor->Modified();
376 mySurfaceActor->Modified();
377 this->vtkActor::Modified();