]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkVectorsVisu.cpp
3182 creaVtk Feature New Normal - Clean PlaneVecterVisu_Widget
[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
35
36 //------------------------------------------------------------------------------
37 vtkVectorsVisu::vtkVectorsVisu()
38   :vtkVectorsTensorsVisuBase()
39 {
40         _vtkarrowsource         = vtkArrowSource::New();
41         _vtkglyph                       = NULL;
42         _vtklinesource          = vtkLineSource ::New();
43         _trans                          = vtkTransform  ::New();
44
45         double point1[3];
46         double point2[3];
47         point1[0]=1;
48         point1[1]=0;
49         point1[2]=0;
50         point2[0]=-1;
51         point2[1]=0;
52         point2[2]=0;
53         _vtklinesource->SetPoint1( point1 );
54         _vtklinesource->SetPoint2( point2 );
55 }
56
57 //------------------------------------------------------------------------------
58 vtkVectorsVisu::~vtkVectorsVisu()
59 {
60 }
61
62
63 //------------------------------------------------------------------------------
64 void vtkVectorsVisu::Process()
65 {
66      if(_active==true)
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 VTK_MAJOR_VERSION <= 5
83          _vtkglyph->SetInput( GetDataObject() );  
84 #else
85          _vtkglyph->SetInputData( GetDataObject() );  
86 #endif
87                         if(GetTypeForm()==1)                                                            // source Arrow
88                         {
89 #if VTK_MAJOR_VERSION <= 5
90                         _vtkglyph->SetSource( _vtkarrowsource->GetOutput() );
91 #else
92                                 _vtkarrowsource->Update();
93                         _vtkglyph->SetSourceData( _vtkarrowsource->GetOutput() );
94 #endif
95                         } else {                                                                                                // source Line
96 #if VTK_MAJOR_VERSION <= 5
97                                 _vtkglyph->SetSource( _vtklinesource->GetOutput() );    
98 #else
99                                 _vtklinesource->Update();
100                                 _vtkglyph->SetSourceData( _vtklinesource->GetOutput() );        
101 #endif
102                         }
103          _vtkglyph->SetScaleModeToScaleByVector();
104          _vtkglyph->SetColorModeToColorByVector();
105          _vtkglyph->SetScaleFactor( GetScaleFactor() );
106                 _vtkglyph->Update();
107
108 #if VTK_MAJOR_VERSION <= 5
109          _pdm->SetInput( _vtkglyph->GetOutput());
110 #else
111          _pdm->SetInputData( _vtkglyph->GetOutput());
112 #endif
113
114 vtkPointData    *data   = _vtkglyph->GetOutput()->GetPointData();
115 //printf("EED -------------------------------------------\n");
116 //_vtkglyph->GetOutput()->Print(std::cout);
117 //printf("EED -------------------------------------------\n");
118 //data->Print(std::cout);
119 //int i,sizeDa = data->GetNumberOfArrays();
120 //for (i=0;i<sizeDa;i++)
121 //{
122 //      data->GetArray(i)->Print(std::cout);
123 //}
124
125         _pdm->ScalarVisibilityOn();
126         _pdm->SetColorModeToMapScalars();
127         //_pdm->SetColorModeToDefault();
128         // _pdm->SetColorModeToDirectScalars();  // NOT compile
129         _pdm->SetScalarModeToUsePointFieldData();
130         _pdm->ImmediateModeRenderingOn();
131
132         _LutEED->SetVectorModeToComponent();
133         //_LutEED->SetVectorModeToRGBColors();
134         //_LutEED->SetVectorModeToMagnitud();
135
136 //         _pdm->SetScalarModeToUsePointFieldData();
137          _pdm->SetLookupTable( _LutEED );
138          _pdm->SelectColorArray( "GlyphVector" );
139
140 //       vSliceMapperVec->SetLookupTable( vGreenToRedLut );
141 //       vSliceMapperVec->SetColorModeToMapScalars();
142
143 #if VTK_MAJOR_VERSION <= 5
144                 // ..
145 #else
146          _pdm->Update();
147 #endif
148
149                 // Orientation -1 3D     OK
150  
151                 // Orientation 0 2D yz 
152                 if (GetOrientation()==0) 
153                 {
154                         _trans->Identity();
155                         _trans->Translate(900,0,0);
156                         _actor->SetUserTransform(_trans);
157                 }
158
159
160                 // Orientation 1 2D xz  
161                 if (GetOrientation()==1) 
162                 {
163                         _trans->Identity();
164                         _trans->Translate(0,-900,0);
165                         _actor->SetUserTransform(_trans);
166                 }
167
168                 // Orientation 2 2D xy  
169                 if (GetOrientation()==2) 
170                 {
171                         _trans->Identity();
172                         _trans->Translate(0,0,-900);
173                         _actor->SetUserTransform(_trans);
174                 }
175
176          _actor->SetMapper( _pdm );
177          _actor->GetProperty()->SetOpacity( GetOpacity() );
178     }// if _active
179
180     VisibilityActor(); 
181 }
182