1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 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 // File: VISU_PipeLine.cxx
24 // 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():
44 SetIsShrinkable(true);
46 myWarpVector = vtkWarpVector::New();
47 myCellDataToPointData = vtkCellDataToPointData::New();
51 //----------------------------------------------------------------------------
53 ::~VISU_DeformedShapePL()
55 myWarpVector->Delete();
57 myCellDataToPointData->Delete();
61 //----------------------------------------------------------------------------
66 unsigned long int aTime = Superclass::GetMTime();
68 aTime = std::max(aTime, myWarpVector->GetMTime());
69 aTime = std::max(aTime, myCellDataToPointData->GetMTime());
75 //----------------------------------------------------------------------------
78 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
81 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
83 if(VISU_DeformedShapePL *aPipeLine = dynamic_cast<VISU_DeformedShapePL*>(thePipeLine)){
84 SetScale(aPipeLine->GetScale());
89 //----------------------------------------------------------------------------
92 ::GetScaleFactor(vtkDataSet* theDataSet)
99 int aNbCells = theDataSet->GetNumberOfCells();
100 int aNbPoints = theDataSet->GetNumberOfPoints();
101 int aNbElem = aNbCells? aNbCells: aNbPoints;
103 vtkFloatingPointType* aBounds = theDataSet->GetBounds();
104 vtkFloatingPointType aVolume = 1, aVol, idim = 0;
105 for(int i = 0; i < 6; i += 2){
106 aVol = fabs(aBounds[i+1] - aBounds[i]);
113 return pow(aVolume, vtkFloatingPointType(1.0/idim));
117 //----------------------------------------------------------------------------
120 ::GetDefaultScale(VISU_ScalarMapPL* theScalarMapPL)
122 vtkFloatingPointType aSourceRange[2];
123 theScalarMapPL->GetSourceRange(aSourceRange);
125 static vtkFloatingPointType EPS = 1.0 / VTK_LARGE_FLOAT;
126 if(fabs(aSourceRange[1]) > EPS){
127 vtkDataSet* aDataSet = theScalarMapPL->GetMergedInput();
128 vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor(aDataSet);
129 return aScaleFactor / aSourceRange[1];
135 //----------------------------------------------------------------------------
138 ::SetScale(vtkFloatingPointType theScale)
140 if(VISU::CheckIsSameValue(myWarpVector->GetScaleFactor(), theScale))
143 myWarpVector->SetScaleFactor(theScale);
144 myScaleFactor = theScale;
148 //----------------------------------------------------------------------------
153 return myScaleFactor;
157 //----------------------------------------------------------------------------
164 SetScale(VISU_DeformedShapePL::GetDefaultScale(this));
168 //----------------------------------------------------------------------------
173 Superclass::Update();
175 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myWarpVector.vtk";
176 // VISU::WriteToFile(myWarpVector->GetUnstructuredGridOutput(), aFileName);
181 //----------------------------------------------------------------------------
186 VISU::CellDataToPoint(myWarpVector,
187 myCellDataToPointData,
190 return myWarpVector->GetOutput();
194 //----------------------------------------------------------------------------
199 unsigned long int aSize = Superclass::GetMemorySize();
201 if(myWarpVector->GetInput())
202 if(vtkDataSet* aDataSet = myWarpVector->GetOutput())
203 aSize += aDataSet->GetActualMemorySize() * 1024;
205 if(myCellDataToPointData->GetInput())
206 if(vtkDataSet* aDataSet = myCellDataToPointData->GetOutput())
207 aSize += aDataSet->GetActualMemorySize() * 1024;
213 //----------------------------------------------------------------------------
216 ::SetMapScale(vtkFloatingPointType theMapScale)
218 Superclass::SetMapScale(theMapScale);
220 myWarpVector->SetScaleFactor(myScaleFactor*theMapScale);
224 //----------------------------------------------------------------------------