59 virtual void Delete(
const VecInt2d& a_polys, BSHP<TrTin> a_tin)
override;
95 TrOuterTriangleDeleterImpl::~TrOuterTriangleDeleterImpl()
113 for (
int i = 0; i < (int)
m_polys.size(); ++i)
124 for (
size_t i = 0; i <
m_polys.size(); ++i)
138 for (
size_t i = 0; i < flags.size(); ++i)
140 if (flags[i] & BE_OUTSIDE)
142 trisToDelete.insert((
int)i);
146 m_tin->DeleteTriangles(trisToDelete);
157 VecInt::const_iterator it0 = a_poly.begin();
158 VecInt::const_iterator it1 = it0;
161 for (; it1 != a_poly.end(); ++it0, ++it1)
165 inTri =
m_tin->TriangleAdjacentToEdge(*it0, *it1);
166 outTri =
m_tin->TriangleAdjacentToEdge(*it1, *it0);
171 if (!(a_flags[outTri] & BE_INSIDE))
172 a_flags[outTri] = BE_OUTSIDE | BE_ONBOUNDARY;
176 a_flags[inTri] = BE_INSIDE | BE_ONBOUNDARY;
192 int numTri =
m_tin->NumTriangles();
202 while (tri < numTri && tri != -1 && !found)
204 if (a_flags[tri] & BE_ONBOUNDARY && !(a_flags[tri] & BE_VISITED))
206 for (
int id = 0;
id < 3 && !found; ++id)
208 int adjTri =
m_tin->AdjacentTriangle(tri,
id);
209 if (adjTri != -1 && a_flags[adjTri] == BE_UNVISITED)
227 for (
size_t i = 0; i < a_flags.size(); ++i)
229 if (a_flags[i] == BE_UNVISITED)
231 a_flags[i] = BE_OUTSIDE;
240 for (
int i = 0; i < size; i++)
242 int currTri = stack[i];
243 a_flags[currTri] |= BE_VISITED;
248 int adjTri =
m_tin->AdjacentTriangle(currTri,
id);
249 if (adjTri != -1 && a_flags[adjTri] == BE_UNVISITED)
252 stack[size++] = adjTri;
253 if (a_flags[currTri] & BE_INSIDE)
254 a_flags[adjTri] = BE_INSIDE;
256 a_flags[adjTri] = BE_OUTSIDE;
282 TrOuterTriangleDeleter::TrOuterTriangleDeleter()
288 TrOuterTriangleDeleter::~TrOuterTriangleDeleter()
363 int outPoly[] = {0, 9, 17, 18, 19, 20, 21, 16, 8, 4, 3, 2, 1, 0};
364 int inPoly1[] = {10, 5, 6, 14, 10};
365 int inPoly2[] = {11, 7, 12, 15, 11};
366 polys.push_back(xms::VecInt(&outPoly[0], &outPoly[
XM_COUNTOF(outPoly)]));
367 polys.push_back(xms::VecInt(&inPoly1[0], &inPoly1[
XM_COUNTOF(inPoly1)]));
368 polys.push_back(xms::VecInt(&inPoly2[0], &inPoly2[
XM_COUNTOF(inPoly2)]));
371 deleter->Delete(polys, tin);
374 int trisA[] = {0, 5, 9, 5, 0, 1, 1, 2, 6, 14, 6, 11, 1, 6, 5, 9, 13, 17, 13,
375 9, 10, 17, 13, 18, 10, 14, 18, 18, 14, 19, 10, 18, 13, 9, 5, 10, 6, 2,
376 7, 7, 11, 6, 3, 4, 8, 3, 8, 7, 7, 2, 3, 12, 7, 8, 19, 15, 20,
377 15, 19, 11, 15, 12, 16, 20, 16, 21, 16, 20, 15, 12, 8, 16, 11, 19, 14};
378 xms::VecInt trisAfter(&trisA[0], &trisA[
XM_COUNTOF(trisA)]);
void FlagTrianglesAlongPolygon(const VecInt &a_poly, VecInt &a_flags)
Flag triangles along polygon as inside or outside the polygon.
BSHP< Observer > m_observer
Observer.
std::vector< int > VecInt
Functions dealing with triangles.
std::vector< VecInt > VecInt2d
#define XM_ENSURE_TRUE_VOID_NO_ASSERT(...)
BoundaryEnum
Flags used triangles.
static boost::shared_ptr< TrOuterTriangleDeleter > New()
Creates a TrOuterTriangleDeleterImpl object.
TrOuterTriangleDeleterImpl()
constructor
virtual void Delete(const VecInt2d &a_polys, BSHP< TrTin > a_tin) override
Deletes triangles in a_tin that are outside a_polys or inside if the poly is a hole.
#define XM_COUNTOF(array)
BSHP< TrTin > trBuildTestTin7()
Builds a simple TIN for testing.
void test1()
Tests TrOuterTriangleDeleter.
Used to delete tin triangles that are outside given polygons. The polygons may include holes - polygo...
virtual void SetObserver(BSHP< Observer > a_) override
Set the observer to use for feedback while processing.
int trIncrementIndex(int i)
Faster than a % operation and we do this a lot.
VecInt2d m_polys
Polygons (boundary and holes) of tin.
void MarkNeighbors(VecInt &a_flags)
Flag all triangles as inside or outside the polygon, starting with those already flagged and working ...