Salome HOME
c34d36d9de8c7aaa94e0dd53497450ddf1489917
[modules/visu.git] / src / PIPELINE / VISU_VectorsPL.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 // File:    VISU_PipeLine.cxx
24 // Author:  Alexey PETROV
25 // Module : VISU
26
27
28 #include "VISU_VectorsPL.hxx"
29 #include "VISU_PipeLineUtils.hxx"
30 #include "VTKViewer_TransformFilter.h"
31 #include "VTKViewer_Transform.h"
32
33 #include <vtkGlyph3D.h>
34 #include <vtkConeSource.h>
35 #include <vtkLineSource.h>
36 #include <vtkGlyphSource2D.h>
37
38 vtkStandardNewMacro(VISU_VectorsPL);
39
40 VISU_VectorsPL::VISU_VectorsPL(){
41   myGlyph = vtkGlyph3D::New();
42
43   myGlyphSource = vtkGlyphSource2D::New();
44   myConeSource = vtkConeSource::New();
45   myLineSource = vtkLineSource::New();
46
47   myCenters = vtkCellCenters::New();
48   myTransformFilter = VTKViewer_TransformFilter::New();
49   myIsShrinkable = false;
50 }
51
52 VISU_VectorsPL::~VISU_VectorsPL(){
53   myGlyph->UnRegisterAllOutputs();
54   myGlyph->Delete();
55
56   myCenters->UnRegisterAllOutputs();
57   myCenters->Delete();
58
59   myGlyphSource->UnRegisterAllOutputs();
60   myGlyphSource->Delete();
61
62   myConeSource->UnRegisterAllOutputs();
63   myConeSource->Delete();
64
65   myLineSource->UnRegisterAllOutputs();
66   myLineSource->Delete();
67
68   myTransformFilter->UnRegisterAllOutputs();
69   myTransformFilter->Delete();
70 }
71
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());
77   }
78 }
79
80
81 void VISU_VectorsPL::SetTransform(VTKViewer_Transform* theTransform){
82   myFieldTransform->SetSpaceTransform(theTransform);
83   myTransformFilter->SetTransform(theTransform);
84   myTransformFilter->Modified();
85 }
86 VTKViewer_Transform* VISU_VectorsPL::GetTransform(){
87   return myFieldTransform->GetSpaceTransform();
88 }
89
90
91 void VISU_VectorsPL::SetScale(float theScale) {
92   if(myScaleFactor == theScale) return;
93   myScaleFactor = theScale;
94   myGlyph->SetScaleFactor(myScaleFactor);
95   Modified();
96 }
97 float VISU_VectorsPL::GetScale() {
98   return myGlyph->GetScaleFactor();
99 }
100
101
102 void VISU_VectorsPL::Init(){
103   VISU_DeformedShapePL::Init();
104
105   myTypeGlyph = ARROW;
106   myPosGlyph = TAIL;
107 }
108
109
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();
117 }
118
119
120 void VISU_VectorsPL::Update(){
121   switch (myTypeGlyph) {
122   case ARROW: {
123     myGlyphSource->SetGlyphTypeToArrow();
124     myGlyphSource->SetFilled(0);
125     switch (myPosGlyph) {
126     case TAIL:
127       myGlyphSource->SetCenter(0.5, 0.0, 0.0);
128       break;
129     case HEAD:
130       myGlyphSource->SetCenter(-0.5, 0.0, 0.0);
131       break;
132     case CENTER:
133       myGlyphSource->SetCenter(0.0, 0.0, 0.0);
134     }
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());
140   }
141     break;
142   case CONE2:
143   case CONE6: {
144     if (myTypeGlyph == CONE2)
145       myConeSource->SetResolution(3);
146     else
147       myConeSource->SetResolution(7);
148     myConeSource->SetHeight(1.0);
149     myConeSource->SetRadius(.1);
150
151     switch (myPosGlyph) {
152     case TAIL:
153       myConeSource->SetCenter(0.5, 0.0, 0.0);
154       break;
155     case HEAD:
156       myConeSource->SetCenter(-0.5, 0.0, 0.0);
157       break;
158     case CENTER:
159       myConeSource->SetCenter(0.0, 0.0, 0.0);
160     }
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());
166   }
167     break;
168   case NONE:
169   default: {
170     myGlyph->SetSource(myLineSource->GetOutput());
171   }
172   }
173
174   VISU_DeformedShapePL::Update();
175 }
176
177
178 void VISU_VectorsPL::SetMapScale(float theMapScale){
179   VISU_ScalarMapPL::SetMapScale(theMapScale);
180
181   myGlyph->SetScaleFactor(myScaleFactor*theMapScale);
182   myGlyph->Modified();
183 }