Salome HOME
Porting to VTK 6.
[modules/visu.git] / src / PIPELINE / VISU_IsoSurfacesPL.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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 //  VISU OBJECT : interactive object for VISU entities implementation
24 // File:    VISU_PipeLine.cxx
25 // Author:  Alexey PETROV
26 // Module : VISU
27 //
28 #include "VISU_IsoSurfacesPL.hxx"
29 #include "VISU_LookupTable.hxx"
30
31 #include "VISU_PipeLineUtils.hxx"
32 #include "VISU_LabelPointsFilter.hxx"
33
34 #include <vtkContourFilter.h>
35
36 #define GAP_COEFFICIENT 0.0001
37
38
39 //----------------------------------------------------------------------------
40 vtkStandardNewMacro(VISU_IsoSurfacesPL);
41
42
43 //----------------------------------------------------------------------------
44 VISU_IsoSurfacesPL
45 ::VISU_IsoSurfacesPL()
46 {
47   SetIsShrinkable(false);
48   SetIsFeatureEdgesAllowed(false);
49
50   SetElnoDisassembleState( true );
51
52   myContourFilter = vtkContourFilter::New();
53
54   myCellDataToPointData = VISU_CellDataToPointData::New();
55 }
56
57
58 //----------------------------------------------------------------------------
59 VISU_IsoSurfacesPL
60 ::~VISU_IsoSurfacesPL()
61 {
62   myContourFilter->Delete();
63   myContourFilter = NULL;
64
65   myCellDataToPointData->Delete();
66   myCellDataToPointData = NULL;
67 }
68
69
70 //----------------------------------------------------------------------------
71 unsigned long int 
72 VISU_IsoSurfacesPL
73 ::GetMTime()
74 {
75   unsigned long int aTime = Superclass::GetMTime();
76
77   aTime = std::max(aTime, myCellDataToPointData->GetMTime());
78   aTime = std::max(aTime, myContourFilter->GetMTime());
79
80   return aTime;
81 }
82
83
84 //----------------------------------------------------------------------------
85 void
86 VISU_IsoSurfacesPL
87 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
88                 bool theIsCopyInput)
89 {
90   Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
91
92   if(VISU_IsoSurfacesPL *aPipeLine = dynamic_cast<VISU_IsoSurfacesPL*>(thePipeLine)){
93     SetNbParts(aPipeLine->GetNbParts());
94     double aRange[2] = {aPipeLine->GetMin(), aPipeLine->GetMax()};
95     SetRange(aRange);
96     SetRangeFixed(aPipeLine->IsRangeFixed());
97   }
98 }
99
100
101 //----------------------------------------------------------------------------
102 int
103 VISU_IsoSurfacesPL
104 ::GetNbParts() 
105 {
106   return myContourFilter->GetNumberOfContours();
107 }
108
109 //----------------------------------------------------------------------------
110 double
111 VISU_IsoSurfacesPL
112 ::GetValue(int i) 
113 {
114   return myContourFilter->GetValue(i);
115 }
116
117
118 //----------------------------------------------------------------------------
119 void
120 VISU_IsoSurfacesPL
121 ::SetNbParts(int theNb) 
122 {
123   myContourFilter->SetNumberOfContours(theNb);
124 }
125
126
127 //----------------------------------------------------------------------------
128 void
129 VISU_IsoSurfacesPL
130 ::SetScalarRange( double theRange[2] ) 
131 {
132   Superclass::SetScalarRange( theRange );
133   SetRange(myRange);
134 }
135
136
137 //----------------------------------------------------------------------------
138 void
139 VISU_IsoSurfacesPL
140 ::SetRange(double theRange[2], bool theIsForced)
141 {
142   if(VISU::CheckIsSameRange(myRange, theRange) && !theIsForced)
143     return;
144
145   if(theRange[0] <= theRange[1]){
146     myRange[0] = theRange[0];  
147     myRange[1] = theRange[1];
148     double aRange[2] = {theRange[0], theRange[1]};
149     if( IsRangeFixed() ) {
150       double aDelta = fabs( aRange[1] - aRange[0] ) * GAP_COEFFICIENT;
151       aRange[0] += aDelta;
152       aRange[1] -= aDelta;
153     }
154     if(GetScaling() == VTK_SCALE_LOG10)
155       VISU_LookupTable::ComputeLogRange(theRange, aRange);
156     myContourFilter->GenerateValues(GetNbParts(), aRange);
157   }
158 }
159
160
161 //----------------------------------------------------------------------------
162 double
163 VISU_IsoSurfacesPL
164 ::GetMin() 
165 {
166   return myRange[0];
167 }
168
169
170 //----------------------------------------------------------------------------
171 double
172 VISU_IsoSurfacesPL
173 ::GetMax() 
174 {
175   return myRange[1];
176 }
177
178
179 //----------------------------------------------------------------------------
180 void
181 VISU_IsoSurfacesPL
182 ::SetRangeFixed(bool theIsFixed)
183 {
184   myIsRangeFixed = theIsFixed;
185   SetRange( myRange, true );
186 }
187
188
189 //----------------------------------------------------------------------------
190 bool
191 VISU_IsoSurfacesPL
192 ::IsRangeFixed()
193 {
194   return myIsRangeFixed;
195 }
196
197
198 void
199 //----------------------------------------------------------------------------
200 VISU_IsoSurfacesPL
201 ::Init()
202 {
203   Superclass::Init();
204
205   SetNbParts(10);
206
207   double aScalarRange[2];
208   GetSourceRange(aScalarRange);
209   SetRange(aScalarRange);
210
211   SetRangeFixed(true);
212 }
213
214 //----------------------------------------------------------------------------
215 void
216 VISU_IsoSurfacesPL
217 ::Build()
218 {
219   Superclass::Build();
220
221   VISU::CellDataToPoint(myContourFilter,
222                         myCellDataToPointData,
223                         GetMergedInput(),
224                         GetMergedInputPort());
225
226 }
227
228
229 //----------------------------------------------------------------------------
230
231 vtkAlgorithmOutput* 
232 VISU_IsoSurfacesPL
233 ::InsertCustomPL()
234 {
235   return myContourFilter->GetOutputPort();
236 }
237
238
239 //----------------------------------------------------------------------------
240 unsigned long int
241 VISU_IsoSurfacesPL
242 ::GetMemorySize()
243 {
244   unsigned long int aSize = Superclass::GetMemorySize();
245
246   if(vtkDataSet* aDataSet = myContourFilter->GetOutput())
247     aSize += aDataSet->GetActualMemorySize() * 1024;
248   
249   if(myCellDataToPointData->GetInput())
250     if(vtkDataSet* aDataSet = myCellDataToPointData->GetOutput())
251       aSize += aDataSet->GetActualMemorySize() * 1024;
252
253   return aSize;
254 }
255
256
257 //----------------------------------------------------------------------------
258 void
259 VISU_IsoSurfacesPL
260 ::SetMapScale(double theMapScale)
261 {
262   Superclass::SetMapScale(theMapScale);
263
264   double aRange[2] = {GetMax() - theMapScale*(GetMax()-GetMin()), GetMax()};
265   double aNewRange[2] = {aRange[0], aRange[1]};
266   if( IsRangeFixed() ) {
267     double aDelta = fabs( aNewRange[1] - aNewRange[0] ) * GAP_COEFFICIENT;
268     aNewRange[0] += aDelta;
269     aNewRange[1] -= aDelta;
270   }
271   if(GetScaling() == VTK_SCALE_LOG10)
272     VISU_LookupTable::ComputeLogRange(aRange,aNewRange);
273   myContourFilter->GenerateValues(GetNbParts(), aNewRange);
274 }
275
276
277 //----------------------------------------------------------------------------