Panda3D
qtessSurface.h
1 // Filename: qtessSurface.h
2 // Created by: drose (13Oct03)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef QTESSSURFACE_H
16 #define QTESSSURFACE_H
17 
18 #include "pandatoolbase.h"
19 #include "isoPlacer.h"
20 #include "eggNurbsSurface.h"
21 #include "eggGroup.h"
22 #include "eggVertex.h"
23 #include "nurbsSurfaceEvaluator.h"
24 #include "nurbsSurfaceResult.h"
25 #include "referenceCount.h"
26 #include "pointerTo.h"
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : QtessSurface
30 // Description : A reference to an EggNurbsSurface in the egg file,
31 // and its parameters as set by the user input file and
32 // as computed in relation to the other surfaces.
33 ////////////////////////////////////////////////////////////////////
34 class QtessSurface : public ReferenceCount {
35 public:
36  QtessSurface(EggNurbsSurface *egg_surface);
37 
38  INLINE const string &get_name() const;
39  INLINE bool is_valid() const;
40 
41  INLINE void set_importance(double importance2);
42  INLINE void set_match_u(QtessSurface **match_u, bool match_u_to_u);
43  INLINE void set_match_v(QtessSurface **match_v, bool match_v_to_v);
44  INLINE void set_min_u(int min_u);
45  INLINE void set_min_v(int min_v);
46 
47  INLINE double count_patches() const;
48  INLINE int count_tris() const;
49 
50  double get_score(double ratio);
51 
52  int tesselate();
53  int write_qtess_parameter(ostream &out);
54  void omit();
55  void tesselate_uv(int u, int v, bool autoplace, double ratio);
56  void tesselate_specific(const pvector<double> &u_list,
57  const pvector<double> &v_list);
58  void tesselate_per_isoparam(double pi, bool autoplace, double ratio);
59  void tesselate_per_score(double pi, bool autoplace, double ratio);
60  void tesselate_auto(int u, int v, double ratio);
61 
62 private:
63  void record_vertex_extras();
64  INLINE int get_joint_membership_index(EggGroup *joint);
65  INLINE int get_dxyz_index(const string &morph_name);
66  INLINE int get_drgba_index(const string &morph_name);
67 
68  void apply_match();
69  PT(EggGroup) do_uniform_tesselate(int &tris) const;
70  PT(EggVertex) evaluate_vertex(double u, double v) const;
71 
72  PT(EggNurbsSurface) _egg_surface;
73  PT(NurbsSurfaceEvaluator) _nurbs;
74  PT(NurbsSurfaceResult) _nurbs_result;
75  bool _has_vertex_color;
76 
77  // Mapping arbitrary attributes to integer extended dimension
78  // values, so we can hang arbitrary data in the extra dimensional
79  // space of the surface.
80  int _next_d;
81  typedef map<EggGroup *, int> JointTable;
82  JointTable _joint_table;
83  typedef map<string, int> MorphTable;
84  MorphTable _dxyz_table;
85  MorphTable _drgba_table;
86 
87  int _num_u, _num_v;
88  int _tess_u, _tess_v;
89  pvector<double> _iso_u, _iso_v; // If nonempty, isoparams at which to tess.
90 
91  // _importance is the relative importance of the surface along either
92  // axis; _importance2 is this number squared, which is the value set by
93  // set_importance().
94  double _importance;
95  double _importance2;
96 
97  // _match_u and _match_v indicate which surface we must match
98  // exactly for tesselation in U or V. This helps get edges to line
99  // up properly. They are indirect pointers because we go through
100  // the surfaces in one pass, and might need to fill in the correct
101  // value later.
102  QtessSurface **_match_u, **_match_v;
103  bool _match_u_to_u, _match_v_to_v;
104 
105  // _min_u and _min_v specify a mininum number of quads below which
106  // we should not attempt to subdivide the surface in either
107  // dimension. This is intended to prevent degenerate cases like
108  // knife-fingers.
109  int _min_u, _min_v;
110 
111  IsoPlacer _u_placer, _v_placer;
112  bool _got_scores;
113 };
114 
115 #include "qtessSurface.I"
116 
117 #endif
118 
A reference to an EggNurbsSurface in the egg file, and its parameters as set by the user input file a...
Definition: qtessSurface.h:34
int count_tris() const
Returns the number of triangles that will be generated by the current tesselation parameters...
Definition: qtessSurface.I:132
void set_importance(double importance2)
Sets the importance of the surface, as a ratio in proportion to the square of its size...
Definition: qtessSurface.I:44
void set_match_v(QtessSurface **match_v, bool match_v_to_v)
Indicates the surface to which this surface must match in its V direction.
Definition: qtessSurface.I:84
This class is an abstraction for evaluating NURBS surfaces.
void set_match_u(QtessSurface **match_u, bool match_u_to_u)
Indicates the surface to which this surface must match in its U direction.
Definition: qtessSurface.I:64
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
Definition: eggGroup.h:36
Contains the logic used to place isoparams where they&#39;ll do the most good on a surface.
Definition: isoPlacer.h:29
void set_min_v(int min_v)
Specifies the absolute minimum number of segments allowed in the V direction.
Definition: qtessSurface.I:107
bool is_valid() const
Returns true if the defined surface is valid, false otherwise.
Definition: qtessSurface.I:33
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
Definition: eggVertex.h:41
void tesselate_auto(int u, int v, double ratio)
Sets the surface up to tesselate itself by automatically determining the best place to put the indica...
The result of a NurbsSurfaceEvaluator.
double get_score(double ratio)
Computes the curvature/stretch score for the surface, if it has not been already computed, and returns the net surface score.
void set_min_u(int min_u)
Specifies the absolute minimum number of segments allowed in the U direction.
Definition: qtessSurface.I:96
int write_qtess_parameter(ostream &out)
Writes a line to the given output file telling qtess how this surface should be tesselated uniformly...
void omit()
Sets up the surface to omit itself from the output.
void tesselate_specific(const pvector< double > &u_list, const pvector< double > &v_list)
Sets the surface up to tesselate itself at specific isoparams only.
A base class for all things that want to be reference-counted.
int tesselate()
Applies the appropriate tesselation to the surface, and replaces its node in the tree with an EggGrou...
A parametric NURBS surface.
void tesselate_per_isoparam(double pi, bool autoplace, double ratio)
Sets the surface up to tesselate itself to a uniform amount per isoparam.
void tesselate_per_score(double pi, bool autoplace, double ratio)
Sets the surface up to tesselate itself according to its computed curvature score in both dimensions...
double count_patches() const
Returns the number of patches the NURBS contains.
Definition: qtessSurface.I:121
void tesselate_uv(int u, int v, bool autoplace, double ratio)
Sets the surface up to tesselate itself uniformly at u x v, or if autoplace is true, automatically with u x v quads.