Просмотр исходного кода

- fixed findEMBREE bug
- added unproject_onto_mesh
- fixed compilation issues in 607


Former-commit-id: 1de205a686f9c98789decf6769878199b67a38ae

Daniele Panozzo 11 лет назад
Родитель
Сommit
46404cfb49

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

@@ -112,37 +112,6 @@ IGL_INLINE int igl::unproject_in_mesh(
   return hits.size();
 }
 
-IGL_INLINE bool igl::unproject_in_mesh(
-  const Eigen::Vector2f& pos,
-  const Eigen::MatrixXi& F,
-  const Eigen::Matrix4f& model,
-  const Eigen::Matrix4f& proj,
-  const Eigen::Vector4f& viewport,
-  const igl::EmbreeIntersector & ei,
-  int& fid,
-  int& vid)
-{
-  using namespace std;
-  using namespace Eigen;
-  MatrixXd obj;
-  vector<igl::Hit> hits;
-
-  unproject_in_mesh(pos,model,proj,viewport,ei,obj,hits);
-
-  if (hits.size()> 0)
-  {
-    Vector3d bc(1.0-hits[0].u-hits[0].v, hits[0].u, hits[0].v);
-    int i;
-    bc.maxCoeff(&i);
-
-    fid = hits[0].id;
-    vid = F(fid,i);
-    return true;
-  }
-
-  return false;
-}
-
 #ifndef IGL_OPENLGL_4
 
 #ifdef IGL_STATIC_LIBRARY

+ 0 - 24
include/igl/embree/unproject_in_mesh.h

@@ -72,30 +72,6 @@ IGL_INLINE int unproject_in_mesh(
   Eigen::PlainObjectBase<Derivedobj> & obj,
   std::vector<igl::Hit > & hits);
 
-// Unproject a screen location (using the given model, proj and viewewport) to a 3D position
-// and a set of hits
-//
-// Inputs:
-//    pos        screen space coordinates
-//    F          #F by 3 face matrix
-//    model      model matrix
-//    proj       projection matrix
-//    viewport   vieweport vector
-//    ei         EmbreeIntersector containing (V,F)
-// Outputs:
-//    fid        id of the first face hit
-//    vid        vertex id of the closest vertex hit
-// Returns true if there is a hit
-IGL_INLINE bool unproject_in_mesh(
-  const Eigen::Vector2f& pos,
-  const Eigen::MatrixXi& F,
-  const Eigen::Matrix4f& model,
-  const Eigen::Matrix4f& proj,
-  const Eigen::Vector4f& viewport,
-  const igl::EmbreeIntersector & ei,
-  int& fid,
-  int& vid);
-
 }
 #ifndef IGL_STATIC_LIBRARY
 #  include "unproject_in_mesh.cpp"

+ 48 - 0
include/igl/embree/unproject_onto_mesh.cpp

@@ -0,0 +1,48 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 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/.
+#include "unproject_onto_mesh.h"
+#include "EmbreeIntersector.h"
+#include <igl/unproject.h>
+#include <igl/embree/unproject_in_mesh.h>
+#include <vector>
+
+IGL_INLINE bool igl::unproject_onto_mesh(
+  const Eigen::Vector2f& pos,
+  const Eigen::MatrixXi& F,
+  const Eigen::Matrix4f& model,
+  const Eigen::Matrix4f& proj,
+  const Eigen::Vector4f& viewport,
+  const igl::EmbreeIntersector & ei,
+  int& fid,
+  int& vid)
+{
+  using namespace std;
+  using namespace Eigen;
+  MatrixXd obj;
+  vector<igl::Hit> hits;
+
+  unproject_in_mesh(pos,model,proj,viewport,ei,obj,hits);
+
+  if (hits.size()> 0)
+  {
+    Vector3d bc(1.0-hits[0].u-hits[0].v, hits[0].u, hits[0].v);
+    int i;
+    bc.maxCoeff(&i);
+
+    fid = hits[0].id;
+    vid = F(fid,i);
+    return true;
+  }
+
+  return false;
+}
+
+
+#ifdef IGL_STATIC_LIBRARY
+
+#endif

