27 ParametricCurveCollection::
28 ParametricCurveCollection() {
36 prepare_add_curve(curve);
37 _curves.push_back(curve);
46 prepare_add_curve(curve);
47 index = std::min(index, _curves.size());
48 _curves.insert(_curves.begin() + index, curve);
74 for (
int i = 0; curve_index == -1 && i < (int)_curves.size(); i++) {
75 if (_curves[i] == curve) {
80 if (curve_index == -1) {
97 nassertv(index < _curves.size());
99 prepare_remove_curve(curve);
100 _curves.erase(_curves.begin() + index);
111 nassertv(index < _curves.size());
112 prepare_remove_curve(_curves[index]);
113 prepare_add_curve(curve);
114 _curves[index] = curve;
124 ParametricCurves::const_iterator ci;
125 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
126 if (curve == (*ci)) {
138 ParametricCurves::iterator ci;
139 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
141 prepare_remove_curve(curve);
156 ParametricCurves::iterator ci;
157 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
162 if (xyz_curve ==
nullptr) {
165 prepare_remove_curve(curve);
170 if (hpr_curve ==
nullptr) {
173 prepare_remove_curve(curve);
178 prepare_remove_curve(curve);
183 _curves.push_back(xyz_curve);
185 if (hpr_curve !=
nullptr) {
186 _curves.push_back(hpr_curve);
198 ParametricCurves::const_iterator ci;
199 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
214 ParametricCurves::const_iterator ci;
215 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
232 if (xyz_curve !=
nullptr) {
236 ParametricCurves::const_iterator ci;
237 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
253 ParametricCurves::const_iterator ci;
254 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
269 ParametricCurves::const_iterator ci;
270 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
279 nassert_raise(
"index out of range");
296 make_even(PN_stdfloat max_t, PN_stdfloat segments_per_unit) {
298 if (xyz_curve ==
nullptr) {
299 parametrics_cat.error()
300 <<
"No XYZ curve for make_even().\n";
310 int num_segments = std::max(1, (
int)cfloor(segments_per_unit * xyz_curve->
get_max_t() + 0.5f));
312 if (parametrics_cat.is_debug()) {
313 parametrics_cat.debug()
314 <<
"Calculating length of curve.\n";
318 PN_stdfloat segment_length = net_length / (PN_stdfloat)num_segments;
320 if (parametrics_cat.is_debug()) {
321 parametrics_cat.debug()
322 <<
"Curve has total length " << net_length <<
"; dividing into "
323 << num_segments <<
" segments of " << segment_length <<
" units each.\n";
326 PN_stdfloat last_t = 0.0f;
327 fitter.
add_xyz(0.0f, LVecBase3(last_t, 0.0f, 0.0f));
328 PN_stdfloat val_inc= max_t/num_segments;
329 PN_stdfloat val=val_inc;
331 for (
int i = 0; i < num_segments; i++,val+=val_inc) {
332 PN_stdfloat next_t = xyz_curve->
find_length(last_t, segment_length);
334 val, LVecBase3(next_t, 0.0f, 0.0f));
336 if (parametrics_cat.is_spam()) {
337 parametrics_cat.spam()
338 <<
"Point " << i <<
" is at " << next_t <<
"\n";
344 if (parametrics_cat.is_debug()) {
345 parametrics_cat.debug()
346 <<
"Done computing segments.\n";
352 nassertv(t_curve !=
nullptr);
365 if (xyz_curve ==
nullptr) {
366 parametrics_cat.error()
367 <<
"No XYZ curve for face_forward().\n";
374 ParametricCurves::const_iterator ci;
377 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
380 prepare_remove_curve(curve);
383 xyz_index = (ci - _curves.begin());
385 new_curves.push_back(curve);
388 _curves.swap(new_curves);
395 int num_segments = (int)cfloor(segments_per_unit * max_t + 0.5);
397 LVecBase3 hpr(0.0f, 0.0f, 0.0f);
402 determine_hpr(0.001, xyz_curve, hpr);
405 for (
int i = 0; i < num_segments; i++) {
406 PN_stdfloat t = (PN_stdfloat)(i + 1) / num_segments * max_t;
407 determine_hpr(t, xyz_curve, hpr);
415 nassertv(hpr_curve !=
nullptr);
429 nurbs->set_curve_type(PCT_T);
431 nurbs->append_cv(LVecBase3(0.0f, 0.0f, 0.0f));
432 nurbs->append_cv(LVecBase3(
get_max_t(), 0.0f, 0.0f));
433 nurbs->set_knot(0, 0.0f);
434 nurbs->set_knot(1, 0.0f);
435 nurbs->set_knot(2, max_t);
436 nurbs->set_knot(3, max_t);
452 evaluate(PN_stdfloat t, LVecBase3 &xyz, LVecBase3 &hpr)
const {
462 ParametricCurves::const_reverse_iterator ci;
463 for (ci = _curves.rbegin(); ci != _curves.rend(); ++ci) {
476 default_curve = curve;
480 if (!curve->get_point(t0, point)) {
487 if (xyz_curve ==
nullptr) {
488 xyz_curve = default_curve;
492 if (xyz_curve !=
nullptr) {
493 if (!xyz_curve->get_point(t0, xyz)) {
498 if (hpr_curve !=
nullptr) {
499 if (!hpr_curve->get_point(t0, hpr)) {
519 evaluate(PN_stdfloat t, LMatrix4 &result, CoordinateSystem cs)
const {
520 LVecBase3 xyz(0.0f, 0.0f, 0.0f);
521 LVecBase3 hpr(0.0f, 0.0f, 0.0f);
527 compose_matrix(result,
528 LVecBase3(1.0f, 1.0f, 1.0f),
529 LVecBase3(0.0f, 0.0f, 0.0f),
544 ParametricCurves::const_iterator ci;
545 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
549 if (!curve->get_point(t0, point)) {
567 if (xyz_curve ==
nullptr) {
572 if (t0 >= 0.0f && t < xyz_curve->
get_max_t()) {
573 return xyz_curve->
adjust_point(t, xyz[0], xyz[1], xyz[2]);
586 if (hpr_curve ==
nullptr) {
591 if (t0 >= 0.0f && t < hpr_curve->
get_max_t()) {
592 return hpr_curve->
adjust_point(t, hpr[0], hpr[1], hpr[2]);
605 ParametricCurves::iterator ci;
606 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
634 if (a_xyz !=
nullptr && b_xyz !=
nullptr) {
636 if (!new_xyz->stitch(a_xyz, b_xyz)) {
643 if (a_hpr !=
nullptr && b_hpr !=
nullptr) {
645 if (!new_hpr->stitch(a_hpr, b_hpr)) {
662 out <<
"1 ParametricCurve";
673 write(std::ostream &out,
int indent_level)
const {
674 ParametricCurves::const_iterator ci;
675 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
677 indent(out, indent_level) << *curve <<
"\n";
691 parametrics_cat.error()
692 <<
"Unable to write to " << filename <<
"\n";
704 if (cs == CS_default) {
705 cs = get_default_coordinate_system();
708 if (cs != CS_invalid) {
709 out <<
"<CoordinateSystem> { ";
737 ParametricCurves::iterator ci;
738 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
749 name += format_string(xyz_count);
757 name += format_string(hpr_count);
765 name += format_string(t_count);
771 curve->set_name(name);
774 if (!curve->
write_egg(out, filename, CS_invalid)) {
789 if (node->
is_of_type(ParametricCurve::get_class_type())) {
791 prepare_add_curve(curve);
792 _curves.push_back(curve);
797 for (
int i = 0; i < num_children; i++) {
815 _drawers.push_back(drawer);
817 ParametricCurves::iterator ci;
818 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
831 _drawers.remove(drawer);
833 ParametricCurves::iterator ci;
834 for (ci = _curves.begin(); ci != _curves.end(); ++ci) {
845 bool ParametricCurveCollection::
846 determine_hpr(PN_stdfloat t,
ParametricCurve *xyz_curve, LVecBase3 &hpr)
const {
850 if (!xyz_curve->get_tangent(t0, tangent)) {
854 if (tangent.length_squared() == 0.0f) {
859 look_at(mat, tangent);
861 LVecBase3 scale, shear;
862 return decompose_matrix(mat, scale, shear, hpr);
869 void ParametricCurveCollection::
871 DrawerList::iterator di;
872 for (di = _drawers.begin(); di != _drawers.end(); ++di) {
873 ParametricCurveDrawer *drawer = (*di);
882 void ParametricCurveCollection::
884 DrawerList::iterator di;
885 for (di = _drawers.begin(); di != _drawers.end(); ++di) {
886 ParametricCurveDrawer *drawer = (*di);
894 void ParametricCurveCollection::