1 // Copyright (C) 2007-2013 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->SetInputData(vtkUnstructuredGrid::New());
60 myCellDataToPointData->SetInputConnection(myInputPassFilter->GetOutputPort());
62 myWarpVector->SetInputConnection(myCellDataToPointData->GetOutputPort());
64 myOutputPassFiler->SetInputConnection(myWarpVector->GetOutputPort());
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(double theScaleFactor)
94 if(myScaleFactor == theScaleFactor)
96 myScaleFactor = theScaleFactor;
97 myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
100 void VISU_DeformationPL::SetMapScale(double theMapScaleFactor)
102 if(myMapScaleFactor == theMapScaleFactor)
104 myMapScaleFactor = theMapScaleFactor;
106 myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
110 double VISU_DeformationPL::GetScale()
112 return myScaleFactor;
115 //----------------------------------------------------------------------------
116 void VISU_DeformationPL::SetWarpVectorInput(vtkDataSet *theInput)
118 myInputPassFilter->SetInputData(theInput);
121 //----------------------------------------------------------------------------
122 vtkDataSet* VISU_DeformationPL::GetWarpVectorOutput()
124 vtkDataSet* aDataSet = myOutputPassFiler->GetOutput();
125 myOutputPassFiler->Update();
129 //----------------------------------------------------------------------------
130 vtkAlgorithmOutput* VISU_DeformationPL::GetWarpVectorOutputPort()
132 return myOutputPassFiler->GetOutputPort();
135 //----------------------------------------------------------------------------
136 void VISU_DeformationPL::SetMergeFilterInput(vtkDataSet* ScalarInput,
137 vtkDataSet* VectorialInput)
139 myVectorMergeFilter->SetScalarsData(ScalarInput);
140 myVectorMergeFilter->AddField("VISU_CELLS_MAPPER",ScalarInput);
141 myVectorMergeFilter->AddField("VISU_POINTS_MAPPER",ScalarInput);
143 myVectorMergeFilter->SetGeometryData(VectorialInput);
144 myVectorMergeFilter->SetVectorsData(VectorialInput);
147 //----------------------------------------------------------------------------
148 vtkDataSet* VISU_DeformationPL::GetMergeFilterOutput(){
149 vtkDataSet* aDataSet = myVectorMergeFilter->GetOutput();
150 myVectorMergeFilter->Update();
154 //----------------------------------------------------------------------------
155 double VISU_DeformationPL::GetDefaultScaleFactor(VISU_DeformationPL *thePipeLine)
157 if(!thePipeLine || !thePipeLine->GetMergeFilterOutput())
160 double aSourceRange[2];
161 thePipeLine->GetMergeFilterOutput()->GetScalarRange(aSourceRange);
163 static double EPS = 1.0 / VTK_LARGE_FLOAT;
164 if(fabs(aSourceRange[1]) > EPS){
165 vtkDataSet* aDataSet = thePipeLine->GetMergeFilterOutput();
166 double aScaleFactor = VISU_DeformedShapePL::GetScaleFactor(aDataSet);
167 return aScaleFactor / aSourceRange[1];