// DelaunayMesh.cpp: implementation of the DelaunayMesh class. // ////////////////////////////////////////////////////////////////////// #include "dxstdafx.h" #include "DelaunayMesh.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// DelaunayMesh::DelaunayMesh(Vector* c,double encloseRad) { encloseRadius = encloseRad; encloseCentre = *c; //to see how we crashed for testing crashed = 0; //WARNING should contain everything, now still hardwired for testing tetrahedra = new Woctreebranch(c->x,c->y,c->z, encloseRad*5,encloseRad*5,encloseRad*5); //enclosing dodecaeder double radius = encloseRadius*4; //WARNING relative coords to c Vector* top = new Vector(c->x, c->y, c->z + radius); nodeArray.push_back( top ); Vector* bottom = new Vector(c->x, c->y, c->z - radius); nodeArray.push_back( bottom ); Vector* highcircle[5]; Vector* lowcircle[5]; for(int i=0;i<5;i++) { highcircle[i] = new Vector(c->x + radius*sin(i*1.257),c->y + radius*cos(i*1.257),c->z + radius/3.0); nodeArray.push_back( highcircle[i] ); 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); nodeArray.push_back( lowcircle[i] ); } nodeArray.push_back( c ); cavvie = new WsubMesh(); for(int s=0;s<5;s++) { cavvie->add(new Wsimplex(top, highcircle[s], highcircle[(s+1)%5],1)); cavvie->add(new Wsimplex(bottom, lowcircle[s], lowcircle[(s+1)%5],1)); cavvie->add(new Wsimplex(highcircle[s], lowcircle[(s+4)%5], lowcircle[s],1)); cavvie->add(new Wsimplex(lowcircle[s], highcircle[s], highcircle[(s+1)%5],1)); } ::std::vector a = cavvie->complete; ::std::vector::const_iterator b = a.begin(); while(b != a.end()) { Wsimplex* pyramid = new Wsimplex(c,*b); (*b)->inFrontOf = pyramid; tetrahedra->add(pyramid); simplexArray.push_back(pyramid); b++; } } DelaunayMesh::~DelaunayMesh() { delete tetrahedra; delete cavvie; } char DelaunayMesh::add(Vector * proxy,Wsimplex* starter) { if(crashed) return 'C'; Wsimplex* first; if(starter) first = starter; else first = tetrahedra->search(proxy); if(!first) return 'I'; WsubMesh* suff = first->cavity(proxy); if(!suff->incomplete.empty()) { crashed = 1; return 'C'; } ::std::vector::iterator a = simplexArray.begin(); while(a != simplexArray.end()) { if((*a)->deleted) { delete(*a); simplexArray.erase(a); } else a++; } a = suff->complete.begin(); while(a != suff->complete.end()) { Wsimplex* pyramid = new Wsimplex(proxy,*a); (*a)->inFrontOf = pyramid; tetrahedra->add(pyramid); simplexArray.push_back(pyramid); a++; } nodeArray.push_back(proxy); delete suff; return 'O'; } int DelaunayMesh::getSimplexCount() { return simplexArray.size(); } Wsimplex* DelaunayMesh::search(Vector* pixie) { return tetrahedra->search(pixie); }