Panda3D
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
ParametricCurve Class Reference

A virtual base class for parametric curves. More...

#include "parametricCurve.h"

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

List of all members.

Classes

struct  BezierSeg

Public Types

typedef pvector< BezierSegBezierSegs

Public Member Functions

 ParametricCurve ()
 This is a virtual base class.
virtual bool adjust_point (PN_stdfloat t, PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz)
 Recomputes the curve such that it passes through the point (px, py, pz) at time t, but keeps the same tangent value at that point.
virtual bool adjust_pt (PN_stdfloat t, PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz, PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz)
 Recomputes the curve such that it passes through the point (px, py, pz) with the tangent (tx, ty, tz).
virtual bool adjust_tangent (PN_stdfloat t, PN_stdfloat tx, PN_stdfloat ty, PN_stdfloat tz)
 Recomputes the curve such that it has the tangent (tx, ty, tz) at time t, but keeps the same position at the point.
PN_stdfloat calc_length () const
 Approximates the length of the entire curve to within a few decimal places.
PN_stdfloat calc_length (PN_stdfloat from, PN_stdfloat to) const
 Approximates the length of the curve segment from parametric time 'from' to time 'to'.
virtual bool convert_to_hermite (HermiteCurve *hc) const
 Stores an equivalent curve representation in the indicated Hermite curve, if possible.
virtual bool convert_to_nurbs (ParametricCurve *nc) const
 Stores in the indicated NurbsCurve a NURBS representation of an equivalent curve.
PN_stdfloat find_length (PN_stdfloat start_t, PN_stdfloat length_offset) const
 Returns the parametric value corresponding to the indicated distance along the curve from the starting parametric value.
virtual TypeHandle force_init_type ()
virtual bool get_2ndtangent (PN_stdfloat t, LVecBase3 &tangent2) const =0
virtual bool get_bezier_seg (BezierSeg &) const
 Fills the BezierSeg structure with a description of the curve segment as a Bezier, if possible, but does not change the _t member of the structure.
virtual bool get_bezier_segs (BezierSegs &) const
 Fills up the indicated vector with a list of BezierSeg structs that describe the curve.
int get_curve_type () const
 Returns the flag indicating the use to which the curve is intended to be put.
virtual PN_stdfloat get_max_t () const
 Returns the upper bound of t for the entire curve.
int get_num_dimensions () const
 Returns the number of significant dimensions in the curve's vertices, as set by a previous call to set_num_dimensions().
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 bool get_point (PN_stdfloat t, LVecBase3 &point) const =0
virtual bool get_pt (PN_stdfloat t, LVecBase3 &point, LVecBase3 &tangent) const =0
virtual bool get_tangent (PN_stdfloat t, LVecBase3 &tangent) const =0
virtual TypeHandle get_type () const
virtual bool is_valid () const
 Returns true if the curve is defined.
virtual bool recompute ()
 Recalculates the curve, if necessary.
void register_drawer (ParametricCurveDrawer *drawer)
 Registers a Drawer with this curve that will automatically be updated whenever the curve is modified, so that the visible representation of the curve is kept up to date.
virtual bool safe_to_flatten () const
 Returns true if it is generally safe to flatten out this particular kind of PandaNode by duplicating instances, false otherwise (for instance, a Camera cannot be safely flattened, because the Camera pointer itself is meaningful).
virtual bool safe_to_transform () const
 Returns true if it is generally safe to transform this particular kind of PandaNode by calling the xform() method, false otherwise.
void set_curve_type (int type)
 Sets the flag indicating the use to which the curve is intended to be put.
void set_num_dimensions (int num)
 Specifies the number of significant dimensions in the curve's vertices.
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.
void unregister_drawer (ParametricCurveDrawer *drawer)
 Removes a previously registered drawer from the list of automatically-refreshed drawers.
bool write_egg (Filename filename, CoordinateSystem cs=CS_default)
 Writes an egg description of the nurbs curve to the specified output file.
bool write_egg (ostream &out, const Filename &filename, CoordinateSystem cs)
 Writes an egg description of the nurbs curve to the specified output stream.

Static Public Member Functions

static TypeHandle get_class_type ()
static void init_type ()

Protected Member Functions

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.
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.
void invalidate (PN_stdfloat t1, PN_stdfloat t2)
 Called from a base class to mark a section of the curve that has been modified and must be redrawn or recomputed in some way.
void invalidate_all ()
 Called from a base class to indicate that the curve has changed in some substantial way and must be entirely redrawn.
virtual void write_datagram (BamWriter *manager, Datagram &me)
 Function to write the important information in the particular object to a Datagram.

Protected Attributes

int _curve_type
int _num_dimensions

Detailed Description

A virtual base class for parametric curves.

This encapsulates all curves in 3-d space defined for a single parameter t in the range [0,get_max_t()].

Definition at line 60 of file parametricCurve.h.


