示例#1
0
文件: splines.cpp 项目: PMBio/peer
Spline<double, 2, Dynamic> closed_spline2d()
{
  RowVectorXd knots(12);
  knots << 0,
    0,
    0,
    0,
    0.867193179093898,
    1.660330955342408,
    2.605084834823134,
    3.484154586374428,
    4.252699478956276,
    4.252699478956276,
    4.252699478956276,
    4.252699478956276;

  MatrixXd ctrls(8,2);
  ctrls << -0.370967741935484,   0.236842105263158,
    -0.231401860693277,   0.442245185027632,
    0.344361228532831,   0.773369994120753,
    0.828990216203802,   0.106550882647595,
    0.407270163678382,  -1.043452922172848,
    -0.488467813584053,  -0.390098582530090,
    -0.494657189446427,   0.054804824897884,
    -0.370967741935484,   0.236842105263158;
  ctrls.transposeInPlace();

  return Spline<double, 2, Dynamic>(knots, ctrls);
}
示例#2
0
文件: splines.cpp 项目: PMBio/peer
/* create a reference spline */
Spline<double, 3, Dynamic> spline3d()
{
  RowVectorXd knots(11);
  knots << 0,
    0,
    0,
    0.118997681558377,
    0.162611735194631,
    0.498364051982143,
    0.655098003973841,
    0.679702676853675,
    1.000000000000000,
    1.000000000000000,
    1.000000000000000;

  MatrixXd ctrls(8,3);
  ctrls <<    0.959743958516081,   0.340385726666133,   0.585267750979777,
    0.223811939491137,   0.751267059305653,   0.255095115459269,
    0.505957051665142,   0.699076722656686,   0.890903252535799,
    0.959291425205444,   0.547215529963803,   0.138624442828679,
    0.149294005559057,   0.257508254123736,   0.840717255983663,
    0.254282178971531,   0.814284826068816,   0.243524968724989,
    0.929263623187228,   0.349983765984809,   0.196595250431208,
    0.251083857976031,   0.616044676146639,   0.473288848902729;
  ctrls.transposeInPlace();

  return Spline<double, 3, Dynamic>(knots, ctrls);
}
示例#3
0
static float get_adi_slip_indicator_needle_value (void)
{
	float
		slip_needle_value;

	if (test_cockpit_instruments)
	{
		static float
			value = -40.0;

		value += 1.0;

		if (value > 40.0)
		{
			value = -40.0;
		}

		slip_needle_value = value;
	}
	else
	{
		slip_needle_value = knots (current_flight_dynamics->indicated_slip.value);
	}

	slip_needle_value = bound (slip_needle_value, -30.0, 30.0);

	return (slip_needle_value);
}
示例#4
0
static float get_airspeed_indicator_needle_value (void)
{
	float
		airspeed_needle_value;

	if (test_cockpit_instruments)
	{
		static float
			value = -50.0;

		value += 2.0;

		if (value > 300.0)
		{
			value = -50.0;
		}

		airspeed_needle_value = value;
	}
	else
	{
		airspeed_needle_value = knots (current_flight_dynamics->indicated_airspeed.value);
	}

	airspeed_needle_value = bound (airspeed_needle_value, 0.0, 250.0);

	return (airspeed_needle_value);
}
KnotVector splineknots::CurveDeboorKnotsGenerator::
GenerateKnots(const SurfaceDimension& dimension, double* calculation_time)
{
	StopWatch sw;
	
	KnotVector knots(dimension.knot_count);
	InitializeKnots(dimension, knots);
	auto dfirst = function_.Dx()(dimension.min, 0);
	auto dlast = function_.Dx()(dimension.max, 0);
	KnotVector result(knots.size());

	sw.Start();
	RightSide(knots, abs(dimension.max - dimension.min)
		/ (dimension.knot_count - 1), dfirst, dlast);
	
	auto& rhs = tridiagonal_.Solve(dimension.knot_count-2);
	result[0] = dfirst;
	result[result.size() - 1] = dlast;
	memcpy(&result.front() + 1, &rhs.front(), rhs.size());
	sw.Stop();
	
	if (calculation_time != nullptr)
	{
		*calculation_time = sw.EllapsedTime();
	}
	return result;
}
void createGroundShape(TopoDS_Shape& shape) {
	TColgp_Array2OfPnt cv (0, 4, 0, 4);
	cv.SetValue(0, 0, gp_Pnt(-10000, -10000, -4130));
	cv.SetValue(0, 1, gp_Pnt(-10000,  -4330, -4130));
	cv.SetValue(0, 2, gp_Pnt(-10000,      0, -5130));
	cv.SetValue(0, 3, gp_Pnt(-10000,   4330, -7130));
	cv.SetValue(0, 4, gp_Pnt(-10000,  10000, -7130));
	cv.SetValue(1, 0, gp_Pnt( -3330, -10000, -5130));
	cv.SetValue(1, 1, gp_Pnt( -7670,  -3670,  5000));
	cv.SetValue(1, 2, gp_Pnt( -9000,      0,  1000));
	cv.SetValue(1, 3, gp_Pnt( -7670,   7670,  6000));
	cv.SetValue(1, 4, gp_Pnt( -3330,  10000, -4130));
	cv.SetValue(2, 0, gp_Pnt(     0, -10000, -5530));
	cv.SetValue(2, 1, gp_Pnt(     0,  -3670,  3000));
	cv.SetValue(2, 2, gp_Pnt(     0,      0, -12000));
	cv.SetValue(2, 3, gp_Pnt(     0,   7670,  1500));
	cv.SetValue(2, 4, gp_Pnt(     0,  10000, -4130));
	cv.SetValue(3, 0, gp_Pnt(  3330, -10000, -6130));
	cv.SetValue(3, 1, gp_Pnt(  7670,  -3670,  6000));
	cv.SetValue(3, 2, gp_Pnt(  9000,      0,  5000));
	cv.SetValue(3, 3, gp_Pnt(  7670,   9000,  7000));
	cv.SetValue(3, 4, gp_Pnt(  3330,  10000, -4130));
	cv.SetValue(4, 0, gp_Pnt( 10000, -10000, -6130));
	cv.SetValue(4, 1, gp_Pnt( 10000,  -4330, -5130));
	cv.SetValue(4, 2, gp_Pnt( 10000,      0, -4130));
	cv.SetValue(4, 3, gp_Pnt( 10000,   4330, -4130));
	cv.SetValue(4, 4, gp_Pnt( 10000,  10000, -8130));
	TColStd_Array1OfReal knots(0, 1);
	knots(0) = 0;
	knots(1) = 1;		
	TColStd_Array1OfInteger mult(0, 1);
	mult(0) = 5;
	mult(1) = 5;	
	Handle(Geom_BSplineSurface) surf = new Geom_BSplineSurface(cv, knots, knots, mult, mult, 4, 4);
#if OCC_VERSION_HEX < 0x60502
	shape = BRepBuilderAPI_MakeFace(surf);
#else
	shape = BRepBuilderAPI_MakeFace(surf, Precision::Confusion());
#endif
}
示例#7
0
  SplineCurve* Element2D::curveOnElement(double start_u, double start_v, double end_u, double end_v) const
  {
    if (support_.size() == 0)
      return NULL;   // This should not happen, some B-splines must have support in this element

    int dim = support_[0]->dimension();
    int deg_u = support_[0]->degree(XFIXED);
    int deg_v = support_[0]->degree(YFIXED);

    vector<vector<double> > bernstein_u;
    vector<vector<double> > bernstein_v;
    univariateBernsteinEvaluationInLine(deg_u, start_u, end_u, bernstein_u);
    univariateBernsteinEvaluationInLine(deg_v, start_v, end_v, bernstein_v);

    int degree = deg_u + deg_v;
    vector<int> binomial(degree + 1);   // binomial[i] shall be the binomial (degree Choose i)
    binomial[0] = binomial[degree] = 1;
    for (int i = 0; i + i <= degree; ++i)
      binomial[degree - i] = binomial[i] = (binomial[i - 1] * (degree - i + 1)) / i;

    vector<double> curve_coefs(dim * (degree + 1));
    vector<double> surface_coefs = unitSquareBernsteinBasis();
    vector<double>::const_iterator surf_it;

    for (int i2 = 0; i2 <= deg_v; ++i2)
      for (int i1 = 0; i1 <= deg_u; ++i1)
	for (int k = 0; k <= dim; ++k, ++surf_it)
	  for (int j2 = 0; j2 <= deg_v; ++j2)
	    for (int j1 = 0; j1 <= deg_u; ++j1)
	      curve_coefs[dim*(j1 + j2) + k] += bernstein_v[i2][j2] * bernstein_u[i1][j1] * (*surf_it);

    for (int i = 0; i <= degree; ++i)
      for (int k = 0; k <= dim; ++k)
	curve_coefs[i * dim + k] /= (double)binomial[i];

    vector<double> knots(2 * (degree + 1));
    for (int i = 0; i <= degree; ++i)
      {
	knots[i] = 0.0;
	knots[i + degree + 1] = 1.0;
      }

    return new SplineCurve(degree + 1, degree + 1, knots.begin(), curve_coefs.begin(), dim);
  }
