1 // Copyright (C) 2007-2010 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 <vtkCellDataToPointData.h>
43 #include <vtkPointDataToCellData.h>
44 #include <vtkImplicitFunctionCollection.h>
51 //----------------------------------------------------------------------------
52 vtkStandardNewMacro(VISU_DeformedShapeAndScalarMapPL)
54 //----------------------------------------------------------------------------
56 * Constructor. Creating new instances of vtkWarpVector,vtkMergeFilter,vtkUnstructuredGrid
58 * \li myDeformVectors is vtkWarpVector - deformation vectors data
59 * \li myScalarsMergeFilter is vtkMergeFilter - merge filter.
60 * Merge filter which unify the deformation and scalars
61 * \li myScalars is vtk shared pointer to vtkUnstructuredGrid - scalars data
63 VISU_DeformedShapeAndScalarMapPL
64 ::VISU_DeformedShapeAndScalarMapPL():
68 myWarpVector = vtkWarpVector::New();
70 myScalarsMergeFilter = VISU_MergeFilter::New();
71 myScalarsMergeFilter->SetMergingInputs(true);
73 myScalarsExtractor = VISU_Extractor::New();
75 myScalarsFieldTransform = VISU_FieldTransform::New();
77 myCellDataToPointData = vtkCellDataToPointData::New();
78 myScalarsElnoDisassembleFilter = VISU_ElnoDisassembleFilter::New();
80 vtkImplicitBoolean* anImplicitBoolean = vtkImplicitBoolean::New();
81 anImplicitBoolean->SetOperationTypeToIntersection();
83 myExtractGeometry = SALOME_ExtractGeometry::New();
84 myExtractGeometry->SetImplicitFunction(anImplicitBoolean);
87 //----------------------------------------------------------------------------
92 VISU_DeformedShapeAndScalarMapPL
93 ::~VISU_DeformedShapeAndScalarMapPL()
95 myWarpVector->Delete();
97 myScalarsMergeFilter->Delete();
99 myScalarsExtractor->Delete();
101 myScalarsFieldTransform->Delete();
103 myCellDataToPointData->Delete();
106 //----------------------------------------------------------------------------
111 VISU_DeformedShapeAndScalarMapPL
116 SetScale(VISU_DeformedShapePL::GetDefaultScale(this));
119 //----------------------------------------------------------------------------
122 * Building of deformation and puts result to merge filter.
125 VISU_DeformedShapeAndScalarMapPL
132 //----------------------------------------------------------------------------
134 VISU_DeformedShapeAndScalarMapPL
137 GetMapper()->SetColorModeToMapScalars();
138 GetMapper()->ScalarVisibilityOn();
140 VISU::CellDataToPoint(myWarpVector,
141 myCellDataToPointData,
144 myScalars = vtkUnstructuredGrid::SafeDownCast(GetMergedInput());
148 myScalarsFieldTransform->SetInput(myScalarsExtractor->GetOutput());
150 // Sets geometry for merge filter
151 myScalarsMergeFilter->SetGeometry(myWarpVector->GetUnstructuredGridOutput());
153 vtkDataSet* aScalarsDataSet = myScalarsFieldTransform->GetOutput();
154 myScalarsMergeFilter->SetScalars(aScalarsDataSet);
155 myScalarsMergeFilter->AddField("VISU_CELLS_MAPPER", aScalarsDataSet);
156 myScalarsMergeFilter->AddField("VISU_POINTS_MAPPER", aScalarsDataSet);
158 return myScalarsMergeFilter->GetOutput();
162 //----------------------------------------------------------------------------
167 VISU_DeformedShapeAndScalarMapPL
170 Superclass::Update();
172 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myScalarsExtractor.vtk";
173 // VISU::WriteToFile(myScalarsExtractor->GetUnstructuredGridOutput(), aFileName);
176 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myWarpVector.vtk";
177 // VISU::WriteToFile(myWarpVector->GetUnstructuredGridOutput(), aFileName);
180 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myScalarsMergeFilter.vtk";
181 // VISU::WriteToFile(myScalarsMergeFilter->GetUnstructuredGridOutput(), aFileName);
185 //----------------------------------------------------------------------------
187 VISU_DeformedShapeAndScalarMapPL
190 unsigned long int aSize = Superclass::GetMemorySize();
192 if(vtkDataSet* aDataSet = myWarpVector->GetOutput())
193 aSize += aDataSet->GetActualMemorySize() * 1024;
195 if(vtkDataSet* aDataSet = myScalarsExtractor->GetOutput())
196 aSize += aDataSet->GetActualMemorySize() * 1024;
198 if(vtkDataSet* aDataSet = myScalarsMergeFilter->GetOutput())
199 aSize += aDataSet->GetActualMemorySize() * 1024;
201 if(myCellDataToPointData->GetInput())
202 if(vtkDataSet* aDataSet = myCellDataToPointData->GetOutput())
203 aSize += aDataSet->GetActualMemorySize() * 1024;
208 //----------------------------------------------------------------------------
210 * Update scalars method.
211 * Put scalars to merge filter.
214 VISU_DeformedShapeAndScalarMapPL
217 vtkDataSet* aScalars = GetScalars();
218 myScalarsElnoDisassembleFilter->SetInput(aScalars);
219 myExtractGeometry->SetInput(myScalarsElnoDisassembleFilter->GetOutput());
220 myScalarsExtractor->SetInput(myExtractGeometry->GetOutput());
222 if(VISU::IsDataOnCells(myScalarsElnoDisassembleFilter->GetOutput()))
223 GetMapper()->SetScalarModeToUseCellData();
225 GetMapper()->SetScalarModeToUsePointData();
228 //----------------------------------------------------------------------------
230 * Copy information about pipline.
231 * Copy scale and scalars.
234 VISU_DeformedShapeAndScalarMapPL
235 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
238 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
240 if(VISU_DeformedShapeAndScalarMapPL *aPipeLine = dynamic_cast<VISU_DeformedShapeAndScalarMapPL*>(thePipeLine)){
241 SetImplicitFunction(aPipeLine->GetImplicitFunction());
242 SetScale(aPipeLine->GetScale());
243 SetScalars(aPipeLine->GetScalars());
247 //----------------------------------------------------------------------------
250 * Sets vtkDataSet with scalars values to VISU_Extractor filter for scalars extraction.
253 VISU_DeformedShapeAndScalarMapPL
254 ::SetScalars(vtkDataSet *theScalars)
256 if(GetScalars() == theScalars)
259 myScalars = vtkUnstructuredGrid::SafeDownCast(theScalars);
263 //----------------------------------------------------------------------------
265 * Get pointer to input scalars.
268 VISU_DeformedShapeAndScalarMapPL
271 return myScalars.GetPointer();
274 //----------------------------------------------------------------------------
276 * Removes all clipping planes (for myScalars)
279 VISU_DeformedShapeAndScalarMapPL
280 ::RemoveAllClippingPlanes()
282 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
283 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
284 aFunction->RemoveAllItems();
285 aBoolean->Modified();
287 Superclass::RemoveAllClippingPlanes();
290 //----------------------------------------------------------------------------
292 * Removes a clipping plane (for myScalars)
295 VISU_DeformedShapeAndScalarMapPL
296 ::RemoveClippingPlane(vtkIdType theID)
298 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
299 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
300 if(theID >= 0 && theID < aFunction->GetNumberOfItems())
301 aFunction->RemoveItem(theID);
302 aBoolean->Modified();
304 Superclass::RemoveClippingPlane(theID);
307 //----------------------------------------------------------------------------
309 * Adds a clipping plane (for myScalars)
312 VISU_DeformedShapeAndScalarMapPL
313 ::AddClippingPlane(vtkPlane* thePlane)
316 if (vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()) {
317 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
318 aFunction->AddItem(thePlane);
320 // Check, that at least one cell present after clipping.
321 // This check was introduced because of bug IPAL8849.
322 vtkDataSet* aClippedDataSet = GetClippedInput();
323 if(aClippedDataSet->GetNumberOfCells() < 1)
327 return Superclass::AddClippingPlane(thePlane);
330 //----------------------------------------------------------------------------
332 * Sets implicit function of clipping
335 VISU_DeformedShapeAndScalarMapPL
336 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
338 myExtractGeometry->SetImplicitFunction(theFunction);
341 //----------------------------------------------------------------------------
343 * Gets implicit function of clipping
345 vtkImplicitFunction *
346 VISU_DeformedShapeAndScalarMapPL
347 ::GetImplicitFunction()
349 return myExtractGeometry->GetImplicitFunction();
352 //----------------------------------------------------------------------------
354 * Sets scale for deformed shape
357 VISU_DeformedShapeAndScalarMapPL
358 ::SetScale(vtkFloatingPointType theScale)
360 if(VISU::CheckIsSameValue(myScaleFactor, theScale))
363 myScaleFactor = theScale;
364 myWarpVector->SetScaleFactor(theScale*myMapScaleFactor);
367 //----------------------------------------------------------------------------
369 * Gets scale of deformed shape.
372 VISU_DeformedShapeAndScalarMapPL
375 return myScaleFactor;
378 //----------------------------------------------------------------------------
380 * Set scale factor of deformation.
383 VISU_DeformedShapeAndScalarMapPL
384 ::SetMapScale(vtkFloatingPointType theMapScale)
386 myMapScaleFactor = theMapScale;
387 Superclass::SetMapScale(theMapScale);
388 myWarpVector->SetScaleFactor(myScaleFactor*theMapScale);
391 //----------------------------------------------------------------------------
396 VISU_DeformedShapeAndScalarMapPL
399 return myScalarsExtractor->GetScalarMode();
402 //----------------------------------------------------------------------------
407 VISU_DeformedShapeAndScalarMapPL
408 ::SetScalarMode(int theScalarMode)
410 VISU_ScalarMapPL::SetScalarMode(theScalarMode, GetScalars(), myScalarsExtractor);
413 //----------------------------------------------------------------------------
415 VISU_DeformedShapeAndScalarMapPL
416 ::SetScaling(int theScaling)
418 if(GetScaling() == theScaling)
421 GetBarTable()->SetScale(theScaling);
423 if(theScaling == VTK_SCALE_LOG10)
424 myScalarsFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10));
426 myScalarsFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Ident));
430 //----------------------------------------------------------------------------
432 VISU_DeformedShapeAndScalarMapPL
433 ::SetScalarRange(vtkFloatingPointType theRange[2])
435 if (isnan(theRange[0]) || isnan(theRange[1]))
436 throw std::runtime_error("NAN values in the presentation");
438 if(VISU::CheckIsSameRange(theRange, GetScalarRange()))
441 myScalarsFieldTransform->SetScalarRange(theRange);
442 GetBarTable()->SetRange(theRange);
446 //----------------------------------------------------------------------------
447 vtkFloatingPointType*
448 VISU_DeformedShapeAndScalarMapPL
451 return myScalarsFieldTransform->GetScalarRange();
455 //----------------------------------------------------------------------------
457 * Gets ranges of extracted scalars
458 * \param theRange[2] - output values
459 * \li theRange[0] - minimum value
460 * \li theRange[1] - maximum value
463 VISU_DeformedShapeAndScalarMapPL
464 ::GetSourceRange(vtkFloatingPointType theRange[2])
466 myScalarsExtractor->Update();
467 myScalarsExtractor->GetUnstructuredGridOutput()->GetScalarRange(theRange);
469 if (isnan(theRange[0]) || isnan(theRange[1]))
470 throw std::runtime_error("NAN values in the presentation");
474 //----------------------------------------------------------------------------
476 VISU_DeformedShapeAndScalarMapPL
477 ::SetGaussMetric(VISU::TGaussMetric theGaussMetric)
479 if(GetGaussMetric() == theGaussMetric)
482 myScalarsExtractor->SetGaussMetric(theGaussMetric);
486 //----------------------------------------------------------------------------
488 VISU_DeformedShapeAndScalarMapPL
491 return myScalarsExtractor->GetGaussMetric();