瀏覽代碼

templates

Former-commit-id: 5434877d3993e10858457057f88e7d56d315aca2
Alec Jacobson 8 年之前
父節點
當前提交
035849c472

+ 13 - 9
include/igl/centroid.cpp

@@ -14,8 +14,8 @@ template <
   typename Derivedc, 
   typename Derivedvol>
 IGL_INLINE void igl::centroid(
-  const Eigen::PlainObjectBase<DerivedV>& V,
-  const Eigen::PlainObjectBase<DerivedF>& F,
+  const Eigen::MatrixBase<DerivedV>& V,
+  const Eigen::MatrixBase<DerivedF>& F,
   Eigen::PlainObjectBase<Derivedc>& cen,
   Derivedvol & vol)
 {
@@ -31,11 +31,12 @@ IGL_INLINE void igl::centroid(
     // "Calculating the volume and centroid of a polyhedron in 3d" [Nuernberg 2013]
     // http://www2.imperial.ac.uk/~rn/centroid.pdf
     // rename corners
-    const RowVector3d & a = V.row(F(f,0));
-    const RowVector3d & b = V.row(F(f,1));
-    const RowVector3d & c = V.row(F(f,2));
+    typedef Eigen::Matrix<typename DerivedV::Scalar,1,3> RowVector3S;
+    const RowVector3S & a = V.row(F(f,0));
+    const RowVector3S & b = V.row(F(f,1));
+    const RowVector3S & c = V.row(F(f,2));
     // un-normalized normal
-    const RowVector3d & n = (b-a).cross(c-a);
+    const RowVector3S & n = (b-a).cross(c-a);
     // total volume via divergence theorem: ∫ 1
     vol += n.dot(a)/6.;
     // centroid via divergence theorem and midpoint quadrature: ∫ x
@@ -50,8 +51,8 @@ template <
   typename DerivedF, 
   typename Derivedc>
 IGL_INLINE void igl::centroid(
-  const Eigen::PlainObjectBase<DerivedV>& V,
-  const Eigen::PlainObjectBase<DerivedF>& F,
+  const Eigen::MatrixBase<DerivedV>& V,
+  const Eigen::MatrixBase<DerivedF>& F,
   Eigen::PlainObjectBase<Derivedc>& c)
 {
   typename Derivedc::Scalar vol;
@@ -59,5 +60,8 @@ IGL_INLINE void igl::centroid(
 }
 
 #ifdef IGL_STATIC_LIBRARY
-template void igl::centroid<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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
+// Explicit template instantiation
+// generated by autoexplicit.sh
+template void igl::centroid<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, Eigen::Matrix<float, 1, 3, 1, 1, 3> >(Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> >&);
+template void igl::centroid<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::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
 #endif

+ 4 - 4
include/igl/centroid.h

@@ -26,8 +26,8 @@ namespace igl
     typename Derivedc, 
     typename Derivedvol>
   IGL_INLINE void centroid(
-    const Eigen::PlainObjectBase<DerivedV>& V,
-    const Eigen::PlainObjectBase<DerivedF>& F,
+    const Eigen::MatrixBase<DerivedV>& V,
+    const Eigen::MatrixBase<DerivedF>& F,
     Eigen::PlainObjectBase<Derivedc>& c,
     Derivedvol & vol);
   template <
@@ -35,8 +35,8 @@ namespace igl
     typename DerivedF, 
     typename Derivedc>
   IGL_INLINE void centroid(
-    const Eigen::PlainObjectBase<DerivedV>& V,
-    const Eigen::PlainObjectBase<DerivedF>& F,
+    const Eigen::MatrixBase<DerivedV>& V,
+    const Eigen::MatrixBase<DerivedF>& F,
     Eigen::PlainObjectBase<Derivedc>& c);
 
 }

+ 2 - 2
include/igl/opengl/create_mesh_vbo.h

@@ -21,7 +21,7 @@ namespace igl
   
     // Inputs:
     //   V  #V by 3 eigen Matrix of mesh vertex 3D positions
-    //   F  #F by 3 eigne Matrix of face (triangle) indices
+    //   F  #F by 3 eigen Matrix of face (triangle) indices
     // Outputs:
     //   V_vbo_id  buffer id for vertex positions
     //   F_vbo_id  buffer id for face indices
@@ -37,7 +37,7 @@ namespace igl
   
     // Inputs:
     //   V  #V by 3 eigen Matrix of mesh vertex 3D positions
-    //   F  #F by 3 eigne Matrix of face (triangle) indices
+    //   F  #F by 3 eigen Matrix of face (triangle) indices
     //   N  #V by 3 eigen Matrix of mesh vertex 3D normals
     // Outputs:
     //   V_vbo_id  buffer id for vertex positions

+ 59 - 16
include/igl/opengl/init_render_to_texture.cpp

@@ -12,42 +12,85 @@
 IGL_INLINE void igl::opengl::init_render_to_texture(
   const size_t width,
   const size_t height,
+  const bool depth_texture,
   GLuint & tex_id,
   GLuint & fbo_id,
-  GLuint & dfbo_id)
+  GLuint & d_id)
 {
   using namespace std;
   // Delete if already exists
   glDeleteTextures(1,&tex_id);
   glDeleteFramebuffers(1,&fbo_id);
-  glDeleteFramebuffers(1,&dfbo_id);
+  if(depth_texture)
+  {
+    glDeleteTextures(1,&d_id);
+  }else
+  {
+    glDeleteFramebuffers(1,&d_id);
+  }
   // http://www.opengl.org/wiki/Framebuffer_Object_Examples#Quick_example.2C_render_to_texture_.282D.29
-  glGenTextures(1, &tex_id);
-  glBindTexture(GL_TEXTURE_2D, tex_id);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+  const auto & gen_tex = [](GLuint & tex_id)
+  {
+    glGenTextures(1, &tex_id);
+    glBindTexture(GL_TEXTURE_2D, tex_id);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+  };
+  gen_tex(tex_id);
   //NULL means reserve texture memory, but texels are undefined
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_BGRA, GL_FLOAT, NULL);
   glBindTexture(GL_TEXTURE_2D, 0);
+
   glGenFramebuffers(1, &fbo_id);
   glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);
   //Attach 2D texture to this FBO
   glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_id, 0);
