1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // VISU OBJECT : interactive object for VISU entities implementation
21 // File: VISU_DeformedGridPL.cxx
22 // Author: Alexey PETROV
25 #include "VISU_DeformedGridPL.hxx"
26 #include "VISU_FieldTransform.hxx"
27 #include "VISU_Plot3DPL.hxx"
29 #include "VISU_PipeLineUtils.hxx"
31 #include <vtkPolyDataMapper.h>
32 #include <vtkContourFilter.h>
33 #include <vtkWarpScalar.h>
36 //----------------------------------------------------------------------------
37 vtkStandardNewMacro(VISU_DeformedGridPL);
40 //----------------------------------------------------------------------------
42 ::VISU_DeformedGridPL():
43 myContourFilter(vtkContourFilter::New()),
44 myWarpScalar(vtkWarpScalar::New()),
49 SetIsShrinkable(false);
50 SetNumberOfContours(32);
54 //----------------------------------------------------------------------------
56 ::~VISU_DeformedGridPL()
60 //----------------------------------------------------------------------------
65 unsigned long int aTime = Superclass::GetMTime();
67 aTime = std::max(aTime, myContourFilter->GetMTime());
68 aTime = std::max(aTime, myWarpScalar->GetMTime());
74 //----------------------------------------------------------------------------
79 unsigned long int aSize = Superclass::GetMemorySize();
81 if(vtkDataObject* aDataObject = myContourFilter->GetInput())
82 aSize += aDataObject->GetActualMemorySize() * 1024;
84 if(vtkDataObject* aDataObject = myWarpScalar->GetInput())
85 aSize += aDataObject->GetActualMemorySize() * 1024;
91 //----------------------------------------------------------------------------
94 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
97 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
99 if(VISU_DeformedGridPL *aPipeLine = dynamic_cast<VISU_DeformedGridPL*>(thePipeLine)){
100 SetScaleFactor( aPipeLine->GetScaleFactor() );
101 SetContourPrs( aPipeLine->GetIsContourPrs() );
102 SetNumberOfContours( aPipeLine->GetNumberOfContours() );
107 //----------------------------------------------------------------------------
114 vtkPointSet* aPointSet = GetFieldTransformFilter()->GetPolyDataOutput();
115 SetScaleFactor( VISU_Plot3DPL::GetScaleFactor( this, aPointSet ) );
119 //----------------------------------------------------------------------------
126 myWarpScalar->SetInput( GetFieldTransformFilter()->GetPolyDataOutput() );
127 GetPolyDataMapper()->SetInput( myWarpScalar->GetPolyDataOutput() );
131 //----------------------------------------------------------------------------
136 vtkPointSet* aPointSet = GetFieldTransformFilter()->GetPolyDataOutput();
137 if ( !myIsContour ) // surface prs
139 myWarpScalar->SetInput( aPointSet );
143 myContourFilter->SetInput( aPointSet );
145 vtkFloatingPointType aScalarRange[2];
146 GetSourceRange( aScalarRange );
148 myContourFilter->GenerateValues( GetNumberOfContours(), aScalarRange );
149 myWarpScalar->SetInput( myContourFilter->GetOutput() );
152 Superclass::Update();
156 //----------------------------------------------------------------------------
159 ::SetNumberOfContours(int theNumber)
161 myContourFilter->SetNumberOfContours(theNumber);
165 //----------------------------------------------------------------------------
168 ::GetNumberOfContours()
170 return myContourFilter->GetNumberOfContours();
174 //----------------------------------------------------------------------------
177 ::SetScaleFactor(vtkFloatingPointType theScaleFactor)
179 if ( VISU::CheckIsSameValue( myWarpScalar->GetScaleFactor(), theScaleFactor ) )
182 myScaleFactor = theScaleFactor;
183 myWarpScalar->SetScaleFactor(theScaleFactor*myMapScaleFactor);
187 //----------------------------------------------------------------------------
192 return myScaleFactor;
196 //----------------------------------------------------------------------------
199 ::SetContourPrs(bool theIsContourPrs )
201 if(myIsContour == theIsContourPrs)
204 myIsContour = theIsContourPrs;
209 //----------------------------------------------------------------------------
218 //----------------------------------------------------------------------------
221 ::SetMapScale(vtkFloatingPointType theMapScale)
223 Superclass::SetMapScale(theMapScale);
224 myMapScaleFactor = theMapScale;
227 vtkFloatingPointType aSourceRange[2];
228 GetSourceRange( aSourceRange );
229 vtkFloatingPointType aDeltaRange = aSourceRange[1] - aSourceRange[0];
230 vtkFloatingPointType aNewRange[2] = { aSourceRange[1] - theMapScale*aDeltaRange, aSourceRange[1] };
231 myContourFilter->GenerateValues( GetNumberOfContours(), aNewRange );
234 myWarpScalar->SetScaleFactor( myScaleFactor * theMapScale );