Эх сурвалжийг харах

Merge branch 'master' of github.com:libigl/libigl into gh-pages

Former-commit-id: ac88971f05ccc6528d6825473013b88337819113
Alec Jacobson 9 жил өмнө
parent
commit
b99342c510

+ 1 - 0
include/igl/components.cpp

@@ -89,4 +89,5 @@ IGL_INLINE void igl::components(
 // Explicit template specialization
 template void igl::components<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 template void igl::components<int, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::SparseMatrix<int, 0, int> const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+template void igl::components<int, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::SparseMatrix<int, 0, int> const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 #endif

+ 11 - 1
include/igl/orientable_patches.cpp

@@ -84,12 +84,22 @@ IGL_INLINE void igl::orientable_patches(
   //% Connected components are patches
   //%C = components(A); % alternative to graphconncomp from matlab_bgl
   //[~,C] = graphconncomp(A);
-  // graph connected components using boost
+  // graph connected components 
   components(A,C);
 
 }
 
+template <typename DerivedF, typename DerivedC>
+IGL_INLINE void igl::orientable_patches(
+  const Eigen::PlainObjectBase<DerivedF> & F,
+  Eigen::PlainObjectBase<DerivedC> & C)
+{
+  Eigen::SparseMatrix<typename DerivedF::Scalar> A;
+  return orientable_patches(F,C,A);
+}
+
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
 template void igl::orientable_patches<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, int>(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::SparseMatrix<int, 0, int>&);
+template void igl::orientable_patches<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 #endif

+ 4 - 0
include/igl/orientable_patches.h

@@ -30,6 +30,10 @@ namespace igl
     const Eigen::PlainObjectBase<DerivedF> & F,
     Eigen::PlainObjectBase<DerivedC> & C,
     Eigen::SparseMatrix<AScalar> & A);
+  template <typename DerivedF, typename DerivedC>
+  IGL_INLINE void orientable_patches(
+    const Eigen::PlainObjectBase<DerivedF> & F,
+    Eigen::PlainObjectBase<DerivedC> & C);
 };
 #ifndef IGL_STATIC_LIBRARY
 #  include "orientable_patches.cpp"

+ 1 - 0
include/igl/randperm.cpp

@@ -31,5 +31,6 @@ IGL_INLINE void igl::randperm(
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
 template void igl::randperm<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+template void igl::randperm<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 //template Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > igl::randperm<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(int);
 #endif

+ 1 - 0
include/igl/slice.cpp

@@ -272,4 +272,5 @@ template void igl::slice<Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0,
 template void igl::slice<Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 template void igl::slice<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
 template void igl::slice<Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<float, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> >&);
+template Eigen::Matrix<int, -1, -1, 0, -1, -1> igl::slice<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&);
 #endif

+ 16 - 0
include/igl/snap_points.cpp

@@ -67,7 +67,23 @@ IGL_INLINE void igl::snap_points(
   }
 }
 
+template <
+  typename DerivedC, 
+  typename DerivedV, 
+  typename DerivedI>
+IGL_INLINE void igl::snap_points(
+  const Eigen::PlainObjectBase<DerivedC > & C,
+  const Eigen::PlainObjectBase<DerivedV > & V,
+  Eigen::PlainObjectBase<DerivedI > & I)
+{
+  Eigen::Matrix<typename DerivedC::Scalar,DerivedC::RowsAtCompileTime,1> minD;
+  return igl::snap_points(C,V,I,minD);
+}
+
+
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
 template void igl::snap_points<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
+template void igl::snap_points<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 #endif
+

+ 8 - 0
include/igl/snap_points.h

@@ -46,6 +46,14 @@ namespace igl
     const Eigen::PlainObjectBase<DerivedV > & V,
     Eigen::PlainObjectBase<DerivedI > & I,
     Eigen::PlainObjectBase<DerivedminD > & minD);
+  template <
+    typename DerivedC, 
+    typename DerivedV, 
+    typename DerivedI >
+  IGL_INLINE void snap_points(
+    const Eigen::PlainObjectBase<DerivedC > & C,
+    const Eigen::PlainObjectBase<DerivedV > & V,
+    Eigen::PlainObjectBase<DerivedI > & I);
 }
 
 #ifndef IGL_STATIC_LIBRARY

