]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkVectorsVisu.cpp
c29dace97f7f3ddbccc12d64f61bc51ba4331aa1
[creaVtk.git] / lib / creaVtk / vtkVectorsVisu.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sante)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and
11 #  abiding by the rules of distribution of free software. You can  use,
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B
13 #  license as circulated by CEA, CNRS and INRIA at the following URL
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability.
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27
28 #include "vtkVectorsVisu.h"
29
30 #include "vtkProperty.h"
31
32 //Borrame
33 #include "vtkPointData.h"
34 #include "vtkArrayData.h"
35 #include "vtkDataObject.h"
36 #include <vtkPointData.h>
37
38 //------------------------------------------------------------------------------
39 vtkVectorsVisu::vtkVectorsVisu()
40   :vtkVectorsTensorsVisuBase()
41 {
42         _vtkarrowsource         = vtkArrowSource::New();
43         _vtkglyph                       = NULL;
44         _vtklinesource          = vtkLineSource ::New();
45         _trans                          = vtkTransform  ::New();
46
47         double point1[3];
48         double point2[3];
49         point1[0]=1;
50         point1[1]=0;
51         point1[2]=0;
52         point2[0]=-1;
53         point2[1]=0;
54         point2[2]=0;
55         _vtklinesource->SetPoint1( point1 );
56         _vtklinesource->SetPoint2( point2 );
57 }
58
59 //------------------------------------------------------------------------------
60 vtkVectorsVisu::~vtkVectorsVisu()
61 {
62 }
63
64
65 //------------------------------------------------------------------------------
66 void vtkVectorsVisu::Process()
67 {
68      if(_active==true)
69      {
70                 if (_vtkglyph==NULL) 
71                 {
72                         if (GetOrientation()==-1) 
73                         {
74                                 _vtkglyph = vtkGlyph3D::New(); 
75                         } // _orientation                       
76                         if ((GetOrientation()>=0) && (GetOrientation()<=2))
77                         {
78                                 _vtkglyph = vtkGlyph3D::New(); 
79 //                              _vtkglyph = vtkGlyph2D::New(); 
80                         } // _orientation                       
81                 } // _vtkglyph NULL
82
83
84 #if VTK_MAJOR_VERSION <= 5
85          _vtkglyph->SetInput( GetDataObject() );  
86 #else
87          _vtkglyph->SetInputData( GetDataObject() );  
88 #endif
89                         if(GetTypeForm()==1)                                                            // source Arrow
90                         {
91 #if VTK_MAJOR_VERSION <= 5
92                         _vtkglyph->SetSource( _vtkarrowsource->GetOutput() );
93 #else
94                                 _vtkarrowsource->Update();
95                         _vtkglyph->SetSourceData( _vtkarrowsource->GetOutput() );
96 #endif
97                         } else {                                                                                                // source Line
98 #if VTK_MAJOR_VERSION <= 5
99                                 _vtkglyph->SetSource( _vtklinesource->GetOutput() );    
100 #else
101                                 _vtklinesource->Update();
102                                 _vtkglyph->SetSourceData( _vtklinesource->GetOutput() );        
103 #endif
104                         }
105          _vtkglyph->SetScaleModeToScaleByVector();
106
107
108                 if (_externalLut==NULL)
109                 {
110                 _vtkglyph->SetColorModeToColorByVector();   
111                 } else {
112                         _vtkglyph->SetColorModeToColorByScalar();   
113                 } // if _externalLut
114
115          _vtkglyph->SetScaleFactor( GetScaleFactor() );
116                 _vtkglyph->Update();
117
118 #if VTK_MAJOR_VERSION <= 5
119          _pdm->SetInput( _vtkglyph->GetOutput());
120 #else
121          _pdm->SetInputData( _vtkglyph->GetOutput());
122 #endif
123
124 vtkPointData    *data   = _vtkglyph->GetOutput()->GetPointData();
125 //printf("EED -------------------------------------------\n");
126 //_vtkglyph->GetOutput()->Print(std::cout);
127 //printf("EED -------------------------------------------\n");
128 //data->Print(std::cout);
129 //int i,sizeDa = data->GetNumberOfArrays();
130 //for (i=0;i<sizeDa;i++)
131 //{
132 //      data->GetArray(i)->Print(std::cout);
133 //}
134
135
136                 if (_externalLut==NULL)
137                 {
138                         _pdm->ScalarVisibilityOn();
139                         _pdm->SetColorModeToMapScalars();
140                 //      _pdm->SetColorModeToDefault();
141                         // _pdm->SetColorModeToDirectScalars();  // NOT compile
142                         _pdm->SetScalarModeToUsePointFieldData();
143                 //      _pdm->ImmediateModeRenderingOn();   // obsolete
144                         _LutEED->SetVectorModeToComponent();
145                         //_LutEED->SetVectorModeToRGBColors();
146                         //_LutEED->SetVectorModeToMagnitud();
147                 //         _pdm->SetScalarModeToUsePointFieldData();
148          _pdm->SetLookupTable( _LutEED );
149          _pdm->SelectColorArray( "GlyphVector" );
150                 } else {
151                         data->SetActiveScalars("angle");
152
153                         _pdm->ScalarVisibilityOn(); 
154                         double scalarRange[2];
155                         scalarRange[0]=0;
156                         scalarRange[1]=40;
157 printf("EED warnnning  .....  vtkVectorsVisu::Process   clean scalar Range ......\n");
158 printf("EED warnnning  .....  vtkVectorsVisu::Process   clean scalar Range ......\n");
159 printf("EED warnnning  .....  vtkVectorsVisu::Process   clean scalar Range ......\n");
160 printf("EED warnnning  .....  vtkVectorsVisu::Process   clean scalar Range ......\n");
161 printf("EED warnnning  .....  vtkVectorsVisu::Process   clean scalar Range ......\n");
162                     _pdm->SetScalarRange(scalarRange);
163                         _pdm->SetColorModeToMapScalars();
164 //                      _pdm->SetColorModeToDefault();
165 //                       _pdm->SetColorModeToDirectScalars();  // NOT compile
166 //                      _pdm->SetScalarModeToUsePointFieldData();
167                         _pdm->ImmediateModeRenderingOn();   // obsolete
168                  _pdm->SetLookupTable( _externalLut );
169                  _pdm->SelectColorArray( "angle" );
170                 }  // if _externalLut
171
172 printf("EED warnnning  .....  vtkVectorsVisu::Process   Clean angle ......\n");
173 printf("EED warnnning  .....  vtkVectorsVisu::Process   Clean angle ......\n");
174 printf("EED warnnning  .....  vtkVectorsVisu::Process   Clean angle ......\n");
175 printf("EED warnnning  .....  vtkVectorsVisu::Process   Clean angle ......\n");
176 printf("EED warnnning  .....  vtkVectorsVisu::Process   Clean angle ......\n");
177
178 /*
179 _vtkglyph->Update();
180 vtkPointData *pointdata=_vtkglyph->GetOutput()->GetPointData();
181 int i,size=pointdata->GetNumberOfArrays();
182 for (i=0;i<size;i++)
183 {
184         vtkDataArray *array=pointdata->GetArray(i);
185         printf(" vtkVectorsVisu::Process array name %d:<%s>  size:%d\n", i, array->GetName(), array->GetSize() );
186 }
187 */
188
189
190 //       vSliceMapperVec->SetLookupTable( vGreenToRedLut );
191 //       vSliceMapperVec->SetColorModeToMapScalars();
192
193 #if VTK_MAJOR_VERSION <= 5
194                 // ..
195 #else
196          _pdm->Update();
197 #endif
198
199                 // Orientation -1 3D     OK
200  
201                 // Orientation 0 2D yz 
202                 if (GetOrientation()==0) 
203                 {
204                         _trans->Identity();
205                         _trans->Translate(900,0,0);
206                         _actor->SetUserTransform(_trans);
207                 }
208
209
210                 // Orientation 1 2D xz  
211                 if (GetOrientation()==1) 
212                 {
213                         _trans->Identity();
214                         _trans->Translate(0,-900,0);
215                         _actor->SetUserTransform(_trans);
216                 }
217
218                 // Orientation 2 2D xy  
219                 if (GetOrientation()==2) 
220                 {
221                         _trans->Identity();
222                         _trans->Translate(0,0,-900);
223                         _actor->SetUserTransform(_trans);
224                 }
225
226          _actor->SetMapper( _pdm );
227          _actor->GetProperty()->SetOpacity( GetOpacity() );
228     }// if _active
229
230     VisibilityActor(); 
231 }
232