Panda3D

qtessSurface.h

00001 // Filename: qtessSurface.h
00002 // Created by:  drose (13Oct03)
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 QTESSSURFACE_H
00016 #define QTESSSURFACE_H
00017 
00018 #include "pandatoolbase.h"
00019 #include "isoPlacer.h"
00020 #include "eggNurbsSurface.h"
00021 #include "eggGroup.h"
00022 #include "eggVertex.h"
00023 #include "nurbsSurfaceEvaluator.h"
00024 #include "nurbsSurfaceResult.h"
00025 #include "referenceCount.h"
00026 #include "pointerTo.h"
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : QtessSurface
00030 // Description : A reference to an EggNurbsSurface in the egg file,
00031 //               and its parameters as set by the user input file and
00032 //               as computed in relation to the other surfaces.
00033 ////////////////////////////////////////////////////////////////////
00034 class QtessSurface : public ReferenceCount {
00035 public:
00036   QtessSurface(EggNurbsSurface *egg_surface);
00037 
00038   INLINE const string &get_name() const;
00039   INLINE bool is_valid() const;
00040 
00041   INLINE void set_importance(double importance2);
00042   INLINE void set_match_u(QtessSurface **match_u, bool match_u_to_u);
00043   INLINE void set_match_v(QtessSurface **match_v, bool match_v_to_v);
00044   INLINE void set_min_u(int min_u);
00045   INLINE void set_min_v(int min_v);
00046 
00047   INLINE double count_patches() const;
00048   INLINE int count_tris() const;
00049 
00050   double get_score(double ratio);
00051   
00052   int tesselate();
00053   int write_qtess_parameter(ostream &out);
00054   void omit();
00055   void tesselate_uv(int u, int v, bool autoplace, double ratio);
00056   void tesselate_specific(const pvector<double> &u_list,
00057                           const pvector<double> &v_list);
00058   void tesselate_per_isoparam(double pi, bool autoplace, double ratio);
00059   void tesselate_per_score(double pi, bool autoplace, double ratio);
00060   void tesselate_auto(int u, int v, double ratio);
00061 
00062 private:
00063   void record_vertex_extras();
00064   INLINE int get_joint_membership_index(EggGroup *joint);
00065   INLINE int get_dxyz_index(const string &morph_name);
00066   INLINE int get_drgba_index(const string &morph_name);
00067 
00068   void apply_match();
00069   PT(EggGroup) do_uniform_tesselate(int &tris) const;
00070   PT(EggVertex) evaluate_vertex(double u, double v) const;
00071 
00072   PT(EggNurbsSurface) _egg_surface;
00073   PT(NurbsSurfaceEvaluator) _nurbs;
00074   PT(NurbsSurfaceResult) _nurbs_result;
00075   bool _has_vertex_color;
00076 
00077   // Mapping arbitrary attributes to integer extended dimension
00078   // values, so we can hang arbitrary data in the extra dimensional
00079   // space of the surface.
00080   int _next_d;
00081   typedef map<EggGroup *, int> JointTable;
00082   JointTable _joint_table;
00083   typedef map<string, int> MorphTable;
00084   MorphTable _dxyz_table;
00085   MorphTable _drgba_table;
00086 
00087   int _num_u, _num_v;
00088   int _tess_u, _tess_v;
00089   pvector<double> _iso_u, _iso_v;  // If nonempty, isoparams at which to tess.
00090 
00091   // _importance is the relative importance of the surface along either
00092   // axis; _importance2 is this number squared, which is the value set by
00093   // set_importance().
00094   double _importance;
00095   double _importance2;
00096 
00097   // _match_u and _match_v indicate which surface we must match
00098   // exactly for tesselation in U or V.  This helps get edges to line
00099   // up properly.  They are indirect pointers because we go through
00100   // the surfaces in one pass, and might need to fill in the correct
00101   // value later.
00102   QtessSurface **_match_u, **_match_v;
00103   bool _match_u_to_u, _match_v_to_v;
00104 
00105   // _min_u and _min_v specify a mininum number of quads below which
00106   // we should not attempt to subdivide the surface in either
00107   // dimension.  This is intended to prevent degenerate cases like
00108   // knife-fingers.
00109   int _min_u, _min_v;
00110 
00111   IsoPlacer _u_placer, _v_placer;
00112   bool _got_scores;
00113 };
00114 
00115 #include "qtessSurface.I"
00116 
00117 #endif
00118 
 All Classes Functions Variables Enumerations