فهرست منبع

Merge branch 'master' of https://github.com/libigl/libigl

Conflicts:
	include/igl/slice_into.cpp

Former-commit-id: 11d8a0655314bcaf2c8c1a539a17d7710bc6eef7
Olga Diamanti 10 سال پیش
والد
کامیت
7ff65c3422

+ 2 - 7
include/igl/draw_point.cpp

@@ -22,11 +22,7 @@ IGL_INLINE void igl::draw_point(
   const bool selected)
 {
   // Push GL settings
-  //GLboolean old_depth_test;
-  //glGetBooleanv(GL_DEPTH_TEST,&old_depth_test);
-  GLboolean old_lighting;
-  glGetBooleanv(GL_LIGHTING,&old_lighting);
-  glEnable( GL_POINT_SMOOTH );
+  glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);
 
   float f;
   glGetFloatv(GL_POINT_SIZE_MAX,&f);
@@ -79,8 +75,7 @@ IGL_INLINE void igl::draw_point(
   glColor4fv(color);
 
   // Pop GL settings
-  if(old_lighting) glEnable(GL_LIGHTING);
-  //if(old_depth_test) glEnable(GL_DEPTH_TEST);
+  glPopAttrib();
 }
 
 template <typename DerivedP>

+ 2 - 0
include/igl/embree/EmbreeIntersector.h

@@ -16,12 +16,14 @@
 #ifndef IGL_EMBREE_INTERSECTOR_H
 #define IGL_EMBREE_INTERSECTOR_H
 
+#include <Eigen/Geometry>
 #include <Eigen/Core>
 #include <Eigen/Geometry>
 
 #include <vector>
 #include <embree2/rtcore.h>
 #include <embree2/rtcore_ray.h>
+#include <iostream>
 #include "Hit.h"
 #include <iostream>
 

+ 8 - 5
include/igl/project.cpp

@@ -115,12 +115,14 @@ IGL_INLINE Eigen::PlainObjectBase<Derivedobj> igl::project(
 #endif
 #endif
 
-IGL_INLINE Eigen::Vector3f igl::project(const Eigen::Vector3f&  obj,
-                        const Eigen::Matrix4f& model,
-                        const Eigen::Matrix4f& proj,
-                        const Eigen::Vector4f&  viewport)
+template <typename Scalar>
+Eigen::Matrix<Scalar,3,1> igl::project(
+  const    Eigen::Matrix<Scalar,3,1>&  obj,
+  const    Eigen::Matrix<Scalar,4,4>& model,
+  const    Eigen::Matrix<Scalar,4,4>& proj,
+  const    Eigen::Matrix<Scalar,4,1>&  viewport)
 {
-  Eigen::Vector4f tmp;
+  Eigen::Matrix<Scalar,4,1> tmp;
   tmp << obj,1;
 
   tmp = model * tmp;
@@ -151,6 +153,7 @@ template Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > igl::proj
 template Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> > igl::project<Eigen::Matrix<double, 1, 2, 1, 1, 2> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> > const&);
 template Eigen::PlainObjectBase<Eigen::Matrix<double, 2, 1, 0, 2, 1> > igl::project<Eigen::Matrix<double, 2, 1, 0, 2, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 2, 1, 0, 2, 1> > const&);
 #endif
+template Eigen::Matrix<double, 3, 1, 0, 3, 1> igl::project<double>(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, Eigen::Matrix<double, 4, 4, 0, 4, 4> const&, Eigen::Matrix<double, 4, 4, 0, 4, 4> const&, Eigen::Matrix<double, 4, 1, 0, 4, 1> const&);
 #endif
 
 #endif

+ 6 - 4
include/igl/project.h

@@ -44,10 +44,12 @@ namespace igl
 // Returns:
 //   screen space x, y, and z coordinates respectively
 // Returns return value of gluProject call
-  IGL_INLINE Eigen::Vector3f project(const Eigen::Vector3f&  obj,
-                          const Eigen::Matrix4f& model,
-                          const Eigen::Matrix4f& proj,
-                          const Eigen::Vector4f&  viewport);
+  template <typename Scalar>
+  IGL_INLINE Eigen::Matrix<Scalar,3,1> project(
+    const    Eigen::Matrix<Scalar,3,1>&  obj,
+    const    Eigen::Matrix<Scalar,4,4>& model,
+    const    Eigen::Matrix<Scalar,4,4>& proj,
+    const    Eigen::Matrix<Scalar,4,1>&  viewport);
 
 }
 

+ 1 - 0
include/igl/slice_into.cpp

@@ -137,4 +137,5 @@ template void igl::slice_into<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::Plain
 template void igl::slice_into<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, int, Eigen::Matrix<double, -1, 1, 0, -1, 1>&);
 template void igl::slice_into<Eigen::SparseMatrix<double, 0, int> >(Eigen::SparseMatrix<double, 0, int> const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, int, Eigen::SparseMatrix<double, 0, int>&);
 template void igl::slice_into<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, int, Eigen::Matrix<int, -1, 1, 0, -1, 1>&);
+template void igl::slice_into<Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
 #endif

+ 35 - 35
include/igl/unproject.cpp

@@ -13,7 +13,7 @@
 #include <Eigen/LU>
 #include "OpenGL_convenience.h"
 
-IGL_INLINE int igl::unproject(
+IGL_INLINE void igl::unproject(
   const double winX,
   const double winY,
   const double winZ,
@@ -21,61 +21,59 @@ IGL_INLINE int igl::unproject(
   double* objY,
   double* objZ)
 {
-  // Put model, projection, and viewport matrices into double arrays
-  double MV[16];
-  double P[16];
-  int VP[4];
-  glGetDoublev(GL_MODELVIEW_MATRIX,  MV);
-  glGetDoublev(GL_PROJECTION_MATRIX, P);
-  glGetIntegerv(GL_VIEWPORT, VP);
-  return gluUnProject(winX,winY,winZ,MV,P,VP,objX,objY,objZ);
+  Eigen::Vector3d obj;
+  igl::unproject(Eigen::Vector3d(winX,winY,winZ),obj);
+  *objX = obj(0);
+  *objY = obj(1);
+  *objZ = obj(2);
 }
 
 template <typename Derivedwin, typename Derivedobj>
-IGL_INLINE int igl::unproject(
+IGL_INLINE void igl::unproject(
   const Eigen::PlainObjectBase<Derivedwin> & win,
   Eigen::PlainObjectBase<Derivedobj> & obj)
 {
-  Eigen::Vector3d dwin(win(0),win(1),win(2));
-  Eigen::Vector3d dobj;
-  int ret = unproject(dwin(0),dwin(1),dwin(2),
-      &dobj.data()[0],
-      &dobj.data()[1],
-      &dobj.data()[2]);
-  obj(0) = dobj(0);
-  obj(1) = dobj(1);
-  obj(2) = dobj(2);
-  return ret;
+  obj = igl::unproject(win).template cast<typename Derivedobj::Scalar>();
 }
 
 template <typename Derivedwin>
 IGL_INLINE Eigen::PlainObjectBase<Derivedwin> igl::unproject(
   const Eigen::PlainObjectBase<Derivedwin> & win)
 {
-  Eigen::PlainObjectBase<Derivedwin> obj;
-  unproject(win,obj);
-  return obj;
+  using namespace Eigen;
+  typedef typename Derivedwin::Scalar Scalar;
+  Matrix4d MV,P;
+  Vector4i VPi;
+  Vector4d VPd;
+  glGetDoublev(GL_MODELVIEW_MATRIX,MV.data());
+  glGetDoublev(GL_PROJECTION_MATRIX,P.data());
+  glGetIntegerv(GL_VIEWPORT,VPi.data());
+  VPd = VPi.cast<double>();
+  Vector3d wind = win.template cast<double>();
+  Vector3d objd = igl::unproject(wind,MV,P,VPd);
+  return objd.template cast<Scalar>();
 }
 
 #endif
 #endif
 
 
-Eigen::Vector3f igl::unproject(
-  const Eigen::Vector3f& win,
-  const Eigen::Matrix4f& model,
-  const Eigen::Matrix4f& proj,
-  const Eigen::Vector4f& viewport)
+template <typename Scalar>
+IGL_INLINE Eigen::Matrix<Scalar,3,1> igl::unproject(
+  const    Eigen::Matrix<Scalar,3,1>&  win,
+  const    Eigen::Matrix<Scalar,4,4>& model,
+  const    Eigen::Matrix<Scalar,4,4>& proj,
+  const    Eigen::Matrix<Scalar,4,1>&  viewport)
 {
-  Eigen::Matrix4f Inverse = (proj * model).inverse();
+  Eigen::Matrix<Scalar,4,4> Inverse = (proj * model).inverse();
 
-  Eigen::Vector4f tmp;
+  Eigen::Matrix<Scalar,4,1> tmp;
   tmp << win, 1;
   tmp(0) = (tmp(0) - viewport(0)) / viewport(2);
   tmp(1) = (tmp(1) - viewport(1)) / viewport(3);
   tmp = tmp.array() * 2.0f - 1.0f;
 
-  Eigen::Vector4f obj = Inverse * tmp;
+  Eigen::Matrix<Scalar,4,1> obj = Inverse * tmp;
   obj /= obj(3);
 
   return obj.head(3);
@@ -86,13 +84,15 @@ Eigen::Vector3f igl::unproject(
 #ifndef IGL_NO_OPENGL
 #ifndef IGL_OPENGL_4
 // Explicit template instanciation
-template int igl::unproject<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<Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
+template void igl::unproject<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 void igl::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
 template Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > igl::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&);
-template int igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
+template void igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
 template Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&);
-template int igl::unproject<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >&);
+template void igl::unproject<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >&);
+template Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > igl::unproject<Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&);
 #endif
