]> Creatis software - creaVtk.git/commitdiff
#3493 MeshManager
authorEduardo DAVILA <davila@creatis.insa-lyon.fr>
Wed, 7 Sep 2022 13:23:27 +0000 (15:23 +0200)
committerEduardo DAVILA <davila@creatis.insa-lyon.fr>
Wed, 7 Sep 2022 13:23:27 +0000 (15:23 +0200)
bbtk_creaVtk_PKG/src/bbcreaVtkBooleanOperationPolyDataFilter.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkCutter.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkLinearExtrusionFilter.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkLinearExtrusionFilter.h
bbtk_creaVtk_PKG/src/bbcreaVtkMeshReduction_DecimatePro.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkMeshReduction_QuadricDecimation.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataNormals.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkTrimmedExtrusionFilter.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkTrimmedExtrusionFilter.h

index c1d7192e642d0df74cb1a40c03fdec9d38341661..564f379457259f14e0509e726a0d9f01d4a8155c 100644 (file)
@@ -10,6 +10,8 @@
 
 #include "vtkCleanPolyData.h"
 #include "vtkTriangleFilter.h"
+#include "vtkFillHolesFilter.h"
+
 
 namespace bbcreaVtk
 {
@@ -42,12 +44,6 @@ void BooleanOperationPolyDataFilter::Process()
 
        if ((bbGetInputIn1()!=NULL)  && (bbGetInputIn2()!=NULL) )
        {
-
-        vtkPoints               *points1         = bbGetInputIn1()->GetPoints();
-        vtkPoints               *points2         = bbGetInputIn2()->GetPoints();
-        printf("EED BooleanOperationPolyDataFilter::Process  Number of points 1  %ld\n", points1->GetNumberOfPoints() );
-        printf("EED BooleanOperationPolyDataFilter::Process  Number of points 2 %ld\n", points2->GetNumberOfPoints() );
-
         
 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
@@ -57,7 +53,8 @@ printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at t
 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
 printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at the end of CreateMesh.. or create 2 new boxes\n");
-               vtkCleanPolyData *clean1 = vtkCleanPolyData::New();
+    
+        vtkCleanPolyData *clean1 = vtkCleanPolyData::New();
                vtkCleanPolyData *clean2 = vtkCleanPolyData::New();
                clean1->SetInputData( bbGetInputIn1() );
                clean2->SetInputData( bbGetInputIn2() );
@@ -70,9 +67,17 @@ printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at t
                triangle1->Update();
                triangle2->Update();
 
+//  vtkPolyDataBooleanFilter  is not a vtk filter   (this one yes: vtkBooleanOperationPolyDataFilter )
+//   https://github.com/zippy84/vtkbool
+        //  vtkPolyDataBooleanFilter is a local code creaVtk lib
         vtkPolyDataBooleanFilter *booleanOperation = vtkPolyDataBooleanFilter::New();
+
         booleanOperation->SetInputData(0, triangle1->GetOutput() );
         booleanOperation->SetInputData(1, triangle2->GetOutput() );
+
+//        booleanOperation->SetInputData(0, bbGetInputIn1() );
+//        booleanOperation->SetInputData(1, bbGetInputIn2() );
+
         if (bbGetInputOperation()==0 )
         {
             booleanOperation->SetOperModeToUnion();
@@ -106,19 +111,24 @@ printf("EED Warnning BooleanOperationPolyDataFilter::Process  Put this code at t
  */
         
         booleanOperation->Update();
+
         vtkPoints *points = booleanOperation->GetOutput()->GetPoints();
         if (points!=NULL)
         {
-            bbSetOutputOut( booleanOperation->GetOutput() );
+            vtkFillHolesFilter *fillHolesFilter = vtkFillHolesFilter::New();
+            fillHolesFilter->SetInputData( booleanOperation->GetOutput() );
+            fillHolesFilter->SetHoleSize(100000.0);
+            fillHolesFilter->Update();
+            bbSetOutputOut( fillHolesFilter->GetOutput() );
+//          bbSetOutputOut( booleanOperation->GetOutput() );
         } else {
             bbSetOutputOut( NULL );
         } // if points!=NULL
+        
        } else {
         bbSetOutputOut( NULL );
                printf("EED Warnning!  BooleanOperationPolyDataFilter::Process   vtkPolyData In1 or In2  is EMPTY\n");
        } // if In1 In2 != NULL
-        
-    printf("EED  BooleanOperationPolyDataFilter::Process End \n" );
 }
 
 //===== 
index 742a700036b835569ae09c414d51850e95a37ea0..0e4f85af50e1e4d59188d59209919b8b8d7c78b2 100644 (file)
@@ -33,7 +33,6 @@ void Cutter::Process()
   //  See example in:
   //  https://kitware.github.io/vtk-examples/site/Cxx/VisualizationAlgorithms/Cutter/
   
-    printf("EED Cutter::Process start this=%p   ImFu=%p In=%p\n", this, bbGetInputImplicitFunction() , bbGetInputIn() );
     if ( (bbGetInputActive()==true) && (bbGetInputIn()!=NULL) )
     {
         vtkCutter *cutter;
index 5d0ea977c3e1ba62ad0f761a7419814bcba95914..2b39efe8a1463a6c85188901682e363c273aeae3 100644 (file)
@@ -3,7 +3,7 @@
 //===== 
 #include "bbcreaVtkLinearExtrusionFilter.h"
 #include "bbcreaVtkPackage.h"
-
+#include <vtkReverseSense.h>
 
 namespace bbcreaVtk
 {
@@ -15,7 +15,6 @@ BBTK_BLACK_BOX_IMPLEMENTATION(LinearExtrusionFilter,bbtk::AtomicBlackBox);
 //===== 
 void LinearExtrusionFilter::Process()
 {
-
 // THE MAIN PROCESSING METHOD BODY
 //   Here we simply set the input 'In' value to the output 'Out'
 //   And print out the output value
@@ -29,23 +28,27 @@ void LinearExtrusionFilter::Process()
 //      (the one provided in the attribute 'type' of the tag 'input')
 //    bbSetOutputOut( bbGetInputIn() );
 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
-  
-    if (bbGetInputIn()!=NULL)
+    
+    printf("EED LinearExtrusionFilter::Process In=%p \n",bbGetInputIn() );
+
+    if (extrude!=NULL)
     {
-        if (extrude!=NULL)
-        {
-            extrude->Delete();
-        }
-        if (triangleFilter!=NULL)
-        {
-            triangleFilter->Delete();
-        }
+        extrude->Delete();
+        extrude=NULL;
+    }
+    if (triangleFilter!=NULL)
+    {
+        triangleFilter->Delete();
+        triangleFilter=NULL;
+    }
 
-        extrude         = vtkLinearExtrusionFilter::New();
-        triangleFilter  = vtkTriangleFilter::New();
+    if (bbGetInputIn()!=NULL)
+    {
+        std::vector<double>     dir             = bbGetInputDirection();
+                                extrude         = vtkLinearExtrusionFilter::New();
+                                triangleFilter  = vtkTriangleFilter::New();
         extrude->SetInputData( bbGetInputIn() );
         extrude->SetExtrusionTypeToNormalExtrusion();
-        std::vector<double> dir = bbGetInputDirection();
         if (dir.size()==3)
         {
             extrude->SetVector( dir[0],dir[1],dir[2] );
@@ -57,55 +60,52 @@ void LinearExtrusionFilter::Process()
         triangleFilter->SetInputData( extrude->GetOutput() );
         triangleFilter->Update( );
         bbSetOutputOut( triangleFilter->GetOutput() );
-    } // if bbGetInputIn
+    } else {
+        bbSetOutputOut( NULL );
+    }// if bbGetInputIn
 }
+
 //===== 
 // 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 LinearExtrusionFilter::bbUserSetDefaultValues()
 {
-
 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
 //    Here we initialize the input 'In' to 0
-
     extrude         = NULL;
     triangleFilter  = NULL;
     bbSetInputIn(NULL);
-
     std::vector<double> dir;
     dir.push_back(1);
     dir.push_back(0);
     dir.push_back(0);
     bbSetInputDirection( dir );
     bbSetInputScalarFactor(0);
-
+    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 LinearExtrusionFilter::bbUserInitializeProcessing()
 {
-
 //  THE INITIALIZATION METHOD BODY :
 //    Here does nothing 
 //    but this is where you should allocate the internal/output pointers 
-//    if any 
-
-  
+//    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 LinearExtrusionFilter::bbUserFinalizeProcessing()
 {
-
 //  THE FINALIZATION METHOD BODY :
 //    Here does nothing 
 //    but this is where you should desallocate the internal/output pointers 
 //    if any
-  
-}
 }
-// EO namespace bbcreaVtk
+
+}  // EO namespace bbcreaVtk
 
 
index e68ba667593412b7b42a57a5c024fa3a429293a4..01547a5b79c0fdfcd17954bb29e67f5bc98e31a5 100644 (file)
@@ -50,9 +50,9 @@ BBTK_CATEGORY("empty");
 BBTK_END_DESCRIBE_BLACK_BOX(LinearExtrusionFilter);
 //===== 
 // 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)
-//===== 
-}
-// EO namespace bbcreaVtk
+//=====
+
+// EO namespace bbcreaVtk
 
 #endif // __bbcreaVtkLinearExtrusionFilter_h_INCLUDED__
 
index 6848c8acc188f1ef86892beffda2190dc427224d..8a019ff2a4fd7d2b786945e4ecf9999518b3f0b9 100644 (file)
@@ -28,17 +28,25 @@ void MeshReduction_DecimatePro::Process()
 //    * TYPE is the C++ type of the input/output
 //      (the one provided in the attribute 'type' of the tag 'input')
 
+    printf("EED MeshReduction_DecimatePro::Process In=%p \n",bbGetInputIn() );
+
 
        if (firsttime==true)
        {
                firsttime       = false;
                decimatepro = vtkDecimatePro::New();
        }
-       decimatepro->SetInputData( bbGetInputIn() );
-       decimatepro->SetTargetReduction( bbGetInputTargetReduction() );
-       decimatepro->PreserveTopologyOn();
-       decimatepro->Update();
-       bbSetOutputOut(decimatepro->GetOutput() );  
+    
+    if (bbGetInputIn()!=NULL)
+    {
+        decimatepro->SetInputData( bbGetInputIn() );
+        decimatepro->SetTargetReduction( bbGetInputTargetReduction() );
+        decimatepro->PreserveTopologyOn();
+        decimatepro->Update();
+        bbSetOutputOut(decimatepro->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)
@@ -52,6 +60,7 @@ void MeshReduction_DecimatePro::bbUserSetDefaultValues()
        decimatepro     =       NULL;
        bbSetInputIn(NULL);
        bbSetInputTargetReduction(0.5);
+    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)
index 38fd833febd0a7fe2b06dc98071d5f84313df14d..bf723e13115e82c9a113c5716de91db3c6ac1e74 100644 (file)
@@ -32,12 +32,16 @@ void MeshReduction_QuadricDecimation::Process()
                firsttime       =false;
                quadricdecimation = vtkQuadricDecimation::New();
        }
-       quadricdecimation->SetInputData( bbGetInputIn() );
+    if (bbGetInputIn()!=NULL)
+    {
+        quadricdecimation->SetInputData( bbGetInputIn() );
+        quadricdecimation->SetTargetReduction( bbGetInputTargetReduction() );
+        quadricdecimation->Update();
+        bbSetOutputOut(quadricdecimation->GetOutput() );
+    } else {
+        bbSetOutputOut( NULL );
+    } // if In
 
-       quadricdecimation->SetTargetReduction( bbGetInputTargetReduction() );
-
-       quadricdecimation->Update();
-       bbSetOutputOut(quadricdecimation->GetOutput() );  
 }
 //===== 
 // 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)
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)
index ee6fc3eefe3c4e48583b8e9d6a5dc35929e78108..84226bd4da9e35a1b20b4fcfa08a47cd35840f6a 100644 (file)
@@ -33,19 +33,6 @@ void TrimmedExtrusionFilter::Process()
 //    bbSetOutputOut( bbGetInputIn() );
 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
  
