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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File: VISU_PipeLine.cxx
24 // Author: Alexey PETROV
28 #include "VISU_VectorsPL.hxx"
29 #include "VISU_PipeLineUtils.hxx"
30 #include "VTKViewer_TransformFilter.h"
31 #include "VTKViewer_Transform.h"
33 #include <vtkGlyph3D.h>
34 #include <vtkConeSource.h>
35 #include <vtkLineSource.h>
36 #include <vtkGlyphSource2D.h>
38 vtkStandardNewMacro(VISU_VectorsPL);
40 VISU_VectorsPL::VISU_VectorsPL(){
41 myGlyph = vtkGlyph3D::New();
43 myGlyphSource = vtkGlyphSource2D::New();
44 myConeSource = vtkConeSource::New();
45 myLineSource = vtkLineSource::New();
47 myCenters = vtkCellCenters::New();
48 myTransformFilter = VTKViewer_TransformFilter::New();
49 myIsShrinkable = false;
52 VISU_VectorsPL::~VISU_VectorsPL(){
53 myGlyph->UnRegisterAllOutputs();
56 myCenters->UnRegisterAllOutputs();
59 myGlyphSource->UnRegisterAllOutputs();
60 myGlyphSource->Delete();
62 myConeSource->UnRegisterAllOutputs();
63 myConeSource->Delete();
65 myLineSource->UnRegisterAllOutputs();
66 myLineSource->Delete();
68 myTransformFilter->UnRegisterAllOutputs();
69 myTransformFilter->Delete();
72 void VISU_VectorsPL::ShallowCopy(VISU_PipeLine *thePipeLine){
73 VISU_DeformedShapePL::ShallowCopy(thePipeLine);
74 if(VISU_VectorsPL *aPipeLine = dynamic_cast<VISU_VectorsPL*>(thePipeLine)){
75 SetGlyphType(aPipeLine->GetGlyphType());
76 SetGlyphPos(aPipeLine->GetGlyphPos());
81 void VISU_VectorsPL::SetTransform(VTKViewer_Transform* theTransform){
82 myFieldTransform->SetSpaceTransform(theTransform);
83 myTransformFilter->SetTransform(theTransform);
84 myTransformFilter->Modified();
86 VTKViewer_Transform* VISU_VectorsPL::GetTransform(){
87 return myFieldTransform->GetSpaceTransform();
91 void VISU_VectorsPL::SetScale(float theScale) {
92 if(myScaleFactor == theScale) return;
93 myScaleFactor = theScale;
94 myGlyph->SetScaleFactor(myScaleFactor);
97 float VISU_VectorsPL::GetScale() {
98 return myGlyph->GetScaleFactor();
102 void VISU_VectorsPL::Init(){
103 VISU_DeformedShapePL::Init();
110 VISU_ScalarMapPL::THook* VISU_VectorsPL::DoHook(){
111 VISU::ToCellCenters(myTransformFilter,myCenters,GetInput2(),myFieldTransform);
112 myGlyph->SetInput(myTransformFilter->GetOutput());
113 myGlyph->SetVectorModeToUseVector();
114 myGlyph->SetScaleModeToScaleByVector();
115 myGlyph->SetColorModeToColorByScalar();
116 return myGlyph->GetOutput();
120 void VISU_VectorsPL::Update(){
121 switch (myTypeGlyph) {
123 myGlyphSource->SetGlyphTypeToArrow();
124 myGlyphSource->SetFilled(0);
125 switch (myPosGlyph) {
127 myGlyphSource->SetCenter(0.5, 0.0, 0.0);
130 myGlyphSource->SetCenter(-0.5, 0.0, 0.0);
133 myGlyphSource->SetCenter(0.0, 0.0, 0.0);
135 // if(myPosGlyph == TAIL)
136 // myGlyphSource->SetCenter(0.5, 0.0, 0.0);
137 // else if(myPosGlyph == HEAD)
138 // myGlyphSource->SetCenter(-0.5, 0.0, 0.0);
139 myGlyph->SetSource(myGlyphSource->GetOutput());
144 if (myTypeGlyph == CONE2)
145 myConeSource->SetResolution(3);
147 myConeSource->SetResolution(7);
148 myConeSource->SetHeight(1.0);
149 myConeSource->SetRadius(.1);
151 switch (myPosGlyph) {
153 myConeSource->SetCenter(0.5, 0.0, 0.0);
156 myConeSource->SetCenter(-0.5, 0.0, 0.0);
159 myConeSource->SetCenter(0.0, 0.0, 0.0);
161 // if(myPosGlyph == TAIL)
162 // myConeSource->SetCenter(0.5, 0.0, 0.0);
163 // else if(myPosGlyph == HEAD)
164 // myConeSource->SetCenter(-0.5, 0.0, 0.0);
165 myGlyph->SetSource(myConeSource->GetOutput());
170 myGlyph->SetSource(myLineSource->GetOutput());
174 VISU_DeformedShapePL::Update();
178 void VISU_VectorsPL::SetMapScale(float theMapScale){
179 VISU_ScalarMapPL::SetMapScale(theMapScale);
181 myGlyph->SetScaleFactor(myScaleFactor*theMapScale);