*** empty log message ***

This commit is contained in:
David Rose 2001-02-16 23:18:17 +00:00
parent d20f9783cf
commit 8d939150d7
11 changed files with 484 additions and 148 deletions

View File

@ -301,7 +301,7 @@ NUMERIC ([+-]?(([0-9]+[.]?)|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?)
yyless(1);
}
[ \t] {
[ \t\r] {
// Eat whitespace.
accept();
}
@ -689,7 +689,7 @@ NUMERIC ([+-]?(([0-9]+[.]?)|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?)
return STRING;
}
[^ \t\n{}"]+ {
[^ \t\n\r{}"]+ {
// Unquoted string.
accept();
eggyylval._string = yytext;

View File

@ -7,7 +7,7 @@
putil
#define SOURCES \
compose_matrix.I compose_matrix.cxx compose_matrix.h \
cmath.I cmath.h compose_matrix.I compose_matrix.cxx compose_matrix.h \
config_linmath.cxx config_linmath.h coordinateSystem.cxx \
coordinateSystem.h deg_2_rad.h \
ioPtaDatagramLinMath.I ioPtaDatagramLinMath.cxx \

View File

@ -6,6 +6,8 @@
#ifndef CMATH_H
#define CMATH_H
#include <pandabase.h>
#include <math.h>
// This file declares a number of C++-style overloading wrappers

View File

@ -25,6 +25,10 @@ ConfigureFn(config_parametrics) {
HermiteCurve::init_type();
NurbsCurve::init_type();
NurbsCurveDrawer::init_type();
CubicCurveseg::register_with_read_factory();
HermiteCurve::register_with_read_factory();
NurbsCurve::register_with_read_factory();
}
const DSearchPath &

View File

@ -22,6 +22,10 @@
#include "nurbsCurve.h"
#include "curveDrawer.h"
#include <datagram.h>
#include <datagramIterator.h>
#include <bamWriter.h>
#include <bamReader.h>
////////////////////////////////////////////////////////////////////
// Statics
@ -595,13 +599,32 @@ r_calc_length(double t1, double t2, const LPoint3f &p1, const LPoint3f &p2,
////////////////////////////////////////////////////////////////////
// Function: ParametricCurve::write_datagram
// Access: Public
// Access: Protected, Virtual
// Description: Function to write the important information in
// the particular object to a Datagram
////////////////////////////////////////////////////////////////////
void ParametricCurve::
write_datagram(BamWriter *, Datagram &) {
// TODO: write the write_datagram.
write_datagram(BamWriter *manager, Datagram &me) {
NamedNode::write_datagram(manager, me);
me.add_int8(_curve_type);
me.add_int8(_num_dimensions);
}
////////////////////////////////////////////////////////////////////
// Function: ParametricCurve::fillin
// Access: Protected
// Description: Function that reads out of the datagram (or asks
// manager to read) all of the data that is needed to
// re-create this object and stores it in the appropiate
// place
////////////////////////////////////////////////////////////////////
void ParametricCurve::
fillin(DatagramIterator &scan, BamReader *manager) {
NamedNode::fillin(scan, manager);
_curve_type = scan.get_int8();
_num_dimensions = scan.get_int8();
}
@ -1150,6 +1173,72 @@ current_seg_range(double t) const {
return t;
}
////////////////////////////////////////////////////////////////////
// Function: PiecewiseCurve::write_datagram
// Access: Protected, Virtual
// Description: Function to write the important information in
// the particular object to a Datagram
////////////////////////////////////////////////////////////////////
void PiecewiseCurve::
write_datagram(BamWriter *manager, Datagram &me) {
ParametricCurve::write_datagram(manager, me);
me.add_uint32(_segs.size());
size_t i;
for (i = 0; i < _segs.size(); i++) {
const Curveseg &seg = _segs[i];
manager->write_pointer(me, seg._curve);
me.add_float64(seg._tend);
}
_last_ti = 0;
}
////////////////////////////////////////////////////////////////////
// Function: PiecewiseCurve::fillin
// Access: Protected
// Description: Function that reads out of the datagram (or asks
// manager to read) all of the data that is needed to
// re-create this object and stores it in the appropiate
// place
////////////////////////////////////////////////////////////////////
void PiecewiseCurve::
fillin(DatagramIterator &scan, BamReader *manager) {
ParametricCurve::fillin(scan, manager);
size_t num_segs = scan.get_uint32();
_segs.reserve(num_segs);
size_t i;
for (i = 0; i < num_segs; i++) {
Curveseg seg;
manager->read_pointer(scan, this);
seg._curve = (ParametricCurve *)NULL;
seg._tend = scan.get_float64();
_segs.push_back(seg);
}
}
////////////////////////////////////////////////////////////////////
// Function: PiecewiseCurve::complete_pointers
// Access: Protected, Virtual
// Description: Takes in a vector of pointes to TypedWriteable
// objects that correspond to all the requests for
// pointers that this object made to BamReader.
////////////////////////////////////////////////////////////////////
int PiecewiseCurve::
complete_pointers(vector_typedWriteable &plist, BamReader *manager) {
int used = ParametricCurve::complete_pointers(plist, manager);
nassertr(used + _segs.size() <= plist.size(), used);
size_t i;
for (i = 0; i < _segs.size(); i++) {
DCAST_INTO_R(_segs[i]._curve, plist[used + i], used);
}
return used + _segs.size();
}
////////////////////////////////////////////////////////////////////
// Function: CubicCurveseg::Constructor
// Access: Public
@ -1678,3 +1767,68 @@ compute_seg(int rtype0, double t0, const LVecBase4f &v0,
return true;
}
////////////////////////////////////////////////////////////////////
// Function: CubicCurveseg::register_with_factory
// Access: Public, Static
// Description: Initializes the factory for reading these things from
// Bam files.
////////////////////////////////////////////////////////////////////
void CubicCurveseg::
register_with_read_factory() {
BamReader::get_factory()->register_factory(get_class_type(), make_CubicCurveseg);
}
////////////////////////////////////////////////////////////////////
// Function: CubicCurveseg::make_CubicCurveseg
// Access: Protected
// Description: Factory method to generate an object of this type.
////////////////////////////////////////////////////////////////////
TypedWriteable *CubicCurveseg::
make_CubicCurveseg(const FactoryParams &params) {
CubicCurveseg *me = new CubicCurveseg;
BamReader *manager;
Datagram packet;
parse_params(params, manager, packet);
DatagramIterator scan(packet);
me->fillin(scan, manager);
return me;
}
////////////////////////////////////////////////////////////////////
// Function: CubicCurveseg::write_datagram
// Access: Protected, Virtual
// Description: Function to write the important information in
// the particular object to a Datagram
////////////////////////////////////////////////////////////////////
void CubicCurveseg::
write_datagram(BamWriter *manager, Datagram &me) {
ParametricCurve::write_datagram(manager, me);
Bx.write_datagram(me);
By.write_datagram(me);
Bz.write_datagram(me);
Bw.write_datagram(me);
me.add_bool(rational);
}
////////////////////////////////////////////////////////////////////
// Function: CubicCurveseg::fillin
// Access: Protected
// Description: Function that reads out of the datagram (or asks
// manager to read) all of the data that is needed to
// re-create this object and stores it in the appropiate
// place
////////////////////////////////////////////////////////////////////
void CubicCurveseg::
fillin(DatagramIterator &scan, BamReader *manager) {
ParametricCurve::fillin(scan, manager);
Bx.read_datagram(scan);
By.read_datagram(scan);
Bz.read_datagram(scan);
Bw.read_datagram(scan);
rational = scan.get_bool();
}

View File

@ -119,8 +119,6 @@ public:
};
typedef vector<BezierSeg> BezierSegs;
virtual void write_datagram(BamWriter *, Datagram &);
virtual bool GetBezierSegs(BezierSegs &) const {
return false;
}
@ -145,6 +143,10 @@ protected:
int _curve_type;
int _num_dimensions;
// TypedWriteable stuff
protected:
virtual void write_datagram(BamWriter *manager, Datagram &me);
void fillin(DatagramIterator &scan, BamReader *manager);
public:
static TypeHandle get_class_type() {
@ -227,10 +229,6 @@ protected:
Curveseg() {}
Curveseg(ParametricCurve *c, double t) : _curve(c), _tend(t) {}
int descend_pfb(void *handle);
int store_pfb(void *handle);
int load_pfb(void *handle);
ParametricCurve *_curve;
double _tend;
};
@ -239,6 +237,13 @@ protected:
int _last_ti;
// TypedWriteable stuff
protected:
virtual void write_datagram(BamWriter *manager, Datagram &me);
void fillin(DatagramIterator &scan, BamReader *manager);
virtual int complete_pointers(vector_typedWriteable &plist,
BamReader *manager);
public:
static TypeHandle get_class_type() {
return _type_handle;
@ -342,6 +347,16 @@ public:
LVecBase4f Bx, By, Bz, Bw;
bool rational;
// TypedWriteable stuff
public:
static void register_with_read_factory();
protected:
static TypedWriteable *make_CubicCurveseg(const FactoryParams &params);
virtual void write_datagram(BamWriter *manager, Datagram &me);
void fillin(DatagramIterator &scan, BamReader *manager);
public:
static TypeHandle get_class_type() {
return _type_handle;

View File

@ -21,6 +21,12 @@
#include "config_parametrics.h"
#include "luse.h"
#include <indent.h>
#include <datagram.h>
#include <datagramIterator.h>
#include <bamWriter.h>
#include <bamReader.h>
#include <math.h>
////////////////////////////////////////////////////////////////////
@ -33,28 +39,15 @@ static const LVecBase3f zero = LVecBase3f(0.0, 0.0, 0.0);
// used from time to time as an initializer.
////////////////////////////////////////////////////////////////////
// Function: Indent
// Description: This function duplicates a similar function declared
// in eggBasics.C. It prints a specified number of
// spaces to indent each line of output.
////////////////////////////////////////////////////////////////////
static ostream &
Indent(ostream &out, int indent) {
for (int i=0; i<indent; i++) {
out << ' ';
}
return out;
}
////////////////////////////////////////////////////////////////////
// Function: show_vec3
// Description: This function writes a LVecBase3f, with a specified
// number of significant dimensions.
////////////////////////////////////////////////////////////////////
static ostream &
show_vec3(ostream &out, int indent, const LVecBase3f &v, int num_dimensions) {
Indent(out, indent) << v[0];
show_vec3(ostream &out, int indent_level, const LVecBase3f &v,
int num_dimensions) {
indent(out, indent_level) << v[0];
for (int i = 1; i<num_dimensions; i++) {
out << " " << v[i];
}
@ -68,7 +61,6 @@ show_vec3(ostream &out, int indent, const LVecBase3f &v, int num_dimensions) {
////////////////////////////////////////////////////////////////////
HermiteCurveCV::
HermiteCurveCV() {
_name = NULL;
}
@ -80,13 +72,8 @@ HermiteCurveCV() {
HermiteCurveCV::
HermiteCurveCV(const HermiteCurveCV &c) :
_p(c._p), _in(c._in), _out(c._out),
_type(c._type) {
if (c._name==NULL) {
_name = NULL;
} else {
_name = new char[strlen(c._name)+1];
strcpy(_name, c._name);
}
_type(c._type), _name(c._name)
{
}
@ -97,9 +84,6 @@ HermiteCurveCV(const HermiteCurveCV &c) :
////////////////////////////////////////////////////////////////////
HermiteCurveCV::
~HermiteCurveCV() {
if (_name != NULL) {
delete [] _name;
}
}
@ -192,39 +176,31 @@ set_type(int type) {
// Description: Sets the name associated with the CV.
////////////////////////////////////////////////////////////////////
void HermiteCurveCV::
set_name(const char *name) {
if (_name != NULL) {
delete [] _name;
_name = NULL;
}
if (name != NULL) {
_name = new char[strlen(name)+1];
strcpy(_name, name);
}
set_name(const string &name) {
_name = name;
}
////////////////////////////////////////////////////////////////////
// Function: HermiteCurveCV::Output
// Function: HermiteCurveCV::format_egg
// Access: Public
// Description: Formats the CV for output to an egg file.
////////////////////////////////////////////////////////////////////
void HermiteCurveCV::
Output(ostream &out, int indent, int num_dimensions,
format_egg(ostream &out, int indent_level, int num_dimensions,
bool show_in, bool show_out,
double scale_in, double scale_out) const {
if (show_in) {
Indent(out, indent) << "<Vertex> {\n";
show_vec3(out, indent+2, _p - scale_in * _in / 3.0,
indent(out, indent_level) << "<Vertex> {\n";
show_vec3(out, indent_level + 2, _p - scale_in * _in / 3.0,
num_dimensions) << "\n";
Indent(out, indent) << "}\n";
indent(out, indent_level) << "}\n";
}
Indent(out, indent) << "<Vertex> {\n";
show_vec3(out, indent+2, _p, num_dimensions) << "\n";
indent(out, indent_level) << "<Vertex> {\n";
show_vec3(out, indent_level + 2, _p, num_dimensions) << "\n";
Indent(out, indent+2) << "<Char*> continuity-type { ";
indent(out, indent_level+2) << "<Scalar> continuity-type { ";
switch (_type) {
case HC_CUT:
out << "Cut";
@ -244,16 +220,49 @@ Output(ostream &out, int indent, int num_dimensions,
};
out << " }\n";
Indent(out, indent) << "}\n";
indent(out, indent_level) << "}\n";
if (show_out) {
Indent(out, indent) << "<Vertex> {\n";
show_vec3(out, indent+2, _p + scale_out * _out / 3.0,
indent(out, indent_level) << "<Vertex> {\n";
show_vec3(out, indent_level + 2, _p + scale_out * _out / 3.0,
num_dimensions) << "\n";
Indent(out, indent) << "}\n";
indent(out, indent_level) << "}\n";
}
}
////////////////////////////////////////////////////////////////////
// Function: HermiteCurveCV::write_datagram
// Access: Public
// Description: Function to write the important information in
// the particular object to a Datagram
////////////////////////////////////////////////////////////////////
void HermiteCurveCV::
write_datagram(BamWriter *, Datagram &me) const {
_p.write_datagram(me);
_in.write_datagram(me);
_out.write_datagram(me);
me.add_int8(_type);
me.add_string(_name);
}
////////////////////////////////////////////////////////////////////
// Function: HermiteCurveCV::fillin
// Access: Public
// Description: Function that reads out of the datagram (or asks
// manager to read) all of the data that is needed to
// re-create this object and stores it in the appropiate
// place
////////////////////////////////////////////////////////////////////
void HermiteCurveCV::
fillin(DatagramIterator &scan, BamReader *) {
_p.read_datagram(scan);
_in.read_datagram(scan);
_out.read_datagram(scan);
_type = scan.get_int8();
_name = scan.get_string();
}
////////////////////////////////////////////////////////////////////
// Function: HermiteCurve::Constructor
// Access: Public, Scheme
@ -634,10 +643,10 @@ get_cv_tstart(int n) const {
// Access: Public, Scheme
// Description: Returns the name of the given CV, or NULL.
////////////////////////////////////////////////////////////////////
const char *HermiteCurve::
string HermiteCurve::
get_cv_name(int n) const {
if (n < 0 || n >= (int)_points.size()) {
return NULL;
return string();
}
return _points[n]._name;
@ -645,47 +654,44 @@ get_cv_name(int n) const {
////////////////////////////////////////////////////////////////////
// Function: HermiteCurve::Print
// Access: Public, Scheme
// Function: HermiteCurve::output
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
void HermiteCurve::
Print() const {
ostream& out = parametrics_cat->info();
output(ostream &out) const {
PiecewiseCurve::output(out);
out << " (";
switch (get_curve_type()) {
case PCT_T:
out << "Time-warping ";
out << "in T, ";
break;
case PCT_XYZ:
out << "XYZ ";
out << "in XYZ, ";
break;
case PCT_HPR:
out << "HPR ";
out << "in HPR, ";
break;
default:
break;
}
out
<< "HermiteCurve, " << get_num_cvs() << " CV's. t ranges from 0 to "
<< get_max_t()
<< endl;
out << get_num_cvs() << " CV's)";
}
////////////////////////////////////////////////////////////////////
// Function: HermiteCurve::print_cv
// Function: HermiteCurve::write_cv
// Access: Public, Scheme
// Description:
////////////////////////////////////////////////////////////////////
void HermiteCurve::
print_cv(int n) const {
ostream& out = parametrics_cat->info();
write_cv(ostream &out, int n) const {
out << "CV";
if (get_cv_name(n)!=NULL) {
if (!get_cv_name(n).empty()) {
out << " " << get_cv_name(n);
}
@ -715,7 +721,7 @@ print_cv(int n) const {
break;
}
out << "\n" << endl;
out << "\n";
}
@ -745,7 +751,7 @@ write_egg(const char *filename) {
////////////////////////////////////////////////////////////////////
bool HermiteCurve::
write_egg(ostream &out, const char *basename) {
if (get_name().empty()) {
if (!has_name()) {
// If we don't have a name, come up with one.
int len = strlen(basename);
if (len>4 && strcmp(basename+len-4, ".egg")==0) {
@ -774,7 +780,7 @@ write_egg(ostream &out, const char *basename) {
set_name(name);
}
Output(out);
format_egg(out);
if (out) {
return true;
@ -802,30 +808,30 @@ rebuild_curveseg(int, double, const LVecBase4f &,
}
////////////////////////////////////////////////////////////////////
// Function: HermiteCurve::Output
// Function: HermiteCurve::format_egg
// Access: Public
// Description: Formats the Hermite curve for output to an Egg file.
////////////////////////////////////////////////////////////////////
void HermiteCurve::
Output(ostream &out, int indent) const {
Indent(out, indent)
format_egg(ostream &out, int indent_level) const {
indent(out, indent_level)
<< "<VertexPool> " << get_name() << ".pool {\n";
int i;
for (i = 0; i < (int)_points.size(); i++) {
bool show_in = (i != 0);
bool show_out = (i != (int)_points.size()-1);
_points[i].Output(out, indent+2, _num_dimensions,
_points[i].format_egg(out, indent_level + 2, _num_dimensions,
show_in, show_out,
show_in ? get_tlength(i-1) : 0.0,
show_out ? get_tlength(i) : 0.0);
}
Indent(out, indent) << "}\n";
indent(out, indent_level) << "}\n";
Indent(out, indent) << "<BezierCurve> " << get_name() << " {\n";
indent(out, indent_level) << "<BezierCurve> " << get_name() << " {\n";
if (_curve_type!=PCT_NONE) {
Indent(out, indent+2) << "<Char*> type { ";
indent(out, indent_level+2) << "<Scalar> type { ";
switch (_curve_type) {
case PCT_XYZ:
out << "XYZ";
@ -842,32 +848,32 @@ Output(ostream &out, int indent) const {
out << " }\n";
}
Indent(out, indent+2) << "<TLengths> {";
indent(out, indent_level+2) << "<TLengths> {";
if (_points.size() > 1) {
for (i = 0; i < (int)_segs.size(); i++) {
if (i%10 == 1) {
out << "\n";
Indent(out, indent+3);
indent(out, indent_level+3);
}
out << " " << get_tlength(i);
}
}
out << "\n";
Indent(out, indent+2) << "}\n";
indent(out, indent_level+2) << "}\n";
Indent(out, indent+2) << "<VertexRef> {";
indent(out, indent_level+2) << "<VertexRef> {";
for (i = 1; i <= (int)_points.size() * 3 - 2; i++) {
if (i%10 == 1) {
out << "\n";
Indent(out, indent+3);
indent(out, indent_level+3);
}
out << " " << i;
}
out << "\n";
Indent(out, indent+4) << "<Ref> { " << get_name() << ".pool }\n";
Indent(out, indent+2) << "}\n";
indent(out, indent_level+4) << "<Ref> { " << get_name() << ".pool }\n";
indent(out, indent_level+2) << "}\n";
Indent(out, indent) << "}\n";
indent(out, indent_level) << "}\n";
}
@ -978,3 +984,71 @@ recompute_basis() {
}
}
////////////////////////////////////////////////////////////////////
// Function: HermiteCurve::register_with_factory
// Access: Public, Static
// Description: Initializes the factory for reading these things from
// Bam files.
////////////////////////////////////////////////////////////////////
void HermiteCurve::
register_with_read_factory() {
BamReader::get_factory()->register_factory(get_class_type(), make_HermiteCurve);
}
////////////////////////////////////////////////////////////////////
// Function: HermiteCurve::make_HermiteCurve
// Access: Protected
// Description: Factory method to generate an object of this type.
////////////////////////////////////////////////////////////////////
TypedWriteable *HermiteCurve::
make_HermiteCurve(const FactoryParams &params) {
HermiteCurve *me = new HermiteCurve;
BamReader *manager;
Datagram packet;
parse_params(params, manager, packet);
DatagramIterator scan(packet);
me->fillin(scan, manager);
return me;
}
////////////////////////////////////////////////////////////////////
// Function: HermiteCurve::write_datagram
// Access: Protected, Virtual
// Description: Function to write the important information in
// the particular object to a Datagram
////////////////////////////////////////////////////////////////////
void HermiteCurve::
write_datagram(BamWriter *manager, Datagram &me) {
PiecewiseCurve::write_datagram(manager, me);
me.add_uint32(_points.size());
size_t i;
for (i = 0; i < _points.size(); i++) {
_points[i].write_datagram(manager, me);
}
}
////////////////////////////////////////////////////////////////////
// Function: HermiteCurve::fillin
// Access: Protected
// Description: Function that reads out of the datagram (or asks
// manager to read) all of the data that is needed to
// re-create this object and stores it in the appropiate
// place
////////////////////////////////////////////////////////////////////
void HermiteCurve::
fillin(DatagramIterator &scan, BamReader *manager) {
PiecewiseCurve::fillin(scan, manager);
size_t num_points = scan.get_uint32();
_points.reserve(num_points);
size_t i;
for (i = 0; i < num_points; i++) {
HermiteCurveCV cv;
cv.fillin(scan, manager);
_points.push_back(cv);
}
}

View File

@ -68,15 +68,18 @@ public:
void set_in(const LVecBase3f &in);
void set_out(const LVecBase3f &out);
void set_type(int type);
void set_name(const char *name);
void set_name(const string &name);
void Output(ostream &out, int indent, int num_dimensions,
void format_egg(ostream &out, int indent, int num_dimensions,
bool show_in, bool show_out,
double scale_in, double scale_out) const;
void write_datagram(BamWriter *manager, Datagram &me) const;
void fillin(DatagramIterator &scan, BamReader *manager);
LVecBase3f _p, _in, _out;
int _type;
char *_name;
string _name;
};
////////////////////////////////////////////////////////////////////
@ -133,10 +136,10 @@ PUBLISHED:
const LVecBase3f &get_cv_out(int n) const;
void get_cv_out(int n, LVecBase3f &v) const;
double get_cv_tstart(int n) const;
const char *get_cv_name(int n) const;
string get_cv_name(int n) const;
void Print() const;
void print_cv(int n) const;
virtual void output(ostream &out) const;
void write_cv(ostream &out, int n) const;
bool write_egg(const char *filename);
bool write_egg(ostream &out, const char *basename);
@ -153,7 +156,7 @@ public:
int rtype2, double t2, const LVecBase4f &v2,
int rtype3, double t3, const LVecBase4f &v3);
void Output(ostream &out, int indent=0) const;
void format_egg(ostream &out, int indent=0) const;
protected:
@ -163,6 +166,15 @@ protected:
vector<HermiteCurveCV> _points;
// TypedWriteable stuff
public:
static void register_with_read_factory();
protected:
static TypedWriteable *make_HermiteCurve(const FactoryParams &params);
virtual void write_datagram(BamWriter *manager, Datagram &me);
void fillin(DatagramIterator &scan, BamReader *manager);
public:
static TypeHandle get_class_type() {
return _type_handle;

View File

@ -16,6 +16,10 @@
#include "config_parametrics.h"
#include <indent.h>
#include <datagram.h>
#include <datagramIterator.h>
#include <bamWriter.h>
#include <bamReader.h>
////////////////////////////////////////////////////////////////////
// Statics
@ -154,7 +158,7 @@ insert_cv(double t) {
t = 0.0;
}
int k = FindCV(t);
int k = find_cv(t);
if (k < 0) {
return append_cv(_cvs.back()._p);
}
@ -169,8 +173,8 @@ insert_cv(double t) {
int i;
for (i = 0; i < _order-1; i++) {
int nk = i + k - (_order-1);
double ti = GetKnot(nk);
double d = GetKnot(nk + _order-1) - ti;
double ti = get_knot(nk);
double d = get_knot(nk + _order-1) - ti;
if (d == 0.0) {
new_cvs[i] = _cvs[nk-1]._p;
} else {
@ -331,17 +335,6 @@ set_knot(int n, double t) {
return true;
}
////////////////////////////////////////////////////////////////////
// Function: NurbsCurve::get_knot
// Access: Public, Scheme
// Description: Returns the value of the indicated knot. There are
// get_num_cvs()+_order-1 knot values.
////////////////////////////////////////////////////////////////////
double NurbsCurve::
get_knot(int n) const {
return GetKnot(n);
}
////////////////////////////////////////////////////////////////////
// Function: NurbsCurve::write
// Access: Public, Scheme
@ -383,7 +376,7 @@ write(ostream &out, int indent_level) const {
indent(out, indent_level)
<< "Knots: ";
for (i = 0; i < (int)_cvs.size()+_order; i++) {
out << " " << GetKnot(i);
out << " " << get_knot(i);
}
out << "\n";
}
@ -424,7 +417,7 @@ recompute() {
if ((int)_cvs.size() > _order-1) {
for (int cv = 0; cv < (int)_cvs.size()-(_order-1); cv++) {
if (GetKnot(cv+_order-1) < GetKnot(cv+_order)) {
if (get_knot(cv+_order-1) < get_knot(cv+_order)) {
// There are _order consecutive CV's that define each segment,
// beginning at cv. Collect the CV's and knot values that define
// this segment.
@ -433,7 +426,7 @@ recompute() {
cvs[c] = _cvs[c+cv]._p;
}
for (c = 0; c < _order+_order; c++) {
knots[c] = GetKnot(c+cv);
knots[c] = get_knot(c+cv);
}
insert_curveseg(_segs.size(), new CubicCurveseg(_order, knots, cvs),
@ -511,7 +504,7 @@ adjust_pt(double t,
int cv = 0;
for (cv = 0; cv < _cvs.size()-(_order-1); cv++) {
if (GetKnot(cv+_order-1) < GetKnot(cv+_order)) {
if (get_knot(cv+_order-1) < get_knot(cv+_order)) {
if (seg == _last_ti) {
break;
}
@ -528,7 +521,7 @@ adjust_pt(double t,
cvs[c] = (c < _order) ? _cvs[c+cv]._p : LVecBase4f(0.0, 0.0, 0.0, 0.0);
}
for (c = 0; c < _order+_order; c++) {
knots[c] = GetKnot(c+cv);
knots[c] = get_knot(c+cv);
}
dnassert(_order>=1 && _order<=4);
@ -620,7 +613,7 @@ rebuild_curveseg(int rtype0, double t0, const LVecBase4f &v0,
int cv = 0;
for (cv = 0; cv < (int)_cvs.size()-(_order-1); cv++) {
if (GetKnot(cv+_order-1) < GetKnot(cv+_order)) {
if (get_knot(cv+_order-1) < get_knot(cv+_order)) {
if (seg == _last_ti) {
break;
}
@ -647,7 +640,7 @@ rebuild_curveseg(int rtype0, double t0, const LVecBase4f &v0,
// But we always need the knot vector to determine the basis matrix.
for (c = 0; c < _order+_order; c++) {
knots[c] = GetKnot(c+cv);
knots[c] = get_knot(c+cv);
}
LMatrix4f B;
@ -876,7 +869,7 @@ format_egg(ostream &out, CoordinateSystem cs, int indent_level) const {
out << "\n";
indent(out, indent_level+4);
}
out << GetKnot(k) << " ";
out << get_knot(k) << " ";
}
out << "\n";
indent(out, indent_level+2) << "}\n";
@ -898,13 +891,13 @@ format_egg(ostream &out, CoordinateSystem cs, int indent_level) const {
}
////////////////////////////////////////////////////////////////////
// Function: NurbsCurve::FindCV
// Function: NurbsCurve::find_cv
// Access: Protected
// Description: Finds the first knot whose value is >= t, or -1 if t
// is beyond the end of the curve.
////////////////////////////////////////////////////////////////////
int NurbsCurve::
FindCV(double t) {
find_cv(double t) {
int i;
for (i = _order-1; i < (int)_cvs.size(); i++) {
if (_cvs[i]._t >= t) {
@ -914,3 +907,79 @@ FindCV(double t) {
return -1;
}
////////////////////////////////////////////////////////////////////
// Function: NurbsCurve::register_with_factory
// Access: Public, Static
// Description: Initializes the factory for reading these things from
// Bam files.
////////////////////////////////////////////////////////////////////
void NurbsCurve::
register_with_read_factory() {
BamReader::get_factory()->register_factory(get_class_type(), make_NurbsCurve);
}
////////////////////////////////////////////////////////////////////
// Function: NurbsCurve::make_NurbsCurve
// Access: Protected
// Description: Factory method to generate an object of this type.
////////////////////////////////////////////////////////////////////
TypedWriteable *NurbsCurve::
make_NurbsCurve(const FactoryParams &params) {
NurbsCurve *me = new NurbsCurve;
BamReader *manager;
Datagram packet;
parse_params(params, manager, packet);
DatagramIterator scan(packet);
me->fillin(scan, manager);
return me;
}
////////////////////////////////////////////////////////////////////
// Function: NurbsCurve::write_datagram
// Access: Protected, Virtual
// Description: Function to write the important information in
// the particular object to a Datagram
////////////////////////////////////////////////////////////////////
void NurbsCurve::
write_datagram(BamWriter *manager, Datagram &me) {
PiecewiseCurve::write_datagram(manager, me);
me.add_int8(_order);
me.add_uint32(_cvs.size());
size_t i;
for (i = 0; i < _cvs.size(); i++) {
const CV &cv = _cvs[i];
cv._p.write_datagram(me);
me.add_float64(cv._t);
}
}
////////////////////////////////////////////////////////////////////
// Function: NurbsCurve::fillin
// Access: Protected
// Description: Function that reads out of the datagram (or asks
// manager to read) all of the data that is needed to
// re-create this object and stores it in the appropiate
// place
////////////////////////////////////////////////////////////////////
void NurbsCurve::
fillin(DatagramIterator &scan, BamReader *manager) {
PiecewiseCurve::fillin(scan, manager);
_order = scan.get_int8();
size_t num_cvs = scan.get_uint32();
_cvs.reserve(num_cvs);
size_t i;
for (i = 0; i < num_cvs; i++) {
CV cv;
cv._p.read_datagram(scan);
cv._t = scan.get_float64();
_cvs.push_back(cv);
}
}

View File

@ -67,7 +67,7 @@ PUBLISHED:
return append_cv(LVecBase4f(v[0], v[1], v[2], 1.0));
}
inline int append_cv(const LVecBase4f &v) {
_cvs.push_back(CV(v, GetKnot(_cvs.size())+1.0));
_cvs.push_back(CV(v, get_knot(_cvs.size())+1.0));
return _cvs.size()-1;
}
@ -85,7 +85,15 @@ PUBLISHED:
float get_cv_weight(int n) const;
bool set_knot(int n, double t);
double get_knot(int n) const;
double get_knot(int n) const {
if (n < _order || _cvs.empty()) {
return 0.0;
} else if (n-1 >= (int)_cvs.size()) {
return _cvs.back()._t;
} else {
return _cvs[n-1]._t;
}
}
virtual void write(ostream &out, int indent_level = 0) const;
void write_cv(ostream &out, int n) const;
@ -113,21 +121,10 @@ public:
return (CubicCurveseg *)PiecewiseCurve::get_curveseg(ti);
}
double
GetKnot(int n) const {
if (n < _order || _cvs.empty()) {
return 0.0;
} else if (n-1 >= (int)_cvs.size()) {
return _cvs.back()._t;
} else {
return _cvs[n-1]._t;
}
}
void format_egg(ostream &out, CoordinateSystem cs, int indent_level) const;
protected:
int FindCV(double t);
int find_cv(double t);
int _order;
@ -142,6 +139,15 @@ protected:
vector<CV> _cvs;
// TypedWriteable stuff
public:
static void register_with_read_factory();
protected:
static TypedWriteable *make_NurbsCurve(const FactoryParams &params);
virtual void write_datagram(BamWriter *manager, Datagram &me);
void fillin(DatagramIterator &scan, BamReader *manager);
public:
static TypeHandle get_class_type() {
return _type_handle;

View File

@ -125,11 +125,11 @@ draw() {
double lt = -1.0;
int ki = -1;
for (i = 0; i < _num_cvs; i++) {
double t = nurbs->GetKnot(i);
double t = nurbs->get_knot(i);
if (t != lt) {
lt = t;
LVecBase3f knot_pos, knot_tan;
nurbs->get_pt(nurbs->GetKnot(i), knot_pos, knot_tan);
nurbs->get_pt(nurbs->get_knot(i), knot_pos, knot_tan);
_knots.move_to(_mapper(knot_pos, knot_tan, t));
ki++;
}
@ -143,7 +143,7 @@ draw() {
_num_cvs = nurbs->get_num_cvs();
for (i = 0; i < _num_cvs; i++) {
_cvs.move_to(_mapper(nurbs->get_cv_point(i), LVecBase3f(0.0, 0.0, 0.0),
nurbs->GetKnot(i+1)));
nurbs->get_knot(i+1)));
}
_cvs.create(_geom_node, _frame_accurate);
@ -153,7 +153,7 @@ draw() {
_num_cvs = nurbs->get_num_cvs();
for (i = 0; i < _num_cvs; i++) {
_hull.draw_to(_mapper(nurbs->get_cv_point(i), LVecBase3f(0.0, 0.0, 0.0),
nurbs->GetKnot(i+1)));
nurbs->get_knot(i+1)));
}
_hull.create(_geom_node, _frame_accurate);