25 #include "opencv2/core/core.hpp" 27 #include "boost/filesystem/path.hpp" 51 std::vector<std::array<int, 3>>
tvi;
52 std::vector<std::array<int, 3>>
tci;
67 std::ofstream obj_file(filename);
70 for (std::size_t i = 0; i < mesh.
vertices.size(); ++i) {
71 obj_file <<
"v " << mesh.
vertices[i][0] <<
" " << mesh.
vertices[i][1] <<
" " << mesh.
vertices[i][2] <<
" " << std::endl;
75 for (std::size_t i = 0; i < mesh.
vertices.size(); ++i) {
80 for (
auto&& v : mesh.
tvi) {
82 obj_file <<
"f " << v[0] + 1 <<
" " << v[1] + 1 <<
" " << v[2] + 1 << std::endl;
103 std::ofstream obj_file(filename);
105 boost::filesystem::path mtl_filename(filename);
106 mtl_filename.replace_extension(
".mtl");
108 obj_file <<
"mtllib " << mtl_filename.filename().string() << std::endl;
111 if (mesh.
colors.empty()) {
112 for (std::size_t i = 0; i < mesh.
vertices.size(); ++i) {
113 obj_file <<
"v " << mesh.
vertices[i][0] <<
" " << mesh.
vertices[i][1] <<
" " << mesh.
vertices[i][2] <<
" " << std::endl;
117 for (std::size_t i = 0; i < mesh.
vertices.size(); ++i) {
123 for (std::size_t i = 0; i < mesh.
texcoords.size(); ++i) {
124 obj_file <<
"vt " << mesh.
texcoords[i][0] <<
" " << 1.0f - mesh.
texcoords[i][1] << std::endl;
128 obj_file <<
"usemtl FaceTexture" << std::endl;
130 for (
auto&& v : mesh.
tvi) {
133 obj_file <<
"f " << v[0] + 1 <<
"/" << v[0] + 1 <<
" " << v[1] + 1 <<
"/" << v[1] + 1 <<
" " << v[2] + 1 <<
"/" << v[2] + 1 << std::endl;
136 std::ofstream mtl_file(mtl_filename.string());
137 boost::filesystem::path texture_filename(filename);
138 texture_filename.replace_extension(
".isomap.png");
140 mtl_file <<
"newmtl FaceTexture" << std::endl;
141 mtl_file <<
"map_Kd " << texture_filename.filename().string() << std::endl;
std::vector< std::array< int, 3 > > tci
Triangle color indices.
Definition: Mesh.hpp:52
std::pair< cv::Mat, cv::Mat > render(Mesh mesh, cv::Mat model_view_matrix, cv::Mat projection_matrix, int viewport_width, int viewport_height, const boost::optional< Texture > &texture=boost::none, bool enable_backface_culling=false, bool enable_near_clipping=true, bool enable_far_clipping=true)
Definition: render.hpp:125
void write_obj(Mesh mesh, std::string filename)
Writes the given Mesh to an obj file that for example can be read by MeshLab.
Definition: Mesh.hpp:63
Namespace containing all of eos's 3D model fitting functionality.
std::vector< cv::Vec4f > vertices
3D vertex positions.
Definition: Mesh.hpp:47
std::vector< cv::Vec3f > colors
Colour information for each vertex. Expected to be in RGB order.
Definition: Mesh.hpp:48
This class represents a 3D mesh consisting of vertices, vertex colour information and texture coordin...
Definition: Mesh.hpp:45
std::vector< std::array< int, 3 > > tvi
Triangle vertex indices.
Definition: Mesh.hpp:51
std::vector< cv::Vec2f > texcoords
Texture coordinates for each vertex.
Definition: Mesh.hpp:49
void write_textured_obj(Mesh mesh, std::string filename)
Writes an obj file of the given Mesh, including texture coordinates, and an mtl file containing a ref...
Definition: Mesh.hpp:99