From 879ef5e3816ad657576269a96edda4ada4848bdf Mon Sep 17 00:00:00 2001
From: Pablo Garzon <gapablo2001@gmail.com>
Date: Thu, 11 May 2023 14:33:51 +0200
Subject: [PATCH] #3501 Geodesic Deformation

---
 .../src/bbitkvtkGeodesicMeshDeformation.cxx   | 40 +++++++++++--------
 .../src/bbitkvtkGeodesicMeshDeformation.h     |  2 +
 2 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/packages/itkvtk/src/bbitkvtkGeodesicMeshDeformation.cxx b/packages/itkvtk/src/bbitkvtkGeodesicMeshDeformation.cxx
index 287c0e6..f99dc9c 100644
--- a/packages/itkvtk/src/bbitkvtkGeodesicMeshDeformation.cxx
+++ b/packages/itkvtk/src/bbitkvtkGeodesicMeshDeformation.cxx
@@ -14,7 +14,7 @@ BBTK_BLACK_BOX_IMPLEMENTATION(GeodesicMeshDeformation,bbtk::AtomicBlackBox);
 //===== 
 void GeodesicMeshDeformation::Process()
 {
-printf("PG GeodesicMeshDeformation::Process START \n");
+//printf("PG GeodesicMeshDeformation::Process START \n");
 // THE MAIN PROCESSING METHOD BODY
 //   Here we simply set the input 'In' value to the output 'Out'
 //   And print out the output value
@@ -35,7 +35,8 @@ printf("PG GeodesicMeshDeformation::Process START \n");
     if ((bbGetInputIn() != polydata) && (bbGetInputActive()==true) && (bbGetInputIn() != NULL))
     {
     	//Reset displacement
-    	if(lstCenter.size() != NULL){
+    	if(lstCenter.size() != NULL)
+    	{
 			backLstCenter[0] = lstCenter[0];
 			backLstCenter[1] = lstCenter[1];
 			backLstCenter[2] = lstCenter[2];
@@ -64,28 +65,31 @@ printf("PG GeodesicMeshDeformation::Process START \n");
 			//point data must be 1 on each point so that fast marching can calculate the distance.
 			quadEdgeMesh->SetPointData(pointId, 1.);
 		}
-		printf("PG GeodesicMeshDeformation::Process Entered FLAG 4 \n");
+
 		//add cells to QuadEdge mesh
 		auto cellIterator = vtk::TakeSmartPointer(bbGetInputIn()->GetPolys()->NewIterator());
 		vtkIdList* cell;
 		for(cellIterator->GoToFirstCell(); !cellIterator->IsDoneWithTraversal(); cellIterator->GoToNextCell()){
 			cell = cellIterator->GetCurrentCell();
 			quadEdgeMesh->AddFaceTriangle(cell->GetId(0), cell->GetId(1), cell->GetId(2));
-		}			
-		printf("PG GeodesicMeshDeformation::Process  FLAG 5\n");
+		}
 		
 		using FastMarchingType = itk::FastMarchingQuadEdgeMeshFilterResultsBase<MeshType, MeshType>;	
 		fmmFilter = FastMarchingType::New();
 		fmmFilter->SetInput(quadEdgeMesh);
 		
-		using NodePairType = FastMarchingType::NodePairType;
-		using NodePairContainerType = FastMarchingType::NodePairContainerType;
+		//Filter and starting trial point removed because the range of point ids is not known when polydatas are split.
 		
-		auto trial = NodePairContainerType::New();
-		NodePairType nodePair(0, 0.);
-		trial->push_back(nodePair);
+		//using NodePairType = FastMarchingType::NodePairType;
+		//using NodePairContainerType = FastMarchingType::NodePairContainerType;
+
+		//auto trial = NodePairContainerType::New();
+		//NodePairType nodePair(0, 0.);
+		//trial->push_back(nodePair);
+
+		//fmmFilter->SetTrialPoints(trial);
 		
-		fmmFilter->SetTrialPoints(trial);
+		EdgeIdBack = bbGetInputEdgeId();
 
 		using CriterionType = itk::FastMarchingThresholdStoppingCriterion<MeshType, MeshType>;
 		auto criterion = CriterionType::New();
@@ -94,9 +98,9 @@ printf("PG GeodesicMeshDeformation::Process START \n");
 		fmmFilter->SetStoppingCriterion(criterion);
 		fmmFilter->SetCollectPoints(true);
 		fmmFilter->SetReleaseDataBeforeUpdateFlag(false);
-		fmmFilter->Update();
+		//fmmFilter->Update();
 
-		printf("PG GeodesicMeshDeformation::Process  Filter Created \n");
+		//printf("PG GeodesicMeshDeformation::Process  Filter Created \n");
     }
     
     if (bbGetInputTypeIn()==0) // direction
@@ -174,7 +178,8 @@ printf("PG GeodesicMeshDeformation::Process START \n");
 			fmmFilter->SetTrialPoints(trial);
 
 			//threshold distance for fast marching method
-			if(sCurrent != s){			
+			if(sCurrent != s)
+			{			
 				using CriterionType = itk::FastMarchingThresholdStoppingCriterion<MeshType, MeshType>;
 				auto criterion = CriterionType::New();
 				sCurrent = s;
@@ -187,7 +192,8 @@ printf("PG GeodesicMeshDeformation::Process START \n");
         
         if ( !((displcement_x==0) &&(displcement_y==0) && (displcement_z==0)) )
         {	
-			if(fmmFilter != NULL){
+			if(fmmFilter != NULL)
+			{
 				MeshType::PointDataContainer::Pointer pointData = fmmFilter->GetOutput()->GetPointData();
 				double pPD[3];
 				
@@ -209,10 +215,10 @@ printf("PG GeodesicMeshDeformation::Process START \n");
 				}
 				points->Modified();
             	bbGetInputIn()->Modified();
-			}
+			}// if ffmFilter != NULL
         } // if distance_x y z  != 0
     } // In != NULL    ok    active
-    printf("PG GeodesicMeshDeformation::Process END \n");
+//    printf("PG GeodesicMeshDeformation::Process END \n");
 }
 //===== 
 // 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)
diff --git a/packages/itkvtk/src/bbitkvtkGeodesicMeshDeformation.h b/packages/itkvtk/src/bbitkvtkGeodesicMeshDeformation.h
index 1ba0448..83c6beb 100644
--- a/packages/itkvtk/src/bbitkvtkGeodesicMeshDeformation.h
+++ b/packages/itkvtk/src/bbitkvtkGeodesicMeshDeformation.h
@@ -37,6 +37,8 @@ class bbitkvtk_EXPORT GeodesicMeshDeformation
   void Process();
   
   using MeshType = itk::QuadEdgeMesh<double, 3>;
+  
+  //This is not the FastMarchingQuadEdge filter from ITK, this is a modified version to increase performance in our use
   using FastMarchingType = itk::FastMarchingQuadEdgeMeshFilterResultsBase<MeshType, MeshType>;
   
   	long 									EdgeIdBack;
-- 
2.49.0