]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkVectorsVisu.cpp
#3274 creaVtk Feature New Normal - BooleanOperationPolyDataFilter BoxWidget ClipPol...
[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 (_vtkglyph==NULL) 
69         {
70                 if (GetOrientation()==-1) 
71                 {
72                         _vtkglyph = vtkGlyph3D::New(); 
73                 } // _orientation                       
74                 if ((GetOrientation()>=0) && (GetOrientation()<=2))
75                 {
76                         _vtkglyph = vtkGlyph3D::New(); 
77 //                              _vtkglyph = vtkGlyph2D::New(); 
78                 } // _orientation                       
79         } // _vtkglyph NULL
80
81
82      if(_active==true)
83      {
84
85                 if (GetDataObject()!=NULL) 
86                 {
87         #if VTK_MAJOR_VERSION <= 5
88                      _vtkglyph->SetInput( GetDataObject() );  
89         #else
90                      _vtkglyph->SetInputData( GetDataObject() );  
91         #endif
92                                 if(GetTypeForm()==1)                                                            // source Arrow
93                                 {
94         #if VTK_MAJOR_VERSION <= 5
95                                 _vtkglyph->SetSource( _vtkarrowsource->GetOutput() );
96         #else
97                                         _vtkarrowsource->Update();
98                                 _vtkglyph->SetSourceData( _vtkarrowsource->GetOutput() );
99         #endif
100                                 } else {                                                                                                // source Line
101         #if VTK_MAJOR_VERSION <= 5
102                                         _vtkglyph->SetSource( _vtklinesource->GetOutput() );    
103         #else
104                                         _vtklinesource->Update();
105                                         _vtkglyph->SetSourceData( _vtklinesource->GetOutput() );        
106         #endif
107                                 }
108                      _vtkglyph->SetScaleModeToScaleByVector();
109
110
111                         if (_externalLut==NULL)
112                         {
113                         _vtkglyph->SetColorModeToColorByVector();   
114                         } else {
115                                 _vtkglyph->SetColorModeToColorByScalar();   
116                         } // if _externalLut
117
118                      _vtkglyph->SetScaleFactor( GetScaleFactor() );
119                         _vtkglyph->Update();
120
121         #if VTK_MAJOR_VERSION <= 5
122                      _pdm->SetInput( _vtkglyph->GetOutput());
123         #else
124                      _pdm->SetInputData( _vtkglyph->GetOutput());
125         #endif
126
127         vtkPointData    *data   = _vtkglyph->GetOutput()->GetPointData();
128         //printf("EED -------------------------------------------\n");
129         //_vtkglyph->GetOutput()->Print(std::cout);
130         //printf("EED -------------------------------------------\n");
131         //data->Print(std::cout);
132         //int i,sizeDa = data->GetNumberOfArrays();
133         //for (i=0;i<sizeDa;i++)
134         //{
135         //      data->GetArray(i)->Print(std::cout);
136         //}
137
138                         if (_externalLut==NULL)
139                         {
140                                 _pdm->ScalarVisibilityOn();
141                                 _pdm->SetColorModeToMapScalars();
142                         //      _pdm->SetColorModeToDefault();
143                                 // _pdm->SetColorModeToDirectScalars();  // NOT compile
144                                 _pdm->SetScalarModeToUsePointFieldData();
145                         //      _pdm->ImmediateModeRenderingOn();   // obsolete
146                                 _LutEED->SetVectorModeToComponent();
147                                 //_LutEED->SetVectorModeToRGBColors();
148                                 //_LutEED->SetVectorModeToMagnitud();
149                         //         _pdm->SetScalarModeToUsePointFieldData();
150                      _pdm->SetLookupTable( _LutEED );
151                      _pdm->SelectColorArray( "GlyphVector" );
152                         } else {
153                                 data->SetActiveScalars("angle");
154
155                                 _pdm->ScalarVisibilityOn(); 
156                                 double scalarRange[2];
157                                 scalarRange[0]=0;
158                                 scalarRange[1]=40;
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         printf("EED warnnning  .....  vtkVectorsVisu::Process   clean scalar Range ......\n");
163         printf("EED warnnning  .....  vtkVectorsVisu::Process   clean scalar Range ......\n");
164                                 _pdm->SetScalarRange(scalarRange);
165                                 _pdm->SetColorModeToMapScalars();
166         //                      _pdm->SetColorModeToDefault();
167         //                       _pdm->SetColorModeToDirectScalars();  // NOT compile
168         //                      _pdm->SetScalarModeToUsePointFieldData();
169                                 _pdm->ImmediateModeRenderingOn();   // obsolete
170                              _pdm->SetLookupTable( _externalLut );
171                              _pdm->SelectColorArray( "angle" );
172                         }  // if _externalLut
173
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         printf("EED warnnning  .....  vtkVectorsVisu::Process   Clean angle ......\n");
178         printf("EED warnnning  .....  vtkVectorsVisu::Process   Clean angle ......\n");
179
180         /*
181         _vtkglyph->Update();
182         vtkPointData *pointdata=_vtkglyph->GetOutput()->GetPointData();
183         int i,size=pointdata->GetNumberOfArrays();
184         for (i=0;i<size;i++)
185         {
186                 vtkDataArray *array=pointdata->GetArray(i);
187                 printf(" vtkVectorsVisu::Process array name %d:<%s>  size:%d\n", i, array->GetName(), array->GetSize() );
188         }
189         */
190
191
192         //       vSliceMapperVec->SetLookupTable( vGreenToRedLut );
193         //       vSliceMapperVec->SetColorModeToMapScalars();
194
195         #if VTK_MAJOR_VERSION <= 5
196                         // ..
197         #else
198                      _pdm->Update();
199         #endif
200
201                         // Orientation -1 3D     OK
202          
203                         // Orientation 0 2D yz 
204                         if (GetOrientation()==0) 
205                         {
206                                 _trans->Identity();
207                                 _trans->Translate(900,0,0);
208                                 _actor->SetUserTransform(_trans);
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                         // Orientation 2 2D xy  
218                         if (GetOrientation()==2) 
219                         {
220                                 _trans->Identity();
221                                 _trans->Translate(0,0,-900);
222                                 _actor->SetUserTransform(_trans);
223                         }
224
225                     _actor->SetMapper( _pdm );
226                     _actor->GetProperty()->SetOpacity( GetOpacity() );
227                 } else {
228                         printf("EED Warnning! vtkVectorsVisu::Process   GetDataObject()  is EMPTY\n");
229                 }// if GetDataObject()!=NULL
230
231     } else {
232                 _vtkglyph->SetInputData( NULL );  
233                 _vtkglyph->Update();
234         }// if _active
235
236     VisibilityActor(); 
237 }
238