Skip to content

Commit

Permalink
fix meshio bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
fwilliams committed Dec 5, 2018
1 parent 97903ea commit 05a702e
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 3 deletions.
2 changes: 1 addition & 1 deletion external/igl/writeOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ IGL_INLINE bool igl::writeOFF(
int rgbScale = (C.maxCoeff() <= 1.0)?255:1;
// Use RGB_Array instead of RGB because of clash with mingw macro
// (https://github.com/libigl/libigl/pull/679)
Eigen::MatrixXd RGB_Array = rgbScale * C;
Eigen::Matrix<typename DerivedC::Scalar, Eigen::Dynamic, Eigen::Dynamic> RGB_Array = rgbScale * C;

s<< "COFF\n"<<V.rows()<<" "<<F.rows()<<" 0\n";
for (unsigned i=0; i< V.rows(); i++)
Expand Down
103 changes: 101 additions & 2 deletions src/meshio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <igl/readPLY.h>
#include <igl/readOFF.h>
#include <igl/writeOBJ.h>
//#include <igl/writePLY.h>
#include <igl/writeOFF.h>

#include <npe.h>
#include <npe_typedefs.h>
Expand Down Expand Up @@ -240,7 +242,7 @@ npe_begin_code()
bool ret = igl::readPLY(filename, v, f, n, uv);
if (!ret) {
throw std::invalid_argument("Failed to read file '" + filename + "'");
throw std::runtime_error("Failed to read file '" + filename + "'");
}
return std::make_tuple(npe::move(v), npe::move(f), npe::move(n), npe::move(uv));
Expand All @@ -250,7 +252,7 @@ npe_begin_code()
bool ret = igl::readPLY(filename, v, f, n, uv);
if (!ret) {
throw std::invalid_argument("Failed to read file '" + filename + "'");
throw std::runtime_error("Failed to read file '" + filename + "'");
}
return std::make_tuple(npe::move(v), npe::move(f), npe::move(n), npe::move(uv));
Expand All @@ -259,3 +261,100 @@ npe_begin_code()
}
npe_end_code()
// FIXME: Compile errors that I'm too lazy to deal with right now
//const char* ds_write_ply = R"igl_Qu8mg5v7(
//Write a mesh to a .ply file.

//Parameters
//----------
//filename : string, path to .off file
//v : #v by 3 list of vertex positions
//f : #f by 3 list of vertex positions
//n : #v by 3 list of vertex normals (or empty for no normals)
//uv : #v by 2 list of vertex texture coordinates (or empty for no texture coordinates)
//ascii: if True, write an ascii instead of a binary PLY file (False by default)

//Returns
//-------
//None

//See also
//--------
//write_obj, write_off

//Notes
//-----
//None

//Examples
//--------
//>>> write_ply("my_model.ply", v, f, n, uv)
//)igl_Qu8mg5v7";
//npe_function(write_ply)
//npe_doc(ds_write_ply)
//npe_arg(filename, std::string)
//npe_arg(v, dense_f32, dense_f64)
//npe_arg(f, dense_i32, dense_i64)
//npe_arg(n, npe_matches(v))
//npe_arg(uv, npe_matches(v))
//npe_default_arg(ascii, bool, false)
//npe_begin_code()

// if (!igl::writePLY(filename, v, f, n, uv, ascii)) {
// throw std::runtime_error("Failed to write PLY file '" + filename + "'");
// }

//npe_end_code()




const char* ds_write_off = R"igl_Qu8mg5v7(
Write a mesh to a .off file.
Parameters
----------
filename : string, path to .off file
v : #v by 3 list of vertex positions
f : #f by 3 list of vertex positions
c : #v list of vertex colors (or empty for no normals)
Returns
-------
None
See also
--------
write_obj, write_ply
Notes
-----
None
Examples
--------
>>> write_off("my_model.off", v, f, c)
)igl_Qu8mg5v7";
npe_function(write_off)
npe_doc(ds_write_off)
npe_arg(filename, std::string)
npe_arg(v, dense_f32, dense_f64)
npe_arg(f, dense_i32, dense_i64)
npe_arg(c, dense_f32, dense_f64)
npe_begin_code()

bool ret;
if (c.rows() == 0 && c.cols() == 0) {
ret = igl::writeOFF(filename, v, f);
} else {
ret = igl::writeOFF(filename, v, f, c);
}

if (!ret) {
throw std::runtime_error("Failed to write OFF file '" + filename + "'");
}

npe_end_code()

0 comments on commit 05a702e

Please sign in to comment.