/[escript]/branches/refine/buckley/src/OctTree.cc
ViewVC logotype

Diff of /branches/refine/buckley/src/OctTree.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3679 by jfenwick, Wed Nov 16 01:49:46 2011 UTC revision 3680 by jfenwick, Fri Nov 18 04:48:53 2011 UTC
# Line 9  using namespace buckley; Line 9  using namespace buckley;
9    
10  // Note: This code assumes x,y,z are positive  // Note: This code assumes x,y,z are positive
11  OctTree::OctTree(double x, double y, double z)  OctTree::OctTree(double x, double y, double z)
12  :p(fabs(x)/2, fabs(y)/2, fabs(z)/2, fabs(x), fabs(y), fabs(z),0)  :p(fabs(x)/2, fabs(y)/2, fabs(z)/2, fabs(x), fabs(y), fabs(z),0), modified(true)
13  {  {
14      side[0]=fabs(x);      side[0]=fabs(x);
15      side[1]=fabs(y);      side[1]=fabs(y);
16      side[2]=fabs(z);      side[2]=fabs(z);
17        leafcount=1;
18  }  }
19    
20  OctTree::~OctTree(){}  OctTree::~OctTree(){}
# Line 21  OctTree::~OctTree(){} Line 22  OctTree::~OctTree(){}
22  // guarantees that all leaves are at depth >=d  // guarantees that all leaves are at depth >=d
23  void OctTree::allSplit(unsigned int d)  void OctTree::allSplit(unsigned int d)
24  {  {
25      p.allSplit(d);        modified=true;
26        p.allSplit(d, &leafcount);  
27  }  }
28    
29  void OctTree::allCollapse(unsigned d)  void OctTree::allCollapse(unsigned d)
30  {  {
31     p.collapseAll(d);        modified=true;  
32         p.collapseAll(d, &leafcount);    
33  }  }
34    
35  void OctTree::collapsePoint(double x, double y, double z, unsigned int d)  void OctTree::collapsePoint(double x, double y, double z, unsigned int d)
36  {  {
37      p.collapsePoint(x,y,z,d);        modified=true;  
38        p.collapsePoint(x,y,z,d, &leafcount);  
39        
40  }  }
41    
42  void OctTree::splitPoint(double x, double y, double z, unsigned int desdepth)  void OctTree::splitPoint(double x, double y, double z, unsigned int desdepth)
43  {  {  
44      if ((x<0) || (y<0) || (z<0) ||      if ((x<0) || (y<0) || (z<0) ||
45          (x>side[0]) || (y>side[1]) || (z>side[2]))          (x>side[0]) || (y>side[1]) || (z>side[2]))
46      {      {
47          return;          return;
48      }      }
49      p.splitPoint(x, y, z, desdepth);      modified=true;    
50        p.splitPoint(x, y, z, desdepth, &leafcount);
51  }  }
52    
53  namespace  namespace
54  {  {
55    
 // I haven't decided whether I want to have a generally mutable interface to nodes or not  
 // the use of const_cast is ok coz it's me doing it  
56  void zorderlabel(const OctCell& c, void* v)  void zorderlabel(const OctCell& c, void* v)
57  {  {
58      const_cast<OctCell&>(c).id=(*reinterpret_cast<unsigned*>(v))++;        c.id=(*reinterpret_cast<unsigned*>(v))++;  
59  }  }
60    
61  void countleaves(const OctCell& c, void* v)  void countleaves(const OctCell& c, void* v)
# Line 65  void clearIDs(const OctCell& c, void* v) Line 67  void clearIDs(const OctCell& c, void* v)
67  {  {
68      if (c.leaf)      if (c.leaf)
69      {      {
70          memset(const_cast<OctCell&>(c).leafinfo->pmap,0,sizeof(unkid)*8);          memset(c.leafinfo->pmap,0,sizeof(unkid)*8);
71      }      }
72  }  }
73    
# Line 102  void setUnkids(const OctCell& c, int kid Line 104  void setUnkids(const OctCell& c, int kid
104  }  }
105    
106    
107    typedef struct
108    {
109       const OctCell** ca;
110       unkid id;  
111    } copier;
112    
113    void copytoarr(const OctCell& c, void* v)
114    {
115        copier* cs=reinterpret_cast<copier*>(v);
116        cs->ca[cs->id++]=&c;
117    }
118    
119    
120    }
121    
122    
123    const OctCell** OctTree::process() const
124    {
125        assignIDs();
126        // nasty hack process for now
127        // ultimately, this should be done by starting each thread midway through the traversal
128        const OctCell** temp=new const OctCell*[leafcount];
129        copier c;
130        c.ca=temp;
131        c.id=0;
132        p.doLeafWalk_const(copytoarr, &c);
133        return temp;
134  }  }
135    
136  void OctTree::assignIDs()  void OctTree::assignIDs() const
137  {  {
138      unsigned id=0;      unsigned id=0;
139      p.doLeafWalk(zorderlabel, &id);      p.doLeafWalk_const(zorderlabel, &id);
140      p.doLeafWalk(clearIDs, 0);      p.doLeafWalk_const(clearIDs, 0);
141      unkid i=HANG_NODE+1;      unkid i=HANG_NODE+1;
142      p.doLeafWalkWithKids(setUnkids, 0, &i);      p.doLeafWalkWithKids_const(setUnkids, 0, &i);
143  }  }
144    
145    
146  void OctTree::walkLeaves(cellfunct c, void* v)  void OctTree::walkLeaves(const_cellfn c, void* v) const
147    {
148        p.doLeafWalk_const(c, v);  
149    }
150    
151    void OctTree::walkLeaves(cellfn c, void* v)
152  {  {
153      p.doLeafWalk(c, v);        p.doLeafWalk(c, v);  
154  }  }
155    
156    
157    
158  void OctTree::walkWithKids(cellfunct2 c, void* v)  void OctTree::walkWithKids(const_cellfn2 c, void* v)
159  {  {
160      p.doLeafWalkWithKids(c, 0, v);      // we need to pick a childnum to start but a level 0 leaf is a trivial      p.doLeafWalkWithKids_const(c, 0, v);    // we need to pick a childnum to start but a level 0 leaf is a trivial
161  }                   // tree anyway  }                   // tree anyway
162    
163  unsigned  OctTree::leafCount()  unsigned  OctTree::leafCountByWalk() const
164  {  {
165      unsigned c;      unsigned c;
166      p.doLeafWalk(countleaves, &c);      p.doLeafWalk_const(countleaves, &c);
167      return c;      return c;
168  }  }
169    
170    unsigned  OctTree::leafCount() const
171    {
172        return leafcount;
173    }
174    
175  void OctTree::debug()  void OctTree::debug()
176  {  {
177     p.debug(false);     p.debug(false);

Legend:
Removed from v.3679  
changed lines
  Added in v.3680

  ViewVC Help
Powered by ViewVC 1.1.26