Skip to content

Commit

Permalink
Triangle Set Reader
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderoster authored and gangatp committed Dec 17, 2024
1 parent afc3bb3 commit a20198c
Show file tree
Hide file tree
Showing 14 changed files with 532 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Include/Common/NMR_ErrorConst.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,19 @@ Core framework error codes (0x2XXX)
// Too many triangle sets
#define NMR_ERROR_TOOMANYTRIANGLESETS 0x2043

// Invalid triangle set attribute
#define NMR_ERROR_TRIANGLESETINVALIDATTRIBUTE 0x2044

// Missing triangle set reference index
#define NMR_ERROR_TRIANGLESETMISSINGREFERENCEINDEX 0x2045

// Triangle set name missing
#define NMR_ERROR_TRIANGLESETNAMEMISSING 0x2046

// Triangle set identifier missing
#define NMR_ERROR_TRIANGLESETIDENTIFIERMISSING 0x2047


/*-------------------------------------------------------------------
Model error codes (0x8XXX)
-------------------------------------------------------------------*/
Expand Down
1 change: 1 addition & 0 deletions Include/Model/Classes/NMR_ModelConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ These are given by the 3MF Standard
#define XML_3MF_ATTRIBUTE_BEAMLATTICE_PRECISION "precision"
#define XML_3MF_ATTRIBUTE_TRIANGLESET_IDENTIFIER "identifier"
#define XML_3MF_ATTRIBUTE_TRIANGLESET_NAME "name"
#define XML_3MF_ATTRIBUTE_TRIANGLESETREF_INDEX "index"