Constructor & Destructor Documentation

This is a virtual base class.

Don't try to construct one from Scheme.

Definition at line 38 of file parametricCurve.cxx.


Member Function Documentation

bool ParametricCurve::adjust_point ( PN_stdfloat  t,
PN_stdfloat  px,
PN_stdfloat  py,
PN_stdfloat  pz 
) [virtual]

Recomputes the curve such that it passes through the point (px, py, pz) at time t, but keeps the same tangent value at that point.

Reimplemented in PiecewiseCurve.

Definition at line 300 of file parametricCurve.cxx.

Referenced by ParametricCurveCollection::adjust_hpr(), and ParametricCurveCollection::adjust_xyz().

bool ParametricCurve::adjust_pt ( PN_stdfloat  t,
PN_stdfloat  px,
PN_stdfloat  py,
PN_stdfloat  pz,
PN_stdfloat  tx,
PN_stdfloat  ty,
PN_stdfloat  tz 
) [virtual]

Recomputes the curve such that it passes through the point (px, py, pz) with the tangent (tx, ty, tz).

Reimplemented in PiecewiseCurve.

Definition at line 323 of file parametricCurve.cxx.

bool ParametricCurve::adjust_tangent ( PN_stdfloat  t,
PN_stdfloat  tx,
PN_stdfloat  ty,
PN_stdfloat  tz 
) [virtual]

Recomputes the curve such that it has the tangent (tx, ty, tz) at time t, but keeps the same position at the point.

Reimplemented in PiecewiseCurve.

Definition at line 312 of file parametricCurve.cxx.

PN_stdfloat ParametricCurve::calc_length ( ) const

Approximates the length of the entire curve to within a few decimal places.

Definition at line 194 of file parametricCurve.cxx.

References get_max_t().

Referenced by ParametricCurveCollection::make_even().

PN_stdfloat ParametricCurve::calc_length ( PN_stdfloat  from,
PN_stdfloat  to 
) const

Approximates the length of the curve segment from parametric time 'from' to time 'to'.

Definition at line 205 of file parametricCurve.cxx.

bool ParametricCurve::convert_to_hermite ( HermiteCurve hc) const [virtual]
bool ParametricCurve::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 in NurbsCurve.

Definition at line 576 of file parametricCurve.cxx.

References get_bezier_segs(), get_nurbs_interface(), recompute(), and set_curve_type().

Referenced by NurbsCurve::NurbsCurve().

void ParametricCurve::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 PandaNode.

Reimplemented in HermiteCurve, CubicCurveseg, NurbsCurve, and PiecewiseCurve.

Definition at line 999 of file parametricCurve.cxx.

References DatagramIterator::get_int8().

PN_stdfloat ParametricCurve::find_length ( PN_stdfloat  start_t,
PN_stdfloat  length_offset 
) const

Returns the parametric value corresponding to the indicated distance along the curve from the starting parametric value.

This is the inverse of calc_length(): rather than determining the length along the curve between two parametric points, it determines the position in parametric time of a point n units along the curve.

The search distance must not be negative.

Definition at line 253 of file parametricCurve.cxx.

References get_max_t().

Referenced by ParametricCurveCollection::make_even().

bool ParametricCurve::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 in HermiteCurve, and NurbsCurve.

Definition at line 698 of file parametricCurve.cxx.

Referenced by write_egg().

Fills the BezierSeg structure with a description of the curve segment as a Bezier, if possible, but does not change the _t member of the structure.

Returns true if successful, false otherwise.

Reimplemented in CubicCurveseg.

Definition at line 479 of file parametricCurve.cxx.

bool ParametricCurve::get_bezier_segs ( ParametricCurve::BezierSegs &  ) const [virtual]

Fills up the indicated vector with a list of BezierSeg structs that describe the curve.

This assumes the curve is a PiecewiseCurve of CubicCurvesegs. Returns true if successful, false otherwise.

Reimplemented in PiecewiseCurve.

Definition at line 466 of file parametricCurve.cxx.

Referenced by convert_to_hermite(), and convert_to_nurbs().

PN_stdfloat ParametricCurve::get_max_t ( ) const [virtual]

Returns the upper bound of t for the entire curve.

The curve is defined in the range 0.0f <= t <= get_max_t(). This base class function always returns 1.0f; derived classes might override this to return something else.

Reimplemented in PiecewiseCurve.

Definition at line 107 of file parametricCurve.cxx.

Referenced by calc_length(), find_length(), and ParametricCurveCollection::make_even().

Returns the number of significant dimensions in the curve's vertices, as set by a previous call to set_num_dimensions().

This is only a hint as to how the curve is intended to be used; the actual number of dimensions of any curve is always three.

Definition at line 182 of file parametricCurve.cxx.

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

Reimplemented in NurbsCurve.

Definition at line 491 of file parametricCurve.cxx.

