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