Exemplo n.º 1
0
int main(int argc, char** argv)
{
    // Get geometric tolerance from the argument list.    
    double epsge = atof(argv[1]);

    // Read curve file
    //string inp_curve_filename("approj_curve.g2"); 
    //string inp_curve_filename("const_u_paramcurve.g2"); 
    string inp_curve_filename("const_v_paramcurve.g2"); 
    ifstream cfile(inp_curve_filename.c_str());
    if (!cfile) {
	cerr << "\nFile error. Could not open file: " << inp_curve_filename.c_str() << endl;
	return 1;
    }
    shared_ptr<SplineCurve> curve(new SplineCurve);
    ObjectHeader header;
    cfile >> header;
    if (!header.classType() == SplineCurve::classType()) {
	THROW("Object type is NOT SplineCurve.");
    }
    cfile >> (*curve);
    cfile.close();
    shared_ptr<ParamCurve> pcurve = curve;

    // Read surface file
    string inp_surf_filename("surface.g2");   
    ifstream sfile(inp_surf_filename.c_str());
    if (!sfile) {
	cerr << "\nFile error. Could not open file: " << inp_surf_filename.c_str() << endl;
	return 1;
    }
    shared_ptr<SplineSurface> surf(new SplineSurface);
    sfile >> header;
    if (!header.classType() == SplineSurface::classType()) {
	THROW("Object type is NOT SplineSurface.");
    }
    sfile >> (*surf);
    sfile.close();
    shared_ptr<ParamSurface> psurf = surf;

    // Create projection curves
    shared_ptr<SplineCurve> proj_cv;
    shared_ptr<SplineCurve> par_cv;
    CurveCreators::projectCurve(pcurve, psurf, epsge, proj_cv, par_cv);

    // Write 3D space curve to file.
    ofstream scvout("proj_space_curve.g2");
    //proj_cv->writeStandardHeader(scvout);
    scvout << "100 1 0 4 0 255 0  255" << endl; // write header. Green curve
    scvout << *proj_cv;    // write space spline curve data.
    scvout.close();

    // Write 2D parameter curve to file.
    ofstream pcvout("proj_param_curve.g2");
    par_cv->writeStandardHeader(pcvout); // write header
    pcvout << *par_cv;    // write parameter spline curve data.
    pcvout.close();

    return 0;
}
Exemplo n.º 2
0
void Outstation::appendVariableSizedObject( const ObjectHeader& h,
                                            const DnpObject& o)
{
    stats.logNormal( h.str( strbuf, sizeof(strbuf)));    
    h.encode( txFragment);
    appendUINT16( txFragment, o.size()); 
    o.encode( txFragment);
}
Exemplo n.º 3
0
int main(int argc, char** argv)
{
    string inp_curve_filename("approj_curve.g2"); 
    Point location(0.0, 5.0, 200.0);
    Point axis_dir(1.0, 0.0, 0.0);
    cout << "\nRunning program '" << argv[0] << "' with spline curve filename= '"
	 << inp_curve_filename.c_str() << "'." << endl;


    // Read spline curve file
    ifstream cfile(inp_curve_filename.c_str());
    if (!cfile) {
	cerr << "\nFile error. Could not open file: " << inp_curve_filename.c_str()
	     << endl;
	return 1;
    }
    shared_ptr<SplineCurve> spline_curve(new SplineCurve);
    ObjectHeader header;
    cfile >> header;
    if (!header.classType() == SplineCurve::classType()) {
	THROW("Object type is NOT SplineCurve.");
    }
    cfile >> (*spline_curve);
    cfile.close();

    // Print some curve information
    Point pnt3d(3);
    spline_curve->point(pnt3d, spline_curve->startparam());     
    cout << "\nSplineCurve:  Dim= " << spline_curve->dimension()
	 << "\nStart.  Param= " << spline_curve->startparam() << "  Point= "
	 << pnt3d << endl;
    spline_curve->point(pnt3d, spline_curve->endparam());    
    cout << "End.  Param= " << spline_curve->endparam() << "  Point= "
	 << pnt3d << endl;
    cout << "Bounding box =   " << spline_curve->boundingBox() << endl;

    // Create the SurfaceOfRevolution object.
    SurfaceOfRevolution surf_of_revolution(location, axis_dir, spline_curve);
    cout << "\nSurface:  Dim= " << surf_of_revolution.dimension() << endl;
    cout << "Bounding box =  " << surf_of_revolution.boundingBox() << endl;
    cout << "Location =  " << surf_of_revolution.getLocation() << endl;
    cout << "Axis direction =  " << surf_of_revolution.getAxisDir() << endl;


    // Make a SplineSurface representation and write to file.
    SplineSurface* spline_surf = surf_of_revolution.geometrySurface();
    ofstream fout("surface_of_revolution.g2");
    spline_surf->writeStandardHeader(fout);
    spline_surf->write(fout);
    fout.close();
    // cout << "\nOpen the files 'surface_of_revolution.g2' and 'approj_curve.g2'"
    //      << " in 'goview' to look at the results.\n" << endl;
    delete spline_surf;

    return 0;
}
Exemplo n.º 4
0
int main(int argc, char** argv)
{
    ASSERT(argc >= 2);
    ifstream file(argv[1]);
    ObjectHeader head;
    SplineSurface sf;
    SplineCurve cv;
    file >> head;
    if (head.classType() == SplineSurface::classType()) { 
	file >> sf;
    } else if (head.classType() == SplineCurve::classType()) {
Exemplo n.º 5
0
int main(int argc, char** argv)
{
  if (argc != 2 && argc != 4)
    {
      std::cout << "Usage; infile (nmb u pts) (nmb v pts)" << std::endl;
      return -1;
    }

  std::ifstream infile(argv[1]);
  ObjectHeader head;
  head.read(infile);
  BoundedSurface gosf;
  gosf.read(infile);

  const RectDomain& dom = gosf.containingDomain();
  double start_u = dom.umin();
  double end_u = dom.umax();
  double start_v = dom.vmin();
  double end_v = dom.vmax();

  int nmb_u = 20, nmb_v = 20;
  if (argc == 4)
    {
      nmb_u = atoi(argv[2]);
      nmb_v = atoi(argv[3]);
    }
  double del_u = (end_u - start_u)/(double)(nmb_u-1);
  double del_v = (end_v - start_v)/(double)(nmb_v-1);

  vector<Point> inside;
  int ki, kj;
  double u, v;
  for (v=start_v, ki=0; ki<nmb_v; v+=del_v, ki++)
    for (u=start_u, kj=0; kj<nmb_u; u+=del_u, kj++)
      {
	Point curr;

	if (!gosf.inDomain(u,v))
	  continue;

	gosf.point(curr, u, v);
	inside.push_back(curr);
      }

  std::ofstream out_file("inside_pts.g2");
  out_file << "400 1 0 4 255 0 0 255" << std::endl;
  out_file << inside.size() << std::endl;
  for (ki=0; ki < (int)inside.size(); ki++)
    {
      out_file << inside[ki][0] << " " << inside[ki][1] << " ";
      out_file << inside[ki][2] << std::endl;
    }
}
Exemplo n.º 6
0
  Object* Thread::unlock_locks(STATE, GCToken gct, CallFrame* calling_environment) {
    Thread* self = this;
    OnStack<1> os(state, self);

    LockedObjects& los = self->vm_->locked_objects();
    for(LockedObjects::iterator i = los.begin();
        i != los.end();
        ++i) {
      ObjectHeader* locked = *i;
      if(locked != self) {
        locked->unlock_for_terminate(state, gct, calling_environment);
      }
    }
    los.clear();
    return cNil;
  }
Exemplo n.º 7
0
int main(int argc, char** argv)
{
 
    if (argc != 6) {
	cout << "Usage: spline_sf x0 y0 z0 r" << endl;
	return 0;
    }

    ObjectHeader header;

    // Read the first curve from file
    ifstream filein(argv[1]);
    if (filein.bad()) {
	cerr << "File #1 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    double x0 = atof(argv[2]);
    double y0 = atof(argv[3]);
    double z0 = atof(argv[4]);
    double r = atof(argv[5]);

    header.read(filein);
    shared_ptr<ParamSurface> surf(new SplineSurface());
    surf->read(filein);
    filein.close();

    Point center(x0, y0, z0);    
    shared_ptr<SphereInt> sphere(new SphereInt(center, r));
//     double dummy_tol = 1e-03; // @@sbr Not yet used.
    shared_ptr<ParamObjectInt> par_obj_int(new ParamSurfaceInt(surf));
    shared_ptr<AlgObjectInt> alg_obj_int = sphere;

    shared_ptr<GeoTol> aepsge(new GeoTol(1.e-6));
    //IntersectorAlgPar int_alg_par(alg_obj_int, par_obj_int, aepsge);
    IntersectorAlgPar int_alg_par(sphere, par_obj_int, aepsge);

    int_alg_par.compute();
    std::vector<shared_ptr<IntersectionPoint> > int_points;
    std::vector<shared_ptr<IntersectionCurve> > int_curves;
    int_alg_par.getResult(int_points, int_curves);

    cout << "IntPoints found: " << int_points.size() << endl;
    cout << "IntCurves found: " << int_curves.size() << endl;

    return 0;
}
Exemplo n.º 8
0
//-*****************************************************************************
void WriteIdentifier( const ObjectHeader &ohead )
{
    std::string name = ohead.getFullName();
    char* nameArray[] = { const_cast<char*>( name.c_str() ), RI_NULL };

    RiAttribute(const_cast<char*>( "identifier" ), const_cast<char*>( "name" ),
                nameArray, RI_NULL );
}
Exemplo n.º 9
0
int main(int argc, char* argv[] )
{
    if (argc != 5)
    {
        std::cout << "Usage: " << argv[0]
                  << " input_ellipse tmin tmax output_subcurve" << endl;
        return -1;
    }

    // Open input surface file
    ifstream is(argv[1]);
    double tmin(atof(argv[2]));
    double tmax(atof(argv[3]));
    ofstream os(argv[4]);
    if (is.bad())
    {
        std::cout << "Bad or no input filename" << std::endl;
        return -1;
    }

    // Read surface from file
    ObjectHeader head;
    Ellipse ellipse; // Typically: centre, dir, normal, r1, r2.
    is >> head;
    ASSERT(head.classType() == Ellipse::classType());
    is >> ellipse;

    if (tmin < ellipse.startparam() || tmax > ellipse.endparam())
    {
        std::cout << "tmin or tmax outside domain of ellipse." << std::endl;
        return -1;
    }

    std::cout << "Writing to file." << std::endl;

    // Extract subcurve, write to file.
    ellipse.setParamBounds(tmin, tmax);

    shared_ptr<SplineCurve> sub_ellipse(ellipse.geometryCurve());

    sub_ellipse->writeStandardHeader(os);
    sub_ellipse->write(os);

    return 0;
}
Exemplo n.º 10
0
int main(int argc, char** argv)
{
    if (argc < 3) {
	cerr << "Usage: " << argv[0] << " u_res v_res" << endl;
	return 1;
    }
    int ures = atoi(argv[1]);
    int vres = atoi(argv[2]);

    ObjectHeader head;
    cin >> head;
    ASSERT(head.classType() == SplineSurface::classType());
    SplineSurface sf;
    cin >> sf;
    vector<double> points;
    vector<double> param_u;
    vector<double> param_v;
    sf.gridEvaluator(ures, vres, points, param_u, param_v);
    RectGrid grid(ures, vres, sf.dimension(), &points[0]);
    grid.writeStandardHeader(cout);
    grid.write(cout);
}
int main(int argc, char *argv[])
{
    if (argc != 3)
    {
	std::cout << "Usage: sfs_file (.g2) repaired_sfs_file (.g2)" << std::endl;
	return -1;
    }

    std::ifstream filein(argv[1]); // Input bd sfs (may contain other objects).
    std::ofstream fileout(argv[2]); // Fixed bd sfs (and unaltered other objects).

    // For BoundedSurface we may choose to recreate all the boundary parameter curves.
    const bool recreate_par_cvs = true;
    if (recreate_par_cvs)
    {
	cout << "Recreating all parameter curve for CurveOnSurface." << endl;
    }

    // Create the default factory
    GoTools::init();

    ObjectHeader header;
    int num_bd_sfs = 0;
    int num_bd_sfs_fixed = 0;
    int num_bd_sfs_fix_failed = 0;
    int obj_id = 0;
    while (filein)
    {
	std::cout << "Object number: " << obj_id << std::endl;
	try {
	    header.read(filein);
	}
	catch (...)
	{
	    MESSAGE("Failed reading the Header!");
	    break; // Assuming we are either done or the rest of the file is garbage ...
	}

	shared_ptr<GeomObject> geom_obj(Factory::createObject(header.classType()));
	try
	{
	    geom_obj->read(filein);
	}
	catch (...)
	{
	    MESSAGE("Failed reading the GeomObject!");
	}
	if (geom_obj->instanceType() != Class_BoundedSurface)
	{
	    cout << "Writing to file an object of type :" << geom_obj->instanceType()<< endl;
	    geom_obj->writeStandardHeader(fileout);
	    geom_obj->write(fileout);
	} else if (geom_obj->instanceType() == Class_BoundedSurface)
	{
	    ++num_bd_sfs;
	    BoundedSurface* bd_sf = dynamic_cast<BoundedSurface*>(geom_obj.get());
	    double epsgeo = 1.5e-02;// bd_sf->getEpsGeo(); // The smallest for all the loops.
	    int valid_state = 0;
	    bool is_valid = bd_sf->isValid(valid_state);


#ifndef NDEBUG
	    std::ofstream debug("tmp/debug.g2");
	    ParamSurface* under_sf = bd_sf->underlyingSurface().get();
	    under_sf->writeStandardHeader(debug);
	    under_sf->write(debug);
	    for (int ki = 0; ki < bd_sf->numberOfLoops(); ++ki)
	    {
		shared_ptr<CurveLoop> loop = bd_sf->loop(ki);
		for (size_t kj = 0; kj < loop->size(); ++kj)
		{
		    shared_ptr<ParamCurve> cv = (*loop)[kj];
		    if (cv->instanceType() == Class_CurveOnSurface)
		    {
			shared_ptr<CurveOnSurface> cv_on_sf =
			    dynamic_pointer_cast<CurveOnSurface, ParamCurve>(cv);
			if (cv_on_sf->parameterCurve() != NULL) {
			    shared_ptr<SplineCurve> pcv =
				dynamic_pointer_cast<SplineCurve, ParamCurve>
				(cv_on_sf->parameterCurve());
			    if (pcv.get() != NULL)
				SplineDebugUtils::writeSpaceParamCurve(*pcv, debug, 0.0);
			    else
			    {
				cv_on_sf->parameterCurve()->writeStandardHeader(debug);
				cv_on_sf->parameterCurve()->write(debug);
			    }
			}
			if (cv_on_sf->spaceCurve() != NULL)
			{
			    cv_on_sf->spaceCurve()->writeStandardHeader(debug);
			    cv_on_sf->spaceCurve()->write(debug);
			}
		    }
		    else
		    {
			cv->writeStandardHeader(debug);
			cv->write(debug);
		    }
		}
	    }
	    double debug_val = 0.0;
#endif

	    if (valid_state < 0)//== -2)
	    {

		if (bd_sf->underlyingSurface()->instanceType() == Class_Cylinder)
		{ // Special treatment checking for par cvs crossing the seem.
		    bool fixed = fixParCvCrossingCylinderSeem(bd_sf);
		    if (fixed)
		    {
			MESSAGE("A parameter curve crossed the seem, fixed!");
			is_valid = bd_sf->isValid(valid_state);
			if (is_valid)
			{
			    cout << "Success! obj_id = " << obj_id << endl;
			    ++num_bd_sfs_fixed;
			    continue;
			}
		    }
		}

		vector<CurveLoop> bd_loops = bd_sf->allBoundaryLoops();		
		//We must create missing parameter curves project space curves).
		for (size_t ki = 0; ki < bd_loops.size(); ++ki)
		{
		    for (size_t kj = 0; kj < bd_loops[ki].size(); ++kj)
		    {
			try
			{
			    if (bd_loops[ki][kj]->instanceType() == Class_CurveOnSurface)
			    {
				CurveOnSurface* cv_on_sf = dynamic_cast<CurveOnSurface*>(bd_loops[ki][kj].get());
				shared_ptr<ParamCurve> empty_par_cv;
				if (recreate_par_cvs)
				{
				    cout << "Removing parameter curve!" << endl;
				    cv_on_sf->setParameterCurve(empty_par_cv);
				}
				cv_on_sf->ensureParCrvExistence(epsgeo);
			    }
			}
			catch (...)
			{
			    MESSAGE("Failed projecting space curve!");
			}
		    }
		}
		is_valid = bd_sf->isValid(valid_state);
		if (is_valid)
		{
		    MESSAGE("Success!");
		}
	    }

	    if (!is_valid)
	    {
		MESSAGE("Trying to fix the BoundedSurface!");

		double max_loop_gap = -1.0;
		bool success = bd_sf->fixInvalidSurface(max_loop_gap);
		if (success)
		{
		    cout << "Success! ki = " << obj_id << endl;
		    ++num_bd_sfs_fixed;
		    bd_sf->writeStandardHeader(fileout);
		    bd_sf->write(fileout);
		}
		else
		{
		    is_valid = bd_sf->isValid(valid_state);
		    MESSAGE("Failed fixing bd_sf! Status: " << valid_state <<
			    ". Object id = " << obj_id);
		    ++num_bd_sfs_fix_failed;

		    if (valid_state == -1)
		    { // This means we may need to replace the epsgeo with a larger value.
			// @@sbr201310 Replace epsgeo with larger value!
			double epsgeo = bd_sf->getEpsGeo();
			// We use the same tolerance for all the loops.
			int num_loops = bd_sf->numberOfLoops();
			double global_max_loop_sf_dist = 0.0;
			int num_samples = 100; // @@sbr201310 The number of samples should not be a user input.
			for (int ki = 0; ki < num_loops; ++ki)
			{
			    double max_loop_sf_dist = bd_sf->maxLoopSfDist(ki, num_samples);
			    if (max_loop_sf_dist > global_max_loop_sf_dist)
			    {
				global_max_loop_sf_dist = max_loop_sf_dist;
			    }
			}

			double new_epsgeo = 1.1*global_max_loop_sf_dist;
			std::cout << "epsgeo: " << epsgeo << ", new_epsgeo: " << new_epsgeo << std::endl;
			for (int ki = 0; ki < num_loops; ++ki)
			{
			    if (bd_sf->loop(ki)->getSpaceEpsilon() < new_epsgeo)
			    {
				bd_sf->loop(ki)->setSpaceEpsilon(new_epsgeo);
			    }
			}
			// /// Get a shared pointer to a specific boundary loop
			// shared_ptr<CurveLoop> loop(int idx)
			// { return boundary_loops_[idx]; }

			// std::vector<CurveLoop> all_bd_loops = bd_sf->absolutelyAllBoundaryLoops();
			// for (size_t ki = 0; ki < all_bd_loops.size(); ++ki)
			// {
			//     if (all_bd_loops[ki].getSpaceEpsilon() < new_epsgeo)
			//     {
			// 	all_bd_loops[ki].setSpaceEpsilon(new_epsgeo);
			//     }
			// }
			// shared_ptr<ParamSurface> under_sf = bd_sf->underlyingSurface();
			// bd_sf = shared_ptr<BoundedSurface>
			//     (new BoundedSurface(under_sf, all_bd_loops, new_epsgeo));
			bd_sf->analyzeLoops();
			is_valid = bd_sf->isValid(valid_state);
			std::cout << "valid_state after tolerance change: " << valid_state << std::endl;
			if (is_valid)
			{
			    --num_bd_sfs_fix_failed;
			    ++num_bd_sfs_fixed;
			}
			bd_sf->writeStandardHeader(fileout);
			bd_sf->write(fileout);
		    }
		    else
		    {
			// We write to file the underlying surfaces and the space curves.
			shared_ptr<ParamSurface> under_sf = bd_sf->underlyingSurface();
			under_sf->writeStandardHeader(fileout);
			under_sf->write(fileout);
			vector<CurveLoop> bd_loops = bd_sf->allBoundaryLoops();
			for (size_t ki = 0; ki < bd_loops.size(); ++ki)
			{
			    for (size_t kj = 0; kj < bd_loops[ki].size(); ++kj)
			    {
				shared_ptr<ParamCurve> par_cv = bd_loops[ki][kj];
				if (par_cv->instanceType() == Class_CurveOnSurface)
				{
				    CurveOnSurface* cv_on_sf = dynamic_cast<CurveOnSurface*>(par_cv.get());
				    if (cv_on_sf->spaceCurve())
				    {
					cv_on_sf->spaceCurve()->writeStandardHeader(fileout);
					cv_on_sf->spaceCurve()->write(fileout);
				    }
				    else
				    {
					MESSAGE("Missing space curve!");
				    }
				}
				else
				{
				    MESSAGE("Unexpected curve type!");
				}
			    }
			}
		    }
		}
	    }
	    else
	    {
		bd_sf->writeStandardHeader(fileout);
		bd_sf->write(fileout);
	    }
	}
	// else
	// {
	//     geom_obj->writeStandardHeader(fileout);
	//     geom_obj->write(fileout);
	// }

	++obj_id;
    }

    std::cout << "num_bd_sfs: " << num_bd_sfs << ", num_bd_sfs_fixed: " << num_bd_sfs_fixed <<
	", num_bd_sfs_fix_failed: " << num_bd_sfs_fix_failed << std::endl;
}
Exemplo n.º 12
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;

}
Exemplo n.º 13
0
int main(int argc, char** argv)
{
 
    if (argc != 4) {
	cout << "Usage: test_CvCvIntersector FileCv1 FileCv2 aepsge"
	     << endl;
	return 0;
    }


    ObjectHeader header;

    // Read the first curve from file
    ifstream input1(argv[1]);
    if (input1.bad()) {
	cerr << "File #1 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    header.read(input1);
    shared_ptr<ParamCurve> curve1(new SplineCurve());
    curve1->read(input1);
    input1.close();
    
    // Read the second curve from file
    ifstream input2(argv[2]);
    if (input2.bad()) {
	cerr << "File #2 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    header.read(input2);
    shared_ptr<ParamCurve> curve2(new SplineCurve());
    curve2->read(input2);
    input2.close();

    double aepsge;
    aepsge = atof(argv[3]);

//     cout << "\nFile : " << argv[2] << " Parameter range u: "
// 	 << curve1->startparam_u() <<" " << curve1->endparam_u()
// 	 << " Parameter range v: " << curve1->startparam_v() <<" " 
// 	 << curve1->endparam_v();

//     cout << "\nFile : " << argv[2] << " Parameter range u: "
// 	 << curve2->startparam_u() <<" " << curve2->endparam_u()
// 	 << " Parameter range v: " << curve2->startparam_v() <<" " 
// 	 << curve2->endparam_v() << endl;

    shared_ptr<ParamGeomInt> scurveint1 =
	shared_ptr<ParamGeomInt>(new SplineCurveInt (curve1));
    shared_ptr<ParamGeomInt> scurveint2 =
	shared_ptr<ParamGeomInt>(new SplineCurveInt (curve2));

    CvCvIntersector cvcvintersect (scurveint1, scurveint2, aepsge);
    cvcvintersect.compute();

    std::vector<shared_ptr<IntersectionPoint> > intpts;
    std::vector<shared_ptr<IntersectionCurve> > intcrv;
    cvcvintersect.getResult(intpts, intcrv);
    printf("Number of points: %d \n", int(intpts.size()));
    printf("Number of curves: %d \n", int(intcrv.size()));

    int ki, kj;
    for (ki=0; ki < int(intpts.size()); ki++) {
	std::vector<double> par = intpts[ki]->getPar();
	for (kj=0; kj<int(par.size()); kj++)
	    std::cout << par[kj] << " ";
	std::cout << std::endl;
    }

    return 0;
}
Exemplo n.º 14
0
int main(int argc, char** argv)
{
    if (argc != 7) {
	cout << "Usage: test_curveSplineCurveInt FILE1 FILE2 "
	     << "pstart1 pstart2 pstop1 pstop2"
	     << endl;
	return 0;
    }
    double pstart1, pstart2, pstop1, pstop2;
    pstart1 = atof(argv[3]);
    pstart2 = atof(argv[4]);
    pstop1 = atof(argv[5]);
    pstop2 = atof(argv[6]);
    ObjectHeader header;

    // Read first curve from file
    ifstream input(argv[1]);
    if (input.bad()) {
	cerr << "File #1 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    header.read(input);
    shared_ptr<SplineCurve> curve1(new SplineCurve());
    curve1->read(input);
    input.close();

   
    
    // Read second curve from file
    ifstream input2(argv[2]);
    if (input2.bad()) {
	cerr << "File #2 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    header.read(input2);
    shared_ptr<SplineCurve> curve2(new SplineCurve());
    curve2->read(input2);
    input.close();

//     int prec = std::cout.precision(16);
    cout << "\nFile : " << argv[1] << " Parameter range: "
	 << curve1->startparam() <<" " << curve1->endparam();
    cout << "  Start: " << pstart1 << "  Stop: " << pstop1;
    cout << "\nFile : " << argv[2] << " Parameter range: "
	 << curve2->startparam() <<" " << curve2->endparam();
    cout << "  Start: " << pstart2 << "  Stop: " << pstop2 << endl;

    const double eps = 1.e-4;
    cout << "  Eps= " << eps << endl;

//     SplineCurveInt sci1(curve1);

//     SplineCurveInt sci2(curve2);

//     int istat;
//     istat = sci1.checkCoincidence(pstart1, pstop1, eps, &sci2,
// 				  pstart2, pstop2);

//     cout << "\nistat = " << istat;

//     if (istat==0)
// 	cout << "  Curves are not coinciding." << endl;
//     else
// 	cout << "  Curves are coinciding." << endl;

//     std::cout.precision(prec);  

    return 0;
}
Exemplo n.º 15
0
int main(int argc, char** argv)
{
    if (argc != 4) {
	cout << "Usage: " << argv[0] << " FileSf FileCv aepsge" << endl;
	return 0;
    }

    ObjectHeader header;

    // Read the first curve from file
    ifstream input1(argv[1]);
    if (input1.bad()) {
	cerr << "File #1 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    header.read(input1);
    SplineSurface surf;
    surf.read(input1);
    input1.close();
    
    // Read the second curve from file
    ifstream input2(argv[2]);
    if (input2.bad()) {
	cerr << "File #2 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    header.read(input2);
    SplineCurve curve;
    curve.read(input2);
    input2.close();

    double aepsge;
    aepsge = atof(argv[3]);

    // Set up and run the intersection algorithm
    SISLCurve* pcurve = Curve2SISL(curve);
    SISLSurf* psurf = GoSurf2SISL(surf);

    double astart1 = curve.startparam();
    double estart2[] = { surf.startparam_u(), surf.startparam_v() };
    double aend1 = curve.endparam();
    double eend2[] = { surf.endparam_u(), surf.endparam_v() };
    cout << "astart1 = " << astart1 << endl
	 << "estart2[] = { " << estart2[0] << ", "
	 << estart2[1] << " }" << endl
	 << "aend1 = " << aend1 << endl
	 << "eend2[] = { " << eend2[0] << ", " 
	 << eend2[1] << " }" << endl;

    double anext1 = astart1;
    double enext2[] = { estart2[0], estart2[1] };
//     double anext1 = 0.0;
//     double enext2[] = { 2.0, 0.0 };
    cout << "anext1 = " << anext1 << endl
	 << "enext2[] = { " << enext2[0] << ", "
	 << enext2[1] << " }" << endl;

    double cpos1;
    double gpos2[2];
    int jstat = 0;
    cout << "jstat = " << jstat << endl;

    s1772(pcurve, psurf, aepsge, astart1, estart2, aend1, eend2,
	  anext1, enext2, &cpos1, gpos2, &jstat);

    // Write the results
    cout << "Results s1772:" << endl
	 << "jstat = " << jstat << endl
	 << "cpos1 = " << cpos1 << endl
	 << "gpos2[] = { " << gpos2[0] << ", "
	 << gpos2[1] << " }" << endl;

    return 0;

}
Exemplo n.º 16
0
//===========================================================================
vector<double>  
TrimCrvUtils::readTrimPoints(ifstream& filein, Point& translate_vec)
//===========================================================================
{
  vector<double> pts_2d;
  translate_vec = Point(0.0, 0.0, 0.0);
  const bool translate_model = true;//false;
  if (translate_model)
    {
      MESSAGE("Switched off translation of the model to the origin!");
    }

  ObjectHeader header;
  header.read(filein);
  if (header.classType() == Class_PointCloud)
    {
      PointCloud3D pt_cloud;
      pt_cloud.read(filein);
      if (translate_model)
	{
	  translateToOrigin(pt_cloud, translate_vec);
	}
      const int dim = pt_cloud.dimension();
      assert(dim == 3);
      const int num_pts = pt_cloud.numPoints();
      vector<double> pts_3d(pt_cloud.rawData(), pt_cloud.rawData() + dim*num_pts);
      pts_2d.resize(num_pts*2);
      for (int ki = 0; ki < num_pts; ++ki)
	{
	  pts_2d[ki*2] = pts_3d[ki*dim];
	  pts_2d[ki*2+1] = pts_3d[ki*dim+1];
	}
    }
  else if (header.classType() == Class_LineCloud)
    {
      LineCloud line_cloud;
      line_cloud.read(filein);
      if (translate_model)
	{
	  translateToOrigin(line_cloud, translate_vec);
	}
      // Assuming the dimension is 3. Which is a requirement by LineCloud, strangely enough.
      const int dim = 3;
      const int num_lines = line_cloud.numLines();
      const int num_pts = num_lines + 1;
      pts_2d.resize(num_pts*2);
      const double* raw_data = line_cloud.rawData();
      pts_2d[0] = raw_data[0];
      pts_2d[1] = raw_data[1];
      for (int ki = 1; ki < num_pts; ++ki)
	{
	  pts_2d[ki*2] = raw_data[ki*dim*2-dim];
	  pts_2d[ki*2+1] = raw_data[ki*dim*2-dim+1];
	}
    }
  else
    {
      MESSAGE("Object  type " << header.classType() << " is not supported.");
    }

  return pts_2d;
}
Exemplo n.º 17
0
int main(int argc, char** argv)
{
#ifndef _MSC_VER
    setenv("DEBUG", "1", 1);
    setenv("DEBUG_PAR", "1", 1);
    setenv("DEBUG_FINISH", "1", 1);
    setenv("DEBUG_IMPL", "1", 1);
    setenv("SUBDIV_SFCV", "1", 1);

    if (getenv("DEBUG") && (*getenv("DEBUG"))=='1')
	cout << "DEBUG=1" << endl;
    if (getenv("DEBUG_PAR") && (*getenv("DEBUG_PAR"))=='1')
	cout << "DEBUG_PAR=1" << endl;
    if (getenv("DEBUG_FINISH") && (*getenv("DEBUG_FINISH"))=='1')
	cout << "DEBUG_FINISH=1" << endl;
    if (getenv("DEBUG_IMPL") && (*getenv("DEBUG_IMPL"))=='1')
	cout << "DEBUG_IMPL=1" << endl;
    if (getenv("SUBDIV_SFCV") && (*getenv("SUBDIV_SFCV"))=='1')
	cout << "SUBDIV_SFCV=1" << endl;
#endif // _MSC_VER
 
    if (argc != 5 && argc != 6) {
	cout << "Usage: test_CvCvIntersector FileSf FileCv"
	     << " aepsge switch-order (OutputFile)" << endl;
	return 0;
    }

    ObjectHeader header;

    // Read the first curve from file
    ifstream input1(argv[1]);
    if (input1.bad()) {
	cerr << "File #1 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    header.read(input1);
    shared_ptr<ParamSurface> surf(new SplineSurface());
    surf->read(input1);
    input1.close();
    
    // Read the second curve from file
    ifstream input2(argv[2]);
    if (input2.bad()) {
	cerr << "File #2 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    header.read(input2);
    shared_ptr<ParamCurve> curve(new SplineCurve());
    curve->read(input2);
    input2.close();

    double aepsge;
    aepsge = atof(argv[3]);

    int seq;
    seq = atoi(argv[4]);

    ofstream tmpout;
    if (argc == 6)
	tmpout.open(argv[5]);
    ostream& out = (argc == 6) ? tmpout : cout;
    out << setprecision(8);

    // Setup the SplineSurfaceInt and SplineCurveInt objects
    shared_ptr<ParamGeomInt> ssurfint =
	shared_ptr<ParamGeomInt>(new SplineSurfaceInt (surf));
    shared_ptr<ParamGeomInt> scurveint =
	shared_ptr<ParamGeomInt>(new SplineCurveInt (curve));

    // Set up and run the intersection algorithm
    if (seq)
    {
	SfCvIntersector sfcvintersect(scurveint, ssurfint, aepsge);
	sfcvintersect.compute();

	// Get the results
	vector<shared_ptr<IntersectionPoint> > intpts;
	vector<shared_ptr<IntersectionCurve> > intcrv;
	sfcvintersect.getResult(intpts, intcrv);

	cout << "Number of points: " << intpts.size() << endl;
	cout << "Number of curves: " << intcrv.size() << endl;

	for (int ki = 0; ki < int(intpts.size()); ki++) {
	    double dist = intpts[ki]->getDist();
	    vector<double> par = intpts[ki]->getPar();
	    for (int kj = 0; kj < int(par.size()); kj++)
		cout << par[kj] << " ";
	    cout << ": dist = " << dist << endl;
	}

	// Write regression test data
	int npoints = (int)intpts.size();
	int ncurves = (int)intcrv.size();
	vector<double> par;
	out << "-1 ______________Case sf-cv intersector______________"
	    << endl;
	out << "0 Surf-Curve:    npoints = " << npoints
	    << "    ncurves = " << ncurves << endl;
	for (int i = 0; i < npoints; ++i) {
	    out << "1 Point: ";
	    par = intpts[i]->getPar();
	    for (int j=0; j < int(par.size()); j++) {
		out << par[j] << " ";
	    }
	    out << endl;
	}
	for (int i = 0; i < ncurves; ++i) {
	    out << "2 Curve:    Start = ";
	    int nguide = intcrv[i]->numGuidePoints(); 
	    shared_ptr<IntersectionPoint> startpt
		= intcrv[i]->getGuidePoint(0);
	    par = startpt->getPar();
	    for (int j=0; j < int(par.size()); j++) {
		out << par[j] << " ";
	    }
	    out << "   End = ";
	    shared_ptr<IntersectionPoint> endpt
		= intcrv[i]->getGuidePoint(nguide-1);
	    par = endpt->getPar();
	    for (int j=0; j < int(par.size()); j++) {
		out << par[j] << " ";
	    }
	    out << endl;
	}

    }
    else
    {
	SfCvIntersector sfcvintersect(ssurfint, scurveint, aepsge);
	sfcvintersect.compute();

	// Get the results
	vector<shared_ptr<IntersectionPoint> > intpts;
	vector<shared_ptr<IntersectionCurve> > intcrv;
	sfcvintersect.getResult(intpts, intcrv);
	cout << "Number of points: " << intpts.size() << endl;
	cout << "Number of curves: " << intcrv.size() << endl;

	for (int ki = 0; ki < int(intpts.size()); ki++) {
	    double dist = intpts[ki]->getDist();
	    vector<double> par = intpts[ki]->getPar();
	    for (int kj = 0; kj < int(par.size()); kj++)
		cout << par[kj] << " ";
	    cout << ": dist = " << dist << endl;
	}

	// Write regression test data
	int npoints = (int)intpts.size();
	int ncurves = (int)intcrv.size();
	vector<double> par;
	out << "-1 ______________Case sf-cv intersector______________"
	    << endl;
	out << "0 Surf-Curve:    npoints = " << npoints
	    << "    ncurves = " << ncurves << endl;
	for (int i = 0; i < npoints; ++i) {
	    out << "1 Point: ";
	    par = intpts[i]->getPar();
	    for (int j=0; j < int(par.size()); j++) {
		out << par[j] << " ";
	    }
	    out << endl;
	}
	for (int i = 0; i < ncurves; ++i) {
	    out << "2 Curve:    Start = ";
	    int nguide = intcrv[i]->numGuidePoints(); 
	    shared_ptr<IntersectionPoint> startpt
		= intcrv[i]->getGuidePoint(0);
	    par = startpt->getPar();
	    for (int j=0; j < int(par.size()); j++) {
		out << par[j] << " ";
	    }
	    out << "   End = ";
	    shared_ptr<IntersectionPoint> endpt
		= intcrv[i]->getGuidePoint(nguide-1);
	    par = endpt->getPar();
	    for (int j=0; j < int(par.size()); j++) {
		out << par[j] << " ";
	    }
	    out << endl;
	}

    }

    return 0;

}
Exemplo n.º 18
0
int main(int argc, char** argv)
{
    const string inp_curve_filename("approj_curve.g2");

    cout << "\nRunning program '" << argv[0]
	 << "'\nSpline curve filename= '"
	 << inp_curve_filename.c_str() << "'." << endl;

    // Read spline curve file
    ifstream cfile(inp_curve_filename.c_str());
    if (!cfile) {
	cerr << "\nFile error. Could not open file: "
	     << inp_curve_filename.c_str() << endl;
	return 1;
    }
    shared_ptr<SplineCurve> curve(new SplineCurve);
    ObjectHeader header;
    cfile >> header;
    if (!header.classType() == SplineCurve::classType()) {
	THROW("Object type is NOT SplineCurve.");
    }
    cfile >> (*curve);
    cfile.close();

    // Print some curve information
    Point pnt3d(3);
    curve->point(pnt3d, curve->startparam());     
    cout << "\nSplineCurve:  Dim= " << curve->dimension()
	 << "\nStart.  Param= " << curve->startparam() << "  Point= "
	 << pnt3d << endl;
    curve->point(pnt3d, curve->endparam());    
    cout << "End.  Param= " << curve->endparam() << "  Point= "
	 << pnt3d << endl;
    cout << "Bounding box =   " << curve->boundingBox() << endl;

    // Create a surface by rotating the curve around the axis an angle of 2PI.
    double angle = 2.0*M_PI;
    Point point_on_axis(0.0, 5.0, 200.0); 
    Point axis_dir(1.0, 0.0, 0.0);
    SplineSurface* surf =
	SweepSurfaceCreator::rotationalSweptSurface(*curve, angle,
						    point_on_axis, axis_dir);
    cout << "\nSurface:  Dim= " << surf->dimension() << endl;
    cout << "Bounding box =  "  << surf->boundingBox() << endl;
    cout << "Point on axis =  " << point_on_axis << endl;
    cout << "Axis direction = " << axis_dir << endl;

    // Open output  file
    ofstream fout("rotational_swept_surface.g2");
    // Write curve to file. Colour=red.
    fout << "100 1 0 4 255 0 0  255" << endl;
    curve->write(fout);

    // Write surface to file. Default colour=blue.    
    surf->writeStandardHeader(fout);
    surf->write(fout);

    // Write axis to file. Colour=green.
    double dlength = 1.2*(surf->boundingBox().high()[0] -
			  surf->boundingBox().low()[0]);
    Point endp = point_on_axis + dlength*axis_dir;
    SplineCurve* axis =  new SplineCurve(point_on_axis, endp);
    fout << "100 1 0 4 0 255 0  255" << endl;
    axis->write(fout);

    // cout << "Open the file 'rotational_swept_surface.g2' in 'goview' to look"
    //      << " at the results" << endl;

    delete surf;
    delete axis;

    return 0;
}
Exemplo n.º 19
0
int main(int argc, char** argv)
{
    if (argc != 5) {
	cout << "\nUsage: " << argv[0]
	     << " Infile1 Infile2 continuity Outfile\n" << endl;
	exit(-1);
    }
    cout << "\nRunning program " << argv[0]
	 << "\nInfile1    = " << argv[1]
	 << "\nInfile2    = " << argv[2]
	 << "\ncontinuity = " << argv[3]
	 << "\nOutfile    = " << argv[4]
	 <<  '\n' << endl;
    // Read first curve file
    ifstream infile(argv[1]);
    if (!infile) {
	cerr << "\nFile error. Could not open file: " << argv[1] << endl;
	return 1;
    }
    SplineCurve curve, other_curve;
    ObjectHeader header;
    infile >> header >> curve;
    if (!header.classType() == SplineCurve::classType()) {
	THROW("Object type is NOT SplineCurve.");
    }
    infile.close();

    // Read second curve file
    ifstream infile2(argv[2]);
    if (!infile2) {
	cerr << "\nFile error. Could not open file: " << argv[2] << endl;
	return 1;
    }
    infile2 >> header >> other_curve;
    if (!header.classType() == SplineCurve::classType()) {
	THROW("Object type is NOT SplineCurve.");
    }
    infile2.close();

    cout << "Curve orders : " << curve.order() << " and " << other_curve.order()
	 << endl;
    // Append the start of the second curve to the end of the first curve.
    double dist = 0; // The estimated maximum distorsion after 'smoothing' of
                     // joined curve to achieve the desired continuity.
    int continuity = atoi(argv[3]);  // Continuity. From -1 to order()-1.
    bool repar = true;     // The reparametrizatin of the second curve will also
                           // be scaled as a function of position of control
                           // points close to the transition.
    curve.appendCurve(&other_curve, continuity, dist, repar);
    cout << "Curve orders : " << curve.order() << " and " << other_curve.order()
 	 << " after appending curve." << endl;
    cout << "Estimated difference between original and smooth curve: "
	 << dist << endl;

    // Write the the new curve to output file. 
    ofstream outfile(argv[4]);
    outfile << header << curve;	

    return 0;

}
Exemplo n.º 20
0
int main(int argc, char *argv[])
{
  if (argc != 4) {
    std::cout << "Usage: spline_sf (.g2) knot_ind_u_min knot_ind_v_min" << std::endl;
    return -1;
  }

  std::ifstream filein(argv[1]); // Input lr spline.
  int ind_u_min = atoi(argv[2]);
  int ind_v_min = atoi(argv[3]);

  ObjectHeader header;
  header.read(filein);
  SplineSurface spline_sf;
  spline_sf.read(filein);

  // We write to screen some info about the spline.
  int dim = spline_sf.dimension();
  int order_u = spline_sf.order_u();
  int order_v = spline_sf.order_v();
  int num_coefs_u = spline_sf.numCoefs_u();
  int num_coefs_v = spline_sf.numCoefs_v();
  std::cout << "Spline sf info:  dim = " << dim << ", order_u = " << order_u << ", order_v = " << order_v << std::endl;
  std::cout << "                 num_coefs_u = " << num_coefs_u << ", num_coefs_v = " << num_coefs_v << std::endl;


  shared_ptr<SplineSurface> bez_sf;
  double umin, umax, vmin, vmax;
  if (ind_u_min == -1 && ind_v_min == -1)
  {
      puts("We use the global bezier refinement matrix code!");
      bez_sf = SplineUtils::refineToBezier(spline_sf);
      umin = bez_sf->startparam_u();
      umax = bez_sf->endparam_u();
      vmin = bez_sf->startparam_v();
      vmax = bez_sf->endparam_v();
  }
  else
  {
      const BsplineBasis& basis_u = spline_sf.basis_u();
      vector<double>::const_iterator iter = basis_u.begin() + ind_u_min;
      umin = *iter;
      while (*iter == umin)
	  ++iter;
      umax = *iter;
      ind_u_min = iter - basis_u.begin() - 1;

      const BsplineBasis& basis_v = spline_sf.basis_v();
      iter = basis_v.begin() + ind_v_min;
      vmin = *iter;
      while (*iter == vmin)
	  ++iter;
      vmax = *iter;
      ind_v_min = iter - basis_v.begin() - 1;

      vector<double> bez_coefs, bez_coefs2;
      Go::SplineUtils::refinedBezierCoefsCubic(spline_sf,
					       ind_u_min, ind_v_min,
					       bez_coefs);

      int num_bez_coefs_u = order_u;
      int num_bez_coefs_v = order_v;
      vector<double> knots_u(order_u, umin);
      knots_u.insert(knots_u.end(), order_u, umax);
      vector<double> knots_v(order_v, vmin);
      knots_v.insert(knots_v.end(), order_v, vmax);
      bez_sf = shared_ptr<SplineSurface>
	  (new SplineSurface(num_bez_coefs_u, num_bez_coefs_v,
			     order_u, order_v,
			     knots_u.begin(), knots_v.begin(),
			     bez_coefs.begin(),
			     dim));

#if 0
      refinedBezierCoefs(spline_sf,
			 ind_u_min, ind_v_min,
			 bez_coefs2);
      SplineSurface bez_sf2(num_bez_coefs_u, num_bez_coefs_v,
			    order_u, order_v,
			    knots_u.begin(), knots_v.begin(),
			    bez_coefs2.begin(),
			    dim);
#endif
  }

  // And finally we compare the distance in a number of sample params.
  const int num_samples_u = 137;
  const int num_samples_v = 143;
  double ustep = (umax - umin)/(num_samples_u -1);
  double vstep = (vmax - vmin)/(num_samples_v -1);
  Point spline_pt(dim), bez_pt(dim), bez_pt2(dim);
  double max_dist = -1.0;
  double max_dist2 = -1.0;
  for (size_t kj = 0; kj < num_samples_v; ++kj)
  {
      double vpar = vmin + kj*vstep;
      for (size_t ki = 0; ki < num_samples_u; ++ki)
      {
	  double upar = umin + ki*ustep;
	  spline_sf.point(spline_pt, upar, vpar);
	  bez_sf->point(bez_pt, upar, vpar);
	  double dist = spline_pt.dist(bez_pt);
	  if (dist > max_dist)
	      max_dist = dist;
#if 0
	  bez_sf2.point(bez_pt2, upar, vpar);
	  double dist2 = spline_pt.dist(bez_pt2);
	  if (dist2 > max_dist2)
	      max_dist2 = dist2;
#endif

      }
  }

  std::cout << "max_dist: " << max_dist << std::endl;
#if 0
  std::cout << "max_dist2: " << max_dist2 << std::endl;
#endif

}
Exemplo n.º 21
0
int main(int argc, char** argv)
{
  bool surface_model = true;
  char* infile = 0;

  for (int i = 1; i < argc; i++)
    if (!infile)
      infile = argv[i];
    else
      std::cerr <<"  ** Unknown option ignored: "<< argv[i] << std::endl;
  
  size_t i = 0;
  while (i < strlen(infile) && isspace(infile[i])) i++;
  std::ifstream isp(infile+i);

  // For spline surface models
  std::vector<SplineSurface*> in_surf;

  // For spline volume models
  std::vector<SplineVolume*> in_vol;

  ObjectHeader head;
  int n = 0;
  while (!isp.eof()) {
    head.read(isp);
    if (head.classType() == Class_SplineVolume) {
      SplineVolume* v(new SplineVolume());
      v->read(isp);
      in_vol.push_back(v);
      surface_model = false;
    }
    else if (head.classType() == Class_SplineSurface) {
      SplineSurface* s(new SplineSurface());
      s->read(isp);
      in_surf.push_back(s);
      surface_model = true;
    }
    else
      std::cerr << "Unknown spline model" << std::endl;
    
    // Ignore blanks
    ws(isp); 
  }

  if (surface_model) {
    std::vector<SplineSurface*> out_surf;

    for (i = 0;i < in_surf.size();i++) {
      SplineSurface* s_it = in_surf[i];

      // basis1 should be one degree higher than basis2 and C^p-1 continuous
      int ndim = s_it->dimension();
      Go::BsplineBasis b1 = s_it->basis(0).extendedBasis(s_it->order_u()+1);
      Go::BsplineBasis b2 = s_it->basis(1).extendedBasis(s_it->order_v()+1);

      // Note: Currently this is implemented for non-rational splines only.
      // TODO: Ask the splines people how to fix this properly, that is, how
      // may be obtain the correct weights for basis1 when *surf is a NURBS?
      if (s_it->rational())
        std::cerr <<"WARNING: The geometry basis is rational (using NURBS)\n."
                  <<"         The basis for the unknown fields of one degree"
                  <<" higher will however be non-rational.\n"
                  <<"         This may affect accuracy.\n"<< std::endl;

      // Compute parameter values of the Greville points
      size_t k;
      std::vector<double> ug(b1.numCoefs()), vg(b2.numCoefs());
      for (k = 0; k < ug.size(); k++)
        ug[k] = b1.grevilleParameter(k);
      for (k = 0; k < vg.size(); k++)
        vg[k] = b2.grevilleParameter(k);

      // Evaluate the spline surface at all points
      std::vector<double> XYZ(ndim*ug.size()*vg.size());
      s_it->gridEvaluator(XYZ,ug,vg);

      // Project the coordinates onto the new basis (the 2nd XYZ is dummy here)
      SplineSurface* s;
      s = Go::SurfaceInterpolator::regularInterpolation(b1,b2,
							ug,vg,XYZ,
							ndim,false,XYZ);
      
      out_surf.push_back(s);
      s->writeStandardHeader(std::cout);
      s->write(std::cout);
    }

    for (i = 0;i < out_surf.size();i++) {
      delete in_surf[i];
      delete out_surf[i];
    }
  }
  else {
    std::vector<SplineVolume*> out_vol; 

    for (i = 0;i < in_vol.size();i++) {
      SplineVolume* v_it = in_vol[i];

      // basis1 should be one degree higher than basis2 and C^p-1 continuous
      int ndim = v_it->dimension();
      Go::BsplineBasis b1 = v_it->basis(0).extendedBasis(v_it->order(0)+1);
      Go::BsplineBasis b2 = v_it->basis(1).extendedBasis(v_it->order(1)+1);
      Go::BsplineBasis b3 = v_it->basis(2).extendedBasis(v_it->order(2)+1);

      // Note: Currently this is implemented for non-rational splines only.
      // TODO: Ask the splines people how to fix this properly, that is, how
      // may be obtain the correct weights for basis1 when *v_it is a NURBS?
      if (v_it->rational())
        std::cerr <<"WARNING: The geometry basis is rational (using NURBS)\n."
                  <<"         The basis for the unknown fields of one degree"
                  <<" higher will however be non-rational.\n"
                  <<"         This may affect accuracy.\n"<< std::endl;

      // Compute parameter values of the Greville points
      size_t k;
      std::vector<double> ug(b1.numCoefs()), vg(b2.numCoefs()), wg(b3.numCoefs());
      for (k = 0; i < ug.size(); k++)
        ug[k] = b1.grevilleParameter(k);
      for (k = 0; i < vg.size(); k++)
        vg[k] = b2.grevilleParameter(k);
      for (k = 0; i < wg.size(); k++)
        wg[k] = b3.grevilleParameter(k);

      // Evaluate the spline surface at all points
      std::vector<double> XYZ(ndim*ug.size()*vg.size()*wg.size());
      v_it->gridEvaluator(ug,vg,wg,XYZ);

      // Project the coordinates onto the new basis (the 2nd XYZ is dummy here)
      SplineVolume* v;
      v = Go::VolumeInterpolator::regularInterpolation(b1,b2,b3,
						       ug,vg,wg,XYZ,
						       ndim,false,XYZ);
      
      out_vol.push_back(v);
      v->writeStandardHeader(std::cout);
      v->write(std::cout);
    }

    for (i = 0;i < out_vol.size();i++) {
      delete in_vol[i];
      delete out_vol[i];
    }
  }

  return 0;
}  
Exemplo n.º 22
0
int main(int argc, char *argv[])
{
  if (argc != 4) {
    std::cout << "Usage: lrspline_in (.g2) refinement_in lrspline_out.g2 " << std::endl;
    return -1;
  }

  std::ifstream filein(argv[1]);
  std::ifstream filein2(argv[2]);
  std::ofstream fileout(argv[3]);

  // Create the default factory
  GoTools::init();
  Registrator<LRSplineSurface> r293;

  // Read input surface
  ObjectHeader header;
  try {
    header.read(filein);
  }
  catch (...)
    {
      std::cerr << "Exiting" << std::endl;
      exit(-1);
    }
  shared_ptr<GeomObject> geom_obj(Factory::createObject(header.classType()));
  geom_obj->read(filein);
  
  shared_ptr<ParamSurface> sf = dynamic_pointer_cast<ParamSurface, GeomObject>(geom_obj);
  if (!sf.get())
    {
      std::cerr << "Input file contains no surface" << std::endl;
      exit(-1);
    }

  shared_ptr<LRSplineSurface> lrsf = 
    dynamic_pointer_cast<LRSplineSurface, ParamSurface>(sf);
  if (!lrsf.get())
    {
      shared_ptr<SplineSurface> splsf = 
	dynamic_pointer_cast<SplineSurface, ParamSurface>(sf);
      if (splsf.get())
	lrsf = shared_ptr<LRSplineSurface>(new LRSplineSurface(splsf.get(), 1.0e-6));
    }
  if (!lrsf.get())
    {
      std::cerr << "Input file contains no spline surface" << std::endl;
      exit(-1);
    }
    
  
  shared_ptr<LRSplineSurface> tmp2(lrsf->clone());
  if (tmp2->dimension() == 1)
    tmp2->to3D();

  // tmp2->writeStandardHeader(fileout);
  // tmp2->write(fileout);
  // fileout << std::endl;
  // LineCloud lines2 = tmp2->getElementBds();
  // lines2.writeStandardHeader(fileout);
  // lines2.write(fileout);
  
  int nmb_refs;
  filein2 >> nmb_refs;
  for (int ki=0; ki<nmb_refs; ++ki)
    {
      double parval, start, end;
      int dir;
      int mult;

      filein2 >> parval;
      filein2 >> start;
      filein2 >> end;
      filein2 >> dir;
      filein2 >> mult;
      //lrsf->refine((dir==0) ? XFIXED : YFIXED, parval, start, end, mult);
      std::cout << "Iteration no. " << ki << std::endl;
      lrsf->refine((dir==0) ? XFIXED : YFIXED, parval, start, end, mult, true);

      puts("Writing lr-spline to file.");
      if (lrsf->dimension() == 1)
	lrsf->to3D();
      lrsf->writeStandardHeader(fileout);
      lrsf->write(fileout);
      fileout << std::endl;
    }
  return 0;
}
Exemplo n.º 23
0
int main(int argc, char** argv)
{

  if (argc != 6)
    {
      cout << "Usage: " << argv[0] << " surfaceinfile surface3doutfile points3doutfile num_u num_v" << endl;
      exit(-1);
    }

  ifstream filein(argv[1]);
  ALWAYS_ERROR_IF(filein.bad(), "Bad or no curvee input filename");
  ObjectHeader head;
  filein >> head;
  if (head.classType() != SplineSurface::classType()) {
    THROW("Not a spline surface");
  }

  SplineSurface sf;
  filein >> sf;

  ofstream fileoutsurf(argv[2]);
  ALWAYS_ERROR_IF(fileoutsurf.bad(), "Bad surface output filename");

  ofstream fileoutpts(argv[3]);
  ALWAYS_ERROR_IF(fileoutpts.bad(), "Bad points output filename");

  int num_u = atoi(argv[4]);
  int num_v = atoi(argv[5]);

  vector<double> pts, param_u, param_v;

  sf.gridEvaluator(num_u, num_v, pts, param_u, param_v);

  vector<double> coefs3d;
  vector<Point> pts3d;
  int dim = sf.dimension();
  bool rational = sf.rational();

  int ctrl_pts = sf.numCoefs_u() * sf.numCoefs_v();
  vector<double>::const_iterator it = sf.ctrl_begin();

  for (int i = 0; i < ctrl_pts; ++i)
    {
      if (dim <= 3)
	for (int j = 0; j < 3; ++j)
	  {
	    if (j>=dim)
	      coefs3d.push_back(0.0);
	    else
	      {
		coefs3d.push_back(*it);
		++it;
	      }
	  }
      else
	{
	  for (int j = 0; j < 3; ++j, ++it)
	    coefs3d.push_back(*it);
	  it += (dim-3);
	}
      if (rational)
	{
	  coefs3d.push_back(*it);
	  ++it;
	}
    }

  int pts_pos = 0;
  for (int i = 0; i < num_u*num_v; ++i)
    {
      double x, y, z;
      if (dim == 0)
	x = 0.0;
      else
	x = pts[pts_pos];
      if (dim <= 1)
	y = 0.0;
      else
	y = pts[pts_pos+1];
      if (dim <= 2)
	z = 0.0;
      else
	z = pts[pts_pos+2];
      pts_pos += dim;
      pts3d.push_back(Point(x, y, z));
    }

  SplineSurface sf3d(sf.basis_u(), sf.basis_v(), coefs3d.begin(), 3, rational);

  sf3d.writeStandardHeader(fileoutsurf);
  sf3d.write(fileoutsurf);

  fileoutpts << "400 1 0 4 255 255 0 255" << endl;
  fileoutpts << pts3d.size() << endl;
  for (int i = 0; i < (int)pts3d.size(); ++i)
    fileoutpts << pts3d[i] << endl;
}
Exemplo n.º 24
0
int main(int argc, char** argv)
{
 
    if (argc != 3) {
	cout << "Usage: pickSingularRegion FileSf1 FileSf2"
	     << endl;
	return 0;
    }


    ObjectHeader header;

    // Read the first curve from file
    ifstream input1(argv[1]);
    if (input1.bad()) {
	cerr << "File #1 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    header.read(input1);
    shared_ptr<ParamSurface> surf1(new SplineSurface());
    surf1->read(input1);
    input1.close();
    
    // Read the second curve from file
    ifstream input2(argv[2]);
    if (input2.bad()) {
	cerr << "File #2 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    header.read(input2);
    shared_ptr<ParamSurface> surf2(new SplineSurface());
    surf2->read(input2);
    input2.close();

    cout << setprecision(15);

    // Make the first subsurface
    SplineSurface* sf1 = dynamic_cast<SplineSurface*>(surf1.get());
    double from_upar = 52.0248;
    double from_vpar = 0.968029;
    double to_upar = sf1->endparam_u();
    double to_vpar = 1.03197;
    SplineSurface* sub1
	= sf1->subSurface(from_upar, from_vpar, to_upar, to_vpar);
    // Make the second subsurface
    SplineSurface* sf2 = dynamic_cast<SplineSurface*>(surf2.get());
    from_upar = 52.03;
    from_vpar = 0.968027;
    to_upar = 52.0349;
    to_vpar = 1.03197;
    SplineSurface* sub2
	= sf2->subSurface(from_upar, from_vpar, to_upar, to_vpar);

    // Magnify in the direction normal to the surfaces
    typedef vector<double>::iterator iter;
    for (iter it = sub1->coefs_begin(); it != sub1->coefs_end(); it += 3) {
	it[0] -= 5.5;
	it[1] += 10.6;
	it[2] += 21.9;
	it[0] *= 100;
	it[1] *= 100;
	it[2] *= 100;
    }
    for (iter it = sub2->coefs_begin(); it != sub2->coefs_end(); it += 3) {
	it[0] -= 5.5;
	it[1] += 10.6;
	it[2] += 21.9;
	it[0] *= 100;
	it[1] *= 100;
	it[2] *= 100;
    }
    Point normal1 = sub1->normalCone().centre();
    Point normal2 = sub2->normalCone().centre();
    Point normal = normal1 + normal2;
    for (iter it = sub1->coefs_begin(); it != sub1->coefs_end(); it += 3) {
	Point coef(it[0], it[1], it[2]);
	double fac = normal * coef;
	fac *= 100.0;
	it[0] += fac * normal[0];
	it[1] += fac * normal[1];
	it[2] += fac * normal[2];
    }
    for (iter it = sub2->coefs_begin(); it != sub2->coefs_end(); it += 3) {
	Point coef(it[0], it[1], it[2]);
	double fac = normal * coef;
	fac *= 100.0;
	it[0] += fac * normal[0];
	it[1] += fac * normal[1];
	it[2] += fac * normal[2];
    }

    ofstream out1("subsurf1.g2");
    sub1->writeStandardHeader(out1);
    sub1->write(out1);
    ofstream out2("subsurf2.g2");
    sub2->writeStandardHeader(out2);
    sub2->write(out2);


    return 0;
}
Exemplo n.º 25
0
int main(int argc, char** argv)
{

#ifndef _MSC_VER
//     _putenv("DEBUG=1");
//     _putenv("DEBUG_PAR=1");
//     _putenv("DEBUG_FINISH=1");
//     _putenv("DEBUG_IMPL=1");
    setenv("DEBUG", "1", 1);
    setenv("DEBUG_PAR", "1", 1);
    setenv("DEBUG_FINISH", "1", 1);
    //setenv("DEBUG_IMPL", "1", 1);
    setenv("SUBDIV_SFSF", "1", 1);
    setenv("DEBUG_MOVE", "1", 1);
    //setenv("DO_REPAIR", "1", 1);

    if (getenv("DEBUG") && (*getenv("DEBUG"))=='1')
	cout << "DEBUG=1" << endl;
    if (getenv("DEBUG_PAR") && (*getenv("DEBUG_PAR"))=='1')
	cout << "DEBUG_PAR=1" << endl;
    if (getenv("DEBUG_FINISH") && (*getenv("DEBUG_FINISH"))=='1')
	cout << "DEBUG_FINISH=1" << endl;
    if (getenv("DEBUG_IMPL") && (*getenv("DEBUG_IMPL"))=='1')
	cout << "DEBUG_IMPL=1" << endl;
    if (getenv("SUBDIV_SFSF") && (*getenv("SUBDIV_SFSF"))=='1')
	cout << "SUBDIV_SFSF=1" << endl;
    if (getenv("DEBUG_MOVE") && (*getenv("DEBUG_MOVE"))=='1')
	cout << "DEBUG_MOVE=1" << endl;
    if (getenv("DO_REPAIR") && (*getenv("DO_REPAIR"))=='1')
	cout << "DO_REPAIR=1" << endl;
#endif // _MSC_VER


    if (argc != 4 && argc != 5 && argc != 6) {
	cout << "Usage: test_SfSfIntersector FileSf1 FileSf2 "
	     <<" aepsge (OutputFile)(selfintflag)"
	     << endl;
	return 0;
    }


    ObjectHeader header;

    // Read the first curve from file
    ifstream input1(argv[1]);
    if (input1.bad()) {
	cerr << "File #1 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    header.read(input1);
    shared_ptr<ParamSurface> surf1(new SplineSurface());
    surf1->read(input1);
    input1.close();
    
    // Read the second curve from file
    ifstream input2(argv[2]);
    if (input2.bad()) {
	cerr << "File #2 error (no file or corrupt file specified)."
	     << std::endl;
	return 1;
    }
    header.read(input2);
    shared_ptr<ParamSurface> surf2(new SplineSurface());
    surf2->read(input2);
    input2.close();

    double aepsge;
    aepsge = atof(argv[3]);

    ofstream tmpout;
    if (argc >= 5)
	tmpout.open(argv[4]);
    ostream& out = tmpout;//(argc == 6) ? tmpout : cout;

    int selfint_flag = 0;
    if (argc == 6)
      selfint_flag = atoi(argv[5]);

    int has_sing = false;
//     if (argc == 5)
// 	has_sing = atoi(argv[4]);
    double sing[4];
//     if (has_sing) {
// 	printf("Give singularity: ");
// 	scanf("%lf",sing);
// 	scanf("%lf",sing+1);
// 	sing[2] = sing[0];
// 	sing[3] = sing[1];
//     }

//     cout << setprecision(15);

    // Setup the SplineSurfaceInt objects
    shared_ptr<ParamGeomInt> ssurfint1 =
	shared_ptr<ParamGeomInt>(new SplineSurfaceInt (surf1));
    shared_ptr<ParamGeomInt> ssurfint2 =
	shared_ptr<ParamGeomInt>(new SplineSurfaceInt (surf2));

    // Set up and run the intersection algorithm
    SfSfIntersector sfsfintersect (ssurfint1, ssurfint2, aepsge);
    if (has_sing)
	sfsfintersect.setHighPriSing(sing);
    if (selfint_flag > 0)
	sfsfintersect.setSelfintCase(selfint_flag); 
    clock_t start_compute = clock();
    sfsfintersect.compute();
    clock_t end_compute = clock();

    // Get the results
    vector<shared_ptr<IntersectionPoint> > intpts;
    vector<shared_ptr<IntersectionCurve> > intcrv;
    sfsfintersect.getResult(intpts, intcrv);
    cout << "Number of points: " << intpts.size() << endl;
    cout << "Number of curves: " << intcrv.size() << endl;

    // Write regression test data
    out << setprecision(8);
    int npoints = (int)intpts.size();
    int ncurves = (int)intcrv.size();
    vector<double> par;
    out << "-1 ______________Case sf-sf intersector______________"
	   << endl;
    out << "0 Surf-Surf:    npoints = " << npoints
	   << "    ncurves = " << ncurves << endl;
    for (int i = 0; i < npoints; ++i) {
	out << "1 Point: ";
	par = intpts[i]->getPar();
	for (int j=0; j < int(par.size()); j++) {
	    out << par[j] << " ";
	}
	out << intpts[i]->getDist() << endl;
    }
    for (int i = 0; i < ncurves; ++i) {
	out << "2 Curve:    Start = ";
	int nguide = intcrv[i]->numGuidePoints(); 
	shared_ptr<IntersectionPoint> startpt
	    = intcrv[i]->getGuidePoint(0);
	par = startpt->getPar();
	for (int j=0; j < int(par.size()); j++) {
	    out << par[j] << " ";
	}
	out << startpt->getDist() << "   End = ";
	shared_ptr<IntersectionPoint> endpt
	    = intcrv[i]->getGuidePoint(nguide-1);
	par = endpt->getPar();
	for (int j=0; j < int(par.size()); j++) {
	    out << par[j] << " ";
	}
	out << endpt->getDist() << endl;
    }

    // Write out isolated intersection points
    string str = "tmp_pnt.g2";
    std::ofstream outf(str.c_str());
    for (int ki=0; ki<int(intpts.size()); ki++) {
	std::vector<IntersectionPoint*> neighbours;
	intpts[ki]->getNeighbours(neighbours);
	std::vector<double> par = intpts[ki]->getPar();
	for (int kj=0; kj<int(par.size()); kj++)
	    std::cout << par[kj] << " ";
	std::cout << neighbours.size() << std::endl;

	Point pt1 = surf1->point(par[0], par[1]);
	Point pt2 = surf2->point(par[2], par[3]);

	outf << "400 1 0 4 255 0 0 255" << std::endl;
	outf << "1" << std::endl;
	pt1.write(outf);
	outf << "\n";

	outf << "400 1 0 4  0 255 0 255" << std::endl;
	outf << "1" << std::endl;
	pt2.write(outf);
	outf << "\n";
      
    }
    cout << ">> Intersection points written to " << str << endl;

    // Write out intersection curves as line-trains
    str = "tmp_crv.g2";
    std::ofstream outg(str.c_str());
    for (int ki=0; ki<int(intcrv.size()); ki++) {
	std::vector<double> guide_pt;
	int nguide = intcrv[ki]->numGuidePoints(); 
	guide_pt.reserve(3*nguide);
	for (int kj=0; kj<nguide; kj++) {
	    shared_ptr<IntersectionPoint> currpt
		= intcrv[ki]->getGuidePoint(kj);
	    Point pt = currpt->getPoint();
	    guide_pt.insert(guide_pt.end(), pt.begin(), pt.end());
	    if (kj>0 && kj<nguide-1)
		guide_pt.insert(guide_pt.end(), pt.begin(), pt.end()); 
	}
	LineCloud line(&guide_pt[0], nguide-1);
	line.writeStandardHeader(outg);
	line.write(outg);
    }
    cout << ">> Intersection curves (line-trains) written to "
	 << str << endl;

    
    double march_tol = 100.0*aepsge;
    //double march_tol = aepsge;
    double ang_tol = 0.01;

    // clock_t start_refine = clock();
    for (int ki=0; ki<int(intcrv.size()); ki++) {
	//      if (ki ==2) 
	cout << "Entering refine..." << endl;
	intcrv[ki]->refine(march_tol, ang_tol);
// 	intcrv[ki]->refine(march_tol, ang_tol);
// 	intcrv[ki]->refine(march_tol, ang_tol);
// 	intcrv[ki]->refine(march_tol, ang_tol);
// 	intcrv[ki]->refine(march_tol, ang_tol);
    }
    // clock_t end_refine = clock();

    // Write out refined intersection curves as line-trains
    str = "tmp2_crv.g2";
    std::ofstream outg2(str.c_str());
    for (int ki=0; ki<int(intcrv.size()); ki++) {
	std::vector<double> guide_pt;
	int nguide = intcrv[ki]->numGuidePoints(); 
	guide_pt.reserve(3*nguide);
	for (int kj=0; kj<nguide; kj++) {
	    shared_ptr<IntersectionPoint> currpt
		= intcrv[ki]->getGuidePoint(kj);
	    Point pt = currpt->getPoint();
	    guide_pt.insert(guide_pt.end(), pt.begin(), pt.end());
	    if (kj>0 && kj<nguide-1)
		guide_pt.insert(guide_pt.end(), pt.begin(), pt.end()); 
	}
	LineCloud line(&guide_pt[0], nguide-1);
	line.writeStandardHeader(outg2);
	line.write(outg2);
    }
    cout << ">> Refined intersection curves (line-trains) written to "
	 << str << endl;

    // Write out intersection curves as spline curve
    str = "tmp3_crv.g2";
    std::ofstream outg3(str.c_str());
    for (int ki=0; ki<int(intcrv.size()); ki++) {
	shared_ptr<ParamCurve> splcrv = intcrv[ki]->getCurve();
	if (splcrv.get()) {
// 	    splcrv->writeStandardHeader(outg3);
	    outg3 << "100 1 0 4 50 205 50 255" << endl;
	    splcrv->write(outg3);
	}
    }
    cout << ">> Intersection curve (spline curve) written to "
	 << str << endl;

    // Write out intersection curves in the parameter plane of the
    // first surface
    str = "tmp4_crv.g2";
    std::ofstream outg4(str.c_str());
    for (int ki=0; ki<int(intcrv.size()); ki++) {
	shared_ptr<ParamCurve> splcrv = intcrv[ki]->getParamCurve(1);
	if (splcrv.get()) {
	    splcrv->writeStandardHeader(outg4);
	    splcrv->write(outg4);
	}
    }
    cout << ">> Intersection curves (in parameter plane of 1st surface) "
	 << "written to " << str << endl;

    // Write out intersection curves in the parameter plane of the
    // second surface
    str = "tmp5_crv.g2";
    std::ofstream outg5(str.c_str());
    for (int ki=0; ki<int(intcrv.size()); ki++) {
	shared_ptr<ParamCurve> splcrv = intcrv[ki]->getParamCurve(2);
	if (splcrv.get()) {
	    splcrv->writeStandardHeader(outg5);
	    splcrv->write(outg5);
	}
    }
    cout << ">> Intersection curves (in parameter plane of 2nd surface) "
	 << "written to " << str << endl;
    

    cout << "Time in intersector:\t" 
	 << (double)(end_compute - start_compute) / double(1000)
	 << " msec. " << endl;
//     cout << "Time spent for refining:\t"
// 	 << (end_refine - start_refine) / double(1000)
// 	 << " msec." << endl;

    return 0;
}