From 2703779300c44f4585ef0ffc0c8da110ff55dc27 Mon Sep 17 00:00:00 2001 From: Pranjal Sahu Date: Mon, 2 May 2022 18:43:47 -0400 Subject: [PATCH] ENH: Initialize PolyLineCell with 2 points Atleast two points should be present in a PolyLineCell so inserting 2 points in the default constructor. --- Modules/Core/Common/include/itkPolyLineCell.h | 16 ++++++++++++---- Modules/Core/Common/include/itkPolyLineCell.hxx | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Modules/Core/Common/include/itkPolyLineCell.h b/Modules/Core/Common/include/itkPolyLineCell.h index b5c3f1bafe3..55e5067848c 100644 --- a/Modules/Core/Common/include/itkPolyLineCell.h +++ b/Modules/Core/Common/include/itkPolyLineCell.h @@ -78,6 +78,9 @@ class ITK_TEMPLATE_EXPORT PolyLineCell : public TCellInterface bool GetBoundaryFeature(int dimension, CellFeatureIdentifier, CellAutoPointer &) override; + void + InitializePoints(); + void ClearPoints(); @@ -114,16 +117,21 @@ class ITK_TEMPLATE_EXPORT PolyLineCell : public TCellInterface /** Visitor interface */ itkCellVisitMacro(CellGeometryEnum::LINE_CELL); - /** Constructor and destructor */ - PolyLineCell() = default; - PolyLineCell(PointIdentifier NumberOfPoints) + void + InitializePoints(PointIdentifier numberOfPoints) { - for (PointIdentifier i = 0; i < NumberOfPoints; ++i) + m_PointIds.clear(); + for (PointIdentifier i = 0; i < numberOfPoints; ++i) { m_PointIds.push_back(NumericTraits::max()); } } + /** Constructor and destructor */ + PolyLineCell() { InitializePoints(2); } + + PolyLineCell(PointIdentifier numberOfPoints) { InitializePoints(numberOfPoints); } + ~PolyLineCell() override = default; protected: diff --git a/Modules/Core/Common/include/itkPolyLineCell.hxx b/Modules/Core/Common/include/itkPolyLineCell.hxx index 32c05075220..fadafd6a497 100644 --- a/Modules/Core/Common/include/itkPolyLineCell.hxx +++ b/Modules/Core/Common/include/itkPolyLineCell.hxx @@ -242,7 +242,7 @@ template void PolyLineCell::ClearPoints() { - m_PointIds.clear(); + InitializePoints(2); }