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

Revision 2197, 2.1 KB checked in by szirmay, 18 years ago (diff)
Line 
1// Wbucket.cpp: implementation of the Wbucket class.
2//
3//////////////////////////////////////////////////////////////////////
4
5#include "dxstdafx.h"
6#include "Wbucket.h"
7#include "Wsimplex.h"
8#include "Woctreebranch.h"
9#include "Vector.hpp"
10//////////////////////////////////////////////////////////////////////
11// ruction/Destruction
12//////////////////////////////////////////////////////////////////////
13
14Wbucket::Wbucket()
15{
16}
17
18Wbucket::~Wbucket()
19{
20        ::std::vector<Wsimplex*>::const_iterator a = simplexArray.begin();
21        while(a != simplexArray.end())
22        {
23                (*a)->cutlinkback(this);
24                a++;
25        }
26}
27
28Woctree* Wbucket::add( Wsimplex *toadd,int maxObjsInBucket, double minBrick)
29{
30        simplexArray.push_back(toadd);
31        toadd->linkback(this);
32        if(simplexArray.size() > maxObjsInBucket && parent->getChildSize()->x>minBrick)
33        {
34                return new Woctreebranch(this, parent, whereami);
35        }
36        return this;
37//WARNING Woctreebracjj constructor deleted this bucket
38}
39
40Wbucket::Wbucket( Wsimplex* founder, int orientation, Woctreebranch* parent)
41{
42        this->parent = parent;
43        simplexArray.push_back(founder);
44        founder->linkback(this);
45        whereami = orientation;
46}
47
48Wsimplex* Wbucket::search(Vector *proxy)
49{
50        ::std::vector<Wsimplex*>::const_iterator a = simplexArray.begin();
51        while(a != simplexArray.end())
52        {
53                if((*a)->inCircle(proxy))
54                        return *a;
55                a++;
56        }
57        //NEVER HAPPENS IN A CORRECT MESH
58        return NULL;
59}
60
61Wsimplex* Wbucket::searchNeighbour(Wsimplex *proxy)
62{
63        Wsimplex* ret = NULL;
64        float distance2 = FLT_MAX;
65        ::std::vector<Wsimplex*>::iterator a = simplexArray.begin();
66        while(a != simplexArray.end())
67        {
68                if(*a != proxy)
69                {
70                        Vector diff = *proxy->getCircumcentre();
71                        diff -= *(*a)->getCircumcentre();
72                        float cd2 = diff.norm2();
73                        if(cd2 < distance2)
74                        {
75                                distance2 = cd2;
76                                ret = *a;
77                        }
78                }
79                a++;
80        }
81        return ret;
82}
83
84void Wbucket::eliminate(Wsimplex *dieing)
85{
86        ::std::vector<Wsimplex*>::iterator a = simplexArray.begin();
87        while(a < simplexArray.end())
88        {
89                if(*a == dieing)
90                        simplexArray.erase(a);
91                else
92                        a++;
93        }
94}
95
96int Wbucket::getCount()
97{
98        return simplexArray.size();
99}
100
Note: See TracBrowser for help on using the repository browser.