Browse Source

Merge branch 'master' of https://github.com/libigl/libigl

Alec Jacobson 5 years ago
parent
commit
782b7fc95d

+ 1 - 1
cmake/LibiglDownloadExternal.cmake

@@ -193,6 +193,6 @@ function(igl_download_tutorial_data)
 	igl_download_project_aux(tutorial_data
 	igl_download_project_aux(tutorial_data
 		"${LIBIGL_EXTERNAL}/../tutorial/data"
 		"${LIBIGL_EXTERNAL}/../tutorial/data"
 		GIT_REPOSITORY https://github.com/libigl/libigl-tutorial-data
 		GIT_REPOSITORY https://github.com/libigl/libigl-tutorial-data
-		GIT_TAG        37d4e836054c9c2d2125a817c489ed8e07cd56fc
+		GIT_TAG        1f8fab844173890f1e326d93c9ca6c50dad1c6b2
 	)
 	)
 endfunction()
 endfunction()

+ 33 - 6
include/igl/read_triangle_mesh.cpp

@@ -8,6 +8,7 @@
 #include "read_triangle_mesh.h"
 #include "read_triangle_mesh.h"
 
 
 #include "list_to_matrix.h"
 #include "list_to_matrix.h"
+#include "readMSH.h"
 #include "readMESH.h"
 #include "readMESH.h"
 #include "readOBJ.h"
 #include "readOBJ.h"
 #include "readOFF.h"
 #include "readOFF.h"
@@ -84,14 +85,38 @@ IGL_INLINE bool igl::read_triangle_mesh(
   pathinfo(filename,dir,base,ext,name);
   pathinfo(filename,dir,base,ext,name);
   // Convert extension to lower case
   // Convert extension to lower case
   transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
   transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
-  FILE * fp = fopen(filename.c_str(),"rb");
-  if(NULL==fp)
+  // readMSH requires filename
+  if(ext == "msh")
   {
   {
-    fprintf(stderr,"IOError: %s could not be opened...\n",
-            filename.c_str());
-    return false;
+    // readMSH is not properly templated
+    Eigen::MatrixXd mV;
+    Eigen::MatrixXi mF,T;
+    Eigen::VectorXi _1,_2;
+    // *TetWild doesn't use Tri field...
+    //bool res = readMSH(filename,mV,mF);
+    bool res = readMSH(filename,mV,mF,T,_1,_2);
+    V = mV.template cast<typename DerivedV::Scalar>();
+    if(mF.rows() == 0 && T.rows() > 0)
+    {
+      boundary_facets(T,F);
+      // outward facing
+      F = F.rowwise().reverse().eval();
+    }else
+    {
+      F = mF.template cast<typename DerivedF::Scalar>();
+    }
+    return res;
+  }else
+    {
+    FILE * fp = fopen(filename.c_str(),"rb");
+    if(NULL==fp)
+    {
+      fprintf(stderr,"IOError: %s could not be opened...\n",
+              filename.c_str());
+      return false;
+    }
+    return read_triangle_mesh(ext,fp,V,F);
   }
   }
-  return read_triangle_mesh(ext,fp,V,F);
 }
 }
 
 
 template <typename DerivedV, typename DerivedF>
 template <typename DerivedV, typename DerivedF>
@@ -119,6 +144,8 @@ IGL_INLINE bool igl::read_triangle_mesh(
     //if(F.size() > T.size() || F.size() == 0)
     //if(F.size() > T.size() || F.size() == 0)
     {
     {
       boundary_facets(T,F);
       boundary_facets(T,F);
+      // outward facing
+      F = F.rowwise().reverse().eval();
     }
     }
   }else if(ext == "obj")
   }else if(ext == "obj")
   {
   {

+ 5 - 0
tutorial/111_MatCap/CMakeLists.txt

@@ -0,0 +1,5 @@
+get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+project(${PROJECT_NAME})
+
+add_executable(${PROJECT_NAME} main.cpp)
+target_link_libraries(${PROJECT_NAME} igl::core igl::opengl igl::opengl_glfw igl::png tutorials)

+ 19 - 0
tutorial/111_MatCap/main.cpp

@@ -0,0 +1,19 @@
+#include <igl/opengl/glfw/Viewer.h>
+#include <igl/read_triangle_mesh.h>
+#include <igl/png/readPNG.h>
+
+int main(int argc, char *argv[])
+{
+  igl::opengl::glfw::Viewer v;
+  Eigen::MatrixXd V;
+  Eigen::MatrixXi F;
+  igl::read_triangle_mesh(
+    argc>1?argv[1]: TUTORIAL_SHARED_PATH "/armadillo.obj",V,F);
+  Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic> R,G,B,A;
+  igl::png::readPNG(argc>2?argv[2]: TUTORIAL_SHARED_PATH "/jade.png",R,G,B,A);
+  v.data().set_mesh(V,F);
+  v.data().set_texture(R,G,B,A);
+  v.data().use_matcap = true;
+  v.data().show_lines = false;
+  v.launch();
+}

+ 1 - 0
tutorial/CMakeLists.txt

@@ -131,6 +131,7 @@ if(TUTORIALS_CHAPTER6)
     add_subdirectory("606_AmbientOcclusion")
     add_subdirectory("606_AmbientOcclusion")
   endif()
   endif()
   if(LIBIGL_WITH_PNG)
   if(LIBIGL_WITH_PNG)
+    add_subdirectory("111_MatCap")
     add_subdirectory("607_ScreenCapture")
     add_subdirectory("607_ScreenCapture")
   endif()
   endif()
   if(LIBIGL_WITH_CGAL)
   if(LIBIGL_WITH_CGAL)