]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_DeformationPL.cxx
Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / PIPELINE / VISU_DeformationPL.cxx
1 //  Copyright (C) 2007-2010  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 <vtkCellDataToPointData.h>
35 #include <vtkUnstructuredGrid.h>
36 #ifdef _DEBUG_
37 static int MYDEBUG = 0;
38 #else
39 static int MYDEBUG = 0;
40 #endif
41
42
43 //----------------------------------------------------------------------------
44 VISU_DeformationPL::VISU_DeformationPL():
45   myScaleFactor(1.0),
46   myMapScaleFactor(1.0)
47 {
48   if(MYDEBUG) MESSAGE("VISU_DeformationPL()::VISU_DeformationPL() - "<<this);
49   myWarpVector = vtkWarpVector::New();
50   myWarpVector->SetScaleFactor(myScaleFactor);
51   
52   myVectorMergeFilter = VISU_MergeFilter::New();
53   myVectorMergeFilter->SetMergingInputs(true);
54   myInputPassFilter = vtkPassThroughFilter::New();
55   myOutputPassFiler = vtkPassThroughFilter::New();
56   myCellDataToPointData = vtkCellDataToPointData::New();
57   myCellDataToPointData->PassCellDataOn();
58
59   myInputPassFilter->SetInput(vtkUnstructuredGrid::New());
60
61   myCellDataToPointData->SetInput(myInputPassFilter->GetOutput());
62
63   myWarpVector->SetInput(myCellDataToPointData->GetOutput());
64   
65   myOutputPassFiler->SetInput(myWarpVector->GetOutput());
66 }
67
68 //----------------------------------------------------------------------------
69 VISU_DeformationPL::~VISU_DeformationPL()
70 {
71   if(MYDEBUG) MESSAGE("VISU_DeformationPL()::~VISU_DeformationPL() - "<<this);
72   myWarpVector->Delete();
73   myVectorMergeFilter->Delete();
74   myInputPassFilter->Delete();
75   myOutputPassFiler->Delete();
76   myCellDataToPointData->Delete();
77 }
78
79
80 //----------------------------------------------------------------------------
81 unsigned long int 
82 VISU_DeformationPL::GetMTime(){
83   unsigned long int aTime = std::max(myWarpVector->GetMTime(), 
84                                      myVectorMergeFilter->GetMTime());
85
86   aTime = std::max(aTime,myInputPassFilter->GetMTime());
87   aTime = std::max(aTime,myOutputPassFiler->GetMTime());
88   aTime = std::max(aTime,myCellDataToPointData->GetMTime());
89   return 0;
90 }
91
92 //----------------------------------------------------------------------------
93 void VISU_DeformationPL::SetScale(vtkFloatingPointType theScaleFactor)
94 {
95   if(myScaleFactor == theScaleFactor)
96     return;
97   myScaleFactor = theScaleFactor;
98   myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
99 }
100
101 void VISU_DeformationPL::SetMapScale(vtkFloatingPointType theMapScaleFactor)
102 {
103   if(myMapScaleFactor == theMapScaleFactor)
104     return;
105   myMapScaleFactor = theMapScaleFactor;
106   
107   myWarpVector->SetScaleFactor(myScaleFactor*myMapScaleFactor);
108 }
109
110
111 vtkFloatingPointType VISU_DeformationPL::GetScale()
112 {
113   return myScaleFactor;
114 }
115
116 //----------------------------------------------------------------------------
117 void VISU_DeformationPL::SetWarpVectorInput(vtkDataSet *theInput)
118 {
119   myInputPassFilter->SetInput(theInput);
120 }
121
122 //----------------------------------------------------------------------------
123 vtkDataSet* VISU_DeformationPL::GetWarpVectorOutput()
124 {
125   return myOutputPassFiler->GetOutput();
126 }
127
128 //----------------------------------------------------------------------------
129 void VISU_DeformationPL::SetMergeFilterInput(vtkDataSet* ScalarInput,
130                          vtkDataSet* VectorialInput)
131 {
132   myVectorMergeFilter->SetScalars(ScalarInput);
133   myVectorMergeFilter->AddField("VISU_CELLS_MAPPER",ScalarInput);
134   myVectorMergeFilter->AddField("VISU_POINTS_MAPPER",ScalarInput);
135   
136   myVectorMergeFilter->SetGeometry(VectorialInput);
137   myVectorMergeFilter->SetVectors(VectorialInput);
138 }
139
140 //----------------------------------------------------------------------------
141 vtkDataSet* VISU_DeformationPL::GetMergeFilterOutput(){
142  return myVectorMergeFilter->GetOutput();
143 }
144
145 //----------------------------------------------------------------------------
146 vtkFloatingPointType VISU_DeformationPL::GetDefaultScaleFactor(VISU_DeformationPL *thePipeLine)
147 {
148   if(!thePipeLine || !thePipeLine->GetMergeFilterOutput())
149     return 0.0;
150   
151   vtkFloatingPointType aSourceRange[2];
152   thePipeLine->GetMergeFilterOutput()->GetScalarRange(aSourceRange);
153   
154   static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT;
155   if(fabs(aSourceRange[1]) > EPS){
156     vtkDataSet* aDataSet = thePipeLine->GetMergeFilterOutput();
157     vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor(aDataSet);
158     return aScaleFactor / aSourceRange[1];
159   }
160   return 0.0;
161 }
162