Panda3D

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