1 // Copyright (C) 2007-2011 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)
101 int aNbCells = theDataSet->GetNumberOfCells();
102 int aNbPoints = theDataSet->GetNumberOfPoints();
103 int aNbElem = aNbCells? aNbCells: aNbPoints;
105 vtkFloatingPointType* aBounds = theDataSet->GetBounds();
106 vtkFloatingPointType aVolume = 1, aVol, idim = 0;
107 for(int i = 0; i < 6; i += 2){
108 aVol = fabs(aBounds[i+1] - aBounds[i]);
114 if( aNbElem == 0 || fabs(idim) < 1.0 / VTK_LARGE_FLOAT )
115 return 0.0; // to avoid division by zero
117 return pow(aVolume, vtkFloatingPointType(1.0/idim));
121 //----------------------------------------------------------------------------
124 ::GetDefaultScale(VISU_ScalarMapPL* theScalarMapPL)
126 vtkFloatingPointType aSourceRange[2];
127 theScalarMapPL->GetSourceRange(aSourceRange);
129 static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT;
130 if(fabs(aSourceRange[1]) > EPS){
131 vtkDataSet* aDataSet = theScalarMapPL->GetMergedInput();
132 vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor(aDataSet);
133 return aScaleFactor / aSourceRange[1];
139 //----------------------------------------------------------------------------
142 ::SetScale(vtkFloatingPointType theScale)
144 if(VISU::CheckIsSameValue(myWarpVector->GetScaleFactor(), theScale))
147 myWarpVector->SetScaleFactor(theScale*myMapScaleFactor);
148 myScaleFactor = theScale;
152 //----------------------------------------------------------------------------
157 return myScaleFactor;
161 //----------------------------------------------------------------------------
168 SetScale(VISU_DeformedShapePL::GetDefaultScale(this));
172 //----------------------------------------------------------------------------
177 Superclass::Update();
179 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myWarpVector.vtk";
180 // VISU::WriteToFile(myWarpVector->GetUnstructuredGridOutput(), aFileName);
185 //----------------------------------------------------------------------------
190 VISU::CellDataToPoint(myWarpVector,
191 myCellDataToPointData,
194 return myWarpVector->GetOutput();
198 //----------------------------------------------------------------------------
203 unsigned long int aSize = Superclass::GetMemorySize();
205 if(myWarpVector->GetInput())
206 if(vtkDataSet* aDataSet = myWarpVector->GetOutput())
207 aSize += aDataSet->GetActualMemorySize() * 1024;
209 if(myCellDataToPointData->GetInput())
210 if(vtkDataSet* aDataSet = myCellDataToPointData->GetOutput())
211 aSize += aDataSet->GetActualMemorySize() * 1024;
217 //----------------------------------------------------------------------------
220 ::SetMapScale(vtkFloatingPointType theMapScale)
222 myMapScaleFactor = theMapScale;
223 Superclass::SetMapScale(theMapScale);
225 vtkFloatingPointType aMapScale = myScaleFactor * theMapScale;
226 if(VISU::CheckIsSameValue(myWarpVector->GetScaleFactor(), aMapScale))
229 myWarpVector->SetScaleFactor( aMapScale );
233 //----------------------------------------------------------------------------