Skip to content

Commit 3474342

Browse files
thewtexdzenanz
authored andcommitted
BUG: Create CellData when requested in Mesh::GetCellData
Similar to ::GetPointData(), create a new container object for the cell data when requested with ::GetCellData(), which prevents client use of nullptr's.
1 parent fa2a3a2 commit 3474342

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Modules/Core/Mesh/include/itkMesh.hxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ template <typename TPixelType, unsigned int VDimension, typename TMeshTraits>
145145
auto
146146
Mesh<TPixelType, VDimension, TMeshTraits>::GetCellData() -> CellDataContainer *
147147
{
148+
if (!m_CellDataContainer)
149+
{
150+
this->SetCellData(CellDataContainer::New());
151+
}
148152
itkDebugMacro("returning CellData container of " << m_CellDataContainer);
149153
return m_CellDataContainer;
150154
}

Modules/Core/Mesh/test/itkMeshCellDataTest.cxx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
*
1717
*=========================================================================*/
1818

19-
#include <itkDefaultDynamicMeshTraits.h>
20-
#include <itkMesh.h>
21-
#include <itkTriangleCell.h>
19+
#include "itkDefaultDynamicMeshTraits.h"
20+
#include "itkMesh.h"
21+
#include "itkTriangleCell.h"
22+
#include "itkTestingMacros.h"
2223

2324
int
2425
itkMeshCellDataTest(int, char *[])
@@ -44,6 +45,8 @@ itkMeshCellDataTest(int, char *[])
4445
mesh->SetPoint(4, TPoint{ { { 4.0, 0.0 } } });
4546
mesh->SetPoint(5, TPoint{ { { 5.0, 1.0 } } });
4647

48+
ITK_TEST_EXPECT_TRUE(mesh->GetCellData() != nullptr);
49+
4750
{
4851
TCell::CellAutoPointer cellpointer;
4952
cellpointer.TakeOwnership(new TTriangle);

0 commit comments

Comments
 (0)