How to delete points in a tube spatial object?

Graft Plan Log.txt (12.6 KB)

I have changed as per the following link. Spatial Objects Refactoring section of the ITK 5 Migration Guide.

I got run time error while executing below code.

/** Remove duplicate points */
template <unsigned int TDimension, typename TTubePointType>
unsigned int
TubeSpatialObject<TDimension, TTubePointType>::RemoveDuplicatePointsInObjectSpace(double minSpacingInObjectSpace)
  int nPoints = 0;

  auto it = this->m_Points.begin();
  while (it != this->m_Points.end())
    PointType pnt = it->GetPositionInObjectSpace();
    if (it != this->m_Points.end())
      PointType pnt2 = it->GetPositionInObjectSpace();
      double    dist = pnt.EuclideanDistanceTo(pnt2);
      if (dist <= minSpacingInObjectSpace)
        it = this->m_Points.erase(it);         //Access violation reading location
  return nPoints;

Exception thrown at 0x00007FFB172D5BCD (ConvertTubesToSurfaceLib.dll) in S1App-real.exe
Access violation reading location while executing the line it = this->m_Points.erase(it); in the above code.

I have attached the graft plan log for more information.

May I know how to fix the above problem?

This sounds more like general programming and iterators problem, than ITK specific one. Can you follow the flow of execution in a debugger? Does the crash happen on first erase, or later?

Crash is not happening on first erase actually. Its later step.
Yes, I have followed the execution in a debugger. I am unable to figured out what problem it is. It may be the problem of ITK or some other. I have crossed checked TRE file which is input for surface generating which is seems like fine.

Maybe @Stephen_Aylward has some advice?

I don’t see anything wrong with this code.

Can you please provide the tre file for the tube and the value you passed to this function for minSpacingInObjectSpace?