Skip to content

Commit

Permalink
CModelReaderNode100_Mesh parses volumeid with namestace prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
3dJan committed Aug 21, 2024
1 parent 1aa1010 commit 6020218
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
6 changes: 4 additions & 2 deletions Include/Model/Reader/v100/NMR_ModelReaderNode100_Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ namespace NMR {
nfBool m_bHasVolumeDataID = false;
ModelResourceID m_nVolumeDataID = 0;
protected:
virtual void OnAttribute(_In_z_ const nfChar * pAttributeName, _In_z_ const nfChar * pAttributeValue);
virtual void OnNSChildElement(_In_z_ const nfChar * pChildName, _In_z_ const nfChar * pNameSpace, _In_ CXmlReader * pXMLReader);
void OnNSAttribute(_In_z_ const nfChar *pAttributeName,
_In_z_ const nfChar *pAttributeValue,
_In_z_ const nfChar *pNameSpace) override;
void OnNSChildElement(_In_z_ const nfChar * pChildName, _In_z_ const nfChar * pNameSpace, _In_ CXmlReader * pXMLReader) override;
public:
CModelReaderNode100_Mesh() = delete;
CModelReaderNode100_Mesh(_In_ CModel * pModel, PModelMeshObject pMesh, _In_ PModelWarnings pWarnings, _In_ PProgressMonitor pProgressMonitor, _In_ PPackageResourceID m_pObjectLevelPropertyID, _In_ ModelResourceIndex nDefaultPropertyIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ namespace NMR
// Parse attribute
parseAttributes(pXMLReader);

// parseContent needs m_pVolumeData to be initialized, and m_nID to be set by parseAttributes
m_pVolumeData = std::make_shared<CModelVolumeData>(m_nID, m_pModel);
// Parse Content
parseContent(pXMLReader);

m_pVolumeData = std::make_shared<CModelVolumeData>(m_nID, m_pModel);
m_pModel->addResource(m_pVolumeData);
}

void CModelReaderNode_Volumetric2201_VolumeData::OnAttribute(
Expand Down
23 changes: 21 additions & 2 deletions Source/Model/Reader/v100/NMR_ModelReaderNode100_Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,32 @@ namespace NMR {
nRepresentationMeshID = m_nRepresentationMeshID;
}

void CModelReaderNode100_Mesh::OnAttribute(_In_z_ const nfChar * pAttributeName, _In_z_ const nfChar * pAttributeValue)
void CModelReaderNode100_Mesh::OnNSAttribute(
_In_z_ const nfChar *pAttributeName,
_In_z_ const nfChar *pAttributeValue,
_In_z_ const nfChar *pNameSpace)
{
__NMRASSERT(pAttributeName);
__NMRASSERT(pAttributeValue);
__NMRASSERT(pNameSpace);

if(strcmp(pNameSpace, XML_3MF_NAMESPACE_VOLUMETRICSPEC) == 0)
{
if(strcmp(pAttributeName, XML_3MF_ATTRIBUTE_MESH_VOLUMEDATA) ==
0)
{
if(m_bHasVolumeDataID)
{
throw CNMRException(
NMR_ERROR_DUPLICATE_BOUNDARY_SHAPE_VOLUME_ID);
}
m_bHasVolumeDataID = true;
m_nVolumeDataID = fnStringToUint32(pAttributeValue);
}
}
}

void CModelReaderNode100_Mesh::OnNSChildElement(_In_z_ const nfChar * pChildName, _In_z_ const nfChar * pNameSpace, _In_ CXmlReader * pXMLReader)
void CModelReaderNode100_Mesh::OnNSChildElement(_In_z_ const nfChar * pChildName, _In_z_ const nfChar * pNameSpace, _In_ CXmlReader * pXMLReader)
{
__NMRASSERT(pChildName);
__NMRASSERT(pXMLReader);
Expand Down
5 changes: 5 additions & 0 deletions Source/Model/Reader/v100/NMR_ModelReaderNode100_Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ namespace NMR {
PModelReaderNode pXMLNode = std::make_shared<CModelReaderNode_FunctionFromImage3D>(
m_pModel, m_pWarnings);
pXMLNode->parseXML(pXMLReader);
} if (strcmp(pChildName, XML_3MF_ELEMENT_VOLUMEDATA) == 0)
{
PModelReaderNode pXMLNode = std::make_shared<CModelReaderNode_Volumetric2201_VolumeData>(
m_pModel, m_pWarnings);
pXMLNode->parseXML(pXMLReader);
}
else
m_pWarnings->addException(CNMRException(NMR_ERROR_NAMESPACE_INVALID_ELEMENT), mrwInvalidOptionalValue);
Expand Down
21 changes: 13 additions & 8 deletions Tests/CPP_Bindings/Source/Volumetric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,6 @@ namespace Lib3MF
auto volumeData = model->AddVolumeData();
auto theColor = volumeData->CreateNewColor(implicitFunction.get());

auto volumeDataId = volumeData->GetUniqueResourceID();
theMesh->SetVolumeData(volumeData);

// Set transformation
Expand All @@ -877,8 +876,14 @@ namespace Lib3MF


// Assert
EXPECT_NE(volumeDataId, 0);
auto volumeDataFromFile = ioModel->GetResourceByID(volumeDataId);
// get the first mesh of ioModel
auto meshesFromWrittenFile = ioModel->GetMeshObjects();
meshesFromWrittenFile->MoveNext();
auto meshFromWrittenFile =
meshesFromWrittenFile->GetCurrentMeshObject();

// Check if volumeData is a volume data
auto volumeDataFromFile = meshFromWrittenFile->GetVolumeData();
ASSERT_TRUE(volumeDataFromFile);

// Check if volumeDataFromFile is a volume data
Expand All @@ -905,11 +910,11 @@ namespace Lib3MF

/**
* @brief Test case to create and load a function from an image3d and add a
* boundary to it.
* levelset to it.
* @details This test case creates a new image stack and adds a function
* from the image3d to the model. It then adds a boundary to the volume data
* from the image3d to the model. It then adds a levelset to the volume data
* and writes the model to a file. The test then reads the file, compares
* the function and boundary with the original and asserts that they are the
* the function and levelset with the original and asserts that they are the
* same.
*/
TEST_F(Volumetric, CreateAndLoad_FunctionFromImage3dAddBoundary_SameContent)
Expand Down Expand Up @@ -947,12 +952,12 @@ namespace Lib3MF

// Write to file
writer3MF = model->QueryWriter("3mf");
writer3MF->WriteToFile(Volumetric::OutFolder + "Boundary.3mf");
writer3MF->WriteToFile(Volumetric::OutFolder + "levlelset.3mf");

// Read and compare
PModel ioModel = wrapper->CreateModel();
PReader ioReader = ioModel->QueryReader("3mf");
ioReader->ReadFromFile(Volumetric::OutFolder + "Boundary.3mf");
ioReader->ReadFromFile(Volumetric::OutFolder + "levlelset.3mf");

// Check the function
auto functionIterator = ioModel->GetFunctions();
Expand Down

0 comments on commit 6020218

Please sign in to comment.