Browse Source

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

Former-commit-id: 4373f9c2dfa02dea7e90e1401c096ea58d07b8e9
Alec Jacobson 10 years ago
parent
commit
da1cb98d95

+ 31 - 3
examples/quicklook-mesh/src/render_to_buffer.cpp

@@ -280,7 +280,24 @@ void display()
       glMaterialfv(GL_BACK, GL_SPECULAR, SILVER_SPECULAR);
       glMaterialf (GL_BACK, GL_SHININESS, 128);
     //}
-    draw_mesh(V,F,N);
+    if(F.rows() == 0)
+    {
+      glPointSize(1.+ 20./log10(V.rows()));
+      const bool has_normals = N.rows() == V.rows();
+      glBegin(GL_POINTS);
+      for(int v = 0;v<V.rows();v++)
+      {
+        if(has_normals)
+        {
+          glNormal3d(N(v,0),N(v,1),N(v,2));
+        }
+        glVertex3d(V(v,0),V(v,1),V(v,2));
+      }
+      glEnd();
+    }else
+    {
+      draw_mesh(V,F,N);
+    }
     //if(invert)
     //{
     //  glFrontFace(GL_CCW);
@@ -355,6 +372,7 @@ bool render_to_buffer(
     // Convert extension to lower case
     if(!igl::readOBJ(filename,vV,vTC,vN,vF,vFTC,vFN))
     {
+      cerr<<"readOBJ failed."<<endl;
       red(width,height,buffer);
       return false;
     }
@@ -363,6 +381,7 @@ bool render_to_buffer(
     // Convert extension to lower case
     if(!igl::readOFF(filename,vV,vF,vN))
     {
+      cerr<<"readOFF failed."<<endl;
       red(width,height,buffer);
       return false;
     }
@@ -408,16 +427,25 @@ bool render_to_buffer(
   {
     if(!list_to_matrix(vV,V))
     {
+      cerr<<"list_to_matrix failed."<<endl;
       red(width,height,buffer);
       return false;
     }
+    if(!list_to_matrix(vN,N))
+    {
+      // silently continue
+      N.resize(0,0);
+    }
     polygon_mesh_to_triangle_mesh(vF,F);
   }
   cout<<"IO: "<<(get_seconds()-ts)<<"s"<<endl;
   ts = get_seconds();
 
-  // Computer already normalized per triangle normals
-  per_face_normals(V,F,N);
+  // Compute already normalized per triangle normals
+  if(N.rows() != V.rows() && N.rows() != F.rows())
+  {
+    per_face_normals(V,F,N);
+  }
   //Vmean = 0.5*(V.colwise().maxCoeff()+V.colwise().minCoeff());
   Vmax = V.colwise().maxCoeff();
   Vmin = V.colwise().minCoeff();

+ 1 - 0
include/igl/OpenGL_convenience.h

@@ -18,6 +18,7 @@
 #if __APPLE__
 #  include <OpenGL/gl.h>
 #  include <OpenGL/glu.h>
+#  include <OpenGL/glext.h>
 #elif defined(_WIN32)
 #    define NOMINMAX
 #    include <Windows.h>

+ 6 - 3
include/igl/readOFF.cpp

@@ -16,6 +16,7 @@ IGL_INLINE bool igl::readOFF(
   std::vector<std::vector<Index > > & F,
   std::vector<std::vector<Scalar > > & N)
 {
+  using namespace std;
   FILE * off_file = fopen(off_file_name.c_str(),"r");                                       
   if(NULL==off_file)
   {
@@ -30,13 +31,15 @@ IGL_INLINE bool igl::readOFF(
   const std::string OFF("OFF");
   const std::string NOFF("NOFF");
   if(fscanf(off_file,"%s\n",header)!=1
-     || !(OFF == header || NOFF == header))
+     || !(
+       string(header).compare(0, OFF.length(), OFF)==0 || 
+       string(header).compare(0,NOFF.length(),NOFF)==0))
   {
     printf("Error: %s's first line should be OFF or NOFF not %s...",off_file_name.c_str(),header);
     fclose(off_file);
     return false; 
   }
-  bool has_normals = NOFF==header;
+  bool has_normals = string(header).compare(0,NOFF.length(),NOFF)==0;
   // Second line is #vertices #faces #edges
   int number_of_vertices;
   int number_of_faces;
@@ -80,7 +83,7 @@ IGL_INLINE bool igl::readOFF(
       }
       i++;
     }else if(
-             fscanf(off_file,"%[#]",&tic_tac_toe)==1)
+        fscanf(off_file,"%[#]",&tic_tac_toe)==1)
     {
       char comment[1000];
       fscanf(off_file,"%[^\n]",comment);

+ 0 - 106
include/igl/slice.cpp

@@ -209,90 +209,6 @@ IGL_INLINE void igl::slice(
   }
 }
 
-template <typename DerivedX>
-IGL_INLINE void igl::slice_mask(
-  const Eigen::PlainObjectBase<DerivedX> & X,
-  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-  const Eigen::Array<bool,Eigen::Dynamic,1> & C,
-  Eigen::PlainObjectBase<DerivedX> & Y)
-{
-  int xm = X.rows();
-  int xn = X.cols();
-  int ym = R.count();
-  int yn = C.count();
-  assert(R.size() == X.rows() && "R.size() should match X.rows()");
-  assert(C.size() == X.cols() && "C.size() should match X.cols()");
-  Y.resize(ym,yn);
-  {
-    int yi = 0;
-    for(int i = 0;i<xm;i++)
-    {
-      if(R(i))
-      {
-        int yj = 0;
-        for(int j = 0;j<xn;j++)
-        {
-          if(C(j))
-          {
-            Y(yi,yj) = X(i,j);
-            yj++;
-          }
-        }
-        yi++;
-      }
-    }
-  }
-}
-
-template <typename DerivedX>
-IGL_INLINE void igl::slice_mask(
-  const Eigen::PlainObjectBase<DerivedX> & X,
-  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-  const int dim,
-  Eigen::PlainObjectBase<DerivedX> & Y)
-{
-  switch(dim)
-  {
-    case 1:
-    {
-      const int ym = R.count();
-      Y.resize(ym,X.cols());
-      assert(X.rows() == R.size() && "X.rows() should match R.size()");
-      {
-        int yi = 0;
-        for(int i = 0;i<X.rows();i++)
-        {
-          if(R(i))
-          {
-            Y.row(yi++) = X.row(i);
-          }
-        }
-      }
-      return;
-    }
-    case 2:
-    {
-      const auto & C = R;
-      const int yn = C.count();
-      Y.resize(X.rows(),yn);
-      assert(X.cols() == R.size() && "X.cols() should match R.size()");
-      {
-        int yj = 0;
-        for(int j = 0;j<X.cols();j++)
-        {
-          if(C(j))
-          {
-            Y.col(yj++) = X.col(j);
-          }
-        }
-      }
-      return;
-    }
-    default:
-      assert(false && "Unsupported dimension");
-      return;
-  }
-}
 
 template <typename DerivedX>
 IGL_INLINE void igl::slice(
@@ -328,28 +244,6 @@ IGL_INLINE Eigen::PlainObjectBase<DerivedX> igl::slice(
   return Y;
 }
 
-template <typename DerivedX>
-IGL_INLINE Eigen::PlainObjectBase<DerivedX> igl::slice_mask(
-  const Eigen::PlainObjectBase<DerivedX> & X,
-  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-  const Eigen::Array<bool,Eigen::Dynamic,1> & C)
-{
-  Eigen::PlainObjectBase<DerivedX> Y;
-  igl::slice_mask(X,R,C,Y);
-  return Y;
-}
-
-template <typename DerivedX>
-IGL_INLINE Eigen::PlainObjectBase<DerivedX> igl::slice_mask(
-  const Eigen::PlainObjectBase<DerivedX>& X,
-  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-  const int dim)
-{
-  Eigen::PlainObjectBase<DerivedX> Y;
-  igl::slice_mask(X,R,dim,Y);
-  return Y;
-}
-
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template specialization
 // generated by autoexplicit.sh

+ 5 - 25
include/igl/slice.h

@@ -9,12 +9,11 @@
 #define IGL_SLICE_H
 #include "igl_inline.h"
 
-#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
 #include <Eigen/Sparse>
-
 namespace igl
 {
-  // Act like the matlab X(row_indices,col_indices) operator
+  // Act like the matlab X(row_indices,col_indices) operator, where
+  // row_indices, col_indices are non-negative integer indices.
   // 
   // Inputs:
   //   X  m by n matrix
@@ -22,6 +21,8 @@ namespace igl
   //   C  list of column indices
   // Output:
   //   Y  #R by #C matrix
+  //
+  // See also: slice_mask
   template <typename T>
   IGL_INLINE void slice(
     const Eigen::SparseMatrix<T>& X,
@@ -46,18 +47,6 @@ namespace igl
     const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
     const Eigen::Matrix<int,Eigen::Dynamic,1> & C,
     Eigen::PlainObjectBase<DerivedX> & Y);
-  template <typename DerivedX>
-  IGL_INLINE void slice_mask(
-    const Eigen::PlainObjectBase<DerivedX> & X,
-    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-    const Eigen::Array<bool,Eigen::Dynamic,1> & C,
-    Eigen::PlainObjectBase<DerivedX> & Y);
-  template <typename DerivedX>
-  IGL_INLINE void slice_mask(
-    const Eigen::PlainObjectBase<DerivedX> & X,
-    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-    const int dim,
-    Eigen::PlainObjectBase<DerivedX> & Y);
 
   template <typename DerivedX>
   IGL_INLINE void slice(
@@ -74,16 +63,7 @@ namespace igl
     const Eigen::PlainObjectBase<DerivedX>& X,
     const Eigen::Matrix<int,Eigen::Dynamic,1> & R,
     const int dim);
-  template <typename DerivedX>
-  IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice_mask(
-    const Eigen::PlainObjectBase<DerivedX> & X,
-    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-    const Eigen::Array<bool,Eigen::Dynamic,1> & C);
-  template <typename DerivedX>
-  IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice_mask(
-    const Eigen::PlainObjectBase<DerivedX> & X,
-    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
-    const int dim);
+
 }
 
 #ifndef IGL_STATIC_LIBRARY

+ 113 - 0
include/igl/slice_mask.cpp

@@ -0,0 +1,113 @@
+#include "slice_mask.h"
+#include <cassert>
+
+template <typename DerivedX>
+IGL_INLINE void igl::slice_mask(
+  const Eigen::PlainObjectBase<DerivedX> & X,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & C,
+  Eigen::PlainObjectBase<DerivedX> & Y)
+{
+  int xm = X.rows();
+  int xn = X.cols();
+  int ym = R.count();
+  int yn = C.count();
+  assert(R.size() == X.rows() && "R.size() should match X.rows()");
+  assert(C.size() == X.cols() && "C.size() should match X.cols()");
+  Y.resize(ym,yn);
+  {
+    int yi = 0;
+    for(int i = 0;i<xm;i++)
+    {
+      if(R(i))
+      {
+        int yj = 0;
+        for(int j = 0;j<xn;j++)
+        {
+          if(C(j))
+          {
+            Y(yi,yj) = X(i,j);
+            yj++;
+          }
+        }
+        yi++;
+      }
+    }
+  }
+}
+
+template <typename DerivedX>
+IGL_INLINE void igl::slice_mask(
+  const Eigen::PlainObjectBase<DerivedX> & X,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+  const int dim,
+  Eigen::PlainObjectBase<DerivedX> & Y)
+{
+  switch(dim)
+  {
+    case 1:
+    {
+      const int ym = R.count();
+      Y.resize(ym,X.cols());
+      assert(X.rows() == R.size() && "X.rows() should match R.size()");
+      {
+        int yi = 0;
+        for(int i = 0;i<X.rows();i++)
+        {
+          if(R(i))
+          {
+            Y.row(yi++) = X.row(i);
+          }
+        }
+      }
+      return;
+    }
+    case 2:
+    {
+      const auto & C = R;
+      const int yn = C.count();
+      Y.resize(X.rows(),yn);
+      assert(X.cols() == R.size() && "X.cols() should match R.size()");
+      {
+        int yj = 0;
+        for(int j = 0;j<X.cols();j++)
+        {
+          if(C(j))
+          {
+            Y.col(yj++) = X.col(j);
+          }
+        }
+      }
+      return;
+    }
+    default:
+      assert(false && "Unsupported dimension");
+      return;
+  }
+}
+
+template <typename DerivedX>
+IGL_INLINE Eigen::PlainObjectBase<DerivedX> igl::slice_mask(
+  const Eigen::PlainObjectBase<DerivedX> & X,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & C)
+{
+  Eigen::PlainObjectBase<DerivedX> Y;
+  igl::slice_mask(X,R,C,Y);
+  return Y;
+}
+
+template <typename DerivedX>
+IGL_INLINE Eigen::PlainObjectBase<DerivedX> igl::slice_mask(
+  const Eigen::PlainObjectBase<DerivedX>& X,
+  const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+  const int dim)
+{
+  Eigen::PlainObjectBase<DerivedX> Y;
+  igl::slice_mask(X,R,dim,Y);
+  return Y;
+}
+
+#ifdef IGL_STATIC_LIBRARY
+template void igl::slice_mask<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::Array<bool, -1, 1, 0, -1, 1> const&, int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
+#endif

+ 57 - 0
include/igl/slice_mask.h

@@ -0,0 +1,57 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2015 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 
+// obtain one at http://mozilla.org/MPL/2.0/.
+#ifndef IGL_SLICE_MASK_H
+#define IGL_SLICE_MASK_H
+#include "igl_inline.h"
+
+#include <Eigen/Sparse>
+namespace igl
+{
+  // Act like the matlab X(row_mask,col_mask) operator, where
+  // row_mask, col_mask are non-negative integer indices.
+  // 
+  // Inputs:
+  //   X  m by n matrix
+  //   R  m list of row bools
+  //   C  n list of column bools
+  // Output:
+  //   Y  #trues-in-R by #trues-in-C matrix
+  //
+  // See also: slice_mask
+  
+  template <typename DerivedX>
+  IGL_INLINE void slice_mask(
+    const Eigen::PlainObjectBase<DerivedX> & X,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & C,
+    Eigen::PlainObjectBase<DerivedX> & Y);
+  template <typename DerivedX>
+  IGL_INLINE void slice_mask(
+    const Eigen::PlainObjectBase<DerivedX> & X,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+    const int dim,
+    Eigen::PlainObjectBase<DerivedX> & Y);
+
+  template <typename DerivedX>
+  IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice_mask(
+    const Eigen::PlainObjectBase<DerivedX> & X,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & C);
+  template <typename DerivedX>
+  IGL_INLINE Eigen::PlainObjectBase<DerivedX> slice_mask(
+    const Eigen::PlainObjectBase<DerivedX> & X,
+    const Eigen::Array<bool,Eigen::Dynamic,1> & R,
+    const int dim);
+}
+
+
+#ifndef IGL_STATIC_LIBRARY
+#  include "slice_mask.cpp"
+#endif
+
+#endif

+ 3 - 0
include/igl/upsample.h

@@ -30,6 +30,9 @@ namespace igl
   //
   // NOTE: V should not be the same as NV,
   // NOTE: F should not be the same as NF, use other proto
+  //
+  // Known issues:
+  //   - assumes (V,F) is edge-manifold.
   template <
     typename DerivedV, 
     typename DerivedF,

+ 1 - 1
include/igl/viewer/OpenGL_shader.cpp

@@ -33,7 +33,7 @@ IGL_INLINE bool igl::OpenGL_shader::init_from_files(
   const std::string &geometry_shader_filename,
   int geometry_shader_max_vertices)
 {
-  auto file_to_string = [](const std::string &filename)
+  auto file_to_string = [](const std::string &filename)->std::string
   {
     std::ifstream t(filename);
     return std::string((std::istreambuf_iterator<char>(t)),