/* # --------------------------------------------------------------------- # # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image # pour la Sante) # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton # Previous Authors : Laurent Guigues, Jean-Pierre Roux # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil # # This software is governed by the CeCILL-B license under French law and # abiding by the rules of distribution of free software. You can use, # modify and/ or redistribute the software under the terms of the CeCILL-B # license as circulated by CEA, CNRS and INRIA at the following URL # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html # or in the file LICENSE.txt. # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-B license and that you accept its terms. # ------------------------------------------------------------------------ */ #include "vtkTensorsVisu.h" #include "vtkProperty.h" #include "vtkDoubleArray.h" //------------------------------------------------------------------------ vtkTensorsVisu::vtkTensorsVisu() : vtkVectorsTensorsVisuBase() { ss = vtkSphereSource::New(); superquadratic = vtkSuperquadricSource::New(); cs = vtkCubeSource::New(); tg = vtkTensorGlyph::New(); pdn = vtkPolyDataNormals::New(); pd = vtkPolyData::New(); pod = vtkPointData::New(); } //------------------------------------------------------------------------ vtkTensorsVisu::~vtkTensorsVisu() { } //------------------------------------------------------------------------ void vtkTensorsVisu::Process() { printf("EED vtkTensorsVisu::Process Start\n"); if (_active==true) { if(GetTypeForm()==2) // source superquadratic { superquadratic->SetThetaResolution(20); superquadratic->SetPhiResolution(20); tg->SetSource(superquadratic->GetOutput()); } else if(GetTypeForm()==1) { // source sphere tg->SetSource(ss->GetOutput()); } else { // source cube tg->SetSource(cs->GetOutput()); } tg->SetInput( GetDataObject() ); // tg->ScalingOn(); // tg->SetScaling(25); tg->SetScaleFactor( GetScaleFactor() ); //The normals are needed to generate the right colors and if // not used some of the glyphs are black. pdn->SetInput(tg->GetOutput()); _pdm->SetInput( pdn->GetOutput() ); _actor->SetMapper( _pdm ); _actor->GetProperty()->SetOpacity( GetOpacity() ); tg->SetColorModeToEigenvalues(); // tg->SetColorModeToScalars(); tg->Update(); pd = tg->GetOutput(); pd->Update(); pod = pd->GetPointData(); pod->Update(); tg->Update(); vtkPolyData *pd_pdn = pdn->GetOutput(); vtkPointData *pointdata_pdn = pd_pdn->GetPointData(); vtkPolyData *pd_tg = tg->GetOutput(); vtkPointData *pointdata_tg = pd_tg->GetPointData(); vtkPolyData *pd_do = (vtkPolyData*)GetDataObject(); vtkPointData *pointdata_do = pd_do->GetPointData(); int numPnts = ((vtkPolyData *)GetDataObject())->GetNumberOfPoints(); vtkIdType numSourcePts; // vtkIdType numSourceCells; vtkPoints *sourcePts = tg->GetSource()->GetPoints(); numSourcePts = sourcePts->GetNumberOfPoints(); // numSourceCells = tg->GetSource()->GetNumberOfCells(); vtkDataArray *tensorsArray = pointdata_do->GetArray("tensors"); if (tensorsArray) { vtkDoubleArray *newScalarArray = vtkDoubleArray::New(); newScalarArray->SetName( "NormalsEED" ); newScalarArray->SetNumberOfComponents(3); int iNumPts,iNumSourcePts; int iNormalsEED=0; double *normalValue; double sumEigenvalue,sumEigenvalue1,sumEigenvalue2,sumEigenvalue3; unsigned char dirx,diry,dirz; int idEigen; for (iNumPts=0;iNumPtsGetTuple9(iNumPts); sumEigenvalue1 = sqrt (normalValue[0]*normalValue[0] + normalValue[1]*normalValue[1] + normalValue[2]*normalValue[2]); sumEigenvalue2 = sqrt (normalValue[3]*normalValue[3] + normalValue[4]*normalValue[4] + normalValue[5]*normalValue[5]); sumEigenvalue3 = sqrt (normalValue[6]*normalValue[6] + normalValue[7]*normalValue[7] + normalValue[8]*normalValue[8]); if ((sumEigenvalue1>=sumEigenvalue2) && (sumEigenvalue1>=sumEigenvalue3)) { sumEigenvalue=sumEigenvalue1; idEigen=0; } if ((sumEigenvalue2>sumEigenvalue1) && (sumEigenvalue2>=sumEigenvalue3)) { sumEigenvalue=sumEigenvalue2; idEigen=3; } if ((sumEigenvalue3>=sumEigenvalue1) && (sumEigenvalue3>=sumEigenvalue2)) { sumEigenvalue=sumEigenvalue3; idEigen=6; } dirx = (unsigned char)( 255*fabs(normalValue[idEigen+0]/sumEigenvalue) ); diry = (unsigned char)( 255*fabs(normalValue[idEigen+1]/sumEigenvalue) ); dirz = (unsigned char)( 255*fabs(normalValue[idEigen+2]/sumEigenvalue) ); for (iNumSourcePts=0;iNumSourcePtsInsertTuple3( iNormalsEED, dirx,diry,dirz); newScalarArray->InsertTuple3( iNormalsEED, normalValue[idEigen+0],normalValue[idEigen+1],normalValue[idEigen+2] ); iNormalsEED++; } // for iNumSourcePts } // for iNumPts pointdata_tg->RemoveArray( "NormalsEED" ); pointdata_tg->AddArray( newScalarArray ); // pointdata_pdn->Update(); tg->Update(); } // if tensorsArray _pdm->ScalarVisibilityOn(); _pdm->SetColorModeToMapScalars(); //_pdm->SetColorModeToDefault(); // _pdm->SetColorModeToDirectScalars(); // NOT compile _pdm->SetScalarModeToUsePointFieldData(); _pdm->ImmediateModeRenderingOn(); _LutEED->SetVectorModeToComponent(); //_LutEED->SetVectorModeToRGBColors(); //_LutEED->SetVectorModeToMagnitud(); _pdm->SetLookupTable( _LutEED ); _pdm->SelectColorArray( "NormalsEED" ); /* int i,sizeDa = pointdata_tg->GetNumberOfArrays(); printf("EED vtkTensorsVisu::Process sizeDa %d \n", sizeDa ); for (i=0;iGetArray(i)->GetSize() / numPnts; //pointdata_pdn->GetArray(i)->Print( std::cout ); printf("EED vtkTensorsVisu::Process-name %d, %s, size=%d %d \n", i, pointdata_tg->GetArrayName(i) , pointdata_tg->GetArray(i)->GetSize(), faces ); } */ } // _active VisibilityActor(); printf("EED vtkTensorsVisu::Process End.\n"); }