+ 28 - 11
include/igl/unproject.cpp

@@ -23,20 +23,35 @@ IGL_INLINE void igl::unproject(
   const Eigen::PlainObjectBase<Derivedviewport>&  viewport,
   Eigen::PlainObjectBase<Derivedscene> & scene)
 {
-  typedef typename Derivedscene::Scalar Scalar;
-  Eigen::Matrix<Scalar,4,4> Inverse = 
-    (proj.template cast<Scalar>() * model.template cast<Scalar>()).inverse();
+  if(win.cols() != 3)
+  {
+    assert(win.rows() == 3);
+    // needless transposes
+    Eigen::Matrix<typename Derivedscene::Scalar,1,3> sceneT;
+    unproject(win.transpose().eval(),model,proj,viewport,sceneT);
+    scene = sceneT.head(3);
+    return;
+  }
+  assert(win.cols() == 3);
+  const int n = win.rows();
+  scene.resize(n,3);
+  for(int i = 0;i<n;i++)
+  {
+    typedef typename Derivedscene::Scalar Scalar;
+    Eigen::Matrix<Scalar,4,4> Inverse = 
+      (proj.template cast<Scalar>() * model.template cast<Scalar>()).inverse();
 
-  Eigen::Matrix<Scalar,4,1> tmp;
-  tmp << win, 1;
-  tmp(0) = (tmp(0) - viewport(0)) / viewport(2);
-  tmp(1) = (tmp(1) - viewport(1)) / viewport(3);
-  tmp = tmp.array() * 2.0f - 1.0f;
+    Eigen::Matrix<Scalar,4,1> tmp;
+    tmp << win.row(i).head(3).transpose(), 1;
+    tmp(0) = (tmp(0) - viewport(0)) / viewport(2);
+    tmp(1) = (tmp(1) - viewport(1)) / viewport(3);
+    tmp = tmp.array() * 2.0f - 1.0f;
 
-  Eigen::Matrix<Scalar,4,1> obj = Inverse * tmp;
-  obj /= obj(3);
+    Eigen::Matrix<Scalar,4,1> obj = Inverse * tmp;
+    obj /= obj(3);
 
-  scene = obj.head(3);
+    scene.row(i).head(3) = obj.head(3);
+  }
 }
 
 template <typename Scalar>
@@ -54,4 +69,6 @@ IGL_INLINE Eigen::Matrix<Scalar,3,1> igl::unproject(
 #ifdef IGL_STATIC_LIBRARY
 template Eigen::Matrix<float, 3, 1, 0, 3, 1> igl::unproject<float>(Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&);
 template Eigen::Matrix<double, 3, 1, 0, 3, 1> igl::unproject<double>(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, Eigen::Matrix<double, 4, 4, 0, 4, 4> const&, Eigen::Matrix<double, 4, 4, 0, 4, 4> const&, Eigen::Matrix<double, 4, 1, 0, 4, 1> const&);
+template void igl::unproject<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+template void igl::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
 #endif

+ 2 - 3
include/igl/unproject.h

@@ -14,12 +14,12 @@ namespace igl
   // Eigen reimplementation of gluUnproject
   //
   // Inputs:
-  //   win  screen space x, y, and z coordinates
+  //   win  #P by 3 or 3-vector (#P=1) of screen space x, y, and z coordinates
   //   model  4x4 model-view matrix
   //   proj  4x4 projection matrix
   //   viewport  4-long viewport vector
   // Outputs:
-  //   scene  the unprojected x, y, and z coordinates
+  //   scene  #P by 3 or 3-vector (#P=1) the unprojected x, y, and z coordinates
   template <
     typename Derivedwin,
     typename Derivedmodel,
@@ -40,7 +40,6 @@ namespace igl
     const Eigen::Matrix<Scalar,4,1>&  viewport);
 }
 
-
 #ifndef IGL_STATIC_LIBRARY
 #  include "unproject.cpp"
 #endif

+ 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