Przeglądaj źródła

compute per triangle circum- and in- radii

Former-commit-id: 4887f2cbc25509a133bfcd32b3dd757d484cf01f
Alec Jacobson 8 lat temu
rodzic
commit
c330b9a5ec

+ 26 - 0
include/igl/circumradius.cpp

@@ -0,0 +1,26 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2016 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/.
+#include "circumradius.h"
+#include "edge_lengths.h"
+#include "doublearea.h"
+template <
+  typename DerivedV, 
+  typename DerivedF,
+  typename DerivedR>
+IGL_INLINE void igl::circumradius(
+  const Eigen::PlainObjectBase<DerivedV> & V, 
+  const Eigen::PlainObjectBase<DerivedF> & F,
+  Eigen::PlainObjectBase<DerivedR> & R)
+{
+  Eigen::Matrix<typename DerivedV::Scalar,Eigen::Dynamic,3> l;
+  igl::edge_lengths(V,F,l);
+  DerivedR A;
+  igl::doublearea(l,A);
+  // use formula: R=abc/(4*area) to compute the circum radius
+  R = l.col(0).array() * l.col(1).array() * l.col(2).array() / (2.0*A.array());
+}

+ 34 - 0
include/igl/circumradius.h

@@ -0,0 +1,34 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2016 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_CIRCUMRADIUS_H
+#define IGL_CIRCUMRADIUS_H
+#include "igl_inline.h"
+#include <Eigen/Core>
+namespace igl
+{
+  // Compute the circumradius of each triangle in a mesh (V,F)
+  //
+  // Inputs:
+  //   V  #V by dim list of mesh vertex positions
+  //   F  #F by 3 list of triangle indices into V
+  // Outputs:
+  //   R  #F list of circumradii
+  //
+  template <
+    typename DerivedV, 
+    typename DerivedF,
+    typename DerivedR>
+  IGL_INLINE void circumradius(
+    const Eigen::PlainObjectBase<DerivedV> & V, 
+    const Eigen::PlainObjectBase<DerivedF> & F,
+    Eigen::PlainObjectBase<DerivedR> & R);
+}
+#ifndef IGL_STATIC_LIBRARY
+#  include "circumradius.cpp"
+#endif
+#endif

+ 33 - 0
include/igl/inradius.cpp

@@ -0,0 +1,33 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2016 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/.
+#include "inradius.h"
+#include "edge_lengths.h"
+#include "doublearea.h"
+
+template <
+  typename DerivedV, 
+  typename DerivedF,
+  typename DerivedR>
+IGL_INLINE void igl::inradius(
+  const Eigen::PlainObjectBase<DerivedV> & V, 
+  const Eigen::PlainObjectBase<DerivedF> & F,
+  Eigen::PlainObjectBase<DerivedR> & r)
+{
+  Eigen::Matrix<typename DerivedV::Scalar,Eigen::Dynamic,3> l;
+  Eigen::Matrix<typename DerivedV::Scalar,Eigen::Dynamic,1> R;
+  igl::edge_lengths(V,F,l);
+  // If R is the circumradius, 
+  // R*r = (abc)/(2*(a+b+c))
+  // R = abc/(4*area)
+  // r(abc/(4*area)) = (abc)/(2*(a+b+c))
+  // r/(4*area) = 1/(2*(a+b+c))
+  // r = (2*area)/(a+b+c)
+  DerivedR A;
+  igl::doublearea(l,A);
+  r = A.array() /l.array().rowwise().sum();
+}

+ 35 - 0
include/igl/inradius.h

@@ -0,0 +1,35 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+// 
+// Copyright (C) 2016 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_INRADIUS_H
+#define IGL_INRADIUS_H
+#include "igl_inline.h"
+#include <Eigen/Core>
+namespace igl
+{
+  // Compute the inradius of each triangle in a mesh (V,F)
+  //
+  // Inputs:
+  //   V  #V by dim list of mesh vertex positions
+  //   F  #F by 3 list of triangle indices into V
+  // Outputs:
+  //   R  #F list of inradii
+  //
+  template <
+    typename DerivedV, 
+    typename DerivedF,
+    typename DerivedR>
+  IGL_INLINE void inradius(
+    const Eigen::PlainObjectBase<DerivedV> & V, 
+    const Eigen::PlainObjectBase<DerivedF> & F,
+    Eigen::PlainObjectBase<DerivedR> & R);
+}
+#ifndef IGL_STATIC_LIBRARY
+#  include "inradius.cpp"
+#endif
+#endif
+