1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File: VISU_PipeLine.cxx
25 // Author: Alexey PETROV
28 #include "VISU_DeformedShapePL.hxx"
29 #include "VISU_PipeLineUtils.hxx"
30 #include "VTKViewer_Transform.h"
32 #include <vtkWarpVector.h>
35 //----------------------------------------------------------------------------
36 vtkStandardNewMacro(VISU_DeformedShapePL);
39 //----------------------------------------------------------------------------
41 ::VISU_DeformedShapePL():
45 SetIsShrinkable(true);
46 SetIsFeatureEdgesAllowed(true);
48 myWarpVector = vtkWarpVector::New();
49 myCellDataToPointData = VISU_CellDataToPointData::New();
53 //----------------------------------------------------------------------------
55 ::~VISU_DeformedShapePL()
57 myWarpVector->Delete();
59 myCellDataToPointData->Delete();
63 //----------------------------------------------------------------------------
68 unsigned long int aTime = Superclass::GetMTime();
70 aTime = std::max(aTime, myWarpVector->GetMTime());
71 aTime = std::max(aTime, myCellDataToPointData->GetMTime());
77 //----------------------------------------------------------------------------
80 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
83 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
85 if(VISU_DeformedShapePL *aPipeLine = dynamic_cast<VISU_DeformedShapePL*>(thePipeLine)){
86 SetScale(aPipeLine->GetScale());
91 //----------------------------------------------------------------------------
94 ::GetScaleFactor(vtkDataSet* theDataSet)
99 int aNbCells = theDataSet->GetNumberOfCells();
100 int aNbPoints = theDataSet->GetNumberOfPoints();
101 int aNbElem = aNbCells? aNbCells: aNbPoints;
103 double* aBounds = theDataSet->GetBounds();
104 double aVolume = 1, aVol, idim = 0;
105 for(int i = 0; i < 6; i += 2){
106 aVol = fabs(aBounds[i+1] - aBounds[i]);
112 if( aNbElem == 0 || fabs(idim) < 1.0 / VTK_LARGE_FLOAT )
113 return 0.0; // to avoid division by zero
115 return pow(aVolume, double(1.0/idim));
119 //----------------------------------------------------------------------------
122 ::GetDefaultScale(VISU_ScalarMapPL* theScalarMapPL)
124 double aSourceRange[2];
125 theScalarMapPL->GetSourceRange(aSourceRange);
127 static double EPS = 1.0 / VTK_LARGE_FLOAT;
128 if(fabs(aSourceRange[1]) > EPS){
129 vtkDataSet* aDataSet = theScalarMapPL->GetMergedInput();
130 double aScaleFactor = VISU_DeformedShapePL::GetScaleFactor(aDataSet);
131 return aScaleFactor / aSourceRange[1];
137 //----------------------------------------------------------------------------
140 ::SetScale(double theScale)
142 if(VISU::CheckIsSameValue(myWarpVector->GetScaleFactor(), theScale))
145 myWarpVector->SetScaleFactor(theScale*myMapScaleFactor);
146 myScaleFactor = theScale;
150 //----------------------------------------------------------------------------
155 return myScaleFactor;
159 //----------------------------------------------------------------------------
166 SetScale(VISU_DeformedShapePL::GetDefaultScale(this));
170 //----------------------------------------------------------------------------
175 Superclass::Update();
177 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myWarpVector.vtk";
178 // VISU::WriteToFile(myWarpVector->GetUnstructuredGridOutput(), aFileName);
183 //----------------------------------------------------------------------------
188 VISU::CellDataToPoint(myWarpVector,
189 myCellDataToPointData,
191 GetMergedInputPort());
193 return myWarpVector->GetOutputPort();
197 //----------------------------------------------------------------------------
202 unsigned long int aSize = Superclass::GetMemorySize();
204 if(myWarpVector->GetInput())
205 if(vtkDataSet* aDataSet = myWarpVector->GetOutput())
206 aSize += aDataSet->GetActualMemorySize() * 1024;
208 if(myCellDataToPointData->GetInput())
209 if(vtkDataSet* aDataSet = myCellDataToPointData->GetOutput())
210 aSize += aDataSet->GetActualMemorySize() * 1024;
216 //----------------------------------------------------------------------------
219 ::SetMapScale(double theMapScale)
221 myMapScaleFactor = theMapScale;
222 Superclass::SetMapScale(theMapScale);
224 double aMapScale = myScaleFactor * theMapScale;
225 if(VISU::CheckIsSameValue(myWarpVector->GetScaleFactor(), aMapScale))
228 myWarpVector->SetScaleFactor( aMapScale );
232 //----------------------------------------------------------------------------