Referenced by NurbsCurveInterface::convert_to_nurbs(), and convert_to_nurbs().

void ParametricCurve::invalidate ( PN_stdfloat  t1,
PN_stdfloat  t2 
) [protected]

Called from a base class to mark a section of the curve that has been modified and must be redrawn or recomputed in some way.

Definition at line 667 of file parametricCurve.cxx.

References invalidate_all().

void ParametricCurve::invalidate_all ( ) [protected]

Called from a base class to indicate that the curve has changed in some substantial way and must be entirely redrawn.

Definition at line 679 of file parametricCurve.cxx.

Referenced by invalidate().

bool ParametricCurve::is_valid ( ) const [virtual]

Returns true if the curve is defined.

This base class function always returns true; derived classes might override this to sometimes return false.

Reimplemented in PiecewiseCurve.

Definition at line 92 of file parametricCurve.cxx.

Referenced by recompute().

bool ParametricCurve::recompute ( ) [virtual]

Recalculates the curve, if necessary.

Returns true if the resulting curve is valid, false otherwise.

Reimplemented in NurbsCurve.

Definition at line 335 of file parametricCurve.cxx.

References is_valid().

Referenced by NurbsCurveInterface::convert_to_nurbs(), convert_to_nurbs(), and ParametricCurveCollection::recompute().

void ParametricCurve::register_drawer ( ParametricCurveDrawer *  drawer)

Registers a Drawer with this curve that will automatically be updated whenever the curve is modified, so that the visible representation of the curve is kept up to date.

This is called automatically by the ParametricCurveDrawer.

Any number of Drawers may be registered with a particular curve.

Definition at line 640 of file parametricCurve.cxx.

Referenced by ParametricCurveCollection::register_drawer().

bool ParametricCurve::safe_to_flatten ( ) const [virtual]

Returns true if it is generally safe to flatten out this particular kind of PandaNode by duplicating instances, false otherwise (for instance, a Camera cannot be safely flattened, because the Camera pointer itself is meaningful).

Reimplemented from PandaNode.

Definition at line 67 of file parametricCurve.cxx.

bool ParametricCurve::safe_to_transform ( ) const [virtual]

Returns true if it is generally safe to transform this particular kind of PandaNode by calling the xform() method, false otherwise.

For instance, it's usually a bad idea to attempt to xform a Character.

Reimplemented from PandaNode.

Definition at line 80 of file parametricCurve.cxx.

void ParametricCurve::set_curve_type ( int  type)

Sets the flag indicating the use to which the curve is intended to be put.

This flag is optional and only serves to provide a hint to the egg reader and writer code; it has no effect on the curve's behavior.

Setting the curve type also sets the num_dimensions to 3 or 1 according to the type.

THis flag may have one of the values PCT_XYZ, PCT_HPR, or PCT_T.

Definition at line 128 of file parametricCurve.cxx.

Referenced by convert_to_hermite(), NurbsCurve::convert_to_nurbs(), convert_to_nurbs(), ParametricCurveCollection::make_even(), ParametricCurveCollection::reset_max_t(), and ParametricCurveCollection::stitch().

Specifies the number of significant dimensions in the curve's vertices.

This should be one of 1, 2, or 3. Normally, XYZ and HPR curves have three dimensions; time curves should always have one dimension. This only serves as a hint to the mopath editor, and also controls how the curve is written out.

Definition at line 168 of file parametricCurve.cxx.

bool ParametricCurve::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 in NurbsCurve.

Definition at line 350 of file parametricCurve.cxx.

void ParametricCurve::unregister_drawer ( ParametricCurveDrawer *  drawer)

Removes a previously registered drawer from the list of automatically-refreshed drawers.

This is called automatically by the ParametricCurveDrawer.

Definition at line 652 of file parametricCurve.cxx.

Referenced by ParametricCurveCollection::unregister_drawer().

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

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

Reimplemented from PandaNode.

Reimplemented in HermiteCurve, CubicCurveseg, NurbsCurve, and PiecewiseCurve.

Definition at line 983 of file parametricCurve.cxx.

References Datagram::add_int8().

bool ParametricCurve::write_egg ( Filename  filename,
CoordinateSystem  cs = CS_default 
)

Writes an egg description of the nurbs curve to the specified output file.

Returns true if the file is successfully written.

Definition at line 365 of file parametricCurve.cxx.

References Filename::open_write(), and Filename::set_text().

Referenced by ParametricCurveCollection::write_egg().

bool ParametricCurve::write_egg ( ostream &  out,
const Filename filename,
CoordinateSystem  cs 
)

Writes an egg description of the nurbs curve to the specified output stream.

Returns true if the file is successfully written.

Definition at line 385 of file parametricCurve.cxx.

References format_egg(), Filename::get_basename_wo_extension(), get_curve_type(), and Namable::has_name().


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