Browse Source

added function to compute local basis for each triangle

Former-commit-id: ab255489ae6bcf0f859efea07996694ff0eb6357
Daniele Panozzo 11 years ago
parent
commit
346f7db74b
2 changed files with 87 additions and 0 deletions
  1. 48 0
      include/igl/local_basis.cpp
  2. 39 0
      include/igl/local_basis.h

+ 48 - 0
include/igl/local_basis.cpp

@@ -0,0 +1,48 @@
+#include "local_basis.h"
+
+#include <sstream>
+#include <string>
+#include <fstream>
+
+#include <vector>
+#include <Eigen/Geometry>
+
+using namespace Eigen;
+using namespace std;
+
+namespace igl
+{
+
+  template <typename DerivedV, typename DerivedF>
+  IGL_INLINE void local_basis(
+    const Eigen::PlainObjectBase<DerivedV>& V,
+    const Eigen::PlainObjectBase<DerivedF>& F,
+    Eigen::PlainObjectBase<DerivedV>& B1,
+    Eigen::PlainObjectBase<DerivedV>& B2,
+    Eigen::PlainObjectBase<DerivedV>& B3
+    )
+  {
+    B1.resize(F.rows(),3);
+    B2.resize(F.rows(),3);
+    B3.resize(F.rows(),3);
+
+    for (unsigned i=0;i<F.rows();++i)
+    {
+      RowVector3d v1 = (V.row(F(i,1)) - V.row(F(i,0))).normalized();
+      RowVector3d t = V.row(F(i,2)) - V.row(F(i,0));
+      RowVector3d v3 = v1.cross(t).normalized();
+      RowVector3d v2 = v1.cross(v3).normalized();
+
+      B1.row(i) = v1;
+      B2.row(i) = v2;
+      B3.row(i) = v3;
+    }
+
+  }
+
+}
+
+#ifndef IGL_HEADER_ONLY
+// Explicit template specialization
+// generated by autoexplicit.sh
+#endif

+ 39 - 0
include/igl/local_basis.h

@@ -0,0 +1,39 @@
+#ifndef IGL_LOCALBASIS_H
+#define IGL_LOCALBASIS_H
+
+#include "igl/igl_inline.h"
+#include <Eigen/Core>
+#include <string>
+#include <vector>
+
+namespace igl 
+{
+  // Compute a local orthogonal reference system for each triangle in the given mesh
+  // Templates:
+  //   DerivedV derived from vertex positions matrix type: i.e. MatrixXd
+  //   DerivedF derived from face indices matrix type: i.e. MatrixXi
+  // Inputs:
+  //   V  eigen matrix #V by 3
+  //   F  #F by 3 list of mesh faces (must be triangles)
+  // Outputs:
+  //   B1 eigen matrix #F by 3, each vector is tangent to the triangle
+  //   B2 eigen matrix #F by 3, each vector is tangent to the triangle and perpendicular to B1
+  //   B3 eigen matrix #F by 3, normal of the triangle
+  //
+  // See also: adjacency_matrix
+  template <typename DerivedV, typename DerivedF>
+  IGL_INLINE void local_basis(
+    const Eigen::PlainObjectBase<DerivedV>& V,
+    const Eigen::PlainObjectBase<DerivedF>& F,
+    Eigen::PlainObjectBase<DerivedV>& B1,
+    Eigen::PlainObjectBase<DerivedV>& B2,
+    Eigen::PlainObjectBase<DerivedV>& B3
+    );
+
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "local_basis.cpp"
+#endif
+
+#endif