16 #ifndef SURGSIM_DATASTRUCTURES_TRIANGLEMESHPLYREADERDELEGATE_INL_H 17 #define SURGSIM_DATASTRUCTURES_TRIANGLEMESHPLYREADERDELEGATE_INL_H 25 m_mesh(
std::make_shared<M>()),
26 m_hasTextureCoordinates(false),
37 m_hasTextureCoordinates(false),
56 std::bind(&TriangleMeshPlyReaderDelegate::beginVertices,
this,
57 std::placeholders::_1, std::placeholders::_2),
58 std::bind(&TriangleMeshPlyReaderDelegate::processVertex,
this, std::placeholders::_1),
59 std::bind(&TriangleMeshPlyReaderDelegate::endVertices,
this, std::placeholders::_1));
67 if (m_hasTextureCoordinates)
78 std::bind(&TriangleMeshPlyReaderDelegate::beginFaces,
this,
79 std::placeholders::_1, std::placeholders::_2),
80 std::bind(&TriangleMeshPlyReaderDelegate::processFace,
this, std::placeholders::_1),
81 std::bind(&TriangleMeshPlyReaderDelegate::endFaces,
this, std::placeholders::_1));
83 PlyReader::TYPE_UNSIGNED_INT,
84 offsetof(ListData, indices),
85 PlyReader::TYPE_UNSIGNED_INT,
86 offsetof(ListData, count));
94 std::bind(&TriangleMeshPlyReaderDelegate::beginEdges,
this,
95 std::placeholders::_1, std::placeholders::_2),
96 std::bind(&TriangleMeshPlyReaderDelegate::processEdge,
this, std::placeholders::_1),
97 std::bind(&TriangleMeshPlyReaderDelegate::endEdges,
this, std::placeholders::_1));
99 PlyReader::TYPE_UNSIGNED_INT,
100 offsetof(ListData, indices),
101 PlyReader::TYPE_UNSIGNED_INT,
102 offsetof(ListData, count));
115 m_hasFaces = reader.
hasProperty(
"face",
"vertex_indices") &&
116 !reader.
isScalar(
"face",
"vertex_indices");
118 m_hasEdges = reader.
hasProperty(
"1d_element",
"vertex_indices") &&
119 !reader.
isScalar(
"1d_element",
"vertex_indices");
122 result = result && reader.
hasProperty(
"vertex",
"x");
123 result = result && reader.
hasProperty(
"vertex",
"y");
124 result = result && reader.
hasProperty(
"vertex",
"z");
125 result = result && (m_hasFaces || m_hasEdges);
132 const std::string& elementName,
135 m_vertexData.overrun1 = 0l;
136 m_vertexData.overrun2 = 0l;
137 return &m_vertexData;
144 m_mesh->addVertex(vertex);
150 SURGSIM_ASSERT(m_vertexData.overrun1 == 0l && m_vertexData.overrun2 == 0l) <<
151 "There was an overrun while reading the vertex structures, it is likely that data " <<
152 "has become corrupted.";
157 const std::string& elementName,
160 m_listData.overrun = 0l;
167 SURGSIM_ASSERT(m_listData.count == 3) <<
"Can only process triangle meshes.";
168 std::copy(m_listData.indices, m_listData.indices + 3, m_face.begin());
170 typename M::TriangleType triangle(m_face);
171 m_mesh->addTriangle(triangle);
178 <<
"There was an overrun while reading the face structures, it is likely that data " 179 <<
"has become corrupted.";
191 return m_hasTextureCoordinates;
198 m_listData.overrun = 0l;
206 SURGSIM_ASSERT(m_listData.count == 2) <<
"Edges have to have 2 points.";
207 std::copy(m_listData.indices, m_listData.indices + 2, m_edge.begin());
209 typename M::EdgeType edge(m_edge);
210 m_mesh->addEdge(edge);
218 <<
"There was an overrun while reading the face structures, it is likely that data " 219 <<
"has become corrupted.";
std::shared_ptr< MeshType > getMesh()
Gets the mesh.
Definition: TriangleMeshPlyReaderDelegate-inl.h:46
bool hasProperty(const std::string &elementName, const std::string &propertyName) const
Query if 'elementName' has the given property.
Definition: PlyReader.cpp:353
bool hasTextureCoordinates()
Definition: TriangleMeshPlyReaderDelegate-inl.h:189
virtual void processVertex(const std::string &elementName)
Callback function to process one vertex.
Definition: TriangleMeshPlyReaderDelegate-inl.h:141
void endFaces(const std::string &elementName)
Callback function to finalize processing of faces.
Definition: TriangleMeshPlyReaderDelegate-inl.h:175
bool registerDelegate(PlyReader *reader) override
Registers the delegate with the reader, overridden from.
Definition: TriangleMeshPlyReaderDelegate-inl.h:52
bool requestScalarProperty(const std::string &elementName, const std::string &propertyName, int dataType, int dataOffset)
Request a scalar property for parsing.
Definition: PlyReader.cpp:121
Definition: MockObjects.h:47
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
void endVertices(const std::string &elementName)
Callback function to finalize processing of vertices.
Definition: TriangleMeshPlyReaderDelegate-inl.h:148
Wrapper for the C .ply file parser This class wraps the main functionality for the original C ...
Definition: PlyReader.h:85
TriangleMeshPlyReaderDelegate()
Default constructor.
Definition: TriangleMeshPlyReaderDelegate-inl.h:24
void endFile()
Callback function to finalize processing of the mesh.
Definition: TriangleMeshPlyReaderDelegate-inl.h:183
Implementation of PlyReaderDelegate for simple triangle meshes.
Definition: TriangleMeshPlyReaderDelegate.h:33
bool requestListProperty(const std::string &elementName, const std::string &propertyName, int dataType, int dataOffset, int countType, int countOffset)
Request a list property for parsing.
Definition: PlyReader.cpp:127
bool isScalar(const std::string &elementName, const std::string &propertyName) const
Query if the property of the give element is scalar.
Definition: PlyReader.cpp:367
void processFace(const std::string &elementName)
Callback function to process one face.
Definition: TriangleMeshPlyReaderDelegate-inl.h:165
Definitions of small fixed-size vector types.
bool requestElement(const std::string &elementName, std::function< void *(const std::string &, size_t)> startElementCallback, std::function< void(const std::string &)> processElementCallback, std::function< void(const std::string &)> endElementCallback)
Request element to be processed during parsing.
Definition: PlyReader.cpp:97
void * beginVertices(const std::string &elementName, size_t vertexCount)
Callback function, begin the processing of vertices.
Definition: TriangleMeshPlyReaderDelegate-inl.h:131
void setEndParseFileCallback(std::function< void(void)> endParseFileCallback)
Register callback to be called at the end of parseFile.
Definition: PlyReader.cpp:140
bool fileIsAcceptable(const PlyReader &reader) override
Check whether this file is acceptable to the delegate, overridden from.
Definition: TriangleMeshPlyReaderDelegate-inl.h:111
void * beginFaces(const std::string &elementName, size_t faceCount)
Callback function, begin the processing of faces.
Definition: TriangleMeshPlyReaderDelegate-inl.h:156