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_Actor.cxx
25 // Author : Laurent CORNABE with help of Nicolas REJNERI
30 #include "VISU_Actor.h"
31 #include "VISU_LookupTable.hxx"
32 #include "VISU_ScalarBarActor.hxx"
36 #include <vtkProperty.h>
37 #include <vtkShrinkPolyData.h>
38 #include <vtkFeatureEdges.h>
39 #include <vtkObjectFactory.h>
41 static int VISU_POINT_SIZE = 3;
43 //=======================================================================
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;
51 VISU_Actor::VISU_Actor(){
53 myIsShrinkable = false;
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);
72 VISU_Actor::~VISU_Actor(){
73 HighlightProperty->Delete();
76 void VISU_Actor::setIO(const Handle(SALOME_InteractiveObject)& theIO){
77 SALOME_Actor::setIO(theIO);
78 myName = theIO->getName();
81 void VISU_Actor::setPrs3d(VISU::Prs3d_i* thePrs3d){
85 void VISU_Actor::SetParent(VISU_Actor* theParent){
89 void VISU_Actor::SetMapper(vtkMapper* theMapper){
90 SALOME_Actor::SetMapper(theMapper);
93 void VISU_Actor::SetShrinkable(bool theIsShrinkable){
94 myIsShrinkable = theIsShrinkable;
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();
109 void VISU_Actor::unShrink(){
110 if(!myIsShrunk) return;
111 myPassFilter[3]->SetInput(myPassFilter[2]->GetPolyDataOutput());
112 myPassFilter[3]->Modified();
116 void VISU_Actor::SetVisibility(int theMode){
117 SALOME_Actor::SetVisibility(theMode);
120 int VISU_Actor::GetVisibility(){
121 return SALOME_Actor::GetVisibility();
124 void VISU_Actor::SetProperty(vtkProperty* theProperty){
125 SALOME_Actor::SetProperty(theProperty);
128 vtkProperty* VISU_Actor::GetProperty(){
129 return SALOME_Actor::GetProperty();
132 void VISU_Actor::SetLineWidth(float theLineWidth){
133 GetProperty()->SetLineWidth(theLineWidth);
136 float VISU_Actor::GetLineWidth(){
137 return GetProperty()->GetLineWidth();
140 void VISU_Actor::SetRepresentation(int theMode) {
141 GetProperty()->SetRepresentation(theMode);
143 GetProperty()->SetPointSize(VISU_POINT_SIZE);
146 int VISU_Actor::GetRepresentation(){
147 return GetProperty()->GetRepresentation();
150 void VISU_Actor::ShallowCopy(vtkProp *prop){
151 VISU_Actor *anActor = VISU_Actor::SafeDownCast(prop);
153 setName(anActor->getName());
154 if(anActor->hasIO()) setIO(anActor->getIO());
156 SALOME_Actor::ShallowCopy(prop);
159 void VISU_Actor::highlight(Standard_Boolean highlight) {
160 if (this->IsHighlighting) {
161 if(highlight && !ishighlighted) {
163 this->SetProperty(HighlightProperty);
164 }else if (!highlight)
165 if(ishighlighted) ishighlighted=false;
169 //=======================================================================
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;
177 VISUScalarMap_Actor::VISUScalarMap_Actor(){
178 myScalarBar = VISU_ScalarBarActor::New();
179 GetProperty()->FrontfaceCullingOff();
180 GetProperty()->BackfaceCullingOff();
183 VISUScalarMap_Actor::~VISUScalarMap_Actor(){
184 myScalarBar->Delete();
187 void VISUScalarMap_Actor::AddToRender(vtkRenderer* theRenderer){
188 SALOME_Actor::AddToRender(theRenderer);
190 theRenderer->AddActor2D(myScalarBar);
193 void VISUScalarMap_Actor::RemoveFromRender(vtkRenderer* theRenderer){
194 SALOME_Actor::RemoveFromRender(theRenderer);
196 theRenderer->RemoveActor(myScalarBar);
199 void VISUScalarMap_Actor::SetVisibility(int theMode){
200 SALOME_Actor::SetVisibility(theMode);
201 if(myScalarBar) myScalarBar->SetVisibility(*myBarVisibility && theMode);
204 int VISUScalarMap_Actor::GetVisibility(){
205 return SALOME_Actor::GetVisibility();
208 void VISUScalarMap_Actor::SetBarVisibility(const bool* theMode){
209 myBarVisibility = theMode;
210 if(myScalarBar) myScalarBar->SetVisibility(*myBarVisibility);
213 //=======================================================================
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;
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);
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);
238 myRepresentation = 2; //SURFACE
239 myVisibility = 1; //On
242 VISUMesh_Actor::~VISUMesh_Actor(){
243 myEdgeMapper->Delete();
244 mySurfaceActor->Delete();
245 myEdgeActor->Delete();
248 void VISUMesh_Actor::setIO(const Handle(SALOME_InteractiveObject)& theIO){
249 mySurfaceActor->setIO(theIO);
250 myEdgeActor->setIO(theIO);
253 void VISUMesh_Actor::setPrs3d(VISU::Prs3d_i* thePrs3d){
255 VISU_Actor::setPrs3d(thePrs3d);
256 mySurfaceActor->setPrs3d(thePrs3d);
257 myEdgeActor->setPrs3d(thePrs3d);
261 void VISUMesh_Actor::AddToRender(vtkRenderer* theRenderer){
262 theRenderer->AddActor(mySurfaceActor);
263 theRenderer->AddActor(myEdgeActor);
266 void VISUMesh_Actor::RemoveFromRender(vtkRenderer* theRenderer){
267 theRenderer->RemoveActor(mySurfaceActor);
268 theRenderer->RemoveActor(myEdgeActor);
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);
286 void VISUMesh_Actor::SetTransform(SALOME_Transform* theTransform){
287 mySurfaceActor->SetTransform(theTransform);
288 myEdgeActor->SetTransform(theTransform);
291 void VISUMesh_Actor::SetShrinkable(bool theIsShrinkable){
292 myIsShrinkable = theIsShrinkable;
293 myEdgeActor->SetShrinkable(myIsShrinkable);
294 mySurfaceActor->SetShrinkable(myIsShrinkable);
297 vtkProperty* VISUMesh_Actor::GetProperty(){
298 mySurfaceActor->GetProperty();
301 void VISUMesh_Actor::SetProperty(vtkProperty* theProperty){
302 mySurfaceActor->SetProperty(theProperty);
305 vtkProperty* VISUMesh_Actor::GetEdgeProperty(){
306 myEdgeActor->GetProperty();
309 void VISUMesh_Actor::SetEdgeProperty(vtkProperty* theProperty){
310 myEdgeActor->SetProperty(theProperty);
313 void VISUMesh_Actor::SetLineWidth(float theLineWidth){
314 GetProperty()->SetLineWidth(theLineWidth);
315 GetEdgeProperty()->SetLineWidth(theLineWidth);
318 float VISUMesh_Actor::GetLineWidth(){
319 return GetProperty()->GetLineWidth();
322 void VISUMesh_Actor::setShrink(float theFactor){
323 if(!myIsShrinkable || myIsShrunk || myRepresentation == 0) return;
324 mySurfaceActor->setShrink(theFactor);
326 SetRepresentation(myRepresentation);
329 void VISUMesh_Actor::unShrink(){
330 if(!myIsShrunk) return;
331 mySurfaceActor->unShrink();
333 SetRepresentation(myRepresentation);
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);
343 myEdgeActor->VisibilityOff();
344 mySurfaceActor->VisibilityOn();
347 myEdgeActor->VisibilityOff();
348 mySurfaceActor->VisibilityOn();
351 myEdgeActor->SetVisibility(!myIsShrunk);
352 mySurfaceActor->VisibilityOn();
355 myRepresentation = theMode;
358 void VISUMesh_Actor::SetVisibility(int theMode){
359 SetRepresentation(myRepresentation);
360 myEdgeActor->SetVisibility(theMode);
361 mySurfaceActor->SetVisibility(theMode);
362 myVisibility = theMode;
365 //=======================================================================