Panda3D

nurbsSurfaceEvaluator.I

00001 // Filename: nurbsSurfaceEvaluator.I
00002 // Created by:  drose (10Oct03)
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: NurbsSurfaceEvaluator::set_u_order
00018 //       Access: Published
00019 //  Description: Sets the order of the surface in the U direction.
00020 //               This resets the knot vector to the default knot
00021 //               vector for the number of vertices.
00022 //
00023 //               The order must be 1, 2, 3, or 4, and the value is one
00024 //               more than the degree of the surface.
00025 ////////////////////////////////////////////////////////////////////
00026 INLINE void NurbsSurfaceEvaluator::
00027 set_u_order(int u_order) {
00028   _u_order = u_order;
00029   _u_knots_dirty = true;
00030   _u_basis_dirty = true;
00031 }
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //     Function: NurbsSurfaceEvaluator::get_u_order
00035 //       Access: Published
00036 //  Description: Returns the order of the surface in the U direction
00037 //               as set by a previous call to set_u_order().
00038 ////////////////////////////////////////////////////////////////////
00039 INLINE int NurbsSurfaceEvaluator::
00040 get_u_order() const {
00041   return _u_order;
00042 }
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //     Function: NurbsSurfaceEvaluator::set_v_order
00046 //       Access: Published
00047 //  Description: Sets the order of the surface in the V direction.
00048 //               This resets the knot vector to the default knot
00049 //               vector for the number of vertices.
00050 //
00051 //               The order must be 1, 2, 3, or 4, and the value is one
00052 //               more than the degree of the surface.
00053 ////////////////////////////////////////////////////////////////////
00054 INLINE void NurbsSurfaceEvaluator::
00055 set_v_order(int v_order) {
00056   _v_order = v_order;
00057   _v_knots_dirty = true;
00058   _v_basis_dirty = true;
00059 }
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //     Function: NurbsSurfaceEvaluator::get_v_order
00063 //       Access: Published
00064 //  Description: Returns the order of the surface in the V direction
00065 //               as set by a previous call to set_v_order().
00066 ////////////////////////////////////////////////////////////////////
00067 INLINE int NurbsSurfaceEvaluator::
00068 get_v_order() const {
00069   return _v_order;
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: NurbsSurfaceEvaluator::get_num_u_vertices
00074 //       Access: Published
00075 //  Description: Returns the number of control vertices in the U
00076 //               direction on the surface.  This is the number passed
00077 //               to the last call to reset().
00078 ////////////////////////////////////////////////////////////////////
00079 INLINE int NurbsSurfaceEvaluator::
00080 get_num_u_vertices() const {
00081   return _num_u_vertices;
00082 }
00083 
00084 ////////////////////////////////////////////////////////////////////
00085 //     Function: NurbsSurfaceEvaluator::get_num_v_vertices
00086 //       Access: Published
00087 //  Description: Returns the number of control vertices in the V
00088 //               direction on the surface.  This is the number passed
00089 //               to the last call to reset().
00090 ////////////////////////////////////////////////////////////////////
00091 INLINE int NurbsSurfaceEvaluator::
00092 get_num_v_vertices() const {
00093   return _num_v_vertices;
00094 }
00095 
00096 ////////////////////////////////////////////////////////////////////
00097 //     Function: NurbsSurfaceEvaluator::set_vertex
00098 //       Access: Published
00099 //  Description: Sets the nth control vertex of the surface, as a vertex
00100 //               in 4-d homogeneous space.  In this form, the first
00101 //               three components of the vertex should already have
00102 //               been scaled by the fourth component, which is the
00103 //               homogeneous weight.
00104 ////////////////////////////////////////////////////////////////////
00105 INLINE void NurbsSurfaceEvaluator::
00106 set_vertex(int ui, int vi, const LVecBase4 &vertex) {
00107   nassertv(ui >= 0 && ui < _num_u_vertices &&
00108            vi >= 0 && vi < _num_v_vertices);
00109   vert(ui, vi).set_vertex(vertex);
00110 }
00111 
00112 ////////////////////////////////////////////////////////////////////
00113 //     Function: NurbsSurfaceEvaluator::set_vertex
00114 //       Access: Published
00115 //  Description: Sets the nth control vertex of the surface.  This
00116 //               flavor sets the vertex as a 3-d coordinate and a
00117 //               weight; the 3-d coordinate values are implicitly
00118 //               scaled up by the weight factor.
00119 ////////////////////////////////////////////////////////////////////
00120 INLINE void NurbsSurfaceEvaluator::
00121 set_vertex(int ui, int vi, const LVecBase3 &vertex, PN_stdfloat weight) {
00122   nassertv(ui >= 0 && ui < _num_u_vertices &&
00123            vi >= 0 && vi < _num_v_vertices);
00124   vert(ui, vi).set_vertex(LVecBase4(vertex[0] * weight, vertex[1] * weight, vertex[2] * weight, weight));
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: NurbsSurfaceEvaluator::get_vertex
00129 //       Access: Published
00130 //  Description: Returns the nth control vertex of the surface, relative
00131 //               to its indicated coordinate space.
00132 ////////////////////////////////////////////////////////////////////
00133 INLINE const LVecBase4 &NurbsSurfaceEvaluator::
00134 get_vertex(int ui, int vi) const {
00135   nassertr(ui >= 0 && ui < _num_u_vertices &&
00136            vi >= 0 && vi < _num_v_vertices, LVecBase4::zero());
00137   return vert(ui, vi).get_vertex();
00138 }
00139 
00140 ////////////////////////////////////////////////////////////////////
00141 //     Function: NurbsSurfaceEvaluator::get_vertex
00142 //       Access: Published
00143 //  Description: Returns the nth control vertex of the surface, relative
00144 //               to the given coordinate space.
00145 ////////////////////////////////////////////////////////////////////
00146 INLINE LVecBase4 NurbsSurfaceEvaluator::
00147 get_vertex(int ui, int vi, const NodePath &rel_to) const {
00148   nassertr(ui >= 0 && ui < _num_u_vertices &&
00149            vi >= 0 && vi < _num_v_vertices, LVecBase4::zero());
00150 
00151   NodePath space = vert(ui, vi).get_space(rel_to);
00152   const LVecBase4 &vertex = vert(ui, vi).get_vertex();
00153   if (space.is_empty()) {
00154     return vertex;
00155   } else {
00156     const LMatrix4 &mat = space.get_mat(rel_to);
00157     return vertex * mat;
00158   }
00159 }
00160 
00161 ////////////////////////////////////////////////////////////////////
00162 //     Function: NurbsSurfaceEvaluator::set_vertex_space
00163 //       Access: Published
00164 //  Description: Sets the coordinate space of the nth control vertex.
00165 //               If this is not specified, or is set to an empty
00166 //               NodePath, the nth control vertex is deemed to be in
00167 //               the coordinate space passed to evaluate().
00168 //
00169 //               This specifies the space as a fixed NodePath, which
00170 //               is always the same NodePath.  Also see setting the
00171 //               space as a path string, which can specify a different
00172 //               NodePath for different instances of the surface.
00173 ////////////////////////////////////////////////////////////////////
00174 INLINE void NurbsSurfaceEvaluator::
00175 set_vertex_space(int ui, int vi, const NodePath &space) {
00176   nassertv(ui >= 0 && ui < _num_u_vertices &&
00177            vi >= 0 && vi < _num_v_vertices);
00178   vert(ui, vi).set_space(space);
00179 }
00180 
00181 ////////////////////////////////////////////////////////////////////
00182 //     Function: NurbsSurfaceEvaluator::set_vertex_space
00183 //       Access: Published
00184 //  Description: Sets the coordinate space of the nth control vertex.
00185 //               If this is not specified, or is set to an empty
00186 //               string, the nth control vertex is deemed to be in
00187 //               the coordinate space passed to evaluate().
00188 //
00189 //               This specifies the space as a string, which describes
00190 //               the path to find the node relative to the rel_to
00191 //               NodePath when the surface is evaluated.
00192 ////////////////////////////////////////////////////////////////////
00193 INLINE void NurbsSurfaceEvaluator::
00194 set_vertex_space(int ui, int vi, const string &space) {
00195   nassertv(ui >= 0 && ui < _num_u_vertices &&
00196            vi >= 0 && vi < _num_v_vertices);
00197   vert(ui, vi).set_space(space);
00198 }
00199 
00200 ////////////////////////////////////////////////////////////////////
00201 //     Function: NurbsSurfaceEvaluator::set_extended_vertex
00202 //       Access: Public
00203 //  Description: Sets an n-dimensional vertex value.  This allows
00204 //               definition of a NURBS surface or surface in a sparse
00205 //               n-dimensional space, typically used for associating
00206 //               additional properties (like color or joint
00207 //               membership) with each vertex of a surface.
00208 //
00209 //               The value d is an arbitrary integer value and
00210 //               specifies the dimension of question for this
00211 //               particular vertex.  Any number of dimensions may be
00212 //               specified, and they need not be consecutive.  If a
00213 //               value for a given dimension is not specified, is it
00214 //               implicitly 0.0.
00215 //
00216 //               The value is implicitly scaled by the homogenous
00217 //               weight value--that is, the fourth component of the
00218 //               value passed to set_vertex().  This means the
00219 //               ordinary vertex must be set first, before the
00220 //               extended vertices can be set.
00221 ////////////////////////////////////////////////////////////////////
00222 INLINE void NurbsSurfaceEvaluator::
00223 set_extended_vertex(int ui, int vi, int d, PN_stdfloat value) {
00224   nassertv(ui >= 0 && ui < _num_u_vertices &&
00225            vi >= 0 && vi < _num_v_vertices);
00226   vert(ui, vi).set_extended_vertex(d, value);
00227 }
00228 
00229 ////////////////////////////////////////////////////////////////////
00230 //     Function: NurbsSurfaceEvaluator::get_extended_vertex
00231 //       Access: Public
00232 //  Description: Returns an n-dimensional vertex value.  See
00233 //               set_extended_vertex().  This returns the value set
00234 //               for the indicated dimension, or 0.0 if nothing has
00235 //               been set.
00236 ////////////////////////////////////////////////////////////////////
00237 INLINE PN_stdfloat NurbsSurfaceEvaluator::
00238 get_extended_vertex(int ui, int vi, int d) const {
00239   nassertr(ui >= 0 && ui < _num_u_vertices &&
00240            vi >= 0 && vi < _num_v_vertices, 0.0f);
00241   return vert(ui, vi).get_extended_vertex(d);
00242 }
00243 
00244 ////////////////////////////////////////////////////////////////////
00245 //     Function: NurbsSurfaceEvaluator::get_num_u_knots
00246 //       Access: Published
00247 //  Description: Returns the number of knot values in the surface in
00248 //               the U direction.  This is based on the number of
00249 //               vertices and the order.
00250 ////////////////////////////////////////////////////////////////////
00251 INLINE int NurbsSurfaceEvaluator::
00252 get_num_u_knots() const {
00253   return _num_u_vertices + _u_order;
00254 }
00255 
00256 ////////////////////////////////////////////////////////////////////
00257 //     Function: NurbsSurfaceEvaluator::get_num_v_knots
00258 //       Access: Published
00259 //  Description: Returns the number of knot values in the surface in
00260 //               the V direction.  This is based on the number of
00261 //               vertices and the order.
00262 ////////////////////////////////////////////////////////////////////
00263 INLINE int NurbsSurfaceEvaluator::
00264 get_num_v_knots() const {
00265   return _num_v_vertices + _v_order;
00266 }
00267 
00268 ////////////////////////////////////////////////////////////////////
00269 //     Function: NurbsSurfaceEvaluator::get_num_u_segments
00270 //       Access: Published
00271 //  Description: Returns the number of piecewise continuous segments
00272 //               in the surface in the U direction.  This is based on
00273 //               the knot vector.
00274 ////////////////////////////////////////////////////////////////////
00275 INLINE int NurbsSurfaceEvaluator::
00276 get_num_u_segments() const {
00277   if (_u_basis_dirty) {
00278     ((NurbsSurfaceEvaluator *)this)->recompute_u_basis();
00279   }
00280   return _u_basis.get_num_segments();
00281 }
00282 
00283 ////////////////////////////////////////////////////////////////////
00284 //     Function: NurbsSurfaceEvaluator::get_num_v_segments
00285 //       Access: Published
00286 //  Description: Returns the number of piecewise continuous segments
00287 //               in the surface in the V direction.  This is based on
00288 //               the knot vector.
00289 ////////////////////////////////////////////////////////////////////
00290 INLINE int NurbsSurfaceEvaluator::
00291 get_num_v_segments() const {
00292   if (_v_basis_dirty) {
00293     ((NurbsSurfaceEvaluator *)this)->recompute_v_basis();
00294   }
00295   return _v_basis.get_num_segments();
00296 }
00297 
00298 ////////////////////////////////////////////////////////////////////
00299 //     Function: NurbsSurfaceEvaluator::vert
00300 //       Access: Private
00301 //  Description: Internal accessor to dereference the 2-d vertex
00302 //               coordinate pair into a linear list of vertices.
00303 ////////////////////////////////////////////////////////////////////
00304 INLINE NurbsVertex &NurbsSurfaceEvaluator::
00305 vert(int ui, int vi) {
00306   return _vertices[ui * _num_v_vertices + vi];
00307 }
00308 
00309 ////////////////////////////////////////////////////////////////////
00310 //     Function: NurbsSurfaceEvaluator::vert
00311 //       Access: Private
00312 //  Description: Internal accessor to dereference the 2-d vertex
00313 //               coordinate pair into a linear list of vertices.
00314 ////////////////////////////////////////////////////////////////////
00315 INLINE const NurbsVertex &NurbsSurfaceEvaluator::
00316 vert(int ui, int vi) const {
00317   return _vertices[ui * _num_v_vertices + vi];
00318 }
00319 
00320 INLINE ostream &
00321 operator << (ostream &out, const NurbsSurfaceEvaluator &n) {
00322   n.output(out);
00323   return out;
00324 }
 All Classes Functions Variables Enumerations