From: davila Date: Fri, 16 Jan 2015 08:25:14 +0000 (+0100) Subject: #2506 creaVtk Bug New Normal - Color Tensors X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=6f0a90ad28dc2855513d2e27c824ac162367cbe7;p=creaVtk.git #2506 creaVtk Bug New Normal - Color Tensors --- diff --git a/lib/creaVtk/vtkTensorsVisu.cpp b/lib/creaVtk/vtkTensorsVisu.cpp index 7f6fe15..836c738 100644 --- a/lib/creaVtk/vtkTensorsVisu.cpp +++ b/lib/creaVtk/vtkTensorsVisu.cpp @@ -28,6 +28,8 @@ #include "vtkTensorsVisu.h" #include "vtkProperty.h" +#include "vtkFloatArray.h" + //------------------------------------------------------------------------ vtkTensorsVisu::vtkTensorsVisu() : vtkVectorsTensorsVisuBase() @@ -59,19 +61,28 @@ 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() ); - tg->ScalingOn( ); +//EED04 +// tg->ScalingOn( ); + //else // //tg->SetScaleFactor(2); // tg->SetScaleFactor(scale_factor); @@ -107,10 +118,21 @@ printf("EED vtkTensorsVisu::Process Start\n"); //===================================== _pdm->SetInput( pdn->GetOutput() ); - _pdm->ImmediateModeRenderingOn(); - _pdm->ScalarVisibilityOn(); - _pdm->SetScalarModeToUsePointFieldData(); +//EED04 +// _pdm->ImmediateModeRenderingOn(); +// _pdm->ScalarVisibilityOn(); +// _pdm->SetScalarModeToUsePointFieldData(); + + + +// _pdm->SetScalarModeToUseFieldData(); +// _pdm->SetScalarModeToUseCellFieldData(); +// _pdm->SetScalarModeToUsePointFieldData(); +// _pdm->SetScalarModeToUseCellData(); +// _pdm->SetScalarModeToUsePointData(); +// _pdm->SetScalarModeToDefault(); + //EED _pdm->Update(); @@ -118,12 +140,51 @@ printf("EED vtkTensorsVisu::Process Start\n"); _actor->SetMapper( _pdm ); _actor->GetProperty()->SetOpacity( GetOpacity() ); - tg->ColorGlyphsOn(); +//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(); +// tg->SetColorModeToEigenvalues(); + - _pdm->SetLookupTable( _LutEED ); - _pdm->SelectColorArray( "Normals" ); +//EED02 +// tg->ColorGlyphsOff(); +// tg->ThreeGlyphsOff(); +// tg->ExtractEigenvaluesOff(); +// tg->Update(); + +//EED01 +// _pdm->SetLookupTable( _LutEED ); +// _pdm->SelectColorArray( "Normals" ); //int tcg = tg->GetColorGlyphs(); @@ -151,45 +212,133 @@ printf("EED vtkTensorsVisu::Process Start\n"); //EED1 pd->Print( std::cout ); - tg->Update(); - vtkPolyData *pd = pdn->GetOutput(); - vtkPointData *pointdata = pd->GetPointData(); + 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); - int aa = pd->GetNumberOfPieces (); - int bb = pd->GetNumberOfVerts (); - int cc = pd->GetNumberOfLines (); - int dd = pd->GetNumberOfPolys (); - int ee = pd->GetNumberOfStrips (); - int ff = pd->GetNumberOfCells(); - printf("EED vtkTensorsVisu::Process %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(); + +// printf("EED vtkTensorsVisu::Process pd_pdn %d %d %d %d %d %d \n", aa,bb,cc,dd,ee,ff); +*/ vtkPolyData *ttt = (vtkPolyData *)GetDataObject(); int numPnts = ttt->GetNumberOfPoints(); - printf("EED vtkTensorsVisu::Process numPnts %d \n", numPnts ); - +// 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); +// 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(); + } + + _LutEED->SetVectorModeToRGBColors(); + _pdm->SetLookupTable( _LutEED ); + _pdm->SelectColorArray( "NormalsEED" ); - int i,sizeDa = pointdata->GetNumberOfArrays(); + + +_pdm->ScalarVisibilityOn(); +_pdm->SetColorModeToMapScalars(); +// _pdm->SetColorModeToDirectScalars(); // NOT compile +_pdm->SetScalarModeToUsePointFieldData(); +_pdm->ImmediateModeRenderingOn(); + +/* + int i,sizeDa = pointdata_tg->GetNumberOfArrays(); printf("EED vtkTensorsVisu::Process sizeDa %d \n", sizeDa ); for (i=0;iGetArray(i)->GetSize() / numPnts; - printf("EED vtkTensorsVisu::Process-name %d, %s, size=%d %d \n", i, pointdata->GetArrayName(i) , pointdata->GetArray(i)->GetSize(), faces ); + int faces = pointdata_tg->GetArray(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 ); + } +*/ diff --git a/lib/creaVtk/vtkVectorsTensorsVisuBase.cpp b/lib/creaVtk/vtkVectorsTensorsVisuBase.cpp index 962eeec..ee7fc49 100644 --- a/lib/creaVtk/vtkVectorsTensorsVisuBase.cpp +++ b/lib/creaVtk/vtkVectorsTensorsVisuBase.cpp @@ -129,10 +129,10 @@ inIncr=3; sum = 0; for (j = 0; j < inIncr; ++j) { - if (j==0) dirx= static_cast(*input); - if (j==1) diry= static_cast(*input); - if (j==2) dirz= static_cast(*input); - tmp = static_cast(*input); + if (j==0) dirx= static_cast(*input); + if (j==1) diry= static_cast(*input); + if (j==2) dirz= static_cast(*input); + tmp = static_cast(*input); sum += (tmp * tmp); ++input; } diff --git a/lib/creaVtk/vtkVectorsVisu.cpp b/lib/creaVtk/vtkVectorsVisu.cpp index ef8e116..d95b454 100644 --- a/lib/creaVtk/vtkVectorsVisu.cpp +++ b/lib/creaVtk/vtkVectorsVisu.cpp @@ -63,7 +63,6 @@ printf("EED vtkVectorsVisu::Process() start\n"); _vtkglyph->SetSource( _vtklinesource->GetOutput() ); } - _vtkglyph->SetScaleModeToScaleByVector(); _vtkglyph->SetColorModeToColorByVector(); _vtkglyph->SetScaleFactor( GetScaleFactor() ); @@ -72,10 +71,10 @@ printf("EED vtkVectorsVisu::Process() start\n"); _pdm->SetInput( _vtkglyph->GetOutput()); vtkPointData *data = _vtkglyph->GetOutput()->GetPointData(); -printf("EED -------------------------------------------\n"); -_vtkglyph->GetOutput()->Print(std::cout); -printf("EED -------------------------------------------\n"); -data->Print(std::cout); +//printf("EED -------------------------------------------\n"); +//_vtkglyph->GetOutput()->Print(std::cout); +//printf("EED -------------------------------------------\n"); +//data->Print(std::cout); printf("EED -------------------------------------------\n"); int i,sizeDa = data->GetNumberOfArrays(); printf("EED vtkVectorsVisu::Process sizeDa %d \n", sizeDa );