]> SALOME platform Git repositories - modules/visu.git/blob - src/OBJECT/VISU_Actor.cxx
Salome HOME
814ef8141d36e0435e8e1bc359326ac307b366d8
[modules/visu.git] / src / OBJECT / VISU_Actor.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_Actor.cxx
25 //  Author : Laurent CORNABE with help of Nicolas REJNERI
26 //  Module : VISU
27 //  $Header$
28
29 using namespace std;
30 #include "VISU_Actor.h"
31 #include "VISU_LookupTable.hxx"
32 #include "VISU_ScalarBarActor.hxx"
33  
34 // VTK Includes
35 #include <vtkActor.h>
36 #include <vtkProperty.h>
37 #include <vtkShrinkPolyData.h>
38 #include <vtkFeatureEdges.h>
39 #include <vtkObjectFactory.h>
40
41 static int VISU_POINT_SIZE = 3;
42
43 //=======================================================================
44
45 VISU_Actor* VISU_Actor::New(){
46   vtkObject* ret = vtkObjectFactory::CreateInstance("VISU_Actor");
47   if(ret) return (VISU_Actor*)ret;
48   return new VISU_Actor;
49
50
51 VISU_Actor::VISU_Actor(){
52   myIsShrunk = false;
53   myIsShrinkable = false;
54   myParent = this;
55   myPrs3d = NULL;
56
57   myIO = NULL;
58   myName = "";
59
60   ishighlighted = false;
61   IsHighlighting = true;
62   HighlightProperty = vtkProperty::New();
63   HighlightProperty->SetAmbient(0.5);
64   HighlightProperty->SetDiffuse(0.3);
65   HighlightProperty->SetSpecular(0.2);
66   HighlightProperty->SetRepresentationToSurface();
67   HighlightProperty->SetAmbientColor(1, 1, 1);
68   HighlightProperty->SetDiffuseColor(1, 1, 1);
69   HighlightProperty->SetSpecularColor(0.5, 0.5, 0.5);
70 }
71
72 VISU_Actor::~VISU_Actor(){
73   HighlightProperty->Delete();
74 }
75
76 void VISU_Actor::setIO(const Handle(SALOME_InteractiveObject)& theIO){
77   SALOME_Actor::setIO(theIO); 
78   myName = theIO->getName(); 
79 }
80
81 void VISU_Actor::setPrs3d(VISU::Prs3d_i* thePrs3d){ 
82   myPrs3d = thePrs3d;
83 }
84
85 void VISU_Actor::SetParent(VISU_Actor* theParent){ 
86   myParent = theParent;
87 }
88
89 void VISU_Actor::SetMapper(vtkMapper* theMapper){
90   SALOME_Actor::SetMapper(theMapper);
91 }
92
93 void VISU_Actor::SetShrinkable(bool theIsShrinkable){
94   myIsShrinkable = theIsShrinkable;
95 }
96
97 void VISU_Actor::setShrink(float theFactor){
98   if(!myIsShrinkable || myIsShrunk) return;
99   vtkShrinkPolyData *aShrinkFilter = vtkShrinkPolyData::New();
100   aShrinkFilter->SetShrinkFactor(theFactor);
101   // use for post-filtering
102   aShrinkFilter->SetInput(myPassFilter[2]->GetPolyDataOutput());
103   myPassFilter[3]->SetInput(aShrinkFilter->GetOutput());
104   myPassFilter[3]->Modified();
105   aShrinkFilter->Delete();
106   myIsShrunk = true;
107 }
108
109 void VISU_Actor::unShrink(){
110   if(!myIsShrunk) return;
111   myPassFilter[3]->SetInput(myPassFilter[2]->GetPolyDataOutput());
112   myPassFilter[3]->Modified();
113   myIsShrunk = false;
114 }
115
116 void VISU_Actor::SetVisibility(int theMode){
117   SALOME_Actor::SetVisibility(theMode);
118 }
119
120 int VISU_Actor::GetVisibility(){
121   return SALOME_Actor::GetVisibility();
122 }
123
124 void VISU_Actor::SetProperty(vtkProperty* theProperty){
125   SALOME_Actor::SetProperty(theProperty);
126 }
127
128 vtkProperty* VISU_Actor::GetProperty(){
129   return SALOME_Actor::GetProperty();
130 }
131
132 void VISU_Actor::SetLineWidth(float theLineWidth){
133   GetProperty()->SetLineWidth(theLineWidth);
134 }
135
136 float VISU_Actor::GetLineWidth(){
137   return GetProperty()->GetLineWidth();
138 }
139
140 void VISU_Actor::SetRepresentation(int theMode) { 
141   GetProperty()->SetRepresentation(theMode);
142   if(theMode == 0) 
143     GetProperty()->SetPointSize(VISU_POINT_SIZE);
144 }
145
146 int VISU_Actor::GetRepresentation(){ 
147   return GetProperty()->GetRepresentation();
148 }
149
150 void VISU_Actor::ShallowCopy(vtkProp *prop){
151   VISU_Actor *anActor = VISU_Actor::SafeDownCast(prop);
152   if(anActor != NULL){
153     setName(anActor->getName());
154     if(anActor->hasIO()) setIO(anActor->getIO());
155   }
156   SALOME_Actor::ShallowCopy(prop);
157 }
158
159 void VISU_Actor::highlight(Standard_Boolean highlight) {
160   if (this->IsHighlighting) {
161     if(highlight && !ishighlighted) {
162       ishighlighted=true;
163       this->SetProperty(HighlightProperty);
164     }else if (!highlight)
165       if(ishighlighted) ishighlighted=false;
166   }
167 }
168
169 //=======================================================================
170
171 VISUScalarMap_Actor* VISUScalarMap_Actor::New(){
172   vtkObject* ret = vtkObjectFactory::CreateInstance("VISUScalarMap_Actor");
173   if(ret) return (VISUScalarMap_Actor*)ret;
174   return new VISUScalarMap_Actor;
175
176
177 VISUScalarMap_Actor::VISUScalarMap_Actor(){
178   myScalarBar = VISU_ScalarBarActor::New();
179   GetProperty()->FrontfaceCullingOff();
180   GetProperty()->BackfaceCullingOff();
181 }
182
183 VISUScalarMap_Actor::~VISUScalarMap_Actor(){
184   myScalarBar->Delete();
185 }
186
187 void VISUScalarMap_Actor::AddToRender(vtkRenderer* theRenderer){
188   SALOME_Actor::AddToRender(theRenderer);
189   if(myScalarBar)
190     theRenderer->AddActor2D(myScalarBar);
191 }
192
193 void VISUScalarMap_Actor::RemoveFromRender(vtkRenderer* theRenderer){
194   SALOME_Actor::RemoveFromRender(theRenderer);
195   if(myScalarBar)
196     theRenderer->RemoveActor(myScalarBar);
197 }
198
199 void VISUScalarMap_Actor::SetVisibility(int theMode){
200   SALOME_Actor::SetVisibility(theMode);
201   if(myScalarBar) myScalarBar->SetVisibility(*myBarVisibility && theMode);
202 }
203
204 int VISUScalarMap_Actor::GetVisibility(){
205   return SALOME_Actor::GetVisibility();
206 }
207
208 void VISUScalarMap_Actor::SetBarVisibility(const bool* theMode){
209   myBarVisibility = theMode;
210   if(myScalarBar) myScalarBar->SetVisibility(*myBarVisibility);
211 }
212
213 //=======================================================================
214
215 VISUMesh_Actor* VISUMesh_Actor::New(){
216   vtkObject* ret = vtkObjectFactory::CreateInstance("VISUMesh_Actor");
217   if(ret) return (VISUMesh_Actor*)ret;
218   return new VISUMesh_Actor;
219
220
221 VISUMesh_Actor::VISUMesh_Actor(){
222   myEdgeMapper = vtkPolyDataMapper::New();
223   mySurfaceActor = VISU_Actor::New();
224   mySurfaceActor->SetParent(this);
225   mySurfaceActor->GetProperty()->SetPointSize(VISU_POINT_SIZE);
226   mySurfaceActor->GetProperty()->FrontfaceCullingOff();
227   mySurfaceActor->GetProperty()->BackfaceCullingOff();
228   mySurfaceActor->SetRepresentation(2);
229
230   myEdgeActor = VISU_Actor::New();
231   myEdgeActor->SetParent(this);
232   myEdgeActor->PickableOff();
233   myEdgeActor->GetProperty()->SetPointSize(VISU_POINT_SIZE);
234   myEdgeActor->GetProperty()->FrontfaceCullingOff();
235   myEdgeActor->GetProperty()->BackfaceCullingOff();
236   myEdgeActor->SetRepresentation(2);
237
238   myRepresentation = 2; //SURFACE
239   myVisibility = 1; //On
240 }
241
242 VISUMesh_Actor::~VISUMesh_Actor(){
243   myEdgeMapper->Delete();
244   mySurfaceActor->Delete();
245   myEdgeActor->Delete();
246 }
247
248 void VISUMesh_Actor::setIO(const Handle(SALOME_InteractiveObject)& theIO){
249   mySurfaceActor->setIO(theIO);
250   myEdgeActor->setIO(theIO);
251 }
252
253 void VISUMesh_Actor::setPrs3d(VISU::Prs3d_i* thePrs3d){ 
254   if(thePrs3d){
255     VISU_Actor::setPrs3d(thePrs3d);
256     mySurfaceActor->setPrs3d(thePrs3d);
257     myEdgeActor->setPrs3d(thePrs3d);
258   }
259 }
260
261 void VISUMesh_Actor::AddToRender(vtkRenderer* theRenderer){
262   theRenderer->AddActor(mySurfaceActor);
263   theRenderer->AddActor(myEdgeActor);
264 }
265
266 void VISUMesh_Actor::RemoveFromRender(vtkRenderer* theRenderer){
267   theRenderer->RemoveActor(mySurfaceActor);
268   theRenderer->RemoveActor(myEdgeActor);
269 }
270
271 void VISUMesh_Actor::SetMapper(vtkMapper* theMapper){
272   VISU_Actor::SetMapper(theMapper);
273   SALOME_PassThroughFilter* aPassFilter = SALOME_PassThroughFilter::New();
274   aPassFilter->SetInput(theMapper->GetInput());
275   vtkFeatureEdges *aFeatureEdges = vtkFeatureEdges::New();
276   aFeatureEdges->SetInput(aPassFilter->GetPolyDataOutput());
277   aFeatureEdges->BoundaryEdgesOn();
278   aFeatureEdges->ManifoldEdgesOn();
279   myEdgeMapper->SetInput(aFeatureEdges->GetOutput());
280   aFeatureEdges->Delete();
281   myEdgeMapper->ScalarVisibilityOff();
282   myEdgeActor->SetMapper(myEdgeMapper);
283   mySurfaceActor->SetMapper(theMapper);
284 }
285
286 void VISUMesh_Actor::SetTransform(SALOME_Transform* theTransform){
287   mySurfaceActor->SetTransform(theTransform);
288   myEdgeActor->SetTransform(theTransform);
289 }
290
291 void VISUMesh_Actor::SetShrinkable(bool theIsShrinkable){
292   myIsShrinkable = theIsShrinkable;
293   myEdgeActor->SetShrinkable(myIsShrinkable);
294   mySurfaceActor->SetShrinkable(myIsShrinkable);
295 }
296
297 vtkProperty* VISUMesh_Actor::GetProperty(){ 
298   mySurfaceActor->GetProperty();
299
300
301 void VISUMesh_Actor::SetProperty(vtkProperty* theProperty){ 
302   mySurfaceActor->SetProperty(theProperty);
303 }
304
305 vtkProperty* VISUMesh_Actor::GetEdgeProperty(){ 
306   myEdgeActor->GetProperty();
307
308
309 void VISUMesh_Actor::SetEdgeProperty(vtkProperty* theProperty){ 
310   myEdgeActor->SetProperty(theProperty);
311 }
312
313 void VISUMesh_Actor::SetLineWidth(float theLineWidth){
314   GetProperty()->SetLineWidth(theLineWidth);
315   GetEdgeProperty()->SetLineWidth(theLineWidth);
316 }
317
318 float VISUMesh_Actor::GetLineWidth(){
319   return GetProperty()->GetLineWidth();
320 }
321
322 void VISUMesh_Actor::setShrink(float theFactor){
323   if(!myIsShrinkable || myIsShrunk || myRepresentation == 0) return;
324   mySurfaceActor->setShrink(theFactor);
325   myIsShrunk = true;
326   SetRepresentation(myRepresentation);
327 }
328
329 void VISUMesh_Actor::unShrink(){
330   if(!myIsShrunk) return;
331   mySurfaceActor->unShrink();
332   myIsShrunk = false;
333   SetRepresentation(myRepresentation);
334 }
335
336 void VISUMesh_Actor::SetRepresentation(int theMode){
337   if(theMode < 0 || theMode >2) return;
338   myRepresentation = theMode;
339   myEdgeActor->SetRepresentation(2);
340   mySurfaceActor->SetRepresentation(myRepresentation);
341   switch(theMode){
342   case 0: //POINTS
343     myEdgeActor->VisibilityOff();
344     mySurfaceActor->VisibilityOn();
345     break;
346   case 1: //WIREFRAME
347     myEdgeActor->VisibilityOff();
348     mySurfaceActor->VisibilityOn();
349     break;
350   case 2: //SURFACE
351     myEdgeActor->SetVisibility(!myIsShrunk);
352     mySurfaceActor->VisibilityOn();
353     break;
354   }
355   myRepresentation = theMode;
356 }
357
358 void VISUMesh_Actor::SetVisibility(int theMode){
359   SetRepresentation(myRepresentation);
360   myEdgeActor->SetVisibility(theMode);
361   mySurfaceActor->SetVisibility(theMode);
362   myVisibility = theMode;
363 }
364
365 //=======================================================================
366