#include <vtkPolyDataNormals.h>
+#include <vtkPolyData.h>
+#include <vtkPointData.h>
+#include <vtkDataArray.h>
+#include <vtkMath.h>
namespace bbcreaVtk
{
//=====
void PolyDataNormals::Process()
{
-
+ printf("EED PolyDataNormals::Process Start\n");
// THE MAIN PROCESSING METHOD BODY
// Here we simply set the input 'In' value to the output 'Out'
// And print out the output value
}
// normal->SetFeatureAngle(60.0);
normal->Update();
+
+ // >>>>>>>>>>>>>>>>>>>> Calculate the MeanNormal
+ vtkPolyData *polydata = normal->GetOutput();
+ vtkPointData *pointdata = polydata->GetPointData();
+ vtkDataArray *dataarray;
+ double *pValue;
+ /*
+ int i,size=pointdata->GetNumberOfArrays();
+ for(i=0;i<size;i++)
+ {
+ dataarray=pointdata->GetArray(i);
+ printf("EED creaVtkCallbackPointPicker::Execute dataarray=%s n=%ld p=%ld\n", dataarray->GetName(),dataarray->GetNumberOfValues() ,polydata->GetNumberOfPoints() );
+ } // for i
+ */
+ dataarray = pointdata->GetNormals();
+ std::vector<double> meanNormal;
+ meanNormal.push_back(1);
+ meanNormal.push_back(0);
+ meanNormal.push_back(0);
+ if (dataarray!=NULL)
+ {
+ meanNormal[0]=0;
+ int i , size=dataarray->GetNumberOfTuples();
+ for (i=0; i<size; i++)
+ {
+ pValue = dataarray->GetTuple3( i );
+ meanNormal[0] = meanNormal[0] + pValue[0];
+ meanNormal[1] = meanNormal[1] + pValue[1];
+ meanNormal[2] = meanNormal[2] + pValue[2];
+ }
+
+ if (size!=0)
+ {
+ meanNormal[0] = meanNormal[0] / size;
+ meanNormal[1] = meanNormal[1] / size;
+ meanNormal[2] = meanNormal[2] / size;
+ } else {
+ meanNormal[0] = 1;
+ meanNormal[1] = 0;
+ meanNormal[2] = 0;
+ }
+ } // if dataarray
+ // <<<<<<<<<<<<<<<<<<<<< Calculate the MeanNormal
+
+ if ((bbGetInputType()==1) && (dataarray!=NULL) )
+ {
+ double meanN[3];
+ double wxyz[4];
+ double meanNormalresult[3];
+ double ang;
+ double crossResult[3];
+ printf("EED PolyDataNormals::Process 1\n");
+ meanN[0] = meanNormal[0];
+ meanN[1] = meanNormal[1];
+ meanN[2] = meanNormal[2];
+ printf("EED PolyDataNormals::Process 2\n");
+ int i , size=dataarray->GetNumberOfTuples();
+ for (i=0; i<size; i++)
+ {
+ printf("EED PolyDataNormals::Process 3\n");
+ pValue = dataarray->GetTuple3( i );
+ ang = vtkMath::AngleBetweenVectors( pValue, meanN );
+
+ vtkMath::Cross(meanN,pValue,crossResult);
+ wxyz[0] = ang * bbGetInputParam();
+ wxyz[1] = crossResult[0];
+ wxyz[2] = crossResult[1];
+ wxyz[3] = crossResult[2];
+ printf("EED PolyDataNormals::Process 4\n");
+ vtkMath::RotateVectorByWXYZ(meanN, wxyz ,meanNormalresult);
+ dataarray->SetTuple3( i , meanNormalresult[0], meanNormalresult[1], meanNormalresult[2] );
+ } // for
+
+ } // if Type==1 && dataarray
+ bbSetOutputMeanNormal( meanNormal );
bbSetOutputOut( normal->GetOutput() );
- } // In
+ } // if In
+
+ printf("EED PolyDataNormals::Process End\n");
+
+
}
//=====
// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)