// Vertex element.
#define XML_3MF_ELEMENT_VERTEX "vertex"
Expand Down
1 change: 1 addition & 0 deletions Include/Model/Classes/NMR_ModelMeshObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ namespace NMR {
ResourceDependencies getDependencies() override;
void deleteTriangleSet (_In_ CModelTriangleSet * pTriangleSet);
PModelTriangleSet addTriangleSet(const std::string& sIdentifier, const std::string& sName);
PModelTriangleSet addTriangleSet(PModelTriangleSet pModelTriangleSet);
PModelTriangleSet findTriangleSet (const std::string & sIdentifier);
uint32_t getTriangleSetCount();
PModelTriangleSet getTriangleSet(const uint32_t nIndex);
Expand Down
4 changes: 4 additions & 0 deletions Include/Model/Reader/v100/NMR_ModelReaderNode100_Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ A mesh reader model node is a parser for the mesh node of an XML Model Stream.
#include "Model/Classes/NMR_ModelObject.h"
#include "Model/Classes/NMR_ModelVolumeData.h"
#include "Model/Classes/NMR_ModelMeshObject.h"
#include "Model/Classes/NMR_ModelTriangleSet.h"

namespace NMR {

class CModelReaderNode100_Mesh : public CModelReaderNode {
private:
PModelMeshObject m_pMesh;
CModel * m_pModel;
std::vector<PModelTriangleSet> m_pTriangleSets;

ModelResourceID m_nObjectLevelPropertyID;
PPackageResourceID m_pObjectLevelPropertyID;
Expand All @@ -72,6 +74,8 @@ namespace NMR {
virtual void parseXML(_In_ CXmlReader * pXMLReader);
void retrieveClippingInfo(_Out_ eModelBeamLatticeClipMode &eClipMode, _Out_ nfBool & bHasClippingMode, _Out_ ModelResourceID & nClippingMeshID);
void retrieveRepresentationInfo(_Out_ nfBool & bHasRepresentation, _Out_ ModelResourceID & nRepresentationMeshID);

std::vector<PModelTriangleSet> getTriangleSets ();
};
typedef std::shared_ptr <CModelReaderNode100_Mesh> PModelReaderNode100_Mesh;
}
Expand Down
63 changes: 63 additions & 0 deletions Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*++
Copyright (C) 2019 3MF Consortium
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--*/

#ifndef __NMR_MODELREADERNODE100_TRIANGLESET
#define __NMR_MODELREADERNODE100_TRIANGLESET

#include "Model/Reader/NMR_ModelReaderNode.h"
#include "Model/Classes/NMR_ModelComponent.h"
#include "Model/Classes/NMR_ModelObject.h"
#include "Model/Classes/NMR_ModelTriangleSet.h"

namespace NMR {

class CModelReaderNode100_TriangleSet : public CModelReaderNode {
protected:

std::string m_sName;
std::string m_sIdentifier;

PModelTriangleSet m_pTriangleSet;

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);

public:
CModelReaderNode100_TriangleSet() = delete;
CModelReaderNode100_TriangleSet(_In_ PModelWarnings pWarnings);

virtual void parseXML(_In_ CXmlReader * pXMLReader);

PModelTriangleSet createTriangleSet();
};

typedef std::shared_ptr <CModelReaderNode100_TriangleSet> PModelReaderNode100_TriangleSet;

}

#endif // __NMR_MODELREADERNODE100_TRIANGLESET
55 changes: 55 additions & 0 deletions Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSetRef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*++
Copyright (C) 2019 3MF Consortium
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--*/

#ifndef __NMR_MODELREADERNODE100_TRIANGLESETREF
#define __NMR_MODELREADERNODE100_TRIANGLESETREF

#include "Model/Reader/NMR_ModelReaderNode.h"

namespace NMR {

class CModelReaderNode100_TriangleSetRef : public CModelReaderNode {
protected:

uint32_t m_nIndex;

virtual void OnAttribute(_In_z_ const nfChar * pAttributeName, _In_z_ const nfChar * pAttributeValue);
public:
CModelReaderNode100_TriangleSetRef() = delete;
CModelReaderNode100_TriangleSetRef(_In_ PModelWarnings pWarnings);

virtual void parseXML(_In_ CXmlReader * pXMLReader);

uint32_t getIndex();
};

typedef std::shared_ptr <CModelReaderNode100_TriangleSetRef> PModelReaderNode100_TriangleSetRef;

}

#endif // __NMR_MODELREADERNODE100_TRIANGLESETREF
62 changes: 62 additions & 0 deletions Include/Model/Reader/v100/NMR_ModelReaderNode100_TriangleSets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*++
Copyright (C) 2019 3MF Consortium
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--*/

#ifndef __NMR_MODELREADERNODE100_TRIANGLESETS
#define __NMR_MODELREADERNODE100_TRIANGLESETS

#include "Model/Reader/NMR_ModelReaderNode.h"
#include "Model/Classes/NMR_ModelComponent.h"
#include "Model/Classes/NMR_ModelObject.h"
#include "Model/Classes/NMR_ModelTriangleSet.h"

namespace NMR {

class CModelReaderNode100_TriangleSets : public CModelReaderNode {
protected:
CMesh * m_pMesh;
CModel * m_pModel;

std::vector <PModelTriangleSet> m_TriangleSets;

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);

public:
CModelReaderNode100_TriangleSets() = delete;
CModelReaderNode100_TriangleSets(_In_ CModel * pModel, _In_ CMesh * pMesh, _In_ PModelWarnings pWarnings);

virtual void parseXML(_In_ CXmlReader * pXMLReader);

std::vector <PModelTriangleSet> getTriangleSets ();
};

typedef std::shared_ptr <CModelReaderNode100_TriangleSets> PModelReaderNode100_TriangleSets;

}

