]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_DeformedShapePL.cxx
Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[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 "SALOME_Transform.h"
31
32 #include <vtkWarpVector.h>
33
34 #ifdef _DEBUG_
35 static int MYDEBUG = 1;
36 #else
37 static int MYDEBUG = 0;
38 #endif
39
40 vtkStandardNewMacro(VISU_DeformedShapePL);
41
42 VISU_DeformedShapePL::VISU_DeformedShapePL(){
43   myWarpVector = vtkWarpVector::New();
44 }
45
46 VISU_DeformedShapePL::~VISU_DeformedShapePL(){
47   myWarpVector->Delete();
48 }
49
50 void VISU_DeformedShapePL::ShallowCopy(VISU_PipeLine *thePipeLine){
51   VISU_ScalarMapPL::ShallowCopy(thePipeLine);
52   if(VISU_DeformedShapePL *aPipeLine = dynamic_cast<VISU_DeformedShapePL*>(thePipeLine)){
53     SetScale(aPipeLine->GetScale());
54   }
55 }
56
57 float VISU_DeformedShapePL::GetScaleFactor(vtkDataSet* theDataSet){
58   if(!theDataSet) return 0.0;
59   theDataSet->Update();
60   int aNbCells = theDataSet->GetNumberOfCells();
61   int aNbPoints = theDataSet->GetNumberOfPoints();
62   int aNbElem = aNbCells? aNbCells: aNbPoints;
63   float* aBounds = theDataSet->GetBounds();
64   float aVolume = 1, aVol, idim = 0;
65   for(int i = 0; i < 6; i += 2){
66     aVol = fabs(aBounds[i+1] - aBounds[i]);
67     if(aVol > 0) {
68       idim++; 
69       aVolume *= aVol;
70     }
71   }
72   aVolume /= aNbElem;
73   return pow(aVolume,float(1.0/idim));
74 }
75
76
77 void VISU_DeformedShapePL::SetScale(float theScale) { 
78   if(myScaleFactor == theScale) return;
79   myScaleFactor = theScale;
80   myWarpVector->SetScaleFactor(myScaleFactor);
81   Modified();
82 }
83 float VISU_DeformedShapePL::GetScale() { 
84   return myWarpVector->GetScaleFactor();
85 }
86
87 void VISU_DeformedShapePL::Init(){
88   VISU_ScalarMapPL::Init();
89   float aScalarRange[2];
90   GetSourceRange(aScalarRange);
91   SetScale(GetScaleFactor(myInput)/aScalarRange[1]);
92 }
93
94 VISU_ScalarMapPL::THook* VISU_DeformedShapePL::DoHook(){
95   VISU::CellDataToPoint(myWarpVector,myInput,myFieldTransform);
96   return myWarpVector->GetOutput();
97 }
98
99 void VISU_DeformedShapePL::Update(){
100   VISU_ScalarMapPL::Update();
101 }
102
103 void VISU_DeformedShapePL::SetMapScale(float theMapScale){
104   VISU_ScalarMapPL::SetMapScale(theMapScale);
105
106   myWarpVector->SetScaleFactor(myScaleFactor*theMapScale);
107   Modified();
108 }