1 // Copyright (C) 2007-2010 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_VectorsPL.hxx"
29 #include "VISU_FieldTransform.hxx"
30 #include "VISU_PipeLineUtils.hxx"
31 #include "VISU_UsedPointsFilter.hxx"
32 #include "VTKViewer_TransformFilter.h"
33 #include "VTKViewer_Transform.h"
35 #include <vtkGlyph3D.h>
36 #include <vtkConeSource.h>
37 #include <vtkLineSource.h>
38 #include <vtkGlyphSource2D.h>
39 #include <vtkPolyData.h>
42 //----------------------------------------------------------------------------
43 vtkStandardNewMacro(VISU_VectorsPL);
45 //----------------------------------------------------------------------------
46 template<class TOutputFilter>
47 void ToCellCenters( TOutputFilter *theOutputFilter,
48 vtkCellCenters *theCellCenters,
49 vtkDataSet* theDataSet,
50 VISU_UsedPointsFilter* theUsedPointsFilter )
52 if ( VISU::IsDataOnCells( theDataSet ) ) {
53 theCellCenters->SetInput( theDataSet );
54 theCellCenters->VertexCellsOn();
55 theOutputFilter->SetInput( theCellCenters->GetOutput() );
57 theUsedPointsFilter->SetInput( theDataSet );
58 theOutputFilter->SetInput( theUsedPointsFilter->GetOutput() );
66 SetIsShrinkable(false);
67 SetIsFeatureEdgesAllowed(false);
69 myGlyph = vtkGlyph3D::New();
71 myGlyphSource = vtkGlyphSource2D::New();
72 myConeSource = vtkConeSource::New();
73 myLineSource = vtkLineSource::New();
75 myCenters = vtkCellCenters::New();
76 myTransformFilter = VTKViewer_TransformFilter::New();
78 myUsedPointsFilter = VISU_UsedPointsFilter::New();
82 //----------------------------------------------------------------------------
90 myGlyphSource->Delete();
92 myConeSource->Delete();
94 myLineSource->Delete();
96 myTransformFilter->Delete();
98 myUsedPointsFilter->Delete();
102 //----------------------------------------------------------------------------
107 unsigned long int aTime = Superclass::GetMTime();
109 aTime = std::max(aTime, myGlyph->GetMTime());
110 aTime = std::max(aTime, myCenters->GetMTime());
111 aTime = std::max(aTime, myGlyphSource->GetMTime());
112 aTime = std::max(aTime, myConeSource->GetMTime());
113 aTime = std::max(aTime, myLineSource->GetMTime());
114 aTime = std::max(aTime, myTransformFilter->GetMTime());
120 //----------------------------------------------------------------------------
123 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
126 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
128 if(VISU_VectorsPL *aPipeLine = dynamic_cast<VISU_VectorsPL*>(thePipeLine)){
129 SetGlyphType(aPipeLine->GetGlyphType());
130 SetGlyphPos(aPipeLine->GetGlyphPos());
135 //----------------------------------------------------------------------------
138 ::SetTransform( VTKViewer_Transform* theTransform )
140 myTransformFilter->SetTransform( theTransform );
141 myTransformFilter->Modified();
145 //----------------------------------------------------------------------------
150 return static_cast< VTKViewer_Transform* >( myTransformFilter->GetTransform() );
154 //----------------------------------------------------------------------------
157 ::SetScale(vtkFloatingPointType theScale)
159 if ( VISU::CheckIsSameValue( myScaleFactor, theScale ) )
162 myGlyph->SetScaleFactor( theScale );
164 myScaleFactor = theScale;
170 //----------------------------------------------------------------------------
175 return myGlyph->GetScaleFactor();
179 //----------------------------------------------------------------------------
182 ::SetGlyphType(VISU_VectorsPL::GlyphType theType)
184 if(myTypeGlyph == theType)
187 myTypeGlyph = theType;
192 //----------------------------------------------------------------------------
193 VISU_VectorsPL::GlyphType
195 ::GetGlyphType() const
201 //----------------------------------------------------------------------------
204 ::SetGlyphPos(VISU_VectorsPL::GlyphPos thePos)
206 if(myPosGlyph == thePos)
214 //----------------------------------------------------------------------------
215 VISU_VectorsPL::GlyphPos
217 ::GetGlyphPos() const
223 //----------------------------------------------------------------------------
235 //----------------------------------------------------------------------------
242 ToCellCenters( myTransformFilter,
245 myUsedPointsFilter );
247 myGlyph->SetInput( myTransformFilter->GetOutput() );
248 myGlyph->SetVectorModeToUseVector();
249 myGlyph->SetScaleModeToScaleByVector();
250 myGlyph->SetColorModeToColorByScalar();
254 //----------------------------------------------------------------------------
259 return myGlyph->GetOutput();
263 //----------------------------------------------------------------------------
268 switch (myTypeGlyph) {
270 myGlyphSource->SetGlyphTypeToArrow();
271 myGlyphSource->SetFilled(0);
272 switch (myPosGlyph) {
274 myGlyphSource->SetCenter(0.5, 0.0, 0.0);
277 myGlyphSource->SetCenter(-0.5, 0.0, 0.0);
280 myGlyphSource->SetCenter(0.0, 0.0, 0.0);
282 myGlyph->SetSource(myGlyphSource->GetOutput());
287 if (myTypeGlyph == CONE2)
288 myConeSource->SetResolution(3);
290 myConeSource->SetResolution(7);
291 myConeSource->SetHeight(1.0);
292 myConeSource->SetRadius(.1);
294 switch (myPosGlyph) {
296 myConeSource->SetCenter(0.5, 0.0, 0.0);
299 myConeSource->SetCenter(-0.5, 0.0, 0.0);
302 myConeSource->SetCenter(0.0, 0.0, 0.0);
304 myGlyph->SetSource(myConeSource->GetOutput());
309 myGlyph->SetSource(myLineSource->GetOutput());
313 Superclass::Update();
317 //----------------------------------------------------------------------------
322 unsigned long int aSize = Superclass::GetMemorySize();
324 if(vtkDataSet* aDataSet = myGlyph->GetOutput())
325 aSize += aDataSet->GetActualMemorySize() * 1024;
327 if(vtkDataSet* aDataSet = myCenters->GetOutput())
328 aSize += aDataSet->GetActualMemorySize() * 1024;
334 //----------------------------------------------------------------------------
341 return myGlyph->GetOutput();
345 //----------------------------------------------------------------------------
348 ::SetMapScale(vtkFloatingPointType theMapScale)
350 VISU_ScalarMapPL::SetMapScale(theMapScale);
351 myMapScaleFactor = theMapScale;
353 myGlyph->SetScaleFactor( myScaleFactor*theMapScale );
359 //----------------------------------------------------------------------------