Selaa lähdekoodia

offset surface using marching cubes

Former-commit-id: e6aa6b1c20279e9380829178c4e017026a6a3448
Alec Jacobson 8 vuotta sitten
vanhempi
commit
167dce3cf5
2 muutettua tiedostoa jossa 106 lisäystä ja 0 poistoa
  1. 52 0
      include/igl/copyleft/offset_surface.cpp
  2. 54 0
      include/igl/copyleft/offset_surface.h

+ 52 - 0
include/igl/copyleft/offset_surface.cpp

@@ -0,0 +1,52 @@
+#include "offset_surface.h"
+#include "marching_cubes.h"
+#include "../voxel_grid.h"
+#include <cassert>
+
+template <
+  typename DerivedV,
+  typename DerivedF,
+  typename isolevelType,
+  typename sType,
+  typename DerivedSV,
+  typename DerivedSF,
+  typename DerivedGV,
+  typename Derivedside,
+  typename DerivedS>
+void igl::copyleft::offset_surface(
+  const Eigen::MatrixBase<DerivedV> & V,
+  const Eigen::MatrixBase<DerivedF> & F,
+  const isolevelType isolevel,
+  const sType s,
+  const SignedDistanceType & signed_distance_type,
+  Eigen::PlainObjectBase<DerivedSV> & SV,
+  Eigen::PlainObjectBase<DerivedSF> & SF,
+  Eigen::PlainObjectBase<DerivedGV> & GV,
+  Eigen::PlainObjectBase<Derivedside> & side,
+  Eigen::PlainObjectBase<DerivedS> & S)
+{
+  {
+    typedef typename DerivedV::Scalar Scalar;
+    Eigen::AlignedBox<Scalar,3> box;
+    typedef Eigen::Matrix<Scalar,1,3> RowVector3S;
+    assert(V.cols() == 3 && "V must contain positions in 3D");
+    RowVector3S min_ext = V.colwise().minCoeff().array() - isolevel;
+    RowVector3S max_ext = V.colwise().maxCoeff().array() + isolevel;
+    box.extend(min_ext.transpose());
+    box.extend(max_ext.transpose());
+    igl::voxel_grid(box,s,0,GV,side);
+  }
+  {
+    Eigen::VectorXi I;
+    Eigen::Matrix<typename DerivedV::Scalar,Eigen::Dynamic,3> C,N;
+    igl::signed_distance(
+      GV,V,F,igl::SIGNED_DISTANCE_TYPE_PSEUDONORMAL,S,I,C,N);
+  }
+  DerivedS SS = S.array()-isolevel;
+  igl::copyleft::marching_cubes(SS,GV,side(0),side(1),side(2),SV,SF);
+}
+
+#ifdef IGL_STATIC_LIBRARY
+// Explicit template instantiation
+template void igl::copyleft::offset_surface<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, double, int, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, double, int, igl::SignedDistanceType const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, 1, 3, 1, 1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
+#endif

+ 54 - 0
include/igl/copyleft/offset_surface.h

@@ -0,0 +1,54 @@
+#ifndef IGL_COPYLEFT_OFFSET_SURFACE_H
+#define IGL_COPYLEFT_OFFSET_SURFACE_H
+#include "../igl_inline.h"
+#include "../signed_distance.h"
+#include <Eigen/Core>
+
+namespace igl
+{
+  namespace copyleft
+  {
+    // Compute a triangulated offset surface using maching cubes on a gride of
+    // signed distance values from the input triangle mesh.
+    //
+    // Inputs:
+    //   V  #V by 3 list of mesh vertex positions
+    //   F  #F by 3 list of mesh triangle indices into V
+    //   isolevel  iso level to extract (signed distance: negative inside)
+    //   s  number of grid cells along longest side (controls resolution)
+    //   signed_distance_type  type of signing to use (see
+    //     ../signed_distance.h)
+    // Outputs:
+    //   SV  #SV by 3 list of output surface mesh vertex positions
+    //   SF  #SF by 3 list of output mesh triangle indices into SV
+    //   GV  #GV=side(0)*side(1)*side(2) by 3 list of grid cell centers
+    //   side  list of number of grid cells in x, y, and z directions
+    //   S  #GV by 3 list of signed distance values
+    //
+    template <
+      typename DerivedV,
+      typename DerivedF,
+      typename isolevelType,
+      typename sType,
+      typename DerivedSV,
+      typename DerivedSF,
+      typename DerivedGV,
+      typename Derivedside,
+      typename DerivedS>
+    void offset_surface(
+      const Eigen::MatrixBase<DerivedV> & V,
+      const Eigen::MatrixBase<DerivedF> & F,
+      const isolevelType isolevel,
+      const sType s,
+      const SignedDistanceType & signed_distance_type,
+      Eigen::PlainObjectBase<DerivedSV> & SV,
+      Eigen::PlainObjectBase<DerivedSF> & SF,
+      Eigen::PlainObjectBase<DerivedGV> & GV,
+      Eigen::PlainObjectBase<Derivedside> & side,
+      Eigen::PlainObjectBase<DerivedS> & S);
+  }
+}
+#ifndef IGL_STATIC_LIBRARY
+#  include "offset_surface.cpp"
+#endif 
+#endif