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

fixed compilation problems
added tutorial
removed debug prints


Former-commit-id: 5215a21524285575064eb89355ce59e15ea6769d

Daniele Panozzo 7 жил өмнө
parent
commit
cac2bc0494

+ 1 - 1
include/igl/exact_geodesic.cpp.REMOVED.git-id

@@ -1 +1 @@
-e12c6ad0fed70dd162910535a698d1f1b9b0d9ac
+e8a96c9321de4f3ef43a3f39728a28efbfc94b18

+ 5 - 0
tutorial/206_GeodesicDistance/CMakeLists.txt

@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(206_GeodesicDistance)
+
+add_executable(${PROJECT_NAME}_bin main.cpp)
+target_link_libraries(${PROJECT_NAME}_bin igl::core igl::opengl igl::opengl_glfw tutorials)

+ 73 - 0
tutorial/206_GeodesicDistance/main.cpp

@@ -0,0 +1,73 @@
+#include <igl/readOBJ.h>
+#include <igl/opengl/glfw/Viewer.h>
+#include <igl/exact_geodesic.h>
+#include <igl/colormap.h>
+#include <igl/unproject_onto_mesh.h>
+
+#include <iostream>
+#include "tutorial_shared_path.h"
+
+Eigen::MatrixXd V;
+Eigen::MatrixXi F;
+
+void plotMeshDistance(igl::opengl::glfw::Viewer& viewer, const Eigen::MatrixXd& V, const Eigen::MatrixXi& F, const Eigen::VectorXd& d, const double strip_size )
+{
+    // Rescale the function depending on the strip size
+    Eigen::VectorXd f = (d/strip_size);
+
+    // The function should be 1 on each integer coordinate
+    f = (f*M_PI).array().sin().abs();
+
+    // Compute per-vertex colors
+    Eigen::MatrixXd C;
+    igl::colormap(igl::COLOR_MAP_TYPE_INFERNO,f,false,C);
+
+    // Plot the mesh
+    viewer.data().set_mesh(V, F);
+    viewer.data().set_colors(C);
+}
+
+int main(int argc, char *argv[])
+{
+  using namespace Eigen;
+  using namespace std;
+
+  // Load a mesh in OFF format
+  igl::readOBJ(TUTORIAL_SHARED_PATH "/armadillo.obj", V, F);
+
+
+  igl::opengl::glfw::Viewer viewer;
+  // Plot a distance when a vertex is picked
+  viewer.callback_mouse_down =
+  [&](igl::opengl::glfw::Viewer& viewer, int, int)->bool
+  {
+      int fid;
+      Eigen::Vector3f bc;
+      // Cast a ray in the view direction starting from the mouse position
+      double x = viewer.current_mouse_x;
+      double y = viewer.core.viewport(3) - viewer.current_mouse_y;
+      if(igl::unproject_onto_mesh(Eigen::Vector2f(x,y), viewer.core.view * viewer.core.model,
+                                  viewer.core.proj, viewer.core.viewport, V, F, fid, bc))
+      {
+          int max;
+          bc.maxCoeff(&max);
+          int vid = F(fid,max);
+          Eigen::VectorXi VS,FS,VT,FT;
+          // The selected vertex is the source
+          VS.resize(1);
+          VS << vid;
+          // All vertices are the targets
+          VT.setLinSpaced(V.rows(),0,V.rows()-1);
+          Eigen::VectorXd d;
+          igl::exact_geodesic(V,F,VS,FS,VT,FT,d);
+
+          plotMeshDistance(viewer,V,F,d,0.05);
+      }
+      return false;
+  };
+  viewer.data().set_mesh(V,F);
+
+  cout << "Press [space] to smooth." << endl;;
+  cout << "Press [r] to reset." << endl;;
+  return viewer.launch();
+}

+ 1 - 0
tutorial/CMakeLists.txt

@@ -64,6 +64,7 @@ if(TUTORIALS_CHAPTER2)
   add_subdirectory("203_CurvatureDirections")
   add_subdirectory("204_Gradient")
   add_subdirectory("205_Laplacian")
+  add_subdirectory("206_GeodesicDistance")
 endif()
 
 # Chapter 3