Преглед на файлове

Merge branch 'master' of github.com:libigl/libigl into alecjacobson

Former-commit-id: 34a777b10bb0e0ff3627e04d607093a789e35124
Alec Jacobson преди 7 години
родител
ревизия
c62871c3c4

+ 9 - 0
include/igl/copyleft/cgal/remesh_intersections.cpp

@@ -148,6 +148,8 @@ IGL_INLINE void igl::copyleft::cgal::remesh_intersections(
     std::vector<Index> source_faces;
     std::vector<Point_3> new_vertices;
     EdgeMap edge_vertices;
+    // face_vertices: Given a face Index, find vertices inside the face
+    std::unordered_map<Index, std::vector<Index>> face_vertices;
 
     // Run constraint Delaunay triangulation on the plane.
     // 
@@ -252,8 +254,15 @@ IGL_INLINE void igl::copyleft::cgal::remesh_intersections(
         }
 
         // p must be in the middle of the triangle.
+        auto & existing_face_vertices = face_vertices[ori_f];
+        for(const auto vid : existing_face_vertices) {
+          if (p == new_vertices[vid - num_base_vertices]) {
+            return vid;
+          }
+        }
         const size_t index = num_base_vertices + new_vertices.size();
         new_vertices.push_back(p);
+        existing_face_vertices.push_back(index);
         return index;
       }
     };

+ 3 - 0
include/igl/delaunay_triangulation.cpp

@@ -81,3 +81,6 @@ IGL_INLINE void igl::delaunay_triangulation(
   }
 }
 
+#ifdef IGL_STATIC_LIBRARY
+template void igl::delaunay_triangulation<Eigen::Matrix<double, -1, -1, 0, -1, -1>, short (*)(double const*, double const*, double const*), short (*)(double const*, double const*, double const*, double const*), Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, short (*)(double const*, double const*, double const*), short (*)(double const*, double const*, double const*, double const*), Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
+#endif

+ 5 - 0
include/igl/flip_edge.cpp

@@ -146,3 +146,8 @@ IGL_INLINE void igl::flip_edge(
   sanity_check(ue_41);
 #endif
 }
+
+
+#ifdef IGL_STATIC_LIBRARY
+template void igl::flip_edge<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, 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> >&, Eigen::PlainObjectBase<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> >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&, unsigned long);
+#endif

+ 4 - 0
include/igl/lexicographic_triangulation.cpp

@@ -126,3 +126,7 @@ IGL_INLINE void igl::lexicographic_triangulation(
   }
 }
 
+
+#ifdef IGL_STATIC_LIBRARY
+template void igl::lexicographic_triangulation<Eigen::Matrix<double, -1, -1, 0, -1, -1>, short (*)(double const*, double const*, double const*), Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, short (*)(double const*, double const*, double const*), Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
+#endif

+ 3 - 2
include/igl/opengl/glfw/Viewer.cpp

@@ -286,9 +286,10 @@ namespace glfw
   IGL_INLINE Viewer::Viewer():
     data_list(1),
     selected_data_index(0),
-    next_data_id(0)
+    next_data_id(1)
   {
     window = nullptr;
+    data_list.front().id = 0;
 
     // Temporary variables initialization
     down = false;
@@ -934,7 +935,7 @@ namespace glfw
     return true;
   }
 
