Panda3D
 All Classes Functions Variables Enumerations
eggMesherStrip.h
1 // Filename: eggMesherStrip.h
2 // Created by: drose (13Mar05)
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 EGGMESHERSTRIP_H
16 #define EGGMESHERSTRIP_H
17 
18 #include "pandabase.h"
19 #include "eggVertexPool.h"
20 #include "eggPrimitive.h"
21 #include "eggMesherEdge.h"
22 #include "plist.h"
23 
24 class EggMesherEdge;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : EggMesherStrip
28 // Description : Represents a triangle strip or quad strip in
29 // progress, as assembled by the mesher. It might also
30 // represent a single polygon such as a triangle or
31 // quad, since that's how strips generally start out.
32 ////////////////////////////////////////////////////////////////////
34 public:
35  enum PrimType {
36  PT_poly,
37  PT_point,
38  PT_line,
39  PT_tri,
40  PT_tristrip,
41  PT_trifan,
42  PT_quad,
43  PT_quadstrip,
44  PT_linestrip,
45  };
46 
47  enum MesherOrigin {
48  MO_unknown,
49  MO_user,
50  MO_firstquad,
51  MO_fanpoly,
52  MO_mate
53  };
54 
55  EggMesherStrip(PrimType prim_type, MesherOrigin origin);
56  EggMesherStrip(const EggPrimitive *prim, int index, const EggVertexPool *vertex_pool,
57  bool flat_shaded);
58  INLINE EggMesherStrip(const EggMesherStrip &copy);
59 
60  PT(EggPrimitive) make_prim(const EggVertexPool *vertex_pool);
61 
62  void measure_sheet(const EggMesherEdge *edge, int new_row,
63  int &num_prims, int &num_rows,
64  int first_row_id, int this_row_id,
65  int this_row_distance);
66  void cut_sheet(int first_row_id, int do_mate,
67  const EggVertexPool *vertex_pool);
68 
69  bool mate(const EggVertexPool *vertex_pool);
70  bool find_ideal_mate(EggMesherStrip *&mate, EggMesherEdge *&common_edge,
71  const EggVertexPool *vertex_pool);
72  static bool mate_pieces(EggMesherEdge *common_edge, EggMesherStrip &front,
73  EggMesherStrip &back, const EggVertexPool *vertex_pool);
74  static bool mate_strips(EggMesherEdge *common_edge, EggMesherStrip &front,
75  EggMesherStrip &back, PrimType type);
76  static bool must_invert(const EggMesherStrip &front, const EggMesherStrip &back,
77  bool will_reverse_back, PrimType type);
78  static bool convex_quad(EggMesherEdge *common_edge, EggMesherStrip &front,
79  EggMesherStrip &back, const EggVertexPool *vertex_pool);
80 
81  int count_neighbors() const;
82  void output_neighbors(ostream &out) const;
83 
84  INLINE bool is_coplanar_with(const EggMesherStrip &other, PN_stdfloat threshold) const;
85  INLINE PN_stdfloat coplanarity(const EggMesherStrip &other) const;
86  INLINE int type_category() const;
87 
88  int find_uncommon_vertex(const EggMesherEdge *edge) const;
89  const EggMesherEdge *find_opposite_edge(int vi) const;
90  const EggMesherEdge *find_opposite_edge(const EggMesherEdge *edge) const;
91  const EggMesherEdge *find_adjacent_edge(const EggMesherEdge *edge) const;
92 
93  INLINE void rotate_forward();
94  INLINE void rotate_back();
95  void rotate_to_front(const EggMesherEdge *edge);
96  void rotate_to_back(const EggMesherEdge *edge);
97  bool can_invert() const;
98  bool invert();
99 
100  INLINE EggMesherEdge get_head_edge() const;
101  INLINE EggMesherEdge get_tail_edge() const;
102 
103  bool is_odd() const;
104  bool would_reverse_tail(PrimType want_type) const;
105  void convert_to_type(PrimType want_type);
106 
107  void combine_edges(EggMesherStrip &other, int remove_sides);
108  void remove_all_edges();
109 
110  // ptr equality
111  INLINE bool operator == (const EggMesherStrip &other) const;
112  INLINE bool operator != (const EggMesherStrip &other) const;
113 
114  bool pick_mate(const EggMesherStrip &a_strip, const EggMesherStrip &b_strip,
115  const EggMesherEdge &a_edge, const EggMesherEdge &b_edge,
116  const EggVertexPool *vertex_pool) const;
117 
118  bool pick_sheet_mate(const EggMesherStrip &a_strip,
119  const EggMesherStrip &b_strip) const;
120 
121  void output(ostream &out) const;
122 
125  typedef plist<int> Verts;
126 
127  Prims _prims;
128  Edges _edges;
129  Verts _verts;
130 
131  enum MesherStatus {
132  MS_alive,
133  MS_dead,
134  MS_done,
135  MS_paired
136  };
137 
138  PrimType _type;
139  int _index;
140  MesherStatus _status;
141 
142  bool _planar;
143  LNormald _plane_normal;
144  PN_stdfloat _plane_offset;
145  int _row_id, _row_distance;
146  MesherOrigin _origin;
147  bool _flat_shaded;
148 };
149 
150 INLINE ostream &
151 operator << (ostream &out, const EggMesherStrip &strip) {
152  strip.output(out);
153  return out;
154 }
155 
156 #include "eggMesherStrip.I"
157 
158 #endif
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
Definition: eggPrimitive.h:51
bool operator==(const EggMesherStrip &other) const
Defines equality for strips.
int count_neighbors() const
Returns the number of neighbors the strip shares.
void rotate_to_front(const EggMesherEdge *edge)
Rotates a triangle or quad so that the given edge is first in the vertex list.
void rotate_forward()
Rotates a triangle or quad by bringing its first vertex to the back.
static bool mate_strips(EggMesherEdge *common_edge, EggMesherStrip &front, EggMesherStrip &back, PrimType type)
Stitches two strips together, producing in &quot;front&quot; a new strip of the indicated type (quadstrip or tr...
const EggMesherEdge * find_adjacent_edge(const EggMesherEdge *edge) const
Returns the first edge found that shares exactly one vertex with the given edge.
bool mate(const EggVertexPool *vertex_pool)
Finds a neighboring strip and joins up with it to make a larger strip.
void output(ostream &out) const
Formats the vertex for output in some sensible way.
void combine_edges(EggMesherStrip &other, int remove_sides)
Removes the edges from the given strip and appends them to our own.
void rotate_back()
Rotates a triangle or quad by bringing its last vertex to the front.
bool can_invert() const
Returns true if the strip can be inverted (reverse its facing direction).
void measure_sheet(const EggMesherEdge *edge, int new_row, int &num_prims, int &num_rows, int first_row_id, int this_row_id, int this_row_distance)
Determines the extents of the quadsheet that can be derived by starting with this strip...
void convert_to_type(PrimType want_type)
Converts the EggMesherStrip from whatever form it is–triangle, quad, or quadstrip–into a tristrip or ...
void output_neighbors(ostream &out) const
Writes all the neighbor indexes to the ostream.
EggMesherEdge get_tail_edge() const
Returns an EggMesherEdge which represents the trailing edge in the quadstrip or tristrip.
void remove_all_edges()
Removes all active edges from the strip.
static bool convex_quad(EggMesherEdge *common_edge, EggMesherStrip &front, EggMesherStrip &back, const EggVertexPool *vertex_pool)
Returns true if the quad that would be formed by connecting coplanar tris front and back along common...
static bool must_invert(const EggMesherStrip &front, const EggMesherStrip &back, bool will_reverse_back, PrimType type)
Returns false if the strips can be mated as they currently are.
void rotate_to_back(const EggMesherEdge *edge)
Rotates a triangle or quad so that the given edge is last in the vertex list.
Represents one edge of a triangle, as used by the EggMesher to discover connected triangles...
Definition: eggMesherEdge.h:32
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:746
int find_uncommon_vertex(const EggMesherEdge *edge) const
Returns the first vertex found that is not shared by the given edge.
bool is_coplanar_with(const EggMesherStrip &other, PN_stdfloat threshold) const
Returns true if the strip and the other strip are coplanar, within the indicated threshold.
bool find_ideal_mate(EggMesherStrip *&mate, EggMesherEdge *&common_edge, const EggVertexPool *vertex_pool)
Searches our neighbors for the most suitable mate.
Represents a triangle strip or quad strip in progress, as assembled by the mesher.
EggMesherEdge get_head_edge() const
Returns an EggMesherEdge which represents the leading edge in the quadstrip or tristrip.
PN_stdfloat coplanarity(const EggMesherStrip &other) const
Returns the degree to which the two strips are coplanar.
int type_category() const
Returns an integer which gives a heuristic about the similarity of different strip types...
static bool mate_pieces(EggMesherEdge *common_edge, EggMesherStrip &front, EggMesherStrip &back, const EggVertexPool *vertex_pool)
Connects two pieces of arbitrary type, if possible.
const EggMesherEdge * find_opposite_edge(int vi) const
Returns the first edge found that does not contain the given vertex.
bool pick_mate(const EggMesherStrip &a_strip, const EggMesherStrip &b_strip, const EggMesherEdge &a_edge, const EggMesherEdge &b_edge, const EggVertexPool *vertex_pool) const
Defines an ordering to select neighbors to mate with.
bool invert()
Reverses the facing of a quadstrip by reversing pairs of vertices.
bool is_odd() const
Returns true if the tristrip or quadstrip contains an odd number of pieces.
A collection of vertices.
Definition: eggVertexPool.h:46
bool pick_sheet_mate(const EggMesherStrip &a_strip, const EggMesherStrip &b_strip) const
Defines an ordering to select neighbors to follow when measuring out a quadsheet. ...
bool would_reverse_tail(PrimType want_type) const
Returns true if convert_to_type() would reverse the tail edge of the given strip, false otherwise...