Panda3D
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes

NurbsCurve Class Reference

A Nonuniform Rational B-Spline. More...

#include "nurbsCurve.h"

Inheritance diagram for NurbsCurve:
PiecewiseCurve NurbsCurveInterface ParametricCurve PandaNode TypedWritable Namable LinkedListNode ReferenceCount TypedObject MemoryBase MemoryBase MemoryBase

List of all members.

Classes

class  CV

Public Member Functions

 NurbsCurve (const ParametricCurve &pc)
 Constructs a NURBS curve equivalent to the indicated (possibly non-NURBS) curve.
 NurbsCurve (int order, int num_cvs, const PN_stdfloat knots[], const LVecBase4 cvs[])
 Constructs a NURBS curve according to the indicated NURBS parameters.
virtual bool convert_to_nurbs (ParametricCurve *nc) const
 Stores in the indicated NurbsCurve a NURBS representation of an equivalent curve.
virtual TypeHandle force_init_type ()
CubicCurvesegget_curveseg (int ti)
 Returns the curve segment corresponding to the given index.
virtual LVecBase4 get_cv (int n) const
 Returns the position in homogeneous space of the indicated CV.
virtual PN_stdfloat get_knot (int n) const
 Retrieves the value of the indicated knot.
virtual int get_num_cvs () const
virtual int get_num_knots () const
 Returns the number of knots on the curve.
virtual NurbsCurveInterfaceget_nurbs_interface ()
 Returns a pointer to the object as a NurbsCurveInterface object if it happens to be a NURBS-style curve; otherwise, returns NULL.
virtual int get_order () const
virtual TypeHandle get_type () const
virtual bool insert_cv (PN_stdfloat t)
 Inserts a new CV into the middle of the curve at the indicated parametric value.
virtual PandaNodemake_copy () const
 Returns a newly-allocated PandaNode that is a shallow copy of this one.
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 the specified properties (see CubicCurveseg::compute_seg).
virtual bool recompute ()
 Recalculates the curve basis according to the latest position of the CV's, knots, etc.
virtual void remove_all_cvs ()
 Removes all CV's from the curve.
virtual bool remove_cv (int n)
 Removes the indicated CV from the curve.
virtual bool set_cv (int n, const LVecBase4 &v)
 Repositions the indicated CV.
virtual bool set_knot (int n, PN_stdfloat t)
 Sets the value of the indicated knot.
virtual void set_order (int order)
 Changes the order of the curve.
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.
virtual void write (ostream &out, int indent_level=0) const

Static Public Member Functions

static TypeHandle get_class_type ()
static void init_type ()
static void register_with_read_factory ()
 Initializes the factory for reading these things from Bam files.

Protected Member Functions

virtual int append_cv_impl (const LVecBase4 &v)
 Adds a new CV to the end of the curve.
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 re-create this object and stores it in the appropiate place.
int find_cv (PN_stdfloat t)
 Finds the first knot whose value is >= t, or -1 if t is beyond the end of the curve.
virtual bool format_egg (ostream &out, const string &name, const string &curve_type, int indent_level) const
 Formats the curve as an egg structure to write to the indicated stream.
virtual void write_datagram (BamWriter *manager, Datagram &me)
 Function to write the important information in the particular object to a Datagram.

Static Protected Member Functions

static TypedWritablemake_NurbsCurve (const FactoryParams &params)
 Factory method to generate an object of this type.

Protected Attributes

epvector< CV_cvs
int _order

Detailed Description

A Nonuniform Rational B-Spline.

This class is actually implemented as a PiecewiseCurve made up of several CubicCurvesegs, each of which is created using the nurbs_basis() method. The list of CV's and knots is kept here, within the NurbsCurve class.

This class is the original Panda-native implementation of a NURBS curve. It is typedeffed as "NurbsCurve" and performs all NURBS curve functions if we do not have the NURBS++ library available.

However, if we *do* have the NURBS++ library, another class exists, the NurbsPPCurve, which is a wrapper around that library and provides some additional functionality. In that case, the other class is typedeffed to "NurbsCurve" instead of this one, and performs most of the NURBS curve functions. This class then becomes vestigial.

