Panda3D
|
Represents a triangle strip or quad strip in progress, as assembled by the mesher. More...
#include "eggMesherStrip.h"
Public Types | |
typedef plist< EggMesherEdge * > | Edges |
enum | MesherOrigin { MO_unknown, MO_user, MO_firstquad, MO_fanpoly, MO_mate } |
enum | MesherStatus { MS_alive, MS_dead, MS_done, MS_paired } |
typedef plist< CPT(EggPrimitive) > | Prims |
enum | PrimType { PT_poly, PT_point, PT_line, PT_tri, PT_tristrip, PT_trifan, PT_quad, PT_quadstrip, PT_linestrip } |
typedef plist< int > | Verts |
Public Member Functions | |
EggMesherStrip (PrimType prim_type, MesherOrigin origin) | |
EggMesherStrip (const EggPrimitive *prim, int index, const EggVertexPool *vertex_pool, bool flat_shaded) | |
EggMesherStrip (const EggMesherStrip ©) | |
bool | can_invert () const |
Returns true if the strip can be inverted (reverse its facing direction). | |
void | combine_edges (EggMesherStrip &other, int remove_sides) |
Removes the edges from the given strip and appends them to our own. | |
void | convert_to_type (PrimType want_type) |
Converts the EggMesherStrip from whatever form it is--triangle, quad, or quadstrip--into a tristrip or quadstrip. | |
PN_stdfloat | coplanarity (const EggMesherStrip &other) const |
Returns the degree to which the two strips are coplanar. | |
int | count_neighbors () const |
Returns the number of neighbors the strip shares. | |
void | cut_sheet (int first_row_id, int do_mate, const EggVertexPool *vertex_pool) |
const EggMesherEdge * | find_adjacent_edge (const EggMesherEdge *edge) const |
Returns the first edge found that shares exactly one vertex with the given edge. | |
bool | find_ideal_mate (EggMesherStrip *&mate, EggMesherEdge *&common_edge, const EggVertexPool *vertex_pool) |
Searches our neighbors for the most suitable mate. | |
const EggMesherEdge * | find_opposite_edge (int vi) const |
Returns the first edge found that does not contain the given vertex. | |
const EggMesherEdge * | find_opposite_edge (const EggMesherEdge *edge) const |
Returns the first edge found that shares no vertices with the given edge. | |
int | find_uncommon_vertex (const EggMesherEdge *edge) const |
Returns the first vertex found that is not shared by the given edge. | |
EggMesherEdge | get_head_edge () const |
Returns an EggMesherEdge which represents the leading edge in the quadstrip or tristrip. | |
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. | |
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 | is_odd () const |
Returns true if the tristrip or quadstrip contains an odd number of pieces. | |
bool | mate (const EggVertexPool *vertex_pool) |
Finds a neighboring strip and joins up with it to make a larger strip. | |
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, and searching in the direction indicated by the given edge. | |
bool | operator!= (const EggMesherStrip &other) const |
bool | operator== (const EggMesherStrip &other) const |
Defines equality for strips. | |
void | output (ostream &out) const |
Formats the vertex for output in some sensible way. | |
void | output_neighbors (ostream &out) const |
Writes all the neighbor indexes to the ostream. | |
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. | |
PT (EggPrimitive) make_prim(const EggVertexPool *vertex_pool) | |
void | remove_all_edges () |
Removes all active edges from the strip. | |
void | rotate_back () |
Rotates a triangle or quad by bringing its last vertex to the front. | |
void | rotate_forward () |
Rotates a triangle or quad by bringing its first vertex to the back. | |
void | rotate_to_back (const EggMesherEdge *edge) |
Rotates a triangle or quad so that the given edge is last in the vertex list. | |
void | rotate_to_front (const EggMesherEdge *edge) |
Rotates a triangle or quad so that the given edge is first in the vertex list. | |
int | type_category () const |
Returns an integer which gives a heuristic about the similarity of different strip types. | |
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. | |
Static Public Member Functions | |
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_edge is convex, false otherwise. | |
static bool | mate_pieces (EggMesherEdge *common_edge, EggMesherStrip &front, EggMesherStrip &back, const EggVertexPool *vertex_pool) |
Connects two pieces of arbitrary type, if possible. | |
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 tristrip). | |
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. | |
Public Attributes | |
Edges | _edges |
bool | _flat_shaded |
int | _index |
MesherOrigin | _origin |
bool | _planar |
LNormald | _plane_normal |
PN_stdfloat | _plane_offset |
Prims | _prims |
int | _row_distance |
int | _row_id |
MesherStatus | _status |
PrimType | _type |
Verts | _verts |
Represents a triangle strip or quad strip in progress, as assembled by the mesher.
It might also represent a single polygon such as a triangle or quad, since that's how strips generally start out.
Definition at line 33 of file eggMesherStrip.h.
bool EggMesherStrip::can_invert | ( | ) | const |
Returns true if the strip can be inverted (reverse its facing direction).
Generally, this is true for quadstrips and false for tristrips.
Definition at line 1096 of file eggMesherStrip.cxx.
Referenced by invert(), and mate_strips().
void EggMesherStrip::combine_edges | ( | EggMesherStrip & | other, |
int | remove_sides | ||
) |
Removes the edges from the given strip and appends them to our own.
If remove_sides is true, then removes all the edges except the head and the tail.
Definition at line 1282 of file eggMesherStrip.cxx.
References get_head_edge(), get_tail_edge(), and is_odd().
Referenced by mate_pieces().
void EggMesherStrip::convert_to_type | ( | EggMesherStrip::PrimType | want_type | ) |
Converts the EggMesherStrip from whatever form it is--triangle, quad, or quadstrip--into a tristrip or quadstrip.
Definition at line 1211 of file eggMesherStrip.cxx.
Referenced by mate_strips().
bool EggMesherStrip::convex_quad | ( | EggMesherEdge * | common_edge, |
EggMesherStrip & | front, | ||
EggMesherStrip & | back, | ||
const EggVertexPool * | vertex_pool | ||
) | [static] |
Returns true if the quad that would be formed by connecting coplanar tris front and back along common_edge is convex, false otherwise.
Definition at line 805 of file eggMesherStrip.cxx.
References find_uncommon_vertex(), EggVertex::get_pos3(), and EggVertexPool::get_vertex().
Referenced by mate_pieces().
PN_stdfloat EggMesherStrip::coplanarity | ( | const EggMesherStrip & | other | ) | const [inline] |
Returns the degree to which the two strips are coplanar.
0.0 is exactly coplanar; numbers somewhat larger than zero indicate less coplanar. 1.0 is at right angles; 2.0 is exactly backfacing. If either strip is not itself planar, 3.0 is returned.
Definition at line 59 of file eggMesherStrip.I.
Referenced by is_coplanar_with(), and pick_mate().
int EggMesherStrip::count_neighbors | ( | ) | const |
Returns the number of neighbors the strip shares.
Definition at line 883 of file eggMesherStrip.cxx.
Referenced by output(), and pick_mate().
const EggMesherEdge * EggMesherStrip::find_adjacent_edge | ( | const EggMesherEdge * | edge | ) | const |
Returns the first edge found that shares exactly one vertex with the given edge.
In a quad, this will be one of two edges adjacent to the given edge.
Definition at line 988 of file eggMesherStrip.cxx.
References EggMesherEdge::contains_vertex().
bool EggMesherStrip::find_ideal_mate | ( | EggMesherStrip *& | mate, |
EggMesherEdge *& | common_edge, | ||
const EggVertexPool * | vertex_pool | ||
) |
Searches our neighbors for the most suitable mate.
Returns true if one is found, false if we have no neighbors.
Definition at line 449 of file eggMesherStrip.cxx.
References pick_mate().
Referenced by mate().
const EggMesherEdge * EggMesherStrip::find_opposite_edge | ( | int | vi | ) | const |
Returns the first edge found that does not contain the given vertex.
In a tri, this will be the edge opposite the given vertex.
Definition at line 945 of file eggMesherStrip.cxx.
References EggMesherEdge::contains_vertex().
const EggMesherEdge * EggMesherStrip::find_opposite_edge | ( | const EggMesherEdge * | edge | ) | const |
Returns the first edge found that shares no vertices with the given edge.
In a quad, this will be the edge opposite the given edge.
Definition at line 965 of file eggMesherStrip.cxx.
References EggMesherEdge::contains_vertex().
int EggMesherStrip::find_uncommon_vertex | ( | const EggMesherEdge * | edge | ) | const |
Returns the first vertex found that is not shared by the given edge.
Definition at line 919 of file eggMesherStrip.cxx.
Referenced by convex_quad(), and mate_pieces().
EggMesherEdge EggMesherStrip::get_head_edge | ( | ) | const [inline] |
Returns an EggMesherEdge which represents the leading edge in the quadstrip or tristrip.
This EggMesherEdge will not have pointer equality with any shared EggMesherEdge.
Definition at line 126 of file eggMesherStrip.I.
Referenced by combine_edges(), and mate_strips().
EggMesherEdge EggMesherStrip::get_tail_edge | ( | ) | const [inline] |
Returns an EggMesherEdge which represents the trailing edge in the quadstrip or tristrip.
This EggMesherEdge will not have pointer equality with any shared EggMesherEdge.
Definition at line 142 of file eggMesherStrip.I.
Referenced by combine_edges(), and mate_strips().
bool EggMesherStrip::invert | ( | ) |
Reverses the facing of a quadstrip by reversing pairs of vertices.
Returns true if successful, false if failure (for instance, on a tristrip).
Definition at line 1108 of file eggMesherStrip.cxx.
References can_invert().
Referenced by mate_strips(), and must_invert().
bool EggMesherStrip::is_coplanar_with | ( | const EggMesherStrip & | other, |
PN_stdfloat | threshold | ||
) | const [inline] |
Returns true if the strip and the other strip are coplanar, within the indicated threshold.
See coplanarity().
Definition at line 45 of file eggMesherStrip.I.
References coplanarity().
Referenced by mate_pieces().
bool EggMesherStrip::is_odd | ( | ) | const |
Returns true if the tristrip or quadstrip contains an odd number of pieces.
Definition at line 1138 of file eggMesherStrip.cxx.
Referenced by combine_edges(), mate_strips(), and must_invert().
bool EggMesherStrip::mate | ( | const EggVertexPool * | vertex_pool | ) |
Finds a neighboring strip and joins up with it to make a larger strip.
Returns true if mating was successful or at least possible, false if the strip has no neighbors.
Definition at line 416 of file eggMesherStrip.cxx.
References find_ideal_mate(), and mate_pieces().
Referenced by measure_sheet().
bool EggMesherStrip::mate_pieces | ( | EggMesherEdge * | common_edge, |
EggMesherStrip & | front, | ||
EggMesherStrip & | back, | ||
const EggVertexPool * | vertex_pool | ||
) | [static] |
Connects two pieces of arbitrary type, if possible.
Returns true if successful, false if failure.
Definition at line 483 of file eggMesherStrip.cxx.
References combine_edges(), EggMesherEdge::contains_vertex(), convex_quad(), find_uncommon_vertex(), is_coplanar_with(), mate_strips(), EggMesherEdge::remove(), and rotate_to_back().
Referenced by mate().
bool EggMesherStrip::mate_strips | ( | EggMesherEdge * | common_edge, |
EggMesherStrip & | front, | ||
EggMesherStrip & | back, | ||
EggMesherStrip::PrimType | type | ||
) | [static] |
Stitches two strips together, producing in "front" a new strip of the indicated type (quadstrip or tristrip).
The front strip stores the result, and the back strip is emptied on success.
Returns true if successful, false if failure (generally because of incorrect polarity of tristrips), in which case nothing has changed (or at least, not much).
Definition at line 634 of file eggMesherStrip.cxx.
References can_invert(), convert_to_type(), get_head_edge(), get_tail_edge(), invert(), is_odd(), EggMesherEdge::matches(), must_invert(), rotate_to_back(), rotate_to_front(), and would_reverse_tail().
Referenced by mate_pieces().
void EggMesherStrip::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, and searching in the direction indicated by the given edge.
Definition at line 184 of file eggMesherStrip.cxx.
References mate(), measure_sheet(), and pick_sheet_mate().
Referenced by measure_sheet().
bool EggMesherStrip::must_invert | ( | const EggMesherStrip & | front, |
const EggMesherStrip & | back, | ||
bool | will_reverse_back, | ||
EggMesherStrip::PrimType | type | ||
) | [static] |
Returns false if the strips can be mated as they currently are.
Returns true if the back strip must be inverted first.
Definition at line 769 of file eggMesherStrip.cxx.
References invert(), and is_odd().
Referenced by mate_strips().
bool EggMesherStrip::operator== | ( | const EggMesherStrip & | other | ) | const [inline] |
Defines equality for strips.
This actually tests only pointer equality; it's used only when removing a strip from the list.
Definition at line 157 of file eggMesherStrip.I.
void EggMesherStrip::output | ( | ostream & | out | ) | const |
Formats the vertex for output in some sensible way.
Definition at line 1446 of file eggMesherStrip.cxx.
References count_neighbors(), and output_neighbors().
void EggMesherStrip::output_neighbors | ( | ostream & | out | ) | const |
Writes all the neighbor indexes to the ostream.
Definition at line 899 of file eggMesherStrip.cxx.
Referenced by output().
bool EggMesherStrip::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.
This compares strip a with strip b and returns true if strip a is the preferable choice, false if strip b.
Definition at line 1358 of file eggMesherStrip.cxx.
References EggMesherEdge::compute_length(), coplanarity(), count_neighbors(), and type_category().
Referenced by find_ideal_mate().
bool EggMesherStrip::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.
This is only called when three or more prims share a single edge, which should be rarely--generally only when coplanar polys are going on.
Definition at line 1416 of file eggMesherStrip.cxx.
References type_category().
Referenced by measure_sheet().
void EggMesherStrip::remove_all_edges | ( | ) |
Removes all active edges from the strip.
This effectively renders it ineligible to mate with anything else.
Definition at line 1336 of file eggMesherStrip.cxx.
void EggMesherStrip::rotate_back | ( | ) | [inline] |
Rotates a triangle or quad by bringing its last vertex to the front.
Definition at line 111 of file eggMesherStrip.I.
Referenced by rotate_to_back(), and rotate_to_front().
void EggMesherStrip::rotate_forward | ( | ) | [inline] |
Rotates a triangle or quad by bringing its first vertex to the back.
Definition at line 99 of file eggMesherStrip.I.
Referenced by rotate_to_back(), and rotate_to_front().
void EggMesherStrip::rotate_to_back | ( | const EggMesherEdge * | edge | ) |
Rotates a triangle or quad so that the given edge is last in the vertex list.
Definition at line 1052 of file eggMesherStrip.cxx.
References rotate_back(), and rotate_forward().
Referenced by mate_pieces(), and mate_strips().
void EggMesherStrip::rotate_to_front | ( | const EggMesherEdge * | edge | ) |
Rotates a triangle or quad so that the given edge is first in the vertex list.
Definition at line 1010 of file eggMesherStrip.cxx.
References rotate_back(), and rotate_forward().
Referenced by mate_strips().
int EggMesherStrip::type_category | ( | ) | const [inline] |
Returns an integer which gives a heuristic about the similarity of different strip types.
In general, closer numbers are more similar.
Definition at line 74 of file eggMesherStrip.I.
Referenced by pick_mate(), and pick_sheet_mate().
bool EggMesherStrip::would_reverse_tail | ( | EggMesherStrip::PrimType | want_type | ) | const |
Returns true if convert_to_type() would reverse the tail edge of the given strip, false otherwise.
Definition at line 1157 of file eggMesherStrip.cxx.
Referenced by mate_strips().