예제 #1
0
void IGES_GEOM_WALL::clear( void )
{
    if( plane )
    {
        freeSurf( plane );
        plane = NULL;
    }

    if( side[0] )
    {
        freeCurve( side[0] );
        side[0] = NULL;
    }

    if( side[1] )
    {
        freeCurve( side[1] );
        side[1] = NULL;
    }

    if( side[2] )
    {
        freeCurve( side[2] );
        side[2] = NULL;
    }

    if( side[3] )
    {
        freeCurve( side[3] );
        side[3] = NULL;
    }

    return;
}
예제 #2
0
void intersectcurves(SplineCurve* cv1, SplineCurve* cv2, double epsge,
		     vector<std::pair<double,double> >& intersections)
  //************************************************************************
  // 
  // Intersect two spline curves. Collect intersection parameters.
  //
  //***********************************************************************
{

  // Make sisl curves and call sisl.
  SISLCurve *pc1 = Curve2SISL(*cv1, false);
  SISLCurve *pc2 = Curve2SISL(*cv2, false);

  int kntrack = 0;
  int trackflag = 0;  // Do not make tracks.
  SISLTrack **track =0;
  int knpt=0, kncrv=0;
  double *par1=0, *par2=0;
  int *pretop = 0;
  SISLIntcurve **intcrvs = 0;
  int stat = 0;
  sh1857(pc1, pc2, 0.0, epsge, trackflag, &kntrack, &track,
	 &knpt, &par1, &par2, &pretop, &kncrv, &intcrvs, &stat);

  ALWAYS_ERROR_IF(stat<0,"Error in intersection, code: " << stat);


  // Remember intersections points. The intersection curves are
  // skipped.
  int ki;
  for (ki=0; ki<knpt; ki++)
    {
      intersections.push_back(std::make_pair(par1[ki],par2[ki]));
    }

  if (kncrv > 0)
    freeIntcrvlist(intcrvs, kncrv);

  if (par1 != 0) free(par1);
  if (par2 != 0) free(par2);
  if (pretop != 0) free(pretop);
  if (pc1 != 0) freeCurve(pc1);
  if (pc2 != 0) freeCurve(pc2);
}
예제 #3
0
 void intersectCurveSurf(SplineCurve *cv, SplineSurface *sf,
			 double epsge, 
			 vector<pair<double, Point> >& int_pts,
			 vector<int>& pretopology,
			 vector<pair<pair<double,Point>, 
			 pair<double,Point> > >& int_crvs)
 {
   SISLSurf* sislsf = GoSurf2SISL(*sf, false);
   SISLCurve* sislcv = Curve2SISL(*cv, false);
   int kntrack = 0;
   int trackflag = 0;  // Do not make tracks.
   SISLTrack **track =0;
   int knpt=0, kncrv=0;
   double *par1=0, *par2=0;
   int *pretop = 0;
   SISLIntcurve **vcrv = 0;
   int stat = 0;

   sh1858(sislsf, sislcv, 0.0, epsge, trackflag, &kntrack, &track,
	  &knpt, &par1, &par2, &pretop, &kncrv, &vcrv, &stat);
   ALWAYS_ERROR_IF(stat<0,"Error in intersection, code: " << stat);

   // Remember intersections points. 
   int ki;
   for (ki=0; ki<knpt; ki++)
     {
       int_pts.push_back(std::make_pair(par2[ki],
					Point(par1[2*ki],par1[2*ki+1])));
       pretopology.insert(pretopology.end(), pretop+4*ki+2, pretop+4*(ki+1));
       pretopology.insert(pretopology.end(), pretop+4*ki, pretop+4*ki+2);
     }

   // Remember intersection curves
   for (ki=0; ki<kncrv; ++ki)
     {
       int nmb_pt = vcrv[ki]->ipoint;
       Point par1 = Point(vcrv[ki]->epar1[0],vcrv[ki]->epar1[1]);
       Point par2 = Point(vcrv[ki]->epar1[2*(nmb_pt-1)],
			  vcrv[ki]->epar1[2*nmb_pt-1]);
       int_crvs.push_back(std::make_pair(std::make_pair(vcrv[ki]->epar2[0], 
							par1),
					 std::make_pair(vcrv[ki]->epar2[nmb_pt-1],
							par2)));
     }

   if (kncrv > 0)
     freeIntcrvlist(vcrv, kncrv);

   if (par1 != NULL) free(par1);
   if (par2 != NULL) free(par2);
   if (sislsf != NULL) freeSurf(sislsf);
   if (sislcv != NULL) freeCurve(sislcv);
   if (pretop != NULL) free(pretop);
 }
