19 #ifndef CUBBYFLOW_LEVEL_SET_UTILS_IMPL_HPP 20 #define CUBBYFLOW_LEVEL_SET_UTILS_IMPL_HPP 47 return 0.5 + phi / 3.0 +
48 0.5 * (1 / PI<T>()) * std::sin(PI<T>() * phi / 1.5);
54 if (std::fabs(phi) > 1.5)
59 return 1.0 / 3.0 + 1.0 / 3.0 * std::cos(PI<T>() * phi / 1.5);
72 return phi0 / (phi0 - phi1);
77 return phi1 / (phi1 - phi0);
88 for (
int i = 0; i < size - 1; ++i)
97 T
FractionInside(T phiBottomLeft, T phiBottomRight, T phiTopLeft, T phiTopRight)
99 const int insideCount =
100 (phiBottomLeft < 0 ? 1 : 0) + (phiTopLeft < 0 ? 1 : 0) +
101 (phiBottomRight < 0 ? 1 : 0) + (phiTopRight < 0 ? 1 : 0);
102 T list[] = { phiBottomLeft, phiBottomRight, phiTopRight, phiTopLeft };
104 if (insideCount == 4)
109 if (insideCount == 3)
121 return 1 - 0.5f * side0 * side1;
124 if (insideCount == 2)
128 while (list[0] >= 0 || !(list[1] < 0 || list[2] < 0))
139 return 0.5f * (side_left + side_right);
144 T middle_point = 0.25f * (list[0] + list[1] + list[2] + list[3]);
145 if (middle_point < 0)
153 area += 0.5f * side1 * side3;
159 area += 0.5f * side0 * side2;
169 area += 0.5f * side0 * side1;
174 area += 0.5f * side2 * side3;
178 if (insideCount == 1)
190 return 0.5f * side0 * side1;
196 template <
typename T>
199 if (std::fabs(phi0) + std::fabs(phi1) >
200 std::numeric_limits<double>::epsilon())
202 return std::fabs(phi0) / (std::fabs(phi0) + std::fabs(phi1));
205 return static_cast<T
>(0.5);
T FractionInside(T phiBottomLeft, T phiBottomRight, T phiTopLeft, T phiTopRight)
Returns the fraction occupied by the implicit surface.
Definition: LevelSetUtils-Impl.hpp:97
bool IsInsideSDF(T phi)
Returns true if phi is inside the implicit surface (< 0).
Definition: LevelSetUtils-Impl.hpp:29
T FractionInsideSDF(T phi0, T phi1)
Returns the fraction occupied by the implicit surface.
Definition: LevelSetUtils-Impl.hpp:63
void CycleArray(T *arr, int size)
Definition: LevelSetUtils-Impl.hpp:84
T SmearedHeavisideSDF(T phi)
Returns smeared Heaviside function.
Definition: LevelSetUtils-Impl.hpp:35
Definition: pybind11Utils.hpp:20
T DistanceToZeroLevelSet(T phi0, T phi1)
Definition: LevelSetUtils-Impl.hpp:197
T SmearedDeltaSDF(T phi)
Returns smeared delta function.
Definition: LevelSetUtils-Impl.hpp:52