Panda3D
 All Classes Functions Variables Enumerations
nurbsSurfaceEvaluator.h
00001 // Filename: nurbsSurfaceEvaluator.h
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 #ifndef NURBSSURFACEEVALUATOR_H
00016 #define NURBSSURFACEEVALUATOR_H
00017 
00018 #include "pandabase.h"
00019 #include "nurbsBasisVector.h"
00020 #include "nurbsSurfaceResult.h"
00021 #include "nurbsVertex.h"
00022 #include "pointerTo.h"
00023 #include "vector_stdfloat.h"
00024 #include "pvector.h"
00025 #include "nodePath.h"
00026 #include "referenceCount.h"
00027 #include "luse.h"
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //       Class : NurbsSurfaceEvaluator
00031 // Description : This class is an abstraction for evaluating NURBS
00032 //               surfaces.  It accepts an array of vertices, each of
00033 //               which may be in a different coordinate space (as
00034 //               defined by a NodePath), as well as an optional knot
00035 //               vector.
00036 ////////////////////////////////////////////////////////////////////
00037 class EXPCL_PANDA_PARAMETRICS NurbsSurfaceEvaluator : public ReferenceCount {
00038 PUBLISHED:
00039   NurbsSurfaceEvaluator();
00040   ~NurbsSurfaceEvaluator();
00041 
00042   INLINE void set_u_order(int u_order);
00043   INLINE int get_u_order() const;
00044 
00045   INLINE void set_v_order(int v_order);
00046   INLINE int get_v_order() const;
00047 
00048   void reset(int num_u_vertices, int num_v_vertices);
00049 
00050   INLINE int get_num_u_vertices() const;
00051   INLINE int get_num_v_vertices() const;
00052   INLINE void set_vertex(int ui, int vi, const LVecBase4 &vertex);
00053   INLINE void set_vertex(int ui, int vi, const LVecBase3 &vertex, PN_stdfloat weight = 1.0);
00054   INLINE const LVecBase4 &get_vertex(int ui, int vi) const;
00055   INLINE LVecBase4 get_vertex(int ui, int vi, const NodePath &rel_to) const;
00056 
00057   INLINE void set_vertex_space(int ui, int vi, const NodePath &space);
00058   INLINE void set_vertex_space(int ui, int vi, const string &space);
00059   NodePath get_vertex_space(int ui, int vi, const NodePath &rel_to) const;
00060 
00061   INLINE void set_extended_vertex(int ui, int vi, int d, PN_stdfloat value);
00062   INLINE PN_stdfloat get_extended_vertex(int ui, int vi, int d) const;
00063   void set_extended_vertices(int ui, int vi, int d, 
00064                              const PN_stdfloat values[], int num_values);
00065 
00066   INLINE int get_num_u_knots() const;
00067   void set_u_knot(int i, PN_stdfloat knot);
00068   PN_stdfloat get_u_knot(int i) const;
00069   MAKE_SEQ(get_u_knots, get_num_u_knots, get_u_knot);
00070   void normalize_u_knots();
00071 
00072   INLINE int get_num_v_knots() const;
00073   void set_v_knot(int i, PN_stdfloat knot);
00074   PN_stdfloat get_v_knot(int i) const;
00075   MAKE_SEQ(get_v_knots, get_num_v_knots, get_v_knot);
00076   void normalize_v_knots();
00077 
00078   INLINE int get_num_u_segments() const;
00079   INLINE int get_num_v_segments() const;
00080 
00081   PT(NurbsSurfaceResult) evaluate(const NodePath &rel_to = NodePath()) const;
00082 
00083   void output(ostream &out) const;
00084 
00085 public:
00086   typedef epvector<LVecBase4> Vert4Array;
00087   typedef pvector<LPoint3> Vert3Array;
00088   void get_vertices(Vert4Array &verts, const NodePath &rel_to) const;
00089   void get_vertices(Vert3Array &verts, const NodePath &rel_to) const;
00090 
00091 private:
00092   INLINE NurbsVertex &vert(int ui, int vi);
00093   INLINE const NurbsVertex &vert(int ui, int vi) const;
00094 
00095   void recompute_u_knots();
00096   void recompute_v_knots();
00097   void recompute_u_basis();
00098   void recompute_v_basis();
00099 
00100   int _u_order;
00101   int _v_order;
00102 
00103   typedef epvector<NurbsVertex> Vertices;
00104   Vertices _vertices;
00105   int _num_u_vertices;
00106   int _num_v_vertices;
00107 
00108   bool _u_knots_dirty;
00109   bool _v_knots_dirty;
00110   typedef vector_stdfloat Knots;
00111   Knots _u_knots;
00112   Knots _v_knots;
00113 
00114   bool _u_basis_dirty;
00115   bool _v_basis_dirty;
00116   NurbsBasisVector _u_basis;
00117   NurbsBasisVector _v_basis;
00118 };
00119 
00120 INLINE ostream &operator << (ostream &out, const NurbsSurfaceEvaluator &n);
00121 
00122 #include "nurbsSurfaceEvaluator.I"
00123 
00124 #endif
00125 
 All Classes Functions Variables Enumerations