2 // File : SMESH_Actor.cxx
3 // Created : Mon May 13 22:31:18 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
12 \class SMESH_Actor SMESH_Actor.h
16 #include "SMESH_Actor.h"
17 #include "SMESH_Grid.h"
18 #include "utilities.h"
21 #include <vtkObjectFactory.h>
22 #include <vtkMergePoints.h>
23 #include <vtkDataSetMapper.h>
24 #include <vtkFeatureEdges.h>
25 #include <vtkGeometryFilter.h>
27 //-------------------------------------------------------------
29 //-------------------------------------------------------------
31 SMESH_Actor* SMESH_Actor::New()
33 // First try to create the object from the vtkObjectFactory
34 vtkObject* ret = vtkObjectFactory::CreateInstance("SMESH_Actor");
37 return (SMESH_Actor*)ret;
39 // If the factory was unable to create the object, then create it here.
40 return new SMESH_Actor;
44 SMESH_Actor::SMESH_Actor()
46 this->Device = vtkActor::New();
48 this->EdgeDevice = vtkActor::New();
49 EdgeDevice->VisibilityOff();
50 EdgeDevice->PickableOff();
52 this->EdgeShrinkDevice = vtkActor::New();
53 EdgeShrinkDevice->VisibilityOff();
54 EdgeShrinkDevice->PickableOff();
60 ishighlighted = false;
61 ispreselected = false;
67 edgeHighlightColor.r = 1.;
68 edgeHighlightColor.g = 1.;
69 edgeHighlightColor.b = 1.;
71 edgePreselectedColor.r = 0.;
72 edgePreselectedColor.g = 1.;
73 edgePreselectedColor.b = 1.;
79 actorHighlightColor.r = 1.;
80 actorHighlightColor.g = 1.;
81 actorHighlightColor.b = 1.;
83 actorPreselectedColor.r = 0.;
84 actorPreselectedColor.g = 1.;
85 actorPreselectedColor.b = 1.;
87 actorNodeColor.r = 1.;
88 actorNodeColor.g = 1.;
89 actorNodeColor.b = 0.;
95 SMESH_Actor::~SMESH_Actor()
97 this->EdgeDevice->Delete();
98 this->EdgeShrinkDevice->Delete();
101 void SMESH_Actor::setReader(vtkUnstructuredGridReader* r) {
105 vtkUnstructuredGridReader* SMESH_Actor::getReader() {
109 vtkMapper* SMESH_Actor::getMapper() {
110 return (this->Mapper);
113 void SMESH_Actor::ShallowCopy(vtkProp *prop)
115 SMESH_Actor *f = SMESH_Actor::SafeDownCast(prop);
118 this->setName( f->getName() );
120 this->setIO( f->getIO() );
121 this->setDisplayMode( f->getDisplayMode() );
124 vtkActor* tempDev = vtkActor::New();
125 tempDev->ShallowCopy(f->Device);
126 vtkProperty* prp = vtkProperty::New();
127 prp->DeepCopy(f->Device->GetProperty());
128 tempDev->SetProperty(prp);
129 prp = vtkProperty::New();
130 prp->DeepCopy(f->Device->GetBackfaceProperty());
131 tempDev->SetBackfaceProperty(prp);
132 this->Device = tempDev;
134 tempDev = vtkActor::New();
135 tempDev->ShallowCopy(f->EdgeDevice);
136 prp = vtkProperty::New();
137 prp->DeepCopy(f->EdgeDevice->GetProperty());
138 tempDev->SetProperty(prp);
139 prp = vtkProperty::New();
140 prp->DeepCopy(f->EdgeDevice->GetBackfaceProperty());
141 tempDev->SetBackfaceProperty(prp);
142 this->EdgeDevice = tempDev;
144 tempDev = vtkActor::New();
145 tempDev->ShallowCopy(f->EdgeShrinkDevice);
146 prp = vtkProperty::New();
147 prp->DeepCopy(f->EdgeShrinkDevice->GetProperty());
148 tempDev->SetProperty(prp);
149 prp = vtkProperty::New();
150 prp->DeepCopy(f->EdgeShrinkDevice->GetBackfaceProperty());
151 tempDev->SetBackfaceProperty(prp);
152 this->EdgeShrinkDevice = tempDev;
155 this->DataSource = f->DataSource;
157 this->myReader = f->myReader;
161 this->SALOME_Actor::ShallowCopy(prop);
163 // Here we need to modify default ShallowCopy() results
164 // Create copies of properties
166 vtkProperty* prp = vtkProperty::New();
167 prp->DeepCopy(f->GetProperty());
168 this->SetProperty(prp);
170 prp = vtkProperty::New();
171 prp->DeepCopy(f->GetBackfaceProperty());
172 this->SetBackfaceProperty(prp);
175 vtkDataSetMapper* mpr = vtkDataSetMapper::New();
176 mpr->ShallowCopy(f->GetMapper());
177 mpr->SetInput(f->DataSource);
178 this->SetMapper(mpr);
182 void SMESH_Actor::Render(vtkRenderer *ren, vtkMapper *Mapper )
184 if (this->Mapper == NULL) {
185 MESSAGE ("No mapper for actor.")
189 if ( myDisplayMode == 1 ) {
190 EdgeDevice->VisibilityOn();
191 EdgeShrinkDevice->VisibilityOff();
192 } else if ( myDisplayMode == 2 ) {
193 EdgeShrinkDevice->VisibilityOn();
194 EdgeDevice->VisibilityOff();
196 EdgeShrinkDevice->VisibilityOff();
197 EdgeDevice->VisibilityOff();
201 vtkMapper *bestMapper;
202 bestMapper = this->Mapper;
204 /* render the property */
205 if (!this->Property) {
206 // force creation of a property
210 if ( ishighlighted ) {
211 if ( myDisplayMode == 1 ) {
212 EdgeDevice->GetProperty()->SetColor(edgeHighlightColor.r,edgeHighlightColor.g,edgeHighlightColor.b);
213 this->GetProperty()->SetColor(actorColor.r,actorColor.g,actorColor.b);
214 } else if ( myDisplayMode == 2 ) {
215 EdgeShrinkDevice->GetProperty()->SetColor(edgeHighlightColor.r,edgeHighlightColor.g,edgeHighlightColor.b);
217 this->GetProperty()->SetColor(actorHighlightColor.r,actorHighlightColor.g,actorHighlightColor.b);
219 } else if (! ispreselected ) {
220 if ( myDisplayMode == 1 ) {
221 EdgeDevice->GetProperty()->SetColor(edgeColor.r,edgeColor.g,edgeColor.b);
222 this->GetProperty()->SetColor(actorColor.r,actorColor.g,actorColor.b);
224 else if ( myDisplayMode == 2 )
225 EdgeShrinkDevice->GetProperty()->SetColor(edgeColor.r,edgeColor.g,edgeColor.b);
227 this->GetProperty()->SetColor(actorColor.r,actorColor.g,actorColor.b);
230 if ( myDisplayMode == 1 )
231 EdgeDevice->GetProperty()->SetColor(edgePreselectedColor.r,edgePreselectedColor.g,edgePreselectedColor.b);
232 else if ( myDisplayMode == 2 )
233 EdgeShrinkDevice->GetProperty()->SetColor(edgePreselectedColor.r,edgePreselectedColor.g,edgePreselectedColor.b);
235 this->GetProperty()->SetColor(actorPreselectedColor.r,actorPreselectedColor.g,actorPreselectedColor.b);
238 this->Property->Render(this, ren);
239 if (this->BackfaceProperty) {
240 this->BackfaceProperty->BackfaceRender(this, ren);
241 this->Device->SetBackfaceProperty(this->BackfaceProperty);
243 this->Device->SetProperty(this->Property);
245 /* render the texture */
247 this->Texture->Render(ren);
251 // Store information on time it takes to render.
252 // We might want to estimate time from the number of polygons in mapper.
253 this->Device->Render(ren,bestMapper);
254 this->EstimatedRenderTime = bestMapper->GetTimeToDraw();
257 int SMESH_Actor::RenderOpaqueGeometry(vtkViewport *vp)
259 int renderedSomething = 0;
260 vtkRenderer *ren = (vtkRenderer *)vp;
262 if ( ! this->Mapper ) {
266 // make sure we have a property
267 if (!this->Property) {
268 // force creation of a property
272 if ( ishighlighted ) {
273 if ( myDisplayMode == 1 ) {
274 EdgeDevice->GetProperty()->SetColor(edgeHighlightColor.r,edgeHighlightColor.g,edgeHighlightColor.b);
275 } else if ( myDisplayMode == 2 ) {
276 EdgeShrinkDevice->GetProperty()->SetColor(edgeHighlightColor.r,edgeHighlightColor.g,edgeHighlightColor.b);
278 this->GetProperty()->SetColor(actorHighlightColor.r,actorHighlightColor.g,actorHighlightColor.b);
280 } else if (! ispreselected ) {
281 if ( myDisplayMode == 1 )
282 EdgeDevice->GetProperty()->SetColor(edgeColor.r,edgeColor.g,edgeColor.b);
283 else if ( myDisplayMode == 2 )
284 EdgeShrinkDevice->GetProperty()->SetColor(edgeColor.r,edgeColor.g,edgeColor.b);
286 this->GetProperty()->SetColor(actorColor.r,actorColor.g,actorColor.b);
289 if ( myDisplayMode == 1 )
290 EdgeDevice->GetProperty()->SetColor(edgePreselectedColor.r,edgePreselectedColor.g,edgePreselectedColor.b);
291 else if ( myDisplayMode == 2 )
292 EdgeShrinkDevice->GetProperty()->SetColor(edgePreselectedColor.r,edgePreselectedColor.g,edgePreselectedColor.b);
294 this->GetProperty()->SetColor(actorPreselectedColor.r,actorPreselectedColor.g,actorPreselectedColor.b);
297 // is this actor opaque ?
298 if (this->GetIsOpaque()) {
299 this->Property->Render(this, ren);
301 // render the backface property
302 if (this->BackfaceProperty) {
303 this->BackfaceProperty->BackfaceRender(this, ren);
306 // render the texture
308 this->Texture->Render(ren);
310 this->Render(ren,this->Mapper);
312 renderedSomething = 1;
315 return renderedSomething;
319 void SMESH_Actor::SetColor(float r,float g,float b)
326 void SMESH_Actor::GetColor(float& r,float& g,float& b)
333 void SMESH_Actor::SetPreselectedColor(float r,float g,float b)
335 actorPreselectedColor.r = r;
336 actorPreselectedColor.g = g;
337 actorPreselectedColor.b = b;
340 void SMESH_Actor::GetPreselectedColor(float& r,float& g,float& b)
342 r = actorPreselectedColor.r;
343 g = actorPreselectedColor.g;
344 b = actorPreselectedColor.b;
347 void SMESH_Actor::SetHighlightColor(float r,float g,float b)
349 actorHighlightColor.r = r;
350 actorHighlightColor.g = g;
351 actorHighlightColor.b = b;
354 void SMESH_Actor::GetHighlightColor(float& r,float& g,float& b)
356 r = actorHighlightColor.r;
357 g = actorHighlightColor.g;
358 b = actorHighlightColor.b;
361 void SMESH_Actor::SetEdgeColor(float r,float g,float b)
368 void SMESH_Actor::GetEdgeColor(float& r,float& g,float& b)
375 void SMESH_Actor::SetEdgeHighlightColor(float r,float g,float b)
377 edgeHighlightColor.r = r;
378 edgeHighlightColor.g = g;
379 edgeHighlightColor.b = b;
382 void SMESH_Actor::GetEdgeHighlightColor(float& r,float& g,float& b)
384 r = edgeHighlightColor.r;
385 g = edgeHighlightColor.g;
386 b = edgeHighlightColor.b;
389 void SMESH_Actor::SetEdgePreselectedColor(float r,float g,float b)
391 edgePreselectedColor.r = r;
392 edgePreselectedColor.g = g;
393 edgePreselectedColor.b = b;
396 void SMESH_Actor::GetEdgePreselectedColor(float& r,float& g,float& b)
398 r = edgePreselectedColor.r;
399 g = edgePreselectedColor.g;
400 b = edgePreselectedColor.b;
404 void SMESH_Actor::SetNodeColor(float r,float g,float b)
406 actorNodeColor.r = r ;
407 actorNodeColor.g = g ;
408 actorNodeColor.b = b ;
411 void SMESH_Actor::GetNodeColor(float& r,float& g,float& b)
413 r = actorNodeColor.r ;
414 g = actorNodeColor.g ;
415 b = actorNodeColor.b ;
418 void SMESH_Actor::SetNodeSize(int size)
420 actorNodeSize = size ;
423 int SMESH_Actor::GetNodeSize()
425 return actorNodeSize ;
429 void SMESH_Actor::AddNode(int idSMESHDSnode,int idVTKnode)
431 if (DataSource->IsA("SMESH_Grid")) {
432 ((SMESH_Grid*)DataSource)->AddNode(idSMESHDSnode, idVTKnode);
434 MESSAGE("AddNode() method has been moved to SMESH_Grid class");
436 void SMESH_Actor::AddElement(int idSMESHDSelement, int idVTKelement)
438 if (DataSource->IsA("SMESH_Grid")) {
439 ((SMESH_Grid*)DataSource)->AddElement(idSMESHDSelement, idVTKelement);
441 MESSAGE("AddElement() method has been moved to SMESH_Grid class");
444 void SMESH_Actor::SetIdsVTKNode(const TColStd_DataMapOfIntegerInteger& mapVTK)
446 if (DataSource->IsA("SMESH_Grid")) {
447 ((SMESH_Grid*)DataSource)->SetIdsVTKNode(mapVTK);
449 MESSAGE("SetIdsVTKNode() method has been moved to SMESH_Grid class");
451 void SMESH_Actor::SetIdsSMESHDSNode(const TColStd_DataMapOfIntegerInteger& mapSMESHDS)
453 if (DataSource->IsA("SMESH_Grid")) {
454 ((SMESH_Grid*)DataSource)->SetIdsSMESHDSNode(mapSMESHDS);
456 MESSAGE("SetIdsSMESHDSNode() method has been moved to SMESH_Grid class");
459 void SMESH_Actor::SetIdsVTKElement(const TColStd_DataMapOfIntegerInteger& mapVTK)
461 if (DataSource->IsA("SMESH_Grid")) {
462 ((SMESH_Grid*)DataSource)->SetIdsVTKElement(mapVTK);
464 MESSAGE("SetIdsVTKElement() method has been moved to SMESH_Grid class");
466 void SMESH_Actor::SetIdsSMESHDSElement(const TColStd_DataMapOfIntegerInteger& mapSMESHDS)
468 if (DataSource->IsA("SMESH_Grid")) {
469 ((SMESH_Grid*)DataSource)->SetIdsSMESHDSElement(mapSMESHDS);
471 MESSAGE("SetIdsSMESHDSElement() method has been moved to SMESH_Grid class");
474 int SMESH_Actor::GetIdVTKNode(int idSMESHDSnode)
476 if (DataSource->IsA("SMESH_Grid")) {
477 return ((SMESH_Grid*)DataSource)->GetIdVTKNode(idSMESHDSnode);
479 MESSAGE("GetIdVTKNode() method has been moved to SMESH_Grid class");
483 int SMESH_Actor::GetIdVTKElement(int idSMESHDSelement)
485 if (DataSource->IsA("SMESH_Grid")) {
486 return ((SMESH_Grid*)DataSource)->GetIdVTKElement(idSMESHDSelement);
488 MESSAGE("GetIdVTKElement() method has been moved to SMESH_Grid class");
494 int SMESH_Actor::GetIdSMESHDSNode(int idVTKnode)
496 if (DataSource->IsA("SMESH_Grid")) {
497 return ((SMESH_Grid*)DataSource)->GetIdSMESHDSNode(idVTKnode);
499 MESSAGE("GetIdSMESHDSNode() method has been moved to SMESH_Grid class");
504 int SMESH_Actor::GetIdSMESHDSElement(int idVTKelement)
506 if (DataSource->IsA("SMESH_Grid")) {
507 return ((SMESH_Grid*)DataSource)->GetIdSMESHDSElement(idVTKelement);
509 MESSAGE("AddNode() method has been moved to SMESH_Grid class");
514 void SMESH_Actor::ClearNode()
516 if (DataSource->IsA("SMESH_Grid")) {
517 ((SMESH_Grid*)DataSource)->ClearNode();
519 MESSAGE("ClearNode() method has been moved to SMESH_Grid class");
522 void SMESH_Actor::ClearElement()
524 if (DataSource->IsA("SMESH_Grid")) {
525 ((SMESH_Grid*)DataSource)->ClearElement();
527 MESSAGE("ClearElement() method has been moved to SMESH_Grid class");
530 void SMESH_Actor::RemoveNode(int id)
532 if (DataSource->IsA("SMESH_Grid")) {
533 ((SMESH_Grid*)DataSource)->RemoveNode(id);
535 MESSAGE("RemoveNode() method has been moved to SMESH_Grid class");
537 void SMESH_Actor::RemoveElement(int id)
539 if (DataSource->IsA("SMESH_Grid")) {
540 ((SMESH_Grid*)DataSource)->RemoveElement(id);
542 MESSAGE("RemoveElement() method has been moved to SMESH_Grid class");
545 void SMESH_Actor::setDisplayMode(int thenewmode) {
546 myDisplayMode = thenewmode;
547 if ( myDisplayMode == 1 ) {
548 EdgeDevice->VisibilityOn();
549 EdgeShrinkDevice->VisibilityOff();
550 } else if ( myDisplayMode == 2 ) {
551 EdgeDevice->VisibilityOff();
552 EdgeShrinkDevice->VisibilityOn();
554 EdgeDevice->VisibilityOff();
555 EdgeShrinkDevice->VisibilityOff();
559 float SMESH_Actor::GetShrinkFactor()
561 return myShrinkFactor;
564 void SMESH_Actor::SetShrinkFactor(float value )
569 myShrinkFactor = value;
572 void SMESH_Actor::GetChildActors(vtkActorCollection* actors)
574 actors->AddItem(EdgeDevice);
575 actors->AddItem(EdgeShrinkDevice);
578 void SMESH_Actor::SetVisibility(bool visibility)
581 this->VisibilityOn();
582 if ( myDisplayMode == 1 ) {
583 EdgeDevice->VisibilityOn();
584 EdgeShrinkDevice->VisibilityOff();
585 } else if ( myDisplayMode == 2 ) {
586 EdgeDevice->VisibilityOff();
587 EdgeShrinkDevice->VisibilityOn();
589 EdgeDevice->VisibilityOff();
590 EdgeShrinkDevice->VisibilityOff();
593 this->VisibilityOff();
594 EdgeDevice->VisibilityOff();
595 EdgeShrinkDevice->VisibilityOff();