+ 49 - 0
include/igl/embree/unproject_onto_mesh.h

@@ -0,0 +1,49 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2014 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/.
+#ifndef IGL_UNPROJECT_ONTO_MESH
+#define IGL_UNPROJECT_ONTO_MESH
+#include <igl/igl_inline.h>
+#include <Eigen/Core>
+
+#include <vector>
+#include "Hit.h"
+
+namespace igl
+{
+  // Forward define
+  class EmbreeIntersector;
+
+// Unproject a screen location (using the given model, proj and viewport) to find
+// the first face on the mesh and the closest vertex
+//
+// Inputs:
+//    pos        screen space coordinates
+//    F          #F by 3 face matrix
+//    model      model matrix
+//    proj       projection matrix
+//    viewport   vieweport vector
+//    ei         EmbreeIntersector containing (V,F)
+// Outputs:
+//    fid        id of the first face hit
+//    vid        vertex id of the closest vertex hit
+// Returns true if there is a hit
+IGL_INLINE bool unproject_onto_mesh(
+  const Eigen::Vector2f& pos,
+  const Eigen::MatrixXi& F,
+  const Eigen::Matrix4f& model,
+  const Eigen::Matrix4f& proj,
+  const Eigen::Vector4f& viewport,
+  const igl::EmbreeIntersector & ei,
+  int& fid,
+  int& vid);
+
+}
+#ifndef IGL_STATIC_LIBRARY
+#  include "unproject_onto_mesh.cpp"
+#endif
+#endif

+ 6 - 6
tutorial/607_Picking/main.cpp

@@ -1,7 +1,7 @@
 #include <igl/readOFF.h>
 #include <igl/viewer/Viewer.h>
 #include <igl/embree/EmbreeIntersector.h>
-#include <igl/embree/unproject_in_mesh.h>
+#include <igl/embree/unproject_onto_mesh.h>
 
 #include <algorithm>
 
@@ -26,12 +26,12 @@ bool mouse_down(igl::Viewer& viewer, int button, int modifier)
 
   // Cast a ray in the view direction starting from the mouse position
   double x = viewer.current_mouse_x;
-  double y = viewer.viewport(3) - viewer.current_mouse_y;
-  bool hit = unproject_in_mesh(Vector2f(x,y),
+  double y = viewer.core.viewport(3) - viewer.current_mouse_y;
+  bool hit = unproject_onto_mesh(Vector2f(x,y),
                                 F,
-                                viewer.view * viewer.model,
-                                viewer.proj,
-                                viewer.viewport,
+                                viewer.core.view * viewer.core.model,
+                                viewer.core.proj,
+                                viewer.core.viewport,
                                 *ei,
                                 fid,
                                 vid);

+ 2 - 2
tutorial/CMakeLists.txt

@@ -8,10 +8,10 @@ SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
 find_package(LIBCOMISO QUIET)
 
 ## Check for MATLAB, if not available skip the examples that depends on it
-find_package(LIBMATLAB QUIET)
+find_package(MATLAB QUIET)
 
 ## Check for EMBREE, if not available skip the examples that depends on it
-find_package(LIBEMBREE QUIET)
+find_package(EMBREE QUIET)
 
 # Chapter 1
 add_subdirectory("101_FileIO")

+ 3 - 0
tutorial/cmake/FindEMBREE.cmake

@@ -10,9 +10,12 @@
 FIND_PATH(EMBREE_INCLUDE_DIR embree/include/embree.h
 	  PATHS
 		${PROJECT_SOURCE_DIR}/../../external/embree
+		${PROJECT_SOURCE_DIR}/../external/embree
 		NO_DEFAULT_PATH
     )
 
+# message(FATAL_ERROR ${PROJECT_SOURCE_DIR}/../../external/embree)
+
 SET(SEARCH_PATHS "${EMBREE_INCLUDE_DIR}" "${EMBREE_INCLUDE_DIR}/build" "${EMBREE_INCLUDE_DIR}/lib")
 
 FIND_LIBRARY(EMBREE_CORE_LIBRARY  NAMES embree PATHS ${SEARCH_PATHS} PATH_SUFFIXES a lib)