示例#8
0
inline void converter<point_t>::convert(tml::nurbscurve<point_t> const& nc,
                                        insert_iterator_t target) const {
  // copy control points into helper array
  std::vector<point_t> points(nc.begin(), nc.end());
  std::multiset<value_type> knots(nc.knots().begin(), nc.knots().end());

  std::size_t order = nc.order();
  std::size_t deg = nc.degree();

  if (order <= 1) {
    std::cerr << "converter::convert() : irregular order " << std::endl;
  }

  if (points.size() + order == knots.size()) {
    knot_insertion(points, knots, order);
  } else {
    std::cerr << "converter(): irregular knotvector" << std::endl;
  }

  if (points.size() + order != knots.size()) {
    std::cerr << "converter::convert() : knot insertion failed " << std::endl;
  }

  // compute how many parts result
  std::size_t parts = (knots.size() - 2 * order) / (order - 1) + 1;

  // copy bezier curves
  typename std::vector<point_t>::iterator start(points.begin());
  typename std::vector<point_t>::iterator end(points.begin());
  std::advance(end, order);

  // create bezier parts and store them
  for (std::size_t i = 0; i < parts; ++i) {
    beziercurve<point_t> bc(start, end);

    if (i < (parts - 1)) {
      std::advance(start, deg);
      std::advance(end, deg);
    }

    target = bc;
  }
}
示例#9
0
    stretchy_buffer<double> generate_knots(unsigned int control_point_count,
                                           unsigned int degree) const
    {
        unsigned int order = degree + 1;
        stretchy_buffer<double> knots(control_point_count + order);
        unsigned int i = 0, foobar = 0;

        switch (type_)
        {
        default:
        case bspline::bstOpen:
        case bspline::bstClose:
            for ( ; i < knots.size();         ++i) knots[i] = foobar++;
            break;
        case bspline::bstClamp:
            for ( ; i < degree;               ++i) knots[i] = foobar;
            for ( ; i < knots.size() - order; ++i) knots[i] = foobar++;
            for ( ; i < knots.size();         ++i) knots[i] = foobar;
            break;
        }

        return knots;
    }
