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>
49 //----------------------------------------------------------------------------
50 vtkStandardNewMacro(VISU_DeformedShapeAndScalarMapPL)
52 //----------------------------------------------------------------------------
54 * Constructor. Creating new instances of vtkWarpVector,vtkMergeFilter,vtkUnstructuredGrid
56 * \li myDeformVectors is vtkWarpVector - deformation vectors data
57 * \li myScalarsMergeFilter is vtkMergeFilter - merge filter.
58 * Merge filter which unify the deformation and scalars
59 * \li myScalars is vtk shared pointer to vtkUnstructuredGrid - scalars data
61 VISU_DeformedShapeAndScalarMapPL
62 ::VISU_DeformedShapeAndScalarMapPL():
66 myWarpVector = vtkWarpVector::New();
68 myScalarsMergeFilter = VISU_MergeFilter::New();
69 myScalarsMergeFilter->SetMergingInputs(true);
71 myScalarsExtractor = VISU_Extractor::New();
73 myScalarsFieldTransform = VISU_FieldTransform::New();
75 myCellDataToPointData = vtkCellDataToPointData::New();
76 myScalarsElnoDisassembleFilter = VISU_ElnoDisassembleFilter::New();
78 vtkImplicitBoolean* anImplicitBoolean = vtkImplicitBoolean::New();
79 anImplicitBoolean->SetOperationTypeToIntersection();
81 myExtractGeometry = SALOME_ExtractGeometry::New();
82 myExtractGeometry->SetImplicitFunction(anImplicitBoolean);
85 //----------------------------------------------------------------------------
90 VISU_DeformedShapeAndScalarMapPL
91 ::~VISU_DeformedShapeAndScalarMapPL()
93 myWarpVector->Delete();
95 myScalarsMergeFilter->Delete();
97 myScalarsExtractor->Delete();
99 myScalarsFieldTransform->Delete();
101 myCellDataToPointData->Delete();
104 //----------------------------------------------------------------------------
109 VISU_DeformedShapeAndScalarMapPL
114 SetScale(VISU_DeformedShapePL::GetDefaultScale(this));
117 //----------------------------------------------------------------------------
120 * Building of deformation and puts result to merge filter.
123 VISU_DeformedShapeAndScalarMapPL
130 //----------------------------------------------------------------------------
132 VISU_DeformedShapeAndScalarMapPL
135 GetMapper()->SetColorModeToMapScalars();
136 GetMapper()->ScalarVisibilityOn();
138 VISU::CellDataToPoint(myWarpVector,
139 myCellDataToPointData,
142 myScalars = GetMergedInput();
146 myScalarsFieldTransform->SetInput(myScalarsExtractor->GetOutput());
148 // Sets geometry for merge filter
149 myScalarsMergeFilter->SetGeometry(myWarpVector->GetUnstructuredGridOutput());
151 vtkDataSet* aScalarsDataSet = myScalarsFieldTransform->GetOutput();
152 myScalarsMergeFilter->SetScalars(aScalarsDataSet);
153 myScalarsMergeFilter->AddField("VISU_CELLS_MAPPER", aScalarsDataSet);
154 myScalarsMergeFilter->AddField("VISU_POINTS_MAPPER", aScalarsDataSet);
156 return myScalarsMergeFilter->GetOutput();
160 //----------------------------------------------------------------------------
165 VISU_DeformedShapeAndScalarMapPL
168 Superclass::Update();
170 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myScalarsExtractor.vtk";
171 // VISU::WriteToFile(myScalarsExtractor->GetUnstructuredGridOutput(), aFileName);
174 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myWarpVector.vtk";
175 // VISU::WriteToFile(myWarpVector->GetUnstructuredGridOutput(), aFileName);
178 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myScalarsMergeFilter.vtk";
179 // VISU::WriteToFile(myScalarsMergeFilter->GetUnstructuredGridOutput(), aFileName);
183 //----------------------------------------------------------------------------
185 VISU_DeformedShapeAndScalarMapPL
188 unsigned long int aSize = Superclass::GetMemorySize();
190 if(vtkDataSet* aDataSet = myWarpVector->GetOutput())
191 aSize += aDataSet->GetActualMemorySize() * 1024;
193 if(vtkDataSet* aDataSet = myScalarsExtractor->GetOutput())
194 aSize += aDataSet->GetActualMemorySize() * 1024;
196 if(vtkDataSet* aDataSet = myScalarsMergeFilter->GetOutput())
197 aSize += aDataSet->GetActualMemorySize() * 1024;
199 if(myCellDataToPointData->GetInput())
200 if(vtkDataSet* aDataSet = myCellDataToPointData->GetOutput())
201 aSize += aDataSet->GetActualMemorySize() * 1024;
206 //----------------------------------------------------------------------------
208 * Update scalars method.
209 * Put scalars to merge filter.
212 VISU_DeformedShapeAndScalarMapPL
215 vtkDataSet* aScalars = GetScalars();
216 myScalarsElnoDisassembleFilter->SetInput(aScalars);
217 myExtractGeometry->SetInput(myScalarsElnoDisassembleFilter->GetOutput());
218 myScalarsExtractor->SetInput(myExtractGeometry->GetOutput());
220 if(VISU::IsDataOnCells(myScalarsElnoDisassembleFilter->GetOutput()))
221 GetMapper()->SetScalarModeToUseCellData();
223 GetMapper()->SetScalarModeToUsePointData();
226 //----------------------------------------------------------------------------
228 * Copy information about pipline.
229 * Copy scale and scalars.
232 VISU_DeformedShapeAndScalarMapPL
233 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
236 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
238 if(VISU_DeformedShapeAndScalarMapPL *aPipeLine = dynamic_cast<VISU_DeformedShapeAndScalarMapPL*>(thePipeLine)){
239 SetImplicitFunction(aPipeLine->GetImplicitFunction());
240 SetScale(aPipeLine->GetScale());
241 SetScalars(aPipeLine->GetScalars());
245 //----------------------------------------------------------------------------
248 * Sets vtkDataSet with scalars values to VISU_Extractor filter for scalars extraction.
251 VISU_DeformedShapeAndScalarMapPL
252 ::SetScalars(vtkDataSet *theScalars)
254 if(GetScalars() == theScalars)
257 myScalars = theScalars;
261 //----------------------------------------------------------------------------
263 * Get pointer to input scalars.
266 VISU_DeformedShapeAndScalarMapPL
269 return myScalars.GetPointer();
272 //----------------------------------------------------------------------------
274 * Removes all clipping planes (for myScalars)
277 VISU_DeformedShapeAndScalarMapPL
278 ::RemoveAllClippingPlanes()
280 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
281 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
282 aFunction->RemoveAllItems();
283 aBoolean->Modified();
285 Superclass::RemoveAllClippingPlanes();
288 //----------------------------------------------------------------------------
290 * Removes a clipping plane (for myScalars)
293 VISU_DeformedShapeAndScalarMapPL
294 ::RemoveClippingPlane(vtkIdType theID)
296 if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
297 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
298 if(theID >= 0 && theID < aFunction->GetNumberOfItems())
299 aFunction->RemoveItem(theID);
300 aBoolean->Modified();
302 Superclass::RemoveClippingPlane(theID);
305 //----------------------------------------------------------------------------
307 * Adds a clipping plane (for myScalars)
310 VISU_DeformedShapeAndScalarMapPL
311 ::AddClippingPlane(vtkPlane* thePlane)
314 if (vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()) {
315 vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
316 aFunction->AddItem(thePlane);
318 // Check, that at least one cell present after clipping.
319 // This check was introduced because of bug IPAL8849.
320 vtkDataSet* aClippedDataSet = GetClippedInput();
321 if(aClippedDataSet->GetNumberOfCells() < 1)
325 return Superclass::AddClippingPlane(thePlane);
328 //----------------------------------------------------------------------------
330 * Sets implicit function of clipping
333 VISU_DeformedShapeAndScalarMapPL
334 ::SetImplicitFunction(vtkImplicitFunction *theFunction)
336 myExtractGeometry->SetImplicitFunction(theFunction);
339 //----------------------------------------------------------------------------
341 * Gets implicit function of clipping
343 vtkImplicitFunction *
344 VISU_DeformedShapeAndScalarMapPL
345 ::GetImplicitFunction()
347 return myExtractGeometry->GetImplicitFunction();
350 //----------------------------------------------------------------------------
352 * Sets scale for deformed shape
355 VISU_DeformedShapeAndScalarMapPL
356 ::SetScale(vtkFloatingPointType theScale)
358 if(VISU::CheckIsSameValue(myScaleFactor, theScale))
361 myScaleFactor = theScale;
362 myWarpVector->SetScaleFactor(theScale*myMapScaleFactor);
365 //----------------------------------------------------------------------------
367 * Gets scale of deformed shape.
370 VISU_DeformedShapeAndScalarMapPL
373 return myScaleFactor;
376 //----------------------------------------------------------------------------
378 * Set scale factor of deformation.
381 VISU_DeformedShapeAndScalarMapPL
382 ::SetMapScale(vtkFloatingPointType theMapScale)
384 myMapScaleFactor = theMapScale;
385 Superclass::SetMapScale(theMapScale);
386 myWarpVector->SetScaleFactor(myScaleFactor*theMapScale);
389 //----------------------------------------------------------------------------
394 VISU_DeformedShapeAndScalarMapPL
397 return myScalarsExtractor->GetScalarMode();
400 //----------------------------------------------------------------------------
405 VISU_DeformedShapeAndScalarMapPL
406 ::SetScalarMode(int theScalarMode)
408 VISU_ScalarMapPL::SetScalarMode(theScalarMode, GetScalars(), myScalarsExtractor);
411 //----------------------------------------------------------------------------
413 VISU_DeformedShapeAndScalarMapPL
414 ::SetScaling(int theScaling)
416 if(GetScaling() == theScaling)
419 GetBarTable()->SetScale(theScaling);
421 if(theScaling == VTK_SCALE_LOG10)
422 myScalarsFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10));
424 myScalarsFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Ident));
428 //----------------------------------------------------------------------------
430 VISU_DeformedShapeAndScalarMapPL
431 ::SetScalarRange(vtkFloatingPointType theRange[2])
433 if(VISU::CheckIsSameRange(theRange, GetScalarRange()))
436 myScalarsFieldTransform->SetScalarRange(theRange);
437 GetBarTable()->SetRange(theRange);
441 //----------------------------------------------------------------------------
442 vtkFloatingPointType*
443 VISU_DeformedShapeAndScalarMapPL
446 return myScalarsFieldTransform->GetScalarRange();
450 //----------------------------------------------------------------------------
452 * Gets ranges of extracted scalars
453 * \param theRange[2] - output values
454 * \li theRange[0] - minimum value
455 * \li theRange[1] - maximum value
458 VISU_DeformedShapeAndScalarMapPL
459 ::GetSourceRange(vtkFloatingPointType theRange[2])
461 myScalarsExtractor->Update();
462 myScalarsExtractor->GetUnstructuredGridOutput()->GetScalarRange(theRange);