Definition at line 47 of file nurbsCurve.h.


Constructor & Destructor Documentation

NurbsCurve::NurbsCurve ( const ParametricCurve pc)

Constructs a NURBS curve equivalent to the indicated (possibly non-NURBS) curve.

Definition at line 44 of file nurbsCurve.cxx.

References ParametricCurve::convert_to_nurbs().

NurbsCurve::NurbsCurve ( int  order,
int  num_cvs,
const PN_stdfloat  knots[],
const LVecBase4  cvs[] 
)

Constructs a NURBS curve according to the indicated NURBS parameters.

Definition at line 60 of file nurbsCurve.cxx.

References recompute(), and set_knot().


Member Function Documentation

int NurbsCurve::append_cv_impl ( const LVecBase4 v) [protected, virtual]

Adds a new CV to the end of the curve.

Creates a new knot value by adding 1 to the last knot value. Returns the index of the new CV.

Implements NurbsCurveInterface.

Definition at line 515 of file nurbsCurve.cxx.

References get_knot().

bool NurbsCurve::convert_to_nurbs ( ParametricCurve nc) const [virtual]

Stores in the indicated NurbsCurve a NURBS representation of an equivalent curve.

Returns true if successful, false otherwise.

Reimplemented from NurbsCurveInterface.

Definition at line 492 of file nurbsCurve.cxx.

References ParametricCurve::set_curve_type().

void NurbsCurve::fillin ( DatagramIterator scan,
BamReader manager 
) [protected, virtual]

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.

Reimplemented from PiecewiseCurve.

Definition at line 608 of file nurbsCurve.cxx.

References DatagramIterator::get_float64(), DatagramIterator::get_int8(), DatagramIterator::get_uint32(), and LVecBase4f::read_datagram().

Referenced by make_NurbsCurve().

int NurbsCurve::find_cv ( PN_stdfloat  t) [protected]

Finds the first knot whose value is >= t, or -1 if t is beyond the end of the curve.

Definition at line 540 of file nurbsCurve.cxx.

Referenced by insert_cv().

bool NurbsCurve::format_egg ( ostream &  out,
const string &  name,
const string &  curve_type,
int  indent_level 
) const [protected, virtual]

Formats the curve as an egg structure to write to the indicated stream.

Returns true on success, false on failure.

Reimplemented from NurbsCurveInterface.

Definition at line 528 of file nurbsCurve.cxx.

CubicCurveseg * NurbsCurve::get_curveseg ( int  ti) [inline]

Returns the curve segment corresponding to the given index.

Reimplemented from PiecewiseCurve.

Definition at line 22 of file nurbsCurve.I.

LVecBase4 NurbsCurve::get_cv ( int  n) const [virtual]

Returns the position in homogeneous space of the indicated CV.

Implements NurbsCurveInterface.

Definition at line 257 of file nurbsCurve.cxx.

References LVecBase4f::zero().

PN_stdfloat NurbsCurve::get_knot ( int  n) const [virtual]

Retrieves the value of the indicated knot.

Implements NurbsCurveInterface.

Definition at line 290 of file nurbsCurve.cxx.

Referenced by append_cv_impl(), insert_cv(), rebuild_curveseg(), and recompute().

int NurbsCurve::get_num_knots ( ) const [virtual]

Returns the number of knots on the curve.

Implements NurbsCurveInterface.

Definition at line 141 of file nurbsCurve.cxx.

Referenced by set_knot().

NurbsCurveInterface * NurbsCurve::get_nurbs_interface ( ) [virtual]

Returns a pointer to the object as a NurbsCurveInterface object if it happens to be a NURBS-style curve; otherwise, returns NULL.

Reimplemented from ParametricCurve.

Definition at line 480 of file nurbsCurve.cxx.

bool NurbsCurve::insert_cv ( PN_stdfloat  t) [virtual]

Inserts a new CV into the middle of the curve at the indicated parametric value.

This doesn't change the shape or timing of the curve; however, it is irreversible: if the new CV is immediately removed, the curve will be changed. Returns true if successful, false otherwise.

Implements NurbsCurveInterface.

Definition at line 158 of file nurbsCurve.cxx.