-
-  glGenRenderbuffers(1, &dfbo_id);
-  glBindRenderbuffer(GL_RENDERBUFFER, dfbo_id);
-  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
-  //Attach depth buffer to FBO (for this example it's not really needed, but if
-  //drawing a 3D scene it would be necessary to attach something)
-  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, dfbo_id);
+  if(depth_texture)
+  {
+    // Generate a depth texture
+    gen_tex(d_id);
+    glTexImage2D(
+      GL_TEXTURE_2D,
+      0,
+      GL_DEPTH_COMPONENT32,
+      width,
+      height,
+      0,
+      GL_DEPTH_COMPONENT,
+      GL_FLOAT,
+      NULL);
+    glFramebufferTexture2D(
+      GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,d_id,0);
+  }else
+  {
+    // Attach a depth buffer
+    glGenRenderbuffers(1, &d_id);
+    glBindRenderbuffer(GL_RENDERBUFFER, d_id);
+    glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT24,width,height);
+    glFramebufferRenderbuffer(
+      GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,d_id);
+  }
 
   //Does the GPU support current FBO configuration?
   GLenum status;
   status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
   assert(status == GL_FRAMEBUFFER_COMPLETE);
   // Unbind to clean up
-  glBindRenderbuffer(GL_RENDERBUFFER, 0);
+  if(!depth_texture)
+  {
+    glBindRenderbuffer(GL_RENDERBUFFER, 0);
+  }
   glBindFramebuffer(GL_FRAMEBUFFER, 0);
 }
