1717 *=========================================================================*/
1818
1919#include < iostream>
20+ #include < numeric>
2021#include < string_view>
22+ #include < vector>
2123
2224#include " itkQuadEdgeMesh.h"
2325
@@ -114,20 +116,18 @@ TestCellInterface(const std::string_view name, TCell * aCell)
114116
115117 using PointIdentifier = MeshType::PointIdentifier;
116118
117- auto * pointIds = new PointIdentifier[cell->GetNumberOfPoints () * 2 ];
118- for (unsigned int i = 0 ; i < cell->GetNumberOfPoints () * 2 ; ++i)
119- {
120- pointIds[i] = i;
121- }
119+ const unsigned int numberOfPoints = cell->GetNumberOfPoints ();
120+ std::vector<PointIdentifier> pointIds (numberOfPoints * 2 );
121+ std::iota (pointIds.begin (), pointIds.end (), PointIdentifier{});
122122
123- cell->SetPointIds (pointIds);
123+ cell->SetPointIds (pointIds. data () );
124124 // exercising the const GetPointIds() method
125125 // null for QE Cells
126126 if (cell2->GetPointIds ())
127127 {
128128 cell->SetPointIds (cell2->GetPointIds ());
129129 }
130- if (cell-> GetNumberOfPoints () > 0 )
130+ if (numberOfPoints > 0 )
131131 {
132132 cell->SetPointId (0 , 100 );
133133 }
@@ -142,7 +142,7 @@ TestCellInterface(const std::string_view name, TCell * aCell)
142142 }
143143 std::cout << std::endl;
144144
145- cell->SetPointIds (&pointIds[cell-> GetNumberOfPoints () ], &pointIds[cell-> GetNumberOfPoints () * 2 ]);
145+ cell->SetPointIds (&pointIds[numberOfPoints ], &pointIds[numberOfPoints * 2 ]);
146146 std::cout << " Iterator test: PointIds for populated cell: " ;
147147 typename TCell::PointIdIterator pxpointId = cell->PointIdsBegin ();
148148 typename TCell::PointIdIterator pxendId = cell->PointIdsEnd ();
@@ -165,9 +165,6 @@ TestCellInterface(const std::string_view name, TCell * aCell)
165165 xpointId++;
166166 }
167167 std::cout << std::endl;
168-
169-
170- delete[] pointIds;
171168 return EXIT_SUCCESS;
172169}
173170
@@ -208,42 +205,40 @@ TestQECellInterface(const std::string_view name, TCell * aCell)
208205
209206 using PointIdentifier = typename TCell::PointIdentifier;
210207
211- auto * pointIds = new PointIdentifier[ cell->GetNumberOfPoints () * 2 ] ;
212- for ( unsigned int i = 0 ; i < cell-> GetNumberOfPoints () * 2 ; ++i )
208+ const unsigned int numberOfPoints = cell->GetNumberOfPoints ();
209+ if (numberOfPoints > 0 )
213210 {
214- pointIds[i] = i;
215- }
216-
217- // actually populate
218- cell->SetPointIds (pointIds);
219- // exercising the non const internal equivalent.
220- cell->InternalSetPointIds (cell->InternalGetPointIds ());
221- // exercising the const internal equivalent
222- cell->InternalSetPointIds (cell2->InternalGetPointIds ());
211+ std::vector<PointIdentifier> pointIds (numberOfPoints * 2 );
212+ std::iota (pointIds.begin (), pointIds.end (), PointIdentifier{});
223213
214+ // actually populate
215+ cell->SetPointIds (pointIds.data ());
216+ // exercising the non const internal equivalent.
217+ cell->InternalSetPointIds (cell->InternalGetPointIds ());
218+ // exercising the const internal equivalent
219+ cell->InternalSetPointIds (cell2->InternalGetPointIds ());
224220
225- std::cout << " ConstIterator test: PointIds for populated cell: " ;
226- typename TCell::PointIdInternalConstIterator ppointId = cell2->InternalPointIdsBegin ();
227- const typename TCell::PointIdInternalConstIterator pendId = cell2->InternalPointIdsEnd ();
228- while (ppointId != pendId)
229- {
230- std::cout << *ppointId << " , " ;
231- ppointId++;
232- }
233- std::cout << std::endl;
221+ std::cout << " ConstIterator test: PointIds for populated cell: " ;
222+ typename TCell::PointIdInternalConstIterator ppointId = cell2->InternalPointIdsBegin ();
223+ const typename TCell::PointIdInternalConstIterator pendId = cell2->InternalPointIdsEnd ();
224+ while (ppointId != pendId)
225+ {
226+ std::cout << *ppointId << " , " ;
227+ ppointId++;
228+ }
229+ std::cout << std::endl;
234230
235- cell->InternalSetPointIds (cell2->InternalPointIdsBegin (), cell2->InternalPointIdsEnd ());
236- std::cout << " Iterator test: PointIds for populated cell: " ;
237- typename TCell::PointIdInternalIterator pxpointId = cell->InternalPointIdsBegin ();
238- const typename TCell::PointIdInternalIterator pxendId = cell->InternalPointIdsEnd ();
239- while (pxpointId != pxendId)
240- {
241- std::cout << *pxpointId << " , " ;
242- pxpointId++;
231+ cell->InternalSetPointIds (cell2->InternalPointIdsBegin (), cell2->InternalPointIdsEnd ());
232+ std::cout << " Iterator test: PointIds for populated cell: " ;
233+ typename TCell::PointIdInternalIterator pxpointId = cell->InternalPointIdsBegin ();
234+ const typename TCell::PointIdInternalIterator pxendId = cell->InternalPointIdsEnd ();
235+ while (pxpointId != pxendId)
236+ {
237+ std::cout << *pxpointId << " , " ;
238+ pxpointId++;
239+ }
240+ std::cout << std::endl;
243241 }
244- std::cout << std::endl;
245-
246- delete[] pointIds;
247242 return EXIT_SUCCESS;
248243}
249244
0 commit comments