source: GTP/trunk/App/Demos/Illum/pathmap/Woctreebranch.cpp @ 2197

Revision 2197, 4.2 KB checked in by szirmay, 18 years ago (diff)
Line 
1// Woctreebranch.cpp: implementation of the Woctreebranch class.
2//
3//////////////////////////////////////////////////////////////////////
4
5#include "dxstdafx.h"
6#include "Woctreebranch.h"
7#include "Wbucket.h"
8#include "Wsimplex.h"
9#include "Vector.hpp"
10
11//////////////////////////////////////////////////////////////////////
12// ruction/Destruction
13//////////////////////////////////////////////////////////////////////
14
15Woctreebranch::Woctreebranch()
16{
17        for(int i=0;i<8;i++)
18                subregion[i] = NULL;
19        parent = NULL;
20        x=y=z=0;
21        rx=ry=rz=1;
22}
23
24Woctreebranch::~Woctreebranch()
25{
26        for(int i=0;i<8;i++)
27                if(subregion[i]) delete  subregion[i];
28}
29
30Woctree* Woctreebranch::add( Wsimplex* toadd,int maxObjsInBucket, double minBrick)
31 {
32        Vector* cc = toadd->getCircumcentre();
33        double radius = toadd->getRadius();
34        Woctree** ps = subregion+7;
35        if(cc->x+radius > x && cc->y+radius > y && cc->z+radius > z)
36                if(*ps)
37                        *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick);
38                else
39                        *ps = new Wbucket(toadd,7,this);
40        ps--;
41        if(cc->x-radius < x && cc->y+radius > y && cc->z+radius > z)
42                if(*ps)
43                        *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick);
44                else
45                        *ps = new Wbucket(toadd,6,this);
46        ps--;
47        if(cc->x+radius > x && cc->y-radius < y && cc->z+radius > z)
48                if(*ps)
49                        *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick);
50                else
51                        *ps = new Wbucket(toadd,5,this);
52        ps--;
53        if(cc->x-radius < x && cc->y-radius < y && cc->z+radius > z)
54                if(*ps)
55                        *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick);
56                else
57                        *ps = new Wbucket(toadd,4,this);
58        ps--;
59        if(cc->x+radius > x && cc->y+radius > y && cc->z-radius < z)
60                if(*ps)
61                        *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick);
62                else
63                        *ps = new Wbucket(toadd,3,this);
64        ps--;
65        if(cc->x-radius < x && cc->y+radius > y && cc->z-radius < z)
66                if(*ps)
67                        *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick);
68                else
69                        *ps = new Wbucket(toadd,2,this);
70        ps--;
71        if(cc->x+radius > x && cc->y-radius < y && cc->z-radius < z)
72                if(*ps)
73                        *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick);
74                else
75                        *ps = new Wbucket(toadd,1,this);
76        ps--;
77        if(cc->x-radius < x && cc->y-radius < y && cc->z-radius < z)
78                if(*ps)
79                        *ps = (*ps)->add(toadd,maxObjsInBucket,minBrick);
80                else
81                        *ps = new Wbucket(toadd,0,this);
82        return this;
83 }
84
85Wsimplex* Woctreebranch::search(Vector *proxy)
86 {
87        return
88                subregion[((proxy->x>x)?1:0) | ((proxy->y>y)?2:0) | ((proxy->z>z)?4:0)]->search(proxy);
89 }
90
91Wsimplex* Woctreebranch::searchNeighbour(Wsimplex* proxy)
92{
93        Vector* cc = proxy->getCircumcentre();
94        int subri = ((cc->x>x)?1:0) | ((cc->y>y)?2:0) | ((cc->z>z)?4:0);
95        Wsimplex* ret = subregion[subri]->searchNeighbour(proxy);
96        if(ret) return ret;
97        for(int i = 0; i<7; i++, subri = (subri + 1) % 8)
98        {
99                ret = subregion[subri]->searchNeighbour(proxy);
100                if(ret)
101                        return ret;
102        }
103        return NULL;
104}
105
106Woctreebranch::Woctreebranch(Wbucket *a, Woctreebranch *parent, int orientation)
107{
108        for(int i=0;i<8;i++)
109                subregion[i] = NULL;
110        this->parent = parent; 
111        Vector* range = parent->getChildSize();
112        Vector* center = parent->getHalfer();
113        x = center->x + (orientation&1)?range->x:-range->x;
114        y = center->y + (orientation&2)?range->y:-range->y;
115        z = center->z + (orientation&4)?range->z:-range->z;
116        delete range;
117        delete center;
118        ::std::vector<Wsimplex*>::const_iterator b = a->simplexArray.begin();
119        while(b != a->simplexArray.end())
120        {
121                add(*b);
122                b++;
123        }
124        delete a;
125}
126
127Woctreebranch::Woctreebranch(double x, double y, double z, double rx, double ry, double rz)
128{
129        for(int i=0;i<8;i++)
130                subregion[i] = NULL;
131        parent = NULL;
132        this->x=x;
133        this->y=y;
134        this->z=z;
135        this->rx=rx;
136        this->ry=ry;
137        this->rz=rz;
138
139}
140
141Woctreebranch::Woctreebranch(Woctreebranch *parent, int orientation)
142{
143        for(int i=0;i<8;i++)
144                subregion[i] = NULL;
145        this->parent = parent; 
146        Vector* range = parent->getChildSize();
147        Vector* center = parent->getHalfer();
148        x = center->x + (orientation&1)?range->x:-range->x;
149        y = center->y + (orientation&2)?range->y:-range->y;
150        z = center->z + (orientation&4)?range->z:-range->z;
151}
152
153Vector* Woctreebranch::getHalfer()
154{
155        return new Vector(x,y,z);
156}
157
158Vector* Woctreebranch::getChildSize()
159{
160        return new Vector(rx/2,ry/2,rz/2);
161}
Note: See TracBrowser for help on using the repository browser.