-
-
Save Erkaman/b1d0c82ab53e81f3c322d3a1cdf4c862 to your computer and use it in GitHub Desktop.
Command line program to view 3D meshes from files, standard input and pipes
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
#include <igl/guess_extension.h> | |
#include <igl/read_triangle_mesh.h> | |
#include <igl/viewer/Viewer.h> | |
#include <Eigen/Core> | |
#include <iostream> | |
#include <string> | |
#include <cstdio> | |
#include <unistd.h> | |
int main(int argc, char * argv[]) | |
{ | |
Eigen::MatrixXd V; | |
Eigen::MatrixXi F; | |
if(argc >= 2) | |
{ | |
igl::read_triangle_mesh(argv[1],V,F); | |
}else if(isatty(fileno(stdin))) | |
{ | |
std::cerr<<R"(Usage: | |
./viewmesh input.obj | |
./viewmesh < input.obj | |
cat input.obj | ./viewmesh | |
)"; | |
return EXIT_FAILURE; | |
}else{ | |
FILE * fp = tmpfile(); | |
while(std::cin.good()) | |
{ | |
std::vector<char> buf(1024); | |
std::cin.read(&buf[0],buf.size()); | |
fwrite(&buf[0],sizeof(char),std::cin.gcount(),fp); | |
} | |
fp = freopen(NULL,"r",fp); | |
std::string ext = igl::guess_extension(fp); | |
std::cout<<"[treating stdin as ."<<ext<<" file]"<<std::endl; | |
igl::read_triangle_mesh(ext,fp,V,F); | |
} | |
igl::viewer::Viewer v; | |
v.data.set_mesh(V,F); | |
v.launch(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment