Browse Source

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

Conflicts:
	tutorial/cmake/FindLIBCOMISO.cmake

Former-commit-id: b15ed9654bcdc5dafcecb34ed9b1addae55fd734
Olga Diamanti 11 years ago
parent
commit
3241251c58
61 changed files with 665 additions and 167 deletions
  1. 1 0
      .gitignore
  2. 1 0
      RELEASE_HISTORY.txt
  3. 1 1
      VERSION.txt
  4. 2 2
      include/igl/HalfEdgeIterator.h
  5. 2 2
      include/igl/comiso/frame_field.cpp
  6. 11 11
      include/igl/comiso/miq.cpp
  7. 2 2
      include/igl/comiso/nrosy.cpp
  8. 1 1
      include/igl/cut_mesh_from_singularities.cpp
  9. 86 4
      include/igl/embree/unproject_in_mesh.cpp
  10. 57 5
      include/igl/embree/unproject_in_mesh.h
  11. 1 1
      include/igl/principal_curvature.cpp
  12. 34 4
      include/igl/unproject.cpp
  13. 24 4
      include/igl/unproject.h
  14. 13 25
      include/igl/viewer/Viewer.cpp
  15. 1 0
      include/igl/viewer/Viewer.h
  16. 2 2
      tutorial/101_FileIO/CMakeLists.txt
  17. 11 0
      tutorial/102_DrawMesh/CMakeLists.txt
  18. 0 0
      tutorial/102_DrawMesh/main.cpp
  19. 0 11
      tutorial/103_DrawMesh/CMakeLists.txt
  20. 11 0
      tutorial/103_Events/CMakeLists.txt
  21. 0 0
      tutorial/103_Events/main.cpp
  22. 11 0
      tutorial/104_Colors/CMakeLists.txt
  23. 2 2
      tutorial/104_Colors/main.cpp
  24. 0 11
      tutorial/104_Events/CMakeLists.txt
  25. 0 11
      tutorial/105_Colors/CMakeLists.txt
  26. 11 0
      tutorial/105_Overlays/CMakeLists.txt
  27. 0 0
      tutorial/105_Overlays/main.cpp
  28. 0 11
      tutorial/106_Overlays/CMakeLists.txt
  29. 15 0
      tutorial/106_Picking/CMakeLists.txt
  30. 68 0
      tutorial/106_Picking/main.cpp
  31. 2 2
      tutorial/201_Normals/CMakeLists.txt
  32. 2 2
      tutorial/202_GaussianCurvature/CMakeLists.txt
  33. 2 2
      tutorial/203_CurvatureDirections/CMakeLists.txt
  34. 3 3
      tutorial/203_CurvatureDirections/main.cpp
  35. 2 2
      tutorial/204_Gradient/CMakeLists.txt
  36. 2 2
      tutorial/205_Laplacian/CMakeLists.txt
  37. 2 2
      tutorial/301_Slice/CMakeLists.txt
  38. 2 2
      tutorial/302_Sort/CMakeLists.txt
  39. 2 2
      tutorial/303_LaplaceEquation/CMakeLists.txt
  40. 2 2
      tutorial/304_LinearEqualityConstraints/CMakeLists.txt
  41. 2 2
      tutorial/305_QuadraticProgramming/CMakeLists.txt
  42. 2 2
      tutorial/501_HarmonicParam/CMakeLists.txt
  43. 2 2
      tutorial/502_LSCMParam/CMakeLists.txt
  44. 2 2
      tutorial/503_ARAPParam/CMakeLists.txt
  45. 2 2
      tutorial/504_NRosyDesign/CMakeLists.txt
  46. 2 2
      tutorial/505_MIQ/CMakeLists.txt
  47. 2 2
      tutorial/506_FrameField/CMakeLists.txt
  48. 6 2
      tutorial/601_Serialization/CMakeLists.txt
  49. 2 2
      tutorial/602_Matlab/CMakeLists.txt
  50. 2 2
      tutorial/604_Triangle/CMakeLists.txt
  51. 2 2
      tutorial/604_Triangle/main.cpp
  52. 2 2
      tutorial/605_Tetgen/CMakeLists.txt
  53. 15 0
      tutorial/606_AmbientOcclusion/CMakeLists.txt
  54. 78 0
      tutorial/606_AmbientOcclusion/main.cpp
  55. 15 8
      tutorial/CMakeLists.shared
  56. 39 0
      tutorial/CMakeLists.txt
  57. 43 0
      tutorial/cmake/FindEMBREE.cmake
  58. 12 3
      tutorial/cmake/FindLIBCOMISO.cmake
  59. 9 0
      tutorial/cmake/FindLIBIGL.cmake
  60. 29 0
      tutorial/compile_linux.sh
  61. 8 1
      tutorial/compile_macosx.sh

+ 1 - 0
.gitignore

