1 // Copyright (C) 2007-2008 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
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File: VISU_PipeLine.cxx
24 // Author: Alexey PETROV
27 #include "VISU_DeformedShapePL.hxx"
28 #include "VISU_PipeLineUtils.hxx"
29 #include "VTKViewer_Transform.h"
31 #include <vtkWarpVector.h>
34 //----------------------------------------------------------------------------
35 vtkStandardNewMacro(VISU_DeformedShapePL);
38 //----------------------------------------------------------------------------
40 ::VISU_DeformedShapePL():
44 SetIsShrinkable(true);
45 SetIsFeatureEdgesAllowed(true);
47 myWarpVector = vtkWarpVector::New();
48 myCellDataToPointData = vtkCellDataToPointData::New();
52 //----------------------------------------------------------------------------
54 ::~VISU_DeformedShapePL()
56 myWarpVector->Delete();
58 myCellDataToPointData->Delete();
62 //----------------------------------------------------------------------------
67 unsigned long int aTime = Superclass::GetMTime();
69 aTime = std::max(aTime, myWarpVector->GetMTime());
70 aTime = std::max(aTime, myCellDataToPointData->GetMTime());
76 //----------------------------------------------------------------------------
79 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
82 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
84 if(VISU_DeformedShapePL *aPipeLine = dynamic_cast<VISU_DeformedShapePL*>(thePipeLine)){
85 SetScale(aPipeLine->GetScale());
90 //----------------------------------------------------------------------------
93 ::GetScaleFactor(vtkDataSet* theDataSet)
100 int aNbCells = theDataSet->GetNumberOfCells();
101 int aNbPoints = theDataSet->GetNumberOfPoints();
102 int aNbElem = aNbCells? aNbCells: aNbPoints;
104 vtkFloatingPointType* aBounds = theDataSet->GetBounds();
105 vtkFloatingPointType aVolume = 1, aVol, idim = 0;
106 for(int i = 0; i < 6; i += 2){
107 aVol = fabs(aBounds[i+1] - aBounds[i]);
113 if( aNbElem == 0 || fabs(idim) < 1.0 / VTK_LARGE_FLOAT )
114 return 0.0; // to avoid division by zero
116 return pow(aVolume, vtkFloatingPointType(1.0/idim));
120 //----------------------------------------------------------------------------
123 ::GetDefaultScale(VISU_ScalarMapPL* theScalarMapPL)
125 vtkFloatingPointType aSourceRange[2];
126 theScalarMapPL->GetSourceRange(aSourceRange);
128 static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT;
129 if(fabs(aSourceRange[1]) > EPS){
130 vtkDataSet* aDataSet = theScalarMapPL->GetMergedInput();
131 vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor(aDataSet);
132 return aScaleFactor / aSourceRange[1];
138 //----------------------------------------------------------------------------
141 ::SetScale(vtkFloatingPointType theScale)
143 if(VISU::CheckIsSameValue(myWarpVector->GetScaleFactor(), theScale))
146 myWarpVector->SetScaleFactor(theScale*myMapScaleFactor);
147 myScaleFactor = theScale;
151 //----------------------------------------------------------------------------
156 return myScaleFactor;
160 //----------------------------------------------------------------------------
167 SetScale(VISU_DeformedShapePL::GetDefaultScale(this));
171 //----------------------------------------------------------------------------
176 Superclass::Update();
178 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myWarpVector.vtk";
179 // VISU::WriteToFile(myWarpVector->GetUnstructuredGridOutput(), aFileName);
184 //----------------------------------------------------------------------------
189 VISU::CellDataToPoint(myWarpVector,
190 myCellDataToPointData,
193 return myWarpVector->GetOutput();
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(vtkFloatingPointType theMapScale)
221 myMapScaleFactor = theMapScale;
222 Superclass::SetMapScale(theMapScale);
224 vtkFloatingPointType aMapScale = myScaleFactor * theMapScale;
225 if(VISU::CheckIsSameValue(myWarpVector->GetScaleFactor(), aMapScale))
228 myWarpVector->SetScaleFactor( aMapScale );
232 //----------------------------------------------------------------------------