Volume Cartographer 2.27.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
OBJReader.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <fstream>
6
7#include <opencv2/core.hpp>
8
12
13namespace volcart::io
14{
15
30{
31public:
33 void setPath(const filesystem::path& p);
34
36 auto read() -> ITKMesh::Pointer;
37
39 auto getMesh() -> ITKMesh::Pointer;
40
47
54 auto getTextureMat() -> cv::Mat;
55
56private:
67 using VertexRefs = cv::Vec3i;
69 using Face = std::vector<VertexRefs>;
70
73 enum class RefType {
74 Invalid,
75 Vertex,
76 VertexWithTexture,
77 VertexWithNormal,
78 VertexWithTextureAndNormal
79 };
80
82 void reset_();
83
85 void parse_();
87 void parse_vertex_(const std::vector<std::string>& strs);
89 void parse_normal_(const std::vector<std::string>& strs);
91 void parse_tcoord_(const std::vector<std::string>& strs);
93 void parse_face_(const std::vector<std::string>& strs);
95 void parse_mtllib_(const std::vector<std::string>& strs);
97 auto classify_vertref_(const std::string& ref) -> RefType;
98
101
103 filesystem::path path_;
105 filesystem::path texturePath_;
107 ITKMesh::Pointer mesh_;
111 cv::Mat textureMat_;
112
114 std::vector<cv::Vec3d> vertices_;
116 std::vector<cv::Vec3d> normals_;
118 std::vector<cv::Vec2d> uvs_;
120 std::vector<OBJReader::Face> faces_;
121};
122
123} // namespace volcart::io
std::shared_ptr< UVMap > Pointer
Definition: UVMap.hpp:55
Read an OBJ file into a volcart::ITKMesh.
Definition: OBJReader.hpp:30
std::vector< cv::Vec3d > vertices_
Definition: OBJReader.hpp:114
RefType
Validation enumeration to ensure proper parsing of OBJReader::VertexRefs.
Definition: OBJReader.hpp:73
std::vector< cv::Vec2d > uvs_
Definition: OBJReader.hpp:118
filesystem::path path_
Definition: OBJReader.hpp:103
std::vector< cv::Vec3d > normals_
Definition: OBJReader.hpp:116
void parse_normal_(const std::vector< std::string > &strs)
auto classify_vertref_(const std::string &ref) -> RefType
void parse_vertex_(const std::vector< std::string > &strs)
auto getTextureMat() -> cv::Mat
Return texture image as cv::Mat.
std::vector< OBJReader::Face > faces_
Definition: OBJReader.hpp:120
filesystem::path texturePath_
Definition: OBJReader.hpp:105
void parse_face_(const std::vector< std::string > &strs)
auto read() -> ITKMesh::Pointer
Read the mesh from file.
auto getUVMap() -> UVMap::Pointer
Return parsed UV information.
cv::Vec3i VertexRefs
3-Tuple linking a vertex to its position, UV, and normal elements
Definition: OBJReader.hpp:67
void parse_mtllib_(const std::vector< std::string > &strs)
void setPath(const filesystem::path &p)
Set the OBJ file path.
ITKMesh::Pointer mesh_
Definition: OBJReader.hpp:107
auto getMesh() -> ITKMesh::Pointer
Return the parsed mesh.
void parse_tcoord_(const std::vector< std::string > &strs)
UVMap::Pointer uvMap_
Definition: OBJReader.hpp:109
std::vector< VertexRefs > Face
A list of at least three OBJReader::VertexRefs comprise a face.
Definition: OBJReader.hpp:69
IO classes.