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 // File: VISU_ScalarMapPL.cxx
21 // Author: Roman NIKOLAEV
25 #include "VISU_DeformationPL.hxx"
26 #include "VISU_MergeFilter.hxx"
27 #include "VISU_DeformedShapePL.hxx"
28 #include "VISU_PipeLineUtils.hxx"
31 #include <vtkDataSet.h>
32 #include <vtkPassThroughFilter.h>
33 #include <vtkWarpVector.h>
34 #include <vtkUnstructuredGrid.h>
36 static int MYDEBUG = 0;
38 static int MYDEBUG = 0;
42 //----------------------------------------------------------------------------
43 VISU_DeformationPL::VISU_DeformationPL():
47 if(MYDEBUG) MESSAGE("VISU_DeformationPL()::VISU_DeformationPL() - "<<this);
48 myWarpVector = vtkWarpVector::New();
49 myWarpVector->SetScaleFactor(myScaleFactor);
51 myVectorMergeFilter = VISU_MergeFilter::New();
52 myVectorMergeFilter->SetMergingInputs(true);
53 myInputPassFilter = vtkPassThroughFilter::New();
54 myOutputPassFiler = vtkPassThroughFilter::New();
55 myCellDataToPointData = VISU_CellDataToPointData::New();
56 myCellDataToPointData->PassCellDataOn();
58 myInputPassFilter->SetInput(vtkUnstructuredGrid::New());
60 myCellDataToPointData->SetInput(myInputPassFilter->GetOutput());
62 myWarpVector->SetInput(myCellDataToPointData->GetOutput());
64 myOutputPassFiler->SetInput(myWarpVector->GetOutput());
67 //----------------------------------------------------------------------------
68 VISU_DeformationPL::~VISU_DeformationPL()
70 if(MYDEBUG) MESSAGE("VISU_DeformationPL()::~VISU_DeformationPL() - "<<this);
71 myWarpVector->Delete();
72 myVectorMergeFilter->Delete();
73 myInputPassFilter->Delete();
74 myOutputPassFiler->Delete();
75 myCellDataToPointData->Delete();
79 //----------------------------------------------------------------------------
81 VISU_DeformationPL::GetMTime(){
82 unsigned long int aTime = std::max(myWarpVector->GetMTime(),
83 myVectorMergeFilter->GetMTime());
85 aTime = std::max(aTime,myInputPassFilter->GetMTime());
86 aTime = std::max(aTime,myOutputPassFiler->GetMTime());
87 aTime = std::max(aTime,myCellDataToPointData->GetMTime());
91 //----------------------------------------------------------------------------
92 void VISU_DeformationPL::SetScale(vtkFloatingPointType theScaleFactor)
94 if(myScaleFactor == theScaleFactor)
96 myScaleFactor = theScaleFactor;
97 myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
100 void VISU_DeformationPL::SetMapScale(vtkFloatingPointType theMapScaleFactor)
102 if(myMapScaleFactor == theMapScaleFactor)
104 myMapScaleFactor = theMapScaleFactor;
106 myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
110 vtkFloatingPointType VISU_DeformationPL::GetScale()
112 return myScaleFactor;
115 //----------------------------------------------------------------------------
116 void VISU_DeformationPL::SetWarpVectorInput(vtkDataSet *theInput)
118 myInputPassFilter->SetInput(theInput);
121 //----------------------------------------------------------------------------
122 vtkDataSet* VISU_DeformationPL::GetWarpVectorOutput()
124 return myOutputPassFiler->GetOutput();
127 //----------------------------------------------------------------------------
128 void VISU_DeformationPL::SetMergeFilterInput(vtkDataSet* ScalarInput,
129 vtkDataSet* VectorialInput)
131 myVectorMergeFilter->SetScalars(ScalarInput);
132 myVectorMergeFilter->AddField("VISU_CELLS_MAPPER",ScalarInput);
133 myVectorMergeFilter->AddField("VISU_POINTS_MAPPER",ScalarInput);
135 myVectorMergeFilter->SetGeometry(VectorialInput);
136 myVectorMergeFilter->SetVectors(VectorialInput);
139 //----------------------------------------------------------------------------
140 vtkDataSet* VISU_DeformationPL::GetMergeFilterOutput(){
141 return myVectorMergeFilter->GetOutput();
144 //----------------------------------------------------------------------------
145 vtkFloatingPointType VISU_DeformationPL::GetDefaultScaleFactor(VISU_DeformationPL *thePipeLine)
147 if(!thePipeLine || !thePipeLine->GetMergeFilterOutput())
150 vtkFloatingPointType aSourceRange[2];
151 thePipeLine->GetMergeFilterOutput()->GetScalarRange(aSourceRange);
153 static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT;
154 if(fabs(aSourceRange[1]) > EPS){
155 vtkDataSet* aDataSet = thePipeLine->GetMergeFilterOutput();
156 vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor(aDataSet);
157 return aScaleFactor / aSourceRange[1];