int main(int argc, char *argv[]) { // Initialize available methods methods["RelativeNeighbor"] = getRelativeNeighborGraph; methods["Gabriel"] = getGabrielGraph; methods["BSkeleton"] = getBSkeleton; methods["RelaxedRelativeNeighbor"] = getRelaxedRelativeNeighborGraph; methods["RelaxedGabriel"] = getRelaxedGabrielGraph; methods["RelaxedBSkeleton"] = getRelaxedBSkeleton; CommandLine cl; cl.addArgument("-i", "input", "Input points", true); cl.addArgument("-d", "2", "Number of dimensions", true); cl.addArgument("-m", "BSkeleton", "Neighborhood Method", false); cl.addArgument("-b", "1.0", "Beta", false); cl.addArgument("-k", "-1", "K max", false); bool hasArguments = cl.processArgs(argc, argv); if(!hasArguments) { fprintf(stderr, "Missing arguments\n"); fprintf(stderr, "Usage:\n\n"); cl.showUsage(); listMethods(); exit(1); } string method = cl.getArgString("-m"); // Check if the method exists if(methods.find(method)==methods.end()) { fprintf(stderr, "Method does not exist\n"); listMethods(); return 0; } const char *src = cl.getArgString("-i").c_str(); int dims = cl.getArgInt("-d"); float param = cl.getArgFloat("-b"); int kmax = cl.getArgInt("-k"); vector<float> inpoints; readPoints(src, inpoints, dims); float *pts = new float[(int) inpoints.size()]; for(unsigned int i = 0; i<inpoints.size(); i++) { pts[i] = inpoints[i]; } Geometry<float>::init(dims); timestamp t1 = now(); int n = (int) inpoints.size()/dims; if(kmax<0) kmax = n-1; ANNPointSet<float> P(pts, n); NGLParams<float> params; params.param1 = param; params.iparam0 = kmax; IndexType *indices; int numEdges; methods[method](P, &indices, numEdges, params); timestamp t2 = now(); for(unsigned int i=0; i<numEdges; i++) { fprintf(stdout,"%d %d\n", indices[2*i+0],indices[2*i+1]); } delete pts; fprintf(stderr, "Ellapsed time: %f s.\n", t2-t1); }
int main(int argc, char *argv[]) { CommandLine cl; cl.addArgument("-i", "input", "Input points", true); cl.addArgument("-d", "2", "Number of dimensions", true); bool hasArguments = cl.processArgs(argc, argv); if(!hasArguments) { fprintf(stderr, "Missing arguments\n"); fprintf(stderr, "Usage:\n\n"); cl.showUsage(); exit(1); } const char *src = cl.getArgString("-i").c_str(); int dims = cl.getArgInt("-d"); vector<float> inpoints; readPoints(src, inpoints, dims); int numPts = (int) inpoints.size()/dims; // Write input for qdelaunay FILE *fp = fopen("temp.qhull", "w"); fprintf(fp, "%d\n", dims); fprintf(fp, "%d\n", numPts); for(unsigned int i=0;i<numPts;i++) { for(int d = 0;d<dims;d++) { fprintf(fp, "%g ", inpoints[dims*i+d]); } fprintf(fp, "\n"); } fclose(fp); timestamp t1 = now(); char cmd[1024]; sprintf(cmd, "%s/qdelaunay Qt i TO temp.out < temp.qhull", QDELAUNAY_PATH); system(cmd); timestamp t2 = now(); fprintf(stderr,"Ellapsed %f\n", t2-t1); // Read output of qdelaunay FILE *fpin = fopen("temp.out","r"); int numTris; fscanf(fpin,"%d", &numTris); bool **edges = new bool*[numPts]; for(int i=0;i<numPts;i++) { edges[i] = new bool[numPts]; for(int j=0;j<numPts;j++) { edges[i][j] = false; } } // Output each edge from qdelaunay output int D = dims; for(int i=0;i<numTris;i++) { int simplex[D+1]; for(int d=0;d<D+1;d++) { fscanf(fpin,"%d", &(simplex[d])); } for(int d=0;d<D+1;d++) { for(int d2=d+1;d2<D+1;d2++) { int i1 = simplex[d]; int i2 = simplex[d2]; if(!edges[i1][i2] && !edges[i2][i1]) { edges[i1][i2] = true; edges[i2][i1] = true; fprintf(stdout, "%d %d\n", i1, i2); } } } } fclose(fpin); delete[] edges; }