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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File: VISU_ColoredPL.cxx
25 // Author: Alexey PETROV
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"
35 #include "VISU_PipeLineUtils.hxx"
38 //----------------------------------------------------------------------------
41 myMapperTable(VISU_LookupTable::New()),
42 myBarTable(VISU_LookupTable::New()),
43 myExtractor(VISU_Extractor::New()),
44 myFieldTransform(VISU_FieldTransform::New())
46 myMapperTable->Delete();
47 myMapperTable->SetScale(VTK_SCALE_LINEAR);
48 myMapperTable->SetHueRange(0.667, 0.0);
51 myBarTable->SetScale(VTK_SCALE_LINEAR);
52 myBarTable->SetHueRange(0.667, 0.0);
54 myExtractor->Delete();
56 myFieldTransform->Delete();
60 //----------------------------------------------------------------------------
66 //----------------------------------------------------------------------------
71 unsigned long int aTime = Superclass::GetMTime();
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());
82 //----------------------------------------------------------------------------
85 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
88 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
90 if(VISU_ColoredPL *aPipeLine = dynamic_cast<VISU_ColoredPL*>(thePipeLine)){
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()){
100 int aNbOfGeometry = aPipeLine->GetNumberOfGeometry();
101 for(int aGeomNumber = 0; aGeomNumber < aNbOfGeometry; aGeomNumber++)
102 AddGeometry(aPipeLine->GetGeometry(aGeomNumber));
110 //----------------------------------------------------------------------------
115 return myExtractor->GetScalarMode();
119 //----------------------------------------------------------------------------
122 ::SetScalarMode(int theScalarMode,
123 vtkDataSet *theInput,
124 VISU_Extractor* theExtractor)
127 if(VISU::IsDataOnPoints(theInput)){
128 vtkPointData *aPointData = theInput->GetPointData();
129 if(!aPointData->GetAttribute(vtkDataSetAttributes::VECTORS)) {
130 if(theScalarMode == 0){
135 vtkCellData *aCellData = theInput->GetCellData();
136 if(!aCellData->GetAttribute(vtkDataSetAttributes::VECTORS)){
137 if(theScalarMode == 0){
144 theExtractor->SetScalarMode(theScalarMode);
148 //----------------------------------------------------------------------------
151 ::SetScalarMode(int theScalarMode)
153 SetScalarMode(theScalarMode, GetInput(), myExtractor);
157 //----------------------------------------------------------------------------
160 ::SetScalarRange(vtkFloatingPointType theRange[2])
162 if(theRange[0] > theRange[1])
165 if(VISU::CheckIsSameRange(GetScalarRange(), theRange))
168 myFieldTransform->SetScalarRange(theRange);
169 myBarTable->SetRange(theRange);
172 //----------------------------------------------------------------------------
173 vtkFloatingPointType*
177 return myFieldTransform->GetScalarRange();
180 //----------------------------------------------------------------------------
183 ::SetScaling(int theScaling)
185 if(GetScaling() == theScaling)
188 myBarTable->SetScale(theScaling);
190 if(theScaling == VTK_SCALE_LOG10)
191 myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10));
193 myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Ident));
196 //----------------------------------------------------------------------------
201 return myBarTable->GetScale();
204 //----------------------------------------------------------------------------
207 ::SetNbColors(int theNbColors)
209 myMapperTable->SetNumberOfColors(theNbColors);
210 myBarTable->SetNumberOfColors(theNbColors);
217 return myMapperTable->GetNumberOfColors();
221 //----------------------------------------------------------------------------
230 //----------------------------------------------------------------------------
235 if(GetFieldTransformFilter()->GetInput())
236 GetFieldTransformFilter()->Update();
237 return GetFieldTransformFilter()->GetUnstructuredGridOutput();
241 //----------------------------------------------------------------------------
246 myExtractor->SetInput(Superclass::GetClippedInput());
247 myFieldTransform->SetInput(myExtractor->GetOutput());
249 GetMapperHolder()->SetLookupTable(GetMapperTable());
250 GetMapper()->SetUseLookupTableScalarRange(true);
251 GetMapper()->SetColorModeToMapScalars();
252 GetMapper()->ScalarVisibilityOn();
256 //----------------------------------------------------------------------------
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);
266 if(!VISU::CheckIsSameRange(myMapperTable->GetRange(), aScalarRange))
267 myMapperTable->SetRange(aScalarRange);
269 myMapperTable->Build();
272 Superclass::Update();
276 //----------------------------------------------------------------------------
281 unsigned long int aSize = Superclass::GetMemorySize();
283 if(vtkDataObject* aDataObject = myExtractor->GetInput())
284 aSize = aDataObject->GetActualMemorySize() * 1024;
286 if(vtkDataObject* aDataObject = myFieldTransform->GetInput())
287 aSize += aDataObject->GetActualMemorySize() * 1024;
293 //----------------------------------------------------------------------------
298 return myMapperTable.GetPointer();
302 //----------------------------------------------------------------------------
307 return myBarTable.GetPointer();
311 //----------------------------------------------------------------------------
314 ::GetExtractorFilter()
316 return myExtractor.GetPointer();
320 //----------------------------------------------------------------------------
323 ::GetFieldTransformFilter()
325 return myFieldTransform.GetPointer();
329 //----------------------------------------------------------------------------
332 ::SetMapScale(vtkFloatingPointType theMapScale)
334 if(!VISU::CheckIsSameValue(myMapperTable->GetMapScale(), theMapScale)){
335 myMapperTable->SetMapScale(theMapScale);
336 myMapperTable->Build();
344 return myMapperTable->GetMapScale();
348 //----------------------------------------------------------------------------
351 ::GetSourceRange(vtkFloatingPointType theRange[2])
353 myExtractor->Update();
354 myExtractor->GetOutput()->GetScalarRange(theRange);
361 vtkFloatingPointType aRange[2];
362 GetSourceRange(aRange);
363 SetScalarRange(aRange);