123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- // 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/.
- #include "volume.h"
- template <
- typename DerivedV,
- typename DerivedT,
- typename Derivedvol>
- IGL_INLINE void igl::volume(
- Eigen::PlainObjectBase<DerivedV>& V,
- Eigen::PlainObjectBase<DerivedT>& T,
- Eigen::PlainObjectBase<Derivedvol>& vol)
- {
- using namespace Eigen;
- const int m = T.rows();
- vol.resize(m,1);
- for(int t = 0;t<m;t++)
- {
- const auto & a = V.row(T(t,0));
- const auto & b = V.row(T(t,1));
- const auto & c = V.row(T(t,2));
- const auto & d = V.row(T(t,3));
- vol(t) = -(a-d).dot((b-d).cross(c-d))/6.;
- }
- }
- template <
- typename DerivedL,
- typename Derivedvol>
- IGL_INLINE void igl::volume(
- Eigen::PlainObjectBase<DerivedL>& L,
- Eigen::PlainObjectBase<Derivedvol>& vol)
- {
- using namespace Eigen;
- const int m = L.rows();
- typedef typename Derivedvol::Scalar ScalarS;
- vol.resize(m,1);
- for(int t = 0;t<m;t++)
- {
- const ScalarS u = L(t,0);
- const ScalarS v = L(t,1);
- const ScalarS w = L(t,2);
- const ScalarS U = L(t,3);
- const ScalarS V = L(t,4);
- const ScalarS W = L(t,5);
- const ScalarS X = (w - U + v)*(U + v + w);
- const ScalarS x = (U - v + w)*(v - w + U);
- const ScalarS Y = (u - V + w)*(V + w + u);
- const ScalarS y = (V - w + u)*(w - u + V);
- const ScalarS Z = (v - W + u)*(W + u + v);
- const ScalarS z = (W - u + v)*(u - v + W);
- const ScalarS a = sqrt(x*Y*Z);
- const ScalarS b = sqrt(y*Z*X);
- const ScalarS c = sqrt(z*X*Y);
- const ScalarS d = sqrt(x*y*z);
- vol(t) = sqrt(
- (-a + b + c + d)*
- ( a - b + c + d)*
- ( a + b - c + d)*
- ( a + b + c - d))/
- (192.*u*v*w);
- }
- }
- #ifndef IGL_HEADER_ONLY
- // Explicit template specialization
- // generated by autoexplicit.sh
- template void igl::volume<Eigen::Matrix<double, -1, 6, 0, -1, 6>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 6, 0, -1, 6> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
- #endif
|