Browse Source

rm superfluous printing nreanttweakbar and unproject inside mesh with embree

Former-commit-id: 361679f72d2cd513834b4392492bfe3f8023f80e
Alec Jacobson (jalec 11 years ago
parent
commit
f51328f60f

+ 1 - 1
include/igl/ReAntTweakBar.cpp

@@ -821,7 +821,7 @@ bool igl::ReTwBar::set_value_from_string(
 
   if(!item_found)
   {
-    printf("ERROR: item not found\n");
+    printf("ERROR: item '%s' not found\n",name);
   }
   return true;
 }

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

@@ -0,0 +1,53 @@
+#include "unproject_in_mesh.h"
+#include "EmbreeIntersector.h"
+#include <igl/unproject.h>
+#include <vector>
+
+template <
+  typename PointMatrixType,
+  typename FaceMatrixType,
+  typename RowVector3,
+  typename Derivedobj>
+bool igl::unproject_in_mesh(
+  const int x,
+  const int y,
+  const igl::EmbreeIntersector<PointMatrixType,FaceMatrixType,RowVector3> & ei,
+  Eigen::PlainObjectBase<Derivedobj> & obj)
+{
+  using namespace igl;
+  using namespace std;
+  using namespace Eigen;
+  // Source and direction on screen
+  Vector3d win_s = Vector3d(x,y,0);
+  Vector3d win_d(x,y,1);
+  // Source, destination and direction in world
+  Vector3d s,d,dir;
+  unproject(win_s,s);
+  unproject(win_d,d);
+  dir = d-s;
+  // Shoot ray, collect all hits (could just collect first two)
+  int num_rays_shot;
+  vector<embree::Hit > hits;
+  ei.intersectRay(s,dir,hits,num_rays_shot);
+  switch(hits.size())
+  {
+    case 0:
+      return false;
+    case 1:
+    {
+      obj = s + dir*hits[0].t;
+      break;
+    }
+    case 2:
+    default:
+    {
+      obj = 0.5*((s + dir*hits[0].t) + (s + dir*hits[hits.size()-1].t));
+      break;
+    }
+  }
+  return true;
+}
+
+#ifndef IGL_HEADER_ONLY
+template bool igl::unproject_in_mesh<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, 3, 1, 0, 3, 1> >(int, int, igl::EmbreeIntersector<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
+#endif

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

@@ -0,0 +1,41 @@
+#ifndef IGL_UNPROJECT_IN_MESH
+#define IGL_UNPROJECT_IN_MESH
+
+#include <igl/igl_inline.h>
+#include <Eigen/Core>
+
+namespace igl
+{
+  // Forward define
+  template <
+    typename PointMatrixType,
+    typename FaceMatrixType,
+    typename RowVector3>
+  class EmbreeIntersector;
+  // Unproject a screen location (using current opengl viewport, projection, and
+  // model view) to a 3D position 
+  //
+  // Inputs:
+  //    x  x-coordinate of mouse location
+  //    y  y-coordinate of mouse location
+  //    ei  EmbreeIntersector containing (V,F)
+  // Outputs:
+  //    obj  3d unprojected mouse point in mesh
+  // Returns true only if ray through (x,y) hits (V,F) at least
+  // once
+  //
+  template <
+    typename PointMatrixType,
+    typename FaceMatrixType,
+    typename RowVector3,
+    typename Derivedobj>
+  bool unproject_in_mesh(
+    const int x,
+    const int y,
+    const igl::EmbreeIntersector<PointMatrixType,FaceMatrixType,RowVector3> & ei,
+    Eigen::PlainObjectBase<Derivedobj> & obj);
+}
+#ifdef IGL_HEADER_ONLY
+#  include "unproject_in_mesh.cpp"
+#endif
+#endif