1 // VISU ScalarMapOnDeformedShapePL
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
23 // File: VISU_ScalarMapOnDeformedShapePL.cxx
24 // Author: Eugeny Nikolaev
27 #include "VISU_ScalarMapOnDeformedShapePL.hxx"
28 #include "VISU_DeformedShapePL.hxx"
29 #include "VISU_PipeLineUtils.hxx"
30 #include "VTKViewer_TransformFilter.h"
31 #include "VTKViewer_Transform.h"
33 #include <vtkWarpVector.h>
34 #include <vtkMergeFilter.h>
35 #include <vtkUnstructuredGrid.h>
36 #include <vtkCellDataToPointData.h>
37 #include <vtkPointDataToCellData.h>
39 #include <VISU_Convertor.hxx>
41 vtkStandardNewMacro(VISU_ScalarMapOnDeformedShapePL)
44 * Constructor. Creating new instances of vtkWarpVector,vtkMergeFilter,vtkUnstructuredGrid
46 * \li myDeformVectors is vtkWarpVector - deformation vectors data
47 * \li myMergeFilter is vtkMergeFilter - merge filter.
48 * Merge filter which unify the deformation and scalars
49 * \li myScalars is vtk shared pointer to vtkUnstructuredGrid - scalars data
51 VISU_ScalarMapOnDeformedShapePL
52 ::VISU_ScalarMapOnDeformedShapePL()
54 myDeformVectors = vtkWarpVector::New();
55 myMergeFilter = vtkMergeFilter::New();
56 myExtractorScalars = VISU_Extractor::New();
57 myCellDataToPointData = vtkCellDataToPointData::New();
64 VISU_ScalarMapOnDeformedShapePL
65 ::~VISU_ScalarMapOnDeformedShapePL()
67 myDeformVectors->UnRegisterAllOutputs();
68 myDeformVectors->Delete();
70 myMergeFilter->UnRegisterAllOutputs();
71 myMergeFilter->Delete();
73 myExtractorScalars->UnRegisterAllOutputs();
74 myExtractorScalars->Delete();
76 myCellDataToPointData->UnRegisterAllOutputs();
77 myCellDataToPointData->Delete();
84 VISU_ScalarMapOnDeformedShapePL
87 if (GetScalars() == NULL) SetScalars(GetInput2());
91 vtkFloatingPointType aScalarRange[2];
92 GetSourceRange(aScalarRange);
93 static double EPS = 1.0 / VTK_LARGE_FLOAT;
94 if(aScalarRange[1] > EPS)
95 SetScale(VISU_DeformedShapePL::GetScaleFactor(GetInput2())/aScalarRange[1]);
99 myMapper->SetColorModeToMapScalars();
100 myMapper->ScalarVisibilityOn();
102 // Sets input for field transformation filter
103 myFieldTransform->SetInput(myExtractor->GetOutput());
109 * Building of deformation and puts result to merge filter.
112 VISU_ScalarMapOnDeformedShapePL
115 // Set input for extractor
116 myExtractor->SetInput(GetInput2());
118 VISU::CellDataToPoint(myDeformVectors,myCellDataToPointData,
119 GetInput2(),myFieldTransform);
121 // Sets geometry for merge filter
122 myMergeFilter->SetGeometry(myDeformVectors->GetOutput());
123 // Sets data to mapper
124 myMapper->SetInput(myMergeFilter->GetOutput());
131 VISU_ScalarMapOnDeformedShapePL
134 this->UpdateScalars();
136 vtkFloatingPointType aRange[2];
137 GetSourceRange(aRange);
138 vtkFloatingPointType aScalarRange[2] = {aRange[0], aRange[1]};
140 if(myBarTable->GetScale() == VTK_SCALE_LOG10)
141 VISU_LookupTable::ComputeLogRange(aRange,aScalarRange);
142 myMapperTable->SetRange(aScalarRange);
144 myMapperTable->Build();
147 myMapper->SetLookupTable(myMapperTable);
148 myMapper->SetScalarRange(aScalarRange);
150 VISU_PipeLine::Update();
154 * Update scalars method.
155 * Put scalars to merge filter.
158 VISU_ScalarMapOnDeformedShapePL
161 if(myScalars->GetCellData()->GetVectors() != NULL ||
162 myScalars->GetPointData()->GetVectors() != NULL)
163 myMergeFilter->SetScalars(myExtractorScalars->GetOutput());
165 myMergeFilter->SetScalars(GetScalars());
169 * Copy information about pipline.
170 * Copy scale and scalars.
173 VISU_ScalarMapOnDeformedShapePL
174 ::ShallowCopy(VISU_PipeLine *thePipeLine)
176 VISU_ScalarMapOnDeformedShapePL *aPipeLine = dynamic_cast<VISU_ScalarMapOnDeformedShapePL*>(thePipeLine);
178 SetScale(aPipeLine->GetScale());
179 SetScalars(aPipeLine->GetScalars());
180 vtkFloatingPointType aRange[2];
181 aPipeLine->GetSourceRange(aRange);
182 SetScalarRange(aRange);
184 Superclass::ShallowCopy(thePipeLine);
189 * Sets vtkDataSet with scalars values to VISU_Extractor filter for scalars extraction.
192 VISU_ScalarMapOnDeformedShapePL
193 ::SetScalars(vtkDataSet *theScalars)
195 myScalars = theScalars;
196 vtkUnstructuredGrid* aScalars = GetScalars();
197 myExtractorScalars->SetInput(aScalars);
202 * Get pointer to input scalars.
205 VISU_ScalarMapOnDeformedShapePL
208 return myScalars.GetPointer();
212 * Sets scale for deformed shape
215 VISU_ScalarMapOnDeformedShapePL
216 ::SetScale(vtkFloatingPointType theScale)
218 if(myScaleFactor == theScale) return;
219 myScaleFactor = theScale;
220 myDeformVectors->SetScaleFactor(myScaleFactor);
225 * Gets scale of deformed shape.
228 VISU_ScalarMapOnDeformedShapePL
231 vtkFloatingPointType aScale=myDeformVectors->GetScaleFactor();
236 * Set scale factor of deformation.
239 VISU_ScalarMapOnDeformedShapePL
240 ::SetMapScale(vtkFloatingPointType theMapScale)
242 myDeformVectors->SetScaleFactor(myScaleFactor*theMapScale);
250 VISU_ScalarMapOnDeformedShapePL
253 int aMode=myExtractorScalars->GetScalarMode();
261 VISU_ScalarMapOnDeformedShapePL
262 ::SetScalarMode(int theScalarMode)
264 myExtractorScalars->SetScalarMode(theScalarMode);
269 * Gets ranges of extracted scalars
270 * \param theRange[2] - output values
271 * \li theRange[0] - minimum value
272 * \li theRange[1] - maximum value
275 VISU_ScalarMapOnDeformedShapePL
276 ::GetSourceRange(vtkFloatingPointType theRange[2])
278 myExtractorScalars->Update();
279 myExtractorScalars->GetUnstructuredGridOutput()->GetScalarRange(theRange);