]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_ColoredPL.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / PIPELINE / VISU_ColoredPL.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_ColoredPL.cxx
25 // Author:  Alexey PETROV
26 // Module : VISU
27
28
29 #include "VISU_ColoredPL.hxx"
30 #include "VISU_Extractor.hxx"
31 #include "VISU_FieldTransform.hxx"
32 #include "VISU_LookupTable.hxx"
33 #include "VISU_MapperHolder.hxx"
34
35 #include "VISU_PipeLineUtils.hxx"
36
37
38 //----------------------------------------------------------------------------
39 VISU_ColoredPL
40 ::VISU_ColoredPL():
41   myMapperTable(VISU_LookupTable::New()),
42   myBarTable(VISU_LookupTable::New()),
43   myExtractor(VISU_Extractor::New()),
44   myFieldTransform(VISU_FieldTransform::New())
45 {
46   myMapperTable->Delete();
47   myMapperTable->SetScale(VTK_SCALE_LINEAR);
48   myMapperTable->SetHueRange(0.667, 0.0);
49
50   myBarTable->Delete();
51   myBarTable->SetScale(VTK_SCALE_LINEAR);
52   myBarTable->SetHueRange(0.667, 0.0);
53
54   myExtractor->Delete();
55
56   myFieldTransform->Delete();
57 }
58
59
60 //----------------------------------------------------------------------------
61 VISU_ColoredPL
62 ::~VISU_ColoredPL()
63 {}
64
65
66 //----------------------------------------------------------------------------
67 unsigned long int 
68 VISU_ColoredPL
69 ::GetMTime()
70 {
71   unsigned long int aTime = Superclass::GetMTime();
72
73   aTime = std::max(aTime, myMapperTable->GetMTime());
74   aTime = std::max(aTime, myBarTable->GetMTime());
75   aTime = std::max(aTime, myExtractor->GetMTime());
76   aTime = std::max(aTime, myFieldTransform->GetMTime());
77
78   return aTime;
79 }
80
81
82 //----------------------------------------------------------------------------
83 void
84 VISU_ColoredPL
85 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
86                 bool theIsCopyInput)
87 {
88   Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
89
90   if(VISU_ColoredPL *aPipeLine = dynamic_cast<VISU_ColoredPL*>(thePipeLine)){
91     if(theIsCopyInput)
92       SetScalarRange(aPipeLine->GetScalarRange());
93     SetScalarMode(aPipeLine->GetScalarMode());
94     SetNbColors(aPipeLine->GetNbColors());
95     SetScaling(aPipeLine->GetScaling());
96     SetMapScale(aPipeLine->GetMapScale());
97     if(this != thePipeLine){
98       if(aPipeLine->IsExternalGeometryUsed()){
99         ClearGeometry();
100         int aNbOfGeometry = aPipeLine->GetNumberOfGeometry();
101         for(int aGeomNumber = 0; aGeomNumber < aNbOfGeometry; aGeomNumber++)
102           AddGeometry(aPipeLine->GetGeometry(aGeomNumber));
103       }else
104         SetSourceGeometry();
105     }
106   }
107 }
108
109
110 //----------------------------------------------------------------------------
111 int
112 VISU_ColoredPL
113 ::GetScalarMode()
114 {
115   return myExtractor->GetScalarMode();
116 }
117
118
119 //----------------------------------------------------------------------------
120 void
121 VISU_ColoredPL
122 ::SetScalarMode(int theScalarMode,
123                 vtkDataSet *theInput,
124                 VISU_Extractor* theExtractor)
125 {
126   if(theInput){
127     if(VISU::IsDataOnPoints(theInput)){
128       vtkPointData *aPointData = theInput->GetPointData();
129       if(!aPointData->GetAttribute(vtkDataSetAttributes::VECTORS)) {
130         if(theScalarMode == 0){
131           return;
132         }
133       }
134     } else {
135       vtkCellData *aCellData = theInput->GetCellData();
136       if(!aCellData->GetAttribute(vtkDataSetAttributes::VECTORS)){
137         if(theScalarMode == 0){
138           return;
139         }
140       }
141     }
142   }
143
144   theExtractor->SetScalarMode(theScalarMode);
145 }
146
147
148 //----------------------------------------------------------------------------
149 void
150 VISU_ColoredPL
151 ::SetScalarMode(int theScalarMode)
152 {
153   SetScalarMode(theScalarMode, GetInput(), myExtractor);
154 }
155
156
157 //----------------------------------------------------------------------------
158 void
159 VISU_ColoredPL
160 ::SetScalarRange(vtkFloatingPointType theRange[2])
161 {
162   if(theRange[0] > theRange[1]) 
163     return;
164   
165   if(VISU::CheckIsSameRange(GetScalarRange(), theRange))
166     return;
167
168   myFieldTransform->SetScalarRange(theRange);
169   myBarTable->SetRange(theRange);
170 }
171
172 //----------------------------------------------------------------------------
173 vtkFloatingPointType* 
174 VISU_ColoredPL
175 ::GetScalarRange() 
176 {
177   return myFieldTransform->GetScalarRange();
178 }
179
180 //----------------------------------------------------------------------------
181 void
182 VISU_ColoredPL
183 ::SetScaling(int theScaling) 
184 {
185   if(GetScaling() == theScaling)
186     return;
187
188   myBarTable->SetScale(theScaling);
189
190   if(theScaling == VTK_SCALE_LOG10)
191     myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10));
192   else
193     myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Ident));
194 }
195
196 //----------------------------------------------------------------------------
197 int
198 VISU_ColoredPL
199 ::GetScaling() 
200 {
201   return myBarTable->GetScale();
202 }
203
204 //----------------------------------------------------------------------------
205 void
206 VISU_ColoredPL
207 ::SetNbColors(int theNbColors) 
208 {
209   myMapperTable->SetNumberOfColors(theNbColors);
210   myBarTable->SetNumberOfColors(theNbColors);
211 }
212
213 int
214 VISU_ColoredPL
215 ::GetNbColors() 
216 {
217   return myMapperTable->GetNumberOfColors();
218 }
219
220
221 //----------------------------------------------------------------------------
222 void
223 VISU_ColoredPL
224 ::Init()
225 {
226   SetScalarMode(0);
227   SetSourceRange();
228 }
229
230 //----------------------------------------------------------------------------
231 vtkPointSet* 
232 VISU_ColoredPL
233 ::GetClippedInput()
234 {
235   if(GetFieldTransformFilter()->GetInput())
236     GetFieldTransformFilter()->Update();
237   return GetFieldTransformFilter()->GetUnstructuredGridOutput();
238 }
239
240
241 //----------------------------------------------------------------------------
242 void
243 VISU_ColoredPL
244 ::Build() 
245 {
246   myExtractor->SetInput(Superclass::GetClippedInput());
247   myFieldTransform->SetInput(myExtractor->GetOutput());
248
249   GetMapperHolder()->SetLookupTable(GetMapperTable());
250   GetMapper()->SetUseLookupTableScalarRange(true);
251   GetMapper()->SetColorModeToMapScalars();
252   GetMapper()->ScalarVisibilityOn();
253 }
254
255
256 //----------------------------------------------------------------------------
257 void
258 VISU_ColoredPL
259 ::Update() 
260
261   vtkFloatingPointType *aRange = GetScalarRange();
262   vtkFloatingPointType aScalarRange[2] = {aRange[0], aRange[1]};
263   if(myBarTable->GetScale() == VTK_SCALE_LOG10)
264     VISU_LookupTable::ComputeLogRange(aRange, aScalarRange);
265
266   if(!VISU::CheckIsSameRange(myMapperTable->GetRange(), aScalarRange))
267     myMapperTable->SetRange(aScalarRange);
268   
269   myMapperTable->Build();
270   myBarTable->Build();
271
272   Superclass::Update();
273 }
274
275
276 //----------------------------------------------------------------------------
277 unsigned long int
278 VISU_ColoredPL
279 ::GetMemorySize()
280 {
281   unsigned long int aSize = Superclass::GetMemorySize();
282
283   if(vtkDataObject* aDataObject = myExtractor->GetInput())
284     aSize = aDataObject->GetActualMemorySize() * 1024;
285   
286   if(vtkDataObject* aDataObject = myFieldTransform->GetInput())
287     aSize += aDataObject->GetActualMemorySize() * 1024;
288   
289   return aSize;
290 }
291
292
293 //----------------------------------------------------------------------------
294 VISU_LookupTable *
295 VISU_ColoredPL
296 ::GetMapperTable()
297
298   return myMapperTable.GetPointer();
299 }
300
301
302 //----------------------------------------------------------------------------
303 VISU_LookupTable*
304 VISU_ColoredPL
305 ::GetBarTable()
306 {
307   return myBarTable.GetPointer();
308 }
309
310
311 //----------------------------------------------------------------------------
312 VISU_Extractor*
313 VISU_ColoredPL
314 ::GetExtractorFilter()
315 {
316   return myExtractor.GetPointer();
317 }
318
319
320 //----------------------------------------------------------------------------
321 VISU_FieldTransform*
322 VISU_ColoredPL
323 ::GetFieldTransformFilter()
324 {
325   return myFieldTransform.GetPointer();
326 }
327
328
329 //----------------------------------------------------------------------------
330 void 
331 VISU_ColoredPL
332 ::SetMapScale(vtkFloatingPointType theMapScale)
333 {
334   if(!VISU::CheckIsSameValue(myMapperTable->GetMapScale(), theMapScale)){
335     myMapperTable->SetMapScale(theMapScale);
336     myMapperTable->Build();
337   }
338 }
339
340 vtkFloatingPointType
341 VISU_ColoredPL
342 ::GetMapScale()
343 {
344   return myMapperTable->GetMapScale();
345 }
346
347
348 //----------------------------------------------------------------------------
349 void
350 VISU_ColoredPL
351 ::GetSourceRange(vtkFloatingPointType theRange[2])
352 {
353   myExtractor->Update();
354   myExtractor->GetOutput()->GetScalarRange(theRange);
355 }
356
357 void
358 VISU_ColoredPL
359 ::SetSourceRange()
360 {
361   vtkFloatingPointType aRange[2];
362   GetSourceRange(aRange);
363   SetScalarRange(aRange);
364 }