+template Eigen::Matrix<double, 3, 1, 0, 3, 1> igl::unproject<double>(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, Eigen::Matrix<double, 4, 4, 0, 4, 4> const&, Eigen::Matrix<double, 4, 4, 0, 4, 4> const&, Eigen::Matrix<double, 4, 1, 0, 4, 1> const&);
 #endif
 
 #endif

+ 8 - 15
include/igl/unproject.h

@@ -18,7 +18,7 @@ namespace igl
   // Outputs:
   //   obj*  pointers to 3D objects' x, y, and z coordinates respectively
   // Returns return value of gluUnProject call
-  IGL_INLINE int unproject(
+  IGL_INLINE void unproject(
     const double winX,
     const double winY,
     const double winZ,
@@ -26,7 +26,7 @@ namespace igl
     double* objY,
     double* objZ);
   template <typename Derivedwin, typename Derivedobj>
-  IGL_INLINE int unproject(
+  IGL_INLINE void unproject(
     const Eigen::PlainObjectBase<Derivedwin> & win,
     Eigen::PlainObjectBase<Derivedobj> & obj);
   template <typename Derivedwin>
@@ -39,19 +39,12 @@ namespace igl
   // Returns:
   //   the unprojected x, y, and z coordinates
   // Returns return value of gluUnProject call
-  IGL_INLINE Eigen::Vector3f unproject(
-    const Eigen::Vector3f& win,
-    const Eigen::Matrix4f& model,
-    const Eigen::Matrix4f& proj,
-    const Eigen::Vector4f& viewport);
-    
-  template <typename Derivedwin, typename Derivedobj>
-  IGL_INLINE int unproject(
-    const Eigen::PlainObjectBase<Derivedwin> & win,
-    Eigen::PlainObjectBase<Derivedobj> & obj);
-  template <typename Derivedwin>
-  IGL_INLINE Eigen::PlainObjectBase<Derivedwin> unproject(
-    const Eigen::PlainObjectBase<Derivedwin> & win);
+  template <typename Scalar>
+  IGL_INLINE Eigen::Matrix<Scalar,3,1> unproject(
+    const    Eigen::Matrix<Scalar,3,1>&  win,
+    const    Eigen::Matrix<Scalar,4,4>& model,
+    const    Eigen::Matrix<Scalar,4,4>& proj,
+    const    Eigen::Matrix<Scalar,4,1>&  viewport);
 }
 
 

+ 2 - 0
include/igl/writeOBJ.cpp

@@ -12,6 +12,7 @@
 #include <iomanip>
 #include <fstream>
 #include <cstdio>
+#include <cassert>
 
 template <typename DerivedV, typename DerivedF>
 IGL_INLINE bool igl::writeOBJ(
@@ -19,6 +20,7 @@ IGL_INLINE bool igl::writeOBJ(
   const Eigen::PlainObjectBase<DerivedV>& V,
   const Eigen::PlainObjectBase<DerivedF>& F)
 {
+  assert(V.cols() == 3 && "V should have 3 columns");
   std::ofstream s(str.c_str());
   s.precision(std::numeric_limits<double>::digits10 + 1);