EBGeometry 1.0
Loading...
Searching...
No Matches
EBGeometry_Parser.hpp
Go to the documentation of this file.
1/* EBGeometry
2 * Copyright © 2022 Robert Marskar
3 * Please refer to Copyright.txt and LICENSE in the EBGeometry root directory.
4 */
5
13#ifndef EBGeometry_Parser
14#define EBGeometry_Parser
15
16// Std includes
17#include <vector>
18#include <memory>
19#include <map>
20
21// Our includes
27
32namespace Parser {
33
37 enum class Encoding
38 {
39 ASCII,
40 Binary,
41 Unknown
42 };
43
47 enum class FileType
48 {
49 STL,
50 PLY,
51 Unsupported
52 };
53
58 template <typename T, typename Meta = DCEL::DefaultMetaData>
59 inline static std::shared_ptr<EBGeometry::DCEL::MeshT<T, Meta>>
60 readIntoDCEL(const std::string a_filename) noexcept;
61
66 template <typename T, typename Meta = DCEL::DefaultMetaData>
67 inline static std::vector<std::shared_ptr<EBGeometry::DCEL::MeshT<T, Meta>>>
68 readIntoDCEL(const std::vector<std::string> a_files) noexcept;
69
74 template <typename T, typename Meta = DCEL::DefaultMetaData>
75 inline static std::shared_ptr<MeshSDF<T, Meta>>
76 readIntoMesh(const std::string a_filename) noexcept;
77
82 template <typename T, typename Meta = DCEL::DefaultMetaData>
83 inline static std::vector<std::shared_ptr<MeshSDF<T, Meta>>>
84 readIntoMesh(const std::vector<std::string> a_files) noexcept;
85
90 template <typename T,
91 typename Meta = DCEL::DefaultMetaData,
92 typename BV = EBGeometry::BoundingVolumes::AABBT<T>,
93 size_t K = 4>
94 inline static std::shared_ptr<FastMeshSDF<T, Meta, BV, K>>
95 readIntoFullBVH(const std::string a_filename) noexcept;
96
101 template <typename T,
102 typename Meta = DCEL::DefaultMetaData,
103 typename BV = EBGeometry::BoundingVolumes::AABBT<T>,
104 size_t K = 4>
105 inline static std::vector<std::shared_ptr<FastMeshSDF<T, Meta, BV, K>>>
106 readIntoFullBVH(const std::vector<std::string> a_files) noexcept;
107
112 template <typename T,
113 typename Meta = DCEL::DefaultMetaData,
114 typename BV = EBGeometry::BoundingVolumes::AABBT<T>,
115 size_t K = 4>
116 inline static std::shared_ptr<FastCompactMeshSDF<T, Meta, BV, K>>
117 readIntoLinearBVH(const std::string a_filename) noexcept;
118
123 template <typename T,
124 typename Meta = DCEL::DefaultMetaData,
125 typename BV = EBGeometry::BoundingVolumes::AABBT<T>,
126 size_t K = 4>
127 inline static std::vector<std::shared_ptr<FastCompactMeshSDF<T, Meta, BV, K>>>
128 readIntoLinearBVH(const std::vector<std::string> a_files) noexcept;
129
134 template <typename T, typename Meta, typename BV = EBGeometry::BoundingVolumes::AABBT<T>, size_t K = 4>
135 inline static std::shared_ptr<FastTriMeshSDF<T, Meta, BV, K>>
136 readIntoTriangleBVH(const std::string a_filename) noexcept;
137
142 template <typename T,
143 typename Meta = DCEL::DefaultMetaData,
144 typename BV = EBGeometry::BoundingVolumes::AABBT<T>,
145 size_t K = 4>
146 inline static std::vector<std::shared_ptr<FastMeshSDF<T, Meta, BV, K>>>
147 readIntoTriangleBVH(const std::vector<std::string> a_files) noexcept;
148
153 template <typename T, typename Meta>
154 inline static std::vector<std::shared_ptr<Triangle<T, Meta>>>
155 readIntoTriangles(const std::string a_filename) noexcept;
156
161 template <typename T, typename Meta>
162 inline static std::vector<std::vector<std::shared_ptr<Triangle<T, Meta>>>>
163 readIntoTriangles(const std::vector<std::string> a_files) noexcept;
164
169 inline static Parser::FileType
170 getFileType(const std::string a_filename) noexcept;
171
177 template <typename T>
178 inline static bool
179 containsDegeneratePolygons(const std::vector<EBGeometry::Vec3T<T>>& a_vertices,
180 const std::vector<std::vector<size_t>>& a_facets) noexcept;
181
187 template <typename T>
188 inline static void
189 compress(std::vector<EBGeometry::Vec3T<T>>& a_vertices, std::vector<std::vector<size_t>>& a_facets) noexcept;
190
197 template <typename T, typename Meta>
198 inline static void
199 soupToDCEL(EBGeometry::DCEL::MeshT<T, Meta>& a_mesh,
200 const std::vector<EBGeometry::Vec3T<T>>& a_vertices,
201 const std::vector<std::vector<size_t>>& a_facets) noexcept;
202
208 template <typename T, typename Meta>
209 inline static void
210 reconcilePairEdgesDCEL(std::vector<std::shared_ptr<EBGeometry::DCEL::EdgeT<T, Meta>>>& a_edges) noexcept;
211
216 template <typename T, typename Meta>
217 class STL
218 {
219 public:
223 using Vec3 = EBGeometry::Vec3T<T>;
224
228 using Vertex = EBGeometry::DCEL::VertexT<T, Meta>;
229
233 using Edge = EBGeometry::DCEL::EdgeT<T, Meta>;
234
238 using Face = EBGeometry::DCEL::FaceT<T, Meta>;
239
243 using Mesh = EBGeometry::DCEL::MeshT<T, Meta>;
244
248 using EdgeIterator = EBGeometry::DCEL::EdgeIteratorT<T, Meta>;
249
255 inline static std::shared_ptr<Mesh>
256 readSingle(const std::string a_filename) noexcept;
257
262 inline static std::vector<std::pair<std::shared_ptr<Mesh>, std::string>>
263 readMulti(const std::string a_filename) noexcept;
264
265 protected:
271 inline static Encoding
272 getEncoding(const std::string a_filename) noexcept;
273
278 inline static std::vector<std::pair<std::shared_ptr<Mesh>, std::string>>
279 readASCII(const std::string a_filename) noexcept;
280
285 inline static std::vector<std::pair<std::shared_ptr<Mesh>, std::string>>
286 readBinary(const std::string a_filename) noexcept;
287
297 inline static void
298 readSTLSoupASCII(std::vector<Vec3>& a_vertices,
299 std::vector<std::vector<size_t>>& a_facets,
300 std::string& a_objectName,
301 const std::vector<std::string>& a_fileContents,
302 const size_t a_firstLine,
303 const size_t a_lastLine) noexcept;
304 };
305
310 template <typename T>
311 class PLY
312 {
313 public:
317 using Vec3 = EBGeometry::Vec3T<T>;
318
322 using Vertex = EBGeometry::DCEL::VertexT<T>;
323
327 using Edge = EBGeometry::DCEL::EdgeT<T>;
328
332 using Face = EBGeometry::DCEL::FaceT<T>;
333
337 using Mesh = EBGeometry::DCEL::MeshT<T>;
338
342 using EdgeIterator = EBGeometry::DCEL::EdgeIteratorT<T>;
343
349 inline static std::shared_ptr<Mesh>
350 read(const std::string a_filename) noexcept;
351
352 protected:
358 inline static Encoding
359 getEncoding(const std::string a_filename) noexcept;
360
368 inline static void
369 readPLYSoupASCII(std::vector<Vec3>& a_vertices,
370 std::vector<std::vector<size_t>>& a_faces,
371 std::ifstream& a_fileStream) noexcept;
372
380 inline static void
381 readPLYSoupBinary(std::vector<Vec3>& a_vertices,
382 std::vector<std::vector<size_t>>& a_faces,
383 std::ifstream& a_fileStream) noexcept;
384 };
385} // namespace Parser
386
388
389#include "EBGeometry_ParserImplem.hpp"
390
391#endif
Declaration of a various bounding volumes used for bounding volume hierarchy.
Declaration of a mesh class which stores a DCEL mesh (with signed distance functions)
Declaration of signed distance functions for DCEL meshes.
Declaration of a triangle class with signed distance functionality.
Class for reading Stanford PLY files.
Definition EBGeometry_Parser.hpp:312
static Encoding getEncoding(const std::string a_filename) noexcept
Check if the input PLY file is an ASCII file or a binary.
EBGeometry::DCEL::MeshT< T > Mesh
Alias for mesh type.
Definition EBGeometry_Parser.hpp:337
static void readPLYSoupBinary(std::vector< Vec3 > &a_vertices, std::vector< std::vector< size_t > > &a_faces, std::ifstream &a_fileStream) noexcept
Read a binary PLY file into a triangle soup.
EBGeometry::DCEL::FaceT< T > Face
Alias for face type.
Definition EBGeometry_Parser.hpp:332
EBGeometry::DCEL::EdgeT< T > Edge
Alias for edge type.
Definition EBGeometry_Parser.hpp:327
static std::shared_ptr< Mesh > read(const std::string a_filename) noexcept
Static function which reads an ASCII .ply file and returns a DCEL mesh.
EBGeometry::DCEL::VertexT< T > Vertex
Alias for vertex type.
Definition EBGeometry_Parser.hpp:322
EBGeometry::DCEL::EdgeIteratorT< T > EdgeIterator
Alias for edge iterator type.
Definition EBGeometry_Parser.hpp:342
static void readPLYSoupASCII(std::vector< Vec3 > &a_vertices, std::vector< std::vector< size_t > > &a_faces, std::ifstream &a_fileStream) noexcept
Read an ASCII PLY file into a triangle soup.
EBGeometry::Vec3T< T > Vec3
Alias for vector type.
Definition EBGeometry_Parser.hpp:317
Class for reading STL files.
Definition EBGeometry_Parser.hpp:218
EBGeometry::DCEL::EdgeT< T, Meta > Edge
Alias for edge type.
Definition EBGeometry_Parser.hpp:233
static std::vector< std::pair< std::shared_ptr< Mesh >, std::string > > readBinary(const std::string a_filename) noexcept
Binary reader for STL files, possibly containing multiple objects. Each object becomes a DCEL mesh.
EBGeometry::Vec3T< T > Vec3
Alias for vector type.
Definition EBGeometry_Parser.hpp:223
EBGeometry::DCEL::FaceT< T, Meta > Face
Alias for face type.
Definition EBGeometry_Parser.hpp:238
static void readSTLSoupASCII(std::vector< Vec3 > &a_vertices, std::vector< std::vector< size_t > > &a_facets, std::string &a_objectName, const std::vector< std::string > &a_fileContents, const size_t a_firstLine, const size_t a_lastLine) noexcept
Read an STL object as a triangle soup into a raw vertices and facets.
EBGeometry::DCEL::MeshT< T, Meta > Mesh
Alias for mesh type.
Definition EBGeometry_Parser.hpp:243
static std::shared_ptr< Mesh > readSingle(const std::string a_filename) noexcept
Read a single STL object from the input file. The file can be binary or ASCII. If the STL file contai...
EBGeometry::DCEL::EdgeIteratorT< T, Meta > EdgeIterator
Alias for edge iterator type.
Definition EBGeometry_Parser.hpp:248
static std::vector< std::pair< std::shared_ptr< Mesh >, std::string > > readMulti(const std::string a_filename) noexcept
Read a single STL object from the input file. The file can be binary or ASCII.
static Encoding getEncoding(const std::string a_filename) noexcept
Check if the input STL file is an ASCII file or a binary.
static std::vector< std::pair< std::shared_ptr< Mesh >, std::string > > readASCII(const std::string a_filename) noexcept
ASCII reader STL files, possibly containing multiple objects. Each object becomes a DCEL mesh.
EBGeometry::DCEL::VertexT< T, Meta > Vertex
Alias for vertex type.
Definition EBGeometry_Parser.hpp:228
Three-dimensional vector class with arithmetic operators.
Definition EBGeometry_Vec.hpp:218
short DefaultMetaData
Default meta-data type for the DCEL primitives.
Definition EBGeometry_DCEL.hpp:27
Namespace which encapsulates possible file parsers for building EBGeometry data structures.
Definition EBGeometry_Parser.hpp:32
Encoding
Simple enum for separating ASCII and binary files.
Definition EBGeometry_Parser.hpp:38
FileType
Various supported file types.
Definition EBGeometry_Parser.hpp:48