示例#10
0
Handle(Geom_BSplineCurve) CFunctionToBspline::CFunctionToBsplineImpl::concatC1(const std::vector<Handle(Geom_BSplineCurve)>& curves)
{
    if (curves.size() == 0) {
        return NULL;
    }
    else if (curves.size() == 1) {
        return curves[0];
    }

#ifdef DEBUG
    // check range connectivities
    for (size_t i = 1; i < curves.size(); ++i) {
        Handle(Geom_BSplineCurve) lastCurve = curves[i-1];
        Handle(Geom_BSplineCurve) thisCurve = curves[i];
        assert(lastCurve->LastParameter() == thisCurve->FirstParameter());
    }
#endif

    // count control points
    int ncp = 2;
    int nkn = 1;
    std::vector<Handle(Geom_BSplineCurve)>::const_iterator curveIt;
    for (curveIt = curves.begin(); curveIt != curves.end(); ++curveIt) {
        Handle(Geom_BSplineCurve) curve = *curveIt;
        ncp += curve->NbPoles() - 2;
        nkn += curve->NbKnots() - 1;
    }

    // allocate arrays
    TColgp_Array1OfPnt      cpoints(1, ncp);
    TColStd_Array1OfReal    knots(1, nkn);
    TColStd_Array1OfInteger mults(1, nkn);

    int iknotT = 1, imultT = 1, icpT = 1;
    int icurve = 0;
    for (curveIt = curves.begin(); curveIt != curves.end(); ++curveIt, ++icurve) {
        Handle(Geom_BSplineCurve) curve = *curveIt;

        // special handling of the first knot, control point
        knots.SetValue(iknotT++, curve->Knot(1));
        if (icurve == 0) {
            // we just copy the data of the very first point/knot
            mults.SetValue(imultT++, curve->Multiplicity(1));
            cpoints.SetValue(icpT++, curve->Pole(1));
        }
        else {
            // set multiplicity to maxDegree to allow c0 concatenation
            mults.SetValue(imultT++, _degree-1);
            // omit the first control points of the current curve
        }

        // just copy control points, weights, knots and multiplicites
        for (int iknot = 2; iknot < curve->NbKnots(); ++iknot) {
            knots.SetValue(iknotT++, curve->Knot(iknot));
            mults.SetValue(imultT++, curve->Multiplicity(iknot));
        }
        for (int icp = 2; icp < curve->NbPoles(); ++icp) {
            cpoints.SetValue(icpT++, curve->Pole(icp));
        }
    }

    // special handling of the last point and knot
    Handle(Geom_BSplineCurve) lastCurve = curves[curves.size()-1];
    knots.SetValue(iknotT, lastCurve->Knot(lastCurve->NbKnots()));
    mults.SetValue(imultT,  lastCurve->Multiplicity(lastCurve->NbKnots()));
    cpoints.SetValue(icpT, lastCurve->Pole(lastCurve->NbPoles()));

    Handle(Geom_BSplineCurve) result = new Geom_BSplineCurve(cpoints, knots, mults, _degree);
    return result;
}
示例#11
0
Handle(Geom_BSplineCurve) CFunctionToBspline::CFunctionToBsplineImpl::Curve()
{
    bool interpolate = true;
    
    std::vector<ChebSegment> segments = approxSegment(_umin, _umax, 1);
    
    int N = _degree + 1;
    math_Matrix Mt = monimial_to_bezier(N)*cheb_to_monomial(N);
    
    // get estimated error and create bspline segments
    std::vector<Handle(Geom_BSplineCurve)> curves;
    double errTotal = 0.;
    std::vector<ChebSegment>::iterator it = segments.begin();
    for (; it != segments.end(); ++it) {
        // get control points
        ChebSegment& seg = *it;
        
        math_Vector cpx = Mt*seg.cx;
        math_Vector cpy = Mt*seg.cy;
        math_Vector cpz = Mt*seg.cz;
        
        TColgp_Array1OfPnt cp(1,cpx.Length());
        for (int i = 1; i <= cpx.Length(); ++i) {
            gp_Pnt p(cpx(i-1), cpy(i-1), cpz(i-1));
            cp.SetValue(i, p);
        }
        
        if (interpolate) {
            gp_Pnt pstart(_xfunc.value(seg.umin), _yfunc.value(seg.umin), _zfunc.value(seg.umin));
            gp_Pnt pstop (_xfunc.value(seg.umax), _yfunc.value(seg.umax), _zfunc.value(seg.umax));
            cp.SetValue(1, pstart);
            cp.SetValue(cpx.Length(), pstop);
        }
        
        // create knots and multiplicity vector
        TColStd_Array1OfReal knots(1,2);
        knots.SetValue(1, seg.umin);
        knots.SetValue(2, seg.umax);
        TColStd_Array1OfInteger mults(1,2);
        mults.SetValue(1, _degree+1);
        mults.SetValue(2, _degree+1);
        
        Handle(Geom_BSplineCurve) curve = new Geom_BSplineCurve(cp, knots, mults, _degree);
        curves.push_back(curve);
        
        if (seg.error > errTotal) {
            errTotal = seg.error;
        }
    }
    _err = errTotal;
     
    // concatenate c1 the bspline curves
    Handle(Geom_BSplineCurve) result = concatC1(curves);

#ifdef DEBUG
    LOG(INFO) << "Result of BSpline approximation of function:";
    LOG(INFO) << "    approximation error = " << errTotal;
    LOG(INFO) << "    number of control points = " << result->NbPoles();
    LOG(INFO) << "    number of segments = " << curves.size();
#endif
    return result;
}
示例#12
0
//===========================================================================
void SplineInterpolator::makeBasis(const std::vector<double>& params,
				   const std::vector<int>& tangent_index,
				   int order)
