Skip to content

Instantly share code, notes, and snippets.

@alecjacobson
Last active January 11, 2019 07:40
Show Gist options
  • Save alecjacobson/b17f309f083a534a558477c065ea3fd7 to your computer and use it in GitHub Desktop.
Save alecjacobson/b17f309f083a534a558477c065ea3fd7 to your computer and use it in GitHub Desktop.

Revisions

  1. alecjacobson revised this gist Dec 15, 2016. No changes.
  2. alecjacobson created this gist Dec 15, 2016.
    44 changes: 44 additions & 0 deletions viewmesh.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #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;
    }