]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkVectorsVisu.cpp
ff49f557748d752cff0bd8be9224cdc5d392be26
[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 = vtkGlyph2D::New(); 
77                         } // _orientation                       
78                 } // _vtkglyph NULL
79
80
81 #if VTK_MAJOR_VERSION <= 5
82          _vtkglyph->SetInput( GetDataObject() );  
83 #else
84          _vtkglyph->SetInputData( GetDataObject() );  
85 #endif
86                         if(GetTypeForm()==1)                                                            // source Arrow
87                         {
88 #if VTK_MAJOR_VERSION <= 5
89                         _vtkglyph->SetSource( _vtkarrowsource->GetOutput() );
90 #else
91                                 _vtkarrowsource->Update();
92                         _vtkglyph->SetSourceData( _vtkarrowsource->GetOutput() );
93 #endif
94                         } else {                                                                                                // source Line
95 #if VTK_MAJOR_VERSION <= 5
96                                 _vtkglyph->SetSource( _vtklinesource->GetOutput() );    
97 #else
98                                 _vtklinesource->Update();
99                                 _vtkglyph->SetSourceData( _vtklinesource->GetOutput() );        
100 #endif
101                         }
102          _vtkglyph->SetScaleModeToScaleByVector();
103          _vtkglyph->SetColorModeToColorByVector();
104          _vtkglyph->SetScaleFactor( GetScaleFactor() );
105                 _vtkglyph->Update();
106
107 #if VTK_MAJOR_VERSION <= 5
108          _pdm->SetInput( _vtkglyph->GetOutput());
109 #else
110          _pdm->SetInputData( _vtkglyph->GetOutput());
111 #endif
112
113 vtkPointData    *data   = _vtkglyph->GetOutput()->GetPointData();
114 //printf("EED -------------------------------------------\n");
115 //_vtkglyph->GetOutput()->Print(std::cout);
116 //printf("EED -------------------------------------------\n");
117 //data->Print(std::cout);
118 //int i,sizeDa = data->GetNumberOfArrays();
119 //for (i=0;i<sizeDa;i++)
120 //{
121 //      data->GetArray(i)->Print(std::cout);
122 //}
123
124         _pdm->ScalarVisibilityOn();
125         _pdm->SetColorModeToMapScalars();
126         //_pdm->SetColorModeToDefault();
127         // _pdm->SetColorModeToDirectScalars();  // NOT compile
128         _pdm->SetScalarModeToUsePointFieldData();
129         _pdm->ImmediateModeRenderingOn();
130
131         _LutEED->SetVectorModeToComponent();
132         //_LutEED->SetVectorModeToRGBColors();
133         //_LutEED->SetVectorModeToMagnitud();
134
135 //         _pdm->SetScalarModeToUsePointFieldData();
136          _pdm->SetLookupTable( _LutEED );
137          _pdm->SelectColorArray( "GlyphVector" );
138
139 //       vSliceMapperVec->SetLookupTable( vGreenToRedLut );
140 //       vSliceMapperVec->SetColorModeToMapScalars();
141
142 #if VTK_MAJOR_VERSION <= 5
143                 // ..
144 #else
145          _pdm->Update();
146 #endif
147
148                 // Orientation -1 3D     OK
149                 // Orientation  2 2D xy  OK
150  
151                 // Orientation 0 2D yz  
152                 if (GetOrientation()==0) 
153                 {
154                         _trans->Identity();
155                         _trans->Translate(900,0,0);
156                         _trans->RotateWXYZ(-90,0,1,0);
157                         _actor->SetUserTransform(_trans);
158                 }
159
160                 // Orientation 1 2D xz  
161                 if (GetOrientation()==1) 
162                 {
163                         _trans->Identity();
164                         _trans->RotateWXYZ(90,1,0,0);
165                         _actor->SetUserTransform(_trans);
166                 }
167
168          _actor->SetMapper( _pdm );
169          _actor->GetProperty()->SetOpacity( GetOpacity() );
170     }// if _active
171
172     VisibilityActor(); 
173 }
174