void getCmdArgs(int argc, char *argv[]) { int i = 1; while (i < argc) { // read arguments if (!strcmp(argv[i], "-i")) { // -i option inStream.open(argv[++i], ios::in); // open input file if (!inStream) { kmError("Cannot open input file", KMabort); } kmIn = &inStream; // make this input stream } else if (!strcmp(argv[i], "-o")) { // -o option outStream.open(argv[++i], ios::out);// open output file if (!outStream) { kmError("Cannot open output file", KMabort); } kmOut = &outStream; // make this output stream } else { // illegal syntax *kmErr << "Syntax:\n" << "kmltest [-i infile] [-o outfile]\n" << " where:\n" << " infile directive input file\n" << " outfile output file\n"; exit(1); // exit } i++; } }
// standard constructor KMfilterCenters::KMfilterCenters(int k, KMdata& p, double df) : KMcenters(k, p) { if (p.getKcTree() == NULL) { // kc-tree not yet built? kmError("Building kc-tree", KMwarn); p.buildKcTree(); // build it now } sums = kmAllocPts(kCtrs, getDim()); sumSqs = new double[kCtrs]; weights = new int[kCtrs]; dists = new double[kCtrs]; currDist = KM_HUGE; dampFactor = df; currDBIndex = KM_HUGE; currXBIndex = KM_HUGE; invalidate(); // distortions are initially invalid }
void KCtree::skeletonTree( // construct skeleton tree KMdataArray pa, // point array (with at least n pts) int n, // number of points int dd, // dimension int n_max, // maximum number of points (optional) KMpoint bb_lo, // bounding box low point (optional) KMpoint bb_hi, // bounding box high point (optional) KMdatIdxArray pi) // point indices (optional) { // initialize basic elements dim = dd; // dimension n_pts = n; // number of points if (n_max < n) n_max = n; // max_pts must be >= n max_pts = n_max; // set max_pts if (pa == NULL) // no points supplied? { kmError("Points must be supplied to construct tree.", KMabort); } pts = pa; // initialize point array if (pi == NULL) // point indices provided? { pidx = new KMdataIdx[max_pts]; // no, allocate them for (int i = 0; i < n; i++) // initialize to identity pidx[i] = i; } else pidx = pi; // yes, just use them if (bb_lo == NULL || bb_hi == NULL) // boundng box fully specified? kmEnclRect(pa, pidx, n, dd, bnd_box); // no, construct from points // save bounding box if (bb_lo != NULL) // if lower point given, then use it bnd_box.lo = kmAllocCopyPt(dd, bb_lo); if (bb_hi != NULL) // same for upper point bnd_box.hi = kmAllocCopyPt(dd, bb_hi); root = NULL; // no associated tree yet }