本文整理汇总了C++中ON_NurbsCurve类的典型用法代码示例。如果您正苦于以下问题:C++ ON_NurbsCurve类的具体用法?C++ ON_NurbsCurve怎么用?C++ ON_NurbsCurve使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ON_NurbsCurve类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
NurbsTools::computeBoundingBox (const ON_NurbsCurve &nurbs, Eigen::Vector3d &_min, Eigen::Vector3d &_max)
{
_min = Eigen::Vector3d (DBL_MAX, DBL_MAX, DBL_MAX);
_max = Eigen::Vector3d (-DBL_MAX, -DBL_MAX, -DBL_MAX);
for (int i = 0; i < nurbs.CVCount (); i++)
{
ON_3dPoint p;
nurbs.GetCV (i, p);
if (p.x < _min (0))
_min (0) = p.x;
if (p.y < _min (1))
_min (1) = p.y;
if (p.z < _min (2))
_min (2) = p.z;
if (p.x > _max (0))
_max (0) = p.x;
if (p.y > _max (1))
_max (1) = p.y;
if (p.z > _max (2))
_max (2) = p.z;
}
}
示例2: GetNurbForm
int ON_LineCurve::GetNurbForm(
ON_NurbsCurve& c,
double tolerance,
const ON_Interval* subdomain
) const
{
int rc = 0;
if ( c.Create( m_dim==2?2:3, false, 2, 2 ) )
{
rc = 1;
double t0 = m_t[0];
double t1 = m_t[1];
if (subdomain )
{
if ( t0 < t1 )
{
const ON_Interval& sd = *subdomain;
double s0 = sd[0];
double s1 = sd[1];
if (s0 < t0) s0 = t0;
if (s1 > t1) s1 = t1;
if (s0 < s1)
{
t0 = s0;
t1 = s1;
}
else
rc = 0;
}
else
{
rc = 0;
}
}
if ( t0 < t1 )
{
c.m_knot[0] = t0;
c.m_knot[1] = t1;
c.SetCV( 0, PointAt(t0));
c.SetCV( 1, PointAt(t1));
}
else if ( t0 > t1 )
{
rc = 0;
c.m_knot[0] = t1;
c.m_knot[1] = t0;
c.SetCV( 0, PointAt(t1));
c.SetCV( 1, PointAt(t0));
}
else
{
rc = 0;
c.m_knot[0] = 0.0;
c.m_knot[1] = 1.0;
c.SetCV( 0, m_line.from );
c.SetCV( 1, m_line.to );
}
}
return rc;
}
示例3: updateInternal
/**
* \return List of bezier spline segments which together represent this curve.
*/
QList<RSpline> RSpline::getBezierSegments() const {
// spline is a single bezier segment:
if (countControlPoints()==getDegree()+1) {
return QList<RSpline>() << *this;
}
updateInternal();
QList<RSpline> ret;
#ifndef R_NO_OPENNURBS
ON_NurbsCurve* dup = dynamic_cast<ON_NurbsCurve*>(curve.DuplicateCurve());
if (dup==NULL) {
return ret;
}
dup->MakePiecewiseBezier();
for (int i=0; i<=dup->CVCount() - dup->Order(); ++i) {
ON_BezierCurve bc;
if (!dup->ConvertSpanToBezier(i, bc)) {
continue;
}
QList<RVector> ctrlPts;
for (int cpi=0; cpi<bc.CVCount(); cpi++) {
ON_3dPoint onp;
bc.GetCV(cpi, onp);
ctrlPts.append(RVector(onp.x, onp.y, onp.z));
}
ret.append(RSpline(ctrlPts, degree));
}
delete dup;
#endif
return ret;
}
示例4: printf
ON_NurbsCurve
FittingCurve2d::initCPsNurbsCurve2D (int order, const vector_vec2d &cps)
{
int cp_red = order - 2;
ON_NurbsCurve nurbs;
if (cps.size () < 3 || cps.size () < (2 * cp_red + 1))
{
printf ("[FittingCurve2d::initCPsNurbsCurve2D] Warning, number of control points too low.\n");
return nurbs;
}
int ncps = cps.size () + 2 * cp_red; // +2*cp_red for smoothness and +1 for closing
nurbs = ON_NurbsCurve (2, false, order, ncps);
nurbs.MakePeriodicUniformKnotVector (1.0 / (ncps - order + 1));
for (int j = 0; j < cps.size (); j++)
nurbs.SetCV (cp_red + j, ON_3dPoint (cps[j] (0), cps[j] (1), 0.0));
// close nurbs
nurbs.SetCV (cp_red + cps.size (), ON_3dPoint (cps[0] (0), cps[0] (1), 0.0));
// make smooth at closing point
for (int j = 0; j < cp_red; j++)
{
ON_3dPoint cp;
nurbs.GetCV (nurbs.CVCount () - 1 - cp_red + j, cp);
nurbs.SetCV (j, cp);
nurbs.GetCV (cp_red - j, cp);
nurbs.SetCV (nurbs.CVCount () - 1 - j, cp);
}
return nurbs;
}
示例5: VisualizeCurve
void
VisualizeCurve (ON_NurbsCurve &curve, double r, double g, double b, bool show_cps)
{
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
pcl::on_nurbs::Triangulation::convertCurve2PointCloud (curve, cloud, 8);
for (std::size_t i = 0; i < cloud->size () - 1; i++)
{
pcl::PointXYZRGB &p1 = cloud->at (i);
pcl::PointXYZRGB &p2 = cloud->at (i + 1);
std::ostringstream os;
os << "line_" << r << "_" << g << "_" << b << "_" << i;
viewer.addLine<pcl::PointXYZRGB> (p1, p2, r, g, b, os.str ());
}
if (show_cps)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cps (new pcl::PointCloud<pcl::PointXYZ>);
for (int i = 0; i < curve.CVCount (); i++)
{
ON_3dPoint cp;
curve.GetCV (i, cp);
pcl::PointXYZ p;
p.x = float (cp.x);
p.y = float (cp.y);
p.z = float (cp.z);
cps->push_back (p);
}
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> handler (cps, 255 * r, 255 * g, 255 * b);
viewer.addPointCloud<pcl::PointXYZ> (cps, handler, "cloud_cps");
}
}
示例6:
std::vector<double>
FittingCurve::getElementVector (const ON_NurbsCurve &nurbs)
{
std::vector<double> result;
int idx_min = 0;
int idx_max = nurbs.m_knot_capacity - 1;
if (nurbs.IsClosed ())
{
idx_min = nurbs.m_order - 2;
idx_max = nurbs.m_knot_capacity - nurbs.m_order + 1;
}
const double* knotsU = nurbs.Knot ();
result.push_back (knotsU[idx_min]);
//for(int E=(m_nurbs.m_order[0]-2); E<(m_nurbs.m_knot_capacity[0]-m_nurbs.m_order[0]+2); E++) {
for (int E = idx_min + 1; E <= idx_max; E++)
{
if (knotsU[E] != knotsU[E - 1]) // do not count double knots
result.push_back (knotsU[E]);
}
return result;
}
示例7: BoundingBox
ON_BoundingBox ON_Arc::BoundingBox() const
{
// TODO - compute tight arc bounding box
// Using these knot[] and cv[] arrays makes this function
// not use any heap memory.
double knot[10];
ON_4dPoint cv[9];
ON_NurbsCurve c;
c.m_knot = knot;
c.m_cv = &cv[0].x;
if ( GetNurbForm(c) )
return c.BoundingBox();
return ON_Circle::BoundingBox();
}
示例8: d_shortest_elem
double
FittingCurve2d::findClosestElementMidPoint (const ON_NurbsCurve &nurbs, const Eigen::Vector2d &pt, double hint)
{
// evaluate hint
double param = hint;
double points[2];
nurbs.Evaluate (param, 0, 2, points);
Eigen::Vector2d p (points[0], points[1]);
Eigen::Vector2d r = p - pt;
double d_shortest_hint = r.squaredNorm ();
double d_shortest_elem (DBL_MAX);
// evaluate elements
std::vector<double> elements = pcl::on_nurbs::FittingCurve2d::getElementVector (nurbs);
double seg = 1.0 / (nurbs.Order () - 1);
for (unsigned i = 0; i < elements.size () - 1; i++)
{
double &xi0 = elements[i];
double &xi1 = elements[i + 1];
double dxi = xi1 - xi0;
for (unsigned j = 0; j < nurbs.Order (); j++)
{
double xi = xi0 + (seg * j) * dxi;
nurbs.Evaluate (xi, 0, 2, points);
p (0) = points[0];
p (1) = points[1];
r = p - pt;
double d = r.squaredNorm ();
if (d < d_shortest_elem)
{
d_shortest_elem = d;
param = xi;
}
}
}
if(d_shortest_hint < d_shortest_elem)
return hint;
else
return param;
}
示例9: hint
double
FittingCurve::findClosestElementMidPoint (const ON_NurbsCurve &nurbs, const Eigen::Vector3d &pt)
{
double hint (0.0);
Eigen::Vector3d p, r;
std::vector<double> elements = getElementVector (nurbs);
double points[3];
double d_shortest (DBL_MAX);
for (unsigned i = 0; i < elements.size () - 1; i++)
{
double xi = elements[i] + 0.5 * (elements[i + 1] - elements[i]);
nurbs.Evaluate (xi, 0, 3, points);
p (0) = points[0];
p (1) = points[1];
p (2) = points[2];
r = p - pt;
double d = r.squaredNorm ();
if (d < d_shortest)
{
d_shortest = d;
hint = xi;
}
}
return hint;
}
示例10: vp
bool
Triangulation::isInside(const ON_NurbsCurve &curve, const pcl::PointXYZ &v)
{
Eigen::Vector2d vp (v.x, v.y);
Eigen::Vector3d a0, a1;
pcl::on_nurbs::NurbsTools::computeBoundingBox (curve, a0, a1);
double rScale = 1.0 / pcl::on_nurbs::NurbsTools::computeRScale (a0, a1);
Eigen::Vector2d pc, tc;
double err, param;
if (curve.Order () == 2)
param = pcl::on_nurbs::FittingCurve2dAPDM::inverseMappingO2 (curve, vp, err, pc, tc);
else
{
param = pcl::on_nurbs::FittingCurve2dAPDM::findClosestElementMidPoint (curve, vp);
param = pcl::on_nurbs::FittingCurve2dAPDM::inverseMapping (curve, vp, param, err, pc, tc, rScale);
}
Eigen::Vector3d a (vp (0) - pc (0), vp (1) - pc (1), 0.0);
Eigen::Vector3d b (tc (0), tc (1), 0.0);
Eigen::Vector3d z = a.cross (b);
return (z (2) >= 0.0);
}
示例11: GetNurbForm
int ON_ArcCurve::GetNurbForm( // returns 0: unable to create NURBS representation
// with desired accuracy.
// 1: success - returned NURBS parameterization
// matches the curve's to wthe desired accuracy
// 2: success - returned NURBS point locus matches
// the curve's to the desired accuracy but, on
// the interior of the curve's domain, the
// curve's parameterization and the NURBS
// parameterization may not match to the
// desired accuracy.
ON_NurbsCurve& c,
double tolerance,
const ON_Interval* subdomain // OPTIONAL subdomain of arc
) const
{
int rc = 0;
if ( subdomain )
{
ON_ArcCurve trimmed_arc(*this);
if ( trimmed_arc.Trim(*subdomain) )
{
rc = trimmed_arc.GetNurbForm( c, tolerance, NULL );
}
}
else if ( m_t.IsIncreasing() && m_arc.IsValid() )
{
if ( NurbsCurveArc( m_arc, m_dim, c ) )
{
rc = 2;
c.SetDomain( m_t[0], m_t[1] );
}
}
return rc;
}
示例12: GetNurbForm
ON_BOOL32 ON_Ellipse::GetNurbForm( ON_NurbsCurve& nurbscurve ) const
{
int rc = 0;
if ( IsValid() ) {
nurbscurve.Create( 3, true, 3, 9 );
nurbscurve.m_knot[0] = nurbscurve.m_knot[1] = 0.0;
nurbscurve.m_knot[2] = nurbscurve.m_knot[3] = 0.5*ON_PI;
nurbscurve.m_knot[4] = nurbscurve.m_knot[5] = ON_PI;
nurbscurve.m_knot[6] = nurbscurve.m_knot[7] = 1.5*ON_PI;
nurbscurve.m_knot[8] = nurbscurve.m_knot[9] = 2.0*ON_PI;
ON_4dPoint* CV = (ON_4dPoint*)nurbscurve.m_cv;
CV[0] = plane.PointAt( radius[0], 0.0);
CV[1] = plane.PointAt( radius[0], radius[1]);
CV[2] = plane.PointAt( 0.0, radius[1]);
CV[3] = plane.PointAt(-radius[0], radius[1]);
CV[4] = plane.PointAt(-radius[0], 0.0);
CV[5] = plane.PointAt(-radius[0], -radius[1]);
CV[6] = plane.PointAt( 0.0, -radius[1]);
CV[7] = plane.PointAt( radius[0], -radius[1]);
CV[8] = CV[0];
const double w = 1.0/sqrt(2.0);
int i;
for ( i = 1; i < 8; i += 2 ) {
CV[i].x *= w;
CV[i].y *= w;
CV[i].z *= w;
CV[i].w = w;
}
rc = 2;
}
return rc;
}
示例13: printf
ON_NurbsCurve
FittingCurve2d::initCPsNurbsCurve2D (int order, const vector_vec2d &cps)
{
ON_NurbsCurve nurbs;
if ((int)cps.size () < (2 * order))
{
printf ("[FittingCurve2d::initCPsNurbsCurve2D] Warning, number of control points too low.\n");
return nurbs;
}
int cp_red = order - 2;
int ncps = cps.size () + cp_red;
nurbs = ON_NurbsCurve (2, false, order, ncps);
nurbs.MakePeriodicUniformKnotVector (1.0 / (ncps - order + 1));
for (int j = 0; j < ncps; j++)
nurbs.SetCV (j, ON_3dPoint (cps[j] (0), cps[j] (1), 0.0));
for (int j = 0; j < cp_red; j++)
{
ON_3dPoint cp;
nurbs.GetCV (nurbs.m_cv_count - 1 - cp_red + j, cp);
nurbs.SetCV (j, cp);
nurbs.GetCV (cp_red - j, cp);
nurbs.SetCV (nurbs.m_cv_count - 1 - j, cp);
}
return nurbs;
}
示例14: ON_NurbsCurve_CreateControlPointCurve
RH_C_FUNCTION ON_NurbsCurve* ON_NurbsCurve_CreateControlPointCurve(int count, /*ARRAY*/const ON_3dPoint* points, int degree)
{
if( count < 2 || NULL == points )
return NULL;
int order = ( count <= degree ) ? count : degree + 1;
ON_NurbsCurve* pNC = ON_NurbsCurve::New();
if( points[0].DistanceTo(points[count-1]) < ON_SQRT_EPSILON )
pNC->CreatePeriodicUniformNurbs( 3, order, count-1, points );
else
pNC->CreateClampedUniformNurbs( 3, order, count, points );
if( !pNC->IsValid() )
{
delete pNC;
return NULL;
}
return pNC;
}
示例15: CircleAt
int ON_Cone::GetNurbForm( ON_NurbsSurface& s ) const
{
int rc = 0;
if ( IsValid() ) {
ON_Circle c = CircleAt(height);
ON_NurbsCurve n;
c.GetNurbForm(n);
ON_3dPoint apex = ApexPoint();
ON_4dPoint cv;
int i, j0, j1;
s.Create(3,TRUE,3,2,9,2);
for ( i = 0; i < 10; i++ )
s.m_knot[0][i] = n.m_knot[i];
if ( height >= 0.0 ) {
s.m_knot[1][0] = 0.0;
s.m_knot[1][1] = height;
j0 = 0;
j1 = 1;
}
else {
s.m_knot[1][0] = height;
s.m_knot[1][1] = 0.0;
j0 = 1;
j1 = 0;
}
for ( i = 0; i < 9; i++ ) {
cv = n.CV(i);
s.SetCV(i, j1, ON::homogeneous_rational, &cv.x );
cv.x = apex.x*cv.w;
cv.y = apex.y*cv.w;
cv.z = apex.z*cv.w;
s.SetCV(i, j0, cv);
}
rc = 2;
}
return rc;
}