]> Creatis software - creaVtk.git/blobdiff - bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataNormals.cxx
#3493 MeshManager
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkPolyDataNormals.cxx
index f9676e5a4b9a3d49f83203df7eb0f0478448ce0e..e36998924ed266a6a1ebef233de5849ce13297e6 100644 (file)
@@ -5,6 +5,7 @@
 #include "bbcreaVtkPackage.h"
 
 #include <vtkPolyDataNormals.h>
+//#include <vtkTriangleMeshPointNormals.h>
 
 #include <vtkPolyData.h>
 #include <vtkPointData.h>
@@ -34,8 +35,12 @@ void PolyDataNormals::Process()
 //      (the one provided in the attribute 'type' of the tag 'input')
 //    bbSetOutputOut( bbGetInputIn() );
 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
+    
+    printf("EED  PolyDataNormals::Process In=%p \n", bbGetInputIn() );
+
     if (bbGetInputIn()!=NULL)
     {
+  
         vtkPolyDataNormals* normal = vtkPolyDataNormals::New();
         normal->SetInputData( bbGetInputIn() );
         if (bbGetInputComputeType()==0)
@@ -44,8 +49,14 @@ void PolyDataNormals::Process()
         } else {
             normal->ComputePointNormalsOn();
         }
-        //        normal->SetFeatureAngle(60.0);
+        normal->SetFeatureAngle(360);
+        normal->Update();
+    
+        /*
+        vtkTriangleMeshPointNormals* normal = vtkTriangleMeshPointNormals::New();
+        normal->SetInputData( bbGetInputIn() );
         normal->Update();
+        */
         
         // >>>>>>>>>>>>>>>>>>>> Calculate the MeanNormal
         vtkPolyData     *polydata   = normal->GetOutput();
@@ -62,12 +73,11 @@ void PolyDataNormals::Process()
         */
         dataarray   = pointdata->GetNormals();
         std::vector<double> meanNormal;
-        meanNormal.push_back(1);
+        meanNormal.push_back(0);
         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++)
             {
@@ -75,18 +85,22 @@ void PolyDataNormals::Process()
                 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
 
@@ -100,25 +114,30 @@ void PolyDataNormals::Process()
             meanN[0] = meanNormal[0];
             meanN[1] = meanNormal[1];
             meanN[2] = meanNormal[2];
+            double magnitude;
             int i , size=dataarray->GetNumberOfTuples();
             for (i=0; i<size; i++)
             {
                 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];
                 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() );
-    } // if In
+    } else {
+        bbSetOutputOut( NULL );
+    }// if In
     
 }
 //===== 
@@ -128,7 +147,8 @@ void PolyDataNormals::bbUserSetDefaultValues()
 {
 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
 //    Here we initialize the input 'In' to 0
-   bbSetInputIn(NULL);
+    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)