-    
-    printf("EED Warning!!!   TrimmedExtrusionFilter::Process      Box not tested.......  \n");
-    printf("EED Warning!!!   TrimmedExtrusionFilter::Process      Box not tested.......  \n");
-    printf("EED Warning!!!   TrimmedExtrusionFilter::Process      Box not tested.......  \n");
-    printf("EED Warning!!!   TrimmedExtrusionFilter::Process      Box not tested.......  \n");
-    printf("EED Warning!!!   TrimmedExtrusionFilter::Process      Box not tested.......  \n");
-    printf("EED Warning!!!   TrimmedExtrusionFilter::Process      Box not tested.......  \n");
-    printf("EED Warning!!!   TrimmedExtrusionFilter::Process      Box not tested.......  \n");
-
-    
-    
-/* ------ Not exist in windows  old VTK 8.1 version ---------
-
     if ( (bbGetInputIn()!=NULL) && (bbGetInputIn2()!=NULL) )
     {
         if (extrusion!=NULL)
@@ -73,56 +60,48 @@ void TrimmedExtrusionFilter::Process()
     } else {
         printf("EED  Warning!!!  TrimmedExtrusionFilter::Process      Either In or In2 is missing \n");
     } // if bbGetInputIn
-*/
-    
 }
+
 //===== 
 // 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 TrimmedExtrusionFilter::bbUserSetDefaultValues()
 {
-
 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
 //    Here we initialize the input 'In' to 0
 
 // ------ Not exist in windows  old VTK 8.1 version ---------
-//    extrusion=NULL;
-     
+    extrusion=NULL;
     bbSetInputIn(NULL);
     bbSetInputIn2(NULL);
     bbSetInputType(0);
-
     std::vector<double> dir;
     dir.push_back(1);
     dir.push_back(0);
     dir.push_back(0);
     bbSetInputDirection( dir );
-
 }
