1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 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 // File: VISU_PipeLine.cxx
24 // 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);
68 myBaseGlyph = vtkGlyph3D::New();
69 myTransformedGlyph = 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 //----------------------------------------------------------------------------
86 myBaseGlyph->Delete();
87 myTransformedGlyph->Delete();
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, myBaseGlyph->GetMTime());
111 aTime = std::max(aTime, myTransformedGlyph->GetMTime());
112 aTime = std::max(aTime, myCenters->GetMTime());
113 aTime = std::max(aTime, myGlyphSource->GetMTime());
114 aTime = std::max(aTime, myConeSource->GetMTime());
115 aTime = std::max(aTime, myLineSource->GetMTime());
116 aTime = std::max(aTime, myTransformFilter->GetMTime());
122 //----------------------------------------------------------------------------
125 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
128 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
130 if(VISU_VectorsPL *aPipeLine = dynamic_cast<VISU_VectorsPL*>(thePipeLine)){
131 SetGlyphType(aPipeLine->GetGlyphType());
132 SetGlyphPos(aPipeLine->GetGlyphPos());
137 //----------------------------------------------------------------------------
140 ::SetTransform(VTKViewer_Transform* theTransform)
142 GetFieldTransformFilter()->SetSpaceTransform(theTransform);
143 myTransformFilter->SetTransform(theTransform);
144 myTransformFilter->Modified();
148 //----------------------------------------------------------------------------
153 return GetFieldTransformFilter()->GetSpaceTransform();
157 //----------------------------------------------------------------------------
160 ::SetScale(vtkFloatingPointType theScale)
162 if(myScaleFactor == theScale)
165 myScaleFactor = theScale;
167 myBaseGlyph->SetScaleFactor(myScaleFactor);
168 myTransformedGlyph->SetScaleFactor(myScaleFactor);
174 //----------------------------------------------------------------------------
179 return myTransformedGlyph->GetScaleFactor();
183 //----------------------------------------------------------------------------
186 ::SetGlyphType(VISU_VectorsPL::GlyphType theType)
188 if(myTypeGlyph == theType)
191 myTypeGlyph = theType;
196 //----------------------------------------------------------------------------
197 VISU_VectorsPL::GlyphType
199 ::GetGlyphType() const
205 //----------------------------------------------------------------------------
208 ::SetGlyphPos(VISU_VectorsPL::GlyphPos thePos)
210 if(myPosGlyph == thePos)
218 //----------------------------------------------------------------------------
219 VISU_VectorsPL::GlyphPos
221 ::GetGlyphPos() const
227 //----------------------------------------------------------------------------
239 //----------------------------------------------------------------------------
246 ToCellCenters(myBaseGlyph,
250 myBaseGlyph->SetVectorModeToUseVector();
251 myBaseGlyph->SetScaleModeToScaleByVector();
252 myBaseGlyph->SetColorModeToColorByScalar();
254 ToCellCenters(myTransformFilter,
258 myTransformedGlyph->SetInput(myTransformFilter->GetOutput());
259 myTransformedGlyph->SetVectorModeToUseVector();
260 myTransformedGlyph->SetScaleModeToScaleByVector();
261 myTransformedGlyph->SetColorModeToColorByScalar();
265 //----------------------------------------------------------------------------
270 return myTransformedGlyph->GetOutput();
274 //----------------------------------------------------------------------------
279 switch (myTypeGlyph) {
281 myGlyphSource->SetGlyphTypeToArrow();
282 myGlyphSource->SetFilled(0);
283 switch (myPosGlyph) {
285 myGlyphSource->SetCenter(0.5, 0.0, 0.0);
288 myGlyphSource->SetCenter(-0.5, 0.0, 0.0);
291 myGlyphSource->SetCenter(0.0, 0.0, 0.0);
293 myBaseGlyph->SetSource(myGlyphSource->GetOutput());
294 myTransformedGlyph->SetSource(myGlyphSource->GetOutput());
299 if (myTypeGlyph == CONE2)
300 myConeSource->SetResolution(3);
302 myConeSource->SetResolution(7);
303 myConeSource->SetHeight(1.0);
304 myConeSource->SetRadius(.1);
306 switch (myPosGlyph) {
308 myConeSource->SetCenter(0.5, 0.0, 0.0);
311 myConeSource->SetCenter(-0.5, 0.0, 0.0);
314 myConeSource->SetCenter(0.0, 0.0, 0.0);
316 myBaseGlyph->SetSource(myConeSource->GetOutput());
317 myTransformedGlyph->SetSource(myConeSource->GetOutput());
322 myBaseGlyph->SetSource(myLineSource->GetOutput());
323 myTransformedGlyph->SetSource(myLineSource->GetOutput());
327 Superclass::Update();
331 //----------------------------------------------------------------------------
336 unsigned long int aSize = Superclass::GetMemorySize();
338 if(vtkDataSet* aDataSet = myBaseGlyph->GetOutput())
339 aSize += aDataSet->GetActualMemorySize() * 1024;
341 if(vtkDataSet* aDataSet = myTransformedGlyph->GetOutput())
342 aSize += aDataSet->GetActualMemorySize() * 1024;
344 if(vtkDataSet* aDataSet = myCenters->GetOutput())
345 aSize += aDataSet->GetActualMemorySize() * 1024;
347 if(myCellDataToPointData->GetInput())
348 if(vtkDataSet* aDataSet = myCellDataToPointData->GetOutput())
349 aSize += aDataSet->GetActualMemorySize() * 1024;
355 //----------------------------------------------------------------------------
360 myBaseGlyph->Update();
361 return myBaseGlyph->GetOutput();
365 //----------------------------------------------------------------------------
368 ::SetMapScale(vtkFloatingPointType theMapScale)
370 VISU_ScalarMapPL::SetMapScale(theMapScale);
372 myBaseGlyph->SetScaleFactor(myScaleFactor*theMapScale);
373 myTransformedGlyph->SetScaleFactor(myScaleFactor*theMapScale);
379 //----------------------------------------------------------------------------