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"
34 #include <vtkProperty.h>
35 #include <vtkDataSetMapper.h>
36 #include <vtkShrinkPolyData.h>
37 #include <vtkObjectFactory.h>
41 //=======================================================================
43 vtkStandardNewMacro(VISU_Actor);
45 VISU_Actor::VISU_Actor(){
47 myIsShrinkable = false;
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);
67 VISU_Actor::~VISU_Actor(){
68 HighlightProperty->Delete();
71 void VISU_Actor::setIO(const Handle(SALOME_InteractiveObject)& theIO){
72 SALOME_Actor::setIO(theIO);
73 myName = theIO->getName();
76 void VISU_Actor::SetPrs3d(VISU::Prs3d_i* thePrs3d){
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);
86 vtkMapper *aMapper = myPipeLine->GetMapper();
87 vtkDataSet *aDataSet = aMapper->GetInput();
89 throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no input data");
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);
98 vtkDataSetMapper* aNewMapper = vtkDataSetMapper::New();
99 aNewMapper->SetInput(aDataSet);
100 aMapper->ShallowCopy(aMapper);
101 SetMapper(aNewMapper);
102 aNewMapper->Delete();
106 void VISU_Actor::SetParent(VISU_Actor* theParent){
107 myParent = theParent;
110 void VISU_Actor::SetShrinkable(bool theIsShrinkable){
111 myIsShrinkable = theIsShrinkable;
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();
126 void VISU_Actor::UnShrink(){
127 if(!myIsShrunk) return;
128 myPassFilter[3]->SetInput(myPassFilter[2]->GetPolyDataOutput());
129 myPassFilter[3]->Modified();
133 void VISU_Actor::SetVisibility(int theMode){
134 SALOME_Actor::SetVisibility(theMode);
137 int VISU_Actor::GetVisibility(){
138 return SALOME_Actor::GetVisibility();
141 void VISU_Actor::SetProperty(vtkProperty* theProperty){
142 SALOME_Actor::SetProperty(theProperty);
145 vtkProperty* VISU_Actor::GetProperty(){
146 return SALOME_Actor::GetProperty();
149 void VISU_Actor::SetLineWidth(float theLineWidth){
150 GetProperty()->SetLineWidth(theLineWidth);
153 float VISU_Actor::GetLineWidth(){
154 return GetProperty()->GetLineWidth();
157 void VISU_Actor::ShallowCopy(vtkProp *prop){
158 VISU_Actor *anActor = VISU_Actor::SafeDownCast(prop);
160 setName(anActor->getName());
161 if(anActor->hasIO()) setIO(anActor->getIO());
163 SALOME_Actor::ShallowCopy(prop);
166 void VISU_Actor::highlight(Standard_Boolean highlight) {
167 if (this->IsHighlighting) {
168 if(highlight && !ishighlighted) {
170 this->SetProperty(HighlightProperty);
171 }else if (!highlight)
172 if(ishighlighted) ishighlighted=false;