Path: blob/devel/ElmerGUI/netgen/libsrc/gprim/adtree.hpp
3206 views
#ifndef FILE_ADTREE1#define FILE_ADTREE23/* *************************************************************************/4/* File: adtree.hh */5/* Author: Joachim Schoeberl */6/* Date: 16. Feb. 98 */7/* Redesigned by Wolfram Muehlhuber, May 1998 */8/* *************************************************************************/9101112/**13Alternating Digital Tree14*/1516#include "../include/mystdlib.h"17#include "../include/myadt.hpp"1819class ADTreeNode20{21public:22ADTreeNode *left, *right, *father;23int dim;24float sep;25float *data;26float *boxmin;27float *boxmax;28int pi;29int nchilds;3031ADTreeNode (int adim);32~ADTreeNode ();3334friend class ADTree;35};363738class ADTreeCriterion39{40public:41ADTreeCriterion() { }42virtual int Eval (const ADTreeNode * node) const = 0;43};444546class ADTree47{48int dim;49ADTreeNode * root;50float *cmin, *cmax;51ARRAY<ADTreeNode*> ela;52const ADTreeCriterion * criterion;5354ARRAY<ADTreeNode*> stack;55ARRAY<int> stackdir;56int stackindex;5758public:59ADTree (int adim, const float * acmin,60const float * acmax);61~ADTree ();6263void Insert (const float * p, int pi);64// void GetIntersecting (const float * bmin, const float * bmax,65// ARRAY<int> & pis) const;66void SetCriterion (ADTreeCriterion & acriterion);67void Reset ();68int Next ();69void GetMatch (ARRAY<int> & matches);7071void DeleteElement (int pi);727374void Print (ostream & ost) const75{ PrintRec (ost, root); }7677void PrintRec (ostream & ost, const ADTreeNode * node) const;78};79808182class ADTreeNode383{84public:85ADTreeNode3 *left, *right, *father;86float sep;87float data[3];88int pi;89int nchilds;9091ADTreeNode3 ();92void DeleteChilds ();93friend class ADTree3;9495static BlockAllocator ball;96void * operator new(size_t);97void operator delete (void *);98};99100101class ADTree3102{103ADTreeNode3 * root;104float cmin[3], cmax[3];105ARRAY<ADTreeNode3*> ela;106107public:108ADTree3 (const float * acmin,109const float * acmax);110~ADTree3 ();111112void Insert (const float * p, int pi);113void GetIntersecting (const float * bmin, const float * bmax,114ARRAY<int> & pis) const;115116void DeleteElement (int pi);117118119void Print (ostream & ost) const120{ PrintRec (ost, root); }121122void PrintRec (ostream & ost, const ADTreeNode3 * node) const;123};124125126/*127128// divide each direction129#define ADTN_DIV 10130class ADTreeNode3Div131{132public:133ADTreeNode3Div *father;134ADTreeNode3Div *childs[ADTN_DIV];135136float minx, dist;137float data[3];138int pi;139int nchilds;140141ADTreeNode3Div ();142void DeleteChilds ();143friend class ADTree3Div;144145static BlockAllocator ball;146void * operator new(size_t);147void operator delete (void *);148};149150151class ADTree3Div152{153ADTreeNode3Div * root;154float cmin[3], cmax[3];155ARRAY<ADTreeNode3Div*> ela;156157public:158ADTree3Div (const float * acmin,159const float * acmax);160~ADTree3Div ();161162void Insert (const float * p, int pi);163void GetIntersecting (const float * bmin, const float * bmax,164ARRAY<int> & pis) const;165166void DeleteElement (int pi);167168169void Print (ostream & ost) const170{ PrintRec (ost, root); }171172void PrintRec (ostream & ost, const ADTreeNode3Div * node) const;173};174175176177178#define ADTN_SIZE 10179180// multiple entries181class ADTreeNode3M182{183public:184ADTreeNode3M *left, *right, *father;185float sep;186float data[ADTN_SIZE][3];187int pi[ADTN_SIZE];188int nchilds;189190ADTreeNode3M ();191void DeleteChilds ();192friend class ADTree3M;193194static BlockAllocator ball;195void * operator new(size_t);196void operator delete (void *);197};198199200class ADTree3M201{202ADTreeNode3M * root;203float cmin[3], cmax[3];204ARRAY<ADTreeNode3M*> ela;205206public:207ADTree3M (const float * acmin,208const float * acmax);209~ADTree3M ();210211void Insert (const float * p, int pi);212void GetIntersecting (const float * bmin, const float * bmax,213ARRAY<int> & pis) const;214215void DeleteElement (int pi);216217218void Print (ostream & ost) const219{ PrintRec (ost, root); }220221void PrintRec (ostream & ost, const ADTreeNode3M * node) const;222};223224225226227228229class ADTreeNode3F230{231public:232ADTreeNode3F *father;233ADTreeNode3F *childs[8];234float sep[3];235float data[3];236int pi;237int nchilds;238239ADTreeNode3F ();240void DeleteChilds ();241friend class ADTree3F;242243static BlockAllocator ball;244void * operator new(size_t);245void operator delete (void *);246};247248// fat tree249class ADTree3F250{251ADTreeNode3F * root;252float cmin[3], cmax[3];253ARRAY<ADTreeNode3F*> ela;254255public:256ADTree3F (const float * acmin,257const float * acmax);258~ADTree3F ();259260void Insert (const float * p, int pi);261void GetIntersecting (const float * bmin, const float * bmax,262ARRAY<int> & pis) const;263264void DeleteElement (int pi);265266267void Print (ostream & ost) const268{ PrintRec (ost, root); }269270void PrintRec (ostream & ost, const ADTreeNode3F * node) const;271};272273274275276class ADTreeNode3FM277{278public:279ADTreeNode3FM *father;280ADTreeNode3FM *childs[8];281float sep[3];282float data[ADTN_SIZE][3];283int pi[ADTN_SIZE];284int nchilds;285286ADTreeNode3FM ();287void DeleteChilds ();288friend class ADTree3FM;289290static BlockAllocator ball;291void * operator new(size_t);292void operator delete (void *);293};294295// fat tree296class ADTree3FM297{298ADTreeNode3FM * root;299float cmin[3], cmax[3];300ARRAY<ADTreeNode3FM*> ela;301302public:303ADTree3FM (const float * acmin,304const float * acmax);305~ADTree3FM ();306307void Insert (const float * p, int pi);308void GetIntersecting (const float * bmin, const float * bmax,309ARRAY<int> & pis) const;310311void DeleteElement (int pi);312313314void Print (ostream & ost) const315{ PrintRec (ost, root); }316317void PrintRec (ostream & ost, const ADTreeNode3FM * node) const;318};319320321322*/323324325326327328class ADTreeNode6329{330public:331ADTreeNode6 *left, *right, *father;332float sep;333float data[6];334int pi;335int nchilds;336337ADTreeNode6 ();338void DeleteChilds ();339friend class ADTree6;340341static BlockAllocator ball;342void * operator new(size_t);343void operator delete (void *);344};345346347class ADTree6348{349ADTreeNode6 * root;350float cmin[6], cmax[6];351ARRAY<ADTreeNode6*> ela;352353public:354ADTree6 (const float * acmin,355const float * acmax);356~ADTree6 ();357358void Insert (const float * p, int pi);359void GetIntersecting (const float * bmin, const float * bmax,360ARRAY<int> & pis) const;361362void DeleteElement (int pi);363364365void Print (ostream & ost) const366{ PrintRec (ost, root); }367int Depth () const368{ return DepthRec (root); }369int Elements () const370{ return ElementsRec (root); }371372void PrintRec (ostream & ost, const ADTreeNode6 * node) const;373int DepthRec (const ADTreeNode6 * node) const;374int ElementsRec (const ADTreeNode6 * node) const;375376void PrintMemInfo (ostream & ost) const;377};378379380381382/*383384class ADTreeNode6F385{386public:387ADTreeNode6F * father;388ADTreeNode6F * childs[64];389390float sep[6];391float data[6];392int pi;393int nchilds;394395ADTreeNode6F ();396void DeleteChilds ();397friend class ADTree6F;398399static BlockAllocator ball;400void * operator new(size_t);401void operator delete (void *);402};403404405class ADTree6F406{407ADTreeNode6F * root;408float cmin[6], cmax[6];409ARRAY<ADTreeNode6F*> ela;410411public:412ADTree6F (const float * acmin,413const float * acmax);414~ADTree6F ();415416void Insert (const float * p, int pi);417void GetIntersecting (const float * bmin, const float * bmax,418ARRAY<int> & pis) const;419420void DeleteElement (int pi);421422423void Print (ostream & ost) const424{ PrintRec (ost, root); }425int Depth () const426{ return DepthRec (root); }427428void PrintRec (ostream & ost, const ADTreeNode6F * node) const;429int DepthRec (const ADTreeNode6F * node) const;430};431432433434435436437438*/439440441442443444class Point3dTree445{446ADTree3 * tree;447448public:449Point3dTree (const Point3d & pmin, const Point3d & pmax);450~Point3dTree ();451void Insert (const Point3d & p, int pi);452void DeleteElement (int pi)453{ tree->DeleteElement(pi); }454void GetIntersecting (const Point3d & pmin, const Point3d & pmax,455ARRAY<int> & pis) const;456const ADTree3 & Tree() const { return *tree; };457};458459460461class Box3dTree462{463ADTree6 * tree;464Point3d boxpmin, boxpmax;465public:466Box3dTree (const Point3d & apmin, const Point3d & apmax);467~Box3dTree ();468void Insert (const Point3d & bmin, const Point3d & bmax, int pi);469void Insert (const Box<3> & box, int pi)470{471Insert (box.PMin(), box.PMax(), pi);472}473void DeleteElement (int pi)474{ tree->DeleteElement(pi); }475void GetIntersecting (const Point3d & pmin, const Point3d & pmax,476ARRAY<int> & pis) const;477478const ADTree6 & Tree() const { return *tree; };479};480#endif481482483