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()
55 printf("EED vtkTensorsVisu::Process Start\n");
59 if(GetTypeForm()==2) // source superquadratic
61 superquadratic->SetThetaResolution(20);
62 superquadratic->SetPhiResolution(20);
63 tg->SetSource(superquadratic->GetOutput());
64 } else if(GetTypeForm()==1) { // source sphere
65 tg->SetSource(ss->GetOutput());
66 } else { // source cube
67 tg->SetSource(cs->GetOutput());
70 tg->SetInput( GetDataObject() );
72 // tg->SetScaling(25);
73 tg->SetScaleFactor( GetScaleFactor() );
75 //The normals are needed to generate the right colors and if
76 // not used some of the glyphs are black.
77 pdn->SetInput(tg->GetOutput());
78 _pdm->SetInput( pdn->GetOutput() );
79 _actor->SetMapper( _pdm );
80 _actor->GetProperty()->SetOpacity( GetOpacity() );
82 tg->SetColorModeToEigenvalues();
83 // tg->SetColorModeToScalars();
88 pod = pd->GetPointData();
92 vtkPolyData *pd_pdn = pdn->GetOutput();
93 vtkPointData *pointdata_pdn = pd_pdn->GetPointData();
95 vtkPolyData *pd_tg = tg->GetOutput();
96 vtkPointData *pointdata_tg = pd_tg->GetPointData();
98 vtkPolyData *pd_do = (vtkPolyData*)GetDataObject();
99 vtkPointData *pointdata_do = pd_do->GetPointData();
101 int numPnts = ((vtkPolyData *)GetDataObject())->GetNumberOfPoints();
103 vtkIdType numSourcePts;
104 // vtkIdType numSourceCells;
106 vtkPoints *sourcePts = tg->GetSource()->GetPoints();
107 numSourcePts = sourcePts->GetNumberOfPoints();
108 // numSourceCells = tg->GetSource()->GetNumberOfCells();
110 vtkDataArray *tensorsArray = pointdata_do->GetArray("tensors");
113 vtkDoubleArray *newScalarArray = vtkDoubleArray::New();
114 newScalarArray->SetName( "NormalsEED" );
115 newScalarArray->SetNumberOfComponents(3);
116 int iNumPts,iNumSourcePts;
119 double sumEigenvalue,sumEigenvalue1,sumEigenvalue2,sumEigenvalue3;
120 unsigned char dirx,diry,dirz;
122 for (iNumPts=0;iNumPts<numPnts;iNumPts++)
124 normalValue = tensorsArray->GetTuple9(iNumPts);
125 sumEigenvalue1 = sqrt (normalValue[0]*normalValue[0] + normalValue[1]*normalValue[1] + normalValue[2]*normalValue[2]);
126 sumEigenvalue2 = sqrt (normalValue[3]*normalValue[3] + normalValue[4]*normalValue[4] + normalValue[5]*normalValue[5]);
127 sumEigenvalue3 = sqrt (normalValue[6]*normalValue[6] + normalValue[7]*normalValue[7] + normalValue[8]*normalValue[8]);
129 if ((sumEigenvalue1>=sumEigenvalue2) && (sumEigenvalue1>=sumEigenvalue3))
131 sumEigenvalue=sumEigenvalue1;
134 if ((sumEigenvalue2>sumEigenvalue1) && (sumEigenvalue2>=sumEigenvalue3))
136 sumEigenvalue=sumEigenvalue2;
139 if ((sumEigenvalue3>=sumEigenvalue1) && (sumEigenvalue3>=sumEigenvalue2))
141 sumEigenvalue=sumEigenvalue3;
145 dirx = (unsigned char)( 255*fabs(normalValue[idEigen+0]/sumEigenvalue) );
146 diry = (unsigned char)( 255*fabs(normalValue[idEigen+1]/sumEigenvalue) );
147 dirz = (unsigned char)( 255*fabs(normalValue[idEigen+2]/sumEigenvalue) );
149 for (iNumSourcePts=0;iNumSourcePts<numSourcePts;iNumSourcePts++)
151 // newScalarArray->InsertTuple3( iNormalsEED, dirx,diry,dirz);
152 newScalarArray->InsertTuple3( iNormalsEED, normalValue[idEigen+0],normalValue[idEigen+1],normalValue[idEigen+2] );
154 } // for iNumSourcePts
157 pointdata_tg->RemoveArray( "NormalsEED" );
158 pointdata_tg->AddArray( newScalarArray );
159 // pointdata_pdn->Update();
165 _pdm->ScalarVisibilityOn();
166 _pdm->SetColorModeToMapScalars();
167 //_pdm->SetColorModeToDefault();
168 // _pdm->SetColorModeToDirectScalars(); // NOT compile
169 _pdm->SetScalarModeToUsePointFieldData();
170 _pdm->ImmediateModeRenderingOn();
172 _LutEED->SetVectorModeToComponent();
173 //_LutEED->SetVectorModeToRGBColors();
174 //_LutEED->SetVectorModeToMagnitud();
175 _pdm->SetLookupTable( _LutEED );
176 _pdm->SelectColorArray( "NormalsEED" );
180 int i,sizeDa = pointdata_tg->GetNumberOfArrays();
181 printf("EED vtkTensorsVisu::Process sizeDa %d \n", sizeDa );
182 for (i=0;i<sizeDa;i++)
184 int faces = pointdata_tg->GetArray(i)->GetSize() / numPnts;
185 //pointdata_pdn->GetArray(i)->Print( std::cout );
186 printf("EED vtkTensorsVisu::Process-name %d, %s, size=%d %d \n", i, pointdata_tg->GetArrayName(i) , pointdata_tg->GetArray(i)->GetSize(), faces );
196 printf("EED vtkTensorsVisu::Process End.\n");