Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[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 #include <vtkPolyData.h>
38
39 vtkStandardNewMacro(VISU_VectorsPL);
40
41 VISU_VectorsPL
42 ::VISU_VectorsPL()
43 {
44   myBaseGlyph = vtkGlyph3D::New();
45   myTransformedGlyph = vtkGlyph3D::New();
46
47   myGlyphSource = vtkGlyphSource2D::New();
48   myConeSource = vtkConeSource::New();
49   myLineSource = vtkLineSource::New();
50
51   myCenters = vtkCellCenters::New();
52   myTransformFilter = VTKViewer_TransformFilter::New();
53   myIsShrinkable = false;
54 }
55
56 VISU_VectorsPL
57 ::~VISU_VectorsPL()
58 {
59   myBaseGlyph->Delete();
60   myTransformedGlyph->Delete();
61
62   myCenters->Delete();
63
64   myGlyphSource->Delete();
65
66   myConeSource->Delete();
67
68   myLineSource->Delete();
69
70   myTransformFilter->Delete();
71 }
72
73 void
74 VISU_VectorsPL
75 ::ShallowCopy(VISU_PipeLine *thePipeLine)
76 {
77   if(VISU_VectorsPL *aPipeLine = dynamic_cast<VISU_VectorsPL*>(thePipeLine)){
78     SetGlyphType(aPipeLine->GetGlyphType());
79     SetGlyphPos(aPipeLine->GetGlyphPos());
80   }
81   Superclass::ShallowCopy(thePipeLine);
82 }
83
84
85 void
86 VISU_VectorsPL
87 ::SetTransform(VTKViewer_Transform* theTransform)
88 {
89   myFieldTransform->SetSpaceTransform(theTransform);
90   myTransformFilter->SetTransform(theTransform);
91   myTransformFilter->Modified();
92 }
93
94 VTKViewer_Transform* 
95 VISU_VectorsPL
96 ::GetTransform()
97 {
98   return myFieldTransform->GetSpaceTransform();
99 }
100
101
102 void
103 VISU_VectorsPL
104 ::SetScale(vtkFloatingPointType theScale) 
105 {
106   if(myScaleFactor == theScale) 
107     return;
108
109   myScaleFactor = theScale;
110
111   myBaseGlyph->SetScaleFactor(myScaleFactor);
112   myTransformedGlyph->SetScaleFactor(myScaleFactor);
113
114   Modified();
115 }
116
117 vtkFloatingPointType
118 VISU_VectorsPL
119 ::GetScale() 
120 {
121   return myTransformedGlyph->GetScaleFactor();
122 }
123
124
125 void
126 VISU_VectorsPL
127 ::Init()
128 {
129   Superclass::Init();
130
131   myTypeGlyph = ARROW;
132   myPosGlyph = TAIL;
133 }
134
135
136 vtkDataSet* 
137 VISU_VectorsPL
138 ::GetOutput()
139 {
140   myBaseGlyph->Update();
141   return myBaseGlyph->GetOutput();
142 }
143
144
145 VISU_ScalarMapPL::THook* 
146 VISU_VectorsPL
147 ::DoHook()
148 {
149   VISU::ToCellCenters(myBaseGlyph,myCenters,GetInput2(),myFieldTransform);
150   myBaseGlyph->SetVectorModeToUseVector();
151   myBaseGlyph->SetScaleModeToScaleByVector();
152   myBaseGlyph->SetColorModeToColorByScalar();
153
154   VISU::ToCellCenters(myTransformFilter,myCenters,GetInput2(),myFieldTransform);
155   myTransformedGlyph->SetInput(myTransformFilter->GetOutput());
156   myTransformedGlyph->SetVectorModeToUseVector();
157   myTransformedGlyph->SetScaleModeToScaleByVector();
158   myTransformedGlyph->SetColorModeToColorByScalar();
159
160   return myTransformedGlyph->GetOutput();
161 }
162
163
164 void
165 VISU_VectorsPL
166 ::Update()
167 {
168   switch (myTypeGlyph) {
169   case ARROW: {
170     myGlyphSource->SetGlyphTypeToArrow();
171     myGlyphSource->SetFilled(0);
172     switch (myPosGlyph) {
173     case TAIL:
174       myGlyphSource->SetCenter(0.5, 0.0, 0.0);
175       break;
176     case HEAD:
177       myGlyphSource->SetCenter(-0.5, 0.0, 0.0);
178       break;
179     case CENTER:
180       myGlyphSource->SetCenter(0.0, 0.0, 0.0);
181     }
182     myBaseGlyph->SetSource(myGlyphSource->GetOutput());
183     myTransformedGlyph->SetSource(myGlyphSource->GetOutput());
184   }
185     break;
186   case CONE2:
187   case CONE6: {
188     if (myTypeGlyph == CONE2)
189       myConeSource->SetResolution(3);
190     else
191       myConeSource->SetResolution(7);
192     myConeSource->SetHeight(1.0);
193     myConeSource->SetRadius(.1);
194
195     switch (myPosGlyph) {
196     case TAIL:
197       myConeSource->SetCenter(0.5, 0.0, 0.0);
198       break;
199     case HEAD:
200       myConeSource->SetCenter(-0.5, 0.0, 0.0);
201       break;
202     case CENTER:
203       myConeSource->SetCenter(0.0, 0.0, 0.0);
204     }
205     myBaseGlyph->SetSource(myConeSource->GetOutput());
206     myTransformedGlyph->SetSource(myConeSource->GetOutput());
207   }
208     break;
209   case NONE:
210   default: {
211     myBaseGlyph->SetSource(myLineSource->GetOutput());
212     myTransformedGlyph->SetSource(myLineSource->GetOutput());
213   }
214   }
215
216   Superclass::Update();
217 }
218
219
220 void
221 VISU_VectorsPL
222 ::SetMapScale(vtkFloatingPointType theMapScale)
223 {
224   VISU_ScalarMapPL::SetMapScale(theMapScale);
225
226   myBaseGlyph->SetScaleFactor(myScaleFactor*theMapScale);
227   myTransformedGlyph->SetScaleFactor(myScaleFactor*theMapScale);
228
229   Modified();
230 }