Salome HOME
Update copyright information
[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->SetInput(vtkUnstructuredGrid::New());
59
60   myCellDataToPointData->SetInput(myInputPassFilter->GetOutput());
61
62   myWarpVector->SetInput(myCellDataToPointData->GetOutput());
63   
64   myOutputPassFiler->SetInput(myWarpVector->GetOutput());
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(vtkFloatingPointType theScaleFactor)
93 {
94   if(myScaleFactor == theScaleFactor)
95     return;
96   myScaleFactor = theScaleFactor;
97   myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
98 }
99
100 void VISU_DeformationPL::SetMapScale(vtkFloatingPointType theMapScaleFactor)
101 {
102   if(myMapScaleFactor == theMapScaleFactor)
103     return;
104   myMapScaleFactor = theMapScaleFactor;
105   
106   myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
107 }
108
109
110 vtkFloatingPointType VISU_DeformationPL::GetScale()
111 {
112   return myScaleFactor;
113 }
114
115 //----------------------------------------------------------------------------
116 void VISU_DeformationPL::SetWarpVectorInput(vtkDataSet *theInput)
117 {
118   myInputPassFilter->SetInput(theInput);
119 }
120
121 //----------------------------------------------------------------------------
122 vtkDataSet* VISU_DeformationPL::GetWarpVectorOutput()
123 {
124   return myOutputPassFiler->GetOutput();
125 }
126
127 //----------------------------------------------------------------------------
128 void VISU_DeformationPL::SetMergeFilterInput(vtkDataSet* ScalarInput,
129                          vtkDataSet* VectorialInput)
130 {
131   myVectorMergeFilter->SetScalars(ScalarInput);
132   myVectorMergeFilter->AddField("VISU_CELLS_MAPPER",ScalarInput);
133   myVectorMergeFilter->AddField("VISU_POINTS_MAPPER",ScalarInput);
134   
135   myVectorMergeFilter->SetGeometry(VectorialInput);
136   myVectorMergeFilter->SetVectors(VectorialInput);
137 }
138
139 //----------------------------------------------------------------------------
140 vtkDataSet* VISU_DeformationPL::GetMergeFilterOutput(){
141  return myVectorMergeFilter->GetOutput();
142 }
143
144 //----------------------------------------------------------------------------
145 vtkFloatingPointType VISU_DeformationPL::GetDefaultScaleFactor(VISU_DeformationPL *thePipeLine)
146 {
147   if(!thePipeLine || !thePipeLine->GetMergeFilterOutput())
148     return 0.0;
149   
150   vtkFloatingPointType aSourceRange[2];
151   thePipeLine->GetMergeFilterOutput()->GetScalarRange(aSourceRange);
152   
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];
158   }
159   return 0.0;
160 }
161