// ------------------------------------------------------------------------ // This program is complementary material for the book: // // Frank Nielsen // // Visual Computing: Geometry, Graphics, and Vision // // ISBN: 1-58450-427-7 // // Charles River Media, Inc. // // // All programs are available at http://www.charlesriver.com/visualcomputing/ // // You may use this program for ACADEMIC and PERSONAL purposes ONLY. // // // The use of this program in a commercial product requires EXPLICITLY // written permission from the author. The author is NOT responsible or // liable for damage or loss that may be caused by the use of this program. // // Copyright (c) 2005. Frank Nielsen. All rights reserved. // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ // File: DiscreteVoronoi.cpp // // Description: Rasterize Voronoi Diagrams for various "distance" functions // ------------------------------------------------------------------------ #include "stdafx.h" #include #include void SaveImagePPM(unsigned char * data, int w, int h, char * file); #define NB_GENERATOR 30 #define LINELENGTH 3 #define WIDTH 800 #define HEIGHT 800 class point { public: double x,y; inline double Distance(point q) {return sqrt((q.x-x)*(q.x-x) + (q.y-y)*(q.y-y));} }; point generator[NB_GENERATOR]; unsigned char red[NB_GENERATOR], green[NB_GENERATOR], blue[NB_GENERATOR]; // Voronoi image short voronoi[WIDTH][HEIGHT]; void VoronoiEuclidean() { int i,j,k,winner; long double dist,distmin; point pixel; // for all pixels for(i=0;i