Browse Source

fixed some template issues and strict warnings, gl type to string, type to size, matlab to eigen html doc

Former-commit-id: 48c593f5a1240b3e7a08769143ebfeb1d98ead18
jalec 13 years ago
parent
commit
206e6bc0eb

+ 1 - 1
cocoa_key_to_anttweakbar_key.h

@@ -75,7 +75,7 @@ int igl::cocoa_key_to_anttweakbar_key(int key)
       return TW_KEY_F14;
     case 63250:
       return TW_KEY_F15;
-    otherwise:
+    default:
       break;
   }
   return key;

+ 12 - 8
create_vector_vbo.h

@@ -15,13 +15,16 @@
 namespace igl
 {
 
+  // Templates:
+  //   T  should be a eigen matrix primitive type like int or double
   // Inputs:
-  //   V  #V by 3 eigen Matrix of vertex 3D positions
+  //   V  m by n eigen Matrix of type T values
   // Outputs:
   //   V_vbo_id  buffer id for vectors
   //
+  template <typename T>
   void create_vector_vbo(
-    const Eigen::MatrixXd & V,
+    const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & V,
     GLuint & V_vbo_id);
 }
 
@@ -29,12 +32,13 @@ namespace igl
 #include <cassert>
 
 // http://www.songho.ca/opengl/gl_vbo.html#create
