فهرست منبع

facet orientation in tutorial

Former-commit-id: dc0e8356004b20ead55dfd69caddc766dcb2636a
Alec Jacobson 9 سال پیش
والد
کامیت
af1ec1491e

+ 8 - 0
tutorial/706_FacetOrientation/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(706_FacetOrientation)
+
+add_executable(${PROJECT_NAME}_bin
+  main.cpp)
+target_include_directories(${PROJECT_NAME}_bin PRIVATE ${LIBIGL_INCLUDE_DIRS})
+target_compile_definitions(${PROJECT_NAME}_bin PRIVATE ${LIBIGL_DEFINITIONS})
+target_link_libraries(${PROJECT_NAME}_bin ${LIBIGL_LIBRARIES} ${LIBIGL_EXTRA_LIBRARIES})

+ 108 - 0
tutorial/706_FacetOrientation/main.cpp

@@ -0,0 +1,108 @@
+
+#include <igl/read_triangle_mesh.h>
+#include <igl/embree/reorient_facets_raycast.h>
+#include <igl/randperm.h>
+#include <igl/orientable_patches.h>
+#include <igl/slice.h>
+#include <igl/hsv_to_rgb.h>
+#include <igl/viewer/Viewer.h>
+#include <fstream>
+#include <iostream>
+#include <string>
+igl::viewer::Viewer viewer;
+Eigen::MatrixXd V;
+std::vector<Eigen::VectorXi> C(2);
+std::vector<Eigen::MatrixXd> RGB(2);
+Eigen::MatrixXi F;
+std::vector<Eigen::MatrixXi> FF(2);
+bool is_showing_reoriented = false;
+bool facetwise = false;
+
+int main(int argc, char * argv[])
+{
+  using namespace std;
+  cout<<R"(
+Usage:
+
+[space]  Toggle between original and reoriented faces
+F,f      Toggle between patchwise and facetwise reorientation
+S,s      Scramble colors
+)";
+  igl::read_triangle_mesh(TUTORIAL_SHARED_PATH "/truck.obj",V,F);
+
+  const auto & scramble_colors = []()
+  {
+    for(int pass = 0;pass<2;pass++)
+    {
+      Eigen::MatrixXi R;
+      igl::randperm(C[pass].maxCoeff()+1,R);
+      C[pass] = igl::slice(R,Eigen::MatrixXi(C[pass]));
+      Eigen::MatrixXd HSV(C[pass].rows(),3);
+      HSV.col(0) = 
+        360.*C[pass].array().cast<double>()/(double)C[pass].maxCoeff();
+      HSV.rightCols(2).setConstant(1.0);
+      igl::hsv_to_rgb(HSV,RGB[pass]);
+    }
+    viewer.data.set_colors(RGB[facetwise]);
+  };
+
+  viewer.callback_key_pressed = 
+    [&scramble_colors]
+    (igl::viewer::Viewer& /*viewer*/, unsigned int key, int mod)->bool
+  {
+    switch(key)
+    {
+    default:
+      return false;
+    case 'F':
+    case 'f':
+    {
+      facetwise = !facetwise;
+      break;
+    }
+    case 'S':
+    case 's':
+    {
+      scramble_colors();
+      return true;
+    }
+    case ' ':
+    {
+      is_showing_reoriented = !is_showing_reoriented;
+      break;
+    }
+    }
+    viewer.data.clear();
+    viewer.data.set_mesh(V,is_showing_reoriented?FF[facetwise]:F);
+    viewer.data.set_colors(RGB[facetwise]);
+    return true;
+  };
+
+
+  // Compute patches
+  for(int pass = 0;pass<2;pass++)
+  {
+    Eigen::VectorXi I;
+    igl::embree::reorient_facets_raycast(
+      V,F,F.rows()*100,10,pass==1,false,false,I,C[pass]);
+    // apply reorientation
+    FF[pass].conservativeResize(F.rows(),F.cols());
+    for(int i = 0;i<I.rows();i++)
+    {
+      if(I(i))
+      {
+        FF[pass].row(i) = (F.row(i).reverse()).eval();
+      }else
+      {
+        FF[pass].row(i) = F.row(i);
+      }
+    }
+  }
+
+  viewer.data.set_mesh(V,is_showing_reoriented?FF[facetwise]:F);
+  viewer.data.set_face_based(true);
+  scramble_colors();
+  viewer.launch();
+}
+
+

+ 1 - 0
tutorial/CMakeLists.txt

@@ -156,6 +156,7 @@ if(TUTORIALS_CHAPTER6)
   if(LIBIGL_WITH_EMBREE)
     add_subdirectory("606_AmbientOcclusion")
     add_subdirectory("607_Picking")
+    add_subdirectory("706_FacetOrientation")
   endif()
   if(LIBIGL_WITH_LIM)
     add_subdirectory("608_LIM")

+ 1 - 0
tutorial/images/truck-facet-orientation.jpg.REMOVED.git-id

@@ -0,0 +1 @@
+b4a33aa46729b26b35d38f6db4cc66f7ea6f7471

+ 1 - 0
tutorial/shared/truck.obj.REMOVED.git-id

@@ -0,0 +1 @@
+c2542e6e6840e1f1c9e15647cc348d276e91e179

+ 1 - 1
tutorial/tutorial.html.REMOVED.git-id

@@ -1 +1 @@
-2407e0ecd2246291f6abd39b420535e7de4112f6
+a12cccc343996a275b1d3f63fb75f453ecfd0d0e

+ 1 - 1
tutorial/tutorial.md.REMOVED.git-id

@@ -1 +1 @@
-f600032cf5553688f2e8ad31dcc300bc9c303a65
+da82267bdbc575f509d20358a28db1ee4af39fab