The base artifact classifier recognizes artifacts based on the contents of the SDF alone.
| 24 | |
| 25 | /// The base artifact classifier recognizes artifacts based on the contents of the SDF alone. |
| 26 | class BaseArtifactClassifier { |
| 27 | public: |
| 28 | inline BaseArtifactClassifier(double span, bool protectedFlag) : span(span), protectedFlag(protectedFlag) { } |
| 29 | /// Evaluates if the median value xm interpolated at xt in the range between am at at and bm at bt indicates an artifact. |
| 30 | inline int rangeTest(double at, double bt, double xt, float am, float bm, float xm) const { |
| 31 | // For protected texels, only consider inversion artifacts (interpolated median has different sign than boundaries). For the rest, it is sufficient that the interpolated median is outside its boundaries. |
| 32 | if ((am > .5f && bm > .5f && xm <= .5f) || (am < .5f && bm < .5f && xm >= .5f) || (!protectedFlag && median(am, bm, xm) != xm)) { |
| 33 | double axSpan = (xt-at)*span, bxSpan = (bt-xt)*span; |
| 34 | // Check if the interpolated median's value is in the expected range based on its distance (span) from boundaries a, b. |
| 35 | if (!(xm >= am-axSpan && xm <= am+axSpan && xm >= bm-bxSpan && xm <= bm+bxSpan)) |
| 36 | return CLASSIFIER_FLAG_CANDIDATE|CLASSIFIER_FLAG_ARTIFACT; |
| 37 | return CLASSIFIER_FLAG_CANDIDATE; |
| 38 | } |
| 39 | return 0; |
| 40 | } |
| 41 | /// Returns true if the combined results of the tests performed on the median value m interpolated at t indicate an artifact. |
| 42 | inline bool evaluate(double t, float m, int flags) const { |
| 43 | return (flags&2) != 0; |
| 44 | } |
| 45 | private: |
| 46 | double span; |
| 47 | bool protectedFlag; |
| 48 | }; |
| 49 | |
| 50 | /// The shape distance checker evaluates the exact shape distance to find additional artifacts at a significant performance cost. |
| 51 | template <template <typename> class ContourCombiner, int N> |