49 virtual void Fix(BSHP<TrTin> a_tin)
override;
58 m_noDelete.insert(a_ptIdx.begin(), a_ptIdx.end());
98 , m_removeAdjTris(false)
106 TrAutoFixFourTrianglePtsImpl::~TrAutoFixFourTrianglePtsImpl()
133 m_tin->BuildTrisAdjToPts();
145 int npts =
static_cast<int>(adjTris.size());
147 for (
int i = 0; i < npts; ++i)
150 if (4 == adjTris[i].size() && it == itEnd)
155 std::map<int, int> mapii;
156 for (
int t = 0; t < 4; ++t)
179 int tIdx = a_tri * 3;
180 int* tPts = &a_tris[tIdx];
181 std::pair<int, int> rval(tPts[0], tPts[1]);
182 if (tPts[0] == a_ptIdx)
184 rval.first = tPts[1];
185 rval.second = tPts[2];
187 else if (tPts[1] == a_ptIdx)
189 rval.first = tPts[2];
190 rval.second = tPts[0];
203 std::map<int, int> a_edges,
207 auto e = a_edges.begin();
208 for (
int t = 0; t < 4; ++t)
211 e = a_edges.find(e->second);
214 Pt3d &p0(a_pts[bound[0]]), &p1(a_pts[bound[1]]), &p2(a_pts[bound[2]]), &p3(a_pts[bound[3]]);
215 double d2_02 =
MdistSq(p0.x, p0.y, p2.x, p2.y);
216 double d2_13 =
MdistSq(p1.x, p1.y, p3.
x, p3.
y);
219 a_tris[0][0] = bound[0];
220 a_tris[0][1] = bound[1];
221 a_tris[0][2] = bound[2];
222 a_tris[1][0] = bound[0];
223 a_tris[1][1] = bound[2];
224 a_tris[1][2] = bound[3];
228 a_tris[0][0] = bound[0];
229 a_tris[0][1] = bound[1];
230 a_tris[0][2] = bound[3];
231 a_tris[1][0] = bound[1];
232 a_tris[1][1] = bound[2];
233 a_tris[1][2] = bound[3];
244 int tIdx = a_tIdx * 3;
245 for (
int i = 0; i < 3; ++i)
246 a_tris[tIdx + i] = a_newTri[i];
256 VecInt oldToNewPt(pts.size());
259 int cnt(0), npts(static_cast<int>(pts.size()));
260 for (
int i = 0; i < npts; ++i)
262 if (it != itEnd && i == *it)
267 oldToNewPt[i] = i - cnt;
281 int ntri =
static_cast<int>(
m_tin->Triangles().size() / 3);
282 VecInt oldToNewTris(ntri);
286 for (
int i = 0; i < ntri; ++i)
288 if (it != itEnd && i == *it)
293 oldToNewTris[i] = i - cnt;
297 for (
auto& v : adjTris)
309 for (; it != itEnd; ++it)
310 pts.erase(pts.begin() + *it);
321 delTris.insert(tIdx + 0);
322 delTris.insert(tIdx + 1);
323 delTris.insert(tIdx + 2);
327 auto it = delTris.rbegin();
328 auto itEnd = delTris.rend();
329 for (; it != itEnd; ++it)
330 tris.erase(tris.begin() + *it);
341 m_tin->BuildTrisAdjToPts();
360 TrAutoFixFourTrianglePts::TrAutoFixFourTrianglePts()
363 TrAutoFixFourTrianglePts::~TrAutoFixFourTrianglePts()
389 BSHP<VecPt3d> pts(
new VecPt3d());
390 *pts = {{0, 0}, {10, 0}, {0, 10}, {10, 10}, {5, 5}};
399 TS_ASSERT_EQUALS(4, tin->Points().size());
std::pair< int, int > EdgeOppositePt(int a_ptIdx, int a_tri, VecInt &a_tris)
Finds and removes the points connected to 4 triangles.
void RenumberTris()
Renumbers the triangle indexes in the adjacent triangles.
SetInt m_trisToDelete
triangles that will be deleted
TrAutoFixFourTrianglePtsImpl()
constructor
virtual void SetObserver(BSHP< Observer > a_) override
Set the observer to use for feedback while processing.
void RemoveTris()
Removes triangles from the triangles vector in the TIN.
std::vector< int > VecInt
static BSHP< TrTin > New()
Create a TrTinImpl object.
SetInt m_noDelete
indexes of points that can't be deleted
bool Triangulate()
Triangulate the points into a tin.
void FillAdjTrisIfNeeded()
Makes sure the adjacent triangles exist in the TIN.
BSHP< Observer > m_observer
Observer.
SetInt m_ptsToDelete
points in the TIN that will be deleted
void MakeTwoNewTriangles(VecPt3d &a_pts, std::map< int, int > a_edges, int a_tris[2][3])
Makes 2 new triangles from the 4 edges passed into this method.
std::vector< Pt3d > VecPt3d
static BSHP< TrAutoFixFourTrianglePts > New()
Creates a TrAutoFixFourTrianglePtsImpl object.
void ReplaceTriangle(int &a_tIdx, int a_newTri[3], VecInt &a_tris)
Makes 2 new triangles from the 4 edges passed into this method.
virtual void Fix(BSHP< TrTin > a_tin) override
Removes any points in the tin that are connected to only 4 triangles. These points usually cause poor...
void GetPtsAndTrisToDelete()
Finds and removes the points connected to 4 triangles.
Used to delete points that are connected to 4 triangles and then retriangulate the void...
void test1()
Tests TrAutoFixFourTrianglePts.
void ClearAdjTrisIfCreated()
Clears the adjacent triangles if this class created them.
void RemovePts()
Removes points from the points vector of the TIN.
virtual void SetUndeleteablePtIdxs(VecInt &a_ptIdx) override
Set the indexes of points that can not be deleted.
std::vector< VecInt > VecInt2d
void RenumberPts()
Renumbers the point indexes in the triangles.
double MdistSq(_T x1, _U y1, _V x2, _W y2)
bool m_removeAdjTris
flag to remove adjacent tris when done
Class to triangulate simple points.