예제 #4
0
void intersectCurvePoint(const ParamCurve* crv, Point pnt, double epsge,
			 vector<double>& intersections, 
			 vector<pair<double, double> >& int_crvs)
  //************************************************************************
  // 
  // Intersect a curve with a point
  //
  //***********************************************************************
{
  // First make sure that the curve is a spline curve
    ParamCurve* tmpcrv = const_cast<ParamCurve*>(crv);
    SplineCurve* sc = tmpcrv->geometryCurve();
    if (sc == NULL)
        THROW("ParamCurve doesn't have a spline representation.");
    
  // Make sisl curve and call sisl.
  SISLCurve *pc = Curve2SISL(*sc, false);

  int knpt=0, kncrv=0;
  double *par=0;
  SISLIntcurve **vcrv = 0;
  int stat = 0;
  s1871(pc, pnt.begin(), pnt.size(), epsge, &knpt, &par, &kncrv, &vcrv, &stat);
  ALWAYS_ERROR_IF(stat<0,"Error in intersection, code: " << stat);


  // Remember intersections points. 
  if (knpt > 0)
    intersections.insert(intersections.end(), par, par+knpt);

  // Remember intersection curves
  for (int ki=0; ki<kncrv; ++ki)
    int_crvs.push_back(std::make_pair(vcrv[ki]->epar1[0], vcrv[ki]->epar1[vcrv[ki]->ipoint-1]));

  if (kncrv > 0)
    freeIntcrvlist(vcrv, kncrv);

  if (par != 0) free(par);
  if (pc) freeCurve(pc);

  delete sc;
}
예제 #5
0
static void read_curves_and_surfaces(int argc, char *argv[])
{
  xscale=yscale=zscale=1.0;
  int ref=DEFAULT_REF; // Number of new knots between old ones.
  int maxref=DEFAULT_MAX_REF; // Maximal number of coeffs in any given direction.
  // (n, n) makes sure new knots are inserted close to max limit = n...
  int i;

  //
  // This must be reset every time we change control vertices, since
  // the discretization is done in the drawing routine.
  //
  for (i=0; i<curves; i++) {
    if (discr_curve[i]!=NULL) {
      delete discr_curve[i];
      discr_curve[i]=NULL;
    }
  }

  // @HH@
  // @HH@ Use the following optional command line options:
  // @HH@
  
  surfaces=0;
  curves=0;



  for (i=1; i<argc; i++) {
    switch (argv[i][0]) {
    case 's': {
      // Next string is filename for surface. (One surface.)
	    
      puts("Reading surfaces");
      // surface[surfaces-1]=read_nurbs_sf(argv[i+1]); // old format    

      std::vector<SISLSurf*> tmp;
      std::ifstream is(argv[i+1]);
      if (!is) {
	CRIT_ERR(printf("Could not open file: '%s'.\n", argv[i+1]));
      }
      try {
	eatwhite(is);
	while (!is.eof()) {
	  //surface[surfaces-1] = readGoSurface(is);
	  tmp.push_back(readGoSurface(is));
	  eatwhite(is);
	}
      } catch (std::exception& e) {
	CRIT_ERR(printf("Error occured while reading surface: %s\n", e.what()));
      }
      is.close();
      int num_surfaces = tmp.size();
      if (surfaces + num_surfaces > MAX_SURFACES) {
	CRIT_ERR(puts("Increase MAX_SURFACES."));
      }
	    
      for (int k = 0; k < num_surfaces; ++k) {
	//
	// 010116: This should be a quick fix for periodic
	//         surfaces...
	//
	if (tmp[k] == NULL) {
	  CRIT_ERR(printf("Couldn't read SISLSurf '%s'.\n", argv[i+1]));	    
	}

	if ((tmp[k]->cuopen_1 == SISL_CRV_PERIODIC ||
	     tmp[k]->cuopen_2 == SISL_CRV_PERIODIC)) {
	  int kstat;
	  SISLSurf *tmp_surf;
	  make_sf_kreg(tmp[k], &tmp_surf, &kstat);
	  if (kstat < 0) {
	    CRIT_ERR(printf("make_sf_kreg failed!\n"));
	  }
	  freeSurf(tmp[k]);
	  tmp[k] = tmp_surf;
	}
	if (tmp[k]->idim != 3) {
	  CRIT_ERR(printf("Dimension of surface is %d and not 3!\n",
			  tmp[k]->idim));
	}
		
	if (surface[surfaces]) {
	  // deleting old surface
	  freeSurf(surface[surfaces]);
	}
	surface[surfaces] = tmp[k];
	surface_name[surfaces] = argv[i+1];
	surf_enabled[surfaces] = 1;

	// Generating an approximating polygon.
	lower_degree_and_subdivide(surface + surfaces, ref, maxref);

	// evaluating normals (normalized)
	delete normal[surfaces];
	compute_surface_normals(surface[surfaces], normal + surfaces);
		
	++surfaces;
      }
    }
      i++;
      break;
      
    case 'c': {
      // Next string is filename for file containing 1 curve.
	    
      printf("Reading a single curve into slot %d.\n", curves);

      std::vector<SISLCurve*> tmp;
	    
      //n=get_curve_set(argv[i+1], &tmp, &stat);
      //get_single_curve(argv[i+1], &tmp, &stat); // old format
      std::ifstream is(argv[i+1]);
      if (!is) {
	CRIT_ERR(printf("Could not open file: '%s'.\n", argv[i+1]));
      }
      try {
	eatwhite(is);
	while (!is.eof()) {
	  tmp.push_back(readGoCurve(is));
	  eatwhite(is);
	}
      } catch (std::exception& e) {
	CRIT_ERR(printf("Error occured while reading curve: %s\n", e.what()));
      }
      is.close();
      int num_curves = tmp.size();

      if (curves + num_curves > MAX_CURVES) {
	CRIT_ERR(puts("Increase MAX_CURVES."));
      }
	    
      for(int k = 0; k < num_curves; ++k) {
	if (curve[curves + k] != NULL) {
	  freeCurve(curve[curves + k]);
	}
	curve[curves + k] = tmp[k];
		
	//
	// 001206: If the dimension is 2, we set up a
	//         new curve, filling in zeros.
	//
	if (curve[curves + k]->idim==2) {
		    
	  double *new_coeffs=
	    new double[3*curve[curves + k]->in];
	  if (new_coeffs==NULL)
	    CRIT_ERR(puts("Couldn't allocate memory."));
	  int j;
		    
	  for (j=0; j<curve[curves + k]->in; j++) {
	    new_coeffs[3*j+0]= curve[curves + k]->ecoef[2*j+0];
	    new_coeffs[3*j+1]= curve[curves + k]->ecoef[2*j+1];
	    new_coeffs[3*j+2]=0.0;
	  }
	  SISLCurve *tmp2=curve[curves + k];
	  curve[curves + k]= newCurve(tmp2->in, tmp2->ik, tmp2->et,
				      new_coeffs, tmp2->ikind, 3, 1);
	  freeCurve(tmp2);
	}
		
	if (curve[curves + k]->idim!=3) {
	  CRIT_ERR(printf("Dimension of curve is %d and not 3?!\n",
			  curve[curves + k]->idim));
	}

	curve_name[curves + k]=argv[i+1];
	curve_enabled[curves + k]=1;
      }
      curves+=num_curves;
    }
      i++;
      break;
	    
    case 'p': {
      // Next string is filename for file containing a point cloud.
	    
      printf("Reading a point cloud.\n");

      std::ifstream is(argv[i+1]);
      if (!is) {
	CRIT_ERR(printf("Could not open file: '%s'.\n", argv[i+1]));
      }
      try {
	  vector<double> coords;
	  readGoPoints(coords, is);
	  int num_points = int(coords.size()) / 3;
	  printf("Number of vertices: %d\n", num_points);
	  for (int i = 0; i < num_points; ++i) {
	      pcloud.push_back(vector3t<float>(coords[3 * i], 
					       coords[3 * i + 1], 
					       coords[3 * i + 2]));
	  }
// 	eatwhite(is);
// 	int tmp;
// 	is >> tmp;
// 	is >> tmp;
// 	is >> tmp;
// 	is >> tmp;
// 	is >> tmp;
// 	is >> tmp;
// 	is >> tmp;
// 	is >> tmp;
// 	eatwhite(is);
// 	is >> tmp;
// 	printf("Number of vertices: %d\n", tmp);
// 	while (!is.eof()) {
// 	  double x, y, z;
// 	  is >> x;
// 	  is >> y;
// 	  is >> z;
// 	  //printf("point: %f %f %f\n", x, y, z);
// 	  pcloud.push_back(vector3t<float>(x, y, z));
// 	  eatwhite(is);
//      }
      } catch (std::exception& e) {
	  CRIT_ERR(printf("Error occured while reading curve: %s\n", e.what()));
      }
      is.close();
      printf("pcloud size is now %d\n", pcloud.size());
    }
	i++;
      break;
	    
// 	case 'r':
// 	    // Set refinement factor. Default value is ???.
	    
// 	    puts("Reading surface refinement factor");
// 	    ref=atoi(argv[i+1]);
// 	    i++;
// 	    break;
	    
//	case 'R': 
    case 'r':
      // Set max refinement factor. Default value is ???.
	    
      puts("Reading upper bound for surface refinement.");
      maxref=atoi(argv[i+1]);
      i++;
      break;
	    
    case 'e': 
      // String with keypresses to execute follows. Not
      // everything will work!
	    
      printf("Executing '%s'.\n", argv[i+1]);
      strncpy(init_key_string, argv[i+1], 1000);
      i++;
      break;
	    
    default:
      puts("Huh?! Unknown option.");
      exit(0);
	    
    }
  }
}
예제 #6
0
void intersect2Dcurves(const ParamCurve* cv1, const ParamCurve* cv2, double epsge,
		       vector<pair<double,double> >& intersections,
		       vector<int>& pretopology,
		       vector<pair<pair<double,double>, pair<double,double> > >& int_crvs)
  //************************************************************************
  // 
  // Intersect two 2D spline curves. Collect intersection parameters
  // and pretopology information.
  //
  //***********************************************************************
{

  // First make sure that the curves are spline curves.
    ParamCurve* tmpcv1 = const_cast<ParamCurve*>(cv1);
    ParamCurve* tmpcv2 = const_cast<ParamCurve*>(cv2);
    SplineCurve* sc1 = tmpcv1->geometryCurve();
    SplineCurve* sc2 = tmpcv2->geometryCurve();
    if (sc1 == NULL || sc2 == NULL)
        THROW("ParamCurves doesn't have a spline representation.");

    MESSAGE_IF(cv1->dimension() != 2,
		"Dimension different from 2, pretopology not reliable.");

  // Make sisl curves and call sisl.
  SISLCurve *pc1 = Curve2SISL(*sc1, false);
  SISLCurve *pc2 = Curve2SISL(*sc2, false);

  int kntrack = 0;
  int trackflag = 0;  // Do not make tracks.
  SISLTrack **track =0;
  int knpt=0, kncrv=0;
  double *par1=0, *par2=0;
  int *pretop = 0;
  SISLIntcurve **vcrv = 0;
  int stat = 0;
  sh1857(pc1, pc2, 0.0, epsge, trackflag, &kntrack, &track,
	 &knpt, &par1, &par2, &pretop, &kncrv, &vcrv, &stat);

  ALWAYS_ERROR_IF(stat<0,"Error in intersection, code: " << stat);


  // Remember intersections points. 
  int ki;
  for (ki=0; ki<knpt; ki++)
    {
      intersections.push_back(std::make_pair(par1[ki],par2[ki]));
      pretopology.insert(pretopology.end(), pretop+4*ki, pretop+4*(ki+1));
    }

  // Remember intersection curves
  for (ki=0; ki<kncrv; ++ki)
    int_crvs.push_back(std::make_pair(std::make_pair(vcrv[ki]->epar1[0], vcrv[ki]->epar2[0]), 
				      std::make_pair(vcrv[ki]->epar1[vcrv[ki]->ipoint-1],
						     vcrv[ki]->epar2[vcrv[ki]->ipoint-1])));

  if (kncrv > 0)
    freeIntcrvlist(vcrv, kncrv);

  if (par1 != 0) free(par1);
  if (par2 != 0) free(par2);
  if (pc1 != 0) freeCurve(pc1);
  if (pc2 != 0) freeCurve(pc2);
  if (pretop != 0) free(pretop);

  delete sc1;
  delete sc2;
}