// ******************************************** // Filename: scale.c++ // // Program: Scale Bounds // // Description: Takes the output-file from the // pfbounds program and generates an appropriate // scaling factor given the maximum absolute value // for each dimension (x,y,z) // // Syntax: scaleBounds (pfbounds-file) (xmax) (ymax) (zmax) // // For Example: // scaleBounds example.txt 100 50 25 // -- This verifies that that x-range is under 100, meaning // (xmax - xmin) <= 100. It checks the y-range is under 50, // and the z-range is under 25. If all the ranges are under // their max, it scales the values UP to the maximum allowed // range and returns that scale factor. // // Author: Heath Beres // // Version: 1.0 // // Last Revision: 12/14/97 // ******************************************** #include #include #include #include #include #include int fexists( char fname[]); int main(int argc, char *argv[]) { // Verify Commandline and existence of Bounds file if( (argc < 5) || (strcmp(argv[1], "") == 0)) { cout << "Syntax error:" << endl << endl; cout << "scaleBounds (pfbounds-file) (xmax) (ymax) (zmax)"; cout << endl << endl; return 1; } if(!fexists(argv[1])) { cout << "File error:" << endl << endl; cout << "Filename: " << argv[1] << " could not be found."; cout << endl << endl; return 1; } // Open Bounds file ifstream inFile; inFile.open(argv[1]); // Set maximum values passed into the program float XMAX = atof(argv[2]); float YMAX = atof(argv[3]); float ZMAX = atof(argv[4]); // Read in the file and assign values char dummy[20] = ""; // dummy string char dummy2 = ' '; // dummy char // x,y,z values read in from the file float xmin, xmax, ymin, ymax, zmin, zmax; float scale = 1.0; // scale factor inFile >> dummy >> dummy >> xmin >> dummy2 >> xmax >> dummy >> ymin >> dummy2 >> ymax >> dummy >> zmin >> dummy2 >> zmax; float x_range, y_range, z_range; // temp differences x_range = xmax - xmin; y_range = ymax - ymin; z_range = zmax - zmin; float newX_range, newY_range, newZ_range; newX_range = x_range; newY_range = y_range; newZ_range = z_range; bool scaleDOWN = false; // Check to scale DOWN // // Check the X-range if(newX_range > XMAX) { scale = XMAX / x_range; newX_range = x_range * scale; newY_range = y_range * scale; newZ_range = z_range * scale; scaleDOWN = true; } // Check the Y-range if(newY_range > YMAX) { scale = YMAX / newY_range; newX_range = newX_range * scale; newY_range = newY_range * scale; newZ_range = newZ_range * scale; scaleDOWN = true; } // Check the Z-range if(newZ_range > ZMAX) { scale = ZMAX / newZ_range; scaleDOWN = true; } // Check to scale UP // if(!scaleDOWN) { float x_diff, y_diff, z_diff; // difference between range and MAX x_diff = XMAX - x_range; y_diff = YMAX - y_range; z_diff = ZMAX - z_range; if( (x_diff < y_diff) && (x_diff < z_diff) ) scale = XMAX / x_range; else if( (y_diff < x_diff) && (y_diff < z_diff) ) scale = YMAX / y_range; else if( (z_diff < x_diff) && (z_diff < y_diff) ) scale = ZMAX / z_range; } // Output the scale factor to the screen, so it can be // easily read by a shell script for processing cout << scale << endl; inFile.close(); return 0; } // fesists Function: checks for the existence of a file. int fexists( char fname[]) { int failed; ifstream inFile (fname, ios::nocreate); failed = inFile.fail(); inFile.close(); return (!failed); }