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

Revision 2197, 3.0 KB checked in by szirmay, 17 years ago (diff)
Line 
1// DelaunayMesh.cpp: implementation of the DelaunayMesh class.
2//
3//////////////////////////////////////////////////////////////////////
4
5#include "dxstdafx.h"
6#include "DelaunayMesh.h"
7
8//////////////////////////////////////////////////////////////////////
9// Construction/Destruction
10//////////////////////////////////////////////////////////////////////
11
12DelaunayMesh::DelaunayMesh(Vector* c,double encloseRad)
13{
14        encloseRadius = encloseRad;
15        encloseCentre = *c;
16//to see how we crashed for testing
17        crashed = 0;
18//WARNING should contain everything, now still hardwired for testing
19        tetrahedra = new Woctreebranch(c->x,c->y,c->z,
20                encloseRad*5,encloseRad*5,encloseRad*5);
21
22//enclosing dodecaeder
23        double radius = encloseRadius*4;
24//WARNING relative coords to c
25        Vector* top = new Vector(c->x, c->y, c->z + radius);
26        nodeArray.push_back( top );
27        Vector* bottom = new Vector(c->x, c->y, c->z - radius);
28        nodeArray.push_back( bottom );
29       
30        Vector* highcircle[5];
31        Vector* lowcircle[5];
32        for(int i=0;i<5;i++)
33        {
34                highcircle[i] = new Vector(c->x + radius*sin(i*1.257),c->y + radius*cos(i*1.257),c->z + radius/3.0);
35                nodeArray.push_back( highcircle[i] );
36                lowcircle[i] = new Vector(c->x + radius*sin(i*1.257+0.628),c->y + radius*cos(i*1.257+0.628),c->z - radius/3.0);
37                nodeArray.push_back( lowcircle[i] );
38        }
39        nodeArray.push_back( c );
40
41        cavvie = new WsubMesh();
42        for(int s=0;s<5;s++)
43        {
44                cavvie->add(new Wsimplex(top, highcircle[s], highcircle[(s+1)%5],1));
45                cavvie->add(new Wsimplex(bottom, lowcircle[s], lowcircle[(s+1)%5],1));
46                cavvie->add(new Wsimplex(highcircle[s], lowcircle[(s+4)%5], lowcircle[s],1));
47                cavvie->add(new Wsimplex(lowcircle[s], highcircle[s], highcircle[(s+1)%5],1));
48        }
49        ::std::vector<Wsimplex*> a = cavvie->complete;
50        ::std::vector<Wsimplex*>::const_iterator b = a.begin();
51
52        while(b != a.end())
53        {
54                Wsimplex* pyramid = new Wsimplex(c,*b);
55                (*b)->inFrontOf = pyramid;
56                tetrahedra->add(pyramid);
57                simplexArray.push_back(pyramid);
58                b++;
59        }
60}
61
62
63DelaunayMesh::~DelaunayMesh()
64{
65        delete tetrahedra;
66        delete cavvie;
67}
68
69char DelaunayMesh::add(Vector * proxy,Wsimplex* starter)
70{
71        if(crashed) return 'C';
72        Wsimplex* first;
73        if(starter)
74                first = starter;
75        else
76                first = tetrahedra->search(proxy);
77        if(!first)
78                return 'I';
79
80        WsubMesh* suff = first->cavity(proxy);
81
82        if(!suff->incomplete.empty())
83        {
84                crashed = 1;
85                return 'C';
86        }
87
88        ::std::vector<Wsimplex*>::iterator a = simplexArray.begin();
89        while(a != simplexArray.end())
90        {
91                if((*a)->deleted)
92                {
93                        delete(*a);
94                        simplexArray.erase(a);
95                }
96                else
97                        a++;
98        }
99
100        a = suff->complete.begin();
101        while(a != suff->complete.end())
102        {
103                Wsimplex* pyramid = new Wsimplex(proxy,*a);
104                (*a)->inFrontOf = pyramid;
105                tetrahedra->add(pyramid);
106                simplexArray.push_back(pyramid);
107                a++;
108        }
109
110        nodeArray.push_back(proxy);
111
112        delete suff;
113        return 'O';
114}
115
116int DelaunayMesh::getSimplexCount()
117{
118        return simplexArray.size();
119}
120
121Wsimplex* DelaunayMesh::search(Vector* pixie)
122{
123        return tetrahedra->search(pixie);
124}
Note: See TracBrowser for help on using the repository browser.