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). More... | |
void | combine_edges (EggMesherStrip &other, int remove_sides) |
Removes the edges from the given strip and appends them to our own. More... | |
void | convert_to_type (PrimType want_type) |
Converts the EggMesherStrip from whatever form it is–triangle, quad, or quadstrip–into a tristrip or quadstrip. More... | |
PN_stdfloat | coplanarity (const EggMesherStrip &other) const |
Returns the degree to which the two strips are coplanar. More... | |
int | count_neighbors () const |
Returns the number of neighbors the strip shares. More... | |
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. More... | |
bool | find_ideal_mate (EggMesherStrip *&mate, EggMesherEdge *&common_edge, const EggVertexPool *vertex_pool) |
Searches our neighbors for the most suitable mate. More... | |
const EggMesherEdge * | find_opposite_edge (int vi) const |
Returns the first edge found that does not contain the given vertex. More... | |
const EggMesherEdge * | find_opposite_edge (const EggMesherEdge *edge) const |
Returns the first edge found that shares no vertices with the given edge. More... | |
int | find_uncommon_vertex (const EggMesherEdge *edge) const |
Returns the first vertex found that is not shared by the given edge. More... | |
EggMesherEdge | get_head_edge () const |
Returns an EggMesherEdge which represents the leading edge in the quadstrip or tristrip. More... | |
EggMesherEdge | get_tail_edge () const |
Returns an EggMesherEdge which represents the trailing edge in the quadstrip or tristrip. More... | |
bool | invert () |
Reverses the facing of a quadstrip by reversing pairs of vertices. More... | |
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. More... | |
bool | is_odd () const |
Returns true if the tristrip or quadstrip contains an odd number of pieces. More... | |
bool | mate (const EggVertexPool *vertex_pool) |
Finds a neighboring strip and joins up with it to make a larger strip. More... | |
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. More... | |
bool | operator!= (const EggMesherStrip &other) const |
bool | operator== (const EggMesherStrip &other) const |
Defines equality for strips. More... | |
void | output (ostream &out) const |
Formats the vertex for output in some sensible way. More... | |
void | output_neighbors (ostream &out) const |
Writes all the neighbor indexes to the ostream. More... | |
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. More... | |
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. More... | |
PT (EggPrimitive) make_prim(const EggVertexPool *vertex_pool) | |
void | remove_all_edges () |
Removes all active edges from the strip. More... | |
void | rotate_back () |
Rotates a triangle or quad by bringing its last vertex to the front. More... | |
void | rotate_forward () |
Rotates a triangle or quad by bringing its first vertex to the back. More... | |
void | rotate_to_back (const EggMesherEdge *edge) |
Rotates a triangle or quad so that the given edge is last in the vertex list. More... | |
void | rotate_to_front (const EggMesherEdge *edge) |
Rotates a triangle or quad so that the given edge is first in the vertex list. More... | |
int | type_category () const |
Returns an integer which gives a heuristic about the similarity of different strip types. More... | |
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. More... | |
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. More... | |
static bool | mate_pieces (EggMesherEdge *common_edge, EggMesherStrip &front, EggMesherStrip &back, const EggVertexPool *vertex_pool) |
Connects two pieces of arbitrary type, if possible. More... | |
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). More... | |
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. More... | |
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.
References invert().
Referenced by invert(), mate_strips(), and rotate_to_back().
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(), is_odd(), and remove_all_edges().
Referenced by convert_to_type(), and 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.
References combine_edges().
Referenced by mate_strips(), and would_reverse_tail().
|
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 count_neighbors(), find_uncommon_vertex(), EggVertex::get_pos3(), and EggVertexPool::get_vertex().
Referenced by mate_pieces(), and must_invert().
|
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.
References type_category().
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.
References output_neighbors().
Referenced by convex_quad(), 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(), and rotate_to_front().
Referenced by find_opposite_edge().
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 mate_pieces(), and pick_mate().
Referenced by mate(), and EggMesher::mesh().
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().
Referenced by find_uncommon_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(), and find_adjacent_edge().
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.
References find_opposite_edge().
Referenced by convex_quad(), mate_pieces(), and output_neighbors().
|
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.
References get_tail_edge().
Referenced by combine_edges(), mate_strips(), and rotate_back().
|
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.
References operator==().
Referenced by combine_edges(), get_head_edge(), 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(), and is_odd().
Referenced by can_invert(), mate_strips(), and must_invert().
|
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.
References would_reverse_tail().
Referenced by combine_edges(), invert(), 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().
|
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 find_ideal_mate(), mate(), measure_sheet(), and EggMesher::mesh().
|
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(), mate_pieces(), measure_sheet(), and pick_sheet_mate().
Referenced by measure_sheet().
|
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 convex_quad(), invert(), and is_odd().
Referenced by mate_strips().
|
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.
Referenced by get_tail_edge().
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().
Referenced by pick_sheet_mate().
void EggMesherStrip::output_neighbors | ( | ostream & | out | ) | const |
Writes all the neighbor indexes to the ostream.
Definition at line 899 of file eggMesherStrip.cxx.
References find_uncommon_vertex().
Referenced by count_neighbors(), and 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(), pick_sheet_mate(), and type_category().
Referenced by find_ideal_mate(), and remove_all_edges().
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 output(), and type_category().
Referenced by measure_sheet(), and pick_mate().
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.
References pick_mate().
Referenced by combine_edges().
|
inline |
Rotates a triangle or quad by bringing its last vertex to the front.
Definition at line 111 of file eggMesherStrip.I.
References get_head_edge().
Referenced by rotate_forward(), rotate_to_back(), and rotate_to_front().
|
inline |
Rotates a triangle or quad by bringing its first vertex to the back.
Definition at line 99 of file eggMesherStrip.I.
References rotate_back().
Referenced by rotate_to_back(), rotate_to_front(), and type_category().
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 can_invert(), rotate_back(), and rotate_forward().
Referenced by mate_pieces(), mate_strips(), and rotate_to_front().
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(), rotate_forward(), and rotate_to_back().
Referenced by find_adjacent_edge(), and mate_strips().
|
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.
References rotate_forward().
Referenced by coplanarity(), 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.
References convert_to_type().
Referenced by is_odd(), and mate_strips().