Alec Jacobson 5 年之前
父節點
當前提交
1de2627280

+ 11 - 5
include/igl/knn.h

@@ -6,8 +6,8 @@
 // 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_KNN
-#define IGL_KNN
+#ifndef IGL_KNN_H
+#define IGL_KNN_H
 #include "igl_inline.h"
 #include <Eigen/Core>
 #include <vector>
@@ -34,10 +34,16 @@ namespace igl
   //          of the ith octree cell
   // Outputs:
   //   I  #P by k list of k-nearest-neighbor indices into P
-  template <typename DerivedP, typename KType, typename IndexType,
-    typename DerivedCH, typename DerivedCN, typename DerivedW,
+  template <
+    typename DerivedP, 
+    typename KType, 
+    typename IndexType,
+    typename DerivedCH, 
+    typename DerivedCN, 
+    typename DerivedW,
     typename DerivedI>
-  IGL_INLINE void knn(const Eigen::MatrixBase<DerivedP>& P,
+  IGL_INLINE void knn(
+    const Eigen::MatrixBase<DerivedP>& P,
     const KType & k,
     const std::vector<std::vector<IndexType> > & point_indices,
     const Eigen::MatrixBase<DerivedCH>& CH,

+ 40 - 0
tests/include/igl/barycentric_interpolation.cpp

@@ -0,0 +1,40 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2018 Alec Jacobson <[email protected]>
+// 
+// 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 <test_common.h>
+#include <igl/barycentric_interpolation.h>
+
+TEST_CASE("barycentric_interpolation: two-triangles", "[igl]")
+{
+  const Eigen::MatrixXd V = 
+    (Eigen::MatrixXd(4,3) << 
+     0,0,0,
+     1,0,0,
+     1,1,0,
+     0,1,0).finished();
+  const Eigen::MatrixXi F = 
+    (Eigen::MatrixXi(2,3) << 0,1,2,0,2,3).finished();
+  const Eigen::VectorXi I =
+   (Eigen::VectorXi(4,1)<<0,0,1,1).finished();
+  const Eigen::MatrixXd B =
+   (Eigen::MatrixXd(4,3)<<
+    1,0,0,
+    0.5,0.5,0,
+    0.5,0.5,0,
+    0.25,0.25,0.5
+    ).finished();
+  const Eigen::MatrixXd Xgt =
+   (Eigen::MatrixXd(4,3)<<
+    0,0,0,
+    0.5,0,0,
+    0.5,0.5,0,
+    0.25,0.75,0
+    ).finished();
+  Eigen::MatrixXd X;
+  igl::barycentric_interpolation(V,F,B,I,X);
+  test_common::assert_eq(X,Xgt);
+}

+ 40 - 0
tests/include/igl/blue_noise.cpp

@@ -0,0 +1,40 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2018 Alec Jacobson <[email protected]>
+// 
+// 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 <test_common.h>
+#include <igl/barycentric_interpolation.h>
+#include <igl/readOBJ.h>
+#include <igl/blue_noise.h>
+#include <igl/knn.h>
+#include <igl/octree.h>
+#include <igl/slice.h>
+
+TEST_CASE("blue_noise: decimated-knight", "[igl]")
+{
+  Eigen::MatrixXd V;
+  Eigen::MatrixXi F;
+  igl::readOBJ(test_common::data_path("decimated-knight.obj"),V,F);
+  const double r = 0.01;
+  Eigen::MatrixXd B,P;
+  {
+    Eigen::VectorXi I;
+    igl::blue_noise(V,F,r,B,I,P);
+  }
+  // There should be ~4000 samples on this model
+  REQUIRE(P.rows() > 3000);
+  std::vector<std::vector<int> > point_indices;
+  Eigen::MatrixXi CH;
+  Eigen::MatrixXd CN;
+  Eigen::VectorXd W;
+  igl::octree(P,point_indices,CH,CN,W);
+  Eigen::MatrixXi I;
+  igl::knn(P,2,point_indices,CH,CN,W,I);
+  Eigen::MatrixXd P2;
+  igl::slice(P,I.col(1).eval(),1,P2);
+  Eigen::VectorXd D = (P-P2).rowwise().norm();
+  REQUIRE(D.minCoeff() > r*0.99);
+}

+ 4 - 2
tutorial/720_BlueNoise/main.cpp

@@ -25,6 +25,7 @@ int main(int argc, char *argv[])
     argc>1?argv[1]: TUTORIAL_SHARED_PATH "/elephant.obj",V,F);
   Eigen::MatrixXd N;
   igl::per_vertex_normals(V,F,N);
+  const double bbd = (V.colwise().maxCoeff()- V.colwise().minCoeff()).norm();
 
   Eigen::MatrixXd P_blue;
   Eigen::MatrixXd N_blue;
@@ -39,6 +40,7 @@ int main(int argc, char *argv[])
       igl::doublearea(V,F,A);
       return sqrt(((A.sum()*0.5/(n*0.6162910373))/M_PI));
     }(n_desired);
+    printf("blue noise radius: %g\n",r);
     Eigen::MatrixXd B;
     Eigen::VectorXi I;
     igl::blue_noise(V,F,r,B,I,P_blue);
@@ -74,11 +76,11 @@ int main(int argc, char *argv[])
     if(use_blue)
     {
       viewer.data().set_points(P_blue,Eigen::RowVector3d(0.3,0.4,1.0));
-      viewer.data().set_edges_from_vector_field(P_blue,N_blue,orange);
+      viewer.data().set_edges_from_vector_field(P_blue,bbd*0.01*N_blue,orange);
     }else
     {
       viewer.data().set_points(P_white,Eigen::RowVector3d(1,1,1));
-      viewer.data().set_edges_from_vector_field(P_white,N_white,orange);
+      viewer.data().set_edges_from_vector_field(P_white,bbd*0.01*N_white,orange);
     }
   };
   update();