Panda3D
Loading...
Searching...
No Matches
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
23class 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 */
30class EXPCL_PANDA_EGG EggMesherStrip {
31public:
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;
121 typedef plist<EggMesherEdge *> Edges;
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
147INLINE std::ostream &
148operator << (std::ostream &out, const EggMesherStrip &strip) {
149 strip.output(out);
150 return out;
151}
152
153#include "eggMesherStrip.I"
154
155#endif
Represents one edge of a triangle, as used by the EggMesher to discover connected triangles.
Represents a triangle strip or quad strip in progress, as assembled by the mesher.
EggMesherEdge get_tail_edge() const
Returns an EggMesherEdge which represents the trailing edge in the quadstrip or tristrip.
bool invert()
Reverses the facing of a quadstrip by reversing pairs of vertices.
void rotate_forward()
Rotates a triangle or quad by bringing its first vertex to the back.
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.
EggMesherEdge get_head_edge() const
Returns an EggMesherEdge which represents the leading edge in the quadstrip or tristrip.
void output_neighbors(std::ostream &out) const
Writes all the neighbor indexes to the ostream.
bool mate(const EggVertexPool *vertex_pool)
Finds a neighboring strip and joins up with it to make a larger strip.
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.
int count_neighbors() const
Returns the number of neighbors the strip shares.
int type_category() const
Returns an integer which gives a heuristic about the similarity of different strip types.
static bool mate_strips(EggMesherEdge *common_edge, EggMesherStrip &front, EggMesherStrip &back, PrimType type)
Stitches two strips together, producing in "front" a new strip of the indicated type (quadstrip or tr...
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 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 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.
static bool mate_pieces(EggMesherEdge *common_edge, EggMesherStrip &front, EggMesherStrip &back, const EggVertexPool *vertex_pool)
Connects two pieces of arbitrary type, if possible.
bool can_invert() const
Returns true if the strip can be inverted (reverse its facing direction).
PN_stdfloat coplanarity(const EggMesherStrip &other) const
Returns the degree to which the two strips are coplanar.
bool is_odd() const
Returns true if the tristrip or quadstrip contains an odd number of pieces.
const EggMesherEdge * find_opposite_edge(int vi) const
Returns the first edge found that does not contain the given vertex.
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,...
int find_uncommon_vertex(const EggMesherEdge *edge) const
Returns the first vertex found that is not shared by the given edge.
void output(std::ostream &out) const
Formats the vertex for output in some sensible way.
void rotate_to_front(const EggMesherEdge *edge)
Rotates a triangle or quad so that the given edge is first in the vertex list.
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.
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...
void rotate_to_back(const EggMesherEdge *edge)
Rotates a triangle or quad so that the given edge is last in the vertex list.
const EggMesherEdge * find_adjacent_edge(const EggMesherEdge *edge) const
Returns the first edge found that shares exactly one vertex with the given edge.
void convert_to_type(PrimType want_type)
Converts the EggMesherStrip from whatever form it is–triangle, quad, or quadstrip–into a tristrip or ...
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
A collection of vertices.
This is our own Panda specialization on the default STL list.
Definition plist.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.