searchtree in MakeAtlas

This commit is contained in:
Joachim Schöberl 2019-09-26 15:22:06 +02:00
parent e81e8f6f41
commit d1705be7a6
2 changed files with 31 additions and 56 deletions

View File

@ -19,6 +19,9 @@ int chartdebug = 0;
void STLGeometry :: MakeAtlas(Mesh & mesh, const MeshingParameters& mparam, const STLParameters& stlparam) void STLGeometry :: MakeAtlas(Mesh & mesh, const MeshingParameters& mparam, const STLParameters& stlparam)
{ {
static Timer t("makeatlas"); RegionTimer reg(t);
static Timer tinner("find innner chart");
static Timer touter("find outer chart");
// int timer1 = NgProfiler::CreateTimer ("makeatlas"); // int timer1 = NgProfiler::CreateTimer ("makeatlas");
/* /*
int timerb = NgProfiler::CreateTimer ("makeatlas - begin"); int timerb = NgProfiler::CreateTimer ("makeatlas - begin");
@ -183,7 +186,7 @@ void STLGeometry :: MakeAtlas(Mesh & mesh, const MeshingParameters& mparam, cons
// NgProfiler::StopTimer (timerb); // NgProfiler::StopTimer (timerb);
// NgProfiler::StartTimer (timer2); // NgProfiler::StartTimer (timer2);
tinner.Start();
while (changed) while (changed)
{ {
changed = false; changed = false;
@ -197,7 +200,7 @@ void STLGeometry :: MakeAtlas(Mesh & mesh, const MeshingParameters& mparam, cons
{ {
for (int j = 1; j <= NONeighbourTrigs(i); j++) for (int j = 1; j <= NONeighbourTrigs(i); j++)
{ {
int nt = NeighbourTrig(i,j); STLTrigId nt = NeighbourTrig(i,j);
// *testout << "check trig " << nt << endl; // *testout << "check trig " << nt << endl;
STLPointId np1, np2; STLPointId np1, np2;
GetTriangle(i).GetNeighbourPoints(GetTriangle(nt),np1,np2); GetTriangle(i).GetNeighbourPoints(GetTriangle(nt),np1,np2);
@ -316,6 +319,7 @@ void STLGeometry :: MakeAtlas(Mesh & mesh, const MeshingParameters& mparam, cons
} }
} }
} }
tinner.Stop();
innerchartpts.SetSize(innerchartpoints.Size()); innerchartpts.SetSize(innerchartpoints.Size());
for (size_t i = 0; i < innerchartpoints.Size(); i++) for (size_t i = 0; i < innerchartpoints.Size(); i++)
@ -330,7 +334,7 @@ void STLGeometry :: MakeAtlas(Mesh & mesh, const MeshingParameters& mparam, cons
// chartbound.Clear(); // chartbound.Clear();
// warum, ic-bound auf edge macht Probleme js ??? // warum, ic-bound auf edge macht Probleme js ???
touter.Start();
outermark[starttrig] = chartnum; outermark[starttrig] = chartnum;
//chart->AddOuterTrig(starttrig); //chart->AddOuterTrig(starttrig);
changed = true; changed = true;
@ -500,7 +504,7 @@ void STLGeometry :: MakeAtlas(Mesh & mesh, const MeshingParameters& mparam, cons
} }
} }
} }
touter.Stop();
// NgProfiler::StopTimer (timer3); // NgProfiler::StopTimer (timer3);
// NgProfiler::StartTimer (timere); // NgProfiler::StartTimer (timere);
// NgProfiler::StartTimer (timere1); // NgProfiler::StartTimer (timere1);

View File

@ -867,6 +867,7 @@ void STLBoundary :: AddOrDelSegment(const STLBoundarySeg & seg)
void STLBoundary ::AddTriangle(const STLTriangle & t) void STLBoundary ::AddTriangle(const STLTriangle & t)
{ {
// static Timer timer("STLBoundary::AddTriangle"); RegionTimer reg(timer);
// static int timer_old = NgProfiler::CreateTimer ("STLChart::AddTriangle_old"); // static int timer_old = NgProfiler::CreateTimer ("STLChart::AddTriangle_old");
// static int timer_new = NgProfiler::CreateTimer ("STLChart::AddTriangle_new"); // static int timer_new = NgProfiler::CreateTimer ("STLChart::AddTriangle_new");
@ -1009,9 +1010,17 @@ void STLBoundary ::AddTriangle(const STLTriangle & t)
INDEX_2 op(seg[1], seg[0]); INDEX_2 op(seg[1], seg[0]);
if (boundary_ht.Used(op)) if (boundary_ht.Used(op))
{
boundary_ht.Delete(op); boundary_ht.Delete(op);
if (searchtree)
searchtree->DeleteElement(op);
}
else else
{
boundary_ht[seg] = bseg; boundary_ht[seg] = bseg;
if (searchtree)
searchtree->Insert (bseg.BoundingBox(), seg);
}
} }
} }
@ -1211,54 +1220,32 @@ bool STLBoundary :: TestSeg(const Point<3>& p1, const Point<3> & p2, const Vec<3
void STLBoundary :: BuildSearchTree() void STLBoundary :: BuildSearchTree()
{ {
// static int timer = NgProfiler::CreateTimer ("BuildSearchTree");
// NgProfiler::RegionTimer reg(timer);
delete searchtree; delete searchtree;
/*
Box<2> box2d(Box<2>::EMPTY_BOX);
int nseg = NOSegments();
for (int j = 1; j <= nseg; j++)
{
const STLBoundarySeg & seg = GetSegment(j);
if (seg.IsSmoothEdge()) continue;
box2d.Add(seg.BoundingBox().PMin());
box2d.Add(seg.BoundingBox().PMax());
}
searchtree = new BoxTree<2> (box2d);
for (int j = 1; j <= nseg; j++)
{
const STLBoundarySeg & seg = GetSegment(j);
if (seg.IsSmoothEdge()) continue;
searchtree -> Insert (seg.BoundingBox(), j);
}
*/
Box<2> box2d(Box<2>::EMPTY_BOX); Box<2> box2d(Box<2>::EMPTY_BOX);
Box<3> box3d = geometry->GetBoundingBox(); Box<3> box3d = geometry->GetBoundingBox();
for (size_t i = 0; i < 8; i++) for (size_t i = 0; i < 8; i++)
box2d.Add ( chart->Project2d (box3d.GetPointNr(i))); box2d.Add ( chart->Project2d (box3d.GetPointNr(i)));
searchtree = new BoxTree<2,INDEX_2> (box2d);
// comment to enable searchtree:
// searchtree = new BoxTree<2,INDEX_2> (box2d);
searchtree = nullptr;
} }
void STLBoundary :: DeleteSearchTree() void STLBoundary :: DeleteSearchTree()
{ {
// static int timer = NgProfiler::CreateTimer ("DeleteSearchTree");
// NgProfiler::RegionTimer reg(timer);
delete searchtree; delete searchtree;
searchtree = nullptr; searchtree = nullptr;
} }
// checks, whether 2d projection intersects // checks, whether 2d projection intersects
bool STLBoundary :: TestSegChartNV(const Point3d & p1, const Point3d& p2, bool STLBoundary :: TestSegChartNV(const Point3d & p1, const Point3d& p2,
const Vec3d& sn) const Vec3d& sn)
{ {
// static int timerquick = NgProfiler::CreateTimer ("TestSegChartNV-searchtree"); // static int timerquick = NgProfiler::CreateTimer ("TestSegChartNV-searchtree");
// static int timer = NgProfiler::CreateTimer ("TestSegChartNV"); // static Timer timer("TestSegChartNV"); RegionTimer reg(timer);
Point<2> p2d1 = chart->Project2d (p1); Point<2> p2d1 = chart->Project2d (p1);
Point<2> p2d2 = chart->Project2d (p2); Point<2> p2d2 = chart->Project2d (p2);
@ -1272,26 +1259,12 @@ bool STLBoundary :: TestSegChartNV(const Point3d & p1, const Point3d& p2,
double eps = 1e-6; double eps = 1e-6;
bool ok = true; bool ok = true;
/* if (searchtree)
static long int cnt = 0;
static long int totnseg = 0;
totnseg += nseg;
cnt++;
if ( (cnt % 100000) == 0)
cout << "avg nseg = " << double(totnseg)/cnt << endl;
*/
// TODO: fix searchtree update
if (false)
{ {
// NgProfiler::RegionTimer reg(timerquick);
NgArrayMem<INDEX_2,100> pis; NgArrayMem<INDEX_2,100> pis;
searchtree -> GetIntersecting (box2d.PMin(), box2d.PMax(), pis); searchtree -> GetIntersecting (box2d.PMin(), box2d.PMax(), pis);
for (auto i2 : pis) for (auto i2 : pis)
{ {
// const STLBoundarySeg & seg = GetSegment(j);
const STLBoundarySeg & seg = boundary_ht[i2]; const STLBoundarySeg & seg = boundary_ht[i2];
if (seg.IsSmoothEdge()) continue; if (seg.IsSmoothEdge()) continue;
@ -1311,7 +1284,6 @@ bool STLBoundary :: TestSegChartNV(const Point3d & p1, const Point3d& p2,
if(!err && ((on1 && in2) || (on2 && in1))) if(!err && ((on1 && in2) || (on2 && in1)))
{ {
ok = false; ok = false;
break; break;
} }
@ -1320,7 +1292,6 @@ bool STLBoundary :: TestSegChartNV(const Point3d & p1, const Point3d& p2,
else else
{ {
// NgProfiler::RegionTimer reg(timer);
for(auto [i2, seg] : boundary_ht) for(auto [i2, seg] : boundary_ht)
{ {
if (seg.IsSmoothEdge()) continue; if (seg.IsSmoothEdge()) continue;