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 // 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 <vtkCellDataToPointData.h>
35 #include <vtkUnstructuredGrid.h>
37 static int MYDEBUG = 0;
39 static int MYDEBUG = 0;
43 //----------------------------------------------------------------------------
44 VISU_DeformationPL::VISU_DeformationPL():
48 if(MYDEBUG) MESSAGE("VISU_DeformationPL()::VISU_DeformationPL() - "<<this);
49 myWarpVector = vtkWarpVector::New();
50 myWarpVector->SetScaleFactor(myScaleFactor);
52 myVectorMergeFilter = VISU_MergeFilter::New();
53 myVectorMergeFilter->SetMergingInputs(true);
54 myInputPassFilter = vtkPassThroughFilter::New();
55 myOutputPassFiler = vtkPassThroughFilter::New();
56 myCellDataToPointData = vtkCellDataToPointData::New();
57 myCellDataToPointData->PassCellDataOn();
59 myInputPassFilter->SetInput(vtkUnstructuredGrid::New());
61 myCellDataToPointData->SetInput(myInputPassFilter->GetOutput());
63 myWarpVector->SetInput(myCellDataToPointData->GetOutput());
65 myOutputPassFiler->SetInput(myWarpVector->GetOutput());
68 //----------------------------------------------------------------------------
69 VISU_DeformationPL::~VISU_DeformationPL()
71 if(MYDEBUG) MESSAGE("VISU_DeformationPL()::~VISU_DeformationPL() - "<<this);
72 myWarpVector->Delete();
73 myVectorMergeFilter->Delete();
74 myInputPassFilter->Delete();
75 myOutputPassFiler->Delete();
76 myCellDataToPointData->Delete();
80 //----------------------------------------------------------------------------
82 VISU_DeformationPL::GetMTime(){
83 unsigned long int aTime = std::max(myWarpVector->GetMTime(),
84 myVectorMergeFilter->GetMTime());
86 aTime = std::max(aTime,myInputPassFilter->GetMTime());
87 aTime = std::max(aTime,myOutputPassFiler->GetMTime());
88 aTime = std::max(aTime,myCellDataToPointData->GetMTime());
92 //----------------------------------------------------------------------------
93 void VISU_DeformationPL::SetScale(vtkFloatingPointType theScaleFactor)
95 if(myScaleFactor == theScaleFactor)
97 myScaleFactor = theScaleFactor;
98 myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
101 void VISU_DeformationPL::SetMapScale(vtkFloatingPointType theMapScaleFactor)
103 if(myMapScaleFactor == theMapScaleFactor)
105 myMapScaleFactor = theMapScaleFactor;
107 myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
111 vtkFloatingPointType VISU_DeformationPL::GetScale()
113 return myScaleFactor;
116 //----------------------------------------------------------------------------
117 void VISU_DeformationPL::SetWarpVectorInput(vtkDataSet *theInput)
119 myInputPassFilter->SetInput(theInput);
122 //----------------------------------------------------------------------------
123 vtkDataSet* VISU_DeformationPL::GetWarpVectorOutput()
125 return myOutputPassFiler->GetOutput();
128 //----------------------------------------------------------------------------
129 void VISU_DeformationPL::SetMergeFilterInput(vtkDataSet* ScalarInput,
130 vtkDataSet* VectorialInput)
132 myVectorMergeFilter->SetScalars(ScalarInput);
133 myVectorMergeFilter->AddField("VISU_CELLS_MAPPER",ScalarInput);
134 myVectorMergeFilter->AddField("VISU_POINTS_MAPPER",ScalarInput);
136 myVectorMergeFilter->SetGeometry(VectorialInput);
137 myVectorMergeFilter->SetVectors(VectorialInput);
140 //----------------------------------------------------------------------------
141 vtkDataSet* VISU_DeformationPL::GetMergeFilterOutput(){
142 return myVectorMergeFilter->GetOutput();
145 //----------------------------------------------------------------------------
146 vtkFloatingPointType VISU_DeformationPL::GetDefaultScaleFactor(VISU_DeformationPL *thePipeLine)
148 if(!thePipeLine || !thePipeLine->GetMergeFilterOutput())
151 vtkFloatingPointType aSourceRange[2];
152 thePipeLine->GetMergeFilterOutput()->GetScalarRange(aSourceRange);
154 static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT;
155 if(fabs(aSourceRange[1]) > EPS){
156 vtkDataSet* aDataSet = thePipeLine->GetMergeFilterOutput();
157 vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor(aDataSet);
158 return aScaleFactor / aSourceRange[1];