//===== // 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) //===== #include "bbcreaVtkPolyDataNormals.h" #include "bbcreaVtkPackage.h" #include //#include #include #include #include #include namespace bbcreaVtk { BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,PolyDataNormals) BBTK_BLACK_BOX_IMPLEMENTATION(PolyDataNormals,bbtk::AtomicBlackBox); //===== // 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) //===== void PolyDataNormals::Process() { // THE MAIN PROCESSING METHOD BODY // Here we simply set the input 'In' value to the output 'Out' // And print out the output value // INPUT/OUTPUT ACCESSORS ARE OF THE FORM : // void bbSet{Input|Output}NAME(const TYPE&) // const TYPE& bbGet{Input|Output}NAME() const // Where : // * NAME is the name of the input/output // (the one provided in the attribute 'name' of the tag 'input') // * TYPE is the C++ type of the input/output // (the one provided in the attribute 'type' of the tag 'input') // bbSetOutputOut( bbGetInputIn() ); // std::cout << "Output value = " <SetInputData( bbGetInputIn() ); if (bbGetInputComputeType()==0) { normal->ComputeCellNormalsOn(); } else { normal->ComputePointNormalsOn(); } normal->SetFeatureAngle(360); normal->Update(); /* vtkTriangleMeshPointNormals* normal = vtkTriangleMeshPointNormals::New(); normal->SetInputData( bbGetInputIn() ); 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;iGetArray(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 meanNormal; meanNormal.push_back(0); meanNormal.push_back(0); meanNormal.push_back(0); if (dataarray!=NULL) { int i , size=dataarray->GetNumberOfTuples(); for (i=0; iGetTuple3( i ); meanNormal[0] = meanNormal[0] + pValue[0]; meanNormal[1] = meanNormal[1] + pValue[1]; meanNormal[2] = meanNormal[2] + pValue[2]; } // for i if (size!=0) { meanNormal[0] = meanNormal[0] / size; meanNormal[1] = meanNormal[1] / size; meanNormal[2] = meanNormal[2] / size; double magnitude = sqrt( meanNormal[0]*meanNormal[0] + meanNormal[1]*meanNormal[1] + meanNormal[2]*meanNormal[2] ); meanNormal[0] = meanNormal[0] / magnitude; meanNormal[1] = meanNormal[1] / magnitude; meanNormal[2] = meanNormal[2] / magnitude; } else { meanNormal[0] = 1; meanNormal[1] = 0; meanNormal[2] = 0; } // if size } // if dataarray // <<<<<<<<<<<<<<<<<<<<< Calculate the MeanNormal if ((bbGetInputType()==1) && (dataarray!=NULL) ) { double meanN[3]; double wxyz[4]; double meanNormalresult[3]; double ang; double crossResult[3]; meanN[0] = meanNormal[0]; meanN[1] = meanNormal[1]; meanN[2] = meanNormal[2]; double magnitude; int i , size=dataarray->GetNumberOfTuples(); for (i=0; iGetTuple3( 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]; vtkMath::RotateVectorByWXYZ(meanN, wxyz ,meanNormalresult); magnitude = sqrt( meanNormalresult[0]*meanNormalresult[0] + meanNormalresult[1]*meanNormalresult[1] + meanNormalresult[2]* meanNormalresult[2] ); meanNormalresult[0] = meanNormalresult[0] / magnitude; meanNormalresult[1] = meanNormalresult[1] / magnitude; meanNormalresult[2] = meanNormalresult[2] / magnitude; dataarray->SetTuple3( i , meanNormalresult[0], meanNormalresult[1], meanNormalresult[2] ); } // for } // if Type==1 && dataarray bbSetOutputMeanNormal( meanNormal ); bbSetOutputOut( normal->GetOutput() ); } else { bbSetOutputOut( NULL ); }// if In } //===== // 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) //===== void PolyDataNormals::bbUserSetDefaultValues() { // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX // Here we initialize the input 'In' to 0 bbSetInputIn(NULL); bbSetOutputOut( NULL ); } //===== // 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) //===== void PolyDataNormals::bbUserInitializeProcessing() { // THE INITIALIZATION METHOD BODY : // Here does nothing // but this is where you should allocate the internal/output pointers // if any } //===== // 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) //===== void PolyDataNormals::bbUserFinalizeProcessing() { // THE FINALIZATION METHOD BODY : // Here does nothing // but this is where you should desallocate the internal/output pointers // if any } }// EO namespace bbcreaVtk