Browse Source

point to mesh distances in cgal

Former-commit-id: 8e83dfaa1f376c72815d4702beafaedab295fc47
Alec Jacobson 11 years ago
parent
commit
23a51e62f6

+ 3 - 0
documentation/implemented-papers.tex

@@ -40,6 +40,9 @@ choosing skinning transformations \cite{Jacobson:FAST:2012}.
 ``skeletal subspace deformation'', or ``enveloping''. This technique is often
 attributed to \cite{Magnenat-Thalmann:1988:JLD}.
 
+\paragraph{\texttt{winding\_number}} implements ``Generalized Winding Numbers''
+\cite{Jacobson:WN:2013}
+
 \bibliographystyle{acmsiggraph}
 \bibliography{references} 
 

+ 1 - 1
documentation/references.bib.REMOVED.git-id

@@ -1 +1 @@
-92b6b20756fd71dd62d7b52066a7bcf07e4acd28
+346cd2c8206ee2c83e7aef50adb832e483320d09

+ 4 - 0
include/igl/cgal/intersect_other.cpp

@@ -128,3 +128,7 @@ IGL_INLINE void igl::intersect_other(
   }
 
 }
+
+#ifndef IGL_HEADER_ONLY
+// Explicit template specialization
+#endif

+ 3 - 0
include/igl/cgal/mesh_to_cgal_triangle_list.h

@@ -14,6 +14,9 @@ namespace igl
 {
   // Convert a mesh (V,F) to a list of CGAL triangles
   //
+  // Templates:
+  //   Kernal  CGAL computation and construction kernel (e.g.
+  //     CGAL::Exact_predicates_exact_constructions_kernel)
   // Inputs:
   //   V  #V by 3 list of vertex positions
   //   F  #F by 3 list of triangle indices

+ 63 - 0
include/igl/cgal/point_mesh_squared_distance.cpp

@@ -0,0 +1,63 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2014 Alec Jacobson <alecjacobson@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/.
+#include "point_mesh_squared_distance.h"
+#include "mesh_to_cgal_triangle_list.h"
+
+template <typename Kernel>
+IGL_INLINE void igl::point_mesh_squared_distance(
+  const Eigen::MatrixXd & P,
+  const Eigen::MatrixXd & V,
+  const Eigen::MatrixXi & F,
+  Eigen::VectorXd & sqrD,
+  Eigen::VectorXi & I,
+  Eigen::MatrixXd & C)
+{
+  using namespace std;
+  typedef CGAL::Point_3<Kernel>    Point_3;
+  typedef CGAL::Triangle_3<Kernel> Triangle_3; 
+  typedef typename std::vector<Triangle_3>::iterator Iterator;
+  typedef CGAL::AABB_triangle_primitive<Kernel, Iterator> Primitive;
+  typedef CGAL::AABB_traits<Kernel, Primitive> AABB_triangle_traits;
+  typedef CGAL::AABB_tree<AABB_triangle_traits> Tree;
+  typedef typename Tree::Point_and_primitive_id Point_and_primitive_id;
+
+  // Must be 3D
+  assert(V.cols() == 3);
+  assert(P.cols() == 3);
+  // Must be triangles
+  assert(F.cols() == 3);
+  // Make list of cgal triangles
+  Tree tree;
+  vector<Triangle_3> T;
+  mesh_to_cgal_triangle_list(V,F,T);
+  tree.insert(T.begin(),T.end());
+
+  tree.accelerate_distance_queries();
+  const int n = P.rows();
+  sqrD.resize(n,1);
+  I.resize(n,1);
+  C.resize(n,P.cols());
+  for(int p = 0;p < n;p++)
+  {
+    Point_3 query(P(p,0),P(p,1),P(p,2));
+    // Find closest point and primitive id
+    Point_and_primitive_id pp = tree.closest_point_and_primitive(query);
+    Point_3 closest_point = pp.first;
+    C(p,0) = CGAL::to_double(closest_point[0]);
+    C(p,1) = CGAL::to_double(closest_point[1]);
+    C(p,2) = CGAL::to_double(closest_point[2]);
+    sqrD(p) = CGAL::to_double((closest_point-query).squared_length());
+    I(p) = pp.second - T.begin();
+  }
+}
+
+#ifndef IGL_HEADER_ONLY
+// Explicit template specialization
+template void igl::point_mesh_squared_distance<CGAL::Epeck>( const Eigen::MatrixXd & P, const Eigen::MatrixXd & V, const Eigen::MatrixXi & F, Eigen::VectorXd & sqrD, Eigen::VectorXi & I, Eigen::MatrixXd & C);
+
+#endif

+ 44 - 0
include/igl/cgal/point_mesh_squared_distance.h

@@ -0,0 +1,44 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2014 Alec Jacobson <alecjacobson@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/.
+#ifndef IGL_POINT_MESH_SQUARED_DISTANCE_H
+#define IGL_POINT_MESH_SQUARED_DISTANCE_H
+#include <igl/igl_inline.h>
+#include <Eigen/Core>
+#include "CGAL_includes.hpp"
+namespace igl
+{
+  // Convert a mesh (V,F) to a list of CGAL triangles
+  //
+  // Templates:
+  //   Kernal  CGAL computation and construction kernel (e.g.
+  //     CGAL::Simple_cartesian<double>)
+  // Inputs:
+  //   P  #P by 3 list of query point positions
+  //   V  #V by 3 list of vertex positions
+  //   F  #F by 3 list of triangle indices
+  // Outputs:
+  //   sqrD  #P list of smallest squared distances
+  //   I  #P list of facet indices corresponding to smallest distances
+  //   C  #P by 3 list of closest points
+  //
+  // Known bugs: This only computes distances to triangles. So unreferenced
+  // vertices are ignored.
+  template <typename Kernel>
+  IGL_INLINE void point_mesh_squared_distance(
+    const Eigen::MatrixXd & P,
+    const Eigen::MatrixXd & V,
+    const Eigen::MatrixXi & F,
+    Eigen::VectorXd & sqrD,
+    Eigen::VectorXi & I,
+    Eigen::MatrixXd & C);
+}
+#ifdef IGL_HEADER_ONLY
+#  include "point_mesh_squared_distance.cpp"
+#endif
+
+#endif