Salome HOME
Fix for Bug PAL8597:
[modules/visu.git] / src / PIPELINE / VISU_IsoSurfacesPL.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_PipeLine.cxx
25 // Author:  Alexey PETROV
26 // Module : VISU
27
28
29 #include "VISU_IsoSurfacesPL.hxx"
30 #include "VISU_PipeLineUtils.hxx"
31
32 #include <vtkContourFilter.h>
33
34 vtkStandardNewMacro(VISU_IsoSurfacesPL);
35
36 VISU_IsoSurfacesPL::VISU_IsoSurfacesPL(){
37   myContourFilter = vtkContourFilter::New();
38   myCellDataToPointData = vtkCellDataToPointData::New();
39   myIsShrinkable = false;
40 }
41
42 VISU_IsoSurfacesPL::~VISU_IsoSurfacesPL(){
43   myContourFilter->UnRegisterAllOutputs();
44   myContourFilter->Delete();
45
46   myCellDataToPointData->UnRegisterAllOutputs();
47   myCellDataToPointData->Delete();
48 }
49
50 void VISU_IsoSurfacesPL::ShallowCopy(VISU_PipeLine *thePipeLine){
51   VISU_ScalarMapPL::ShallowCopy(thePipeLine);
52   if(VISU_IsoSurfacesPL *aPipeLine = dynamic_cast<VISU_IsoSurfacesPL*>(thePipeLine)){
53     SetNbParts(aPipeLine->GetNbParts());
54     float aRange[2] = {aPipeLine->GetMin(), aPipeLine->GetMax()};
55     SetRange(aRange);
56   }
57 }
58
59 int VISU_IsoSurfacesPL::GetNbParts() {
60   return myContourFilter->GetNumberOfContours();
61 }
62 void VISU_IsoSurfacesPL::SetNbParts(int theNb) {
63   myContourFilter->SetNumberOfContours(theNb);
64   Modified();
65 }
66
67
68 void VISU_IsoSurfacesPL::SetScaling(int theScaling) {
69   VISU_ScalarMapPL::SetScaling(theScaling);
70   SetRange(myRange);
71 }
72 void VISU_IsoSurfacesPL::SetRange(float theRange[2]){
73   if(theRange[0] <= theRange[1]){
74     myRange[0] = theRange[0];  myRange[1] = theRange[1];
75     float aRange[2] = {myRange[0], myRange[1]};
76     if(GetScaling() == VTK_SCALE_LOG10)
77       VISU_LookupTable::ComputeLogRange(theRange,aRange);
78     myContourFilter->GenerateValues(GetNbParts(),aRange);
79     Modified();
80   }
81 }
82 float VISU_IsoSurfacesPL::GetMin() {
83   return myRange[0];
84 }
85 float VISU_IsoSurfacesPL::GetMax() {
86   return myRange[1];
87 }
88
89
90 void VISU_IsoSurfacesPL::Init(){
91   VISU_ScalarMapPL::Init();
92
93   SetNbParts(10);
94   float aScalarRange[2];
95   GetSourceRange(aScalarRange);
96   SetRange(aScalarRange);
97 }
98
99 VISU_ScalarMapPL::THook* VISU_IsoSurfacesPL::DoHook(){
100   return myContourFilter->GetOutput();
101 }
102
103
104 void VISU_IsoSurfacesPL::Update(){
105   VISU::CellDataToPoint(myContourFilter,myCellDataToPointData,GetInput2(),myFieldTransform);
106   SetMapScale();
107
108   VISU_ScalarMapPL::Update();
109 }
110
111 void VISU_IsoSurfacesPL::SetMapScale(float theMapScale){
112   VISU_ScalarMapPL::SetMapScale(theMapScale);
113
114   float aRange[2] = {GetMax() - theMapScale*(GetMax()-GetMin()), GetMax()};
115   float aNewRange[2] = {aRange[0], aRange[1]};
116   if(GetScaling() == VTK_SCALE_LOG10)
117     VISU_LookupTable::ComputeLogRange(aRange,aNewRange);
118   myContourFilter->GenerateValues(GetNbParts(),aNewRange);
119   Modified();
120 }