+
+IGL_INLINE void igl::opengl::init_render_to_texture(
+  const size_t width,
+  const size_t height,
+  GLuint & tex_id,
+  GLuint & fbo_id,
+  GLuint & dfbo_id)
+{
+  return init_render_to_texture(width,height,false,tex_id,fbo_id,dfbo_id);
+}

+ 41 - 2
include/igl/opengl/init_render_to_texture.h

@@ -17,13 +17,52 @@ namespace igl
     // Create a frame buffer that renders color to a RGBA texture a depth to a
     // "render buffer".
     //
+    // After calling this, you can use with something like:
+    //
+    //     glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);
+    //     if(!depth_texture)
+    //     {
+    //       glBindRenderbuffer(GL_RENDERBUFFER, d_id);
+    //     }
+    //     //
+    //     // draw scene ...
+    //     //
+    //     // clean up
+    //     glBindFramebuffer(GL_FRAMEBUFFER,0);
+    //     if(!depth_texture)
+    //     {
+    //       glBindRenderbuffer(GL_RENDERBUFFER, 0);
+    //     }
+    //     // Later ...
+    //     glActiveTexture(GL_TEXTURE0+0);
+    //     glBindTexture(GL_TEXTURE_2D,tex_id);
+    //     if(depth_texture)
+    //     {
+    //       glActiveTexture(GL_TEXTURE0+1);
+    //       glBindTexture(GL_TEXTURE_2D,d_id);
+    //     }
+    //     // draw textures
+    //      
+    //     
+    //
     // Inputs:
     //   width  image width
-    //   height image height
+    //   height  image height
+    //   depth_texture  whether to create a texture for depth or to create a
+    //     render buffer for depth 
     // Outputs:
     //   tex_id  id of the texture
     //   fbo_id  id of the frame buffer object
-    //   dfbo_id  id of the depth frame buffer object
+    //   d_id  id of the depth texture or frame buffer object
+    //
+    IGL_INLINE void init_render_to_texture(
+      const size_t width,
+      const size_t height,
+      const bool depth_texture,
+      GLuint & tex_id,
+      GLuint & fbo_id,
+      GLuint & d_id);
+    // Wrapper with depth_texture = false for legacy reasons
     IGL_INLINE void init_render_to_texture(
       const size_t width,
       const size_t height,

+ 2 - 0
include/igl/readMESH.cpp

@@ -489,6 +489,8 @@ IGL_INLINE bool igl::readMESH(
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template instantiation
 // generated by autoexplicit.sh
+template bool igl::readMESH<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(__sFILE*, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> >&);
+// generated by autoexplicit.sh
 template bool igl::readMESH<Eigen::Matrix<double, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 1, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 // generated by autoexplicit.sh
 template bool igl::readMESH<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, 3, 1, -1, 3> >&);

+ 2 - 0
include/igl/read_triangle_mesh.cpp

@@ -168,6 +168,8 @@ IGL_INLINE bool igl::read_triangle_mesh(
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template instantiation
 // generated by autoexplicit.sh
+template bool igl::read_triangle_mesh<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> >&);
+// generated by autoexplicit.sh
 template bool igl::read_triangle_mesh<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 template bool igl::read_triangle_mesh<double, int>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >&);
 template bool igl::read_triangle_mesh<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(std::string, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&);

+ 2 - 2
include/igl/voxel_grid.h

@@ -20,8 +20,8 @@ namespace igl
   //   s  number of cell centers on largest side (including 2*pad_count)
   //   pad_count  number of cells beyond box
   // Outputs:
-  //   GV  res(0)*res(1)*res(2) by 3 list of cell center positions
-  //   res  3-long list of dimension of voxel grid
+  //   GV  side(0)*side(1)*side(2) by 3 list of cell center positions
+  //   side  3-long list of dimension of voxel grid
   IGL_INLINE void voxel_grid(
     const Eigen::AlignedBox3d & box, 
     const int s,