15 #include "pandabase.h" 16 #include "hermiteCurve.h" 17 #include "config_parametrics.h" 22 #include "datagramIterator.h" 23 #include "bamWriter.h" 24 #include "bamReader.h" 41 show_vec3(ostream &out,
int indent_level,
const LVecBase3 &v,
43 indent(out, indent_level) << v[0];
44 for (
int i = 1; i<num_dimensions; i++) {
67 _p(c._p), _in(c._in), _out(c._out),
68 _type(c._type), _name(c._name)
183 format_egg(ostream &out,
int indent_level,
int num_dimensions,
184 bool show_in,
bool show_out,
185 PN_stdfloat scale_in, PN_stdfloat scale_out)
const {
187 indent(out, indent_level) <<
"<Vertex> {\n";
188 show_vec3(out, indent_level + 2, _p - scale_in * _in / 3.0,
189 num_dimensions) <<
"\n";
190 indent(out, indent_level) <<
"}\n";
193 indent(out, indent_level) <<
"<Vertex> {\n";
194 show_vec3(out, indent_level + 2, _p, num_dimensions) <<
"\n";
196 indent(out, indent_level+2) <<
"<Scalar> continuity-type { ";
216 indent(out, indent_level) <<
"}\n";
219 indent(out, indent_level) <<
"<Vertex> {\n";
220 show_vec3(out, indent_level + 2, _p + scale_out * _out / 3.0,
221 num_dimensions) <<
"\n";
222 indent(out, indent_level) <<
"}\n";
234 _p.write_datagram(me);
235 _in.write_datagram(me);
236 _out.write_datagram(me);
251 _p.read_datagram(scan);
252 _in.read_datagram(scan);
253 _out.read_datagram(scan);
277 parametrics_cat->warning()
278 <<
"Cannot make a Hermite from the indicated curve." 305 return _points.size();
328 int n =
append_cv(HC_SMOOTH, 0.0f, 0.0f, 0.0f);
333 t = min(max(t, (PN_stdfloat)0.0),
get_max_t());
340 cv._type = HC_SMOOTH;
342 cv._out = cv._in = tan * 0.5f;
344 _points.insert(_points.begin() + n + 1, cv);
364 append_cv(
int type, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
370 _points.push_back(cv);
371 if (_points.size()>1) {
380 return _points.size()-1;
392 if (n < 0 || n >= (
int)_points.size()) {
396 _points.erase(_points.begin() + n);
397 if (_segs.size()>0) {
414 _points.erase(_points.begin(), _points.end());
442 if (n < 0 || n >= (
int)_points.size()) {
446 bool changed_cut =
false;
448 if (type!=_points[n]._type) {
449 changed_cut = (type==HC_CUT || _points[n]._type==HC_CUT);
450 _points[n].set_type(type);
453 invalidate_cv(n, changed_cut);
465 if (n < 0 || n >= (
int)_points.size()) {
468 _points[n].set_point(
LVecBase3(x, y, z));
469 invalidate_cv(n,
false);
481 set_cv_in(
int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
482 if (n < 0 || n >= (
int)_points.size()) {
486 invalidate_cv(n,
false);
498 set_cv_out(
int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
499 if (n < 0 || n >= (
int)_points.size()) {
503 invalidate_cv(n,
false);
515 if (n <= 0 || n >= (
int)_points.size()) {
534 if (n < 0 || n >= (
int)_points.size()) {
537 _points[n].set_name(name);
552 if (n < 0 || n >= (
int)_points.size()) {
556 return _points[n]._type;
567 if (n < 0 || n >= (
int)_points.size()) {
571 return _points[n]._p;
586 if (n < 0 || n >= (
int)_points.size() || _points[n-1]._type==HC_CUT) {
590 return _points[n]._in;
605 if (n < 0 || n >= (
int)_points.size() || _points[n]._type==HC_CUT) {
609 return _points[n]._out;
627 }
else if (n >= (
int)_points.size()) {
641 if (n < 0 || n >= (
int)_points.size()) {
645 return _points[n]._name;
655 output(ostream &out)
const {
656 PiecewiseCurve::output(out);
685 write_cv(ostream &out,
int n)
const {
694 <<
"\ncontinuity type = ";
735 cerr <<
"rebuild_curveseg not implemented for this curve type.\n";
745 format_egg(ostream &out,
const string &name,
const string &curve_type,
746 int indent_level)
const {
747 indent(out, indent_level)
748 <<
"<VertexPool> " << name <<
".pool {\n";
751 for (i = 0; i < (int)_points.size(); i++) {
752 bool show_in = (i != 0);
753 bool show_out = (i != (int)_points.size()-1);
754 _points[i].format_egg(out, indent_level + 2, _num_dimensions,
759 indent(out, indent_level) <<
"}\n";
761 indent(out, indent_level) <<
"<BezierCurve> " << name <<
" {\n";
763 if (!curve_type.empty()) {
764 indent(out, indent_level+2)
765 <<
"<Scalar> type { " << curve_type <<
" }\n";
768 indent(out, indent_level+2) <<
"<TLengths> {";
769 if (_points.size() > 1) {
770 for (i = 0; i < (int)_segs.size(); i++) {
773 indent(out, indent_level+3);
779 indent(out, indent_level+2) <<
"}\n";
781 indent(out, indent_level+2) <<
"<VertexRef> {";
782 for (i = 1; i <= (int)_points.size() * 3 - 2; i++) {
785 indent(out, indent_level+3);
790 indent(out, indent_level+4) <<
"<Ref> { " << name <<
".pool }\n";
791 indent(out, indent_level+2) <<
"}\n";
793 indent(out, indent_level) <<
"}\n";
801 for (
int i = 0; i < 3; i++) {
802 while ((hpr2[i] - hpr1[i]) > 180.0) {
806 while ((hpr2[i] - hpr1[i]) < -180.0) {
819 invalidate_cv(
int n,
bool redo_all) {
821 if (n>0 && _points[n-1]._type!=HC_CUT) {
824 if (_curve_type == PCT_HPR) {
825 wrap_hpr(p1._p, p2._p);
831 if (n+1 < (
int)_points.size()) {
832 if (_points[n]._type==HC_CUT) {
834 seg._v[0] = seg._v[1] = seg._v[2] = seg._v[3] = _points[n]._p;
839 if (_curve_type == PCT_HPR) {
840 wrap_hpr(p1._p, p2._p);
865 find_cv(PN_stdfloat t) {
869 for (n = 0; n < (int)_segs.size(); n++) {
870 if (_segs[n]._tend+0.00001 > t) {
890 for (n = 0; n < (int)_segs.size(); n++) {
891 if (_points[n]._type==HC_CUT) {
893 seg._v[0] = seg._v[1] = seg._v[2] = seg._v[3] = _points[n]._p;
898 if (_curve_type == PCT_HPR) {
899 wrap_hpr(p1._p, p2._p);
929 parse_params(params, scan, manager);
930 me->fillin(scan, manager);
942 PiecewiseCurve::write_datagram(manager, me);
946 for (i = 0; i < _points.size(); i++) {
947 _points[i].write_datagram(manager, me);
961 PiecewiseCurve::fillin(scan, manager);
964 _points.reserve(num_points);
966 for (i = 0; i < num_points; i++) {
969 _points.push_back(cv);
bool remove_cv(int n)
Removes the given CV from the curve.
PN_int8 get_int8()
Extracts a signed 8-bit integer.
This is the base class for all three-component vectors and points.
void add_string(const string &str)
Adds a variable-length string to the datagram.
void remove_all_curvesegs()
Removes all curve segments from the curve.
PN_stdfloat get_cv_tstart(int n) const
Returns the starting point in parametric space of the given CV.
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.
int insert_cv(PN_stdfloat t)
Inserts a new CV at the given parametric point along the curve.
bool insert_curveseg(int ti, ParametricCurve *seg, PN_stdfloat tlength)
Inserts a new curve segment at the indicated index.
void add_int8(PN_int8 value)
Adds a signed 8-bit integer to the datagram.
int get_cv_type(int n) const
Returns the given CV's continuity type, HC_CUT, HC_FREE, HC_G1, or HC_SMOOTH, or 0 if there is no suc...
bool set_cv_name(int n, const char *name)
Changes the name associated with a particular CV.
void hermite_basis(const HermiteCurveCV &cv0, const HermiteCurveCV &cv1, PN_stdfloat tlength=1.0f)
Defines the curve segment as a Hermite.
bool set_cv_out(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Changes the given CV's out tangent.
void fillin(DatagramIterator &scan, BamReader *manager)
Function that reads out of the datagram (or asks manager to read) all of the data that is needed to r...
int append_cv(int type, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Adds a new CV to the end of the curve.
Base class for objects that can be written to and read from Bam files.
void bezier_basis(const BezierSeg &seg)
Defines the curve segment as a Bezier.
virtual bool convert_to_hermite(HermiteCurve *hc) const
Stores an equivalent curve representation in the indicated Hermite curve, if possible.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
PN_uint32 get_uint32()
Extracts an unsigned 32-bit integer.
bool set_cv_point(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Changes the given CV's position.
int get_num_cvs() const
Returns the number of CV's in the curve.
void set_in(const LVecBase3 &in)
Sets the CV's in tangent.
virtual bool get_pt(PN_stdfloat t, LVecBase3 &point, LVecBase3 &tangent) const
Simultaneously returns the point and tangent of the curve at a given parametric point t...
A parametric curve defined by a sequence of control vertices, each with an in and out tangent...
string get_string()
Extracts a variable-length string.
A CubicCurveseg is any curve that can be completely described by four 4-valued basis vectors...
virtual PN_stdfloat get_max_t() const
Returns the upper bound of t for the entire curve.
PN_stdfloat get_tlength(int ti) const
Returns the parametric length of the given segment of the curve.
string get_cv_name(int n) const
Returns the name of the given CV, or NULL.
void set_out(const LVecBase3 &out)
Sets the CV's out tangent.
void set_type(int type)
Sets the continuity type of the CV.
static void register_with_read_factory()
Initializes the factory for reading these things from Bam files.
void remove_all_cvs()
Removes all CV's from the curve.
void format_egg(ostream &out, int indent, int num_dimensions, bool show_in, bool show_out, PN_stdfloat scale_in, PN_stdfloat scale_out) const
Formats the CV for output to an egg file.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
const LVecBase3 & get_cv_in(int n) const
Returns the in tangent of the given CV.
bool set_tlength(int ti, PN_stdfloat tlength)
Sets the parametric length of the given segment of the curve.
bool set_cv_type(int n, int type)
Changes the given CV's continuity type.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
const LVecBase3 & get_cv_point(int n) const
Returns the position of the given CV.
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...
This is the base class for all three-component vectors and points.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
bool set_cv_tstart(int n, PN_stdfloat tstart)
Changes the given CV's parametric starting time.
A single CV of a Hermite curve.
void add_uint32(PN_uint32 value)
Adds an unsigned 32-bit integer to the datagram.
void set_name(const string &name)
Sets the name associated with the CV.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
void write_datagram(BamWriter *manager, Datagram &me) const
Function to write the important information in the particular object to a Datagram.
bool set_cv_in(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Changes the given CV's in tangent.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
const LVecBase3 & get_cv_out(int n) const
Returns the out tangent of the given CV.
bool remove_curveseg(int ti)
Removes the given curve segment from the curve and frees it.
PN_stdfloat get_tstart(int ti) const
Returns the parametric start of the given segment of the curve.
virtual bool is_valid() const
Returns true if the curve is defined.
int get_curve_type() const
Returns the flag indicating the use to which the curve is intended to be put.