Use searchtree in STLBoundary

This commit is contained in:
Matthias Hochsteger 2019-10-01 11:23:22 +02:00
parent ef64a5e7eb
commit 7ced41e56f
5 changed files with 97 additions and 103 deletions

View File

@ -741,10 +741,10 @@ public:
const ADTree3 & Tree() const { return *tree; };
};
template<int dim, typename T=INDEX>
class BoxTree
{
public:
template<int dim, typename T=INDEX>
class BoxTree
{
public:
// Number of entries per leaf
static constexpr int N = 100;
@ -756,7 +756,8 @@ public:
T index[N];
int n_elements;
Leaf() : n_elements(0) {}
Leaf() : n_elements(0)
{ }
void Add( ClosedHashTable<T, Leaf*> &leaf_index, const Point<2*dim> &ap, T aindex )
{
@ -790,10 +791,9 @@ public:
}
};
private:
private:
Node root;
// Array<Leaf*, INDEX> leaf_index;
ClosedHashTable<T, Leaf*> leaf_index;
Point<dim> global_min, global_max;
@ -803,10 +803,7 @@ public:
BlockAllocator ball_nodes;
BlockAllocator ball_leaves;
public:
BoxTree (const Box<dim> & abox)
: BoxTree( abox.PMin(), abox.PMax() )
{ }
public:
BoxTree (const Point<dim> & pmin, const Point<dim> & pmax)
: global_min(pmin), global_max(pmax), n_leaves(1), n_nodes(1), ball_nodes(sizeof(Node)), ball_leaves(sizeof(Leaf))
@ -816,6 +813,10 @@ public:
tol = 1e-7 * Dist(pmax, pmin);
}
BoxTree (const Box<dim> & box)
: BoxTree(box.PMin(), box.PMax())
{ }
size_t GetNLeaves()
{
return n_leaves;
@ -830,8 +831,8 @@ public:
void GetFirstIntersecting (const Point<dim> & pmin, const Point<dim> & pmax,
TFunc func=[](auto pi){return false;}) const
{
// static Timer timer("BTree::GetIntersecting"); RegionTimer rt(timer);
// static Timer timer1("BTree::GetIntersecting-LinearSearch");
// static Timer timer("BoxTree::GetIntersecting"); RegionTimer rt(timer);
// static Timer timer1("BoxTree::GetIntersecting-LinearSearch");
ArrayMem<const Node*, 100> stack;
ArrayMem<int, 100> dir_stack;
@ -862,7 +863,7 @@ public:
if(Leaf *leaf = node->GetLeaf())
{
// RegionTimer rt1(timer1);
// RegionTimer rt1(timer1);
for (auto i : IntRange(leaf->n_elements))
{
bool intersect = true;
@ -910,7 +911,7 @@ public:
void Insert (const Point<dim> & pmin, const Point<dim> & pmax, T pi)
{
// static Timer timer("BTree::Insert"); RegionTimer rt(timer);
// static Timer timer("BoxTree::Insert"); RegionTimer rt(timer);
int dir = 0;
Point<2*dim> p;
for (auto i : IntRange(dim))
@ -984,7 +985,7 @@ public:
void DeleteElement (T pi)
{
// static Timer timer("BTree::DeleteElement"); RegionTimer rt(timer);
// static Timer timer("BoxTree::DeleteElement"); RegionTimer rt(timer);
Leaf *leaf = leaf_index[pi];
leaf_index.Delete(pi);
auto & n_elements = leaf->n_elements;
@ -1005,7 +1006,7 @@ public:
}
}
}
};
};
// template <int dim, typename T = INDEX>
// class BoxTree

View File

@ -5,10 +5,6 @@
namespace netgen
{
// typedef BTree<3> TBoxTree;
typedef BoxTree<3> TBoxTree;
static const int deltetfaces[][3] =
{ { 1, 2, 3 },
{ 2, 0, 3 },
@ -231,7 +227,7 @@ namespace netgen
void AddDelaunayPoint (PointIndex newpi, const Point3d & newp,
NgArray<DelaunayTet> & tempels,
Mesh & mesh,
TBoxTree & tettree,
BoxTree<3> & tettree,
MeshNB & meshnb,
NgArray<Point<3> > & centers, NgArray<double> & radi2,
NgArray<int> & connected, NgArray<int> & treesearch,
@ -639,7 +635,7 @@ namespace netgen
pmin2 = pmin2 + 0.1 * (pmin2 - pmax2);
pmax2 = pmax2 + 0.1 * (pmax2 - pmin2);
TBoxTree tettree(pmin2, pmax2);
BoxTree<3> tettree(pmin2, pmax2);
tempels.Append (startel);

View File

@ -146,8 +146,6 @@ void STLGeometry :: MakeAtlas(Mesh & mesh, const MeshingParameters& mparam, cons
chartbound.Clear();
chartbound.SetChart(&chart);
chartbound.BuildSearchTree(); // different !!!
if (!found) throw Exception("Make Atlas, no starttrig found");
//find surrounding trigs
@ -324,7 +322,6 @@ void STLGeometry :: MakeAtlas(Mesh & mesh, const MeshingParameters& mparam, cons
innerchartpts.SetSize(innerchartpoints.Size());
for (size_t i = 0; i < innerchartpoints.Size(); i++)
innerchartpts[i] = GetPoint(innerchartpoints[i]);
// chartbound.BuildSearchTree(); // different !!!
// NgProfiler::StopTimer (timer2);
// NgProfiler::StartTimer (timer3);

View File

@ -1095,6 +1095,9 @@ void STLBoundary ::AddTriangle(const STLTriangle & t)
segs[1] = INDEX_2(t[1], t[2]);
segs[2] = INDEX_2(t[2], t[0]);
if(!searchtree)
BuildSearchTree();
for (auto seg : segs)
{
STLBoundarySeg bseg(seg[0], seg[1], geometry->GetPoints(), chart);
@ -1312,21 +1315,18 @@ bool STLBoundary :: TestSeg(const Point<3>& p1, const Point<3> & p2, const Vec<3
void STLBoundary :: BuildSearchTree()
{
delete searchtree;
Box<2> box2d(Box<2>::EMPTY_BOX);
Box<3> box3d = geometry->GetBoundingBox();
for (size_t i = 0; i < 8; i++)
box2d.Add ( chart->Project2d (box3d.GetPointNr(i)));
// comment to enable searchtree:
// searchtree = new BoxTree<2,INDEX_2> (box2d);
searchtree = nullptr;
searchtree = make_unique<BoxTree<2,INDEX_2>> (box2d);
// searchtree = nullptr;
}
void STLBoundary :: DeleteSearchTree()
{
delete searchtree;
searchtree = nullptr;
}

View File

@ -191,10 +191,10 @@ private:
const STLChart * chart;
// NgArray<STLBoundarySeg> boundary;
ClosedHashTable<INDEX_2, STLBoundarySeg> boundary_ht;
BoxTree<2,INDEX_2> * searchtree = nullptr;
unique_ptr<BoxTree<2,INDEX_2>> searchtree;
public:
STLBoundary(STLGeometry * ageometry);
~STLBoundary() { delete searchtree; }
~STLBoundary() {}
void Clear() { /* boundary.SetSize(0); */ boundary_ht = ClosedHashTable<INDEX_2,STLBoundarySeg>(); }
void SetChart (const STLChart * achart) { chart = achart; }