1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // VISU DeformedShapeAndScalarMapPL
21 // File: VISU_DeformedShapeAndScalarMapPL.cxx
22 // Author: Eugeny Nikolaev
25 #include "VISU_DeformedShapeAndScalarMapPL.hxx"
26 #include "VISU_FieldTransform.hxx"
27 #include "VISU_Extractor.hxx"
28 #include "VISU_LookupTable.hxx"
29 #include "VISU_DeformedShapePL.hxx"
30 #include "VTKViewer_TransformFilter.h"
31 #include "VTKViewer_Transform.h"
32 #include "VISU_MergeFilter.hxx"
33 #include "VISU_ElnoDisassembleFilter.hxx"
34 #include "VISU_PipeLineUtils.hxx"
35 #include "SALOME_ExtractGeometry.h"
38 #include <vtkWarpVector.h>
39 #include <vtkImplicitBoolean.h>
40 #include <vtkImplicitFunction.h>
41 #include <vtkUnstructuredGrid.h>
42 #include <vtkPointDataToCellData.h>
43 #include <vtkImplicitFunctionCollection.h>
50 //----------------------------------------------------------------------------
51 vtkStandardNewMacro(VISU_DeformedShapeAndScalarMapPL)
53 //----------------------------------------------------------------------------
55 * Constructor. Creating new instances of vtkWarpVector,vtkMergeFilter,vtkUnstructuredGrid
57 * \li myDeformVectors is vtkWarpVector - deformation vectors data
58 * \li myScalarsMergeFilter is vtkMergeFilter - merge filter.
59 * Merge filter which unify the deformation and scalars
60 * \li myScalars is vtk shared pointer to vtkUnstructuredGrid - scalars data
62 VISU_DeformedShapeAndScalarMapPL
63 ::VISU_DeformedShapeAndScalarMapPL():
67 myWarpVector = vtkWarpVector::New();
69 myScalarsMergeFilter = VISU_MergeFilter::New();
70 myScalarsMergeFilter->SetMergingInputs(true);
72 myScalarsExtractor = VISU_Extractor::New();
74 myScalarsFieldTransform = VISU_FieldTransform::New();
76 myCellDataToPointData = VISU_CellDataToPointData::New();
77 myScalarsElnoDisassembleFilter = VISU_ElnoDisassembleFilter::New();
79 vtkImplicitBoolean* anImplicitBoolean = vtkImplicitBoolean::New();
80 anImplicitBoolean->SetOperationTypeToIntersection();
82 myExtractGeometry = SALOME_ExtractGeometry::New();
83 myExtractGeometry->SetImplicitFunction(anImplicitBoolean);
86 //----------------------------------------------------------------------------
91 VISU_DeformedShapeAndScalarMapPL
92 ::~VISU_DeformedShapeAndScalarMapPL()
94 myWarpVector->Delete();
96 myScalarsMergeFilter->Delete();
98 myScalarsExtractor->Delete();
100 myScalarsFieldTransform->Delete();
102 myCellDataToPointData->Delete();
105 //----------------------------------------------------------------------------
110 VISU_DeformedShapeAndScalarMapPL
115 SetScale(VISU_DeformedShapePL::GetDefaultScale(this));
118 //----------------------------------------------------------------------------
121 * Building of deformation and puts result to merge filter.
124 VISU_DeformedShapeAndScalarMapPL
131 //----------------------------------------------------------------------------
133 VISU_DeformedShapeAndScalarMapPL
136 GetMapper()->SetColorModeToMapScalars();
137 GetMapper()->ScalarVisibilityOn();
139 VISU::CellDataToPoint(myWarpVector,
140 myCellDataToPointData,
143 myScalars = vtkUnstructuredGrid::SafeDownCast(GetMergedInput());
147 myScalarsFieldTransform->SetInput(myScalarsExtractor->GetOutput());
149 // Sets geometry for merge filter
150 myScalarsMergeFilter->SetGeometry(myWarpVector->GetUnstructuredGridOutput());
152 vtkDataSet* aScalarsDataSet = myScalarsFieldTransform->GetOutput();
153 myScalarsMergeFilter->SetScalars(aScalarsDataSet);
154 myScalarsMergeFilter->AddField("VISU_CELLS_MAPPER", aScalarsDataSet);
155 myScalarsMergeFilter->AddField("VISU_POINTS_MAPPER", aScalarsDataSet);
157 return myScalarsMergeFilter->GetOutput();
161 //----------------------------------------------------------------------------
166 VISU_DeformedShapeAndScalarMapPL
169 Superclass::Update();
171 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myScalarsExtractor.vtk";
172 // VISU::WriteToFile(myScalarsExtractor->GetUnstructuredGridOutput(), aFileName);
175 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myWarpVector.vtk";
176 // VISU::WriteToFile(myWarpVector->GetUnstructuredGridOutput(), aFileName);
179 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myScalarsMergeFilter.vtk";
180 // VISU::WriteToFile(myScalarsMergeFilter->GetUnstructuredGridOutput(), aFileName);
184 //----------------------------------------------------------------------------
186 VISU_DeformedShapeAndScalarMapPL
189 unsigned long int aSize = Superclass::GetMemorySize();
191 if(vtkDataSet* aDataSet = myWarpVector->GetOutput())
192 aSize += aDataSet->GetActualMemorySize() * 1024;
194 if(vtkDataSet* aDataSet = myScalarsExtractor->GetOutput())
195 aSize += aDataSet->GetActualMemorySize() * 1024;
197 if(vtkDataSet* aDataSet = myScalarsMergeFilter->GetOutput())
198 aSize += aDataSet->GetActualMemorySize() * 1024;
200 if(myCellDataToPointData->GetInput())
201 if(vtkDataSet* aDataSet = myCellDataToPointData->GetOutput())
202 aSize += aDataSet->GetActualMemorySize() * 1024;
207 //----------------------------------------------------------------------------
209 * Update scalars method.
210 * Put scalars to merge filter.
213 VISU_DeformedShapeAndScalarMapPL
216 vtkDataSet* aScalars = GetScalars();
217 myScalarsElnoDisassembleFilter->SetInput(aScalars);
218 myExtractGeometry->SetInput(myScalarsElnoDisassembleFilter->GetOutput());
219 myScalarsExtractor->SetInput(myExtractGeometry->GetOutput());
221 if(VISU::IsDataOnCells(myScalarsElnoDisassembleFilter->GetOutput()))
222 GetMapper()->SetScalarModeToUseCellData();
224 GetMapper()->SetScalarModeToUsePointData();
227 //----------------------------------------------------------------------------
229 * Copy information about pipline.
230 * Copy scale and scalars.
233 VISU_DeformedShapeAndScalarMapPL
234 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
237 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
239 if(VISU_DeformedShapeAndScalarMapPL *aPipeLine = dynamic_cast<VISU_DeformedShapeAndScalarMapPL*>(thePipeLine)){
240 SetImplicitFunction(aPipeLine->GetImplicitFunction());
241 SetScale(aPipeLine->GetScale());
242 SetScalars(aPipeLine->GetScalars());
246 //----------------------------------------------------------------------------
249 * Sets vtkDataSet with scalars values to VISU_Extractor filter for scalars extraction.
252 VISU_DeformedShapeAndScalarMapPL
253 ::SetScalars(vtkDataSet *theScalars)
255 if(GetScalars() == theScalars)
258 myScalars = vtkUnstructuredGrid::SafeDownCast(theScalars);
262 //----------------------------------------------------------------------------
264 * Get pointer to input scalars.
267 VISU_DeformedShapeAndScalarMapPL
270 return myScalars.GetPointer();
273 //----------------------------------------------------------------------------
275 * Removes all clipping planes (for myScalars)
278 VISU_DeformedShapeAndScalarMapPL
279 ::RemoveAllClippingPlanes()
281 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
282 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
283 aFunction->RemoveAllItems();
284 aBoolean->Modified();
286 Superclass::RemoveAllClippingPlanes();
289 //----------------------------------------------------------------------------
291 * Removes a clipping plane (for myScalars)
294 VISU_DeformedShapeAndScalarMapPL
295 ::RemoveClippingPlane(vtkIdType theID)
297 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
298 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
299 if(theID >= 0 && theID < aFunction->GetNumberOfItems())
300 aFunction->RemoveItem(theID);
301 aBoolean->Modified();
303 Superclass::RemoveClippingPlane(theID);
306 //----------------------------------------------------------------------------
308 * Adds a clipping plane (for myScalars)
311 VISU_DeformedShapeAndScalarMapPL
312 ::AddClippingPlane(vtkPlane* thePlane)
315 if (vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()) {
316 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
317 aFunction->AddItem(thePlane);
319 // Check, that at least one cell present after clipping.
320 // This check was introduced because of bug IPAL8849.
321 vtkDataSet* aClippedDataSet = GetClippedInput();
322 if(aClippedDataSet->GetNumberOfCells() < 1)
326 return Superclass::AddClippingPlane(thePlane);
329 //----------------------------------------------------------------------------
331 * Sets implicit function of clipping
334 VISU_DeformedShapeAndScalarMapPL
335 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
337 myExtractGeometry->SetImplicitFunction(theFunction);
340 //----------------------------------------------------------------------------
342 * Gets implicit function of clipping
344 vtkImplicitFunction *
345 VISU_DeformedShapeAndScalarMapPL
346 ::GetImplicitFunction()
348 return myExtractGeometry->GetImplicitFunction();
351 //----------------------------------------------------------------------------
353 * Sets scale for deformed shape
356 VISU_DeformedShapeAndScalarMapPL
357 ::SetScale(vtkFloatingPointType theScale)
359 if(VISU::CheckIsSameValue(myScaleFactor, theScale))
362 myScaleFactor = theScale;
363 myWarpVector->SetScaleFactor(theScale*myMapScaleFactor);
366 //----------------------------------------------------------------------------
368 * Gets scale of deformed shape.
371 VISU_DeformedShapeAndScalarMapPL
374 return myScaleFactor;
377 //----------------------------------------------------------------------------
379 * Set scale factor of deformation.
382 VISU_DeformedShapeAndScalarMapPL
383 ::SetMapScale(vtkFloatingPointType theMapScale)
385 myMapScaleFactor = theMapScale;
386 Superclass::SetMapScale(theMapScale);
387 myWarpVector->SetScaleFactor(myScaleFactor*theMapScale);
390 //----------------------------------------------------------------------------
395 VISU_DeformedShapeAndScalarMapPL
398 return myScalarsExtractor->GetScalarMode();
401 //----------------------------------------------------------------------------
406 VISU_DeformedShapeAndScalarMapPL
407 ::SetScalarMode(int theScalarMode)
409 VISU_ScalarMapPL::SetScalarMode(theScalarMode, GetScalars(), myScalarsExtractor);
412 //----------------------------------------------------------------------------
414 VISU_DeformedShapeAndScalarMapPL
415 ::SetScaling(int theScaling)
417 if(GetScaling() == theScaling)
420 GetBarTable()->SetScale(theScaling);
422 if(theScaling == VTK_SCALE_LOG10)
423 myScalarsFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10));
425 myScalarsFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Ident));
429 //----------------------------------------------------------------------------
431 VISU_DeformedShapeAndScalarMapPL
432 ::SetScalarRange(vtkFloatingPointType theRange[2])
434 if (isnan(theRange[0]) || isnan(theRange[1]))
435 throw std::runtime_error("NAN values in the presentation");
437 if(VISU::CheckIsSameRange(theRange, GetScalarRange()))
440 myScalarsFieldTransform->SetScalarRange(theRange);
441 GetBarTable()->SetRange(theRange);
445 //----------------------------------------------------------------------------
446 vtkFloatingPointType*
447 VISU_DeformedShapeAndScalarMapPL
450 return myScalarsFieldTransform->GetScalarRange();
454 //----------------------------------------------------------------------------
456 * Gets ranges of extracted scalars
457 * \param theRange[2] - output values
458 * \li theRange[0] - minimum value
459 * \li theRange[1] - maximum value
462 VISU_DeformedShapeAndScalarMapPL
463 ::GetSourceRange(vtkFloatingPointType theRange[2])
465 myScalarsExtractor->Update();
466 myScalarsExtractor->GetUnstructuredGridOutput()->GetScalarRange(theRange);
468 if (isnan(theRange[0]) || isnan(theRange[1]))
469 throw std::runtime_error("NAN values in the presentation");
473 //----------------------------------------------------------------------------
475 VISU_DeformedShapeAndScalarMapPL
476 ::SetGaussMetric(VISU::TGaussMetric theGaussMetric)
478 if(GetGaussMetric() == theGaussMetric)
481 myScalarsExtractor->SetGaussMetric(theGaussMetric);
485 //----------------------------------------------------------------------------
487 VISU_DeformedShapeAndScalarMapPL
490 return myScalarsExtractor->GetGaussMetric();