Panda3D

nurbsCurveEvaluator.I

00001 // Filename: nurbsCurveEvaluator.I
00002 // Created by:  drose (05Dec02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: NurbsCurveEvaluator::set_order
00018 //       Access: Published
00019 //  Description: Sets the order of the curve.  This resets the knot
00020 //               vector to the default knot vector for the number of
00021 //               vertices.
00022 //
00023 //               The order must be 1, 2, 3, or 4, and the value is one
00024 //               more than the degree of the curve.
00025 ////////////////////////////////////////////////////////////////////
00026 INLINE void NurbsCurveEvaluator::
00027 set_order(int order) {
00028   _order = order;
00029   _knots_dirty = true;
00030   _basis_dirty = true;
00031 }
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //     Function: NurbsCurveEvaluator::get_order
00035 //       Access: Published
00036 //  Description: Returns the order of the curve as set by a previous
00037 //               call to set_order().
00038 ////////////////////////////////////////////////////////////////////
00039 INLINE int NurbsCurveEvaluator::
00040 get_order() const {
00041   return _order;
00042 }
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //     Function: NurbsCurveEvaluator::get_num_vertices
00046 //       Access: Published
00047 //  Description: Returns the number of control vertices in the curve.
00048 //               This is the number passed to the last call to
00049 //               reset().
00050 ////////////////////////////////////////////////////////////////////
00051 INLINE int NurbsCurveEvaluator::
00052 get_num_vertices() const {
00053   return (int)_vertices.size();
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: NurbsCurveEvaluator::set_vertex
00058 //       Access: Published
00059 //  Description: Sets the nth control vertex of the curve, as a vertex
00060 //               in 4-d homogeneous space.  In this form, the first
00061 //               three components of the vertex should already have
00062 //               been scaled by the fourth component, which is the
00063 //               homogeneous weight.
00064 ////////////////////////////////////////////////////////////////////
00065 INLINE void NurbsCurveEvaluator::
00066 set_vertex(int i, const LVecBase4 &vertex) {
00067   nassertv(i >= 0 && i < (int)_vertices.size());
00068   _vertices[i].set_vertex(vertex);
00069 }
00070 
00071 ////////////////////////////////////////////////////////////////////
00072 //     Function: NurbsCurveEvaluator::set_vertex
00073 //       Access: Published
00074 //  Description: Sets the nth control vertex of the curve.  This
00075 //               flavor sets the vertex as a 3-d coordinate and a
00076 //               weight; the 3-d coordinate values are implicitly
00077 //               scaled up by the weight factor.
00078 ////////////////////////////////////////////////////////////////////
00079 INLINE void NurbsCurveEvaluator::
00080 set_vertex(int i, const LVecBase3 &vertex, PN_stdfloat weight) {
00081   nassertv(i >= 0 && i < (int)_vertices.size());
00082   _vertices[i].set_vertex(LVecBase4(vertex[0] * weight, vertex[1] * weight, vertex[2] * weight, weight));
00083 }
00084 
00085 ////////////////////////////////////////////////////////////////////
00086 //     Function: NurbsCurveEvaluator::get_vertex
00087 //       Access: Published
00088 //  Description: Returns the nth control vertex of the curve, relative
00089 //               to its indicated coordinate space.
00090 ////////////////////////////////////////////////////////////////////
00091 INLINE const LVecBase4 &NurbsCurveEvaluator::
00092 get_vertex(int i) const {
00093   nassertr(i >= 0 && i < (int)_vertices.size(), LVecBase4::zero());
00094   return _vertices[i].get_vertex();
00095 }
00096 
00097 ////////////////////////////////////////////////////////////////////
00098 //     Function: NurbsCurveEvaluator::get_vertex
00099 //       Access: Published
00100 //  Description: Returns the nth control vertex of the curve, relative
00101 //               to the given coordinate space.
00102 ////////////////////////////////////////////////////////////////////
00103 INLINE LVecBase4 NurbsCurveEvaluator::
00104 get_vertex(int i, const NodePath &rel_to) const {
00105   nassertr(i >= 0 && i < (int)_vertices.size(), LVecBase4::zero());
00106 
00107   NodePath space = _vertices[i].get_space(rel_to);
00108   const LVecBase4 &vertex = _vertices[i].get_vertex();
00109   if (space.is_empty()) {
00110     return vertex;
00111   } else {
00112     const LMatrix4 &mat = space.get_mat(rel_to);
00113     return vertex * mat;
00114   }
00115 }
00116 
00117 ////////////////////////////////////////////////////////////////////
00118 //     Function: NurbsCurveEvaluator::set_vertex_space
00119 //       Access: Published
00120 //  Description: Sets the coordinate space of the nth control vertex.
00121 //               If this is not specified, or is set to an empty
00122 //               NodePath, the nth control vertex is deemed to be in
00123 //               the coordinate space passed to evaluate().
00124 //
00125 //               This specifies the space as a fixed NodePath, which
00126 //               is always the same NodePath.  Also see setting the
00127 //               space as a path string, which can specify a different
00128 //               NodePath for different instances of the curve.
00129 ////////////////////////////////////////////////////////////////////
00130 INLINE void NurbsCurveEvaluator::
00131 set_vertex_space(int i, const NodePath &space) {
00132   nassertv(i >= 0 && i < (int)_vertices.size());
00133   _vertices[i].set_space(space);
00134 }
00135 
00136 ////////////////////////////////////////////////////////////////////
00137 //     Function: NurbsCurveEvaluator::set_vertex_space
00138 //       Access: Published
00139 //  Description: Sets the coordinate space of the nth control vertex.
00140 //               If this is not specified, or is set to an empty
00141 //               string, the nth control vertex is deemed to be in
00142 //               the coordinate space passed to evaluate().
00143 //
00144 //               This specifies the space as a string, which describes
00145 //               the path to find the node relative to the rel_to
00146 //               NodePath when the curve is evaluated.
00147 ////////////////////////////////////////////////////////////////////
00148 INLINE void NurbsCurveEvaluator::
00149 set_vertex_space(int i, const string &space) {
00150   nassertv(i >= 0 && i < (int)_vertices.size());
00151   _vertices[i].set_space(space);
00152 }
00153 
00154 ////////////////////////////////////////////////////////////////////
00155 //     Function: NurbsCurveEvaluator::set_extended_vertex
00156 //       Access: Public
00157 //  Description: Sets an n-dimensional vertex value.  This allows
00158 //               definition of a NURBS surface or curve in a sparse
00159 //               n-dimensional space, typically used for associating
00160 //               additional properties (like color or joint
00161 //               membership) with each vertex of a surface.
00162 //
00163 //               The value d is an arbitrary integer value and
00164 //               specifies the dimension of question for this
00165 //               particular vertex.  Any number of dimensions may be
00166 //               specified, and they need not be consecutive.  If a
00167 //               value for a given dimension is not specified, is it
00168 //               implicitly 0.0.
00169 //
00170 //               The value is implicitly scaled by the homogenous
00171 //               weight value--that is, the fourth component of the
00172 //               value passed to set_vertex().  This means the
00173 //               ordinary vertex must be set first, before the
00174 //               extended vertices can be set.
00175 ////////////////////////////////////////////////////////////////////
00176 INLINE void NurbsCurveEvaluator::
00177 set_extended_vertex(int i, int d, PN_stdfloat value) {
00178   nassertv(i >= 0 && i < (int)_vertices.size());
00179   _vertices[i].set_extended_vertex(d, value);
00180 }
00181 
00182 ////////////////////////////////////////////////////////////////////
00183 //     Function: NurbsCurveEvaluator::get_extended_vertex
00184 //       Access: Public
00185 //  Description: Returns an n-dimensional vertex value.  See
00186 //               set_extended_vertex().  This returns the value set
00187 //               for the indicated dimension, or 0.0 if nothing has
00188 //               been set.
00189 ////////////////////////////////////////////////////////////////////
00190 INLINE PN_stdfloat NurbsCurveEvaluator::
00191 get_extended_vertex(int i, int d) const {
00192   nassertr(i >= 0 && i < (int)_vertices.size(), 0.0f);
00193   return _vertices[i].get_extended_vertex(d);
00194 }
00195 
00196 ////////////////////////////////////////////////////////////////////
00197 //     Function: NurbsCurveEvaluator::get_num_knots
00198 //       Access: Published
00199 //  Description: Returns the number of knot values in the curve.  This
00200 //               is based on the number of vertices and the order.
00201 ////////////////////////////////////////////////////////////////////
00202 INLINE int NurbsCurveEvaluator::
00203 get_num_knots() const {
00204   return (int)_vertices.size() + _order;
00205 }
00206 
00207 ////////////////////////////////////////////////////////////////////
00208 //     Function: NurbsCurveEvaluator::get_num_segments
00209 //       Access: Published
00210 //  Description: Returns the number of piecewise continuous segments
00211 //               in the curve.  This is based on the knot vector.
00212 ////////////////////////////////////////////////////////////////////
00213 INLINE int NurbsCurveEvaluator::
00214 get_num_segments() const {
00215   if (_basis_dirty) {
00216     ((NurbsCurveEvaluator *)this)->recompute_basis();
00217   }
00218   return _basis.get_num_segments();
00219 }
00220 
00221 INLINE ostream &
00222 operator << (ostream &out, const NurbsCurveEvaluator &n) {
00223   n.output(out);
00224   return out;
00225 }
 All Classes Functions Variables Enumerations