+template <typename T>
 void igl::create_vector_vbo(
-  const Eigen::MatrixXd & V,
+  const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> & V,
   GLuint & V_vbo_id)
 {
-  // Expects that input is list of 3D vectors along rows
-  assert(V.cols() == 3);
+  //// Expects that input is list of 3D vectors along rows
+  //assert(V.cols() == 3);
 
   // Generate Buffers
   glGenBuffers(1,&V_vbo_id);
@@ -47,17 +51,17 @@ void igl::create_vector_vbo(
   {
     glBufferData(
       GL_ARRAY_BUFFER,
-      sizeof(double)*V.size(),
+      sizeof(T)*V.size(),
       V.data(),
       GL_STATIC_DRAW);
   }else
   {
     // Create temporary copy of transpose
-    Eigen::MatrixXd VT = V.transpose();
+    Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic> VT = V.transpose();
     // If its column major then we need to temporarily store a transpose
     glBufferData(
       GL_ARRAY_BUFFER,
-      sizeof(double)*V.size(),
+      sizeof(T)*V.size(),
       VT.data(),
       GL_STATIC_DRAW);
   }

+ 42 - 0
gl_type_size.h

@@ -0,0 +1,42 @@
+#ifndef IGL_GL_TYPE_SIZE
+#define IGL_GL_TYPE_SIZE
+
+#if __APPLE__
+#  include <OpenGL/gl.h>
+#else
+#  include <GL/gl.h>
+#endif
+
+namespace igl
+{
+  // Return the number of bytes for a given OpenGL type
+  // Inputs:
+  //   type  enum value of opengl type
+  // Returns size in bytes of type
+  inline int gl_type_size(GLenum type);
+}
+
+//Implementation
+inline int igl::gl_type_size(GLenum type)
+{
+  switch(type)
+  {
+    case GL_DOUBLE:
+      return 8;
+      break;
+    case GL_FLOAT:
+      return 4;
+      break;
+    case GL_INT:
+      return 4;
+      break;
+    default:
+      // should handle all other GL_[types]
+      assert(false);
+      break;
+  }
+  return -1;
+}
+
+#endif 
+

+ 83 - 0
matlab-to-eigen.html

@@ -0,0 +1,83 @@
+<html>
+  <head>
+    <title>MATLAB to Eigen</title>
+    <style type="text/css">
+table
+{
+  border-spacing: 0px;
+}
+tr.header th
+{
+  border-bottom: 1px solid; 
+  background-color: #ffb;
+  padding-left: 10px;
+  padding-right: 20px;
+}
+tr.d0 td 
+{
+  background-color: #EEE; 
+  color: black;
+  padding-left: 10px;
+  padding-right: 20px;
+  min-width: 200px;
+}
+tr.d1 td
+{
+  background-color: #bcf; 
+  color: black;
+  padding-left: 10px;
+  padding-right: 20px;
+  min-width: 200px;
+}
+    </style>
+  </head>
+  <body>
+    <table>
+      <tr class="header">
+        <th>MATLAB</th>
+        <th>Eigen</th>
+        <th>Notes</th>
+      </tr>
+
+      <tr class=d0>
+        <td><pre><code>[Y,IX] = sort(Y,dim,mode)</code></pre></td>
+        <td><pre><code>igl::sort(X,dim,mode,Y,IX)</code></pre></td>
+        <td>MATLAB version allows Y to be a multidimensional matrix, but the
+        Eigen version is only for 1D or 2D matrices.</td>
+      </tr>
+
+      <tr class=d1>
+        <td><pre><code>B(i:(i+w),j:(j+h)) = A(x:(x+w),y:(y+h))</code></pre></td>
+        <td><pre><code>B.block(i,j,w,h) = A.block(i,j,w,h)</code></pre></td>
+        <td>MATLAB version would allow w and h to be non-positive since the
+        colon operator evaluates to a list of indices, but the Eigen version
+        needs non-negative width and height values.</td>
+      </tr>
+
+      <tr class=d0>
+        <td><pre><code>max(A(:))</code></pre></td>
+        <td><pre><code>A.maxCoeff()</code></pre></td>
+        <td>Find the maximum coefficient over all entries of the matrix.</td>
+      </tr>
+
+      <tr class=d1>
+        <td><pre><code>min(A(:))</code></pre></td>
+        <td><pre><code>A.minCoeff()</code></pre></td>
+        <td>Find the minimum coefficient over all entries of the matrix.</td>
+      </tr>
+
+      <!-- Insert rows for each command pair -->
+
+      <!-- Leave this here for copy and pasting
+
+      <tr class=d0>
+        <td><pre><code>Matlab code</code></pre></td>
+        <td><pre><code>Eigen code</code></pre></td>
+        <td>Notes</td>
+      </tr>
+
+      -->
+
+    </table>
+  </body>
+</html>

+ 1 - 1
reorder.h

@@ -28,7 +28,7 @@ inline void igl::reorder(
   // sorted
   std::vector<T> copy = unordered;
   ordered.resize(index_map.size());
-  for(int i = 0; i<index_map.size();i++)
+  for(int i = 0; i<(int)index_map.size();i++)
   {
     ordered[i] = copy[index_map[i]];
   }

+ 8 - 5
report_gl_error.h

@@ -10,24 +10,27 @@
 #endif
 
 #include <cstdio>
+#include <string>
 
 namespace igl
 {
-  // Print last OpenGL error to stderr
-  // Returns result of glGetError()
-  inline GLenum report_gl_error();
+  // Print last OpenGL error to stderr prefixed by specified id string
+  // Inputs:
+  //   id   string to appear before any error msgs
+  // Returns result of glGetError() 
+  inline GLenum report_gl_error(const std::string id = string(""));
 }
 
 // Implementation
 #include "verbose.h"
 
-inline GLenum igl::report_gl_error()
+inline GLenum igl::report_gl_error(const std::string id)
 {
   GLenum err = glGetError();
   if(GL_NO_ERROR != err)
   {
     verbose("GL_ERROR: ");
-    fprintf(stderr,"%s\n",gluErrorString(err));
+    fprintf(stderr,"%s%s\n",id.c_str(),gluErrorString(err));
   }
   return err;
 }

+ 1 - 1
snap_to_canonical_view_quat.h

@@ -59,7 +59,7 @@ inline bool igl::snap_to_canonical_view_quat(
   // loop over canonical view quaternions
   for(int sign = -1;sign<=1;sign+=2)
   {
-    for(int i = 0; i<NUM_CANONICAL_VIEW_QUAT; i++)
+    for(int i = 0; i<(int)NUM_CANONICAL_VIEW_QUAT; i++)
     {
       Q_type distance = 0.0;
       // loop over coordinates

+ 87 - 0
uniform_type_to_string.h

@@ -0,0 +1,87 @@
+#ifndef IGL_UNIFORM_TYPE_TO_STRING
+#define IGL_UNIFORM_TYPE_TO_STRING
+
+#include <string>
+
+#ifdef __APPLE__
+#   include <OpenGL/gl.h>
+#else
+#   include <GL/gl.h>
+#endif
+
+namespace igl
+{
+  // Convert a GL uniform variable type (say, returned from
+  // glGetActiveUniform) and output a string naming that type
+  // Inputs:
+  //   type  enum for given type
+  // Returns string name of that type
+  inline std::string uniform_type_to_string(const GLenum type);
+}
+
+// Implementation
+
+inline std::string igl::uniform_type_to_string(const GLenum type)
+{
+  switch(type)
+  {
+    case GL_FLOAT:
+      return "GL_FLOAT";
+    case GL_FLOAT_VEC2:
+      return "GL_FLOAT_VEC2";
+    case GL_FLOAT_VEC3:
+      return "GL_FLOAT_VEC3";
+    case GL_FLOAT_VEC4:
+      return "GL_FLOAT_VEC4";
+    case GL_INT:
+      return "GL_INT";
+    case GL_INT_VEC2:
+      return "GL_INT_VEC2";
+    case GL_INT_VEC3:
+      return "GL_INT_VEC3";
+    case GL_INT_VEC4:
+      return "GL_INT_VEC4";
+    case GL_BOOL:
+      return "GL_BOOL";
+    case GL_BOOL_VEC2:
+      return "GL_BOOL_VEC2";
+    case GL_BOOL_VEC3:
+      return "GL_BOOL_VEC3";
+    case GL_BOOL_VEC4:
+      return "GL_BOOL_VEC4";
+    case GL_FLOAT_MAT2:
+      return "GL_FLOAT_MAT2";
+    case GL_FLOAT_MAT3:
+      return "GL_FLOAT_MAT3";
+    case GL_FLOAT_MAT4:
+      return "GL_FLOAT_MAT4";
+    case GL_FLOAT_MAT2x3:
+      return "GL_FLOAT_MAT2x3";
+    case GL_FLOAT_MAT2x4:
+      return "GL_FLOAT_MAT2x4";
+    case GL_FLOAT_MAT3x2:
+      return "GL_FLOAT_MAT3x2";
+    case GL_FLOAT_MAT3x4:
+      return "GL_FLOAT_MAT3x4";
+    case GL_FLOAT_MAT4x2:
+      return "GL_FLOAT_MAT4x2";
+    case GL_FLOAT_MAT4x3:
+      return "GL_FLOAT_MAT4x3";
+    case GL_SAMPLER_1D:
+      return "GL_SAMPLER_1D";
+    case GL_SAMPLER_2D:
+      return "GL_SAMPLER_2D";
+    case GL_SAMPLER_3D:
+      return "GL_SAMPLER_3D";
+    case GL_SAMPLER_CUBE:
+      return "GL_SAMPLER_CUBE";
+    case GL_SAMPLER_1D_SHADOW:
+      return "GL_SAMPLER_1D_SHADOW";
+    case GL_SAMPLER_2D_SHADOW:
+      return "GL_SAMPLER_2D_SHADOW";
+    default:
+      return "UNKNOWN_TYPE";
+  }
+}
+
+#endif