@@ -64,3 +64,4 @@ tutorial/*/Makefile
 external/glew/build
 external/glfw/build
 *buildXcode*
+tutorial/build*

+ 1 - 0
RELEASE_HISTORY.txt

@@ -1,3 +1,4 @@
+1.0.0  Major beta release: many renames, tutorial, triangle wrapper, org. build
 0.4.6  Generalized Winding Numbers
 0.4.5  CGAL extra: mesh selfintersection
 0.4.4  STL file format support

+ 1 - 1
VERSION.txt

@@ -3,4 +3,4 @@
 # Anyone may increment Minor to indicate a small change.
 # Major indicates a large change or large number of changes (upload to website)
 # World indicates a substantial change or release
-0.4.6
+1.0.0

+ 2 - 2
include/igl/HalfEdgeIterator.h

@@ -18,7 +18,7 @@ namespace igl
   // HalfEdgeIterator - Fake halfedge for fast and easy navigation on triangle meshes with vertex_triangle_adjacency and
   // triangle_triangle adjacency
   template <typename DerivedF>
-  class Pos
+  class HalfEdgeIterator
   {
   public:
     // Init the HalfEdgeIterator by specifying Face,Edge Index and Orientation
@@ -128,7 +128,7 @@ namespace igl
     }
 
 
-    IGL_INLINE bool operator==(Pos& p2)
+    IGL_INLINE bool operator==(HalfEdgeIterator& p2)
     {
       return
       (

+ 2 - 2
include/igl/comiso/frame_field.cpp

@@ -1,6 +1,6 @@
 #include "frame_field.h"
 
-#include <igl/tt.h>
+#include <igl/triangle_triangle_adjacency.h>
 #include <igl/edge_topology.h>
 #include <igl/per_face_normals.h>
 #include <igl/comiso/nrosy.h>
@@ -109,7 +109,7 @@ FrameInterpolator::FrameInterpolator(const Eigen::MatrixXd& _V, const Eigen::Mat
 
 
   // Generate topological relations
-  igl::tt(V,F,TT,TTi);
+  igl::triangle_triangle_adjacency(V,F,TT,TTi);
   igl::edge_topology(V,F, EV, FE, EF);
 
   // Flag border edges

+ 11 - 11
include/igl/comiso/miq.cpp

@@ -8,12 +8,12 @@
 
 #include <igl/comiso/miq.h>
 #include <igl/local_basis.h>
-#include <igl/tt.h>
+#include <igl/triangle_triangle_adjacency.h>
 
 // includes for VertexIndexing
-#include <igl/Pos.h>
+#include <igl/HalfEdgeIterator.h>
 #include <igl/is_border_vertex.h>
-#include <igl/vf.h>
+#include <igl/vertex_triangle_adjacency.h>
 
 
 // includes for poissonSolver
@@ -572,11 +572,11 @@ namespace igl {
 
     IGL_INLINE bool updateStiffeningJacobianDistorsion(double grad_size, const Eigen::MatrixXd& WUV);
 
-    IGL_INLINE IGL_INLINE bool IsFlipped(const Eigen::Vector2d &uv0,
+    IGL_INLINE bool IsFlipped(const Eigen::Vector2d &uv0,
                           const Eigen::Vector2d &uv1,
                           const Eigen::Vector2d &uv2);
 
-    IGL_INLINE IGL_INLINE bool IsFlipped(const int i, const Eigen::MatrixXd& WUV);
+    IGL_INLINE bool IsFlipped(const int i, const Eigen::MatrixXd& WUV);
 
   };
 };
@@ -633,7 +633,7 @@ Handle_Seams(_Handle_Seams)
 {
 
   V_border = igl::is_border_vertex(V,F);
-  igl::vf(V,F,VF,VFi);
+  igl::vertex_triangle_adjacency(V,F,VF,VFi);
 
   IndexToVert.clear();
 
@@ -725,7 +725,7 @@ IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::FindInitialPos(const in
   int f_init;
   int edge_init;
   FirstPos(vert,f_init,edge_init); // todo manually IGL_INLINE the function
-  igl::Pos<DerivedF> VFI(&F,&TT,&TTi,f_init,edge_init);
+  igl::HalfEdgeIterator<DerivedF> VFI(&F,&TT,&TTi,f_init,edge_init);
 
   bool vertexB = V_border[vert];
   bool possible_split=false;
@@ -773,7 +773,7 @@ IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::MapIndexes(const int  v
   ///insert an initial index
   int curr_index=AddNewIndex(vert);
   ///and initialize the jumping pos
-  igl::Pos<DerivedF> VFI(&F,&TT,&TTi,f_init,edge_init);
+  igl::HalfEdgeIterator<DerivedF> VFI(&F,&TT,&TTi,f_init,edge_init);
   bool complete_turn=false;
   do
   {
@@ -809,7 +809,7 @@ IGL_INLINE void igl::VertexIndexing<DerivedV, DerivedF>::InitMappingSeam(const i
   int f_init = VF[vert][0];
   int indexE = VFi[vert][0];
 
-  igl::Pos<DerivedF> VFI(&F,&TT,&TTi,f_init,indexE);
+  igl::HalfEdgeIterator<DerivedF> VFI(&F,&TT,&TTi,f_init,indexE);
 
   int edge_init;
   int face_init;
@@ -1052,7 +1052,7 @@ Handle_SystemInfo(_Handle_SystemInfo)
   WUV       = Eigen::MatrixXd(F.rows(),6);
   igl::doublearea(V,F,doublearea);
   igl::per_face_normals(V,F,N);
-  igl::vf(V,F,VF,VFi);
+  igl::vertex_triangle_adjacency(V,F,VF,VFi);
 }
 
 
@@ -1850,7 +1850,7 @@ V(V_),
 F(F_)
 {
   igl::local_basis(V,F,B1,B2,B3);
-  igl::tt(V,F,TT,TTi);
+  igl::triangle_triangle_adjacency(V,F,TT,TTi);
 
   // Prepare indexing for the linear system
   VertexIndexing<DerivedV, DerivedF> VInd(V, F, TT, TTi, BIS1_combed, BIS2_combed, Handle_MMatch, Handle_Singular, Handle_SingularDegree, Handle_Seams);

+ 2 - 2
include/igl/comiso/nrosy.cpp

@@ -7,7 +7,7 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 
 #include <igl/comiso/nrosy.h>
-#include <igl/tt.h>
+#include <igl/triangle_triangle_adjacency.h>
 #include <igl/edge_topology.h>
 #include <igl/per_face_normals.h>
 
@@ -159,7 +159,7 @@ igl::NRosyField::NRosyField(const Eigen::MatrixXd& _V, const Eigen::MatrixXi& _F
 
 
   // Generate topological relations
-  igl::tt(V,F,TT,TTi);
+  igl::triangle_triangle_adjacency(V,F,TT,TTi);
   igl::edge_topology(V,F, EV, FE, EF);
 
   // Flag border edges

+ 1 - 1
include/igl/cut_mesh_from_singularities.cpp

@@ -135,7 +135,7 @@ namespace igl {
     Handle_Singular(Handle_Singular_),
     Handle_SingularDegree(Handle_SingularDegree_)
     {
-      tt(V,F,TT,TTi);
+      triangle_triangle_adjacency(V,F,TT,TTi);
     };
 
     inline void cut(Eigen::PlainObjectBase<DerivedO> &Handle_Seams)

+ 86 - 4
include/igl/embree/unproject_in_mesh.cpp

@@ -1,15 +1,16 @@
 // This file is part of libigl, a simple c++ geometry processing library.
-// 
+//
 // Copyright (C) 2013 Alec Jacobson <alecjacobson@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 
+//
+// 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_in_mesh.h"
 #include "EmbreeIntersector.h"
 #include <igl/unproject.h>
 #include <vector>
 
+#ifndef IGL_OPENGL_4
 template <
   typename Derivedobj>
 IGL_INLINE int igl::unproject_in_mesh(
@@ -64,8 +65,89 @@ IGL_INLINE int igl::unproject_in_mesh(
   }
   return hits.size();
 }
+#endif
+
+template <typename Derivedobj>
+IGL_INLINE int igl::unproject_in_mesh(
+  const Eigen::Vector2f& pos,
+  const Eigen::Matrix4f& model,
+  const Eigen::Matrix4f& proj,
+  const Eigen::Vector4f& viewport,
+  const igl::EmbreeIntersector & ei,
+  Eigen::PlainObjectBase<Derivedobj> & obj,
+  std::vector<igl::Hit > & hits)
+{
+  using namespace igl;
+  using namespace std;
+  using namespace Eigen;
+  // Source and direction on screen
+  Vector3f win_s(pos(0),pos(1),0);
+  Vector3f win_d(pos(0),pos(1),1);
+  // Source, destination and direction in world
+  Vector3f s,d,dir;
+  s = igl::unproject(win_s,model,proj,viewport);
+  d = igl::unproject(win_d,model,proj,viewport);
+  dir = d-s;
+
+  // Shoot ray, collect all hits (could just collect first two)
+  int num_rays_shot;
+  hits.clear();
+  ei.intersectRay(s,dir,hits,num_rays_shot);
+  switch(hits.size())
+  {
+    case 0:
+      break;
+    case 1:
+    {
+      obj = (s + dir*hits[0].t).cast<typename Derivedobj::Scalar>();
+      break;
+    }
+    case 2:
+    default:
+    {
+      obj = 0.5*((s + dir*hits[0].t) + (s + dir*hits[1].t)).cast<typename Derivedobj::Scalar>();
+      break;
+    }
+  }
+  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
 template int igl::unproject_in_mesh<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(int, int, igl::EmbreeIntersector const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&, std::vector<igl::Hit, std::allocator<igl::Hit> >&);
 template int igl::unproject_in_mesh<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(int, int, igl::EmbreeIntersector const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
 #endif
+
+#endif

+ 57 - 5
include/igl/embree/unproject_in_mesh.h

@@ -1,9 +1,9 @@
 // This file is part of libigl, a simple c++ geometry processing library.
-// 
+//
 // Copyright (C) 2013 Alec Jacobson <alecjacobson@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 
+//
+// 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_IN_MESH
 #define IGL_UNPROJECT_IN_MESH
@@ -17,8 +17,10 @@ namespace igl
 {
   // Forward define
   class EmbreeIntersector;
+
+  #ifndef IGL_OPENGL_4
   // Unproject a screen location (using current opengl viewport, projection, and
-  // model view) to a 3D position 
+  // model view) to a 3D position
   //
   // Inputs:
   //    x  x-coordinate of mouse location
@@ -44,6 +46,56 @@ namespace igl
     const igl::EmbreeIntersector & ei,
     Eigen::PlainObjectBase<Derivedobj> & obj,
     std::vector<igl::Hit > & hits);
+  #endif
+
+// 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
+//    model      model matrix
+//    proj       projection matrix
+//    viewport   vieweport vector
+//    ei         EmbreeIntersector containing (V,F)
+// Outputs:
+//    obj        3d unprojected mouse point in mesh
+//    hits       vector of embree hits
+// Returns number of hits
+template <
+  typename Derivedobj>
+IGL_INLINE int unproject_in_mesh(
+  const Eigen::Vector2f& pos,
+  const Eigen::Matrix4f& model,
+  const Eigen::Matrix4f& proj,
+  const Eigen::Vector4f& viewport,
+  const igl::EmbreeIntersector & ei,
+  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"

+ 1 - 1
include/igl/principal_curvature.cpp

@@ -823,7 +823,7 @@ IGL_INLINE void igl::principal_curvature(
     PD1.row(i).normalize();
     PD2.row(i).normalize();
 
-    if (isnan(PD1(i,0)) || isnan(PD1(i,1)) || isnan(PD1(i,2)) || isnan(PD2(i,0)) || isnan(PD2(i,1)) || isnan(PD2(i,2)))
+    if (std::isnan(PD1(i,0)) || std::isnan(PD1(i,1)) || std::isnan(PD1(i,2)) || std::isnan(PD2(i,0)) || std::isnan(PD2(i,1)) || std::isnan(PD2(i,2)))
     {
       PD1.row(i) << 0,0,0;
       PD2.row(i) << 0,0,0;

+ 34 - 4
include/igl/unproject.cpp

@@ -1,13 +1,16 @@
 // This file is part of libigl, a simple c++ geometry processing library.
-// 
+//
 // Copyright (C) 2013 Alec Jacobson <alecjacobson@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 
+//
+// 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.h"
 #ifndef IGL_NO_OPENGL
+#ifndef IGL_OPENGL_4
 
+#include <Eigen/Dense>
+#include <Eigen/LU>
 #include "OpenGL_convenience.h"
 
 IGL_INLINE int igl::unproject(
@@ -54,8 +57,34 @@ IGL_INLINE Eigen::PlainObjectBase<Derivedwin> igl::unproject(
   return obj;
 }
 
+#endif
+#endif
+
+
+Eigen::Vector3f igl::unproject(
+  const Eigen::Vector3f& win,
+  const Eigen::Matrix4f& model,
+  const Eigen::Matrix4f& proj,
+  const Eigen::Vector4f& viewport)
+{
+  Eigen::Matrix4f Inverse = (proj * model).inverse();
+
+  Eigen::Vector4f 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;
+  obj /= obj(3);
+
+  return obj.head(3);
+}
 
 #ifdef IGL_STATIC_LIBRARY
+
+#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> >&);
@@ -64,5 +93,6 @@ template int igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<
 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> >&);
 #endif
+#endif
 
 #endif

+ 24 - 4
include/igl/unproject.h

@@ -1,9 +1,9 @@
 // This file is part of libigl, a simple c++ geometry processing library.
-// 
+//
 // Copyright (C) 2013 Alec Jacobson <alecjacobson@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 
+//
+// 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_H
 #define IGL_UNPROJECT_H
@@ -32,8 +32,28 @@ namespace igl
   template <typename Derivedwin>
   IGL_INLINE Eigen::PlainObjectBase<Derivedwin> unproject(
     const Eigen::PlainObjectBase<Derivedwin> & win);
+
+  // Eigen reimplementation of gluUnproject
+  // Inputs:
+  //   win  screen space x, y, and z coordinates
+  // 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);
 }
 
+
 #ifndef IGL_STATIC_LIBRARY
 #  include "unproject.cpp"
 #endif

+ 13 - 25
include/igl/viewer/Viewer.cpp

@@ -4,6 +4,9 @@
 #  include <windows.h>
 #  undef max
 #  undef min
+#endif
+
+#ifndef __APPLE__
 #  include <GL/glew.h>
 #endif
 
@@ -52,25 +55,6 @@ Eigen::Vector3f project(const Eigen::Vector3f&  obj,
   return tmp.head(3);
 }
 
-Eigen::Vector3f unproject(const Eigen::Vector3f& win,
-                          const Eigen::Matrix4f& model,
-                          const Eigen::Matrix4f& proj,
-                          const Eigen::Vector4f& viewport)
-{
-  Eigen::Matrix4f Inverse = (proj * model).inverse();
-
-  Eigen::Vector4f 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;
-  obj /= obj(3);
-
-  return obj.head(3);
-}
-
 Eigen::Matrix4f lookAt (
                         const Eigen::Vector3f& eye,
                         const Eigen::Vector3f& center,
@@ -178,6 +162,7 @@ Eigen::Matrix4f translate(
 #include <igl/axis_angle_to_quat.h>
 #include <igl/trackball.h>
 #include <igl/snap_to_canonical_view_quat.h>
+#include <igl/unproject.h>
 #include <TwOpenGLCore.h>
 
 // Plugin manager (exported to other compilation units)
@@ -656,6 +641,7 @@ namespace igl
 
     // Default lights settings
     options.light_position << 0.0f, -0.30f, -5.0f;
+    options.lighting_factor = 1.0f; //on
 
     // Default trackball
     options.trackball_angle << 0.0f, 0.0f, 0.0f, 1.0f;
@@ -1075,8 +1061,8 @@ namespace igl
         case TRANSLATE:
         {
           //translation
-          Eigen::Vector3f pos1 = unproject(Eigen::Vector3f(mouse_x, viewport[3] - mouse_y, down_mouse_z), view * model, proj, viewport);
-          Eigen::Vector3f pos0 = unproject(Eigen::Vector3f(down_mouse_x, viewport[3] - down_mouse_y, down_mouse_z), view * model, proj, viewport);
+          Eigen::Vector3f pos1 = igl::unproject(Eigen::Vector3f(mouse_x, viewport[3] - mouse_y, down_mouse_z), view * model, proj, viewport);
+          Eigen::Vector3f pos0 = igl::unproject(Eigen::Vector3f(down_mouse_x, viewport[3] - down_mouse_y, down_mouse_z), view * model, proj, viewport);
 
           Eigen::Vector3f diff = pos1 - pos0;
           options.model_translation = down_translation + Eigen::Vector3f(diff[0],diff[1],diff[2]);
@@ -1703,7 +1689,7 @@ namespace igl
     "dot_prod_specular = max (dot_prod_specular, 0.0);"
     "float specular_factor = pow (dot_prod_specular, specular_exponent);"
     "vec3 Is = Ls * Ksi * specular_factor;"    // specular intensity
-    "vec4 color = vec4(lighting_factor * (Is + Id) + Ia, 1.0);"
+    "vec4 color = vec4(lighting_factor * (Is + Id) + Ia, 1.0) + vec4((1.0-lighting_factor) * Kdi,1.0);"
     "outColor = mix(vec4(1,1,1,1), texture(tex, texcoordi), texture_factor) * color;"
     "if (fixed_color != vec4(0.0)) outColor = fixed_color;"
     "}";
@@ -1847,7 +1833,7 @@ namespace igl
     glUniform1f(specular_exponenti, options.shininess);
     Vector3f rev_light = -1.*options.light_position;
     glUniform3fv(light_position_worldi, 1, rev_light.data());
-    glUniform1f(lighting_factori, 1.0f); // enables lighting
+    glUniform1f(lighting_factori, options.lighting_factor); // enables lighting
     glUniform4f(fixed_colori, 0.0, 0.0, 0.0, 0.0);
 
     if (data.V.rows()>0)
@@ -2096,6 +2082,7 @@ namespace igl
     xmlSerializer->Add(background_color, "background_color");
     xmlSerializer->Add(line_color, "line_color");
     xmlSerializer->Add(light_position, "light_position");
+    xmlSerializer->Add(lighting_factor, "lighting_factor");
     xmlSerializer->Add(trackball_angle, "trackball_angle");
     xmlSerializer->Add(model_zoom, "model_zoom");
     xmlSerializer->Add(model_translation, "model_translation");
@@ -2392,9 +2379,10 @@ namespace igl
     glfwWindowHint(GLFW_SAMPLES, 16);
     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
+    #ifdef __APPLE__
     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
     glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
-
+    #endif
     window = glfwCreateWindow(1280, 800, "IGL Viewer", NULL, NULL);
     if (!window)
     {
@@ -2404,7 +2392,7 @@ namespace igl
 
 	glfwMakeContextCurrent(window);
 
-#ifdef _WIN32
+#ifndef __APPLE__
 	glewExperimental = true;
 	GLenum err = glewInit();
 	if (GLEW_OK != err)

+ 1 - 0
include/igl/viewer/Viewer.h

@@ -55,6 +55,7 @@ namespace igl
 
       // Lighting
       Eigen::Vector3f light_position;
+      float lighting_factor;
 
       // Trackball angle (quaternion)
       Eigen::Vector4f trackball_angle;

+ 2 - 2
tutorial/101_FileIO/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(101_FileIO ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(101_FileIO ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 11 - 0
tutorial/102_DrawMesh/CMakeLists.txt

@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 2.6)
+project(102_DrawMesh)
+
+include("../CMakeLists.shared")
+
+set(SOURCES
+${PROJECT_SOURCE_DIR}/main.cpp
+)
+
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 0 - 0
tutorial/103_DrawMesh/main.cpp → tutorial/102_DrawMesh/main.cpp


+ 0 - 11
tutorial/103_DrawMesh/CMakeLists.txt

@@ -1,11 +0,0 @@
-cmake_minimum_required(VERSION 2.6)
-project(103_DrawMesh)
-
-include("../CMakeLists.shared")
-
-set(SOURCES
-${PROJECT_SOURCE_DIR}/main.cpp
-)
-
-add_executable(103_DrawMesh ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(103_DrawMesh ${SHARED_LIBRARIES})

+ 11 - 0
tutorial/103_Events/CMakeLists.txt

@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 2.6)
+project(103_Events)
+
+include("../CMakeLists.shared")
+
+set(SOURCES
+${PROJECT_SOURCE_DIR}/main.cpp
+)
+
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 0 - 0
tutorial/104_Events/main.cpp → tutorial/103_Events/main.cpp


+ 11 - 0
tutorial/104_Colors/CMakeLists.txt

@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 2.6)
+project(104_Colors)
+
+include("../CMakeLists.shared")
+
+set(SOURCES
+${PROJECT_SOURCE_DIR}/main.cpp
+)
+
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/105_Colors/main.cpp → tutorial/104_Colors/main.cpp

@@ -13,7 +13,7 @@ int main(int argc, char *argv[])
 
   // Plot the mesh
   igl::Viewer viewer;
-  viewer.draw_mesh(V, F);
+  viewer.set_mesh(V, F);
 
 
   // Normalize x coordinate between 0 and 1
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
   }
 
   // Add per-vertex colors
-  viewer.draw_colors(C);
+  viewer.set_colors(C);
 
   // Launch the viewer
   viewer.launch();

+ 0 - 11
tutorial/104_Events/CMakeLists.txt

@@ -1,11 +0,0 @@
-cmake_minimum_required(VERSION 2.6)
-project(104_Events)
-
-include("../CMakeLists.shared")
-
-set(SOURCES
-${PROJECT_SOURCE_DIR}/main.cpp
-)
-
-add_executable(104_Events ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(104_Events ${SHARED_LIBRARIES})

+ 0 - 11
tutorial/105_Colors/CMakeLists.txt

@@ -1,11 +0,0 @@
-cmake_minimum_required(VERSION 2.6)
-project(105_Colors)
-
-include("../CMakeLists.shared")
-
-set(SOURCES
-${PROJECT_SOURCE_DIR}/main.cpp
-)
-
-add_executable(105_Colors ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(105_Colors ${SHARED_LIBRARIES})

+ 11 - 0
tutorial/105_Overlays/CMakeLists.txt

@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 2.6)
+project(105_Overlays)
+
+include("../CMakeLists.shared")
+
+set(SOURCES
+${PROJECT_SOURCE_DIR}/main.cpp
+)
+
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 0 - 0
tutorial/106_Overlays/main.cpp → tutorial/105_Overlays/main.cpp


+ 0 - 11
tutorial/106_Overlays/CMakeLists.txt

@@ -1,11 +0,0 @@
-cmake_minimum_required(VERSION 2.6)
-project(106_Overlays)
-
-include("../CMakeLists.shared")
-
-set(SOURCES
-${PROJECT_SOURCE_DIR}/main.cpp
-)
-
-add_executable(106_Overlays ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(106_Overlays ${SHARED_LIBRARIES})

+ 15 - 0
tutorial/106_Picking/CMakeLists.txt

@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 2.6)
+project(106_Picking)
+
+include("../CMakeLists.shared")
+
+find_package(EMBREE REQUIRED)
+
+include_directories(${EMBREE_INCLUDE_DIRS})
+
+set(SOURCES
+${PROJECT_SOURCE_DIR}/main.cpp
+)
+
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES} ${EMBREE_LIBRARIES})

+ 68 - 0
tutorial/106_Picking/main.cpp

@@ -0,0 +1,68 @@
+#include <igl/readOFF.h>
+#include <igl/viewer/Viewer.h>
+#include <igl/embree/EmbreeIntersector.h>
+#include <igl/embree/unproject_in_mesh.h>
+
+#include <algorithm>
+
+using namespace Eigen;
+using namespace std;
+
+// Mesh
+Eigen::MatrixXd V;
+Eigen::MatrixXi F;
+
+// Per-vertex color
+MatrixXd C;
+
+igl::EmbreeIntersector* ei;
+
+vector<int> picked_vertices;
+
+bool mouse_down(igl::Viewer& viewer, int button, int modifier)
+{
+
+  int vid, fid;
+
+  // Cast a ray in the view direction starting from the mouse position
+  bool hit = unproject_in_mesh(Vector2f(viewer.current_mouse_x,viewer.viewport(3) - viewer.current_mouse_y),
+                                F,
+                                viewer.view * viewer.model,
+                                viewer.proj,
+                                viewer.viewport,
+                                *ei,
+                                fid,
+                                vid);
+
+  // If the ray hits a face, assign a red color to the closest vertex
+  if (hit)
+  {
+    cerr << "Picked face(vertex): " << fid << " (" << vid << ")" << endl;
+    C.row(vid) << 1,0,0;
+    viewer.set_colors(C);
+    return true;
+  }
+
+  return false;
+}
+
+int main(int argc, char *argv[])
+{
+  // Load a mesh in OFF format
+  igl::readOFF("../shared/fertility.off", V, F);
+
+  // Create a BVH for raycasting
+  ei = new igl::EmbreeIntersector();
+  ei->init(V.cast<float>(),F);
+
+  // Initialize the colors to white for all vertices
+  C = MatrixXd::Constant(V.rows(),3,1);
+
+  // Show mesh
+  igl::Viewer viewer;
+  viewer.set_mesh(V, F);
+  viewer.callback_mouse_down = &mouse_down;
+  viewer.set_colors(C);
+  viewer.options.show_lines = false;
+  viewer.launch();
+}

+ 2 - 2
tutorial/201_Normals/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/202_GaussianCurvature/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/203_CurvatureDirections/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 3 - 3
tutorial/203_CurvatureDirections/main.cpp

@@ -28,11 +28,11 @@ int main(int argc, char *argv[])
   // Laplace-Beltrami of position
   HN = -Minv*(L*V);
   // Extract magnitude as mean curvature
-  H = HN.rowwise().norm();
+  VectorXd H = HN.rowwise().norm();
 
   // Compute curvature directions via quadric fitting
   MatrixXd PD1,PD2;
-  VectorXd PV1,PV2,H;
+  VectorXd PV1,PV2;
   igl::principal_curvature(V,F,PD1,PD2,PV1,PV2);
   // mean curvature
   H = 0.5*(PV1+PV2);
@@ -48,7 +48,7 @@ int main(int argc, char *argv[])
 
   // Average edge length for sizing
   const double avg = igl::avg_edge_length(V,F);
-  
+
   // Draw a red segment parallel to the minimal curvature direction
   const RowVector3d red(1,0,0),blue(0,0,1);
   viewer.add_edges(V + PD1*avg, V - PD1*avg, red);

+ 2 - 2
tutorial/204_Gradient/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/205_Laplacian/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/301_Slice/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/302_Sort/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/303_LaplaceEquation/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/304_LinearEqualityConstraints/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/305_QuadraticProgramming/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/501_HarmonicParam/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/502_LSCMParam/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/503_ARAPParam/CMakeLists.txt

@@ -7,5 +7,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/504_NRosyDesign/CMakeLists.txt

@@ -11,5 +11,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES} ${LIBCOMISO_LIBRARY})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES} ${LIBCOMISO_LIBRARY})

+ 2 - 2
tutorial/505_MIQ/CMakeLists.txt

@@ -11,5 +11,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES} ${LIBCOMISO_LIBRARY})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES} ${LIBCOMISO_LIBRARY})

+ 2 - 2
tutorial/506_FrameField/CMakeLists.txt

@@ -11,5 +11,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES} ${LIBCOMISO_LIBRARY})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES} ${LIBCOMISO_LIBRARY})

+ 6 - 2
tutorial/601_Serialization/CMakeLists.txt

@@ -3,9 +3,13 @@ project(601_Serialization)
 
 include("../CMakeLists.shared")
 
+find_package(TINYXML2 REQUIRED)
+
+include_directories( ${TINYXML2_INCLUDE_DIR})
+
 set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES} ${TINYXML2_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES} ${TINYXML2_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/602_Matlab/CMakeLists.txt

@@ -14,5 +14,5 @@ if(APPLE)
   set(CMAKE_EXE_LINKER_FLAGS "-rpath ${MATLAB_INCLUDE_DIR}/../../bin/maci64"})
 endif (APPLE) #APPLE
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES} ${MATLAB_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES} ${MATLAB_LIBRARIES})

+ 2 - 2
tutorial/604_Triangle/CMakeLists.txt

@@ -10,5 +10,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES} ${TRIANGLE_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES} ${TRIANGLE_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 2 - 2
tutorial/604_Triangle/main.cpp

@@ -1,5 +1,5 @@
 #include <igl/viewer/Viewer.h>
-#include <igl/triangle/triangle_wrapper.h>
+#include <igl/triangle/triangulate.h>
 // Input polygon
 Eigen::MatrixXd V;
 Eigen::MatrixXi E;
@@ -28,7 +28,7 @@ int main(int argc, char *argv[])
   H << 0,0;
 
   // Triangulate the interior
-  igl::triangle_wrapper(V,E,H,V2,F2,"a0.005q");
+  igl::triangulate(V,E,H,V2,F2,"a0.005q");
 
   // Plot the generated mesh
   igl::Viewer viewer;

+ 2 - 2
tutorial/605_Tetgen/CMakeLists.txt

@@ -10,5 +10,5 @@ set(SOURCES
 ${PROJECT_SOURCE_DIR}/main.cpp
 )
 
-add_executable(${CMAKE_PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES} ${TETGEN_SOURCES})
-target_link_libraries(${CMAKE_PROJECT_NAME} ${SHARED_LIBRARIES})
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES} ${TETGEN_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES})

+ 15 - 0
tutorial/606_AmbientOcclusion/CMakeLists.txt

@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 2.6)
+project(606_AmbientOcclusion)
+
+include("../CMakeLists.shared")
+
+find_package(EMBREE REQUIRED)
+
+include_directories(${EMBREE_INCLUDE_DIRS})
+
+set(SOURCES
+${PROJECT_SOURCE_DIR}/main.cpp
+)
+
+add_executable(${PROJECT_NAME} ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME} ${SHARED_LIBRARIES} ${EMBREE_LIBRARIES})

+ 78 - 0
tutorial/606_AmbientOcclusion/main.cpp

@@ -0,0 +1,78 @@
+#include <igl/readOFF.h>
+#include <igl/viewer/Viewer.h>
+#include <igl/per_vertex_normals.h>
+#include <igl/avg_edge_length.h>
+#include <igl/embree/ambient_occlusion.h>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+// Mesh
+Eigen::MatrixXd V;
+Eigen::MatrixXi F;
+
+VectorXd AO;
+
+  // It allows to change the degree of the field when a number is pressed
+bool key_down(igl::Viewer& viewer, unsigned char key, int modifier)
+{
+  const RowVector3d color(0.9,0.85,0.9);
+  switch(key)
+  {
+    case '1':
+      // Show the mesh without the ambient occlusion factor
+      viewer.set_colors(color);
+      break;
+    case '2':
+    {
+      // Show the mesh with the ambient occlusion factor
+      MatrixXd C = color.replicate(V.rows(),1);
+      for (unsigned i=0; i<C.rows();++i)
+        C.row(i) *= AO(i);//std::min<double>(AO(i)+0.2,1);
+      viewer.set_colors(C);
+      break;
+    }
+    case '.':
+      viewer.options.lighting_factor += 0.1;
+      break;
+    case ',':
+      viewer.options.lighting_factor -= 0.1;
+      break;
+    default: break;
+  }
+  viewer.options.lighting_factor = 
+    std::min(std::max(viewer.options.lighting_factor,0.f),1.f);
+
+  return false;
+}
+
+int main(int argc, char *argv[])
+{
+  using namespace std;
+  using namespace Eigen;
+  cout<<
+    "Press 1 to turn off Ambient Occlusion"<<endl<<
+    "Press 2 to turn on Ambient Occlusion"<<endl<<
+    "Press . to turn up lighting"<<endl<<
+    "Press , to turn down lighting"<<endl;
+
+  // Load a mesh in OFF format
+  igl::readOFF("../shared/fertility.off", V, F);
+
+  MatrixXd N;
+  igl::per_vertex_normals(V,F,N);
+
+  // Compute ambient occlusion factor using embree
+  igl::ambient_occlusion(V,F,V,N,500,AO);
+  AO = 1.0 - AO.array();
+
+  // Show mesh
+  igl::Viewer viewer;
+  viewer.set_mesh(V, F);
+  viewer.callback_key_down = &key_down;
+  key_down(viewer,'2',0);
+  viewer.options.show_lines = false;
+  viewer.options.lighting_factor = 0.0f;
+  viewer.launch();
+}

+ 15 - 8
tutorial/CMakeLists.shared

@@ -11,28 +11,31 @@ find_package(ANTTWEAKBAR REQUIRED)
 find_package(OpenGL REQUIRED)
 find_package(EIGEN REQUIRED)
 find_package(LIBIGL REQUIRED)
-find_package(TINYXML2 REQUIRED)
 find_package(GLFW REQUIRED)
 
-if(WIN32)
+if(NOT APPLE)
 	find_package(GLEW REQUIRED)
-endif(WIN32)
+endif(NOT APPLE)
 
 if(APPLE)
 	set(CMAKE_CXX_LINK_FLAGS "-framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo")
 endif (APPLE) #APPLE
 
+if(UNIX AND NOT APPLE)
+  set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -lGL -lGLU -lrt -lX11 -lXxf86vm -lXrandr -lpthread -lXi")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
+endif(UNIX AND NOT APPLE)
+
 include_directories( ${ANT_TWEAK_BAR_INCLUDE_DIR} )
 
 # message(FATAL_ERROR ${ANT_TWEAK_BAR_INCLUDE_DIR})
 
-if(WIN32)
+if(NOT APPLE)
 	include_directories( ${GLEW_INCLUDE_DIR} )
-endif(WIN32)
+endif(NOT APPLE)
 
 include_directories( ${EIGEN_INCLUDE_DIR})
 include_directories( ${LIBIGL_INCLUDE_DIR})
-include_directories( ${TINYXML2_INCLUDE_DIR})
 include_directories( ${GLFW_INCLUDE_DIR})
 include_directories(
 	/usr/local/include
@@ -50,6 +53,10 @@ link_directories(
 
 #set(CMAKE_CXX_FLAGS -Wall -W -pedantic -std=c99)
 
+# Disable deprecated opengl code from libigl
+add_definitions(-DIGL_OPENGL_4)
+
+
 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
 	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register")
@@ -57,9 +64,9 @@ endif()
 
 set(SHARED_SOURCES ${LIBIGL_SOURCES})
 
-if(WIN32)
+if(NOT APPLE)
 	set(SHARED_SOURCES ${SHARED_SOURCES} ${GLEW_SOURCES})
-endif(WIN32)
+endif(NOT APPLE)
 
 # message(FATAL_ERROR ${LIBIGL_SOURCES})
 

+ 39 - 0
tutorial/CMakeLists.txt

@@ -0,0 +1,39 @@
+cmake_minimum_required(VERSION 2.6)
+project(libigl_tutorials)
+
+# Chapter 1
+add_subdirectory("101_FileIO")
+add_subdirectory("102_DrawMesh")
+add_subdirectory("103_Events")
+add_subdirectory("104_Colors")
+add_subdirectory("105_Overlays")
+add_subdirectory("106_Picking")
+
+# Chapter 2
+add_subdirectory("201_Normals")
+add_subdirectory("202_GaussianCurvature")
+add_subdirectory("203_CurvatureDirections")
+add_subdirectory("204_Gradient")
+add_subdirectory("205_Laplacian")
+
+# Chapter 3
+add_subdirectory("301_Slice")
+add_subdirectory("302_Sort")
+add_subdirectory("303_LaplaceEquation")
+add_subdirectory("304_LinearEqualityConstraints")
+add_subdirectory("305_QuadraticProgramming")
+
+# Chapter 5
+add_subdirectory("501_HarmonicParam")
+add_subdirectory("502_LSCMParam")
+add_subdirectory("503_ARAPParam")
+add_subdirectory("504_NRosyDesign")
+add_subdirectory("505_MIQ")
+add_subdirectory("506_FrameField")
+
+# Chapter 6
+add_subdirectory("601_Serialization")
+add_subdirectory("602_Matlab")
+add_subdirectory("604_Triangle")
+add_subdirectory("605_Tetgen")
+add_subdirectory("606_AmbientOcclusion")

+ 43 - 0
tutorial/cmake/FindEMBREE.cmake

@@ -0,0 +1,43 @@
+#
+# Try to find EMBREE
+# Once done this will define
+#
+# EMBREE_FOUND           - system has EMBREE
+# EMBREE_INCLUDE_DIRS    - the EMBREE include directories
+# EMBREE_LIBRARIES       - Link these to use EMBREE
+#
+
+FIND_PATH(EMBREE_INCLUDE_DIR embree/include/embree.h
+	  PATHS
+		${PROJECT_SOURCE_DIR}/../../external/embree
+		NO_DEFAULT_PATH
+    )
+
+SET(SEARCH_PATHS "${EMBREE_INCLUDE_DIR}" "${EMBREE_INCLUDE_DIR}/build")
+
+FIND_LIBRARY(EMBREE_CORE_LIBRARY  NAMES libembree.a PATHS ${SEARCH_PATHS})
+FIND_LIBRARY(EMBREE_CORE_LIBRARY2 NAMES libdevice.a PATHS ${SEARCH_PATHS})
+FIND_LIBRARY(EMBREE_CORE_LIBRARY3 NAMES libimage.a PATHS ${SEARCH_PATHS})
+FIND_LIBRARY(EMBREE_CORE_LIBRARY4 NAMES liblexers.a PATHS ${SEARCH_PATHS})
+FIND_LIBRARY(EMBREE_CORE_LIBRARY5 NAMES libloaders.a PATHS ${SEARCH_PATHS})
+FIND_LIBRARY(EMBREE_CORE_LIBRARY6 NAMES libsys.a PATHS ${SEARCH_PATHS})
+
+if(EMBREE_CORE_LIBRARY AND EMBREE_INCLUDE_DIR)
+set(EMBREE_FOUND TRUE)
+endif(EMBREE_CORE_LIBRARY AND EMBREE_INCLUDE_DIR)
+
+IF (EMBREE_FOUND)
+   message(STATUS "Found EMBREE: ${EMBREE_INCLUDE_DIR}")
+
+   SET(EMBREE_LIBRARIES
+   "${EMBREE_CORE_LIBRARY}"
+   "${EMBREE_CORE_LIBRARY2}"
+   "${EMBREE_CORE_LIBRARY3}"
+   "${EMBREE_CORE_LIBRARY4}"
+   "${EMBREE_CORE_LIBRARY5}"
+   "${EMBREE_CORE_LIBRARY6}"
+   )
+   SET(EMBREE_INCLUDE_DIRS ${EMBREE_INCLUDE_DIR} ${EMBREE_INCLUDE_DIR}/embree)
+ELSE (EMBREE_FOUND)
+    message(FATAL_ERROR "could NOT find EMBREE")
+ENDIF (EMBREE_FOUND)

+ 12 - 3
tutorial/cmake/FindLIBCOMISO.cmake

@@ -12,12 +12,19 @@ FIND_PATH(LIBCOMISO_INCLUDE_DIR CoMISo/Solver/ConstrainedSolver.hh
    $ENV{LIBCOMISO_ROOT}/include
    $ENV{LIBCOMISO_DIR}/include
    $ENV{LIBCOMISO_DIR}/inc
+   ${PROJECT_SOURCE_DIR}/../
+   ${PROJECT_SOURCE_DIR}/../../
+   ${PROJECT_SOURCE_DIR}/../../../
    ${PROJECT_SOURCE_DIR}/../CoMISo/
    ${PROJECT_SOURCE_DIR}/../CoMISo/include
+   ${PROJECT_SOURCE_DIR}/../../CoMISo/
+   ${PROJECT_SOURCE_DIR}/../../CoMISo/include
    /Users/daniele/Dropbox/igl/MIQ/src
    /Users/olkido/Documents/igl/MIQ/src
 )
 
+#message(FATAL_ERROR "${LIBCOMISO_INCLUDE_DIR}")
+
 FIND_LIBRARY(LIBCOMISO_LIBRARY NAMES CoMISo
   PATHS
     /usr/local
@@ -25,9 +32,11 @@ FIND_LIBRARY(LIBCOMISO_LIBRARY NAMES CoMISo
     /usr
     /
     ${PROJECT_SOURCE_DIR}/../CoMISo/
-    ${PROJECT_SOURCE_DIR}/../CoMISo/build
-    /Users/daniele/Dropbox/igl/MIQ/src/CoMISo/build
-    /Users/olkido/Documents/igl/MIQ/src/CoMISo/build
+    ${PROJECT_SOURCE_DIR}/../CoMISo/build/Build/lib/CoMISo/
+    ${PROJECT_SOURCE_DIR}/../../CoMISo/
+    ${PROJECT_SOURCE_DIR}/../../CoMISo/build/Build/lib/CoMISo/
+    ${PROJECT_SOURCE_DIR}/../../../CoMISo/
+    ${PROJECT_SOURCE_DIR}/../../../CoMISo/build/Build/lib/CoMISo/
 )
 
 if(LIBCOMISO_INCLUDE_DIR AND LIBCOMISO_LIBRARY)

+ 9 - 0
tutorial/cmake/FindLIBIGL.cmake

@@ -43,6 +43,14 @@ if(LIBIGL_USE_STATIC_LIBRARY)
     set(LIBIGL_FOUND FALSE)
   endif(NOT LIBIGL_LIBRARY)
   set(LIBIGL_LIBRARIES ${LIBIGL_LIBRARIES}  ${LIBIGL_LIBRARY})
+
+  FIND_LIBRARY( LIBIGLEMBREE_LIBRARY NAMES iglembree PATHS ${LIBIGL_LIB_DIRS})
+  if(NOT LIBIGLEMBREE_LIBRARY)
+    set(LIBIGL_FOUND FALSE)
+  endif(NOT LIBIGLEMBREE_LIBRARY)
+  set(LIBIGL_LIBRARIES ${LIBIGL_LIBRARIES}  ${LIBIGLEMBREE_LIBRARY})
+  find_package(Embree REQUIRED)
+
   FIND_LIBRARY( LIBIGLMATLAB_LIBRARY NAMES iglmatlab PATHS ${LIBIGL_LIB_DIRS})
   if(NOT LIBIGLMATLAB_LIBRARY)
     set(LIBIGL_FOUND FALSE)
@@ -55,6 +63,7 @@ if(LIBIGL_USE_STATIC_LIBRARY)
   else(MATLAB_FOUND)
     set(LIBIGL_FOUND FALSE)
   endif(MATLAB_FOUND)
+
   FIND_LIBRARY( LIBIGLSVD3X3_LIBRARY NAMES iglsvd3x3 PATHS ${LIBIGL_LIB_DIRS})
   if(NOT LIBIGLSVD3X3_LIBRARY)
     set(LIBIGL_FOUND FALSE)

+ 29 - 0
tutorial/compile_linux.sh

@@ -0,0 +1,29 @@
+sudo apt-get install git
+sudo apt-get install build-essential
+sudo apt-get install libeigen3-dev
+sudo apt-get install cmake
+sudo apt-get install libx11-dev
+sudo apt-get install mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev
+sudo apt-get install libxrandr-dev
+sudo apt-get install libxi-dev
+sudo apt-get install freeglut3-dev
+sudo apt-get install libxmu-dev
+sudo apt-get install libblas-dev libsuitesparse-dev
+
+cd ../external/AntTweakBar/src/
+rm ../lib/*.a
+make
+
+cd ../../glfw/
+cmake -DCMAKE_BUILD_TYPE=Release .
+rm src/*.a
+make
+
+cd ../embree/
+rm -fr build
+mkdir build
+cd build
+cmake -DCMAKE_BUILD_TYPE=Release ../
+make
+
+cd ../../../tutorial

+ 8 - 1
tutorial/compile_macosx.sh

@@ -7,4 +7,11 @@ cmake -DCMAKE_BUILD_TYPE=Release .
 rm src/*.a
 make
 
-cd ../../tutorial
+cd ../embree/
+rm -fr build
+mkdir build
+cd build
+cmake -DCMAKE_BUILD_TYPE=Release ../
+make
+
+cd ../../../tutorial