Salome HOME
Porting to VTK 6.
[modules/visu.git] / src / PIPELINE / VISU_DeformationPL.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:    VISU_ScalarMapPL.cxx
21 // Author:  Roman NIKOLAEV
22 // Module : VISU
23 //Salome includes
24 //
25 #include "VISU_DeformationPL.hxx"
26 #include "VISU_MergeFilter.hxx"
27 #include "VISU_DeformedShapePL.hxx"
28 #include "VISU_PipeLineUtils.hxx"
29
30 //VTK includes
31 #include <vtkDataSet.h>
32 #include <vtkPassThroughFilter.h>
33 #include <vtkWarpVector.h>
34 #include <vtkUnstructuredGrid.h>
35 #ifdef _DEBUG_
36 static int MYDEBUG = 0;
37 #else
38 static int MYDEBUG = 0;
39 #endif
40
41
42 //----------------------------------------------------------------------------
43 VISU_DeformationPL::VISU_DeformationPL():
44   myScaleFactor(1.0),
45   myMapScaleFactor(1.0)
46 {
47   if(MYDEBUG) MESSAGE("VISU_DeformationPL()::VISU_DeformationPL() - "<<this);
48   myWarpVector = vtkWarpVector::New();
49   myWarpVector->SetScaleFactor(myScaleFactor);
50   
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();
57
58   myInputPassFilter->SetInputData(vtkUnstructuredGrid::New());
59
60   myCellDataToPointData->SetInputConnection(myInputPassFilter->GetOutputPort());
61
62   myWarpVector->SetInputConnection(myCellDataToPointData->GetOutputPort());
63   
64   myOutputPassFiler->SetInputConnection(myWarpVector->GetOutputPort());
65 }
66
67 //----------------------------------------------------------------------------
68 VISU_DeformationPL::~VISU_DeformationPL()
69 {
70   if(MYDEBUG) MESSAGE("VISU_DeformationPL()::~VISU_DeformationPL() - "<<this);
71   myWarpVector->Delete();
72   myVectorMergeFilter->Delete();
73   myInputPassFilter->Delete();
74   myOutputPassFiler->Delete();
75   myCellDataToPointData->Delete();
76 }
77
78
79 //----------------------------------------------------------------------------
80 unsigned long int 
81 VISU_DeformationPL::GetMTime(){
82   unsigned long int aTime = std::max(myWarpVector->GetMTime(), 
83                                      myVectorMergeFilter->GetMTime());
84
85   aTime = std::max(aTime,myInputPassFilter->GetMTime());
86   aTime = std::max(aTime,myOutputPassFiler->GetMTime());
87   aTime = std::max(aTime,myCellDataToPointData->GetMTime());
88   return 0;
89 }
90
91 //----------------------------------------------------------------------------
92 void VISU_DeformationPL::SetScale(double theScaleFactor)
93 {
94   if(myScaleFactor == theScaleFactor)
95     return;
96   myScaleFactor = theScaleFactor;
97   myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
98 }
99
100 void VISU_DeformationPL::SetMapScale(double theMapScaleFactor)
101 {
102   if(myMapScaleFactor == theMapScaleFactor)
103     return;
104   myMapScaleFactor = theMapScaleFactor;
105   
106   myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
107 }
108
109
110 double VISU_DeformationPL::GetScale()
111 {
112   return myScaleFactor;
113 }
114
115 //----------------------------------------------------------------------------
116 void VISU_DeformationPL::SetWarpVectorInput(vtkDataSet *theInput)
117 {
118   myInputPassFilter->SetInputData(theInput);
119 }
120
121 //----------------------------------------------------------------------------
122 vtkDataSet* VISU_DeformationPL::GetWarpVectorOutput()
123 {
124   vtkDataSet* aDataSet = myOutputPassFiler->GetOutput();
125   myOutputPassFiler->Update();
126   return aDataSet;
127 }
128
129 //----------------------------------------------------------------------------
130 vtkAlgorithmOutput* VISU_DeformationPL::GetWarpVectorOutputPort()
131 {
132   return myOutputPassFiler->GetOutputPort();
133 }
134
135 //----------------------------------------------------------------------------
136 void VISU_DeformationPL::SetMergeFilterInput(vtkDataSet* ScalarInput,
137                          vtkDataSet* VectorialInput)
138 {
139   myVectorMergeFilter->SetScalarsData(ScalarInput);
140   myVectorMergeFilter->AddField("VISU_CELLS_MAPPER",ScalarInput);
141   myVectorMergeFilter->AddField("VISU_POINTS_MAPPER",ScalarInput);
142   
143   myVectorMergeFilter->SetGeometryData(VectorialInput);
144   myVectorMergeFilter->SetVectorsData(VectorialInput);
145 }
146
147 //----------------------------------------------------------------------------
148 vtkDataSet* VISU_DeformationPL::GetMergeFilterOutput(){
149   vtkDataSet* aDataSet = myVectorMergeFilter->GetOutput();
150   myVectorMergeFilter->Update();
151   return aDataSet;
152 }
153
154 //----------------------------------------------------------------------------
155 double VISU_DeformationPL::GetDefaultScaleFactor(VISU_DeformationPL *thePipeLine)
156 {
157   if(!thePipeLine || !thePipeLine->GetMergeFilterOutput())
158     return 0.0;
159   
160   double aSourceRange[2];
161   thePipeLine->GetMergeFilterOutput()->GetScalarRange(aSourceRange);
162   
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];
168   }
169   return 0.0;
170 }
171