References find_cv(), and get_knot().

PandaNode * NurbsCurve::make_copy ( ) const [virtual]

Returns a newly-allocated PandaNode that is a shallow copy of this one.

It will be a different pointer, but its internal data may or may not be shared with that of the original PandaNode. No children will be copied.

Reimplemented from PandaNode.

Definition at line 97 of file nurbsCurve.cxx.

TypedWritable * NurbsCurve::make_NurbsCurve ( const FactoryParams params) [static, protected]

Factory method to generate an object of this type.

Definition at line 568 of file nurbsCurve.cxx.

References fillin().

Referenced by register_with_read_factory().

bool NurbsCurve::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 
) [virtual]

Rebuilds the current curve segment (as selected by the most recent call to find_curve()) according to the specified properties (see CubicCurveseg::compute_seg).

Returns true if possible, false if something goes horribly wrong.

Reimplemented from PiecewiseCurve.

Definition at line 351 of file nurbsCurve.cxx.

References CubicCurveseg::compute_seg(), LMatrix4f::get_col(), get_knot(), LMatrix4f::set_col(), and LVecBase4f::zero().

bool NurbsCurve::recompute ( ) [virtual]

Recalculates the curve basis according to the latest position of the CV's, knots, etc.

Until this function is called, adjusting the NURBS parameters will have no visible effect on the curve. Returns true if the resulting curve is valid, false otherwise.

Reimplemented from ParametricCurve.

Definition at line 312 of file nurbsCurve.cxx.

References get_knot(), and PiecewiseCurve::insert_curveseg().

Referenced by NurbsCurve(), and stitch().

void NurbsCurve::register_with_read_factory ( ) [static]

Initializes the factory for reading these things from Bam files.

Reimplemented from PandaNode.

Definition at line 558 of file nurbsCurve.cxx.

References BamReader::get_factory(), make_NurbsCurve(), and Factory< Type >::register_factory().

void NurbsCurve::remove_all_cvs ( ) [virtual]

Removes all CV's from the curve.

Implements NurbsCurveInterface.

Definition at line 231 of file nurbsCurve.cxx.

bool NurbsCurve::remove_cv ( int  n) [virtual]

Removes the indicated CV from the curve.

Returns true if the CV index was valid, false otherwise.

Implements NurbsCurveInterface.

Definition at line 216 of file nurbsCurve.cxx.

bool NurbsCurve::set_cv ( int  n,
const LVecBase4 v 
) [virtual]

Repositions the indicated CV.

Returns true if successful, false otherwise.

Implements NurbsCurveInterface.

Definition at line 243 of file nurbsCurve.cxx.

bool NurbsCurve::set_knot ( int  n,
PN_stdfloat  t 
) [virtual]

Sets the value of the indicated knot.

There are get_num_cvs() + _order knot values, but the first _order - 1 and the last 1 knot values cannot be changed. It is also an error to set a knot value outside the range of its neighbors.

Implements NurbsCurveInterface.

Definition at line 274 of file nurbsCurve.cxx.

References get_num_knots().

Referenced by NurbsCurve().

void NurbsCurve::set_order ( int  order) [virtual]

Changes the order of the curve.

Must be a value from 1 to 4. Can only be done when there are no cv's.

Implements NurbsCurveInterface.

Definition at line 108 of file nurbsCurve.cxx.

bool NurbsCurve::stitch ( const ParametricCurve a,
const ParametricCurve b 
) [virtual]

Regenerates this curve as one long curve: the first curve connected end-to-end with the second one.

Either a or b may be the same as 'this'.

Returns true if successful, false on failure or if the curve type does not support stitching.

Reimplemented from ParametricCurve.

Definition at line 425 of file nurbsCurve.cxx.

References recompute().

void NurbsCurve::write_datagram ( BamWriter manager,
Datagram me 
) [protected, virtual]

Function to write the important information in the particular object to a Datagram.

Reimplemented from PiecewiseCurve.

Definition at line 585 of file nurbsCurve.cxx.

References Datagram::add_float64(), Datagram::add_int8(), Datagram::add_uint32(), and LVecBase4f::write_datagram().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations