From 05a702e13f59821abed7ce05b238f85e59a98026 Mon Sep 17 00:00:00 2001 From: Francis Williams Date: Wed, 5 Dec 2018 18:33:55 -0500 Subject: [PATCH] fix meshio bugs --- external/igl/writeOFF.cpp | 2 +- src/meshio.cpp | 103 +++++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 3 deletions(-) diff --git a/external/igl/writeOFF.cpp b/external/igl/writeOFF.cpp index e2bfc8d0..2afd5ac4 100644 --- a/external/igl/writeOFF.cpp +++ b/external/igl/writeOFF.cpp @@ -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 RGB_Array = rgbScale * C; s<< "COFF\n"< #include #include +//#include +#include #include #include @@ -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)); @@ -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)); @@ -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()