int main(int argc, char* argv[] ) { ALWAYS_ERROR_IF(argc < 3, "Usage: " << argv[0] << " inputsurf inputpoints" << endl); // Open input surface file ifstream is(argv[1]); ALWAYS_ERROR_IF(is.bad(), "Bad or no input filename"); // Read surface from file SplineSurface sf; is >> sf; // Get points ifstream pts(argv[2]); ALWAYS_ERROR_IF(pts.bad(), "Bad or no input filename"); int n; pts >> n; vector<double> pt(n*2); for (int i = 0; i < n; ++i) { pts >> pt[2*i] >> pt[2*i+1]; } std::vector<Point> p(3, Point(sf.dimension())); for (int i = 0; i < 10000; ++i) { for (int j = 0; j < n; ++j) { sf.point(p, pt[2*j], pt[2*j+1], 0); } } // cout << p[0] << p[1] << p[2] << (p[1] % p[2]); }
int main(int argc, char** argv) { // Read the curve from file std::ifstream input(argv[1]); if (input.bad()) { std::cerr << "File error (no file or corrupt file specified)." << std::endl; return 1; } ObjectHeader header; SplineSurface surface; input >> header >> surface; // Loop through parameter space const int samples = 50; double increment_u = (surface.endparam_u() - surface.startparam_u()) / (samples-1); double increment_v = (surface.endparam_v() - surface.startparam_v()) / (samples-1); Point result; double param_u = surface.startparam_u(); int prec = (int)std::cout.precision(15); for (int i = 0; i < samples; ++i) { double param_v = surface.startparam_v(); for (int j = 0; j < samples; ++j) { surface.point(result, param_u, param_v); std::cout << result[0] << "\t" << result[1] << "\t" << result[2] << std::endl; param_v += increment_v; } std::cout << std::endl; param_u += increment_u; } std::cout.precision(prec); return 0; }
int main(int argc, char** argv) { // Read the surface from a file in Go-format. string filename("degenerate_sf.g2"); cout << "\nProgram " << argv[0] << " using file " << filename.c_str() << endl; ifstream file(filename.c_str()); if (!file) { cerr << "\nFile error. Could not open file: " << filename.c_str() << endl; return 1; } ObjectHeader head; SplineSurface surf; file >> head; if (!head.classType() == SplineSurface::classType()) { THROW("Object type is NOT SplineSurface."); } file >> surf; file.close(); // Read the points from a file. xyz-coordinates. string point_filename("inp_degen_surf_close_points.dat"); ifstream pfile(point_filename.c_str()); if (!pfile) { cerr << "\nFile error. Could not open file: " << point_filename.c_str() << endl; return 1; } vector<Point> points; while (1) { Point p(3); pfile >> p; if (!pfile) break; points.push_back(p); } pfile.close(); int N = (int)points.size(); cout << "\nProgram '" << argv[0] << "' using input files '" << filename.c_str() << "' and '" << point_filename.c_str() << ", and output file 'degen_surf_close_points.g2'." << endl; // Find the points on the surface closest to these points. double close_u; // Closest point's u parameter. double close_v; // Closest point's v parameter. Point close_pt(3); // Closest point's coordinates. double close_dist; // Distance between the two points. double epsilon = 1e-8; // Parameter tolerance // Write to file vectors from a point to the closest point on the surface. ofstream fout2("degenerate_sf_close_points.g2"); // Class_LineCloud=410 MAJOR_VERSION=1 MINOR_VERSION=1 auxillary data=4 // The four auxillary data values defines the colour (r g b alpha) fout2 << "410 1 0 4 255 0 0 255" << endl; // Header. fout2 << N << endl; // Find closest point using the whole surface. (The two last arguments // 'RectDomain* domain_of_interest' and 'double *seed' are by default // equal to 0). cout << "\nClosest points from inputfile points to points on the surface "; for (int i=0; i<N; ++i) { surf.closestPoint(points[i], close_u, close_v, close_pt, close_dist, epsilon); fout2 << points[i] << ' ' << close_pt << endl; // write vector cout << "Point: " << points[i] << " Closest point: " << close_pt << "\nParameter values= " << close_u << " , " << close_v << " Closest distance= " << close_dist << endl; } fout2.close(); // Find closest point from points on the surface. Should be 0 + some tolerance. cout << "\nClosest points from points on the surface." << endl; const int nsp = 9; double du = (surf.endparam_u() - surf.startparam_u()) / (nsp-1); double dv = (surf.endparam_v() - surf.startparam_v()) / (nsp-1); cout << "Parameter u from " << surf.startparam_u() << " to " << surf.endparam_u() << " step " << du << endl; cout << "Parameter v from " << surf.startparam_v() << " to " << surf.endparam_v() << " step " << dv << endl; double max_dist = 0.0; Point point; for (double v=surf.startparam_v(); v<=surf.endparam_v(); v += dv) { for (double u=surf.startparam_u(); u<=surf.endparam_u(); u += du) { surf.point(point, u, v); // interpolate at u,v surf.closestPoint(point, close_u, close_v, close_pt, close_dist, epsilon); #ifdef DEBUG cout << "\n Point: " << point << "\nClosest point: " << close_pt << "\nParameter values= " << close_u << " , " << close_v << " Closest distance= " << close_dist << endl; #endif } max_dist = std::max(close_dist, max_dist); } cout << "\nMaximum distance between an interpolated point and the " << "corresponding input point is " << max_dist << '\n' << endl; }