18 #ifndef CUBBYFLOW_LEVEL_SET_UTILS_IMPL_H 19 #define CUBBYFLOW_LEVEL_SET_UTILS_IMPL_H 47 return 0.5f + phi / 3.0 + 0.5f * (1 / PI<T>()) * std::sin(PI<T>() * phi / 1.5);
53 if (std::fabs(phi) > 1.5)
58 return 1.0 / 3.0 + 1.0 / 3.0 * std::cos(PI<T>() * phi / 1.5);
71 return phi0 / (phi0 - phi1);
76 return phi1 / (phi1 - phi0);
87 for (
int i = 0; i < size - 1; ++i)
96 T
FractionInside(T phiBottomLeft, T phiBottomRight, T phiTopLeft, T phiTopRight)
98 int insideCount = (phiBottomLeft < 0 ? 1 : 0) + (phiTopLeft < 0 ? 1 : 0) + (phiBottomRight < 0 ? 1 : 0) + (phiTopRight < 0 ? 1 : 0);
99 T list[] = { phiBottomLeft, phiBottomRight, phiTopRight, phiTopLeft };
101 if (insideCount == 4)
106 if (insideCount == 3)
118 return 1 - 0.5f * side0 * side1;
121 if (insideCount == 2)
125 while (list[0] >= 0 || !(list[1] < 0 || list[2] < 0))
136 return 0.5f * (side_left + side_right);
141 T middle_point = 0.25f * (list[0] + list[1] + list[2] + list[3]);
142 if (middle_point < 0)
150 area += 0.5f * side1 * side3;
156 area += 0.5f * side0 * side2;
166 area += 0.5f * side0 * side1;
171 area += 0.5f * side2 * side3;
175 if (insideCount == 1)
187 return 0.5f * side0 * side1;
193 template <
typename T>
196 if (std::fabs(phi0) + std::fabs(phi1) > std::numeric_limits<double>::epsilon())
198 return std::fabs(phi0) / (std::fabs(phi0) + std::fabs(phi1));
201 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.h:96
bool IsInsideSDF(T phi)
Returns true if phi is inside the implicit surface (< 0).
Definition: LevelSetUtils-Impl.h:29
T FractionInsideSDF(T phi0, T phi1)
Returns the fraction occupied by the implicit surface.
Definition: LevelSetUtils-Impl.h:62
void CycleArray(T *arr, int size)
Definition: LevelSetUtils-Impl.h:83
T SmearedHeavisideSDF(T phi)
Returns smeared Heaviside function.
Definition: LevelSetUtils-Impl.h:35
Definition: pybind11Utils.h:24
T DistanceToZeroLevelSet(T phi0, T phi1)
Definition: LevelSetUtils-Impl.h:194
T SmearedDeltaSDF(T phi)
Returns smeared delta function.
Definition: LevelSetUtils-Impl.h:51