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_DeformedGridPL.cxx
24 // Author: Alexey PETROV
27 #include "VISU_DeformedGridPL.hxx"
28 #include "VISU_FieldTransform.hxx"
29 #include "VISU_Plot3DPL.hxx"
31 #include "VISU_PipeLineUtils.hxx"
33 #include <vtkPolyDataMapper.h>
34 #include <vtkContourFilter.h>
35 #include <vtkWarpScalar.h>
38 //----------------------------------------------------------------------------
39 vtkStandardNewMacro(VISU_DeformedGridPL);
42 //----------------------------------------------------------------------------
44 ::VISU_DeformedGridPL():
45 myContourFilter(vtkContourFilter::New()),
46 myWarpScalar(vtkWarpScalar::New()),
51 SetIsShrinkable(false);
52 SetNumberOfContours(32);
56 //----------------------------------------------------------------------------
58 ::~VISU_DeformedGridPL()
62 //----------------------------------------------------------------------------
67 unsigned long int aTime = Superclass::GetMTime();
69 aTime = std::max(aTime, myContourFilter->GetMTime());
70 aTime = std::max(aTime, myWarpScalar->GetMTime());
76 //----------------------------------------------------------------------------
81 unsigned long int aSize = Superclass::GetMemorySize();
83 if(vtkDataObject* aDataObject = myContourFilter->GetInput())
84 aSize += aDataObject->GetActualMemorySize() * 1024;
86 if(vtkDataObject* aDataObject = myWarpScalar->GetInput())
87 aSize += aDataObject->GetActualMemorySize() * 1024;
93 //----------------------------------------------------------------------------
96 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
99 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
101 if(VISU_DeformedGridPL *aPipeLine = dynamic_cast<VISU_DeformedGridPL*>(thePipeLine)){
102 SetScaleFactor( aPipeLine->GetScaleFactor() );
103 SetContourPrs( aPipeLine->GetIsContourPrs() );
104 SetNumberOfContours( aPipeLine->GetNumberOfContours() );
109 //----------------------------------------------------------------------------
116 vtkPointSet* aPointSet = GetFieldTransformFilter()->GetPolyDataOutput();
117 SetScaleFactor( VISU_Plot3DPL::GetScaleFactor( this, aPointSet ) );
121 //----------------------------------------------------------------------------
128 myWarpScalar->SetInput( GetFieldTransformFilter()->GetPolyDataOutput() );
129 GetPolyDataMapper()->SetInput( myWarpScalar->GetPolyDataOutput() );
133 //----------------------------------------------------------------------------
138 vtkPointSet* aPointSet = GetFieldTransformFilter()->GetPolyDataOutput();
139 if ( !myIsContour ) // surface prs
141 myWarpScalar->SetInput( aPointSet );
145 myContourFilter->SetInput( aPointSet );
147 vtkFloatingPointType aScalarRange[2];
148 GetSourceRange( aScalarRange );
150 myContourFilter->GenerateValues( GetNumberOfContours(), aScalarRange );
151 myWarpScalar->SetInput( myContourFilter->GetOutput() );
154 Superclass::Update();
158 //----------------------------------------------------------------------------
161 ::SetNumberOfContours(int theNumber)
163 myContourFilter->SetNumberOfContours(theNumber);
167 //----------------------------------------------------------------------------
170 ::GetNumberOfContours()
172 return myContourFilter->GetNumberOfContours();
176 //----------------------------------------------------------------------------
179 ::SetScaleFactor(vtkFloatingPointType theScaleFactor)
181 if ( VISU::CheckIsSameValue( myWarpScalar->GetScaleFactor(), theScaleFactor ) )
184 myScaleFactor = theScaleFactor;
185 myWarpScalar->SetScaleFactor(theScaleFactor*myMapScaleFactor);
189 //----------------------------------------------------------------------------
194 return myScaleFactor;
198 //----------------------------------------------------------------------------
201 ::SetContourPrs(bool theIsContourPrs )
203 if(myIsContour == theIsContourPrs)
206 myIsContour = theIsContourPrs;
211 //----------------------------------------------------------------------------
220 //----------------------------------------------------------------------------
223 ::SetMapScale(vtkFloatingPointType theMapScale)
225 Superclass::SetMapScale(theMapScale);
226 myMapScaleFactor = theMapScale;
229 vtkFloatingPointType aSourceRange[2];
230 GetSourceRange( aSourceRange );
231 vtkFloatingPointType aDeltaRange = aSourceRange[1] - aSourceRange[0];
232 vtkFloatingPointType aNewRange[2] = { aSourceRange[1] - theMapScale*aDeltaRange, aSourceRange[1] };
233 myContourFilter->GenerateValues( GetNumberOfContours(), aNewRange );
236 myWarpScalar->SetScaleFactor( myScaleFactor * theMapScale );