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 // File: VISU_ScalarMapPL.cxx
23 // Author: Roman NIKOLAEV
27 #include "VISU_DeformationPL.hxx"
28 #include "VISU_MergeFilter.hxx"
29 #include "VISU_DeformedShapePL.hxx"
30 #include "VISU_PipeLineUtils.hxx"
33 #include <vtkDataSet.h>
34 #include <vtkPassThroughFilter.h>
35 #include <vtkWarpVector.h>
36 #include <vtkCellDataToPointData.h>
37 #include <vtkUnstructuredGrid.h>
39 static int MYDEBUG = 0;
41 static int MYDEBUG = 0;
45 //----------------------------------------------------------------------------
46 VISU_DeformationPL::VISU_DeformationPL():
50 if(MYDEBUG) MESSAGE("VISU_DeformationPL()::VISU_DeformationPL() - "<<this);
51 myWarpVector = vtkWarpVector::New();
52 myWarpVector->SetScaleFactor(myScaleFactor);
54 myVectorMergeFilter = VISU_MergeFilter::New();
55 myVectorMergeFilter->SetMergingInputs(true);
56 myInputPassFilter = vtkPassThroughFilter::New();
57 myOutputPassFiler = vtkPassThroughFilter::New();
58 myCellDataToPointData = vtkCellDataToPointData::New();
59 myCellDataToPointData->PassCellDataOn();
61 myInputPassFilter->SetInput(vtkUnstructuredGrid::New());
63 myCellDataToPointData->SetInput(myInputPassFilter->GetOutput());
65 myWarpVector->SetInput(myCellDataToPointData->GetOutput());
67 myOutputPassFiler->SetInput(myWarpVector->GetOutput());
70 //----------------------------------------------------------------------------
71 VISU_DeformationPL::~VISU_DeformationPL()
73 if(MYDEBUG) MESSAGE("VISU_DeformationPL()::~VISU_DeformationPL() - "<<this);
74 myWarpVector->Delete();
75 myVectorMergeFilter->Delete();
76 myInputPassFilter->Delete();
77 myOutputPassFiler->Delete();
78 myCellDataToPointData->Delete();
82 //----------------------------------------------------------------------------
84 VISU_DeformationPL::GetMTime(){
85 unsigned long int aTime = std::max(myWarpVector->GetMTime(),
86 myVectorMergeFilter->GetMTime());
88 aTime = std::max(aTime,myInputPassFilter->GetMTime());
89 aTime = std::max(aTime,myOutputPassFiler->GetMTime());
90 aTime = std::max(aTime,myCellDataToPointData->GetMTime());
94 //----------------------------------------------------------------------------
95 void VISU_DeformationPL::SetScale(vtkFloatingPointType theScaleFactor)
97 if(myScaleFactor == theScaleFactor)
99 myScaleFactor = theScaleFactor;
100 myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
103 void VISU_DeformationPL::SetMapScale(vtkFloatingPointType theMapScaleFactor)
105 if(myMapScaleFactor == theMapScaleFactor)
107 myMapScaleFactor = theMapScaleFactor;
109 myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
113 vtkFloatingPointType VISU_DeformationPL::GetScale()
115 return myScaleFactor;
118 //----------------------------------------------------------------------------
119 void VISU_DeformationPL::SetWarpVectorInput(vtkDataSet *theInput)
121 myInputPassFilter->SetInput(theInput);
124 //----------------------------------------------------------------------------
125 vtkDataSet* VISU_DeformationPL::GetWarpVectorOutput()
127 return myOutputPassFiler->GetOutput();
130 //----------------------------------------------------------------------------
131 void VISU_DeformationPL::SetMergeFilterInput(vtkDataSet* ScalarInput,
132 vtkDataSet* VectorialInput)
134 myVectorMergeFilter->SetScalars(ScalarInput);
135 myVectorMergeFilter->AddField("VISU_CELLS_MAPPER",ScalarInput);
136 myVectorMergeFilter->AddField("VISU_POINTS_MAPPER",ScalarInput);
138 myVectorMergeFilter->SetGeometry(VectorialInput);
139 myVectorMergeFilter->SetVectors(VectorialInput);
142 //----------------------------------------------------------------------------
143 vtkDataSet* VISU_DeformationPL::GetMergeFilterOutput(){
144 return myVectorMergeFilter->GetOutput();
147 //----------------------------------------------------------------------------
148 vtkFloatingPointType VISU_DeformationPL::GetDefaultScaleFactor(VISU_DeformationPL *thePipeLine)
150 if(!thePipeLine || !thePipeLine->GetMergeFilterOutput())
153 vtkFloatingPointType aSourceRange[2];
154 thePipeLine->GetMergeFilterOutput()->GetScalarRange(aSourceRange);
156 static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT;
157 if(fabs(aSourceRange[1]) > EPS){
158 vtkDataSet* aDataSet = thePipeLine->GetMergeFilterOutput();
159 vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor(aDataSet);
160 return aScaleFactor / aSourceRange[1];