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
29 #include "VISU_Actor.h"
30 #include "VISU_PipeLine.hxx"
31 #include "SALOME_PassThroughFilter.h"
32 #include "utilities.h"
35 #include <vtkProperty.h>
36 #include <vtkDataSetMapper.h>
37 #include <vtkShrinkPolyData.h>
38 #include <vtkGeometryFilter.h>
39 #include <vtkObjectFactory.h>
43 static int MYVTKDEBUG = 0;
46 static int MYDEBUG = 1;
47 static int MYDEBUGWITHFILES = 0;
49 static int MYDEBUG = 0;
50 static int MYDEBUGWITHFILES = 0;
53 //=======================================================================
55 vtkStandardNewMacro(VISU_Actor);
57 VISU_Actor::VISU_Actor(){
63 myStoreMapping = true;
66 myIsShrinkable = false;
67 myShrinkFilter = vtkShrinkPolyData::New();
72 ishighlighted = false;
73 IsHighlighting = true;
74 HighlightProperty = vtkProperty::New();
75 HighlightProperty->SetAmbient(0.5);
76 HighlightProperty->SetDiffuse(0.3);
77 HighlightProperty->SetSpecular(0.2);
78 HighlightProperty->SetRepresentationToSurface();
79 HighlightProperty->SetAmbientColor(1, 1, 1);
80 HighlightProperty->SetDiffuseColor(1, 1, 1);
81 HighlightProperty->SetSpecularColor(0.5, 0.5, 0.5);
83 vtkProperty* aProperty = this->GetProperty();
84 aProperty->SetAmbient(0.5);
85 aProperty->SetDiffuse(0.2);
86 aProperty->SetSpecular(0.2);
87 aProperty->SetAmbientColor(1, 1, 1);
88 aProperty->SetDiffuseColor(1, 1, 1);
89 aProperty->SetSpecularColor(0.5, 0.5, 0.5);
90 this->SetProperty(aProperty);
93 VISU_Actor::~VISU_Actor(){
94 SALOME_Actor::SetProperty(NULL);
95 HighlightProperty->Delete();
96 if(myPipeLine) myPipeLine->UnRegister(this);
98 myShrinkFilter->UnRegisterAllOutputs();
99 myShrinkFilter->Delete();
102 void VISU_Actor::setIO(const Handle(SALOME_InteractiveObject)& theIO){
103 SALOME_Actor::setIO(theIO);
104 myName = theIO->getName();
107 void VISU_Actor::SetPrs3d(VISU::Prs3d_i* thePrs3d){
111 void VISU_Actor::SetPipeLine(VISU_PipeLine* thePipeLine) {
112 if (myPipeLine != thePipeLine){
113 if (myPipeLine != NULL) myPipeLine->UnRegister(this);
114 myPipeLine = thePipeLine;
115 if (myPipeLine != NULL) myPipeLine->Register(this);
117 vtkMapper *aMapper = myPipeLine->GetMapper();
118 vtkDataSet *aDataSet = aMapper->GetInput();
120 throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no input data !!!");
122 static float eps = VTK_LARGE_FLOAT * 0.1 ;
123 if(aDataSet->GetLength() > eps)
124 throw std::runtime_error("VISU_Actor::SetPipeLine >> Diagonal of the actor is too large !!!");
125 if(!aDataSet->GetNumberOfCells())
126 throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no visible elements");
127 //Bug SAL4221: Mesh with less than 10 cells : shrink mode disable
128 //SetShrinkable(aDataSet->GetNumberOfCells() > 10);
130 //Now, we use vtkShrinkPolyData (not vtkShrinkFilter),
131 //and the class there is no such limitation.
133 vtkDataSetMapper* aNewMapper = vtkDataSetMapper::New();
134 aNewMapper->SetInput(aDataSet);
135 SetMapper(aNewMapper);
136 aNewMapper->Delete();
140 void VISU_Actor::SetParent(VISU_Actor* theParent){
141 myParent = theParent;
144 void VISU_Actor::SetRepresentation(int theMode) {
145 SALOME_Actor::SetRepresentation(theMode);
148 void VISU_Actor::SetOpacity(float theValue){
149 GetProperty()->SetOpacity(theValue);
152 float VISU_Actor::GetOpacity(){
153 return GetProperty()->GetOpacity();
156 void VISU_Actor::SetShrinkable(bool theIsShrinkable){
157 myIsShrinkable = theIsShrinkable;
160 void VISU_Actor::SetShrink(float theFactor){
161 if(!myIsShrinkable) return;
162 if(vtkPolyData* aDataSet = myPassFilter.at(1)->GetPolyDataOutput()){
163 myShrinkFilter->SetShrinkFactor(theFactor);
164 myShrinkFilter->SetInput(aDataSet);
165 myPassFilter.at(2)->SetInput(myShrinkFilter->GetOutput());
170 void VISU_Actor::UnShrink(){
171 if(!myIsShrunk) return;
172 if(vtkPolyData* aDataSet = myPassFilter.at(1)->GetPolyDataOutput()){
173 myPassFilter.at(2)->SetInput(aDataSet);
174 myPassFilter.at(2)->Modified();
179 void VISU_Actor::SetVisibility(int theMode){
180 SALOME_Actor::SetVisibility(theMode);
183 int VISU_Actor::GetVisibility(){
184 return SALOME_Actor::GetVisibility();
187 void VISU_Actor::SetProperty(vtkProperty* theProperty){
188 SALOME_Actor::SetProperty(theProperty);
191 vtkProperty* VISU_Actor::GetProperty(){
192 return SALOME_Actor::GetProperty();
195 void VISU_Actor::SetLineWidth(float theLineWidth){
196 GetProperty()->SetLineWidth(theLineWidth);
199 float VISU_Actor::GetLineWidth(){
200 return GetProperty()->GetLineWidth();
203 void VISU_Actor::ShallowCopy(vtkProp *prop){
204 VISU_Actor *anActor = VISU_Actor::SafeDownCast(prop);
206 setName(anActor->getName());
207 if(anActor->hasIO()) setIO(anActor->getIO());
209 SALOME_Actor::ShallowCopy(prop);
212 void VISU_Actor::highlight(Standard_Boolean highlight) {
213 if (this->IsHighlighting) {
214 if(highlight && !ishighlighted) {
216 this->SetProperty(HighlightProperty);
217 }else if (!highlight)
218 if(ishighlighted) ishighlighted=false;
222 int VISU_Actor::GetObjId(int theVtkID){
223 if (GetRepresentation() == 0) return -1; // points
224 return myGeomFilter->GetObjId(theVtkID);
227 VISU_Actor::TVectorId VISU_Actor::GetVtkId(int theObjID){
228 return myGeomFilter->GetVtkId(theObjID);