Skip to content

Commit

Permalink
fix(WasmMesh): Use GetCellArray for cell buffer
Browse files Browse the repository at this point in the history
Reuse the existing implementation. The alternative implementation does
not work well in WASI.
  • Loading branch information
thewtex committed Feb 7, 2023
1 parent 57add05 commit 4adffc1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 68 deletions.
2 changes: 1 addition & 1 deletion include/itkWasmMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ITK_TEMPLATE_EXPORT WasmMesh : public WasmDataObject

using PointIdentifier = typename MeshType::PointIdentifier;
using CellIdentifier = typename MeshType::CellIdentifier;
using CellBufferContainerType = VectorContainer<SizeValueType, CellIdentifier>;
using CellBufferContainerType = typename MeshType::CellsVectorContainer;

void SetMesh(const MeshType * mesh);

Expand Down
69 changes: 2 additions & 67 deletions include/itkWasmMesh.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,73 +28,8 @@ void
WasmMesh<TMesh>
::SetMesh(const MeshType * mesh)
{
SizeValueType cellBufferSize = 2 * mesh->GetNumberOfCells();
for (typename MeshType::CellsContainerConstIterator ct = mesh->GetCells()->Begin(); ct != mesh->GetCells()->End(); ++ct)
{
cellBufferSize += ct->Value()->GetNumberOfPoints();
}
this->m_CellBufferContainer->resize(cellBufferSize);

const typename MeshType::CellsContainer * cells = mesh->GetCells();

typename MeshType::PointIdentifier const * ptIds;
typename MeshType::CellType * cellPtr;

// For each cell
SizeValueType index = NumericTraits<SizeValueType>::ZeroValue();
typename MeshType::CellsContainerConstIterator cter = cells->Begin();
while (cter != cells->End())
{
cellPtr = cter.Value();

// Write the cell type
switch (cellPtr->GetType())
{
case CellGeometryEnum::VERTEX_CELL:
this->m_CellBufferContainer->SetElement(index++, static_cast<CellIdentifier>(CellGeometryEnum::VERTEX_CELL));
break;
case CellGeometryEnum::LINE_CELL:
this->m_CellBufferContainer->SetElement(index++, static_cast<CellIdentifier>(CellGeometryEnum::LINE_CELL));
break;
case CellGeometryEnum::TRIANGLE_CELL:
this->m_CellBufferContainer->SetElement(index++, static_cast<CellIdentifier>(CellGeometryEnum::TRIANGLE_CELL));
break;
case CellGeometryEnum::QUADRILATERAL_CELL:
this->m_CellBufferContainer->SetElement(index++, static_cast<CellIdentifier>(CellGeometryEnum::QUADRILATERAL_CELL));
break;
case CellGeometryEnum::POLYGON_CELL:
this->m_CellBufferContainer->SetElement(index++, static_cast<CellIdentifier>(CellGeometryEnum::POLYGON_CELL));
break;
case CellGeometryEnum::TETRAHEDRON_CELL:
this->m_CellBufferContainer->SetElement(index++, static_cast<CellIdentifier>(CellGeometryEnum::TETRAHEDRON_CELL));
break;
case CellGeometryEnum::HEXAHEDRON_CELL:
this->m_CellBufferContainer->SetElement(index++, static_cast<CellIdentifier>(CellGeometryEnum::HEXAHEDRON_CELL));
break;
case CellGeometryEnum::QUADRATIC_EDGE_CELL:
this->m_CellBufferContainer->SetElement(index++, static_cast<CellIdentifier>(CellGeometryEnum::QUADRATIC_EDGE_CELL));
break;
case CellGeometryEnum::QUADRATIC_TRIANGLE_CELL:
this->m_CellBufferContainer->SetElement(index++, static_cast<CellIdentifier>(CellGeometryEnum::QUADRATIC_TRIANGLE_CELL));
break;
default:
itkExceptionMacro(<< "Unknown mesh cell");
}

// The second element is number of points for each cell
this->m_CellBufferContainer->SetElement(index++, cellPtr->GetNumberOfPoints());

// Others are point identifiers in the cell
ptIds = cellPtr->GetPointIds();
unsigned int numberOfPoints = cellPtr->GetNumberOfPoints();
for (unsigned int ii = 0; ii < numberOfPoints; ++ii)
{
this->m_CellBufferContainer->SetElement(index++, static_cast<CellIdentifier>(ptIds[ii]));
}

++cter;
}
this->SetDataObject(const_cast<MeshType *>(mesh));
this->m_CellBufferContainer = const_cast<MeshType *>(mesh)->GetCellsArray();
this->SetDataObject(const_cast<MeshType *>(mesh));
}

} // end namespace itk
Expand Down

0 comments on commit 4adffc1

Please sign in to comment.