Browse Source

generate triangles from a points streaming triangle strip

Former-commit-id: 50677548afa46f4519493955b07a3ada96afbd84
Alec Jacobson 10 years ago
parent
commit
9522dfd77e
2 changed files with 62 additions and 0 deletions
  1. 29 0
      include/igl/triangles_from_strip.cpp
  2. 33 0
      include/igl/triangles_from_strip.h

+ 29 - 0
include/igl/triangles_from_strip.cpp

@@ -0,0 +1,29 @@
+#include "triangles_from_strip.h"
+#include <iostream>
+
+template <typename DerivedS, typename DerivedF>
+IGL_INLINE void igl::triangles_from_strip(
+  const Eigen::MatrixBase<DerivedS>& S,
+  Eigen::PlainObjectBase<DerivedF>& F)
+{
+  using namespace std;
+  F.resize(S.size()-2,3);
+  for(int s = 0;s < S.size()-2;s++)
+  {
+    if(s%2 == 0)
+    {
+      F(s,0) = S(s+2);
+      F(s,1) = S(s+1);
+      F(s,2) = S(s+0);
+    }else
+    {
+      F(s,0) = S(s+0);
+      F(s,1) = S(s+1);
+      F(s,2) = S(s+2);
+    }
+  }
+}
+
+#ifdef IGL_STATIC_LIBRARY
+// Explicit template specialization
+#endif

+ 33 - 0
include/igl/triangles_from_strip.h

@@ -0,0 +1,33 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com>
+// 
+// This Source Code Form is subject to the terms of the Mozilla Public License 
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+// obtain one at http://mozilla.org/MPL/2.0/.
+#ifndef IGL_TRIANGLES_FROM_STRIP_H
+#define IGL_TRIANGLES_FROM_STRIP_H
+#include "igl_inline.h"
+#include <Eigen/Core>
+namespace igl
+{
+  // TRIANGLES_FROM_STRIP Create a list of triangles from a stream of indices
+  // along a strip.
+  //
+  // Inputs:
+  //   S  #S list of indices
+  // Outputs:
+  //   F  #S-2 by 3 list of triangle indices
+  //
+  template <typename DerivedS, typename DerivedF>
+  IGL_INLINE void triangles_from_strip(
+    const Eigen::MatrixBase<DerivedS>& S,
+    Eigen::PlainObjectBase<DerivedF>& F);
+}
+
+#ifndef IGL_STATIC_LIBRARY
+#  include "triangles_from_strip.cpp"
+#endif
+
+#endif
+