2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
28 #include "vtkTensorsVisu.h"
30 #include "vtkProperty.h"
31 #include "vtkDoubleArray.h"
34 //------------------------------------------------------------------------
35 vtkTensorsVisu::vtkTensorsVisu() : vtkVectorsTensorsVisuBase()
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();
46 //------------------------------------------------------------------------
47 vtkTensorsVisu::~vtkTensorsVisu()
52 //------------------------------------------------------------------------
53 void vtkTensorsVisu::Process()
57 if(GetTypeForm()==2) // source superquadratic
59 superquadratic->SetThetaResolution(20);
60 superquadratic->SetPhiResolution(20);
61 #if VTK_MAJOR_VERSION <= 5
62 tg->SetSource(superquadratic->GetOutput());
64 tg->SetSourceData(superquadratic->GetOutput());
66 } else if(GetTypeForm()==1) { // source sphere
67 #if VTK_MAJOR_VERSION <= 5
68 tg->SetSource(ss->GetOutput());
70 tg->SetSourceData(ss->GetOutput());
72 } else { // source cube
73 #if VTK_MAJOR_VERSION <= 5
74 tg->SetSource(cs->GetOutput());
76 tg->SetSourceData(cs->GetOutput());
80 #if VTK_MAJOR_VERSION <= 5
81 tg->SetInput( GetDataObject() );
83 tg->SetInputData( GetDataObject() );
86 // tg->SetScaling(25);
87 tg->SetScaleFactor( GetScaleFactor() );
89 //The normals are needed to generate the right colors and if
90 // not used some of the glyphs are black.
91 //EED 2017-01-01 Migration VTK7
92 #if VTK_MAJOR_VERSION <= 5
93 pdn->SetInput(tg->GetOutput());
94 _pdm->SetInput( pdn->GetOutput() );
96 pdn->SetInputData(tg->GetOutput());
97 _pdm->SetInputData( pdn->GetOutput() );
99 _actor->SetMapper( _pdm );
100 _actor->GetProperty()->SetOpacity( GetOpacity() );
102 tg->SetColorModeToEigenvalues();
103 // tg->SetColorModeToScalars();
106 //EED 2017-01-01 Migration VTK7
107 #if VTK_MAJOR_VERSION <= 5
108 pd = tg->GetOutput();
112 pd = tg->GetOutput();
115 pod = pd->GetPointData();
119 vtkPolyData *pd_pdn = pdn->GetOutput();
120 vtkPointData *pointdata_pdn = pd_pdn->GetPointData();
122 vtkPolyData *pd_tg = tg->GetOutput();
123 vtkPointData *pointdata_tg = pd_tg->GetPointData();
125 vtkPolyData *pd_do = (vtkPolyData*)GetDataObject();
126 vtkPointData *pointdata_do = pd_do->GetPointData();
128 int numPnts = ((vtkPolyData *)GetDataObject())->GetNumberOfPoints();
130 vtkIdType numSourcePts;
131 // vtkIdType numSourceCells;
133 vtkPoints *sourcePts = tg->GetSource()->GetPoints();
134 numSourcePts = sourcePts->GetNumberOfPoints();
135 // numSourceCells = tg->GetSource()->GetNumberOfCells();
137 vtkDataArray *tensorsArray = pointdata_do->GetArray("tensors");
140 vtkDoubleArray *newScalarArray = vtkDoubleArray::New();
141 newScalarArray->SetName( "NormalsEED" );
142 newScalarArray->SetNumberOfComponents(3);
143 int iNumPts,iNumSourcePts;
146 double sumEigenvalue,sumEigenvalue1,sumEigenvalue2,sumEigenvalue3;
147 unsigned char dirx,diry,dirz;
149 for (iNumPts=0;iNumPts<numPnts;iNumPts++)
151 normalValue = tensorsArray->GetTuple9(iNumPts);
152 sumEigenvalue1 = sqrt (normalValue[0]*normalValue[0] + normalValue[1]*normalValue[1] + normalValue[2]*normalValue[2]);
153 sumEigenvalue2 = sqrt (normalValue[3]*normalValue[3] + normalValue[4]*normalValue[4] + normalValue[5]*normalValue[5]);
154 sumEigenvalue3 = sqrt (normalValue[6]*normalValue[6] + normalValue[7]*normalValue[7] + normalValue[8]*normalValue[8]);
156 if ((sumEigenvalue1>=sumEigenvalue2) && (sumEigenvalue1>=sumEigenvalue3))
158 sumEigenvalue=sumEigenvalue1;
161 if ((sumEigenvalue2>sumEigenvalue1) && (sumEigenvalue2>=sumEigenvalue3))
163 sumEigenvalue=sumEigenvalue2;
166 if ((sumEigenvalue3>=sumEigenvalue1) && (sumEigenvalue3>=sumEigenvalue2))
168 sumEigenvalue=sumEigenvalue3;
172 dirx = (unsigned char)( 255*fabs(normalValue[idEigen+0]/sumEigenvalue) );
173 diry = (unsigned char)( 255*fabs(normalValue[idEigen+1]/sumEigenvalue) );
174 dirz = (unsigned char)( 255*fabs(normalValue[idEigen+2]/sumEigenvalue) );
176 for (iNumSourcePts=0;iNumSourcePts<numSourcePts;iNumSourcePts++)
178 // newScalarArray->InsertTuple3( iNormalsEED, dirx,diry,dirz);
179 newScalarArray->InsertTuple3( iNormalsEED, normalValue[idEigen+0],normalValue[idEigen+1],normalValue[idEigen+2] );
181 } // for iNumSourcePts
184 pointdata_tg->RemoveArray( "NormalsEED" );
185 pointdata_tg->AddArray( newScalarArray );
186 // pointdata_pdn->Update();
192 _pdm->ScalarVisibilityOn();
193 _pdm->SetColorModeToMapScalars();
194 //_pdm->SetColorModeToDefault();
195 // _pdm->SetColorModeToDirectScalars(); // NOT compile
196 _pdm->SetScalarModeToUsePointFieldData();
197 _pdm->ImmediateModeRenderingOn();
199 _LutEED->SetVectorModeToComponent();
200 //_LutEED->SetVectorModeToRGBColors();
201 //_LutEED->SetVectorModeToMagnitud();
202 _pdm->SetLookupTable( _LutEED );
203 _pdm->SelectColorArray( "NormalsEED" );
207 int i,sizeDa = pointdata_tg->GetNumberOfArrays();
208 printf("EED vtkTensorsVisu::Process sizeDa %d \n", sizeDa );
209 for (i=0;i<sizeDa;i++)
211 int faces = pointdata_tg->GetArray(i)->GetSize() / numPnts;
212 //pointdata_pdn->GetArray(i)->Print( std::cout );
213 printf("EED vtkTensorsVisu::Process-name %d, %s, size=%d %d \n", i, pointdata_tg->GetArrayName(i) , pointdata_tg->GetArray(i)->GetSize(), faces );