Centerline extraction C++ having different result from the slicer

Hello,

I have an STL file containing a surface mesh.

When I use the slicer I can easily extract the centerlines from it.

However when I use the following C++ code. I am only getting 3 output points.
vtkSmartPointer reader = vtkSmartPointer::New();
reader->SetFileName( “D:\Projects\cooling to test\conformal\surface_mesh.stl” );
reader->Update();

vtkSmartPointer inletSeedIds = vtkSmartPointer::New();
vtkSmartPointer outletSeedIds = vtkSmartPointer::New();

//Locate points
vtkSmartPointer pointLocator = vtkSmartPointer::New();
pointLocator->SetDataSet( reader->GetOutput() );
pointLocator->BuildLocator();

double sourcePoint[3];
sourcePoint[0] = -6.092;
sourcePoint[1] = -6.036;
sourcePoint[2] = 128.186;

double targetPoint[3];

targetPoint[0] = -15.177;
targetPoint[1] = -6.048;
targetPoint[2] = 128.183;

int sourceid = pointLocator->FindClosestPoint( sourcePoint );
int targetid = pointLocator->FindClosestPoint( targetPoint );

inletSeedIds->InsertNextId( sourceid );
outletSeedIds->InsertNextId( targetid );

//// Compute Centerlines
vtkSmartPointer centerlineFilter = vtkSmartPointer::New();
centerlineFilter->SetInputData( reader->GetOutput() );

centerlineFilter->SetSourceSeedIds( inletSeedIds );
centerlineFilter->SetTargetSeedIds( outletSeedIds );
centerlineFilter->SetRadiusArrayName( “MaximumInscribedSphereRadius” );
centerlineFilter->SetCostFunction( “1/R” );
centerlineFilter->SetFlipNormals( false );
centerlineFilter->SetAppendEndPointsToCenterlines( 0 );
centerlineFilter->SetSimplifyVoronoi( 0 );
centerlineFilter->SetCenterlineResampling( 0 );
centerlineFilter->SetResamplingStepLength( 1.0 );
centerlineFilter->Update();

// access centerline points
vtkSmartPointer centerlinesPolyData = vtkSmartPointer::New();
centerlinesPolyData = centerlineFilter->GetOutput();

vtkSmartPointer points = centerlinesPolyData->GetPoints();
sim::Dbl3Array centerline_points_array;

int numberOfCells = centerlinesPolyData->GetNumberOfCells();
int numberOfPoints = centerlinesPolyData->GetNumberOfPoints();
int numberOfLines = centerlinesPolyData->GetNumberOfLines();
//int numberOfVerts = centerlinesPolyData->GetNumberOfVerts();
//int numberOfStrips = centerlinesPolyData->GetNumberOfStrips();
int numberOfPieces = centerlinesPolyData->GetNumberOfPieces();
int numberOfPolys = centerlinesPolyData->GetNumberOfPolys();

I would appreciate it if you could let me know what I am doing wrong.

Hi,
I have the same problem as you.Apply the same code but generate a different centerline than the one generated in slicer.
Have you solved the problem?I would appreciate it if you have any suggestions

Slicer’s Extract Centerline module uses the VMTK C++ code via a thin Python wrapping layer so there is no difference due to using C++ or Python.

You get different results when you use the code above because you missed the required preprocessing steps - see the centerline extraction module source code.