Panda3D
 All Classes Functions Variables Enumerations
eggNurbsSurface.I
00001 // Filename: eggNurbsSurface.I
00002 // Created by:  drose (15Feb00)
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 //     Function: EggNurbsSurface::Constructor
00017 //       Access: Public
00018 //  Description:
00019 ////////////////////////////////////////////////////////////////////
00020 INLINE EggNurbsSurface::
00021 EggNurbsSurface(const string &name) : EggSurface(name) {
00022   _u_order = 0;
00023   _v_order = 0;
00024 }
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: EggNurbsSurface::Copy constructor
00028 //       Access: Public
00029 //  Description:
00030 ////////////////////////////////////////////////////////////////////
00031 INLINE EggNurbsSurface::
00032 EggNurbsSurface(const EggNurbsSurface &copy) :
00033   EggSurface(copy),
00034   _u_knots(copy._u_knots),
00035   _v_knots(copy._v_knots),
00036   _u_order(copy._u_order),
00037   _v_order(copy._v_order)
00038 {
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: EggNurbsSurface::Copy assignment operator
00043 //       Access: Public
00044 //  Description:
00045 ////////////////////////////////////////////////////////////////////
00046 INLINE EggNurbsSurface &EggNurbsSurface::
00047 operator = (const EggNurbsSurface &copy) {
00048   EggSurface::operator = (copy);
00049   _u_knots = copy._u_knots;
00050   _v_knots = copy._v_knots;
00051   _u_order = copy._u_order;
00052   _v_order = copy._v_order;
00053   return *this;
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: EggNurbsSurface::set_u_order
00058 //       Access: Public
00059 //  Description: Directly changes the order in the U direction to the
00060 //               indicated value (which must be an integer in the
00061 //               range 1 <= u_order <= 4).  If possible, it is
00062 //               preferable to use the setup() method instead of this
00063 //               method, since changing the order directly may result
00064 //               in an invalid surface.
00065 ////////////////////////////////////////////////////////////////////
00066 INLINE void EggNurbsSurface::
00067 set_u_order(int u_order) {
00068   nassertv(u_order >= 1 && u_order <= 4);
00069   _u_order = u_order;
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: EggNurbsSurface::set_v_order
00074 //       Access: Public
00075 //  Description: Directly changes the order in the V direction to the
00076 //               indicated value (which must be an integer in the
00077 //               range 1 <= v_order <= 4).  If possible, it is
00078 //               preferable to use the setup() method instead of this
00079 //               method, since changing the order directly may result
00080 //               in an invalid surface.
00081 ////////////////////////////////////////////////////////////////////
00082 INLINE void EggNurbsSurface::
00083 set_v_order(int v_order) {
00084   nassertv(v_order >= 1 && v_order <= 4);
00085   _v_order = v_order;
00086 }
00087 
00088 ////////////////////////////////////////////////////////////////////
00089 //     Function: EggNurbsSurface::set_u_knot
00090 //       Access: Public
00091 //  Description: Resets the value of the indicated knot as indicated.
00092 //               k must be in the range 0 <= k < get_num_u_knots(),
00093 //               and the value must be in the range get_u_knot(k - 1)
00094 //               <= value <= get_u_knot(k + 1).
00095 ////////////////////////////////////////////////////////////////////
00096 INLINE void EggNurbsSurface::
00097 set_u_knot(int k, double value) {
00098   nassertv(k >= 0 && k < (int)_u_knots.size());
00099   _u_knots[k] = value;
00100 }
00101 
00102 ////////////////////////////////////////////////////////////////////
00103 //     Function: EggNurbsSurface::set_v_knot
00104 //       Access: Public
00105 //  Description: Resets the value of the indicated knot as indicated.
00106 //               k must be in the range 0 <= k < get_num_v_knots(),
00107 //               and the value must be in the range get_v_knot(k - 1)
00108 //               <= value <= get_v_knot(k + 1).
00109 ////////////////////////////////////////////////////////////////////
00110 INLINE void EggNurbsSurface::
00111 set_v_knot(int k, double value) {
00112   nassertv(k >= 0 && k < (int)_v_knots.size());
00113   _v_knots[k] = value;
00114 }
00115 
00116 ////////////////////////////////////////////////////////////////////
00117 //     Function: EggNurbsSurface::set_cv
00118 //       Access: Public
00119 //  Description: Redefines the control vertex associated with a
00120 //               particular u, v coordinate pair.  This is just a
00121 //               shorthand to access the EggPrimitive's normal vertex
00122 //               assignment for a 2-d control vertex.
00123 ////////////////////////////////////////////////////////////////////
00124 INLINE void EggNurbsSurface::
00125 set_cv(int ui, int vi, EggVertex *vertex) {
00126   int vertex_index = get_vertex_index(ui, vi);
00127   set_vertex(vertex_index, vertex);
00128 }
00129 
00130 ////////////////////////////////////////////////////////////////////
00131 //     Function: EggNurbsSurface::get_u_order
00132 //       Access: Public
00133 //  Description: Returns the order of the surface in the U direction.
00134 //               The order is the degree of the NURBS equation plus 1;
00135 //               for a typical NURBS, the order is 4.  With this
00136 //               implementation of NURBS, the order must be in the
00137 //               range [1, 4].
00138 ////////////////////////////////////////////////////////////////////
00139 INLINE int EggNurbsSurface::
00140 get_u_order() const {
00141   return _u_order;
00142 }
00143 
00144 ////////////////////////////////////////////////////////////////////
00145 //     Function: EggNurbsSurface::get_v_order
00146 //       Access: Public
00147 //  Description: Returns the order of the surface in the V direction.
00148 //               The order is the degree of the NURBS equation plus 1;
00149 //               for a typical NURBS, the order is 4.  With this
00150 //               implementation of NURBS, the order must be in the
00151 //               range [1, 4].
00152 ////////////////////////////////////////////////////////////////////
00153 INLINE int EggNurbsSurface::
00154 get_v_order() const {
00155   return _v_order;
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: EggNurbsSurface::get_u_degree
00160 //       Access: Public
00161 //  Description: Returns the degree of the surface in the U direction.
00162 //               For a typical NURBS, the degree is 3.
00163 ////////////////////////////////////////////////////////////////////
00164 INLINE int EggNurbsSurface::
00165 get_u_degree() const {
00166   return _u_order - 1;
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //     Function: EggNurbsSurface::get_v_degree
00171 //       Access: Public
00172 //  Description: Returns the degree of the surface in the V direction.
00173 //               for a typical NURBS, the degree is 3.
00174 ////////////////////////////////////////////////////////////////////
00175 INLINE int EggNurbsSurface::
00176 get_v_degree() const {
00177   return _v_order - 1;
00178 }
00179 
00180 ////////////////////////////////////////////////////////////////////
00181 //     Function: EggNurbsSurface::get_num_u_knots
00182 //       Access: Public
00183 //  Description: Returns the number of knots in the U direction.
00184 ////////////////////////////////////////////////////////////////////
00185 INLINE int EggNurbsSurface::
00186 get_num_u_knots() const {
00187   return _u_knots.size();
00188 }
00189 
00190 ////////////////////////////////////////////////////////////////////
00191 //     Function: EggNurbsSurface::get_num_v_knots
00192 //       Access: Public
00193 //  Description: Returns the number of knots in the V direction.
00194 ////////////////////////////////////////////////////////////////////
00195 INLINE int EggNurbsSurface::
00196 get_num_v_knots() const {
00197   return _v_knots.size();
00198 }
00199 
00200 ////////////////////////////////////////////////////////////////////
00201 //     Function: EggNurbsSurface::get_num_u_cvs
00202 //       Access: Public
00203 //  Description: Returns the number of control vertices that should be
00204 //               present in the U direction.  This is determined by
00205 //               the number of knots and the order; it does not
00206 //               necessarily reflect the number of vertices that have
00207 //               actually been added to the surface.  (However, if the
00208 //               number of vertices in the surface are wrong, the
00209 //               surface is invalid.)
00210 ////////////////////////////////////////////////////////////////////
00211 INLINE int EggNurbsSurface::
00212 get_num_u_cvs() const {
00213   return get_num_u_knots() - get_u_order();
00214 }
00215 
00216 ////////////////////////////////////////////////////////////////////
00217 //     Function: EggNurbsSurface::get_num_v_cvs
00218 //       Access: Public
00219 //  Description: Returns the number of control vertices that should be
00220 //               present in the V direction.  This is determined by
00221 //               the number of knots and the order; it does not
00222 //               necessarily reflect the number of vertices that have
00223 //               actually been added to the surface.  (However, if the
00224 //               number of vertices in the surface are wrong, the
00225 //               surface is invalid.)
00226 ////////////////////////////////////////////////////////////////////
00227 INLINE int EggNurbsSurface::
00228 get_num_v_cvs() const {
00229   return get_num_v_knots() - get_v_order();
00230 }
00231 
00232 ////////////////////////////////////////////////////////////////////
00233 //     Function: EggNurbsSurface::get_num_cvs
00234 //       Access: Public
00235 //  Description: Returns the total number of control vertices that
00236 //               *should* be defined for the surface.  This is
00237 //               determined by the number of knots and the order, in
00238 //               each direction; it does not necessarily reflect the
00239 //               number of vertices that have actually been added to
00240 //               the surface.  (However, if the number of vertices in
00241 //               the surface are wrong, the surface is invalid.)
00242 ////////////////////////////////////////////////////////////////////
00243 INLINE int EggNurbsSurface::
00244 get_num_cvs() const {
00245   return get_num_u_cvs() * get_num_v_cvs();
00246 }
00247 
00248 ////////////////////////////////////////////////////////////////////
00249 //     Function: EggNurbsSurface::get_u_index
00250 //       Access: Public
00251 //  Description: Returns the U index number of the given vertex within
00252 //               the EggPrimitive's linear list of vertices.  An
00253 //               EggNurbsSurface maps a linear list of vertices to its
00254 //               2-d mesh; this returns the U index number that
00255 //               corresponds to the nth vertex in the list.
00256 ////////////////////////////////////////////////////////////////////
00257 INLINE int EggNurbsSurface::
00258 get_u_index(int vertex_index) const {
00259   nassertr(vertex_index >= 0 && vertex_index < get_num_cvs(), 0);
00260   return vertex_index % get_num_u_cvs();
00261 }
00262 
00263 ////////////////////////////////////////////////////////////////////
00264 //     Function: EggNurbsSurface::get_v_index
00265 //       Access: Public
00266 //  Description: Returns the V index number of the given vertex within
00267 //               the EggPrimitive's linear list of vertices.  An
00268 //               EggNurbsSurface maps a linear list of vertices to its
00269 //               2-d mesh; this returns the V index number that
00270 //               corresponds to the nth vertex in the list.
00271 ////////////////////////////////////////////////////////////////////
00272 INLINE int EggNurbsSurface::
00273 get_v_index(int vertex_index) const {
00274   nassertr(vertex_index >= 0 && vertex_index < get_num_cvs(), 0);
00275   return vertex_index / get_num_u_cvs();
00276 }
00277 
00278 ////////////////////////////////////////////////////////////////////
00279 //     Function: EggNurbsSurface::get_vertex_index
00280 //       Access: Public
00281 //  Description: Returns the index number within the EggPrimitive's
00282 //               list of the control vertex at position ui, vi.
00283 ////////////////////////////////////////////////////////////////////
00284 INLINE int EggNurbsSurface::
00285 get_vertex_index(int ui, int vi) const {
00286   nassertr(ui >= 0 && ui < get_num_u_cvs(), 0);
00287   nassertr(vi >= 0 && vi < get_num_v_cvs(), 0);
00288   return vi * get_num_u_cvs() + ui;
00289 }
00290 
00291 ////////////////////////////////////////////////////////////////////
00292 //     Function: EggNurbsSurface::get_u_knot
00293 //       Access: Public
00294 //  Description: Returns the nth knot value defined in the U
00295 //               direction.
00296 ////////////////////////////////////////////////////////////////////
00297 INLINE double EggNurbsSurface::
00298 get_u_knot(int k) const {
00299   nassertr(k >= 0 && k < (int)_u_knots.size(), 0.0);
00300   return _u_knots[k];
00301 }
00302 
00303 ////////////////////////////////////////////////////////////////////
00304 //     Function: EggNurbsSurface::get_v_knot
00305 //       Access: Public
00306 //  Description: Returns the nth knot value defined in the V
00307 //               direction.
00308 ////////////////////////////////////////////////////////////////////
00309 INLINE double EggNurbsSurface::
00310 get_v_knot(int k) const {
00311   nassertr(k >= 0 && k < (int)_v_knots.size(), 0.0);
00312   return _v_knots[k];
00313 }
00314 
00315 ////////////////////////////////////////////////////////////////////
00316 //     Function: EggNurbsSurface::get_cv
00317 //       Access: Public
00318 //  Description: Returns the control vertex at the indicate U, V
00319 //               position.
00320 ////////////////////////////////////////////////////////////////////
00321 INLINE EggVertex *EggNurbsSurface::
00322 get_cv(int ui, int vi) const {
00323   int vertex_index = get_vertex_index(ui, vi);
00324   return get_vertex(vertex_index);
00325 }
 All Classes Functions Variables Enumerations