48 virtual void Fix(BSHP<TrTin> a_tin)
override;
57 m_noDelete.insert(a_ptIdx.begin(), a_ptIdx.end());
97 , m_removeAdjTris(false)
105 TrAutoFixFourTrianglePtsImpl::~TrAutoFixFourTrianglePtsImpl()
132 m_tin->BuildTrisAdjToPts();
144 int npts =
static_cast<int>(adjTris.size());
146 for (
int i = 0; i < npts; ++i)
149 if (4 == adjTris[i].size() && it == itEnd)
154 std::map<int, int> mapii;
155 for (
int t = 0; t < 4; ++t)
178 int tIdx = a_tri * 3;
179 int* tPts = &a_tris[tIdx];
180 std::pair<int, int> rval(tPts[0], tPts[1]);
181 if (tPts[0] == a_ptIdx)
183 rval.first = tPts[1];
184 rval.second = tPts[2];
186 else if (tPts[1] == a_ptIdx)
188 rval.first = tPts[2];
189 rval.second = tPts[0];
202 std::map<int, int> a_edges,
206 auto e = a_edges.begin();
207 for (
int t = 0; t < 4; ++t)
210 e = a_edges.find(e->second);
213 Pt3d &p0(a_pts[bound[0]]), &p1(a_pts[bound[1]]), &p2(a_pts[bound[2]]), &p3(a_pts[bound[3]]);
214 double d2_02 =
MdistSq(p0.x, p0.y, p2.x, p2.y);
215 double d2_13 =
MdistSq(p1.x, p1.y, p3.
x, p3.
y);
218 a_tris[0][0] = bound[0];
219 a_tris[0][1] = bound[1];
220 a_tris[0][2] = bound[2];
221 a_tris[1][0] = bound[0];
222 a_tris[1][1] = bound[2];
223 a_tris[1][2] = bound[3];
227 a_tris[0][0] = bound[0];
228 a_tris[0][1] = bound[1];
229 a_tris[0][2] = bound[3];
230 a_tris[1][0] = bound[1];
231 a_tris[1][1] = bound[2];
232 a_tris[1][2] = bound[3];
243 int tIdx = a_tIdx * 3;
244 for (
int i = 0; i < 3; ++i)
245 a_tris[tIdx + i] = a_newTri[i];
255 VecInt oldToNewPt(pts.size());
258 int cnt(0), npts(static_cast<int>(pts.size()));
259 for (
int i = 0; i < npts; ++i)
261 if (it != itEnd && i == *it)
266 oldToNewPt[i] = i - cnt;
280 int ntri =
static_cast<int>(
m_tin->Triangles().size() / 3);
281 VecInt oldToNewTris(ntri);
285 for (
int i = 0; i < ntri; ++i)
287 if (it != itEnd && i == *it)
292 oldToNewTris[i] = i - cnt;
296 for (
auto& v : adjTris)
308 for (; it != itEnd; ++it)
309 pts.erase(pts.begin() + *it);
320 delTris.insert(tIdx + 0);
321 delTris.insert(tIdx + 1);
322 delTris.insert(tIdx + 2);
326 auto it = delTris.rbegin();
327 auto itEnd = delTris.rend();
328 for (; it != itEnd; ++it)
329 tris.erase(tris.begin() + *it);
340 m_tin->BuildTrisAdjToPts();
359 TrAutoFixFourTrianglePts::TrAutoFixFourTrianglePts()
362 TrAutoFixFourTrianglePts::~TrAutoFixFourTrianglePts()
388 BSHP<VecPt3d> pts(
new VecPt3d());
389 *pts = {{0, 0}, {10, 0}, {0, 10}, {10, 10}, {5, 5}};
398 TS_ASSERT_EQUALS(4, tin->Points().size());
std::vector< int > VecInt
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< VecInt > VecInt2d
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.
double MdistSq(_T x1, _U y1, _V x2, _W y2)
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.
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.
void RenumberPts()
Renumbers the point indexes in the triangles.
bool m_removeAdjTris
flag to remove adjacent tris when done
Class to triangulate simple points.
std::vector< Pt3d > VecPt3d