43 parametrics_cat->warning()
44 <<
"Cannot make a NURBS from the indicated curve.\n";
52 NurbsCurve(
int order,
int num_cvs,
53 const PN_stdfloat knots[],
const LVecBase4 cvs[]) {
57 _cvs.reserve(num_cvs);
58 for (i = 0; i < num_cvs; i++) {
62 int num_knots = num_cvs + order;
63 for (i = 0; i < num_knots; i++) {
93 nassertv(order >= 1 && order <= 4);
94 nassertv(_cvs.empty());
111 get_num_cvs()
const {
120 return _cvs.size() + _order;
134 append_cv(0.0f, 0.0f, 0.0f);
144 append_cv(_cvs.back()._p);
154 LVecBase4 new_cvs[3];
156 for (i = 0; i < _order-1; i++) {
157 int nk = i + k - (_order-1);
159 PN_stdfloat d =
get_knot(nk + _order-1) - ti;
161 new_cvs[i] = _cvs[nk-1]._p;
163 PN_stdfloat a = (t - ti) / d;
164 new_cvs[i] = (1.0f-a)*_cvs[nk-1]._p + a*_cvs[nk]._p;
169 _cvs.insert(_cvs.begin() + k-1, CV());
172 for (i = 0; i < _order-1; i++) {
173 int nk = i + k - (_order-1);
174 _cvs[nk]._p = new_cvs[i];
189 if (n < 0 || n >= (
int)_cvs.size()) {
193 _cvs.erase(_cvs.begin() + n);
202 _cvs.erase(_cvs.begin(), _cvs.end());
211 nassertr(n >= 0 && n < get_num_cvs(),
false);
222 nassertr(n >= 0 && n < get_num_cvs(), LVecBase4::zero());
238 if (n < _order || n-1 >= (
int)_cvs.size()) {
250 if (n < _order || _cvs.empty()) {
252 }
else if (n-1 >= (
int)_cvs.size()) {
253 return _cvs.back()._t;
268 _segs.erase(_segs.begin(), _segs.end());
270 PN_stdfloat knots[8];
273 if ((
int)_cvs.size() > _order-1) {
274 for (
int cv = 0; cv < (int)_cvs.size()-(_order-1); cv++) {
280 for (c = 0; c < _order; c++) {
281 cvs[c] = _cvs[c+cv]._p;
283 for (c = 0; c < _order+_order; c++) {
288 knots[_order] - knots[_order-1]);
293 return !_segs.empty();
304 int rtype1, PN_stdfloat t1,
const LVecBase4 &v1,
305 int rtype2, PN_stdfloat t2,
const LVecBase4 &v2,
306 int rtype3, PN_stdfloat t3,
const LVecBase4 &v3) {
310 nassertr((
int)_cvs.size() > _order-1,
false);
313 for (cv = 0; cv < (int)_cvs.size()-(_order-1); cv++) {
315 if (seg == _last_ti) {
324 PN_stdfloat knots[8];
330 if ((rtype0 | rtype1 | rtype2 | rtype3) & RT_KEEP_ORIG) {
331 for (c = 0; c < 4; c++) {
332 const LVecBase4 &s = (c < _order) ? _cvs[c+cv]._p : LVecBase4::zero();
339 for (c = 0; c < _order+_order; c++) {
344 compute_nurbs_basis(_order, knots, B);
359 for (c = 0; c < _order; c++) {
360 _cvs[c+cv]._p = G.get_col(c);
381 if (na->get_num_cvs() == 0 || nb->get_num_cvs() == 0) {
385 if (na->get_order() != nb->get_order()) {
386 parametrics_cat->error()
387 <<
"Cannot stitch NURBS curves of different orders!\n";
392 LVecBase3 point_offset =
393 na->get_cv_point(na->get_num_cvs() - 1) - nb->get_cv_point(0);
394 int num_b_cvs = nb->get_num_cvs();
395 for (
int i = 0; i < num_b_cvs; i++) {
396 nb->set_cv_point(i, nb->get_cv_point(i) + point_offset);
405 PN_stdfloat t = na->get_max_t();
408 epvector<CV>::iterator ci;
409 for (ci = nb->_cvs.begin(); ci != nb->_cvs.end(); ++ci) {
412 _cvs.push_back(new_cv);
436 return NurbsCurveInterface::convert_to_nurbs(nc);
443 write(std::ostream &out,
int indent_level)
const {
444 NurbsCurveInterface::write(out, indent_level);
452 append_cv_impl(
const LVecBase4 &v) {
453 _cvs.push_back(CV(v,
get_knot(_cvs.size())+1.0f));
454 return _cvs.size()-1;
462 format_egg(std::ostream &out,
const std::string &name,
const std::string &curve_type,
463 int indent_level)
const {
464 return NurbsCurveInterface::format_egg(out, name, curve_type, indent_level);
472 find_cv(PN_stdfloat t) {
474 for (i = _order-1; i < (int)_cvs.size(); i++) {
475 if (_cvs[i]._t >= t) {
501 me->fillin(scan, manager);
511 PiecewiseCurve::write_datagram(manager, me);
517 for (i = 0; i < _cvs.size(); i++) {
518 const CV &cv = _cvs[i];
519 cv._p.write_datagram(me);
531 PiecewiseCurve::fillin(scan, manager);
537 _cvs.reserve(num_cvs);
539 for (i = 0; i < num_cvs; i++) {
541 cv._p.read_datagram(scan);
static void register_with_read_factory()
Initializes the factory for reading these things from Bam files.
virtual void set_order(int order)
Changes the order of the curve.
A basic node of the scene graph or data graph.
virtual bool rebuild_curveseg(int rtype0, PN_stdfloat t0, const LVecBase4 &v0, int rtype1, PN_stdfloat t1, const LVecBase4 &v1, int rtype2, PN_stdfloat t2, const LVecBase4 &v2, int rtype3, PN_stdfloat t3, const LVecBase4 &v3)
Rebuilds the current curve segment (as selected by the most recent call to find_curve()) according to...
void add_float64(PN_float64 value)
Adds a 64-bit floating-point number to the datagram.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
A virtual base class for parametric curves.
virtual bool remove_cv(int n)
Removes the indicated CV from the curve.
bool insert_curveseg(int ti, ParametricCurve *seg, PN_stdfloat tlength)
Inserts a new curve segment at the indicated index.
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual LVecBase4 get_cv(int n) const
Returns the position in homogeneous space of the indicated CV.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual NurbsCurveInterface * get_nurbs_interface()
Returns a pointer to the object as a NurbsCurveInterface object if it happens to be a NURBS-style cur...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
virtual bool stitch(const ParametricCurve *a, const ParametricCurve *b)
Regenerates this curve as one long curve: the first curve connected end-to- end with the second one.
This abstract class defines the interface only for a Nurbs-style curve, with knots and coordinates in...
virtual PN_stdfloat get_knot(int n) const
Retrieves the value of the indicated knot.
A CubicCurveseg is any curve that can be completely described by four 4-valued basis vectors,...
void add_uint32(uint32_t value)
Adds an unsigned 32-bit integer to the datagram.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
virtual bool set_knot(int n, PN_stdfloat t)
Sets the value of the indicated knot.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
virtual bool convert_to_nurbs(ParametricCurve *nc) const
Stores in the indicated NurbsCurve a NURBS representation of an equivalent curve.
virtual bool recompute()
Recalculates the curve basis according to the latest position of the CV's, knots, etc.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
A Nonuniform Rational B-Spline.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
virtual bool insert_cv(PN_stdfloat t)
Inserts a new CV into the middle of the curve at the indicated parametric value.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual int get_num_knots() const
Returns the number of knots on the curve.
virtual bool set_cv(int n, const LVecBase4 &v)
Repositions the indicated CV.
void set_curve_type(int type)
Sets the flag indicating the use to which the curve is intended to be put.
static bool compute_seg(int rtype0, PN_stdfloat t0, const LVecBase4 &v0, int rtype1, PN_stdfloat t1, const LVecBase4 &v1, int rtype2, PN_stdfloat t2, const LVecBase4 &v2, int rtype3, PN_stdfloat t3, const LVecBase4 &v3, const LMatrix4 &B, const LMatrix4 &Bi, LMatrix4 &G)
Given a set of four properties of a curve segment (e.g.
PN_float64 get_float64()
Extracts a 64-bit floating-point number.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A class to retrieve the individual data elements previously stored in a Datagram.
int8_t get_int8()
Extracts a signed 8-bit integer.
TypeHandle is the identifier used to differentiate C++ class types.
virtual bool convert_to_nurbs(ParametricCurve *nc) const
Stores in the indicated NurbsCurve a NURBS representation of an equivalent curve.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
virtual void remove_all_cvs()
Removes all CV's from the curve.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.