//===========================================================================
{
    int tsize = (int)tangent_index.size();
    int nmb_points = (int)params.size();
    DEBUG_ERROR_IF(nmb_points + tsize < order,
	     "Mismatch between interpolation conditions and order.");

    int i;
    int ti = 0; // Variable used to iterate through the tangent_index.
    int di;
    int k2 = order / 2; // Half the order.
    int kstop; // Control variable of the loop.
    int kpar;

    // Values in params are not repeated; derivatives are given by tangent_index.
    int nmb_int_cond = nmb_points + tsize;
    double startparam = params[0];
    double endparam = params[nmb_points - 1];
    // We remember start and end multiplicities.
    int start_mult = (tsize != 0 && tangent_index[0] == 0) ? 2 : 1;
    int end_mult = (tsize != 0 &&
		    tangent_index[tsize - 1] == nmb_points - 1) ?
	2 : 1;

    std::vector<double> knots(order + nmb_int_cond);
    int ki = 0; // Variabel used when setting values in the knot vector;
    // We make the knot vector k-regular in the startparam.
    for (ki = 0; ki < order; ++ki)
	knots[ki] = startparam;

    double dummy1, dummy2;
    if (order % 2 == 0) {
	// Even order: place the internal knots at the parameter values.
	dummy1 = 0.5 * (params[1] + startparam);
	dummy2 = 0.5 * (params[nmb_points - 2] + endparam);
	if (dummy1 == dummy2)
	    {
		dummy1 = (params[1] + startparam + startparam)/3.0;
		dummy2 = (params[nmb_points - 2] + endparam + endparam)/3.0;
	    }
	if (start_mult > 1)
	    ++ti;
	for (i = 0; i < start_mult - k2; ++i, ++ki)
	    knots[ki] = dummy1;

// #ifdef _MSC_VER
// 	int kss = (k2-start_mult > 0) ? k2-start_mult : 0;
// 	int kse = (k2-end_mult > 0) ? k2-end_mult : 0;
// #else
	int kss = std::max(0, k2 - start_mult);
	int kse = std::max(0, k2 - end_mult);
// #endif
	for (kpar = 1 + kss,
	       kstop = nmb_points - 1 - kse;
	     kpar < kstop; kpar++, ++ki) {
	  knots[ki] = params[kpar];
	  di = ki;
	    if (tsize != 0)
		while (tangent_index[ti] == kpar) {
		    knots[++ki] = knots[di];
		    ++ti;
		}
	}

	for (i = 0; i < end_mult - k2; ++i, ++ki)
	    knots[ki] = dummy2;
    } else {
	double delta;
	// The order is odd: place internal knots between parameter values.
	if (start_mult > 1)
	    ++ti;
	if (start_mult - k2 > 0)
	    {
		delta = (params[1] - startparam) / (start_mult - k2 + 1);
		dummy1 = startparam + delta;
		for (i = 0; i < start_mult - k2;
		     ++i, dummy1 += delta, ++ki)
		    knots[ki] = dummy1;
	    }

// #ifdef _MSC_VER
// 	int kss = (k2-start_mult > 0) ? k2-start_mult : 0;
// 	int kse = (k2-end_mult > 0) ? k2-end_mult : 0;
// #else
	int kss = std::max(0, k2 - start_mult);
	int kse = std::max(0, k2 - end_mult);
// #endif
	for (kpar = start_mult + kss,
		 kstop = nmb_points - end_mult - kse;
	     kpar < kstop; kpar++, ++ki) {
	    knots[ki] = 0.5 *(params[kpar] + params[kpar + 1]);
	    di = ki;
	    if (tsize != 0)
		while (tangent_index[ti] == kpar) {
		    knots[++ki] = knots[di];
		    ++ti;
		}
	}

	if (end_mult - k2 > 0)
	    {
// 		delta = (endparam - params[nmb_points -end_mult - 1]) /
		delta = (endparam - params[nmb_points - 2]) /
		    (end_mult - k2 + 1);
// 		dummy2 = params[nmb_points -end_mult - 1] +delta;
		dummy2 = params[nmb_points - 2] +delta;
		for (i = 0; i < end_mult - k2; ++i, dummy2 += delta, ++ki)
		    knots[ki] = dummy2;
	    }
    }

    for (ki = 0; ki < order; ki++)
	knots[nmb_int_cond+ki] = endparam;

    basis_ = BsplineBasis(order, knots.begin(), knots.end());
    basis_set_ = true;

}
示例#13
0
inline void converter<point_t>::convert(
    nurbsvolume_type const& volume,
    insert_iterator_t ins_iter,
    std::list<beziervolumeindex>& indices) const {
  typedef typename std::set<value_type>::const_iterator set_const_iterator;

  std::set<value_type> unique_knots_u(volume.knotvector_u().begin(),
                                      volume.knotvector_u().end());
  std::set<value_type> unique_knots_v(volume.knotvector_v().begin(),
                                      volume.knotvector_v().end());
  std::set<value_type> unique_knots_w(volume.knotvector_w().begin(),
                                      volume.knotvector_w().end());

  std::vector<value_type> unique_knots_u_as_vector(unique_knots_u.begin(),
                                                   unique_knots_u.end());
  std::vector<value_type> unique_knots_v_as_vector(unique_knots_v.begin(),
                                                   unique_knots_v.end());
  std::vector<value_type> unique_knots_w_as_vector(unique_knots_w.begin(),
                                                   unique_knots_w.end());

  // compute target size of mesh after knot insertion
  std::size_t knotspans_u = unique_knots_u.size() - 1;
  std::size_t knotspans_v = unique_knots_v.size() - 1;
  std::size_t knotspans_w = unique_knots_w.size() - 1;

  std::size_t targetsize_u = (knotspans_u) * (volume.order_u() - 1) + 1;
  std::size_t targetsize_v = (knotspans_v) * (volume.order_v() - 1) + 1;
  std::size_t targetsize_w = (knotspans_w) * (volume.order_w() - 1) + 1;

  pointmesh3d<point_t> mesh(volume.points().begin(),
                            volume.points().end(),
                            volume.knotvector_u().size() - volume.order_u(),
                            volume.knotvector_v().size() - volume.order_v(),
                            volume.knotvector_w().size() - volume.order_w());

  // knot insertion in u direction
  pointmesh3d<point_t> mesh_u(
      targetsize_u, volume.numberofpoints_v(), volume.numberofpoints_w());
  for (unsigned int v = 0; v != volume.numberofpoints_v(); ++v) {
    for (unsigned int w = 0; w != volume.numberofpoints_w(); ++w) {
      std::vector<point_t> curve = mesh.submesh(0, v, w);
      std::multiset<value_type> knots(volume.knotvector_u().begin(),
                                      volume.knotvector_u().end());
      knot_insertion(curve, knots, volume.order_u());
      mesh_u.submesh(curve.begin(), 0, v, w);
    }
  }

  // knot insertion in v direction
  pointmesh3d<point_t> mesh_uv(
      targetsize_u, targetsize_v, volume.numberofpoints_w());
  for (unsigned int u = 0; u != targetsize_u; ++u) {
    for (unsigned int w = 0; w != volume.numberofpoints_w(); ++w) {
      std::vector<point_t> curve = mesh_u.submesh(1, u, w);
      std::multiset<value_type> knots(volume.knotvector_v().begin(),
                                      volume.knotvector_v().end());
      knot_insertion(curve, knots, volume.order_v());
      mesh_uv.submesh(curve.begin(), 1, u, w);
    }
  }

  // knot insertion in w direction
  pointmesh3d<point_t> mesh_uvw(targetsize_u, targetsize_v, targetsize_w);
  for (unsigned int u = 0; u != targetsize_u; ++u) {
    for (unsigned int v = 0; v != targetsize_v; ++v) {
      std::vector<point_t> curve = mesh_uv.submesh(2, u, v);
      std::multiset<value_type> knots(volume.knotvector_w().begin(),
                                      volume.knotvector_w().end());
      knot_insertion(curve, knots, volume.order_w());
      mesh_uvw.submesh(curve.begin(), 2, u, v);
    }
  }

  typename beziervolume_type::parameter_type uvwglobalmin(
      unique_knots_u_as_vector[0],
      unique_knots_v_as_vector[0],
      unique_knots_w_as_vector[0]);
  typename beziervolume_type::parameter_type uvwglobalmax(
      unique_knots_u_as_vector[knotspans_u],
      unique_knots_v_as_vector[knotspans_v],
      unique_knots_w_as_vector[knotspans_w]);

  indices.clear();

  // read control points of submeshes
  for (int u = 0; u != int(knotspans_u); ++u) {
    for (int v = 0; v != int(knotspans_v); ++v) {
      for (int w = 0; w != int(knotspans_w); ++w) {
        typename beziervolume_type::parameter_type uvwmin(
            unique_knots_u_as_vector[u],
            unique_knots_v_as_vector[v],
            unique_knots_w_as_vector[w]);
        typename beziervolume_type::parameter_type uvwmax(
            unique_knots_u_as_vector[u + 1],
            unique_knots_v_as_vector[v + 1],
            unique_knots_w_as_vector[w + 1]);

        // create control point mesh of target size
        pointmesh3d<point_t> bmesh(
            volume.order_u(), volume.order_v(), volume.order_w());

        for (unsigned int du = 0; du != volume.order_u(); ++du) {
          for (unsigned int dv = 0; dv != volume.order_v(); ++dv) {
            for (unsigned int dw = 0; dw != volume.order_w(); ++dw) {
              bmesh(du, dv, dw) = mesh_uvw(u * (volume.order_u() - 1) + du,
                                           v * (volume.order_v() - 1) + dv,
                                           w * (volume.order_w() - 1) + dw);
            }
          }
        }

        // create and insert sub bezier volume
        beziervolume<point_t> subvolume(bmesh);

        subvolume.uvw_local(uvwmin, uvwmax);
        subvolume.uvw_global(uvwglobalmin, uvwglobalmax);

        *ins_iter = subvolume;
        beziervolumeindex idx = { u, v, w };
        indices.push_back(idx);
      }
    }
  }
}
示例#14
0
void export_igs(Patch face[], int patch_num)

