#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();
+ ss = vtkSphereSource::New();
+ superquadratic = vtkSuperquadricSource::New();
+ cs = vtkCubeSource::New();
+
+ tg = NULL;
+
+ pdn = vtkPolyDataNormals::New();
+ pd = vtkPolyData::New();
+ pod = vtkPointData::New();
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
void vtkTensorsVisu::Process()
{
-printf("EED vtkTensorsVisu::Process Start\n");
-
-
- if (_active==true){
-// std::string source="sphere";
- std::string source="superquadratic";
- if(source=="sphere")
+ if (_active==true)
+ {
+ if(GetTypeForm()==2) // source superquadratic
{
- tg->SetSource(ss->GetOutput());
- } else if(source=="cube") {
- tg->SetSource(cs->GetOutput());
- }else if(source=="superquadratic") {
+ if (tg==NULL) { tg = vtkTensorGlyph::New(); }
+
superquadratic->SetThetaResolution(20);
superquadratic->SetPhiResolution(20);
+#if VTK_MAJOR_VERSION <= 5
tg->SetSource(superquadratic->GetOutput());
- } else {
+#else
+ superquadratic->Update();
+ tg->SetSourceData(superquadratic->GetOutput());
+#endif
+ } else if(GetTypeForm()==1) { // source sphere
+#if VTK_MAJOR_VERSION <= 5
+ tg->SetSource(ss->GetOutput());
+#else
+ ss->Update();
+ tg->SetSourceData(ss->GetOutput());
+#endif
+ } else { // source cube
+#if VTK_MAJOR_VERSION <= 5
+ tg->SetSource(cs->GetOutput());
+#else
+ cs->Update();
+ tg->SetSourceData(cs->GetOutput());
+#endif
}
-
+#if VTK_MAJOR_VERSION <= 5
tg->SetInput( GetDataObject() );
+#else
+ tg->SetInputData( GetDataObject() );
+#endif
// tg->ScalingOn();
// tg->SetScaling(25);
- //if(isfromcal)
tg->SetScaleFactor( GetScaleFactor() );
- 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.
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
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() );
- _pdm->ImmediateModeRenderingOn();
-
- _pdm->ScalarVisibilityOn();
- _pdm->SetScalarModeToUsePointFieldData();
-
-
-//EED _pdm->Update();
-
+#else
+ pdn->SetInputData(tg->GetOutput());
+ pdn->Update();
+ _pdm->SetInputData( pdn->GetOutput() );
+ _pdm->Update();
+#endif
_actor->SetMapper( _pdm );
_actor->GetProperty()->SetOpacity( GetOpacity() );
- tg->ColorGlyphsOn();
-// tg->ExtractEigenvaluesOn();
- tg->SetColorModeToEigenvalues();
-
- _pdm->SetLookupTable( _LutEED );
- _pdm->SelectColorArray( "Normals" );
-
+ tg->SetColorModeToEigenvalues();
+// tg->SetColorModeToScalars();
+ tg->Update();
- //int tcg = tg->GetColorGlyphs();
-// tg->SetColorGlyphs(10);
-// tg->SetColorModeToScalars();
- //tg->ThreeGlyphsOn();
-
-
- //vtkDataArray* da = vtkDataArray::New();
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
pd = tg->GetOutput();
pd->Update();
+#else
+ tg->Update();
+ pd = tg->GetOutput();
+#endif
+
pod = pd->GetPointData();
pod->Update();
-//EED1 if(pod->GetScalars())
-//EED1 {
-//EED1 _pdm->SetScalarRange(pod->GetScalars()->GetRange());
-//EED1 }
- //pdm->SelectColorArray("GlyphVector");
-
-//EED _pdm->Update();
-
-
-
- tg->Print( std::cout );
- printf("EED vtkTensorsVisu::Process ------------------------------------------\n");
- pd->Print( std::cout );
-
tg->Update();
- vtkPolyData *pd = pdn->GetOutput();
- vtkPointData *pointdata = pd->GetPointData();
-
+ 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;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;
+ }
- printf("EED vtkTensorsVisu::Process XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx\n");
- pointdata->Print( std::cout );
-
+ 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) );
- int aa = pd->GetNumberOfPieces ();
- int bb = pd->GetNumberOfVerts ();
- int cc = pd->GetNumberOfLines ();
- int dd = pd->GetNumberOfPolys ();
- int ee = pd->GetNumberOfStrips ();
- int ff = pd->GetNumberOfCells();
+ for (iNumSourcePts=0;iNumSourcePts<numSourcePts;iNumSourcePts++)
+ {
+// newScalarArray->InsertTuple3( iNormalsEED, dirx,diry,dirz);
+ newScalarArray->InsertTuple3( iNormalsEED, normalValue[idEigen+0],normalValue[idEigen+1],normalValue[idEigen+2] );
+ iNormalsEED++;
+ } // for iNumSourcePts
- printf("EED vtkTensorsVisu::Process %d %d %d %d %d %d \n", aa,bb,cc,dd,ee,ff);
+ } // for iNumPts
- vtkPolyData *ttt = (vtkPolyData *)GetDataObject();
- int numPnts = ttt->GetNumberOfPoints();
- printf("EED vtkTensorsVisu::Process numPnts %d \n", numPnts );
+ pointdata_tg->RemoveArray( "NormalsEED" );
+ pointdata_tg->AddArray( newScalarArray );
+// pointdata_pdn->Update();
+ tg->Update();
+ } // if tensorsArray
- 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);
+ _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" );
+//EED 2017-01-01 Migration VTK7
+#if VTK_MAJOR_VERSION <= 5
+ //...
+#else
+ _pdm->Update();
+#endif
- int i,sizeDa = pointdata->GetNumberOfArrays();
+/*
+ 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 );
+ }
+*/
} // _active
-
- VisibilityActor();
-
-printf("EED vtkTensorsVisu::Process End.\n");
+ VisibilityActor();
}