Эх сурвалжийг харах

fixed up style and compilation errors in flipped_triangles

Former-commit-id: 8f4655c281544eeb495490e08696b0f276c8824e
Alec Jacobson 8 жил өмнө
parent
commit
4ebf2b20ef

+ 54 - 0
include/igl/flipped_triangles.cpp

@@ -0,0 +1,54 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2016 Michael Rabinovich <michaelrabinovich27@gmail.com@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/.
+#include "flipped_triangles.h"
+
+#include "list_to_matrix.h"
+#include <vector>
+template <typename DerivedV, typename DerivedF, typename DerivedX>
+IGL_INLINE void igl::flipped_triangles(
+  const Eigen::PlainObjectBase<DerivedV> & V,
+  const Eigen::PlainObjectBase<DerivedF> & F,
+  Eigen::PlainObjectBase<DerivedX> & X)
+{
+  assert(V.cols() == 2 && "V should contain 2D positions");
+  std::vector<typename DerivedX::Scalar> flip_idx;
+  for (int i = 0; i < F.rows(); i++) 
+  {
+    // https://www.cs.cmu.edu/~quake/robust.html
+    typedef Eigen::Matrix<typename DerivedV::Scalar,1,2> RowVector2S;
+    RowVector2S v1_n = V.row(F(i,0)); 
+    RowVector2S v2_n = V.row(F(i,1)); 
+    RowVector2S v3_n = V.row(F(i,2));
+    Eigen::Matrix<typename DerivedV::Scalar,3,3> T2_Homo;
+    T2_Homo.col(0) << v1_n(0),v1_n(1),1.;
+    T2_Homo.col(1) << v2_n(0),v2_n(1),1.;
+    T2_Homo.col(2) << v3_n(0),v3_n(1),1.;
+    double det = T2_Homo.determinant();
+    assert(det == det && "det should not be NaN");
+    if (det < 0) 
+    {
+      flip_idx.push_back(i);
+    }
+  }
+  igl::list_to_matrix(flip_idx,X);
+}
+
+template <typename DerivedV, typename DerivedF>
+IGL_INLINE Eigen::VectorXi igl::flipped_triangles(
+  const Eigen::PlainObjectBase<DerivedV> & V,
+  const Eigen::PlainObjectBase<DerivedF> & F)
+{
+  Eigen::VectorXi X;
+  flipped_triangles(V,F,X);
+  return X;
+}
+
+#ifdef IGL_STATIC_LIBRARY
+// Explicit template specialization
+template void igl::flipped_triangles<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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+#endif

+ 15 - 14
include/igl/flipped_triangles_ids.h → include/igl/flipped_triangles.h

@@ -5,34 +5,35 @@
 // This Source Code Form is subject to the terms of the Mozilla Public License
 // 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
 // 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/.
 // obtain one at http://mozilla.org/MPL/2.0/.
-#ifndef IGL_FLIPPED_TRIANGLES_IDS_H
-#define IGL_FLIPPED_TRIANGLES_IDS_H
+#ifndef IGL_FLIPPED_TRIANGLES_H
+#define IGL_FLIPPED_TRIANGLES_H
 #include "igl_inline.h"
 #include "igl_inline.h"
 
 
 #include <Eigen/Dense>
 #include <Eigen/Dense>
-#include <Eigen/Sparse>
-#include <vector>
 namespace igl
 namespace igl
 {
 {
   // Finds the ids of the flipped triangles of the mesh V,F in the UV mapping uv
   // Finds the ids of the flipped triangles of the mesh V,F in the UV mapping uv
-  // Templates:
-  //   Scalar  should be a floating point number type
-  //   Index   should be an integer type
+  //
   // Inputs:
   // Inputs:
-  //   V       #V by 2 list of mesh vertex positions
-  //   F       #F by dim list of mesh faces (must be triangles)
+  //   V  #V by 2 list of mesh vertex positions
+  //   F  #F by 3 list of mesh faces (must be triangles)
   // Outputs:
   // Outputs:
-  //   A vector containing the ids of the flipped triangles
+  //   X  #flipped list of containing the indices into F of the flipped triangles
+  // Wrapper with return type
+  template <typename DerivedV, typename DerivedF, typename DerivedX>
+  IGL_INLINE void flipped_triangles(
+    const Eigen::PlainObjectBase<DerivedV> & V,
+    const Eigen::PlainObjectBase<DerivedF> & F,
+    Eigen::PlainObjectBase<DerivedX> & X);
   template <typename Scalar, typename Index>
   template <typename Scalar, typename Index>
-  IGL_INLINE Eigen::VectorXi flipped_triangles_ids(
+  IGL_INLINE Eigen::VectorXi flipped_triangles(
     const Eigen::PlainObjectBase<Scalar> & V,
     const Eigen::PlainObjectBase<Scalar> & V,
-    const Eigen::PlainObjectBase<Index> & F
-  );
+    const Eigen::PlainObjectBase<Index> & F);
 
 
 }
 }
 
 
 #ifndef IGL_STATIC_LIBRARY
 #ifndef IGL_STATIC_LIBRARY
-#  include "flipped_triangles_ids.cpp"
+#  include "flipped_triangles.cpp"
 #endif
 #endif
 
 
 #endif
 #endif

+ 0 - 45
include/igl/flipped_triangles_ids.cpp

@@ -1,45 +0,0 @@
-// This file is part of libigl, a simple c++ geometry processing library.
-//
-// Copyright (C) 2016 Michael Rabinovich <michaelrabinovich27@gmail.com@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/.
-#include "flipped_triangles_ids.h"
-
-#include <igl/edge_topology.h>
-
-template <typename Scalar, typename Index>
-IGL_INLINE Eigen::VectorXi flipped_triangles_ids(
-  const Eigen::PlainObjectBase<Scalar> & V,
-  const Eigen::PlainObjectBase<Index> & F
-)
-{
-  assert(V.cols() == 2);
-  std::vector<int> flip_idx;
-  for (int i = 0; i < F.rows(); i++) {
-
-    Eigen::Vector2d v1_n = V.row(F(i,0)); Eigen::Vector2d v2_n = V.row(F(i,1)); Eigen::Vector2d v3_n = V.row(F(i,2));
-
-    Eigen::MatrixXd T2_Homo(3,3);
-    T2_Homo.col(0) << v1_n(0),v1_n(1),1;
-    T2_Homo.col(1) << v2_n(0),v2_n(1),1;
-    T2_Homo.col(2) << v3_n(0),v3_n(1),1;
-    double det = T2_Homo.determinant();
-    assert (det == det);
-    if (det < 0) {
-      flip_idx.push_back(i);
-    }
-  }
-
-  Eigen::VectorXi ret(flip_idx.size());
-  for (unsigned i=0; i<flip_idx.size();++i)
-    ret[i] = flip_idx[i];
-
-  return ret;
-}
-
-#ifdef IGL_STATIC_LIBRARY
-// Explicit template specialization
-// generated by autoexplicit.sh
-#endif