MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
mesh_io.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#include <stdexcept>
11
12#include "util/strings.h"
13#include "mve/mesh.h"
14#include "mve/mesh_io.h"
15#include "mve/mesh_io_ply.h"
16#include "mve/mesh_io_off.h"
17#include "mve/mesh_io_npts.h"
18#include "mve/mesh_io_pbrt.h"
19#include "mve/mesh_io_smf.h"
20#include "mve/mesh_io_obj.h"
21
24
25TriangleMesh::Ptr
26load_mesh (std::string const& filename)
27{
28 if (util::string::right(filename, 4) == ".off")
29 return load_off_mesh(filename);
30 else if (util::string::right(filename, 4) == ".ply")
31 return load_ply_mesh(filename);
32 else if (util::string::right(filename, 5) == ".npts")
33 return load_npts_mesh(filename, false);
34 else if (util::string::right(filename, 6) == ".bnpts")
35 return load_npts_mesh(filename, true);
36 else if (util::string::right(filename, 4) == ".smf")
37 return load_smf_mesh(filename);
38 else if (util::string::right(filename, 4) == ".obj")
39 return load_obj_mesh(filename);
40 else
41 throw std::runtime_error("Extension not recognized");
42}
43
44/* ---------------------------------------------------------------- */
45
46void
47save_mesh (TriangleMesh::ConstPtr mesh, std::string const& filename)
48{
49 if (util::string::right(filename, 4) == ".off")
50 save_off_mesh(mesh, filename);
51 else if (util::string::right(filename, 4) == ".ply")
52 save_ply_mesh(mesh, filename);
53 else if (util::string::right(filename, 5) == ".pbrt")
54 save_pbrt_mesh(mesh, filename);
55 else if (util::string::right(filename, 5) == ".npts")
56 save_npts_mesh(mesh, filename, false);
57 else if (util::string::right(filename, 6) == ".bnpts")
58 save_npts_mesh(mesh, filename, true);
59 else if (util::string::right(filename, 4) == ".smf")
60 save_smf_mesh(mesh, filename);
61 else if (util::string::right(filename, 4) == ".obj")
62 save_obj_mesh(mesh, filename);
63 else
64 throw std::runtime_error("Extension not recognized");
65}
66
std::shared_ptr< TriangleMesh const > ConstPtr
Definition mesh.h:93
#define MVE_NAMESPACE_BEGIN
Definition defines.h:13
#define MVE_NAMESPACE_END
Definition defines.h:14
#define MVE_GEOM_NAMESPACE_END
Definition defines.h:20
#define MVE_GEOM_NAMESPACE_BEGIN
Definition defines.h:19
TriangleMesh::Ptr load_npts_mesh(std::string const &filename, bool format_binary)
Simple importer for Kazhdan's .npts ASCII and binary files.
TriangleMesh::Ptr load_ply_mesh(std::string const &filename)
Loads a triangle mesh from a PLY model file.
void save_npts_mesh(TriangleMesh::ConstPtr mesh, std::string const &filename, bool format_binary)
Simple exporter for Kazhdan's .npts ASCII and binary files.
void save_obj_mesh(TriangleMesh::ConstPtr mesh, std::string const &filename)
Saves a triangle mesh to an OBJ model file.
TriangleMesh::Ptr load_off_mesh(std::string const &filename)
Loads a triangle mesh from an OFF model file.
void save_off_mesh(TriangleMesh::ConstPtr mesh, std::string const &filename)
Saves a triangle mesh to an OFF model file.
void save_smf_mesh(mve::TriangleMesh::ConstPtr mesh, std::string const &filename)
Saves a triangle mesh to a file in SMF file format.
TriangleMesh::Ptr load_mesh(std::string const &filename)
Auto-detects filetype from extension and delegates to readers.
Definition mesh_io.cc:26
mve::TriangleMesh::Ptr load_obj_mesh(std::string const &filename)
Loads a triangle mesh from an OBJ model file.
TriangleMesh::Ptr load_smf_mesh(std::string const &filename)
Loads a triangle mesh from a SMF file format.
void save_mesh(TriangleMesh::ConstPtr mesh, std::string const &filename)
Auto-detects filetype from extension and delegates to writers.
Definition mesh_io.cc:47
void save_ply_mesh(TriangleMesh::ConstPtr mesh, std::string const &filename, SavePLYOptions const &options)
Stores a PLY file from a triangle mesh.
void save_pbrt_mesh(TriangleMesh::ConstPtr mesh, std::string const &filename)
Saves a PBRT compatible mesh from a triangle mesh.
std::string right(std::string const &str, std::size_t chars)
Returns the rightmost 'chars' characters of 'str'.
Definition strings.h:452