1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // VISU DeformedShapeAndScalarMapPL
23 // File: VISU_DeformedShapeAndScalarMapPL.cxx
24 // Author: Eugeny Nikolaev
27 #include "VISU_DeformedShapeAndScalarMapPL.hxx"
28 #include "VISU_FieldTransform.hxx"
29 #include "VISU_Extractor.hxx"
30 #include "VISU_LookupTable.hxx"
31 #include "VISU_DeformedShapePL.hxx"
32 #include "VTKViewer_TransformFilter.h"
33 #include "VTKViewer_Transform.h"
34 #include "VISU_MergeFilter.hxx"
35 #include "VISU_ElnoDisassembleFilter.hxx"
36 #include "VISU_PipeLineUtils.hxx"
37 #include "SALOME_ExtractGeometry.h"
40 #include <vtkWarpVector.h>
41 #include <vtkImplicitBoolean.h>
42 #include <vtkImplicitFunction.h>
43 #include <vtkUnstructuredGrid.h>
44 #include <vtkCellDataToPointData.h>
45 #include <vtkPointDataToCellData.h>
46 #include <vtkImplicitFunctionCollection.h>
53 //----------------------------------------------------------------------------
54 vtkStandardNewMacro(VISU_DeformedShapeAndScalarMapPL)
56 //----------------------------------------------------------------------------
58 * Constructor. Creating new instances of vtkWarpVector,vtkMergeFilter,vtkUnstructuredGrid
60 * \li myDeformVectors is vtkWarpVector - deformation vectors data
61 * \li myScalarsMergeFilter is vtkMergeFilter - merge filter.
62 * Merge filter which unify the deformation and scalars
63 * \li myScalars is vtk shared pointer to vtkUnstructuredGrid - scalars data
65 VISU_DeformedShapeAndScalarMapPL
66 ::VISU_DeformedShapeAndScalarMapPL():
70 myWarpVector = vtkWarpVector::New();
72 myScalarsMergeFilter = VISU_MergeFilter::New();
73 myScalarsMergeFilter->SetMergingInputs(true);
75 myScalarsExtractor = VISU_Extractor::New();
77 myScalarsFieldTransform = VISU_FieldTransform::New();
79 myCellDataToPointData = vtkCellDataToPointData::New();
80 myScalarsElnoDisassembleFilter = VISU_ElnoDisassembleFilter::New();
82 vtkImplicitBoolean* anImplicitBoolean = vtkImplicitBoolean::New();
83 anImplicitBoolean->SetOperationTypeToIntersection();
85 myExtractGeometry = SALOME_ExtractGeometry::New();
86 myExtractGeometry->SetImplicitFunction(anImplicitBoolean);
89 //----------------------------------------------------------------------------
94 VISU_DeformedShapeAndScalarMapPL
95 ::~VISU_DeformedShapeAndScalarMapPL()
97 myWarpVector->Delete();
99 myScalarsMergeFilter->Delete();
101 myScalarsExtractor->Delete();
103 myScalarsFieldTransform->Delete();
105 myCellDataToPointData->Delete();
108 //----------------------------------------------------------------------------
113 VISU_DeformedShapeAndScalarMapPL
118 SetScale(VISU_DeformedShapePL::GetDefaultScale(this));
121 //----------------------------------------------------------------------------
124 * Building of deformation and puts result to merge filter.
127 VISU_DeformedShapeAndScalarMapPL
134 //----------------------------------------------------------------------------
136 VISU_DeformedShapeAndScalarMapPL
139 GetMapper()->SetColorModeToMapScalars();
140 GetMapper()->ScalarVisibilityOn();
142 VISU::CellDataToPoint(myWarpVector,
143 myCellDataToPointData,
146 myScalars = vtkUnstructuredGrid::SafeDownCast(GetMergedInput());
150 myScalarsFieldTransform->SetInput(myScalarsExtractor->GetOutput());
152 // Sets geometry for merge filter
153 myScalarsMergeFilter->SetGeometry(myWarpVector->GetUnstructuredGridOutput());
155 vtkDataSet* aScalarsDataSet = myScalarsFieldTransform->GetOutput();
156 myScalarsMergeFilter->SetScalars(aScalarsDataSet);
157 myScalarsMergeFilter->AddField("VISU_CELLS_MAPPER", aScalarsDataSet);
158 myScalarsMergeFilter->AddField("VISU_POINTS_MAPPER", aScalarsDataSet);
160 return myScalarsMergeFilter->GetOutput();
164 //----------------------------------------------------------------------------
169 VISU_DeformedShapeAndScalarMapPL
172 Superclass::Update();
174 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myScalarsExtractor.vtk";
175 // VISU::WriteToFile(myScalarsExtractor->GetUnstructuredGridOutput(), aFileName);
178 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myWarpVector.vtk";
179 // VISU::WriteToFile(myWarpVector->GetUnstructuredGridOutput(), aFileName);
182 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myScalarsMergeFilter.vtk";
183 // VISU::WriteToFile(myScalarsMergeFilter->GetUnstructuredGridOutput(), aFileName);
187 //----------------------------------------------------------------------------
189 VISU_DeformedShapeAndScalarMapPL
192 unsigned long int aSize = Superclass::GetMemorySize();
194 if(vtkDataSet* aDataSet = myWarpVector->GetOutput())
195 aSize += aDataSet->GetActualMemorySize() * 1024;
197 if(vtkDataSet* aDataSet = myScalarsExtractor->GetOutput())
198 aSize += aDataSet->GetActualMemorySize() * 1024;
200 if(vtkDataSet* aDataSet = myScalarsMergeFilter->GetOutput())
201 aSize += aDataSet->GetActualMemorySize() * 1024;
203 if(myCellDataToPointData->GetInput())
204 if(vtkDataSet* aDataSet = myCellDataToPointData->GetOutput())
205 aSize += aDataSet->GetActualMemorySize() * 1024;
210 //----------------------------------------------------------------------------
212 * Update scalars method.
213 * Put scalars to merge filter.
216 VISU_DeformedShapeAndScalarMapPL
219 vtkDataSet* aScalars = GetScalars();
220 myScalarsElnoDisassembleFilter->SetInput(aScalars);
221 myExtractGeometry->SetInput(myScalarsElnoDisassembleFilter->GetOutput());
222 myScalarsExtractor->SetInput(myExtractGeometry->GetOutput());
224 if(VISU::IsDataOnCells(myScalarsElnoDisassembleFilter->GetOutput()))
225 GetMapper()->SetScalarModeToUseCellData();
227 GetMapper()->SetScalarModeToUsePointData();
230 //----------------------------------------------------------------------------
232 * Copy information about pipline.
233 * Copy scale and scalars.
236 VISU_DeformedShapeAndScalarMapPL
237 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
240 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
242 if(VISU_DeformedShapeAndScalarMapPL *aPipeLine = dynamic_cast<VISU_DeformedShapeAndScalarMapPL*>(thePipeLine)){
243 SetImplicitFunction(aPipeLine->GetImplicitFunction());
244 SetScale(aPipeLine->GetScale());
245 SetScalars(aPipeLine->GetScalars());
249 //----------------------------------------------------------------------------
252 * Sets vtkDataSet with scalars values to VISU_Extractor filter for scalars extraction.
255 VISU_DeformedShapeAndScalarMapPL
256 ::SetScalars(vtkDataSet *theScalars)
258 if(GetScalars() == theScalars)
261 myScalars = vtkUnstructuredGrid::SafeDownCast(theScalars);
265 //----------------------------------------------------------------------------
267 * Get pointer to input scalars.
270 VISU_DeformedShapeAndScalarMapPL
273 return myScalars.GetPointer();
276 //----------------------------------------------------------------------------
278 * Removes all clipping planes (for myScalars)
281 VISU_DeformedShapeAndScalarMapPL
282 ::RemoveAllClippingPlanes()
284 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
285 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
286 aFunction->RemoveAllItems();
287 aBoolean->Modified();
289 Superclass::RemoveAllClippingPlanes();
292 //----------------------------------------------------------------------------
294 * Removes a clipping plane (for myScalars)
297 VISU_DeformedShapeAndScalarMapPL
298 ::RemoveClippingPlane(vtkIdType theID)
300 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
301 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
302 if(theID >= 0 && theID < aFunction->GetNumberOfItems())
303 aFunction->RemoveItem(theID);
304 aBoolean->Modified();
306 Superclass::RemoveClippingPlane(theID);
309 //----------------------------------------------------------------------------
311 * Adds a clipping plane (for myScalars)
314 VISU_DeformedShapeAndScalarMapPL
315 ::AddClippingPlane(vtkPlane* thePlane)
318 if (vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()) {
319 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
320 aFunction->AddItem(thePlane);
322 // Check, that at least one cell present after clipping.
323 // This check was introduced because of bug IPAL8849.
324 vtkDataSet* aClippedDataSet = GetClippedInput();
325 if(aClippedDataSet->GetNumberOfCells() < 1)
329 return Superclass::AddClippingPlane(thePlane);
332 //----------------------------------------------------------------------------
334 * Sets implicit function of clipping
337 VISU_DeformedShapeAndScalarMapPL
338 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
340 myExtractGeometry->SetImplicitFunction(theFunction);
343 //----------------------------------------------------------------------------
345 * Gets implicit function of clipping
347 vtkImplicitFunction *
348 VISU_DeformedShapeAndScalarMapPL
349 ::GetImplicitFunction()
351 return myExtractGeometry->GetImplicitFunction();
354 //----------------------------------------------------------------------------
356 * Sets scale for deformed shape
359 VISU_DeformedShapeAndScalarMapPL
360 ::SetScale(vtkFloatingPointType theScale)
362 if(VISU::CheckIsSameValue(myScaleFactor, theScale))
365 myScaleFactor = theScale;
366 myWarpVector->SetScaleFactor(theScale*myMapScaleFactor);
369 //----------------------------------------------------------------------------
371 * Gets scale of deformed shape.
374 VISU_DeformedShapeAndScalarMapPL
377 return myScaleFactor;
380 //----------------------------------------------------------------------------
382 * Set scale factor of deformation.
385 VISU_DeformedShapeAndScalarMapPL
386 ::SetMapScale(vtkFloatingPointType theMapScale)
388 myMapScaleFactor = theMapScale;
389 Superclass::SetMapScale(theMapScale);
390 myWarpVector->SetScaleFactor(myScaleFactor*theMapScale);
393 //----------------------------------------------------------------------------
398 VISU_DeformedShapeAndScalarMapPL
401 return myScalarsExtractor->GetScalarMode();
404 //----------------------------------------------------------------------------
409 VISU_DeformedShapeAndScalarMapPL
410 ::SetScalarMode(int theScalarMode)
412 VISU_ScalarMapPL::SetScalarMode(theScalarMode, GetScalars(), myScalarsExtractor);
415 //----------------------------------------------------------------------------
417 VISU_DeformedShapeAndScalarMapPL
418 ::SetScaling(int theScaling)
420 if(GetScaling() == theScaling)
423 GetBarTable()->SetScale(theScaling);
425 if(theScaling == VTK_SCALE_LOG10)
426 myScalarsFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10));
428 myScalarsFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Ident));
432 //----------------------------------------------------------------------------
434 VISU_DeformedShapeAndScalarMapPL
435 ::SetScalarRange(vtkFloatingPointType theRange[2])
437 if (isnan(theRange[0]) || isnan(theRange[1]))
438 throw std::runtime_error("NAN values in the presentation");
440 if(VISU::CheckIsSameRange(theRange, GetScalarRange()))
443 myScalarsFieldTransform->SetScalarRange(theRange);
444 GetBarTable()->SetRange(theRange);
448 //----------------------------------------------------------------------------
449 vtkFloatingPointType*
450 VISU_DeformedShapeAndScalarMapPL
453 return myScalarsFieldTransform->GetScalarRange();
457 //----------------------------------------------------------------------------
459 * Gets ranges of extracted scalars
460 * \param theRange[2] - output values
461 * \li theRange[0] - minimum value
462 * \li theRange[1] - maximum value
465 VISU_DeformedShapeAndScalarMapPL
466 ::GetSourceRange(vtkFloatingPointType theRange[2])
468 myScalarsExtractor->Update();
469 myScalarsExtractor->GetUnstructuredGridOutput()->GetScalarRange(theRange);
471 if (isnan(theRange[0]) || isnan(theRange[1]))
472 throw std::runtime_error("NAN values in the presentation");
476 //----------------------------------------------------------------------------
478 VISU_DeformedShapeAndScalarMapPL
479 ::SetGaussMetric(VISU::TGaussMetric theGaussMetric)
481 if(GetGaussMetric() == theGaussMetric)
484 myScalarsExtractor->SetGaussMetric(theGaussMetric);
488 //----------------------------------------------------------------------------
490 VISU_DeformedShapeAndScalarMapPL
493 return myScalarsExtractor->GetGaussMetric();