Forráskód Böngészése

cdt in 2d

Former-commit-id: 1340495cec84c59465dcf6d80951cb5dbcb2951b
Alec Jacobson 8 éve
szülő
commit
dc9595282f
2 módosított fájl, 110 hozzáadás és 0 törlés
  1. 56 0
      include/igl/triangle/cdt.cpp
  2. 54 0
      include/igl/triangle/cdt.h

+ 56 - 0
include/igl/triangle/cdt.cpp

@@ -0,0 +1,56 @@
+#include "cdt.h"
+#include "../bounding_box.h"
+#include "../triangle/triangulate.h"
+#include "../remove_duplicate_vertices.h"
+#include "../remove_unreferenced.h"
+#include "../slice_mask.h"
+
+template <
+  typename DerivedV, 
+  typename DerivedE,
+  typename DerivedWV,
+  typename DerivedWF,
+  typename DerivedWE,
+  typename DerivedJ>
+IGL_INLINE void igl::triangle::cdt(
+  const Eigen::MatrixBase<DerivedV> & V,
+  const Eigen::MatrixBase<DerivedE> & E,
+  const std::string & flags,
+  Eigen::PlainObjectBase<DerivedWV> & WV,
+  Eigen::PlainObjectBase<DerivedWF> & WF,
+  Eigen::PlainObjectBase<DerivedWE> & WE,
+  Eigen::PlainObjectBase<DerivedJ> & J)
+{
+  assert(V.cols() == 2);
+  assert(E.cols() == 2);
+  typedef typename DerivedV::Scalar Scalar;
+  typedef Eigen::Matrix<Scalar,Eigen::Dynamic,2> MatrixX2S;
+  //MatrixX2S BV;
+  //Eigen::MatrixXi BE;
+  //igl::bounding_box(V,BV,BE);
+  //WV.resize(V.rows()+BV.rows(),2);
+  //WV<<V,BV;
+  //WE.resize(E.rows()+BE.rows(),2);
+  //WE<<E,(BE.array()+V.rows());
+  WV = V;
+  WE = E;
+  Eigen::VectorXi _;
+  igl::remove_duplicate_vertices(DerivedWV(WV),DerivedWE(WE),1e-10,WV,_,J,WE);
+  // Remove degenerate edges
+  igl::slice_mask(DerivedWE(WE),(WE.array().col(0) != WE.array().col(1)).eval(),1,WE);
+  // c flag must be present
+  igl::triangle::triangulate(DerivedWV(WV),WE,DerivedWV(),flags,WV,WF);
+  Eigen::VectorXi UJ;
+  igl::remove_unreferenced(DerivedV(WV),Eigen::MatrixXi(WF),WV,WF,UJ);
+  for(int i=0;i<WE.rows();i++) for(int j=0;j<WE.cols();j++) WE(i,j)=UJ(WE(i,j));
+  // Remove edges from box
+  //WE.conservativeResize(WE.rows()-BE.rows(),2);
+  for(int i=0;i<J.size();i++) J(i)=UJ(J(i));
+  //J.conservativeResize(J.size()-BV.rows());
+}
+
+#ifdef IGL_STATIC_LIBRARY
+// Explicit template instantiation
+// generated by autoexplicit.sh
+template void igl::triangle::cdt<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, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > 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<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+#endif

+ 54 - 0
include/igl/triangle/cdt.h

@@ -0,0 +1,54 @@
+#ifndef IGL_TRIANGLE_CDT_H
+#define IGL_TRIANGLE_CDT_H
+
+#include "../igl_inline.h"
+#include <Eigen/Core>
+
+namespace igl
+{
+  namespace triangle
+  {
+    // CDT Construct the constrained delaunay triangulation of the convex hull
+    // of a given set of points and segments in 2D. This differs from a direct
+    // call to triangulate because it will preprocess the input to remove
+    // duplicates and return an adjusted segment list on the output.
+    // 
+    //
+    // BACKGROUND_MESH Construct a background mesh for a (messy) texture mesh with
+    // cosntraint edges that are about to deform.
+    // 
+    // Inputs:
+    //   V  #V by 2 list of texture mesh vertices
+    //   E  #E by 2 list of constraint edge indices into V
+    //   flags  string of triangle flags should contain "-c" unless the
+    //     some subset of segments are known to enclose all other
+    //     points/segments.
+    // Outputs:
+    //   WV  #WV by 2 list of background mesh vertices 
+    //   WF  #WF by 2 list of background mesh triangle indices into WV
+    //   WE  #WE by 2 list of constraint edge indices into WV (might be smaller
+    //     than E because degenerate constraints have been removed)
+    //   J  #V list of indices into WF/WE for each vertex in V
+    //
+    template <
+      typename DerivedV, 
+      typename DerivedE,
+      typename DerivedWV,
+      typename DerivedWF,
+      typename DerivedWE,
+      typename DerivedJ>
+    IGL_INLINE void cdt(
+      const Eigen::MatrixBase<DerivedV> & V,
+      const Eigen::MatrixBase<DerivedE> & E,
+      const std::string & flags,
+      Eigen::PlainObjectBase<DerivedWV> & WV,
+      Eigen::PlainObjectBase<DerivedWF> & WF,
+      Eigen::PlainObjectBase<DerivedWE> & WE,
+      Eigen::PlainObjectBase<DerivedJ> & J);
+  }
+}
+
+#ifndef IGL_STATIC_LIBRARY
+#include "cdt.cpp"
+#endif
+#endif