#include #include #include #include #include #include #include #include #include #include #include #include #include #include "gen_tile.h" #include "protocol.h" #include "render_config.h" #include "dir_utils.h" #define DEG_TO_RAD (M_PI/180) #define RAD_TO_DEG (180/M_PI) #ifndef METATILE #warning("Speed test not implemented for non-metatile mode. Feel free to submit fix") int main(int argc, char **argv) { fprintf(stderr, "Speed test not implemented for non-metatile mode. Feel free to submit fix!\n"); return -1; } #else static const int minZoom = 0; static const int maxZoom = 18; #if 1 static double boundx0=-0.5; static double boundy0=51.25; static double boundx1=0.5; static double boundy1=51.75; #endif #if 0 // bbox = (-6.0, 50.0,3.0,58.0) static double boundx0=-6.0; static double boundy0=50.0; static double boundx1=3.0; static double boundy1=58.0; #endif #if 0 // UK: 49.7,-7.6, 58.8, 3.2 static double boundx0=-7.6; static double boundy0=49.7; static double boundx1=3.2; static double boundy1=58.8; #endif static double minmax(double a, double b, double c) { #define MIN(x,y) ((x)<(y)?(x):(y)) #define MAX(x,y) ((x)>(y)?(x):(y)) a = MAX(a,b); a = MIN(a,c); return a; } class GoogleProjection { double *Ac, *Bc, *Cc, *zc; public: GoogleProjection(int levels=18) { Ac = new double[levels]; Bc = new double[levels]; Cc = new double[levels]; zc = new double[levels]; int d, c = 256; for (d=0; dver, req->cmd, req->z, req->x, req->y); return 0; } int process_loop(int fd, int x, int y, int z) { struct protocol cmd, rsp; //struct pollfd fds[1]; int ret = 0; bzero(&cmd, sizeof(cmd)); cmd.ver = 2; cmd.cmd = cmdRender; cmd.z = z; cmd.x = x; cmd.y = y; strcpy(cmd.xmlname, XMLCONFIG_DEFAULT); //strcpy(cmd.path, "/tmp/foo.png"); //printf("Sending request\n"); ret = send(fd, &cmd, sizeof(cmd), 0); if (ret != sizeof(cmd)) { perror("send error"); } //printf("Waiting for response\n"); bzero(&rsp, sizeof(rsp)); ret = recv(fd, &rsp, sizeof(rsp), 0); if (ret != sizeof(rsp)) { perror("recv error"); return 0; } //printf("Got response\n"); if (!ret) perror("Socket send error"); return ret; } int main(int argc, char **argv) { const char *spath = RENDER_SOCKET; int fd; struct sockaddr_un addr; int ret=0; int z; char name[PATH_MAX]; struct timeval start, end; struct timeval start_all, end_all; int num, num_all = 0; fprintf(stderr, "Rendering client\n"); fd = socket(PF_UNIX, SOCK_STREAM, 0); if (fd < 0) { fprintf(stderr, "failed to create unix socket\n"); exit(2); } bzero(&addr, sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, spath, sizeof(addr.sun_path)); if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { fprintf(stderr, "socket connect failed for: %s\n", spath); close(fd); exit(3); } // Render something to counter act the startup costs // of obtaining the Postgis table extents printf("Initial startup costs\n"); gettimeofday(&start, NULL); process_loop(fd, 0,0,0); gettimeofday(&end, NULL); display_rate(start, end, 1); gettimeofday(&start_all, NULL); for (z=minZoom; z<=maxZoom; z++) { double px0 = boundx0; double py0 = boundy1; double px1 = boundx1; double py1 = boundy0; gprj.fromLLtoPixel(px0, py0, z); gprj.fromLLtoPixel(px1, py1, z); int x, xmin, xmax; xmin = (int)(px0/256.0); xmax = (int)(px1/256.0); int y, ymin, ymax; ymin = (int)(py0/256.0); ymax = (int)(py1/256.0); num = (xmax - xmin + 1) * (ymax - ymin + 1); // if (!num) { // printf("No tiles at zoom(%d)\n", z); // continue; // } printf("\nZoom(%d) Now rendering %d tiles\n", z, num); num_all += num; gettimeofday(&start, NULL); for (x=xmin; x<=xmax; x++) { for (y=ymin; y<=ymax; y++) { struct stat s; xyz_to_meta(name, sizeof(name), XMLCONFIG_DEFAULT, x, y, z); if (stat(name, &s) < 0) { // File doesn't exist ret = process_loop(fd, x, y, z); } //printf("."); fflush(NULL); } } //printf("\n"); gettimeofday(&end, NULL); display_rate(start, end, num); } gettimeofday(&end_all, NULL); printf("\nTotal for all tiles rendered\n"); display_rate(start_all, end_all, num_all); close(fd); return ret; } #endif