]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkTensorsVisu.cpp
#3110 creaVtk Bug New Normal - branch vtk7itk4 compilation with vtk7
[creaVtk.git] / lib / creaVtk / vtkTensorsVisu.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 "vtkTensorsVisu.h"
29
30 #include "vtkProperty.h"
31 #include "vtkDoubleArray.h"
32
33
34 //------------------------------------------------------------------------
35 vtkTensorsVisu::vtkTensorsVisu() : vtkVectorsTensorsVisuBase()
36 {
37         ss                                      = vtkSphereSource::New();
38         superquadratic          = vtkSuperquadricSource::New();
39         cs                                      = vtkCubeSource::New(); 
40         tg                                      = vtkTensorGlyph::New();
41         pdn                             = vtkPolyDataNormals::New();
42         pd                                      = vtkPolyData::New();
43         pod                             = vtkPointData::New();
44 }
45
46 //------------------------------------------------------------------------
47 vtkTensorsVisu::~vtkTensorsVisu()
48 {
49 }
50
51
52 //------------------------------------------------------------------------
53 void vtkTensorsVisu::Process()
54 {
55 printf("EED vtkTensorsVisu::Process() start\n");
56   if (_active==true)
57   {
58         if(GetTypeForm()==2)                                                            // source superquadratic
59         {
60                 superquadratic->SetThetaResolution(20);
61                 superquadratic->SetPhiResolution(20);
62 #if VTK_MAJOR_VERSION <= 5
63                 tg->SetSource(superquadratic->GetOutput());
64 #else
65                 tg->SetSourceData(superquadratic->GetOutput());
66 #endif
67         } else if(GetTypeForm()==1) {                                   // source sphere
68 #if VTK_MAJOR_VERSION <= 5
69                 tg->SetSource(ss->GetOutput());
70 #else
71                 tg->SetSourceData(ss->GetOutput());
72 #endif
73         } else {                                                                                                // source cube
74 #if VTK_MAJOR_VERSION <= 5
75                 tg->SetSource(cs->GetOutput());         
76 #else
77                 tg->SetSourceData(cs->GetOutput());     
78 #endif
79         }
80
81 #if VTK_MAJOR_VERSION <= 5
82         tg->SetInput( GetDataObject() );
83 #else
84         tg->SetInputData( GetDataObject() );
85 #endif
86         //              tg->ScalingOn();
87         //              tg->SetScaling(25);
88         tg->SetScaleFactor( GetScaleFactor() );
89
90 printf("EED vtkTensorsVisu::Process() 1\n");
91
92
93         //The normals are needed to generate the right colors and if
94         // not used some of the glyphs are black.
95 //EED 2017-01-01 Migration VTK7
96 #if VTK_MAJOR_VERSION <= 5
97         pdn->SetInput(tg->GetOutput());
98         _pdm->SetInput( pdn->GetOutput() );
99 #else
100 printf("EED vtkTensorsVisu::Process() 1.1\n");
101         pdn->SetInputData(tg->GetOutput());
102 printf("EED vtkTensorsVisu::Process() 1.2\n");
103         _pdm->SetInputData( pdn->GetOutput() );
104         _pdm->Update();
105 #endif
106 printf("EED vtkTensorsVisu::Process() 1.3\n");
107         _actor->SetMapper( _pdm );
108 printf("EED vtkTensorsVisu::Process() 1.4\n");
109    _actor->GetProperty()->SetOpacity( GetOpacity() );
110
111
112
113
114 printf("EED vtkTensorsVisu::Process() 1.5\n");
115    tg->SetColorModeToEigenvalues();
116 //   tg->SetColorModeToScalars();
117 printf("EED vtkTensorsVisu::Process() 1.6\n");
118    tg->Update();
119
120 printf("EED vtkTensorsVisu::Process() 1.7\n");
121
122
123
124 //EED 2017-01-01 Migration VTK7
125 #if VTK_MAJOR_VERSION <= 5
126         pd = tg->GetOutput();
127         pd->Update();
128 #else
129         tg->Update();
130         pd = tg->GetOutput();
131 #endif
132
133         pod = pd->GetPointData();
134 printf("EED vtkTensorsVisu::Process() 1.8\n");
135         pod->Update();
136 printf("EED vtkTensorsVisu::Process() 1.9\n");
137
138         tg->Update();
139         vtkPolyData             *pd_pdn                         = pdn->GetOutput();
140         vtkPointData    *pointdata_pdn          = pd_pdn->GetPointData();
141
142         vtkPolyData             *pd_tg                          = tg->GetOutput();
143         vtkPointData    *pointdata_tg           = pd_tg->GetPointData();
144
145 printf("EED vtkTensorsVisu::Process() 1.20\n");
146         vtkPolyData             *pd_do                          = (vtkPolyData*)GetDataObject();
147         vtkPointData    *pointdata_do           = pd_do->GetPointData();
148
149         int numPnts = ((vtkPolyData *)GetDataObject())->GetNumberOfPoints();
150
151         vtkIdType numSourcePts;
152 //      vtkIdType numSourceCells;
153
154 printf("EED vtkTensorsVisu::Process() 1.22\n");
155         vtkPoints *sourcePts    = tg->GetSource()->GetPoints();
156 printf("EED vtkTensorsVisu::Process() 1.23\n"); 
157
158
159         numSourcePts                    = sourcePts->GetNumberOfPoints();
160 //      numSourceCells = tg->GetSource()->GetNumberOfCells();
161
162
163 printf("EED vtkTensorsVisu::Process() 2\n");
164
165
166         vtkDataArray *tensorsArray = pointdata_do->GetArray("tensors");
167         if (tensorsArray)
168    {
169                 vtkDoubleArray  *newScalarArray                         = vtkDoubleArray::New();
170                 newScalarArray->SetName( "NormalsEED" );
171                 newScalarArray->SetNumberOfComponents(3); 
172                 int     iNumPts,iNumSourcePts;
173                 int             iNormalsEED=0;
174                 double  *normalValue;
175                 double   sumEigenvalue,sumEigenvalue1,sumEigenvalue2,sumEigenvalue3;
176                 unsigned char   dirx,diry,dirz;
177                 int      idEigen;
178                 for (iNumPts=0;iNumPts<numPnts;iNumPts++)
179                 {
180                         normalValue = tensorsArray->GetTuple9(iNumPts);
181                 sumEigenvalue1 = sqrt (normalValue[0]*normalValue[0] + normalValue[1]*normalValue[1] + normalValue[2]*normalValue[2]);
182                 sumEigenvalue2 = sqrt (normalValue[3]*normalValue[3] + normalValue[4]*normalValue[4] + normalValue[5]*normalValue[5]);
183                 sumEigenvalue3 = sqrt (normalValue[6]*normalValue[6] + normalValue[7]*normalValue[7] + normalValue[8]*normalValue[8]);
184
185                         if ((sumEigenvalue1>=sumEigenvalue2) && (sumEigenvalue1>=sumEigenvalue3))
186                         {
187                                 sumEigenvalue=sumEigenvalue1;
188                                 idEigen=0;
189                         }
190                         if ((sumEigenvalue2>sumEigenvalue1) && (sumEigenvalue2>=sumEigenvalue3))
191                         {
192                                 sumEigenvalue=sumEigenvalue2;
193                                 idEigen=3;
194                         }
195                         if ((sumEigenvalue3>=sumEigenvalue1) && (sumEigenvalue3>=sumEigenvalue2))
196                         {
197                                 sumEigenvalue=sumEigenvalue3;
198                                 idEigen=6;
199                         }
200
201                         dirx = (unsigned char)( 255*fabs(normalValue[idEigen+0]/sumEigenvalue) );
202                         diry = (unsigned char)( 255*fabs(normalValue[idEigen+1]/sumEigenvalue) );
203                         dirz = (unsigned char)( 255*fabs(normalValue[idEigen+2]/sumEigenvalue) );
204
205                         for (iNumSourcePts=0;iNumSourcePts<numSourcePts;iNumSourcePts++)
206                         {
207 //                              newScalarArray->InsertTuple3( iNormalsEED, dirx,diry,dirz);
208                                 newScalarArray->InsertTuple3( iNormalsEED, normalValue[idEigen+0],normalValue[idEigen+1],normalValue[idEigen+2] );
209                                 iNormalsEED++;
210                         } // for iNumSourcePts
211
212                 } // for iNumPts
213
214
215                 pointdata_tg->RemoveArray( "NormalsEED" );
216                 pointdata_tg->AddArray( newScalarArray );
217 //              pointdata_pdn->Update();
218                 tg->Update();
219         } // if  tensorsArray
220
221
222
223
224
225 printf("EED vtkTensorsVisu::Process() 3\n");
226
227         _pdm->ScalarVisibilityOn();
228         _pdm->SetColorModeToMapScalars();
229         //_pdm->SetColorModeToDefault();
230         // _pdm->SetColorModeToDirectScalars();  // NOT compile
231         _pdm->SetScalarModeToUsePointFieldData();
232         _pdm->ImmediateModeRenderingOn();
233
234         _LutEED->SetVectorModeToComponent();
235         //_LutEED->SetVectorModeToRGBColors();
236         //_LutEED->SetVectorModeToMagnitud();
237         _pdm->SetLookupTable( _LutEED );
238         _pdm->SelectColorArray( "NormalsEED" );
239
240 //EED 2017-01-01 Migration VTK7
241 #if VTK_MAJOR_VERSION <= 5
242   //...
243 #else
244         _pdm->Update();
245 #endif
246
247 /*
248                         int i,sizeDa = pointdata_tg->GetNumberOfArrays();
249                         printf("EED vtkTensorsVisu::Process  sizeDa %d \n", sizeDa );
250                         for (i=0;i<sizeDa;i++)
251                         {
252                                 int faces = pointdata_tg->GetArray(i)->GetSize() / numPnts;
253 //pointdata_pdn->GetArray(i)->Print( std::cout );
254                                 printf("EED vtkTensorsVisu::Process-name %d, %s, size=%d   %d \n", i, pointdata_tg->GetArrayName(i) , pointdata_tg->GetArray(i)->GetSize(), faces );
255
256                         }
257 */
258
259
260   } // _active
261 printf("EED vtkTensorsVisu::Process() 4\n");
262
263     VisibilityActor(); 
264
265 printf("EED vtkTensorsVisu::Process() END\n");
266
267
268 }
269