]> SALOME platform Git repositories - modules/visu.git/blob - src/OBJECT/VISU_Actor.cxx
Salome HOME
sources v1.2c
[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 #include "VISU_Actor.h"
30 #include "VISU_PipeLine.hxx"
31 #include "SALOME_PassThroughFilter.h"
32  
33 // VTK Includes
34 #include <vtkProperty.h>
35 #include <vtkDataSetMapper.h>
36 #include <vtkShrinkPolyData.h>
37 #include <vtkObjectFactory.h>
38
39 using namespace std;
40
41 //=======================================================================
42
43 vtkStandardNewMacro(VISU_Actor);
44
45 VISU_Actor::VISU_Actor(){
46   myIsShrunk = false;
47   myIsShrinkable = false;
48   myParent = this;
49   myPipeLine = NULL;
50   myPrs3d = NULL;
51
52   myIO = NULL;
53   myName = "";
54
55   ishighlighted = false;
56   IsHighlighting = true;
57   HighlightProperty = vtkProperty::New();
58   HighlightProperty->SetAmbient(0.5);
59   HighlightProperty->SetDiffuse(0.3);
60   HighlightProperty->SetSpecular(0.2);
61   HighlightProperty->SetRepresentationToSurface();
62   HighlightProperty->SetAmbientColor(1, 1, 1);
63   HighlightProperty->SetDiffuseColor(1, 1, 1);
64   HighlightProperty->SetSpecularColor(0.5, 0.5, 0.5);
65 }
66
67 VISU_Actor::~VISU_Actor(){
68   HighlightProperty->Delete();
69 }
70
71 void VISU_Actor::setIO(const Handle(SALOME_InteractiveObject)& theIO){
72   SALOME_Actor::setIO(theIO); 
73   myName = theIO->getName(); 
74 }
75
76 void VISU_Actor::SetPrs3d(VISU::Prs3d_i* thePrs3d){ 
77   myPrs3d = thePrs3d;
78 }
79
80 void VISU_Actor::SetPipeLine(VISU_PipeLine* thePipeLine) throw(std::runtime_error&){
81   if (myPipeLine != thePipeLine){
82     if (myPipeLine != NULL) myPipeLine->UnRegister(this);
83     myPipeLine = thePipeLine;
84     if (myPipeLine != NULL) myPipeLine->Register(this);
85     this->Modified();
86     vtkMapper *aMapper = myPipeLine->GetMapper();
87     vtkDataSet *aDataSet = aMapper->GetInput();
88     if(!aDataSet)
89       throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no input data");
90     aDataSet->Update();
91     static float eps = VTK_LARGE_FLOAT * 0.1 ;
92     if(aDataSet->GetLength() > eps)
93       throw std::runtime_error("VISU_Actor::SetPipeLine >> Diagonal of the actor is too large");
94     if(!aDataSet->GetNumberOfCells())
95       throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no visible elements");
96     SetShrinkable(aDataSet->GetNumberOfCells() > 10);
97
98     vtkDataSetMapper* aNewMapper = vtkDataSetMapper::New();
99     aNewMapper->SetInput(aDataSet);
100     aMapper->ShallowCopy(aMapper);
101     SetMapper(aNewMapper);
102     aNewMapper->Delete();
103   }
104 }
105
106 void VISU_Actor::SetParent(VISU_Actor* theParent){ 
107   myParent = theParent;
108 }
109
110 void VISU_Actor::SetShrinkable(bool theIsShrinkable){
111   myIsShrinkable = theIsShrinkable;
112 }
113
114 void VISU_Actor::SetShrink(float theFactor){
115   if(!myIsShrinkable || myIsShrunk) return;
116   vtkShrinkPolyData *aShrinkFilter = vtkShrinkPolyData::New();
117   aShrinkFilter->SetShrinkFactor(theFactor);
118   // use for post-filtering
119   aShrinkFilter->SetInput(myPassFilter[2]->GetPolyDataOutput());
120   myPassFilter[3]->SetInput(aShrinkFilter->GetOutput());
121   aShrinkFilter->Register(myPassFilter[3]);
122   aShrinkFilter->Delete();
123   myIsShrunk = true;
124 }
125
126 void VISU_Actor::UnShrink(){
127   if(!myIsShrunk) return;
128   myPassFilter[3]->SetInput(myPassFilter[2]->GetPolyDataOutput());
129   myPassFilter[3]->Modified();
130   myIsShrunk = false;
131 }
132
133 void VISU_Actor::SetVisibility(int theMode){
134   SALOME_Actor::SetVisibility(theMode);
135 }
136
137 int VISU_Actor::GetVisibility(){
138   return SALOME_Actor::GetVisibility();
139 }
140
141 void VISU_Actor::SetProperty(vtkProperty* theProperty){
142   SALOME_Actor::SetProperty(theProperty);
143 }
144
145 vtkProperty* VISU_Actor::GetProperty(){
146   return SALOME_Actor::GetProperty();
147 }
148
149 void VISU_Actor::SetLineWidth(float theLineWidth){
150   GetProperty()->SetLineWidth(theLineWidth);
151 }
152
153 float VISU_Actor::GetLineWidth(){
154   return GetProperty()->GetLineWidth();
155 }
156
157 void VISU_Actor::ShallowCopy(vtkProp *prop){
158   VISU_Actor *anActor = VISU_Actor::SafeDownCast(prop);
159   if(anActor != NULL){
160     setName(anActor->getName());
161     if(anActor->hasIO()) setIO(anActor->getIO());
162   }
163   SALOME_Actor::ShallowCopy(prop);
164 }
165
166 void VISU_Actor::highlight(Standard_Boolean highlight) {
167   if (this->IsHighlighting) {
168     if(highlight && !ishighlighted) {
169       ishighlighted=true;
170       this->SetProperty(HighlightProperty);
171     }else if (!highlight)
172       if(ishighlighted) ishighlighted=false;
173   }
174 }