BinaryWindingNumberOperations.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Qingnan Zhou <qnzhou@gmail.com>
  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. //
  9. #ifndef IGL_COPYLEFT_BOOLEAN_BINARY_WINDING_NUMBER_OPERATIONS_H
  10. #define IGL_COPYLEFT_BOOLEAN_BINARY_WINDING_NUMBER_OPERATIONS_H
  11. #include <stdexcept>
  12. #include "../../igl_inline.h"
  13. #include "MeshBooleanType.h"
  14. #include <Eigen/Core>
  15. namespace igl
  16. {
  17. namespace copyleft
  18. {
  19. namespace boolean
  20. {
  21. template <igl::copyleft::boolean::MeshBooleanType Op>
  22. class BinaryWindingNumberOperations {
  23. public:
  24. template<typename DerivedW>
  25. typename DerivedW::Scalar operator()(
  26. const Eigen::PlainObjectBase<DerivedW>& /*win_nums*/) const {
  27. throw (std::runtime_error("not implemented!"));
  28. }
  29. };
  30. template <>
  31. class BinaryWindingNumberOperations<MESH_BOOLEAN_TYPE_UNION> {
  32. public:
  33. template<typename DerivedW>
  34. typename DerivedW::Scalar operator()(
  35. const Eigen::PlainObjectBase<DerivedW>& win_nums) const {
  36. return win_nums(0) > 0 || win_nums(1) > 0;
  37. }
  38. };
  39. template <>
  40. class BinaryWindingNumberOperations<MESH_BOOLEAN_TYPE_INTERSECT> {
  41. public:
  42. template<typename DerivedW>
  43. typename DerivedW::Scalar operator()(
  44. const Eigen::PlainObjectBase<DerivedW>& win_nums) const {
  45. return win_nums(0) > 0 && win_nums(1) > 0;
  46. }
  47. };
  48. template <>
  49. class BinaryWindingNumberOperations<MESH_BOOLEAN_TYPE_MINUS> {
  50. public:
  51. template<typename DerivedW>
  52. typename DerivedW::Scalar operator()(
  53. const Eigen::PlainObjectBase<DerivedW>& win_nums) const {
  54. return win_nums(0) > 0 && win_nums(1) <= 0;
  55. }
  56. };
  57. template <>
  58. class BinaryWindingNumberOperations<MESH_BOOLEAN_TYPE_XOR> {
  59. public:
  60. template<typename DerivedW>
  61. typename DerivedW::Scalar operator()(
  62. const Eigen::PlainObjectBase<DerivedW>& win_nums) const {
  63. return (win_nums(0) > 0 && win_nums(1) <= 0) ||
  64. (win_nums(0) <= 0 && win_nums(1) > 0);
  65. }
  66. };
  67. template <>
  68. class BinaryWindingNumberOperations<igl::copyleft::boolean::MESH_BOOLEAN_TYPE_RESOLVE> {
  69. public:
  70. template<typename DerivedW>
  71. typename DerivedW::Scalar operator()(
  72. const Eigen::PlainObjectBase<DerivedW>& /*win_nums*/) const {
  73. return true;
  74. }
  75. };
  76. typedef BinaryWindingNumberOperations<MESH_BOOLEAN_TYPE_UNION> BinaryUnion;
  77. typedef BinaryWindingNumberOperations<MESH_BOOLEAN_TYPE_INTERSECT> BinaryIntersect;
  78. typedef BinaryWindingNumberOperations<MESH_BOOLEAN_TYPE_MINUS> BinaryMinus;
  79. typedef BinaryWindingNumberOperations<MESH_BOOLEAN_TYPE_XOR> BinaryXor;
  80. typedef BinaryWindingNumberOperations<MESH_BOOLEAN_TYPE_RESOLVE> BinaryResolve;
  81. enum KeeperType {
  82. KEEP_INSIDE,
  83. KEEP_ALL
  84. };
  85. template<KeeperType T>
  86. class WindingNumberFilter {
  87. public:
  88. template<typename DerivedW>
  89. short operator()(
  90. const Eigen::PlainObjectBase<DerivedW>& /*win_nums*/) const {
  91. throw std::runtime_error("Not implemented");
  92. }
  93. };
  94. template<>
  95. class WindingNumberFilter<KEEP_INSIDE> {
  96. public:
  97. template<typename T>
  98. short operator()(T out_w, T in_w) const {
  99. if (in_w > 0 && out_w <= 0) return 1;
  100. else if (in_w <= 0 && out_w > 0) return -1;
  101. else return 0;
  102. }
  103. };
  104. template<>
  105. class WindingNumberFilter<KEEP_ALL> {
  106. public:
  107. template<typename T>
  108. short operator()(T /*out_w*/, T /*in_w*/) const {
  109. return 1;
  110. }
  111. };
  112. typedef WindingNumberFilter<KEEP_INSIDE> KeepInside;
  113. typedef WindingNumberFilter<KEEP_ALL> KeepAll;
  114. }
  115. }
  116. }
  117. #endif