Panda3D
eggMesherStrip.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 eggMesherStrip.h
10  * @author drose
11  * @date 2005-03-13
12  */
13 
14 #ifndef EGGMESHERSTRIP_H
15 #define EGGMESHERSTRIP_H
16 
17 #include "pandabase.h"
18 #include "eggVertexPool.h"
19 #include "eggPrimitive.h"
20 #include "eggMesherEdge.h"
21 #include "plist.h"
22 
23 class EggMesherEdge;
24 
25 /**
26  * Represents a triangle strip or quad strip in progress, as assembled by the
27  * mesher. It might also represent a single polygon such as a triangle or
28  * quad, since that's how strips generally start out.
29  */
30 class EXPCL_PANDA_EGG EggMesherStrip {
31 public:
32  enum PrimType {
33  PT_poly,
34  PT_point,
35  PT_line,
36  PT_tri,
37  PT_tristrip,
38  PT_trifan,
39  PT_quad,
40  PT_quadstrip,
41  PT_linestrip,
42  };
43 
44  enum MesherOrigin {
45  MO_unknown,
46  MO_user,
47  MO_firstquad,
48  MO_fanpoly,
49  MO_mate
50  };
51 
52  EggMesherStrip(PrimType prim_type, MesherOrigin origin);
53  EggMesherStrip(const EggPrimitive *prim, int index, const EggVertexPool *vertex_pool,
54  bool flat_shaded);
55  INLINE EggMesherStrip(const EggMesherStrip &copy);
56 
57  PT(EggPrimitive) make_prim(const EggVertexPool *vertex_pool);
58 
59  void measure_sheet(const EggMesherEdge *edge, int new_row,
60  int &num_prims, int &num_rows,
61  int first_row_id, int this_row_id,
62  int this_row_distance);
63  void cut_sheet(int first_row_id, int do_mate,
64  const EggVertexPool *vertex_pool);
65 
66  bool mate(const EggVertexPool *vertex_pool);
67  bool find_ideal_mate(EggMesherStrip *&mate, EggMesherEdge *&common_edge,
68  const EggVertexPool *vertex_pool);
69  static bool mate_pieces(EggMesherEdge *common_edge, EggMesherStrip &front,
70  EggMesherStrip &back, const EggVertexPool *vertex_pool);
71  static bool mate_strips(EggMesherEdge *common_edge, EggMesherStrip &front,
72  EggMesherStrip &back, PrimType type);
73  static bool must_invert(const EggMesherStrip &front, const EggMesherStrip &back,
74  bool will_reverse_back, PrimType type);
75  static bool convex_quad(EggMesherEdge *common_edge, EggMesherStrip &front,
76  EggMesherStrip &back, const EggVertexPool *vertex_pool);
77 
78  int count_neighbors() const;
79  void output_neighbors(std::ostream &out) const;
80 
81  INLINE bool is_coplanar_with(const EggMesherStrip &other, PN_stdfloat threshold) const;
82  INLINE PN_stdfloat coplanarity(const EggMesherStrip &other) const;
83  INLINE int type_category() const;
84 
85  int find_uncommon_vertex(const EggMesherEdge *edge) const;
86  const EggMesherEdge *find_opposite_edge(int vi) const;
87  const EggMesherEdge *find_opposite_edge(const EggMesherEdge *edge) const;
88  const EggMesherEdge *find_adjacent_edge(const EggMesherEdge *edge) const;
89 
90  INLINE void rotate_forward();
91  INLINE void rotate_back();
92  void rotate_to_front(const EggMesherEdge *edge);
93  void rotate_to_back(const EggMesherEdge *edge);
94  bool can_invert() const;
95  bool invert();
96 
97  INLINE EggMesherEdge get_head_edge() const;
98  INLINE EggMesherEdge get_tail_edge() const;
99 
100  bool is_odd() const;
101  bool would_reverse_tail(PrimType want_type) const;
102  void convert_to_type(PrimType want_type);
103 
104  void combine_edges(EggMesherStrip &other, int remove_sides);
105  void remove_all_edges();
106 
107  // ptr equality
108  INLINE bool operator == (const EggMesherStrip &other) const;
109  INLINE bool operator != (const EggMesherStrip &other) const;
110 
111  bool pick_mate(const EggMesherStrip &a_strip, const EggMesherStrip &b_strip,
112  const EggMesherEdge &a_edge, const EggMesherEdge &b_edge,
113  const EggVertexPool *vertex_pool) const;
114 
115  bool pick_sheet_mate(const EggMesherStrip &a_strip,
116  const EggMesherStrip &b_strip) const;
117 
118  void output(std::ostream &out) const;
119 
120  typedef plist<CPT(EggPrimitive) > Prims;
122  typedef plist<int> Verts;
123 
124  Prims _prims;
125  Edges _edges;
126  Verts _verts;
127 
128  enum MesherStatus {
129  MS_alive,
130  MS_dead,
131  MS_done,
132  MS_paired
133  };
134 
135  PrimType _type;
136  int _index;
137  MesherStatus _status;
138 
139  bool _planar;
140  LNormald _plane_normal;
141  PN_stdfloat _plane_offset;
142  int _row_id, _row_distance;
143  MesherOrigin _origin;
144  bool _flat_shaded;
145 };
146 
147 INLINE std::ostream &
148 operator << (std::ostream &out, const EggMesherStrip &strip) {
149  strip.output(out);
150  return out;
151 }
152 
153 #include "eggMesherStrip.I"
154 
155 #endif
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
Definition: eggPrimitive.h:47
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
void output(std::ostream &out) const
Formats the vertex for output in some sensible way.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Represents one edge of a triangle, as used by the EggMesher to discover connected triangles.
Definition: eggMesherEdge.h:29
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Represents a triangle strip or quad strip in progress, as assembled by the mesher.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A collection of vertices.
Definition: eggVertexPool.h:41