Bladeren bron

snap points and templates

Former-commit-id: 3a555962199cc1652c28fffe3fb5900a42f7f1b7
Alec Jacobson (jalec 11 jaren geleden
bovenliggende
commit
801315915a

+ 1 - 0
include/igl/embree/unproject_in_mesh.cpp

@@ -67,4 +67,5 @@ int igl::unproject_in_mesh(
 
 #ifndef IGL_HEADER_ONLY
 template int igl::unproject_in_mesh<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(int, int, igl::EmbreeIntersector const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&, std::vector<igl::Hit, std::allocator<igl::Hit> >&);
+template int igl::unproject_in_mesh<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(int, int, igl::EmbreeIntersector const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
 #endif

+ 2 - 0
include/igl/histc.cpp

@@ -96,4 +96,6 @@ IGL_INLINE void igl::histc(
 template void igl::histc<Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -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<double, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
 template void igl::histc<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::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> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 template void igl::histc<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::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> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+template void igl::histc<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> >&);
+template void igl::histc<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

+ 73 - 0
include/igl/snap_points.cpp

@@ -0,0 +1,73 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2013 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 "snap_points.h"
+#include <cassert>
+#include <limits>
+
+template <
+  typename DerivedC, 
+  typename DerivedV, 
+  typename DerivedI, 
+  typename DerivedminD, 
+  typename DerivedVI>
+IGL_INLINE void igl::snap_points(
+  const Eigen::PlainObjectBase<DerivedC > & C,
+  const Eigen::PlainObjectBase<DerivedV > & V,
+  Eigen::PlainObjectBase<DerivedI > & I,
+  Eigen::PlainObjectBase<DerivedminD > & minD,
+  Eigen::PlainObjectBase<DerivedVI > & VI)
+{
+  snap_points(C,V,I,minD);
+  const int m = C.rows();
+  VI.resize(m,V.cols());
+  for(int c = 0;c<m;c++)
+  {
+    VI.row(c) = V.row(I(c));
+  }
+}
+
+template <
+  typename DerivedC, 
+  typename DerivedV, 
+  typename DerivedI, 
+  typename DerivedminD>
+IGL_INLINE void igl::snap_points(
+  const Eigen::PlainObjectBase<DerivedC > & C,
+  const Eigen::PlainObjectBase<DerivedV > & V,
+  Eigen::PlainObjectBase<DerivedI > & I,
+  Eigen::PlainObjectBase<DerivedminD > & minD)
+{
+  using namespace std;
+  const int n = V.rows();
+  const int m = C.rows();
+  assert(V.cols() == C.cols() && "Dimensions should match");
+  // O(m*n)
+  //
+  // I believe there should be a way to do this in O(m*log(n) + n) assuming
+  // reasonably distubed points.
+  I.resize(m,1);
+  typedef typename DerivedV::Scalar Scalar;
+  minD.setConstant(m,1,numeric_limits<Scalar>::max());
+  for(int v = 0;v<n;v++)
+  {
+    for(int c = 0;c<m;c++)
+    {
+      const Scalar d = (C.row(c) - V.row(v)).squaredNorm();
+      if(d < minD(c))
+      {
+        minD(c,0) = d;
+        I(c,0) = v;
+      }
+    }
+  }
+}
+
+#ifndef IGL_HEADER_ONLY
+// 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> >&);
+#endif

+ 59 - 0
include/igl/snap_points.h

@@ -0,0 +1,59 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2013 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_SNAP_POINTS_H
+#define IGL_SNAP_POINTS_H
+
+#include "igl_inline.h"
+#include <Eigen/Core>
+
+namespace igl
+{
+  // SNAP_POINTS snap list of points C to closest of another list of points V
+  //
+  // [I,minD,VI] = snap_points(C,V)
+  // 
+  // Inputs:
+  //   C  #C by dim list of query point positions
+  //   V  #V by dim list of data point positions
+  // Outputs:
+  //   I  #C list of indices into V of closest points to C
+  //   minD  #C list of squared (^p) distances to closest points
+  //   VI  #C by dim list of new point positions, VI = V(I,:)
+  template <
+    typename DerivedC, 
+    typename DerivedV, 
+    typename DerivedI, 
+    typename DerivedminD, 
+    typename DerivedVI>
+  IGL_INLINE void snap_points(
+    const Eigen::PlainObjectBase<DerivedC > & C,
+    const Eigen::PlainObjectBase<DerivedV > & V,
+    Eigen::PlainObjectBase<DerivedI > & I,
+    Eigen::PlainObjectBase<DerivedminD > & minD,
+    Eigen::PlainObjectBase<DerivedVI > & VI);
+  template <
+    typename DerivedC, 
+    typename DerivedV, 
+    typename DerivedI, 
+    typename DerivedminD>
+  IGL_INLINE void snap_points(
+    const Eigen::PlainObjectBase<DerivedC > & C,
+    const Eigen::PlainObjectBase<DerivedV > & V,
+    Eigen::PlainObjectBase<DerivedI > & I,
+    Eigen::PlainObjectBase<DerivedminD > & minD);
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "snap_points.cpp"
+#endif
+
+#endif
+
+
+
+

+ 2 - 0
include/igl/unproject_to_zero_plane.cpp

@@ -39,6 +39,8 @@ IGL_INLINE int igl::unproject_to_zero_plane(
 #ifndef IGL_HEADER_ONLY
 // Explicit template instanciation
 template int igl::unproject_to_zero_plane<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
+template int igl::unproject_to_zero_plane<Eigen::Matrix<double, 2, 1, 0, 2, 1>, Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 2, 1, 0, 2, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >&);
+template int igl::unproject_to_zero_plane<Eigen::Matrix<double, 2, 1, 0, 2, 1>, Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 2, 1, 0, 2, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
 #endif
 
 #endif