#endif // __NMR_MODELREADERNODE100_TRIANGLESETS
5 changes: 4 additions & 1 deletion Source/Common/NMR_Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ namespace NMR {
case NMR_ERROR_INVALIDSLICEVERTEX: return "Invalid slice vertex index";
case NMR_ERROR_DUPLICATETRIANGLESET: return "Duplicate triangle set";
case NMR_ERROR_TOOMANYTRIANGLESETS: return "Too many triangle sets";

case NMR_ERROR_TRIANGLESETINVALIDATTRIBUTE: return "Invalid triangle set attribute";
case NMR_ERROR_TRIANGLESETMISSINGREFERENCEINDEX: return "Missing triangle set reference index";
case NMR_ERROR_TRIANGLESETNAMEMISSING: return "Triangle set name missing";
case NMR_ERROR_TRIANGLESETIDENTIFIERMISSING : return "Triangle set identifier missing";

// Model error codes (0x8XXX)
case NMR_ERROR_OPCREADFAILED: return "3MF Loading - OPC could not be loaded";
Expand Down
18 changes: 18 additions & 0 deletions Source/Model/Classes/NMR_ModelMeshObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,24 @@ namespace NMR {

}

PModelTriangleSet CModelMeshObject::addTriangleSet(PModelTriangleSet pModelTriangleSet)
{
if (pModelTriangleSet.get() == nullptr)
throw CNMRException(NMR_ERROR_INVALIDPARAM);

auto iIterator = m_TriangleSetMap.find(pModelTriangleSet->getIdentifier());
if (iIterator != m_TriangleSetMap.end())
throw CNMRException(NMR_ERROR_DUPLICATETRIANGLESET);

if (m_TriangleSets.size() >= TRIANGLESET_MAXCOUNT)
throw CNMRException(NMR_ERROR_TOOMANYTRIANGLESETS);

m_TriangleSets.push_back(pModelTriangleSet);
m_TriangleSetMap.insert(std::make_pair(pModelTriangleSet->getIdentifier(), pModelTriangleSet));

return pModelTriangleSet;
}

uint32_t CModelMeshObject::getTriangleSetCount()
{
return (uint32_t)m_TriangleSets.size();
Expand Down
18 changes: 18 additions & 0 deletions Source/Model/Reader/v100/NMR_ModelReaderNode100_Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ A mesh reader model node is a parser for the mesh node of an XML Model Stream.
#include "Model/Reader/v100/NMR_ModelReaderNode100_Mesh.h"
#include "Model/Reader/v100/NMR_ModelReaderNode100_Vertices.h"
#include "Model/Reader/v100/NMR_ModelReaderNode100_Triangles.h"
#include "Model/Reader/v100/NMR_ModelReaderNode100_TriangleSets.h"
#include "Model/Reader/BeamLattice1702/NMR_ModelReaderNode_BeamLattice1702_BeamLattice.h"
#include "Model/Reader/Volumetric2201/NMR_ModelReaderNode_Volumetric2201_VolumeData.h"

Expand Down Expand Up @@ -194,6 +195,23 @@ namespace NMR {
m_pWarnings->addException(CNMRException(NMR_ERROR_NAMESPACE_INVALID_ELEMENT), mrwInvalidOptionalValue);
}

if (strcmp(pNameSpace, XML_3MF_NAMESPACE_TRIANGLESETS) == 0) {
if (strcmp(pChildName, XML_3MF_ELEMENT_TRIANGLESETS) == 0)
{
PModelReaderNode100_TriangleSets pXMLNode = std::make_shared<CModelReaderNode100_TriangleSets>(m_pModel, m_pMesh, m_pWarnings);
pXMLNode->parseXML(pXMLReader);

m_pTriangleSets = pXMLNode->getTriangleSets ();
}
else
m_pWarnings->addException(CNMRException(NMR_ERROR_NAMESPACE_INVALID_ELEMENT), mrwInvalidOptionalValue);
}

}

std::vector<PModelTriangleSet> CModelReaderNode100_Mesh::getTriangleSets()
{
return m_pTriangleSets;
}

}
5 changes: 5 additions & 0 deletions Source/Model/Reader/v100/NMR_ModelReaderNode100_Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ namespace NMR {
m_pWarnings, m_pProgressMonitor, m_pObjectLevelPropertyID, m_nObjectLevelPropertyIndex);
pXMLNode->parseXML(pXMLReader);

// store triangle sets in memory model
auto triangleSets = pXMLNode->getTriangleSets();
for (auto triangleSet : triangleSets)
pModelMeshObject->addTriangleSet(triangleSet);

// Add Object to Parent
m_pModel->addResource(m_pObject);

Expand Down
Loading

0 comments on commit a20198c

Please sign in to comment.