insphere.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2019 Qingnan Zhou <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "insphere.h"
  9. #include <predicates.h>
  10. namespace igl {
  11. namespace predicates {
  12. using REAL = IGL_PREDICATES_REAL;
  13. #include "IGL_PREDICATES_ASSERT_SCALAR.h"
  14. template<typename Vector3D>
  15. IGL_INLINE Orientation insphere(
  16. const Eigen::MatrixBase<Vector3D>& pa,
  17. const Eigen::MatrixBase<Vector3D>& pb,
  18. const Eigen::MatrixBase<Vector3D>& pc,
  19. const Eigen::MatrixBase<Vector3D>& pd,
  20. const Eigen::MatrixBase<Vector3D>& pe)
  21. {
  22. EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Vector3D, 3);
  23. IGL_PREDICATES_ASSERT_SCALAR(Vector3D);
  24. using Point = Eigen::Matrix<REAL, 3, 1>;
  25. Point a{pa[0], pa[1], pa[2]};
  26. Point b{pb[0], pb[1], pb[2]};
  27. Point c{pc[0], pc[1], pc[2]};
  28. Point d{pd[0], pd[1], pd[2]};
  29. Point e{pe[0], pe[1], pe[2]};
  30. const auto r = ::insphere(a.data(), b.data(), c.data(), d.data(), e.data());
  31. if (r > 0) return Orientation::INSIDE;
  32. else if (r < 0) return Orientation::OUTSIDE;
  33. else return Orientation::COSPHERICAL;
  34. }
  35. }
  36. }
  37. #ifdef IGL_STATIC_LIBRARY
  38. #define IGL_INSPHERE(Vector) template igl::predicates::Orientation igl::predicates::insphere<Vector>(const Eigen::MatrixBase<Vector>&, const Eigen::MatrixBase<Vector>&, const Eigen::MatrixBase<Vector>&, const Eigen::MatrixBase<Vector>&, const Eigen::MatrixBase<Vector>&)
  39. #define IGL_MATRIX(T, R, C) Eigen::Matrix<T, R, C>
  40. IGL_INSPHERE(IGL_MATRIX(float, 1, 3));
  41. IGL_INSPHERE(IGL_MATRIX(float, 3, 1));
  42. #ifndef LIBIGL_PREDICATES_USE_FLOAT
  43. IGL_INSPHERE(IGL_MATRIX(double, 1, 3));
  44. IGL_INSPHERE(IGL_MATRIX(double, 3, 1));
  45. #endif
  46. #undef IGL_MATRIX
  47. #undef IGL_INSPHERE
  48. #endif