]> Creatis software - creaVtk.git/commitdiff
#2506 creaVtk Bug New Normal - Color Tensors
authordavila <eduardo.davila@creatis.insa-lyon.fr>
Fri, 16 Jan 2015 08:25:14 +0000 (09:25 +0100)
committerdavila <eduardo.davila@creatis.insa-lyon.fr>
Fri, 16 Jan 2015 08:25:14 +0000 (09:25 +0100)
lib/creaVtk/vtkTensorsVisu.cpp
lib/creaVtk/vtkVectorsTensorsVisuBase.cpp
lib/creaVtk/vtkVectorsVisu.cpp

index 7f6fe1584f133499c230ca9d2ca550bebccbcc73..836c73826ab6c020b2e7b7f9570b20df06a6bc4d 100644 (file)
@@ -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;iNumPts<numPnts;iNumPts++)
+                               {
+                                       normalValue     = tensorsArray->GetTuple9(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;iNumSourcePts<numSourcePts;iNumSourcePts++)
+                                       {
+                                               newScalarArray->InsertTuple3( 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;i<sizeDa;i++)
                        {
-                               int faces = pointdata->GetArray(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 );
+
                        }
+*/
 
 
 
index 962eeec5ee4e582cb2db6c23b9081227cacd09ae..ee7fc4999d6066a96640c5bedb001e17b4286343 100644 (file)
@@ -129,10 +129,10 @@ inIncr=3;
                sum     = 0;
                for (j = 0; j < inIncr; ++j)
                {
-                       if (j==0) dirx= static_cast<double>(*input);  
-                       if (j==1) diry= static_cast<double>(*input);  
-                       if (j==2) dirz= static_cast<double>(*input);  
-                       tmp = static_cast<double>(*input);  
+                       if (j==0) dirx= static_cast<T>(*input);  
+                       if (j==1) diry= static_cast<T>(*input);  
+                       if (j==2) dirz= static_cast<T>(*input);  
+                       tmp = static_cast<T>(*input);  
                        sum += (tmp * tmp);
                        ++input;
                }
index ef8e1162b74557f091d38dfc7c894dfd19f9abf7..d95b454c9f9d428345d1eb3f44f91be60c88c5f7 100644 (file)
@@ -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 );