فهرست منبع

cylinder generator

Former-commit-id: a10cb0df31811655483d32bea0f590fb2e818173
Alec Jacobson 8 سال پیش
والد
کامیت
fc6d8c37c3
2فایلهای تغییر یافته به همراه67 افزوده شده و 0 حذف شده
  1. 41 0
      include/igl/cylinder.cpp
  2. 26 0
      include/igl/cylinder.h

+ 41 - 0
include/igl/cylinder.cpp

@@ -0,0 +1,41 @@
+#include "cylinder.h"
+#include <cassert>
+#include <cmath>
+#include <cstddef>
+
+template <typename DerivedV, typename DerivedF>
+IGL_INLINE void igl::cylinder(
+  const int axis_devisions,
+  const int height_devisions,
+  Eigen::PlainObjectBase<DerivedV> & V,
+  Eigen::PlainObjectBase<DerivedF> & F)
+{
+  V.resize(axis_devisions*height_devisions,3);
+  F.resize(2*(axis_devisions*(height_devisions-1)),3);
+  int f = 0;
+  typedef typename DerivedV::Scalar Scalar;
+  for(int th = 0;th<axis_devisions;th++)
+  {
+    Scalar x = cos(2.*M_PI*Scalar(th)/Scalar(axis_devisions));
+    Scalar y = sin(2.*M_PI*Scalar(th)/Scalar(axis_devisions));
+    for(int h = 0;h<height_devisions;h++)
+    {
+      Scalar z = Scalar(h)/Scalar(height_devisions-1);
+      V(th+h*axis_devisions,0) = x;
+      V(th+h*axis_devisions,1) = y;
+      V(th+h*axis_devisions,2) = z;
+      if(h > 0)
+      {
+        F(f,0) = ((th+0)%axis_devisions)+(h-1)*axis_devisions;
+        F(f,1) = ((th+1)%axis_devisions)+(h-1)*axis_devisions;
+        F(f,2) = ((th+0)%axis_devisions)+(h+0)*axis_devisions;
+        f++;
+        F(f,0) = ((th+1)%axis_devisions)+(h-1)*axis_devisions;
+        F(f,1) = ((th+1)%axis_devisions)+(h+0)*axis_devisions;
+        F(f,2) = ((th+0)%axis_devisions)+(h+0)*axis_devisions;
+        f++;
+      }
+    }
+  }
+  assert(f == F.rows());
+}

+ 26 - 0
include/igl/cylinder.h

@@ -0,0 +1,26 @@
+#ifndef IGL_CYLINDER_H
+#define IGL_CYLINDER_H
+#include "igl_inline.h"
+#include <Eigen/Core>
+namespace igl
+{
+  // Construct a triangle mesh of a cylinder (without caps)
+  //
+  // Inputs:
+  //   axis_devisions  number of vertices _around the cylinder_
+  //   height_devisions  number of vertices _up the cylinder_
+  // Outputs:
+  //   V  #V by 3 list of mesh vertex positions
+  //   F  #F by 3 list of triangle indices into V
+  //
+  template <typename DerivedV, typename DerivedF>
+  IGL_INLINE void cylinder(
+    const int axis_devisions,
+    const int height_devisions,
+    Eigen::PlainObjectBase<DerivedV> & V,
+    Eigen::PlainObjectBase<DerivedF> & F);
+}
+#ifndef IGL_STATIC_LIBRARY
+#  include "cylinder.cpp"
+#endif
+#endif