2 // 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)
4 #include "bbcreaVtkPolyDataNormals.h"
5 #include "bbcreaVtkPackage.h"
7 #include <vtkPolyDataNormals.h>
9 #include <vtkPolyData.h>
10 #include <vtkPointData.h>
11 #include <vtkDataArray.h>
17 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,PolyDataNormals)
18 BBTK_BLACK_BOX_IMPLEMENTATION(PolyDataNormals,bbtk::AtomicBlackBox);
20 // 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)
22 void PolyDataNormals::Process()
24 printf("EED PolyDataNormals::Process Start\n");
25 // THE MAIN PROCESSING METHOD BODY
26 // Here we simply set the input 'In' value to the output 'Out'
27 // And print out the output value
28 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
29 // void bbSet{Input|Output}NAME(const TYPE&)
30 // const TYPE& bbGet{Input|Output}NAME() const
32 // * NAME is the name of the input/output
33 // (the one provided in the attribute 'name' of the tag 'input')
34 // * TYPE is the C++ type of the input/output
35 // (the one provided in the attribute 'type' of the tag 'input')
36 // bbSetOutputOut( bbGetInputIn() );
37 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
38 if (bbGetInputIn()!=NULL)
40 vtkPolyDataNormals* normal = vtkPolyDataNormals::New();
41 normal->SetInputData( bbGetInputIn() );
42 if (bbGetInputComputeType()==0)
44 normal->ComputeCellNormalsOn();
46 normal->ComputePointNormalsOn();
48 // normal->SetFeatureAngle(60.0);
51 // >>>>>>>>>>>>>>>>>>>> Calculate the MeanNormal
52 vtkPolyData *polydata = normal->GetOutput();
53 vtkPointData *pointdata = polydata->GetPointData();
54 vtkDataArray *dataarray;
57 int i,size=pointdata->GetNumberOfArrays();
60 dataarray=pointdata->GetArray(i);
61 printf("EED creaVtkCallbackPointPicker::Execute dataarray=%s n=%ld p=%ld\n", dataarray->GetName(),dataarray->GetNumberOfValues() ,polydata->GetNumberOfPoints() );
64 dataarray = pointdata->GetNormals();
65 std::vector<double> meanNormal;
66 meanNormal.push_back(1);
67 meanNormal.push_back(0);
68 meanNormal.push_back(0);
72 int i , size=dataarray->GetNumberOfTuples();
73 for (i=0; i<size; i++)
75 pValue = dataarray->GetTuple3( i );
76 meanNormal[0] = meanNormal[0] + pValue[0];
77 meanNormal[1] = meanNormal[1] + pValue[1];
78 meanNormal[2] = meanNormal[2] + pValue[2];
83 meanNormal[0] = meanNormal[0] / size;
84 meanNormal[1] = meanNormal[1] / size;
85 meanNormal[2] = meanNormal[2] / size;
92 // <<<<<<<<<<<<<<<<<<<<< Calculate the MeanNormal
94 if ((bbGetInputType()==1) && (dataarray!=NULL) )
98 double meanNormalresult[3];
100 double crossResult[3];
101 printf("EED PolyDataNormals::Process 1\n");
102 meanN[0] = meanNormal[0];
103 meanN[1] = meanNormal[1];
104 meanN[2] = meanNormal[2];
105 printf("EED PolyDataNormals::Process 2\n");
106 int i , size=dataarray->GetNumberOfTuples();
107 for (i=0; i<size; i++)
109 printf("EED PolyDataNormals::Process 3\n");
110 pValue = dataarray->GetTuple3( i );
111 ang = vtkMath::AngleBetweenVectors( pValue, meanN );
113 vtkMath::Cross(meanN,pValue,crossResult);
114 wxyz[0] = ang * bbGetInputParam();
115 wxyz[1] = crossResult[0];
116 wxyz[2] = crossResult[1];
117 wxyz[3] = crossResult[2];
118 printf("EED PolyDataNormals::Process 4\n");
119 vtkMath::RotateVectorByWXYZ(meanN, wxyz ,meanNormalresult);
120 dataarray->SetTuple3( i , meanNormalresult[0], meanNormalresult[1], meanNormalresult[2] );
123 } // if Type==1 && dataarray
124 bbSetOutputMeanNormal( meanNormal );
125 bbSetOutputOut( normal->GetOutput() );
128 printf("EED PolyDataNormals::Process End\n");
133 // 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)
135 void PolyDataNormals::bbUserSetDefaultValues()
137 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
138 // Here we initialize the input 'In' to 0
142 // 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)
144 void PolyDataNormals::bbUserInitializeProcessing()
147 // THE INITIALIZATION METHOD BODY :
149 // but this is where you should allocate the internal/output pointers
155 // 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)
157 void PolyDataNormals::bbUserFinalizeProcessing()
160 // THE FINALIZATION METHOD BODY :
162 // but this is where you should desallocate the internal/output pointers
167 // EO namespace bbcreaVtk