int main(int argc,char **argv) { float xValues[4] = {-22, -17, 4,22}; float yValues[4] = {-9, 31,13,-5}; long count = 4; VoronoiDiagramGenerator vdg; vdg.generateVoronoi(xValues,yValues,count, -100,100,-100,100,3); vdg.resetIterator(); float x1,y1,x2,y2; printf("\n-------------------------------\n"); while(vdg.getNext(x1,y1,x2,y2)) { printf("GOT Line (%f,%f)->(%f,%f)\n",x1,y1,x2, y2); } return 0; }
void Stippler::createVoronoiDiagram() { VoronoiDiagramGenerator generator; generator.generateVoronoi( vertsX, vertsY, parameters.points, 0.0f, (float)(image.getWidth() - 1), 0.0f, (float)(image.getHeight() - 1) ); edges.clear(); Point< float > p1, p2; Edge< float > edge; generator.resetIterator(); while ( generator.getNext( edge.begin.x, edge.begin.y, edge.end.x, edge.end.y, p1.x, p1.y, p2.x, p2.y ) ) { if ( edge.begin == edge.end ) { continue; } if ( edges.find( p1 ) == edges.end() ) { edges[p1] = EdgeList(); } if ( edges.find( p2 ) == edges.end() ) { edges[p2] = EdgeList(); } edges[p1].push_back( edge ); edges[p2].push_back( edge ); } }
int main(int argc, char** argv) { if(argc<2){ cout << "Configuration file is not specified." << endl ; return -1; } Configuration* config = new Configuration(argv[1]); Plotter* plot = new Plotter(gnuPlot, config); cout << "generating voronoi diagram..." << endl ; float* xValues = new float[100]; float* yValues = new float[100]; long count = 100; for(int i=0;i<count;i++){ xValues[i] = utility::unifRand(-10, 10); yValues[i] = utility::unifRand(-10, 10); } VoronoiDiagramGenerator vdg; vdg.generateVoronoi(xValues,yValues,count, -10,10,-10,10,0); cout << "here it comes..." << endl ; vdg.resetIterator(); float x1,y1,x2,y2; printf("\n-------------------------------\n"); while(vdg.getNext(x1,y1,x2,y2)) { plot->drawLine(x1,y1,x2, y2); printf("GOT Line (%f,%f)->(%f,%f)\n",x1,y1,x2, y2); } plot->close(); delete config; delete plot; return 0; }
int main(int argc,char **argv) { auto data = ReadFile<double>(std::string(argv[1])); float xValues[data.size()]; float yValues[data.size()]; for(size_t i = 0; i < data.size(); ++i){ xValues[i] = data[i][0]; yValues[i] = data[i][1]; } long count = data.size(); float max_x = *std::max_element(xValues, xValues + count); float max_y = *std::max_element(yValues, yValues + count); float min_x = *std::min_element(xValues, xValues + count); float min_y = *std::min_element(yValues, yValues + count); VoronoiDiagramGenerator vdg; vdg.generateVoronoi(xValues,yValues,count, min_x, max_x, min_y, max_y, 0); vdg.resetIterator(); float x1,y1,x2,y2; while(vdg.getNext(x1,y1,x2,y2)) { printf("%f %f \n",x1,y1); printf("%f %f \n",x2, y2); printf("\n"); } return 0; }
int main(int argc, const char * argv[]) { //variables provided by publisher const int count = 5; //number of sites(robots) float xValues[count] = {4, 5, 19, 36, 51}; //X position of sites(robots) float yValues[count] = {13, 49, 88, 76, 27}; //Y position of sites(robots) //variables should be provided by "Graham Scan" Algorithm const int nCzyBdyVert = 8; float boundaryPos[nCzyBdyVert][2] = {{2, -15}, {35, -23}, {72, -23}, {112, -3}, {109, 98}, {100, 120}, {-5, 120}, {-43, 36}}; //define the minimum and maximum X and Y values for the Fortune's Algorithm float minX, maxX, minY, maxY; for (int i=0; i<nCzyBdyVert; i++) { if (i==0) { minX = maxX = boundaryPos[i][0]; minY = maxY = boundaryPos[i][1]; } else { if (boundaryPos[i][0]<minX) minX = boundaryPos[i][0]; else if(boundaryPos[i][0]>maxX) maxX = boundaryPos[i][0]; if (boundaryPos[i][1]<minY) minY = boundaryPos[i][1]; else if(boundaryPos[i][1]>maxY) maxY = boundaryPos[i][1]; } } //cout << "minX: " << minX << ". maxX: " << maxX << ". minY: " << minY << ". maxY: " << maxY << endl; //Store the position of the sites in a Matrix int nSites = Matrix_Size(xValues); Matrix sitesPos(nSites,2); for(int i=0; i<Matrix_Size(xValues);i++){ sitesPos.setElement(i, 0, xValues[i]); //sitePos.elements[i][0] = xValues[i]; sitesPos.setElement(i, 1, yValues[i]); } //sitesPos.printArray("Sites"); int iteration=1; while (iteration<=100) { cout << endl << "Iteration " << iteration; CentroidGenerator cg; VoronoiDiagramGenerator vdg; vdg.generateVoronoi(xValues, yValues, count, minX, maxX, minY, maxY, 3); vdg.resetIterator(); float x1,y1,x2,y2; int a=1; printf("\n-------------------------------\n"); while(vdg.getNext(x1,y1,x2,y2)) { //printf("GOT Line (%.4f,%.4f)->(%.4f,%.4f)\n", x1,y1,x2,y2); //printf("v%dx = [%.4f,%.4f];\n", a, x1,x2); //to work with MATLAB //printf("v%dy = [%.4f,%.4f];\n", a, y1,y2); //to work with MATLAB a++; if (x1!=x2 || y1!=y2) //if condition necessary due to some unknown problem (Fortune's Algorithm generating vertices that shouldn't exist) { cg.posVertVector.push_back(x1); cg.posVertVector.push_back(y1); cg.posVertVector.push_back(x2); cg.posVertVector.push_back(y2); } //even though it seems to not affect the centroids' position } cout << endl; //After store position of all vertices, store the position of the edges of the plane (polygon boundary) for (int i=0; i<nCzyBdyVert; i++) { cg.posVertVector.push_back(boundaryPos[i][0]); cg.posVertVector.push_back(boundaryPos[i][1]); } //Return the position of the centroids sitesPos = cg.generateCentroid(cg.posVertVector, sitesPos, nSites, minX, maxX, minY, maxY, nCzyBdyVert); //sitesPos.printArray("new"); //Split the Centroid Matrix in X and Y vectors in order to pass in to the Fortune's Algorithm for (int i=0; i<sitesPos.rows; i++) { xValues[i]=sitesPos.elements[i][0]; yValues[i]=sitesPos.elements[i][1]; } iteration++; } return 0; }
void Server::generateVoronoi() { clock_t start = clock(); for(unsigned long k=0;k<REPCOUNT;k++){ std::vector<Point> sPoints; std::vector<Point> vPoints; std::vector<Point> points; sPoints.clear(); vPoints.clear(); points.clear(); VoronoiDiagramGenerator vdg; set <Server*>::iterator it; float x1,y1,x2,y2; Point curPoint; double distTp, newDist; // Get all server locations points.push_back(this->loc); for(it = this->neighbours.begin(); it != this->neighbours.end(); it++) { points.push_back((*it)->loc); } int count = points.size(); float xValues[count]; float yValues[count]; vPoints.push_back(Point(0,0)); vPoints.push_back(Point(WIDTH,0)); vPoints.push_back(Point(WIDTH,WIDTH)); vPoints.push_back(Point(0,WIDTH)); for (int i=0;i<count;i++) { xValues[i] = points.at(i).x(); yValues[i] = points.at(i).y(); } vdg.generateVoronoi(xValues,yValues,count, 0,WIDTH,0,WIDTH); vdg.resetIterator(); // printf("\n-------------------------------\n"); while(vdg.getNext(x1,y1,x2,y2)) { // printf("GOT Line (%g,%g)->(%g,%g)\n",x1,y1,x2, y2); vPoints.push_back(Point(x1,y1)); vPoints.push_back(Point(x2,y2)); } vPoints = myUnique(vPoints); this->deleteCell(); bool mine; for (unsigned int i=0;i<vPoints.size();i++) { mine = true; curPoint = vPoints[i]; distTp = this->loc.dist(curPoint); for(it = this->neighbours.begin(); it != this->neighbours.end(); it++) { newDist = (*it)->loc.dist(curPoint); // if(distTp < newDist){ // mine = true; // }else if(abs(newDist - distTp) < EPS) { // mine = true; // }else if(newDist < distTp){ // mine = false; // } if (abs(newDist - distTp) > EPS) { if (newDist < distTp) { mine = false; } } } if (mine) { sPoints.push_back(curPoint); } } this->GrahamScan(sPoints); } clock_t end = clock(); double cpu_time = static_cast<double>( end - start )/REPCOUNT; printf("generateVoronoi() comp_time = %f \n",cpu_time); }