-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
190 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2011-2022 the Polygon Mesh Processing Library developers. | ||
// Distributed under a MIT-style license, see LICENSE.txt for details. | ||
|
||
#include "pmp/io/read_pmp.h" | ||
|
||
#include "pmp/io/helpers.h" | ||
|
||
namespace pmp { | ||
|
||
void read_pmp(SurfaceMesh& mesh, const std::string& filename) | ||
{ | ||
// open file (in binary mode) | ||
FILE* in = fopen(filename.c_str(), "rb"); | ||
if (!in) | ||
throw IOException("Failed to open file: " + filename); | ||
|
||
// how many elements? | ||
unsigned int nv(0), ne(0), nh(0), nf(0); | ||
tfread(in, nv); | ||
tfread(in, ne); | ||
tfread(in, nf); | ||
nh = 2 * ne; | ||
|
||
// texture coordinates? | ||
bool has_htex(false); | ||
tfread(in, has_htex); | ||
|
||
// resize containers | ||
mesh.vprops_.resize(nv); | ||
mesh.hprops_.resize(nh); | ||
mesh.eprops_.resize(ne); | ||
mesh.fprops_.resize(nf); | ||
|
||
// get properties | ||
auto vconn = | ||
mesh.vertex_property<SurfaceMesh::VertexConnectivity>("v:connectivity"); | ||
auto hconn = mesh.halfedge_property<SurfaceMesh::HalfedgeConnectivity>( | ||
"h:connectivity"); | ||
auto fconn = | ||
mesh.face_property<SurfaceMesh::FaceConnectivity>("f:connectivity"); | ||
auto point = mesh.vertex_property<Point>("v:point"); | ||
|
||
// read properties from file | ||
size_t nvc = fread((char*)vconn.data(), | ||
sizeof(SurfaceMesh::VertexConnectivity), nv, in); | ||
size_t nhc = fread((char*)hconn.data(), | ||
sizeof(SurfaceMesh::HalfedgeConnectivity), nh, in); | ||
size_t nfc = fread((char*)fconn.data(), | ||
sizeof(SurfaceMesh::FaceConnectivity), nf, in); | ||
size_t np = fread((char*)point.data(), sizeof(Point), nv, in); | ||
PMP_ASSERT(nvc == nv); | ||
PMP_ASSERT(nhc == nh); | ||
PMP_ASSERT(nfc == nf); | ||
PMP_ASSERT(np == nv); | ||
|
||
// read texture coordiantes | ||
if (has_htex) | ||
{ | ||
auto htex = mesh.halfedge_property<TexCoord>("h:tex"); | ||
size_t nhtc = fread((char*)htex.data(), sizeof(TexCoord), nh, in); | ||
PMP_ASSERT(nhtc == nh); | ||
} | ||
|
||
fclose(in); | ||
} | ||
|
||
} // namespace pmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2011-2022 the Polygon Mesh Processing Library developers. | ||
// Distributed under a MIT-style license, see LICENSE.txt for details. | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "pmp/SurfaceMesh.h" | ||
|
||
namespace pmp { | ||
|
||
void read_pmp(SurfaceMesh& mesh, const std::string& filename); | ||
|
||
} // namespace pmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2011-2022 the Polygon Mesh Processing Library developers. | ||
// Distributed under a MIT-style license, see LICENSE.txt for details. | ||
|
||
#include "pmp/io/write_pmp.h" | ||
#include "pmp/Types.h" | ||
#include "pmp/io/helpers.h" | ||
|
||
namespace pmp { | ||
|
||
void write_pmp(const SurfaceMesh& mesh, const std::string& filename, | ||
const IOFlags&) | ||
{ | ||
// open file (in binary mode) | ||
FILE* out = fopen(filename.c_str(), "wb"); | ||
if (!out) | ||
throw IOException("Failed to open file: " + filename); | ||
|
||
// get properties | ||
auto vconn = mesh.get_vertex_property<SurfaceMesh::VertexConnectivity>( | ||
"v:connectivity"); | ||
auto hconn = mesh.get_halfedge_property<SurfaceMesh::HalfedgeConnectivity>( | ||
"h:connectivity"); | ||
auto fconn = | ||
mesh.get_face_property<SurfaceMesh::FaceConnectivity>("f:connectivity"); | ||
auto point = mesh.get_vertex_property<Point>("v:point"); | ||
auto htex = mesh.get_halfedge_property<TexCoord>("h:tex"); | ||
|
||
// how many elements? | ||
unsigned int nv, ne, nh, nf; | ||
nv = mesh.n_vertices(); | ||
ne = mesh.n_edges(); | ||
nh = mesh.n_halfedges(); | ||
nf = mesh.n_faces(); | ||
|
||
// write header | ||
tfwrite(out, nv); | ||
tfwrite(out, ne); | ||
tfwrite(out, nf); | ||
tfwrite(out, (bool)htex); | ||
|
||
// write properties to file | ||
fwrite((char*)vconn.data(), sizeof(SurfaceMesh::VertexConnectivity), nv, | ||
out); | ||
fwrite((char*)hconn.data(), sizeof(SurfaceMesh::HalfedgeConnectivity), nh, | ||
out); | ||
fwrite((char*)fconn.data(), sizeof(SurfaceMesh::FaceConnectivity), nf, out); | ||
fwrite((char*)point.data(), sizeof(Point), nv, out); | ||
|
||
// texture coordinates | ||
if (htex) | ||
fwrite((char*)htex.data(), sizeof(TexCoord), nh, out); | ||
|
||
fclose(out); | ||
} | ||
|
||
} // namespace pmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2011-2022 the Polygon Mesh Processing Library developers. | ||
// Distributed under a MIT-style license, see LICENSE.txt for details. | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "pmp/SurfaceMesh.h" | ||
#include "pmp/Types.h" | ||
|
||
namespace pmp { | ||
|
||
void write_pmp(SurfaceMesh& mesh, const std::string& filename, | ||
const IOFlags& flags); | ||
|
||
} // namespace pmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters