Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/visu.git] / src / PIPELINE / VISU_DeformedShapePL.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 // File:    VISU_PipeLine.cxx
24 // Author:  Alexey PETROV
25 // Module : VISU
26
27
28 #include "VISU_DeformedShapePL.hxx"
29 #include "VISU_PipeLineUtils.hxx"
30 #include "VTKViewer_Transform.h"
31
32 #include <vtkWarpVector.h>
33
34 vtkStandardNewMacro(VISU_DeformedShapePL);
35
36 VISU_DeformedShapePL
37 ::VISU_DeformedShapePL()
38 {
39   myWarpVector = vtkWarpVector::New();
40   myCellDataToPointData = vtkCellDataToPointData::New();
41 }
42
43 VISU_DeformedShapePL
44 ::~VISU_DeformedShapePL()
45 {
46   myWarpVector->UnRegisterAllOutputs();
47   myWarpVector->Delete();
48
49   myCellDataToPointData->UnRegisterAllOutputs();
50   myCellDataToPointData->Delete();
51 }
52
53 void
54 VISU_DeformedShapePL
55 ::ShallowCopy(VISU_PipeLine *thePipeLine)
56 {
57   if(VISU_DeformedShapePL *aPipeLine = dynamic_cast<VISU_DeformedShapePL*>(thePipeLine)){
58     SetScale(aPipeLine->GetScale());
59   }
60   VISU_ScalarMapPL::ShallowCopy(thePipeLine);
61 }
62
63 vtkFloatingPointType
64 VISU_DeformedShapePL
65 ::GetScaleFactor(vtkDataSet* theDataSet)
66 {
67   if(!theDataSet) return 0.0;
68   theDataSet->Update();
69   int aNbCells = theDataSet->GetNumberOfCells();
70   int aNbPoints = theDataSet->GetNumberOfPoints();
71   int aNbElem = aNbCells? aNbCells: aNbPoints;
72   vtkFloatingPointType* aBounds = theDataSet->GetBounds();
73   vtkFloatingPointType aVolume = 1, aVol, idim = 0;
74   for(int i = 0; i < 6; i += 2){
75     aVol = fabs(aBounds[i+1] - aBounds[i]);
76     if(aVol > 0) {
77       idim++;
78       aVolume *= aVol;
79     }
80   }
81   aVolume /= aNbElem;
82   return pow(aVolume,vtkFloatingPointType(1.0/idim));
83 }
84
85
86 void
87 VISU_DeformedShapePL
88 ::SetScale(vtkFloatingPointType theScale) 
89 {
90   myWarpVector->SetScaleFactor(theScale);
91   myScaleFactor = theScale;
92   Modified();
93 }
94
95 vtkFloatingPointType
96 VISU_DeformedShapePL
97 ::GetScale() 
98 {
99   return myScaleFactor;
100 }
101
102 void
103 VISU_DeformedShapePL
104 ::Init()
105 {
106   VISU_ScalarMapPL::Init();
107   vtkFloatingPointType aScalarRange[2];
108   GetSourceRange(aScalarRange);
109
110   vtkDataSet* aDataSet = GetInput2();
111   vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor( aDataSet );
112
113   static double EPS = 1.0 / VTK_LARGE_FLOAT;
114   if(fabs(aScalarRange[1]) > EPS)
115     SetScale(aScaleFactor / aScalarRange[1]);
116   else
117     SetScale(0.0);
118 }
119
120 VISU_ScalarMapPL::THook* 
121 VISU_DeformedShapePL
122 ::DoHook()
123 {
124   VISU::CellDataToPoint(myWarpVector,myCellDataToPointData,GetInput2(),myFieldTransform);
125   return myWarpVector->GetOutput();
126 }
127
128 void
129 VISU_DeformedShapePL
130 ::Update()
131 {
132   VISU_ScalarMapPL::Update();
133 }
134
135 void
136 VISU_DeformedShapePL
137 ::SetMapScale(vtkFloatingPointType theMapScale)
138 {
139   VISU_ScalarMapPL::SetMapScale(theMapScale);
140
141   myWarpVector->SetScaleFactor(myScaleFactor*theMapScale);
142   Modified();
143 }