From: davila Date: Fri, 16 Jan 2015 13:37:42 +0000 (+0100) Subject: #2506 creaVtk Bug New Normal - Color Tensors X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=757629f8d0ef2c660febc7f1ce734021559a3763;p=creaVtk.git #2506 creaVtk Bug New Normal - Color Tensors --- diff --git a/lib/creaVtk/vtkTensorsVisu.cpp b/lib/creaVtk/vtkTensorsVisu.cpp index 836c738..7d451f3 100644 --- a/lib/creaVtk/vtkTensorsVisu.cpp +++ b/lib/creaVtk/vtkTensorsVisu.cpp @@ -28,7 +28,7 @@ #include "vtkTensorsVisu.h" #include "vtkProperty.h" -#include "vtkFloatArray.h" +#include "vtkDoubleArray.h" //------------------------------------------------------------------------ @@ -61,272 +61,120 @@ printf("EED vtkTensorsVisu::Process Start\n"); superquadratic->SetThetaResolution(20); superquadratic->SetPhiResolution(20); tg->SetSource(superquadratic->GetOutput()); -superquadratic->Print( std::cout ); - } else if(GetTypeForm()==1) { // source sphere tg->SetSource(ss->GetOutput()); -ss->Print( std::cout ); } else { // source cube tg->SetSource(cs->GetOutput()); -cs->Print( std::cout ); } - -//GetDataObject()->Print( std::cout ); - - tg->SetInput( GetDataObject() ); // tg->ScalingOn(); // tg->SetScaling(25); - //if(isfromcal) tg->SetScaleFactor( GetScaleFactor() ); -//EED04 -// tg->ScalingOn( ); - - //else - // //tg->SetScaleFactor(2); - // tg->SetScaleFactor(scale_factor); -//EED tg->Update(); //The normals are needed to generate the right colors and if // not used some of the glyphs are black. pdn->SetInput(tg->GetOutput()); -//EED pdn->Update(); - - - //EED================================ - //pdm->SetInput( tg->GetOutput()); - //pdm->SetScalarRange( range ); - - //vtkPolyData *pd = tg->GetOutput(); - //vtkPointData *pointdata = pd->GetPointData(); - //vtkDataArray *da = pointdata->GetVectors(); - - //vtkDataArray *nda = vtkFloatArray::New(); - //nda->DeepCopy(da); - - //pointdata->AddArray( nda ); - //reader->GetOutput()->GetPointData()->AddArray( nda ); - - //pdm->SetInput(pdn->GetOutput()); - //pdm->ScalarVisibilityOn(); - //pdm->SetLookupTable(vLutEED); - //pdm->SetColorModeToMapScalars(); - //pdm->SelectColorArray("color"); - //pdm->SetScalarModeToUsePointFieldData(); - //pdm->ImmediateModeRenderingOn(); - //===================================== - _pdm->SetInput( pdn->GetOutput() ); - -//EED04 -// _pdm->ImmediateModeRenderingOn(); -// _pdm->ScalarVisibilityOn(); -// _pdm->SetScalarModeToUsePointFieldData(); - - - -// _pdm->SetScalarModeToUseFieldData(); -// _pdm->SetScalarModeToUseCellFieldData(); -// _pdm->SetScalarModeToUsePointFieldData(); -// _pdm->SetScalarModeToUseCellData(); -// _pdm->SetScalarModeToUsePointData(); -// _pdm->SetScalarModeToDefault(); - - - -//EED _pdm->Update(); - _actor->SetMapper( _pdm ); _actor->GetProperty()->SetOpacity( GetOpacity() ); -//EED04.1 -// tg->ColorGlyphsOff(); -// tg->Update(); -// vtkDataArray* s = tg->GetOutput()->GetPointData()->GetScalars(); -// if (s) _pdm->SetScalarRange( s->GetRange() ); - - -//EED04.2 -// tg->ExtractEigenvaluesOff(); -// tg->Update(); -// vtkDataArray* s = tg->GetOutput()->GetPointData()->GetScalars(); -// if (s) _pdm->SetScalarRange( s->GetRange() ); - -//EED04.3 -// tg->SetColorModeToEigenvalues(); -// tg->ThreeGlyphsOn(); -// tg->Update(); -// vtkDataArray* s = tg->GetOutput()->GetPointData()->GetScalars(); -// if (s) _pdm->SetScalarRange( s->GetRange() ); - -//EED04.4 tg->SetColorModeToEigenvalues(); // tg->SetColorModeToScalars(); -// tg->ThreeGlyphsOn(); -// tg->SymmetricOn(); tg->Update(); -// vtkDataArray* s = tg->GetOutput()->GetPointData()->GetScalars(); -// if (s) _pdm->SetScalarRange( s->GetRange() ); - - -//EED03 -// tg->ColorGlyphsOn(); -// tg->ExtractEigenvaluesOn(); -// tg->SetColorModeToEigenvalues(); - - -//EED02 -// tg->ColorGlyphsOff(); -// tg->ThreeGlyphsOff(); -// tg->ExtractEigenvaluesOff(); -// tg->Update(); -//EED01 -// _pdm->SetLookupTable( _LutEED ); -// _pdm->SelectColorArray( "Normals" ); - - - //int tcg = tg->GetColorGlyphs(); -// tg->SetColorGlyphs(10); -// tg->SetColorModeToScalars(); - //tg->ThreeGlyphsOn(); - - - //vtkDataArray* da = vtkDataArray::New(); pd = tg->GetOutput(); pd->Update(); pod = pd->GetPointData(); pod->Update(); -//EED1 if(pod->GetScalars()) -//EED1 { -//EED1 _pdm->SetScalarRange(pod->GetScalars()->GetRange()); -//EED1 } - //pdm->SelectColorArray("GlyphVector"); - -//EED _pdm->Update(); - - -//EED1 tg->Print( std::cout ); -//EED1 printf("EED vtkTensorsVisu::Process ------------------------------------------\n"); -//EED1 pd->Print( std::cout ); - - - 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(); - - -//EED1 printf("EED vtkTensorsVisu::Process XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx\n"); -//EED1 pointdata->Print( std::cout ); - -/* - int aa = pd_tg->GetNumberOfPieces (); - int bb = pd_tg->GetNumberOfVerts (); - int cc = pd_tg->GetNumberOfLines (); - int dd = pd_tg->GetNumberOfPolys (); - int ee = pd_tg->GetNumberOfStrips (); - int ff = pd_tg->GetNumberOfCells(); - printf("EED vtkTensorsVisu::Process pd_tg %d %d %d %d %d %d \n", aa,bb,cc,dd,ee,ff); - - - aa = pd_pdn->GetNumberOfPieces (); - bb = pd_pdn->GetNumberOfVerts (); - cc = pd_pdn->GetNumberOfLines (); - dd = pd_pdn->GetNumberOfPolys (); - ee = pd_pdn->GetNumberOfStrips (); - ff = pd_pdn->GetNumberOfCells(); + 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; + } -// printf("EED vtkTensorsVisu::Process pd_pdn %d %d %d %d %d %d \n", aa,bb,cc,dd,ee,ff); -*/ + 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) ); - vtkPolyData *ttt = (vtkPolyData *)GetDataObject(); - int numPnts = ttt->GetNumberOfPoints(); -// printf("EED vtkTensorsVisu::Process numPnts %d \n", numPnts ); - - vtkIdType numSourcePts, numSourceCells; - vtkPoints *sourcePts; - sourcePts = tg->GetSource()->GetPoints(); - numSourcePts = sourcePts->GetNumberOfPoints(); - numSourceCells = tg->GetSource()->GetNumberOfCells(); -// printf("EED vtkTensorsVisu::Process numSourcePts %d numSourceCells %d\n", numSourcePts, numSourceCells); - - vtkDataArray *tensorsArray = pointdata_do->GetArray("tensors"); - if (tensorsArray) - { - vtkFloatArray *newScalarArray = vtkFloatArray::New(); - newScalarArray->SetName( "NormalsEED" ); - newScalarArray->SetNumberOfComponents(3); - int iNumPts,iNumSourcePts; - int iNormalsEED=0; - double *normalValue; - double sumEigenvalue,sumEigenvalue1,sumEigenvalue2,sumEigenvalue3; - double 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 = fabs(normalValue[idEigen+0]/sumEigenvalue); - diry = fabs(normalValue[idEigen+1]/sumEigenvalue); - dirz = fabs(normalValue[idEigen+2]/sumEigenvalue); -//printf("%f %f %f\n",dirx, diry,dirz ); -//printf("%f %f %f\n",sumEigenvalue1, sumEigenvalue2, sumEigenvalue3 ); -//printf("%f %f %f\n", normalValue[0], normalValue[1], normalValue[2] ); - - - for (iNumSourcePts=0;iNumSourcePtsInsertTuple3( iNormalsEED, dirx,diry,dirz ); - iNormalsEED++; - } // for iNumSourcePts - - } - pointdata_tg->RemoveArray( "NormalsEED" ); - pointdata_tg->AddArray( newScalarArray ); - pointdata_pdn->Update(); - tg->Update(); - } + 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 - _LutEED->SetVectorModeToRGBColors(); - _pdm->SetLookupTable( _LutEED ); - _pdm->SelectColorArray( "NormalsEED" ); + _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" ); -_pdm->ScalarVisibilityOn(); -_pdm->SetColorModeToMapScalars(); -// _pdm->SetColorModeToDirectScalars(); // NOT compile -_pdm->SetScalarModeToUsePointFieldData(); -_pdm->ImmediateModeRenderingOn(); /* int i,sizeDa = pointdata_tg->GetNumberOfArrays(); @@ -341,8 +189,6 @@ _pdm->ImmediateModeRenderingOn(); */ - - } // _active VisibilityActor();