{
    FILE* fp;
    Patch* p;

    int         bbctr,ffctr,
                k,k1,w,w1,rows,flen[4],
                i,j, col,cols, fc,dg;
    double      h;
    double*     hv;

    fp = fopen("output.igs", "w");
    if(fp==NULL) {
        printf("can't open output file output.igs\n");
        return ;  // can't write
    }

    printf("outputing the object into file output.igs..\n");

    flen[0] = 3;
    flen[1] = 8;

    fprintf(fp, "WRAP                                                                    S      1\n");
    fprintf(fp, "B-spline surfaces.                                                      S      2\n");
    fprintf(fp, "Number of Patches:  %4d                                                S      3\n", patch_num);

    for(i=1;i<=flen[1];i++)
       fprintf(fp, "                                                                        G      %d\n", i);

    bbctr=1; ffctr=1;
    for (fc=1; fc <= patch_num; fc++) {
        p = &(face[fc]);
        int patch_kind = p->type;
        if(patch_kind == TRIANG ) {
            Patch * tri = p;
            if(tri->degu == 1) {
                dg = 1;
                k = (dg+1)*2;
                k1 = (k%8 != 0) + k/8;  /* knots */
                w = (dg+1)*(dg+1);
                w1 = (w%8 != 0) + w/8;  /* weights */
                /* deg-line, knots, weights, xyz location, param */
                rows  = (1+ 2*k1 + w1 + w + 1);  /* size of one block */

                fprintf(fp,"     128%8d       0       1       0       0       0        00000000D%7d\n",
                    bbctr, ffctr);
                fprintf(fp,"     128%8d       8      %d       2                NurbSurf       0D%7d\n",
                    0, rows, ffctr+1);
                bbctr += rows;
                ffctr += 2;
            }
        }
        if(patch_kind == TP || patch_kind == TP_EQ ) {

            Patch * quad = p;

            dg = quad->degu;

            k = (dg+1)*2;
            k1 = (k%8 != 0) + k/8;  /* knots */
            w = (dg+1)*(dg+1);
            w1 = (w%8 != 0) + w/8;  /* weights */
            /* deg-line, knots, weights, xyz location, param */
            rows  = (1+ 2*k1 + w1 + w + 1);  /* size of one block */

            fprintf(fp,"     128%8d       0       1       0       0       0        00000000D%7d\n",
                bbctr, ffctr);
            fprintf(fp,"     128%8d       8      %d       2                NurbSurf       0D%7d\n",
                0, rows, ffctr+1);
            bbctr += rows;
            ffctr += 2;
        }
    }


    ffctr = 1; bbctr=1;
    for (fc=1; fc<=patch_num ; fc++)
    {
        p = &(face[fc]);
        int patch_kind = p->type;

        if(patch_kind == TRIANG ) {
            Patch * tri = p;

            if(tri->degu == 1) {
                printf("outputing triangles as degenrated quads\n");

                dg = 1;

                // HEADER
                fprintf(fp,"128,%7d,%7d,%7d,%7d,0,0,1,0,0,%26dP%7d\n",
                    dg,dg,dg,dg,ffctr,bbctr);
                bbctr++;

                // KNOTS
                w = (dg+1)*(dg+1);
                bbctr = knots(dg+1, bbctr, ffctr,fp,8);
                bbctr = knots(dg+1, bbctr, ffctr,fp,8);

                // the w==RATIONAL coordinate
                cols = 8;
                col = 0;
                for (i=0; i<= dg; i++) {
                    for (j=0; j<= dg; j++) {
                        if ((col % cols==0) && (col != 0)) {  /* typeset */
                            fprintf(fp,"%8dP%7d\n",ffctr,bbctr);
                            bbctr++;
                        }
                        h = 1.0; //(fp->bb[0][i][j])->w;
                        fprintf(fp,"%7.5f,", h);
                        col++;
                    }
                }
                // finish line
                col = col%cols;
                if (col != 0) {
                    col = cols-col;
                    for (i=0; i< col; i++)
                        fprintf(fp,"        ");
                }
                fprintf(fp,"%8dP%7d\n",ffctr,bbctr);

                bbctr++;

                // the XYZ coordinates
                for (i=0; i<= 1; i++) {
                    for (j=0; j<= 1; j++) {
                        if(i==1 && j==1)
                            hv=TriBezier_get_bb(tri,0,1);
                        else
                            hv=TriBezier_get_bb(tri,i,j);

                        fprintf(fp,"%20e,%20e,%20e,%9dP%7d\n",
                            hv[0],hv[1], hv[2], ffctr,bbctr);
                        //fprintf(fp,"%20e,%20e,%20e,%9dP%7d\n",
                            //0.0,0.0, 0.0, ffctr,bbctr);
                        bbctr++;
                    }
                }
                fprintf(fp,"0.00000,1.00000,0.00000,1.00000;%40dP%7d\n",
                    ffctr,bbctr);
                bbctr++;
                ffctr += 2;
            }
            else{
                printf("skiping the pach number %d (not tensor product)\n", fc);
            }
        }
        else if(patch_kind == TP || patch_kind == TP_EQ ) {

            Patch * quad = p;

            dg = quad->degu;

            // HEADER
            fprintf(fp,"128,%7d,%7d,%7d,%7d,0,0,1,0,0,%26dP%7d\n",
                dg,dg,dg,dg,ffctr,bbctr);
            bbctr++;

            // KNOTS
            w = (dg+1)*(dg+1);
            bbctr = knots(dg+1, bbctr, ffctr,fp,8);
            bbctr = knots(dg+1, bbctr, ffctr,fp,8);

            // the w==RATIONAL coordinate
            cols = 8;
            col = 0;
            for (i=0; i<= dg; i++) {
                for (j=0; j<= dg; j++) {
                    if ((col % cols==0) && (col != 0)) {  /* typeset */
                        fprintf(fp,"%8dP%7d\n",ffctr,bbctr);
                        bbctr++;
                    }
                    h = 1.0; //(fp->bb[0][i][j])->w;
                    fprintf(fp,"%7.5f,", h);
                    col++;
                }
            }
            // finish line
            col = col%cols;
            if (col != 0) {
                col = cols-col;
                for (i=0; i< col; i++)
                    fprintf(fp,"        ");
            }
            fprintf(fp,"%8dP%7d\n",ffctr,bbctr);

            bbctr++;

            // the XYZ coordinates
            for (i=0; i<= dg; i++) {
                for (j=0; j<= dg; j++) {
                    hv=QuadBezier_get_bb(quad,i,j);
                    fprintf(fp,"%20e,%20e,%20e,%9dP%7d\n",
                        hv[0],hv[1], hv[2], ffctr,bbctr);
                    bbctr++;
                }
            }
            fprintf(fp,"0.00000,1.00000,0.00000,1.00000;%40dP%7d\n",
                ffctr,bbctr);
            bbctr++;
            ffctr += 2;
        }
        else
            printf("skiping the pach number %d (not tensor product)\n", fc);
    }
    flen[2] = ffctr;
    flen[3] = bbctr;
    // structure of file
    fprintf(fp,"S%7dG%7dD%7dP%7d%40dT%7d\n",
                flen[0],flen[1],flen[2]-1,flen[3]-1,1,1);
    fclose(fp);
    printf("done\n");
}