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 // THE MAIN PROCESSING METHOD BODY
25 // Here we simply set the input 'In' value to the output 'Out'
26 // And print out the output value
27 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
28 // void bbSet{Input|Output}NAME(const TYPE&)
29 // const TYPE& bbGet{Input|Output}NAME() const
31 // * NAME is the name of the input/output
32 // (the one provided in the attribute 'name' of the tag 'input')
33 // * TYPE is the C++ type of the input/output
34 // (the one provided in the attribute 'type' of the tag 'input')
35 // bbSetOutputOut( bbGetInputIn() );
36 // std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
37 if (bbGetInputIn()!=NULL)
39 vtkPolyDataNormals* normal = vtkPolyDataNormals::New();
40 normal->SetInputData( bbGetInputIn() );
41 if (bbGetInputComputeType()==0)
43 normal->ComputeCellNormalsOn();
45 normal->ComputePointNormalsOn();
47 // normal->SetFeatureAngle(60.0);
50 // >>>>>>>>>>>>>>>>>>>> Calculate the MeanNormal
51 vtkPolyData *polydata = normal->GetOutput();
52 vtkPointData *pointdata = polydata->GetPointData();
53 vtkDataArray *dataarray;
56 int i,size=pointdata->GetNumberOfArrays();
59 dataarray=pointdata->GetArray(i);
60 printf("EED creaVtkCallbackPointPicker::Execute dataarray=%s n=%ld p=%ld\n", dataarray->GetName(),dataarray->GetNumberOfValues() ,polydata->GetNumberOfPoints() );
63 dataarray = pointdata->GetNormals();
64 std::vector<double> meanNormal;
65 meanNormal.push_back(1);
66 meanNormal.push_back(0);
67 meanNormal.push_back(0);
71 int i , size=dataarray->GetNumberOfTuples();
72 for (i=0; i<size; i++)
74 pValue = dataarray->GetTuple3( i );
75 meanNormal[0] = meanNormal[0] + pValue[0];
76 meanNormal[1] = meanNormal[1] + pValue[1];
77 meanNormal[2] = meanNormal[2] + pValue[2];
82 meanNormal[0] = meanNormal[0] / size;
83 meanNormal[1] = meanNormal[1] / size;
84 meanNormal[2] = meanNormal[2] / size;
91 // <<<<<<<<<<<<<<<<<<<<< Calculate the MeanNormal
93 if ((bbGetInputType()==1) && (dataarray!=NULL) )
97 double meanNormalresult[3];
99 double crossResult[3];
100 meanN[0] = meanNormal[0];
101 meanN[1] = meanNormal[1];
102 meanN[2] = meanNormal[2];
103 int i , size=dataarray->GetNumberOfTuples();
104 for (i=0; i<size; i++)
106 pValue = dataarray->GetTuple3( i );
107 ang = vtkMath::AngleBetweenVectors( pValue, meanN );
109 vtkMath::Cross(meanN,pValue,crossResult);
110 wxyz[0] = ang * bbGetInputParam();
111 wxyz[1] = crossResult[0];
112 wxyz[2] = crossResult[1];
113 wxyz[3] = crossResult[2];
114 vtkMath::RotateVectorByWXYZ(meanN, wxyz ,meanNormalresult);
115 dataarray->SetTuple3( i , meanNormalresult[0], meanNormalresult[1], meanNormalresult[2] );
118 } // if Type==1 && dataarray
119 bbSetOutputMeanNormal( meanNormal );
120 bbSetOutputOut( normal->GetOutput() );
125 // 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)
127 void PolyDataNormals::bbUserSetDefaultValues()
129 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
130 // Here we initialize the input 'In' to 0
134 // 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)
136 void PolyDataNormals::bbUserInitializeProcessing()
139 // THE INITIALIZATION METHOD BODY :
141 // but this is where you should allocate the internal/output pointers
147 // 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)
149 void PolyDataNormals::bbUserFinalizeProcessing()
152 // THE FINALIZATION METHOD BODY :
154 // but this is where you should desallocate the internal/output pointers
159 // EO namespace bbcreaVtk