-  IGL_INLINE size_t Viewer::mesh_index(const int id) {
+  IGL_INLINE size_t Viewer::mesh_index(const int id) const {
     for (size_t i = 0; i < data_list.size(); ++i)
     {
       if (data_list[i].id == id)

+ 1 - 1
include/igl/opengl/glfw/Viewer.h

@@ -111,7 +111,7 @@ namespace glfw
 
     // Retrieve mesh index from its unique identifier
     // Returns 0 if not found
-    IGL_INLINE size_t mesh_index(const int id);
+    IGL_INLINE size_t mesh_index(const int id) const;
 
     // Alec: I call this data_list instead of just data to avoid confusion with
     // old "data" variable.

+ 1 - 1
include/igl/opengl/glfw/imgui/ImGuiMenu.cpp

@@ -221,7 +221,7 @@ IGL_INLINE void ImGuiMenu::draw_viewer_menu()
     ImGui::DragFloat("Zoom", &(viewer->core.camera_zoom), 0.05f, 0.1f, 20.0f);
 
     // Select rotation type
-    static int rotation_type = static_cast<int>(viewer->core.rotation_type);
+    int rotation_type = static_cast<int>(viewer->core.rotation_type);
     static Eigen::Quaternionf trackball_angle = Eigen::Quaternionf::Identity();
     static bool orthographic = true;
     if (ImGui::Combo("Camera Type", &rotation_type, "Trackball\0Two Axes\0002D Mode\0\0"))

+ 1 - 1
include/igl/ply.h.REMOVED.git-id

@@ -1 +1 @@
-75a3bab471417c278eec124122f42d7a6f8cfee2
+71f4860db5bab6831ffc0ceb38c42c4973c0fc1a

+ 31 - 0
include/igl/shape_diameter_function.cpp

@@ -7,7 +7,10 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "shape_diameter_function.h"
 #include "random_dir.h"
+#include "barycenter.h"
 #include "ray_mesh_intersect.h"
+#include "per_vertex_normals.h"
+#include "per_face_normals.h"
 #include "EPS.h"
 #include "Hit.h"
 #include "parallel_for.h"
@@ -141,11 +144,39 @@ IGL_INLINE void igl::shape_diameter_function(
   return shape_diameter_function(aabb,V,F,P,N,num_samples,S);
 }
 
+template <
+  typename DerivedV,
+  typename DerivedF,
+  typename DerivedS>
+IGL_INLINE void igl::shape_diameter_function(
+  const Eigen::PlainObjectBase<DerivedV> & V,
+  const Eigen::PlainObjectBase<DerivedF> & F,
+  const bool per_face,
+  const int num_samples,
+  Eigen::PlainObjectBase<DerivedS> & S)
+{
+  if (per_face)
+  {
+    DerivedV N;
+    igl::per_face_normals(V, F, N);
+    DerivedV P;
+    igl::barycenter(V, F, P);
+    return igl::shape_diameter_function(V, F, P, N, num_samples, S);
+  }
+  else
+  {
+    DerivedV N;
+    igl::per_vertex_normals(V, F, N);
+    return igl::shape_diameter_function(V, F, V, N, num_samples, S);
+  }
+}
+
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template instantiation
 template void igl::shape_diameter_function<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(std::function<double (Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 3, 1, 0, 3, 1> const&)> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
 template void igl::shape_diameter_function<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(std::function<double (Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 3, 1, 0, 3, 1> const&)> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
 template void igl::shape_diameter_function<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(std::function<double (Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 3, 1, 0, 3, 1> const&)> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
 template void igl::shape_diameter_function<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::function<double (Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 3, 1, 0, 3, 1> const&)> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+template void igl::shape_diameter_function<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, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, bool, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
 #endif
 

+ 4 - 2
include/igl/writeOFF.cpp

@@ -61,13 +61,15 @@ IGL_INLINE bool igl::writeOFF(
 
   //Check if RGB values are in the range [0..1] or [0..255]
   int rgbScale = (C.maxCoeff() <= 1.0)?255:1;
-  Eigen::MatrixXd RGB = rgbScale * C;
+  // Use RGB_Array instead of RGB because of clash with mingw macro 
+  // (https://github.com/libigl/libigl/pull/679)
+  Eigen::MatrixXd RGB_Array = rgbScale * C;
 
   s<< "COFF\n"<<V.rows()<<" "<<F.rows()<<" 0\n";
   for (unsigned i=0; i< V.rows(); i++)
   {
     s <<V.row(i).format(IOFormat(FullPrecision,DontAlignCols," "," ","","",""," "));
-    s << unsigned(RGB(i,0)) << " " << unsigned(RGB(i,1)) << " " << unsigned(RGB(i,2)) << " 255\n";
+    s << unsigned(RGB_Array(i,0)) << " " << unsigned(RGB_Array(i,1)) << " " << unsigned(RGB_Array(i,2)) << " 255\n";
   }
 
   s<<(F.array()).format(IOFormat(FullPrecision,DontAlignCols," ","\n","3 ","","","\n"));

+ 14 - 0
python/py_doc.cpp

@@ -1196,6 +1196,20 @@ const char *__doc_igl_setdiff = R"igl_Qu8mg5v7(// Set difference of elements of
   //   C  (k<=m)-long vector of unique elements appearing in A but not in B
   //   IA  (k<=m)-long list of indices into A so that C = A(IA)
   //)igl_Qu8mg5v7";
+const char *__doc_igl_shape_diameter_function = R"igl_Qu8mg5v7(// Compute shape diamater function per given point. In the parlence of the
+  // paper "Consistent Mesh Partitioning and Skeletonisation using the Shape
+  // Diameter Function" [Shapiro et al. 2008], this implementation uses a 180°
+  // cone and a _uniform_ average (_not_ a average weighted by inverse angles).
+  //
+  // Inputs:
+  //    shoot_ray  function handle that outputs hits of a given ray against a
+  //      mesh (embedded in function handles as captured variable/data)
+  //    P  #P by 3 list of origin points
+  //    N  #P by 3 list of origin normals
+  // Outputs:
+  //    S  #P list of shape diamater function values between bounding box
+  //    diagonal (perfect sphere) and 0 (perfect needle hook)
+  //)igl_Qu8mg5v7";
 const char *__doc_igl_signed_distance = R"igl_Qu8mg5v7(// Computes signed distance to a mesh
   //
   // Inputs:

+ 1 - 0
python/py_doc.h

@@ -101,6 +101,7 @@ extern const char *__doc_igl_remove_duplicate_vertices;
 extern const char *__doc_igl_rotate_vectors;
 extern const char *__doc_igl_seam_edges;
 extern const char *__doc_igl_setdiff;
+extern const char *__doc_igl_shape_diameter_function;
 extern const char *__doc_igl_signed_distance;
 extern const char *__doc_igl_signed_distance_pseudonormal;
 extern const char *__doc_igl_signed_distance_winding_number;

+ 4 - 0
python/py_igl.cpp

@@ -16,6 +16,7 @@
 #include <igl/SolverStatus.h>
 #include <igl/active_set.h>
 #include <igl/adjacency_list.h>
+#include <igl/adjacency_matrix.h>
 #include <igl/arap.h>
 #include <igl/avg_edge_length.h>
 #include <igl/barycenter.h>
@@ -86,6 +87,7 @@
 #include <igl/remove_duplicate_vertices.h>
 #include <igl/rotate_vectors.h>
 #include <igl/setdiff.h>
+#include <igl/shape_diameter_function.h>
 #include <igl/signed_distance.h>
 #include <igl/slice.h>
 #include <igl/slice_into.h>
@@ -113,6 +115,7 @@ void python_export_igl(py::module &m)
 #include "py_igl/py_SolverStatus.cpp"
 #include "py_igl/py_active_set.cpp"
 #include "py_igl/py_adjacency_list.cpp"
+#include "py_igl/py_adjacency_matrix.cpp"
 #include "py_igl/py_arap.cpp"
 #include "py_igl/py_avg_edge_length.cpp"
 #include "py_igl/py_barycenter.cpp"
@@ -183,6 +186,7 @@ void python_export_igl(py::module &m)
 #include "py_igl/py_remove_duplicate_vertices.cpp"
 #include "py_igl/py_rotate_vectors.cpp"
 #include "py_igl/py_setdiff.cpp"
+#include "py_igl/py_shape_diameter_function.cpp"
 #include "py_igl/py_signed_distance.cpp"
 #include "py_igl/py_slice.cpp"
 #include "py_igl/py_slice_into.cpp"

+ 10 - 0
python/py_igl/py_adjacency_matrix.cpp

@@ -0,0 +1,10 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2017 Sebastian Koch <s.koch@tu-berlin.de> and Daniele Panozzo <daniele.panozzo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+m.def("adjacency_matrix", [](const Eigen::MatrixXi & F, Eigen::SparseMatrix<int>& A) {
+    igl::adjacency_matrix(F, A);
+}, py::arg("F"), py::arg("A"));

+ 35 - 0
python/py_igl/py_shape_diameter_function.cpp

@@ -0,0 +1,35 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2017 Sebastian Koch <s.koch@tu-berlin.de> and Daniele Panozzo <daniele.panozzo@gmail.com>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+
+m.def("shape_diameter_function", []
+(
+  const Eigen::MatrixXd& V,
+  const Eigen::MatrixXi& F,
+  const Eigen::MatrixXd& P,
+  const Eigen::MatrixXd& N,
+  const int num_samples,
+  Eigen::MatrixXd& S
+)
+{
+  return igl::shape_diameter_function(V, F, P, N, num_samples, S);
+}, __doc_igl_shape_diameter_function,
+py::arg("V"), py::arg("F"), py::arg("P"), py::arg("N"), py::arg("num_samples"), py::arg("S"));
+
+m.def("shape_diameter_function", []
+(
+  const Eigen::MatrixXd& V,
+  const Eigen::MatrixXi& F,
+  const bool per_face,
+  const int num_samples,
+  Eigen::MatrixXd& S
+)
+{
+  return igl::shape_diameter_function(V, F, per_face, num_samples, S);
+}, __doc_igl_shape_diameter_function,
+py::arg("V"), py::arg("F"), py::arg("per_face"), py::arg("num_samples"), py::arg("S"));
+