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_PipeLine.cxx
24 // Author: Alexey PETROV
27 #include "VISU_VectorsPL.hxx"
28 #include "VISU_FieldTransform.hxx"
29 #include "VISU_PipeLineUtils.hxx"
30 #include "VISU_UsedPointsFilter.hxx"
31 #include "VTKViewer_TransformFilter.h"
32 #include "VTKViewer_Transform.h"
34 #include <vtkGlyph3D.h>
35 #include <vtkConeSource.h>
36 #include <vtkLineSource.h>
37 #include <vtkGlyphSource2D.h>
38 #include <vtkPolyData.h>
41 //----------------------------------------------------------------------------
42 vtkStandardNewMacro(VISU_VectorsPL);
44 //----------------------------------------------------------------------------
45 template<class TOutputFilter>
46 void ToCellCenters( TOutputFilter *theOutputFilter,
47 vtkCellCenters *theCellCenters,
48 vtkDataSet* theDataSet,
49 VISU_UsedPointsFilter* theUsedPointsFilter )
51 if ( VISU::IsDataOnCells( theDataSet ) ) {
52 theCellCenters->SetInput( theDataSet );
53 theCellCenters->VertexCellsOn();
54 theOutputFilter->SetInput( theCellCenters->GetOutput() );
56 theUsedPointsFilter->SetInput( theDataSet );
57 theOutputFilter->SetInput( theUsedPointsFilter->GetOutput() );
65 SetIsShrinkable(false);
66 SetIsFeatureEdgesAllowed(false);
68 myGlyph = vtkGlyph3D::New();
70 myGlyphSource = vtkGlyphSource2D::New();
71 myConeSource = vtkConeSource::New();
72 myLineSource = vtkLineSource::New();
74 myCenters = vtkCellCenters::New();
75 myTransformFilter = VTKViewer_TransformFilter::New();
77 myUsedPointsFilter = VISU_UsedPointsFilter::New();
81 //----------------------------------------------------------------------------
89 myGlyphSource->Delete();
91 myConeSource->Delete();
93 myLineSource->Delete();
95 myTransformFilter->Delete();
97 myUsedPointsFilter->Delete();
101 //----------------------------------------------------------------------------
106 unsigned long int aTime = Superclass::GetMTime();
108 aTime = std::max(aTime, myGlyph->GetMTime());
109 aTime = std::max(aTime, myCenters->GetMTime());
110 aTime = std::max(aTime, myGlyphSource->GetMTime());
111 aTime = std::max(aTime, myConeSource->GetMTime());
112 aTime = std::max(aTime, myLineSource->GetMTime());
113 aTime = std::max(aTime, myTransformFilter->GetMTime());
119 //----------------------------------------------------------------------------
122 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
125 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
127 if(VISU_VectorsPL *aPipeLine = dynamic_cast<VISU_VectorsPL*>(thePipeLine)){
128 SetGlyphType(aPipeLine->GetGlyphType());
129 SetGlyphPos(aPipeLine->GetGlyphPos());
134 //----------------------------------------------------------------------------
137 ::SetTransform( VTKViewer_Transform* theTransform )
139 myTransformFilter->SetTransform( theTransform );
140 myTransformFilter->Modified();
144 //----------------------------------------------------------------------------
149 return static_cast< VTKViewer_Transform* >( myTransformFilter->GetTransform() );
153 //----------------------------------------------------------------------------
156 ::SetScale(vtkFloatingPointType theScale)
158 if ( VISU::CheckIsSameValue( myScaleFactor, theScale ) )
161 myGlyph->SetScaleFactor( theScale );
163 myScaleFactor = theScale;
169 //----------------------------------------------------------------------------
174 return myGlyph->GetScaleFactor();
178 //----------------------------------------------------------------------------
181 ::SetGlyphType(VISU_VectorsPL::GlyphType theType)
183 if(myTypeGlyph == theType)
186 myTypeGlyph = theType;
191 //----------------------------------------------------------------------------
192 VISU_VectorsPL::GlyphType
194 ::GetGlyphType() const
200 //----------------------------------------------------------------------------
203 ::SetGlyphPos(VISU_VectorsPL::GlyphPos thePos)
205 if(myPosGlyph == thePos)
213 //----------------------------------------------------------------------------
214 VISU_VectorsPL::GlyphPos
216 ::GetGlyphPos() const
222 //----------------------------------------------------------------------------
234 //----------------------------------------------------------------------------
241 ToCellCenters( myTransformFilter,
244 myUsedPointsFilter );
246 myGlyph->SetInput( myTransformFilter->GetOutput() );
247 myGlyph->SetVectorModeToUseVector();
248 myGlyph->SetScaleModeToScaleByVector();
249 myGlyph->SetColorModeToColorByScalar();
253 //----------------------------------------------------------------------------
258 return myGlyph->GetOutput();
262 //----------------------------------------------------------------------------
267 switch (myTypeGlyph) {
269 myGlyphSource->SetGlyphTypeToArrow();
270 myGlyphSource->SetFilled(0);
271 switch (myPosGlyph) {
273 myGlyphSource->SetCenter(0.5, 0.0, 0.0);
276 myGlyphSource->SetCenter(-0.5, 0.0, 0.0);
279 myGlyphSource->SetCenter(0.0, 0.0, 0.0);
281 myGlyph->SetSource(myGlyphSource->GetOutput());
286 if (myTypeGlyph == CONE2)
287 myConeSource->SetResolution(3);
289 myConeSource->SetResolution(7);
290 myConeSource->SetHeight(1.0);
291 myConeSource->SetRadius(.1);
293 switch (myPosGlyph) {
295 myConeSource->SetCenter(0.5, 0.0, 0.0);
298 myConeSource->SetCenter(-0.5, 0.0, 0.0);
301 myConeSource->SetCenter(0.0, 0.0, 0.0);
303 myGlyph->SetSource(myConeSource->GetOutput());
308 myGlyph->SetSource(myLineSource->GetOutput());
312 Superclass::Update();
316 //----------------------------------------------------------------------------
321 unsigned long int aSize = Superclass::GetMemorySize();
323 if(vtkDataSet* aDataSet = myGlyph->GetOutput())
324 aSize += aDataSet->GetActualMemorySize() * 1024;
326 if(vtkDataSet* aDataSet = myCenters->GetOutput())
327 aSize += aDataSet->GetActualMemorySize() * 1024;
333 //----------------------------------------------------------------------------
340 return myGlyph->GetOutput();
344 //----------------------------------------------------------------------------
347 ::SetMapScale(vtkFloatingPointType theMapScale)
349 VISU_ScalarMapPL::SetMapScale(theMapScale);
350 myMapScaleFactor = theMapScale;
352 myGlyph->SetScaleFactor( myScaleFactor*theMapScale );
358 //----------------------------------------------------------------------------