EBGeometry  1.0
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
22 #include "EBGeometry_DCEL_Mesh.hpp"
26 
31 namespace Parser {
32 
36  enum class Encoding
37  {
38  ASCII,
39  Binary,
40  Unknown
41  };
42 
46  enum class FileType
47  {
48  STL,
49  PLY,
50  Unsupported
51  };
52 
57  template <typename T, typename Meta = DCEL::DefaultMetaData>
58  inline static std::shared_ptr<EBGeometry::DCEL::MeshT<T, Meta>>
59  readIntoDCEL(const std::string a_filename) noexcept;
60 
65  template <typename T, typename Meta = DCEL::DefaultMetaData>
66  inline static std::vector<std::shared_ptr<EBGeometry::DCEL::MeshT<T, Meta>>>
67  readIntoDCEL(const std::vector<std::string> a_files) noexcept;
68 
73  template <typename T, typename Meta = DCEL::DefaultMetaData>
74  inline static std::shared_ptr<MeshSDF<T, Meta>>
75  readIntoMesh(const std::string a_filename) noexcept;
76 
81  template <typename T, typename Meta = DCEL::DefaultMetaData>
82  inline static std::vector<std::shared_ptr<MeshSDF<T, Meta>>>
83  readIntoMesh(const std::vector<std::string> a_files) noexcept;
84 
89  template <typename T,
90  typename Meta = DCEL::DefaultMetaData,
91  typename BV = EBGeometry::BoundingVolumes::AABBT<T>,
92  size_t K = 4>
93  inline static std::shared_ptr<FastMeshSDF<T, Meta, BV, K>>
94  readIntoFullBVH(const std::string a_filename) noexcept;
95 
100  template <typename T,
101  typename Meta = DCEL::DefaultMetaData,
102  typename BV = EBGeometry::BoundingVolumes::AABBT<T>,
103  size_t K = 4>
104  inline static std::vector<std::shared_ptr<FastMeshSDF<T, Meta, BV, K>>>
105  readIntoFullBVH(const std::vector<std::string> a_files) noexcept;
106 
111  template <typename T,
112  typename Meta = DCEL::DefaultMetaData,
113  typename BV = EBGeometry::BoundingVolumes::AABBT<T>,
114  size_t K = 4>
115  inline static std::shared_ptr<FastCompactMeshSDF<T, Meta, BV, K>>
116  readIntoLinearBVH(const std::string a_filename) noexcept;
117 
122  template <typename T,
123  typename Meta = DCEL::DefaultMetaData,
124  typename BV = EBGeometry::BoundingVolumes::AABBT<T>,
125  size_t K = 4>
126  inline static std::vector<std::shared_ptr<FastCompactMeshSDF<T, Meta, BV, K>>>
127  readIntoLinearBVH(const std::vector<std::string> a_files) noexcept;
128 
133  inline static Parser::FileType
134  getFileType(const std::string a_filename) noexcept;
135 
141  template <typename T>
142  inline static bool
143  containsDegeneratePolygons(const std::vector<EBGeometry::Vec3T<T>>& a_vertices,
144  const std::vector<std::vector<size_t>>& a_facets) noexcept;
145 
151  template <typename T>
152  inline static void
153  compress(std::vector<EBGeometry::Vec3T<T>>& a_vertices, std::vector<std::vector<size_t>>& a_facets) noexcept;
154 
161  template <typename T, typename Meta>
162  inline static void
163  soupToDCEL(EBGeometry::DCEL::MeshT<T, Meta>& a_mesh,
164  const std::vector<EBGeometry::Vec3T<T>>& a_vertices,
165  const std::vector<std::vector<size_t>>& a_facets) noexcept;
166 
172  template <typename T, typename Meta>
173  inline static void
174  reconcilePairEdgesDCEL(std::vector<std::shared_ptr<EBGeometry::DCEL::EdgeT<T, Meta>>>& a_edges) noexcept;
175 
180  template <typename T, typename Meta>
181  class STL
182  {
183  public:
187  using Vec3 = EBGeometry::Vec3T<T>;
188 
192  using Vertex = EBGeometry::DCEL::VertexT<T, Meta>;
193 
197  using Edge = EBGeometry::DCEL::EdgeT<T, Meta>;
198 
202  using Face = EBGeometry::DCEL::FaceT<T, Meta>;
203 
207  using Mesh = EBGeometry::DCEL::MeshT<T, Meta>;
208 
212  using EdgeIterator = EBGeometry::DCEL::EdgeIteratorT<T, Meta>;
213 
219  inline static std::shared_ptr<Mesh>
220  readSingle(const std::string a_filename) noexcept;
221 
226  inline static std::vector<std::pair<std::shared_ptr<Mesh>, std::string>>
227  readMulti(const std::string a_filename) noexcept;
228 
229  protected:
235  inline static Encoding
236  getEncoding(const std::string a_filename) noexcept;
237 
242  inline static std::vector<std::pair<std::shared_ptr<Mesh>, std::string>>
243  readASCII(const std::string a_filename) noexcept;
244 
249  inline static std::vector<std::pair<std::shared_ptr<Mesh>, std::string>>
250  readBinary(const std::string a_filename) noexcept;
251 
261  inline static void
262  readSTLSoupASCII(std::vector<Vec3>& a_vertices,
263  std::vector<std::vector<size_t>>& a_facets,
264  std::string& a_objectName,
265  const std::vector<std::string>& a_fileContents,
266  const size_t a_firstLine,
267  const size_t a_lastLine) noexcept;
268  };
269 
274  template <typename T>
275  class PLY
276  {
277  public:
281  using Vec3 = EBGeometry::Vec3T<T>;
282 
286  using Vertex = EBGeometry::DCEL::VertexT<T>;
287 
291  using Edge = EBGeometry::DCEL::EdgeT<T>;
292 
296  using Face = EBGeometry::DCEL::FaceT<T>;
297 
301  using Mesh = EBGeometry::DCEL::MeshT<T>;
302 
306  using EdgeIterator = EBGeometry::DCEL::EdgeIteratorT<T>;
307 
313  inline static std::shared_ptr<Mesh>
314  read(const std::string a_filename) noexcept;
315 
316  protected:
322  inline static Encoding
323  getEncoding(const std::string a_filename) noexcept;
324 
332  inline static void
333  readPLYSoupASCII(std::vector<Vec3>& a_vertices,
334  std::vector<std::vector<size_t>>& a_faces,
335  std::ifstream& a_fileStream) noexcept;
336 
344  inline static void
345  readPLYSoupBinary(std::vector<Vec3>& a_vertices,
346  std::vector<std::vector<size_t>>& a_faces,
347  std::ifstream& a_fileStream) noexcept;
348  };
349 } // namespace Parser
350 
352 
353 #include "EBGeometry_ParserImplem.hpp"
354 
355 #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.
Class for reading Stanford PLY files.
Definition: EBGeometry_Parser.hpp:276
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.
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:301
EBGeometry::DCEL::FaceT< T > Face
Alias for face type.
Definition: EBGeometry_Parser.hpp:296
EBGeometry::DCEL::EdgeT< T > Edge
Alias for edge type.
Definition: EBGeometry_Parser.hpp:291
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::DCEL::VertexT< T > Vertex
Alias for vertex type.
Definition: EBGeometry_Parser.hpp:286
EBGeometry::DCEL::EdgeIteratorT< T > EdgeIterator
Alias for edge iterator type.
Definition: EBGeometry_Parser.hpp:306
EBGeometry::Vec3T< T > Vec3
Alias for vector type.
Definition: EBGeometry_Parser.hpp:281
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.
Class for reading STL files.
Definition: EBGeometry_Parser.hpp:182
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.
EBGeometry::DCEL::EdgeT< T, Meta > Edge
Alias for edge type.
Definition: EBGeometry_Parser.hpp:197
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:187
EBGeometry::DCEL::FaceT< T, Meta > Face
Alias for face type.
Definition: EBGeometry_Parser.hpp:202
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::MeshT< T, Meta > Mesh
Alias for mesh type.
Definition: EBGeometry_Parser.hpp:207
EBGeometry::DCEL::EdgeIteratorT< T, Meta > EdgeIterator
Alias for edge iterator type.
Definition: EBGeometry_Parser.hpp:212
static Encoding getEncoding(const std::string a_filename) noexcept
Check if the input STL file is an ASCII file or a binary.
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::VertexT< T, Meta > Vertex
Alias for vertex type.
Definition: EBGeometry_Parser.hpp:192
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.
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:31
Encoding
Simple enum for separating ASCII and binary files.
Definition: EBGeometry_Parser.hpp:37
FileType
Various supported file types.
Definition: EBGeometry_Parser.hpp:47