]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkVectorsVisu.cpp
#3470 merge vtk8itk5wx3-mingw64
[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 #include <vtkAppendPolyData.h>
39
40 //------------------------------------------------------------------------------
41 vtkVectorsVisu::vtkVectorsVisu()
42   :vtkVectorsTensorsVisuBase()
43 {
44                                         _vtkarrowsource                 = vtkArrowSource::New();
45                                         _vtkglyph                               = NULL;
46                                         _vtklineGlyphPolyData   = NULL;
47                                         _trans                                  = vtkTransform  ::New();
48
49                         double  sizeCross                               = 0.05; 
50         
51         double point1[3];
52         double point2[3];
53
54         point1[0] = 1;
55         point1[1] = 0;
56         point1[2] = 0;
57         point2[0] = -1;
58         point2[1] = 0;
59         point2[2] = 0;
60         vtkLineSource   *vtklinesource1                 = vtkLineSource ::New();
61         vtklinesource1->SetPoint1( point1 );
62         vtklinesource1->SetPoint2( point2 );
63         vtklinesource1->Update();
64
65         point1[0] = 0;
66         point1[1] = sizeCross;
67         point1[2] = 0;
68         point2[0] = 0;
69         point2[1] = -sizeCross;
70         point2[2] = 0;
71         vtkLineSource   *vtklinesource2                 = vtkLineSource ::New();
72         vtklinesource2->SetPoint1( point1 );
73         vtklinesource2->SetPoint2( point2 );
74         vtklinesource2->Update();
75
76         point1[0] = 0;
77         point1[1] = 0;
78         point1[2] = sizeCross;
79         point2[0] = 0;
80         point2[1] = 0;
81         point2[2] = -sizeCross;
82         vtkLineSource   *vtklinesource3                 = vtkLineSource ::New();
83         vtklinesource3->SetPoint1( point1 );
84         vtklinesource3->SetPoint2( point2 );
85         vtklinesource3->Update();
86         
87         
88         vtkAppendPolyData *appendPolyData = vtkAppendPolyData::New();
89         appendPolyData->AddInputData( vtklinesource1->GetOutput() );
90         appendPolyData->AddInputData( vtklinesource2->GetOutput() );
91         appendPolyData->AddInputData( vtklinesource3->GetOutput() );
92         appendPolyData->Update();
93         _vtklineGlyphPolyData = appendPolyData->GetOutput();
94 }
95
96 //------------------------------------------------------------------------------
97 vtkVectorsVisu::~vtkVectorsVisu()
98 {
99 }
100
101
102 //------------------------------------------------------------------------------
103 void vtkVectorsVisu::Process()
104 {
105         if (_vtkglyph==NULL) 
106         {
107                 if (GetOrientation()==-1) 
108                 {
109                         _vtkglyph = vtkGlyph3D::New(); 
110                 } // _orientation                       
111                 if ((GetOrientation()>=0) && (GetOrientation()<=2))
112                 {
113                         _vtkglyph = vtkGlyph3D::New(); 
114 //                              _vtkglyph = vtkGlyph2D::New(); 
115                 } // _orientation                       
116         } // _vtkglyph NULL
117
118
119      if(_active==true)
120      {
121
122                 if (GetDataObject()!=NULL) 
123                 {
124         #if VTK_MAJOR_VERSION <= 5
125                      _vtkglyph->SetInput( GetDataObject() );  
126         #else
127                      _vtkglyph->SetInputData( GetDataObject() );  
128         #endif
129                                 if(GetTypeForm()==1)                                                            // source Arrow
130                                 {
131         #if VTK_MAJOR_VERSION <= 5
132                                 _vtkglyph->SetSource( _vtkarrowsource->GetOutput() );
133         #else
134                                         _vtkarrowsource->Update();
135                                 _vtkglyph->SetSourceData( _vtkarrowsource->GetOutput() );
136         #endif
137                                 } else {                                                                                                // source Line
138         #if VTK_MAJOR_VERSION <= 5
139                                         _vtkglyph->SetSource( _vtklineGlyphPolyData );          
140         #else
141                                         _vtkglyph->SetSourceData( _vtklineGlyphPolyData );      
142         #endif
143                                 }
144                      _vtkglyph->SetScaleModeToScaleByVector();
145
146
147                         if (_externalLut==NULL)
148                         {
149                         _vtkglyph->SetColorModeToColorByVector();   
150                         } else {
151                                 _vtkglyph->SetColorModeToColorByScalar();   
152                         } // if _externalLut
153
154                      _vtkglyph->SetScaleFactor( GetScaleFactor() );
155                         _vtkglyph->Update();
156
157         #if VTK_MAJOR_VERSION <= 5
158                      _pdm->SetInput( _vtkglyph->GetOutput());
159         #else
160                      _pdm->SetInputData( _vtkglyph->GetOutput());
161         #endif
162
163         vtkPointData    *data   = _vtkglyph->GetOutput()->GetPointData();
164         //printf("EED -------------------------------------------\n");
165         //_vtkglyph->GetOutput()->Print(std::cout);
166         //printf("EED -------------------------------------------\n");
167         //data->Print(std::cout);
168         //int i,sizeDa = data->GetNumberOfArrays();
169         //for (i=0;i<sizeDa;i++)
170         //{
171         //      data->GetArray(i)->Print(std::cout);
172         //}
173
174                         if (_externalLut==NULL)
175                         {
176                                 _pdm->ScalarVisibilityOn();
177                                 _pdm->SetColorModeToMapScalars();
178                         //      _pdm->SetColorModeToDefault();
179                                 // _pdm->SetColorModeToDirectScalars();  // NOT compile
180                                 _pdm->SetScalarModeToUsePointFieldData();
181                         //      _pdm->ImmediateModeRenderingOn();   // obsolete
182                                 _LutEED->SetVectorModeToComponent();
183                                 //_LutEED->SetVectorModeToRGBColors();
184                                 //_LutEED->SetVectorModeToMagnitud();
185                         //         _pdm->SetScalarModeToUsePointFieldData();
186                      _pdm->SetLookupTable( _LutEED );
187                      _pdm->SelectColorArray( "GlyphVector" );
188                         } else {
189                                 data->SetActiveScalars("angle");
190
191                                 _pdm->ScalarVisibilityOn(); 
192                                 double scalarRange[2];
193                                 scalarRange[0]=0;
194                                 scalarRange[1]=40;
195         printf("EED warnnning  .....  vtkVectorsVisu::Process   clean scalar Range ......\n");
196         printf("EED warnnning  .....  vtkVectorsVisu::Process   clean scalar Range ......\n");
197         printf("EED warnnning  .....  vtkVectorsVisu::Process   clean scalar Range ......\n");
198         printf("EED warnnning  .....  vtkVectorsVisu::Process   clean scalar Range ......\n");
199         printf("EED warnnning  .....  vtkVectorsVisu::Process   clean scalar Range ......\n");
200                                 _pdm->SetScalarRange(scalarRange);
201                                 _pdm->SetColorModeToMapScalars();
202         //                      _pdm->SetColorModeToDefault();
203         //                       _pdm->SetColorModeToDirectScalars();  // NOT compile
204         //                      _pdm->SetScalarModeToUsePointFieldData();
205 //                              _pdm->ImmediateModeRenderingOn();   // obsolete
206                              _pdm->SetLookupTable( _externalLut );
207                              _pdm->SelectColorArray( "angle" );
208                         }  // if _externalLut
209
210         printf("EED warnnning  .....  vtkVectorsVisu::Process   Clean angle ......\n");
211         printf("EED warnnning  .....  vtkVectorsVisu::Process   Clean angle ......\n");
212         printf("EED warnnning  .....  vtkVectorsVisu::Process   Clean angle ......\n");
213         printf("EED warnnning  .....  vtkVectorsVisu::Process   Clean angle ......\n");
214         printf("EED warnnning  .....  vtkVectorsVisu::Process   Clean angle ......\n");
215
216         /*
217         _vtkglyph->Update();
218         vtkPointData *pointdata=_vtkglyph->GetOutput()->GetPointData();
219         int i,size=pointdata->GetNumberOfArrays();
220         for (i=0;i<size;i++)
221         {
222                 vtkDataArray *array=pointdata->GetArray(i);
223                 printf(" vtkVectorsVisu::Process array name %d:<%s>  size:%d\n", i, array->GetName(), array->GetSize() );
224         }
225         */
226
227
228         //       vSliceMapperVec->SetLookupTable( vGreenToRedLut );
229         //       vSliceMapperVec->SetColorModeToMapScalars();
230
231         #if VTK_MAJOR_VERSION <= 5
232                         // ..
233         #else
234                      _pdm->Update();
235         #endif
236
237                         // Orientation -1 3D     OK
238          
239                         // Orientation 0 2D yz 
240                         if (GetOrientation()==0) 
241                         {
242                                 _trans->Identity();
243                                 _trans->Translate(900,0,0);
244                                 _actor->SetUserTransform(_trans);
245                         }
246                         // Orientation 1 2D xz  
247                         if (GetOrientation()==1) 
248                         {
249                                 _trans->Identity();
250                                 _trans->Translate(0,-900,0);
251                                 _actor->SetUserTransform(_trans);
252                         }
253                         // Orientation 2 2D xy  
254                         if (GetOrientation()==2) 
255                         {
256                                 _trans->Identity();
257                                 _trans->Translate(0,0,-900);
258                                 _actor->SetUserTransform(_trans);
259                         }
260
261                     _actor->SetMapper( _pdm );
262                     _actor->GetProperty()->SetOpacity( GetOpacity() );
263                 } else {
264                         printf("EED Warnning! vtkVectorsVisu::Process   GetDataObject()  is EMPTY\n");
265                 }// if GetDataObject()!=NULL
266
267         _pdm->ScalarVisibilityOn();
268         _pdm->SetColorModeToMapScalars();
269         //_pdm->SetColorModeToDefault();
270         // _pdm->SetColorModeToDirectScalars();  // NOT compile
271         _pdm->SetScalarModeToUsePointFieldData();
272
273 //EED2021-09-03 Deprecated. Removed in vtk 8.1
274 //      _pdm->ImmediateModeRenderingOn();
275
276         _LutEED->SetVectorModeToComponent();
277         //_LutEED->SetVectorModeToRGBColors();
278         //_LutEED->SetVectorModeToMagnitud();
279
280 //         _pdm->SetScalarModeToUsePointFieldData();
281          _pdm->SetLookupTable( _LutEED );
282          _pdm->SelectColorArray( "GlyphVector" );
283
284 //       vSliceMapperVec->SetLookupTable( vGreenToRedLut );
285 //       vSliceMapperVec->SetColorModeToMapScalars();
286
287 #if VTK_MAJOR_VERSION <= 5
288                 // ..
289 #else
290          _pdm->Update();
291 #endif
292          _actor->SetMapper( _pdm );
293          _actor->GetProperty()->SetOpacity( GetOpacity() );
294     } else {
295                 _vtkglyph->SetInputData( NULL );  
296                 _vtkglyph->Update();
297         }// if _active
298
299     VisibilityActor(); 
300 }
301