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 "VTKViewer_ShrinkFilter.h"
32 #include "VTKViewer_GeometryFilter.h"
33 #include "VTKViewer_PassThroughFilter.h"
38 #include <vtkProperty.h>
40 #include <vtkDataSet.h>
41 #include <vtkPolyData.h>
42 #include <vtkUnstructuredGrid.h>
44 #include <vtkShrinkFilter.h>
45 #include <vtkShrinkPolyData.h>
47 #include <vtkDataSetMapper.h>
48 #include <vtkGeometryFilter.h>
49 #include <vtkObjectFactory.h>
51 #include "utilities.h"
55 static int MYVTKDEBUG = 0;
58 static int MYDEBUG = 1;
60 static int MYDEBUG = 0;
63 //=======================================================================
65 vtkStandardNewMacro(VISU_Actor);
67 VISU_Actor::VISU_Actor(){
73 myStoreMapping = true;
76 myIsShrinkable = false;
77 myShrinkFilter = VTKViewer_ShrinkFilter::New();
78 myShrinkFilter->SetStoreMapping(true);
81 myMapper = vtkDataSetMapper::New();
87 VISU_Actor::~VISU_Actor(){
88 SALOME_Actor::SetProperty(NULL);
90 myMapper->RemoveAllInputs();
94 myPipeLine->UnRegister(this);
96 myShrinkFilter->UnRegisterAllOutputs();
97 myShrinkFilter->Delete();
100 void VISU_Actor::setIO(const Handle(SALOME_InteractiveObject)& theIO){
101 SALOME_Actor::setIO(theIO);
102 myName = theIO->getName();
105 void VISU_Actor::SetPrs3d(VISU::Prs3d_i* thePrs3d){
109 void VISU_Actor::SetPipeLine(VISU_PipeLine* thePipeLine) {
110 if (myPipeLine != thePipeLine){
111 if (myPipeLine != NULL) myPipeLine->UnRegister(this);
112 myPipeLine = thePipeLine;
113 if (myPipeLine != NULL) myPipeLine->Register(this);
115 vtkMapper *aMapper = myPipeLine->GetMapper();
116 vtkDataSet *aDataSet = aMapper->GetInput();
118 throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no input data !!!");
120 static float eps = VTK_LARGE_FLOAT * 0.1 ;
121 if(aDataSet->GetLength() > eps)
122 throw std::runtime_error("VISU_Actor::SetPipeLine >> Diagonal of the actor is too large !!!");
123 if(!aDataSet->GetNumberOfCells())
124 throw std::runtime_error("VISU_Actor::SetPipeLine >> There is no visible elements");
125 //Bug SAL4221: Mesh with less than 10 cells : shrink mode disable
126 //SetShrinkable(aDataSet->GetNumberOfCells() > 10);
127 SetShrinkable(thePipeLine->IsShrinkable());
128 //Now, we use vtkShrinkPolyData (not vtkShrinkFilter),
129 //and the class there is no such limitation.
131 myMapper->SetInput(aDataSet);
136 void VISU_Actor::SetParent(VISU_Actor* theParent){
137 myParent = theParent;
140 void VISU_Actor::SetRepresentation(int theMode) {
141 SALOME_Actor::SetRepresentation(theMode);
142 if(myRepresentation == VTK_POINTS)
146 void VISU_Actor::SetOpacity(float theValue){
147 GetProperty()->SetOpacity(theValue);
150 float VISU_Actor::GetOpacity(){
151 return GetProperty()->GetOpacity();
155 void VISU_Actor::SetShrink(){
156 if(!myIsShrinkable) return;
157 if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
158 myShrinkFilter->SetInput(aDataSet);
159 myPassFilter[1]->SetInput(myShrinkFilter->GetOutput());
164 void VISU_Actor::UnShrink(){
165 if(!myIsShrunk) return;
166 if(vtkDataSet* aDataSet = myPassFilter[0]->GetOutput()){
167 myPassFilter[1]->SetInput(aDataSet);
168 myPassFilter[1]->Modified();
174 void VISU_Actor::SetShrinkable(bool theIsShrinkable){
175 myIsShrinkable = theIsShrinkable;
178 void VISU_Actor::SetShrinkFactor(float theValue){
179 myShrinkFilter->SetShrinkFactor(theValue);
183 float VISU_Actor::GetShrinkFactor(){
184 return myShrinkFilter->GetShrinkFactor();
188 //----------------------------------------------------------------------------
189 void VISU_Actor::SetVisibility(int theMode){
190 SALOME_Actor::SetVisibility(theMode);
193 int VISU_Actor::GetVisibility(){
194 return SALOME_Actor::GetVisibility();
197 void VISU_Actor::SetLineWidth(float theLineWidth){
198 GetProperty()->SetLineWidth(theLineWidth);
201 float VISU_Actor::GetLineWidth(){
202 return GetProperty()->GetLineWidth();
205 //----------------------------------------------------------------------------
206 void VISU_Actor::ShallowCopy(vtkProp *prop){
207 VISU_Actor *anActor = VISU_Actor::SafeDownCast(prop);
209 setName(anActor->getName());
210 if(anActor->hasIO()) setIO(anActor->getIO());
212 SALOME_Actor::ShallowCopy(prop);
215 //----------------------------------------------------------------------------
216 int VISU_Actor::GetNodeObjId(int theVtkID){
218 return myShrinkFilter->GetNodeObjId(theVtkID);
222 int VISU_Actor::GetElemObjId(int theVtkID){
223 return myGeomFilter->GetElemObjId(theVtkID);