+
 //===== 
 // 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 TrimmedExtrusionFilter::bbUserInitializeProcessing()
 {
-
 //  THE INITIALIZATION METHOD BODY :
 //    Here does nothing 
 //    but this is where you should allocate the internal/output pointers 
-//    if any 
-
-  
+//    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 TrimmedExtrusionFilter::bbUserFinalizeProcessing()
 {
-
 //  THE FINALIZATION METHOD BODY :
 //    Here does nothing 
 //    but this is where you should desallocate the internal/output pointers 
 //    if any
-  
 }
 
 } // EO namespace bbcreaVtk
index b97511114e803299705ae76f60b9719f77bfc4a7..30ddfdcd6b159c65212dc2bc5823006676bc8175 100644 (file)
@@ -9,10 +9,7 @@
 #include "iostream"
 
 #include <vtkPolyData.h>
-
-// ------ Not exist in windows  old VTK version ---------
-//#include <vtkTrimmedExtrusionFilter.h>
-
+#include <vtkTrimmedExtrusionFilter.h>
 
 namespace bbcreaVtk
 {
@@ -34,8 +31,7 @@ class bbcreaVtk_EXPORT TrimmedExtrusionFilter
   BBTK_PROCESS(Process);
   void Process();
     
-// ------ Not exist in windows  old VTK version ---------
-//    vtkTrimmedExtrusionFilter *extrusion;
+    vtkTrimmedExtrusionFilter *extrusion;
 
     
 //===== 
@@ -61,8 +57,7 @@ BBTK_END_DESCRIBE_BLACK_BOX(TrimmedExtrusionFilter);
 //===== 
 // 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)
 //===== 
-}
-// EO namespace bbcreaVtk
+}// EO namespace bbcreaVtk
 
 #endif // __bbcreaVtkTrimmedExtrusionFilter_h_INCLUDED__