123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- #pragma once
- #include <Mathematics/CurveExtractor.h>
- namespace WwiseGTE
- {
-
-
-
-
- template <typename T, typename Real>
- class CurveExtractorTriangles : public CurveExtractor<T, Real>
- {
- public:
-
- typedef typename CurveExtractor<T, Real>::Vertex Vertex;
- typedef typename CurveExtractor<T, Real>::Edge Edge;
-
-
-
-
-
-
- CurveExtractorTriangles(int xBound, int yBound, T const* inputPixels)
- :
- CurveExtractor<T, Real>(xBound, yBound, inputPixels)
- {
- }
-
-
- virtual void Extract(T level, std::vector<Vertex>& vertices,
- std::vector<Edge>& edges) override
- {
-
- int64_t levelI64 = static_cast<int64_t>(level);
- for (size_t i = 0; i < this->mPixels.size(); ++i)
- {
- int64_t inputI64 = static_cast<int64_t>(this->mInputPixels[i]);
- this->mPixels[i] = inputI64 - levelI64;
- }
- vertices.clear();
- edges.clear();
- for (int y = 0, yp = 1; yp < this->mYBound; ++y, ++yp)
- {
- int yParity = (y & 1);
- for (int x = 0, xp = 1; xp < this->mXBound; ++x, ++xp)
- {
- int xParity = (x & 1);
-
- int i00 = x + this->mXBound * y;
- int i10 = i00 + 1;
- int i01 = i00 + this->mXBound;
- int i11 = i10 + this->mXBound;
- int64_t f00 = this->mPixels[i00];
- int64_t f10 = this->mPixels[i10];
- int64_t f01 = this->mPixels[i01];
- int64_t f11 = this->mPixels[i11];
-
-
-
-
- if (xParity == yParity)
- {
- ProcessTriangle(vertices, edges, x, y, f00, x, yp, f01, xp, y, f10);
- ProcessTriangle(vertices, edges, xp, yp, f11, xp, y, f10, x, yp, f01);
- }
- else
- {
- ProcessTriangle(vertices, edges, x, yp, f01, xp, yp, f11, x, y, f00);
- ProcessTriangle(vertices, edges, xp, y, f10, x, y, f00, xp, yp, f11);
- }
- }
- }
- }
- protected:
- void ProcessTriangle(std::vector<Vertex>& vertices, std::vector<Edge>& edges,
- int64_t x0, int64_t y0, int64_t f0,
- int64_t x1, int64_t y1, int64_t f1,
- int64_t x2, int64_t y2, int64_t f2)
- {
- int64_t xn0, yn0, xn1, yn1, d0, d1;
- if (f0 != 0)
- {
-
- if (f0 < 0)
- {
- f0 = -f0;
- f1 = -f1;
- f2 = -f2;
- }
- if (f1 > 0)
- {
- if (f2 > 0)
- {
-
- return;
- }
- else if (f2 < 0)
- {
-
- d0 = f0 - f2;
- xn0 = f0 * x2 - f2 * x0;
- yn0 = f0 * y2 - f2 * y0;
- d1 = f1 - f2;
- xn1 = f1 * x2 - f2 * x1;
- yn1 = f1 * y2 - f2 * y1;
- this->AddEdge(vertices, edges, xn0, d0, yn0, d0, xn1, d1, yn1, d1);
- }
- else
- {
-
- this->AddVertex(vertices, x2, 1, y2, 1);
- }
- }
- else if (f1 < 0)
- {
- d0 = f0 - f1;
- xn0 = f0 * x1 - f1 * x0;
- yn0 = f0 * y1 - f1 * y0;
- if (f2 > 0)
- {
-
- d1 = f2 - f1;
- xn1 = f2 * x1 - f1 * x2;
- yn1 = f2 * y1 - f1 * y2;
- this->AddEdge(vertices, edges, xn0, d0, yn0, d0, xn1, d1, yn1, d1);
- }
- else if (f2 < 0)
- {
-
- d1 = f2 - f0;
- xn1 = f2 * x0 - f0 * x2;
- yn1 = f2 * y0 - f0 * y2;
- this->AddEdge(vertices, edges, xn0, d0, yn0, d0, xn1, d1, yn1, d1);
- }
- else
- {
-
- this->AddEdge(vertices, edges, x2, 1, y2, 1, xn0, d0, yn0, d0);
- }
- }
- else
- {
- if (f2 > 0)
- {
-
- this->AddVertex(vertices, x1, 1, y1, 1);
- }
- else if (f2 < 0)
- {
-
- d0 = f2 - f0;
- xn0 = f2 * x0 - f0 * x2;
- yn0 = f2 * y0 - f0 * y2;
- this->AddEdge(vertices, edges, x1, 1, y1, 1, xn0, d0, yn0, d0);
- }
- else
- {
-
- this->AddEdge(vertices, edges, x1, 1, y1, 1, x2, 1, y2, 1);
- }
- }
- }
- else if (f1 != 0)
- {
-
- if (f1 < 0)
- {
- f1 = -f1;
- f2 = -f2;
- }
- if (f2 > 0)
- {
-
- this->AddVertex(vertices, x0, 1, y0, 1);
- }
- else if (f2 < 0)
- {
-
- d0 = f1 - f2;
- xn0 = f1 * x2 - f2 * x1;
- yn0 = f1 * y2 - f2 * y1;
- this->AddEdge(vertices, edges, x0, 1, y0, 1, xn0, d0, yn0, d0);
- }
- else
- {
-
- this->AddEdge(vertices, edges, x0, 1, y0, 1, x2, 1, y2, 1);
- }
- }
- else if (f2 != 0)
- {
-
- this->AddEdge(vertices, edges, x0, 1, y0, 1, x1, 1, y1, 1);
- }
- else
- {
-
- this->AddEdge(vertices, edges, x0, 1, y0, 1, x1, 1, y1, 1);
- this->AddEdge(vertices, edges, x1, 1, y1, 1, x2, 1, y2, 1);
- this->AddEdge(vertices, edges, x2, 1, y2, 1, x0, 1, y0, 1);
- }
- }
- };
- }
|