Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/egg/eggNurbsSurface.I

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

Generated on Fri May 2 00:37:48 2003 for Panda by doxygen1.3