Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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_LookupTable.hxx"
31
32 #include "VISU_PipeLineUtils.hxx"
33
34 #include <vtkContourFilter.h>
35
36
37 //----------------------------------------------------------------------------
38 vtkStandardNewMacro(VISU_IsoSurfacesPL);
39
40
41 //----------------------------------------------------------------------------
42 VISU_IsoSurfacesPL
43 ::VISU_IsoSurfacesPL()
44 {
45   SetIsShrinkable(false);
46
47   myContourFilter = vtkContourFilter::New();
48
49   myCellDataToPointData = vtkCellDataToPointData::New();
50 }
51
52
53 //----------------------------------------------------------------------------
54 VISU_IsoSurfacesPL
55 ::~VISU_IsoSurfacesPL()
56 {
57   myContourFilter->Delete();
58   myContourFilter = NULL;
59
60   myCellDataToPointData->Delete();
61   myCellDataToPointData = NULL;
62 }
63
64
65 //----------------------------------------------------------------------------
66 unsigned long int 
67 VISU_IsoSurfacesPL
68 ::GetMTime()
69 {
70   unsigned long int aTime = Superclass::GetMTime();
71
72   aTime = std::max(aTime, myCellDataToPointData->GetMTime());
73   aTime = std::max(aTime, myContourFilter->GetMTime());
74
75   return aTime;
76 }
77
78
79 //----------------------------------------------------------------------------
80 void
81 VISU_IsoSurfacesPL
82 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
83                 bool theIsCopyInput)
84 {
85   Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
86
87   if(VISU_IsoSurfacesPL *aPipeLine = dynamic_cast<VISU_IsoSurfacesPL*>(thePipeLine)){
88     SetNbParts(aPipeLine->GetNbParts());
89     vtkFloatingPointType aRange[2] = {aPipeLine->GetMin(), aPipeLine->GetMax()};
90     SetRange(aRange);
91   }
92 }
93
94
95 //----------------------------------------------------------------------------
96 int
97 VISU_IsoSurfacesPL
98 ::GetNbParts() 
99 {
100   return myContourFilter->GetNumberOfContours();
101 }
102
103
104 //----------------------------------------------------------------------------
105 void
106 VISU_IsoSurfacesPL
107 ::SetNbParts(int theNb) 
108 {
109   myContourFilter->SetNumberOfContours(theNb);
110 }
111
112
113 //----------------------------------------------------------------------------
114 void
115 VISU_IsoSurfacesPL
116 ::SetScalarRange(vtkFloatingPointType theRange[2]) 
117 {
118   Superclass::SetScalarRange(theRange);
119   SetRange(myRange);
120 }
121
122
123 //----------------------------------------------------------------------------
124 void
125 VISU_IsoSurfacesPL
126 ::SetRange(vtkFloatingPointType theRange[2])
127 {
128   if(VISU::CheckIsSameRange(myRange, theRange))
129     return;
130
131   if(theRange[0] <= theRange[1]){
132     myRange[0] = theRange[0];  
133     myRange[1] = theRange[1];
134     vtkFloatingPointType aRange[2] = {theRange[0], theRange[1]};
135     if(GetScaling() == VTK_SCALE_LOG10)
136       VISU_LookupTable::ComputeLogRange(theRange, aRange);
137     myContourFilter->GenerateValues(GetNbParts(), aRange);
138   }
139 }
140
141
142 //----------------------------------------------------------------------------
143 vtkFloatingPointType
144 VISU_IsoSurfacesPL
145 ::GetMin() 
146 {
147   return myRange[0];
148 }
149
150
151 //----------------------------------------------------------------------------
152 vtkFloatingPointType
153 VISU_IsoSurfacesPL
154 ::GetMax() 
155 {
156   return myRange[1];
157 }
158
159
160 void
161 //----------------------------------------------------------------------------
162 VISU_IsoSurfacesPL
163 ::Init()
164 {
165   Superclass::Init();
166
167   SetNbParts(10);
168
169   vtkFloatingPointType aScalarRange[2];
170   GetSourceRange(aScalarRange);
171   SetRange(aScalarRange);
172 }
173
174 //----------------------------------------------------------------------------
175 void
176 VISU_IsoSurfacesPL
177 ::Build()
178 {
179   Superclass::Build();
180
181   VISU::CellDataToPoint(myContourFilter,
182                         myCellDataToPointData,
183                         GetMergedInput());
184 }
185
186
187 //----------------------------------------------------------------------------
188
189 vtkDataSet* 
190 VISU_IsoSurfacesPL
191 ::InsertCustomPL()
192 {
193   return myContourFilter->GetOutput();
194 }
195
196
197 //----------------------------------------------------------------------------
198 unsigned long int
199 VISU_IsoSurfacesPL
200 ::GetMemorySize()
201 {
202   unsigned long int aSize = Superclass::GetMemorySize();
203
204   if(vtkDataSet* aDataSet = myContourFilter->GetOutput())
205     aSize += aDataSet->GetActualMemorySize() * 1024;
206   
207   if(myCellDataToPointData->GetInput())
208     if(vtkDataSet* aDataSet = myCellDataToPointData->GetOutput())
209       aSize += aDataSet->GetActualMemorySize() * 1024;
210
211   return aSize;
212 }
213
214
215 //----------------------------------------------------------------------------
216 void
217 VISU_IsoSurfacesPL
218 ::SetMapScale(vtkFloatingPointType theMapScale)
219 {
220   Superclass::SetMapScale(theMapScale);
221
222   vtkFloatingPointType aRange[2] = {GetMax() - theMapScale*(GetMax()-GetMin()), GetMax()};
223   vtkFloatingPointType aNewRange[2] = {aRange[0], aRange[1]};
224   if(GetScaling() == VTK_SCALE_LOG10)
225     VISU_LookupTable::ComputeLogRange(aRange,aNewRange);
226   myContourFilter->GenerateValues(GetNbParts(), aNewRange);
227 }
228
229
230 //----------------------------------------------------------------------------