Salome HOME
SMH: 3.0.0 preparation - merged and adopted version (POLYWORK+HEAD)
[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 }
50
51 VISU_VectorsPL::~VISU_VectorsPL(){
52   myGlyph->UnRegisterAllOutputs();
53   myGlyph->Delete();
54
55   myCenters->UnRegisterAllOutputs();
56   myCenters->Delete();
57
58   myGlyphSource->UnRegisterAllOutputs();
59   myGlyphSource->Delete();
60
61   myConeSource->UnRegisterAllOutputs();
62   myConeSource->Delete();
63
64   myLineSource->UnRegisterAllOutputs();
65   myLineSource->Delete();
66
67   myTransformFilter->UnRegisterAllOutputs();
68   myTransformFilter->Delete();
69 }
70
71 void VISU_VectorsPL::ShallowCopy(VISU_PipeLine *thePipeLine){
72   VISU_DeformedShapePL::ShallowCopy(thePipeLine);
73   if(VISU_VectorsPL *aPipeLine = dynamic_cast<VISU_VectorsPL*>(thePipeLine)){
74     SetGlyphType(aPipeLine->GetGlyphType());
75     SetGlyphPos(aPipeLine->GetGlyphPos());
76   }
77 }
78
79
80 void VISU_VectorsPL::SetTransform(VTKViewer_Transform* theTransform){
81   myFieldTransform->SetSpaceTransform(theTransform);
82   myTransformFilter->SetTransform(theTransform);
83   myTransformFilter->Modified();
84 }
85 VTKViewer_Transform* VISU_VectorsPL::GetTransform(){
86   return myFieldTransform->GetSpaceTransform();
87 }
88
89
90 void VISU_VectorsPL::SetScale(float theScale) { 
91   if(myScaleFactor == theScale) return;
92   myScaleFactor = theScale;
93   myGlyph->SetScaleFactor(myScaleFactor);
94   Modified();
95 }
96 float VISU_VectorsPL::GetScale() { 
97   return myGlyph->GetScaleFactor();
98 }
99
100
101 void VISU_VectorsPL::Init(){
102   VISU_DeformedShapePL::Init();
103
104   myTypeGlyph = ARROW;
105   myPosGlyph = TAIL;
106 }
107
108
109 VISU_ScalarMapPL::THook* VISU_VectorsPL::DoHook(){
110   VISU::ToCellCenters(myTransformFilter,myCenters,myInput,myFieldTransform);
111   myGlyph->SetInput(myTransformFilter->GetOutput());
112   myGlyph->SetVectorModeToUseVector();
113   myGlyph->SetScaleModeToScaleByVector();
114   myGlyph->SetColorModeToColorByScalar();
115   return myGlyph->GetOutput();
116 }
117
118
119 void VISU_VectorsPL::Update(){
120   switch (myTypeGlyph) {
121   case ARROW: {
122     myGlyphSource->SetGlyphTypeToArrow();
123     myGlyphSource->SetFilled(0);
124     switch (myPosGlyph) {
125     case TAIL:
126       myGlyphSource->SetCenter(0.5, 0.0, 0.0);
127       break;
128     case HEAD:
129       myGlyphSource->SetCenter(-0.5, 0.0, 0.0);
130       break;
131     case CENTER:
132       myGlyphSource->SetCenter(0.0, 0.0, 0.0);
133     }
134 //     if(myPosGlyph == TAIL)
135 //       myGlyphSource->SetCenter(0.5, 0.0, 0.0);
136 //     else if(myPosGlyph == HEAD)
137 //       myGlyphSource->SetCenter(-0.5, 0.0, 0.0);
138     myGlyph->SetSource(myGlyphSource->GetOutput());
139   }
140     break;
141   case CONE2:
142   case CONE6: {
143     if (myTypeGlyph == CONE2)
144       myConeSource->SetResolution(3);
145     else
146       myConeSource->SetResolution(7);
147     myConeSource->SetHeight(1.0);
148     myConeSource->SetRadius(.1);
149     
150     switch (myPosGlyph) {
151     case TAIL:
152       myConeSource->SetCenter(0.5, 0.0, 0.0);
153       break;
154     case HEAD:
155       myConeSource->SetCenter(-0.5, 0.0, 0.0);
156       break;
157     case CENTER:
158       myConeSource->SetCenter(0.0, 0.0, 0.0);
159     }
160 //     if(myPosGlyph == TAIL)
161 //       myConeSource->SetCenter(0.5, 0.0, 0.0);
162 //     else if(myPosGlyph == HEAD)
163 //       myConeSource->SetCenter(-0.5, 0.0, 0.0);
164     myGlyph->SetSource(myConeSource->GetOutput());
165   }
166     break;
167   case NONE:
168   default: {
169     myGlyph->SetSource(myLineSource->GetOutput());
170   }
171   }
172
173   VISU_DeformedShapePL::Update();
174 }
175
176
177 void VISU_VectorsPL::SetMapScale(float theMapScale){
178   VISU_ScalarMapPL::SetMapScale(theMapScale);
179
180   myGlyph->SetScaleFactor(myScaleFactor*theMapScale);
181   myGlyph->Modified();
182 }