1 // Copyright (C) 2007-2012 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"
34 #include "VTKViewer_CellCenters.h"
36 #include <vtkGlyph3D.h>
37 #include <vtkConeSource.h>
38 #include <vtkLineSource.h>
39 #include <vtkGlyphSource2D.h>
40 #include <vtkPolyData.h>
43 //----------------------------------------------------------------------------
44 vtkStandardNewMacro(VISU_VectorsPL);
46 //----------------------------------------------------------------------------
47 template<class TOutputFilter>
48 void ToCellCenters( TOutputFilter *theOutputFilter,
49 VTKViewer_CellCenters *theCellCenters,
50 vtkDataSet* theDataSet,
51 VISU_UsedPointsFilter* theUsedPointsFilter )
53 if ( VISU::IsDataOnCells( theDataSet ) ) {
54 theCellCenters->SetInput( theDataSet );
55 theCellCenters->VertexCellsOn();
56 theOutputFilter->SetInput( theCellCenters->GetOutput() );
58 theUsedPointsFilter->SetInput( theDataSet );
59 theOutputFilter->SetInput( theUsedPointsFilter->GetOutput() );
67 SetIsShrinkable(false);
68 SetIsFeatureEdgesAllowed(false);
70 myGlyph = vtkGlyph3D::New();
72 myGlyphSource = vtkGlyphSource2D::New();
73 myConeSource = vtkConeSource::New();
74 myLineSource = vtkLineSource::New();
76 myCenters = VTKViewer_CellCenters::New();
77 myTransformFilter = VTKViewer_TransformFilter::New();
79 myUsedPointsFilter = VISU_UsedPointsFilter::New();
83 //----------------------------------------------------------------------------
91 myGlyphSource->Delete();
93 myConeSource->Delete();
95 myLineSource->Delete();
97 myTransformFilter->Delete();
99 myUsedPointsFilter->Delete();
103 //----------------------------------------------------------------------------
108 unsigned long int aTime = Superclass::GetMTime();
110 aTime = std::max(aTime, myGlyph->GetMTime());
111 aTime = std::max(aTime, myCenters->GetMTime());
112 aTime = std::max(aTime, myGlyphSource->GetMTime());
113 aTime = std::max(aTime, myConeSource->GetMTime());
114 aTime = std::max(aTime, myLineSource->GetMTime());
115 aTime = std::max(aTime, myTransformFilter->GetMTime());
121 //----------------------------------------------------------------------------
124 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
127 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
129 if(VISU_VectorsPL *aPipeLine = dynamic_cast<VISU_VectorsPL*>(thePipeLine)){
130 SetGlyphType(aPipeLine->GetGlyphType());
131 SetGlyphPos(aPipeLine->GetGlyphPos());
136 //----------------------------------------------------------------------------
139 ::SetTransform( VTKViewer_Transform* theTransform )
141 myTransformFilter->SetTransform( theTransform );
142 myTransformFilter->Modified();
146 //----------------------------------------------------------------------------
151 return static_cast< VTKViewer_Transform* >( myTransformFilter->GetTransform() );
155 //----------------------------------------------------------------------------
158 ::SetScale(vtkFloatingPointType theScale)
160 if ( VISU::CheckIsSameValue( myScaleFactor, theScale ) )
163 myGlyph->SetScaleFactor( theScale );
165 myScaleFactor = theScale;
171 //----------------------------------------------------------------------------
176 return myGlyph->GetScaleFactor();
180 //----------------------------------------------------------------------------
183 ::SetGlyphType(VISU_VectorsPL::GlyphType theType)
185 if(myTypeGlyph == theType)
188 myTypeGlyph = theType;
193 //----------------------------------------------------------------------------
194 VISU_VectorsPL::GlyphType
196 ::GetGlyphType() const
202 //----------------------------------------------------------------------------
205 ::SetGlyphPos(VISU_VectorsPL::GlyphPos thePos)
207 if(myPosGlyph == thePos)
215 //----------------------------------------------------------------------------
216 VISU_VectorsPL::GlyphPos
218 ::GetGlyphPos() const
224 //----------------------------------------------------------------------------
236 //----------------------------------------------------------------------------
243 ToCellCenters( myTransformFilter,
246 myUsedPointsFilter );
248 myGlyph->SetInput( myTransformFilter->GetOutput() );
249 myGlyph->SetVectorModeToUseVector();
250 myGlyph->SetScaleModeToScaleByVector();
251 myGlyph->SetColorModeToColorByScalar();
255 //----------------------------------------------------------------------------
260 return myGlyph->GetOutput();
264 //----------------------------------------------------------------------------
269 switch (myTypeGlyph) {
271 myGlyphSource->SetGlyphTypeToArrow();
272 myGlyphSource->SetFilled(0);
273 switch (myPosGlyph) {
275 myGlyphSource->SetCenter(0.5, 0.0, 0.0);
278 myGlyphSource->SetCenter(-0.5, 0.0, 0.0);
281 myGlyphSource->SetCenter(0.0, 0.0, 0.0);
283 myGlyph->SetSource(myGlyphSource->GetOutput());
288 if (myTypeGlyph == CONE2)
289 myConeSource->SetResolution(3);
291 myConeSource->SetResolution(7);
292 myConeSource->SetHeight(1.0);
293 myConeSource->SetRadius(.1);
295 switch (myPosGlyph) {
297 myConeSource->SetCenter(0.5, 0.0, 0.0);
300 myConeSource->SetCenter(-0.5, 0.0, 0.0);
303 myConeSource->SetCenter(0.0, 0.0, 0.0);
305 myGlyph->SetSource(myConeSource->GetOutput());
310 myGlyph->SetSource(myLineSource->GetOutput());
314 Superclass::Update();
318 //----------------------------------------------------------------------------
323 unsigned long int aSize = Superclass::GetMemorySize();
325 if(vtkDataSet* aDataSet = myGlyph->GetOutput())
326 aSize += aDataSet->GetActualMemorySize() * 1024;
328 if(vtkDataSet* aDataSet = myCenters->GetOutput())
329 aSize += aDataSet->GetActualMemorySize() * 1024;
335 //----------------------------------------------------------------------------
342 return myGlyph->GetOutput();
346 //----------------------------------------------------------------------------
349 ::SetMapScale(vtkFloatingPointType theMapScale)
351 VISU_ScalarMapPL::SetMapScale(theMapScale);
352 myMapScaleFactor = theMapScale;
354 myGlyph->SetScaleFactor( myScaleFactor*theMapScale );
360 //----------------------------------------------------------------------------