Panda3D
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends

EggVertexPool Class Reference

A collection of vertices. More...

#include "eggVertexPool.h"

Inheritance diagram for EggVertexPool:
EggNode EggNamedObject EggObject Namable TypedReferenceCount MemoryBase TypedObject ReferenceCount MemoryBase MemoryBase

List of all members.

Public Types

typedef iterator const_iterator
typedef
second_of_pair_iterator
< IndexVertices::const_iterator > 
iterator
typedef IndexVertices::size_type size_type

Public Member Functions

 EggVertexPool (const string &name)
 EggVertexPool (const EggVertexPool &copy)
 Copying a vertex pool is of questionable value, since it will copy all of the vertices and assign new pointers to them all.
void add_unused_vertices_to_prim (EggPrimitive *prim)
 Adds all of the unused vertices in this vertex pool to the indicated primitive, in ascending order.
EggVertexadd_vertex (EggVertex *vertex, int index=-1)
 Adds the indicated vertex to the pool.
iterator begin () const
 Returns an iterator that can be used to traverse through all the vertices in the pool.
void check_overall_color (bool &has_overall_color, LColor &overall_color) const
 Scans the vertex pool for different colors on different vertices.
EggVertexcreate_unique_vertex (const EggVertex &copy)
 Creates a new vertex in the pool that is a copy of the indicated one and returns it.
bool empty () const
 Returns true if the pool is empty.
iterator end () const
 Returns an iterator that can be used to traverse through all the vertices in the pool.
EggVertexfind_matching_vertex (const EggVertex &copy)
 If the EggVertexPool already has a vertex matching the indicated vertex, returns it; otherwise, returns NULL.
virtual TypeHandle force_init_type ()
void get_aux_names (vector_string &aux_names) const
 Returns the list of auxiliary data names that are defined by any vertices in the pool.
EggVertexget_forward_vertex (int index)
 Returns the vertex in the pool with the indicated index number.
int get_highest_index () const
 Returns the highest index number used by any vertex in the pool (except forward references).
int get_num_dimensions () const
 Returns the maximum number of dimensions used by any vertex in the pool.
virtual TypeHandle get_type () const
void get_uv_names (vector_string &uv_names, vector_string &uvw_names, vector_string &tbn_names) const
 Returns the list of UV names that are defined by any vertices in the pool, as well as the subset of UV names that actually define 3-d texture coordinates ("uvw_names").
EggVertexget_vertex (int index) const
 Returns the vertex in the pool with the indicated index number, or NULL if no vertices have that index number.
bool has_aux () const
 Returns true if any vertex in the pool has auxiliary data defined, false if none of them do.
bool has_colors () const
 Returns true if any vertex in the pool has a color defined, false if none of them do.
bool has_defined_vertices () const
 Returns true if any vertices in the pool are fully defined vertices, false if all vertices are forward references.
bool has_forward_vertices () const
 Returns true if any vertices in the pool are undefined forward-reference vertices, false if all vertices are defined.
bool has_nonwhite_colors () const
 Returns true if any vertex in the pool has a color defined other than white, false if no vertices have colors, or if all colors are white.
bool has_normals () const
 Returns true if any vertex in the pool has a normal defined, false if none of them do.
bool has_uvs () const
 Returns true if any vertex in the pool has a uv defined, false if none of them do.
bool has_vertex (int index) const
 Returns true if the indicated vertex has been defined in the vertex pool, false otherwise.
EggVertexmake_new_vertex (double pos)
 Allocates and returns a new vertex from the pool.
EggVertexmake_new_vertex (const LPoint3d &pos)
 Allocates and returns a new vertex from the pool.
EggVertexmake_new_vertex (const LPoint4d &pos)
 Allocates and returns a new vertex from the pool.
EggVertexmake_new_vertex (const LPoint2d &pos)
 Allocates and returns a new vertex from the pool.
EggVertexmake_new_vertex ()
 Allocates and returns a new vertex from the pool.
EggVertexoperator[] (int index) const
 Returns the vertex in the pool with the indicated index number, or NULL if no vertices have that index number.
int remove_unused_vertices ()
 Removes all vertices from the pool that are not referenced by at least one primitive.
void remove_vertex (EggVertex *vertex)
 Removes the vertex from the pool.
void set_highest_index (int highest_index)
 Artificially changes the "highest index number", so that a newly created vertex will begin at this number plus 1.
size_type size () const
 Returns the number of vertices in the pool.
void sort_by_external_index ()
 Re-orders (and re-numbers) the vertices in this vertex pool so that they appear in increasing order by the optional external_index that has been assigned to each vertex.
void transform (const LMatrix4d &mat)
 Applies the indicated transformation matrix to all the vertices.
void write (ostream &out, int indent_level) const
 Writes the vertex pool to the indicated output stream in Egg format.

Static Public Member Functions

static TypeHandle get_class_type ()
static void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96.

Protected Member Functions

virtual void r_transform (const LMatrix4d &mat, const LMatrix4d &inv, CoordinateSystem to_cs)
 This is called from within the egg code by transform().
virtual void r_transform_vertices (const LMatrix4d &mat)
 This is called from within the egg code by transform_vertices_only()().

Friends

class EggVertex

Detailed Description

A collection of vertices.

There may be any number of vertex pools in a single egg structure. The vertices in a single pool need not necessarily have any connection to each other, but it is necessary that any one primitive (e.g. a polygon) must pull all its vertices from the same pool.

An EggVertexPool is an STL-style container of pointers to EggVertex's. Functions add_vertex() and remove_vertex() are provided to manipulate the list. The list may also be operated on (read-only) via iterators and begin()/end().

Definition at line 46 of file eggVertexPool.h.


Constructor & Destructor Documentation

EggVertexPool::EggVertexPool ( const EggVertexPool copy)

Copying a vertex pool is of questionable value, since it will copy all of the vertices and assign new pointers to them all.

There will be no polygons referring to the new vertices.

Definition at line 45 of file eggVertexPool.cxx.

References add_vertex(), begin(), end(), and EggVertex::get_index().


Member Function Documentation

void EggVertexPool::add_unused_vertices_to_prim ( EggPrimitive prim)

Adds all of the unused vertices in this vertex pool to the indicated primitive, in ascending order.

Definition at line 708 of file eggVertexPool.cxx.

References EggPrimitive::add_vertex(), and EggVertex::pref_size().

Referenced by EggGroupNode::make_point_primitives().

EggVertex * EggVertexPool::add_vertex ( EggVertex vertex,
int  index = -1 
)

Adds the indicated vertex to the pool.

It is an error if the vertex is already a member of this or any other pool. The vertex must have been allocated from the free store; its pointer will now be owned by the vertex pool. If the index number is supplied, tries to assign that index number; it is an error if the index number is already in use.

It is possible that a forward reference to this vertex was requested in the past; if so, the data from the supplied vertex is copied onto the forward reference, which becomes the actual vertex. In this case, a different pointer is saved (and returned) than the one actually passed in. In the usual case, however, the vertex pointer passed in is the one that is saved in the vertex pool and returned from this method.

Definition at line 484 of file eggVertexPool.cxx.

References get_highest_index(), and EggVertex::is_forward_reference().

Referenced by create_unique_vertex(), EggVertexPool(), get_forward_vertex(), make_new_vertex(), and EggMesherFanMaker::unroll().

EggVertexPool::iterator EggVertexPool::begin ( ) const

Returns an iterator that can be used to traverse through all the vertices in the pool.

Definition at line 424 of file eggVertexPool.cxx.

Referenced by XFileMesh::create_polygons(), EggVertexPool(), SoftToEggConverter::FindClosestTriVert(), SoftNodeDesc::make_vertex_offsets(), sort_by_external_index(), transform(), and write().

void EggVertexPool::check_overall_color ( bool &  has_overall_color,
LColor overall_color 
) const

Scans the vertex pool for different colors on different vertices.

If all vertices are the same color, sets has_overall_color to true and fills the color into overall_color. If no vertices have any color, set has_overall_color to true and fills white into overall_color. If at least two vertices have different colors, sets has_overall_color to false.

Definition at line 286 of file eggVertexPool.cxx.

References LVecBase4f::almost_equal(), empty(), and EggAttributes::get_color().

Referenced by EggLoader::make_polyset().

EggVertex * EggVertexPool::create_unique_vertex ( const EggVertex copy)

Creates a new vertex in the pool that is a copy of the indicated one and returns it.

If there is already a vertex in the pool like the indicated one, simply returns that one.

Definition at line 537 of file eggVertexPool.cxx.

References add_vertex().

Referenced by XFileMesh::create_polygons(), EggPrimitive::do_apply_flat_attribute(), EggPrimitive::r_apply_texmats(), EggPrimitive::r_flatten_transforms(), EggGroupNode::rebuild_vertex_pools(), EggGroupNode::recompute_polygon_normals(), EggGroupNode::strip_normals(), EggPrimitive::unify_attributes(), and EggCompositePrimitive::unify_attributes().

bool EggVertexPool::empty ( ) const

Returns true if the pool is empty.

Definition at line 447 of file eggVertexPool.cxx.

Referenced by check_overall_color(), and EggGroupNode::remove_unused_vertices().

EggVertexPool::iterator EggVertexPool::end ( ) const

Returns an iterator that can be used to traverse through all the vertices in the pool.

Definition at line 437 of file eggVertexPool.cxx.

Referenced by XFileMesh::create_polygons(), EggVertexPool(), SoftToEggConverter::FindClosestTriVert(), SoftNodeDesc::make_vertex_offsets(), sort_by_external_index(), transform(), and write().

EggVertex * EggVertexPool::find_matching_vertex ( const EggVertex copy)

If the EggVertexPool already has a vertex matching the indicated vertex, returns it; otherwise, returns NULL.

This is similar to create_unique_vertex() except that a new vertex is never created.

Definition at line 559 of file eggVertexPool.cxx.

Referenced by EggGroupNode::rebuild_vertex_pools().

void EggVertexPool::get_aux_names ( vector_string &  aux_names) const

Returns the list of auxiliary data names that are defined by any vertices in the pool.

Definition at line 399 of file eggVertexPool.cxx.

References EggVertex::aux_begin(), and EggVertex::aux_end().

EggVertex * EggVertexPool::get_forward_vertex ( int  index)

Returns the vertex in the pool with the indicated index number.

If there is not a vertex in the pool with the indicated index number, creates a special forward-reference EggVertex that has no data, on the assumption that the vertex pool has not yet been fully read and more data will be available later.

Definition at line 155 of file eggVertexPool.cxx.

References add_vertex().

int EggVertexPool::get_highest_index ( ) const

Returns the highest index number used by any vertex in the pool (except forward references).

Returns -1 if the pool is empty.

Definition at line 177 of file eggVertexPool.cxx.

Referenced by add_vertex().

int EggVertexPool::get_num_dimensions ( ) const

Returns the maximum number of dimensions used by any vertex in the pool.

Definition at line 202 of file eggVertexPool.cxx.

References EggVertex::get_num_dimensions().

void EggVertexPool::get_uv_names ( vector_string &  uv_names,
vector_string &  uvw_names,
vector_string &  tbn_names 
) const

Returns the list of UV names that are defined by any vertices in the pool, as well as the subset of UV names that actually define 3-d texture coordinates ("uvw_names").

Also returns the subset of UV/UVW names that define a tangent and binormal. It is the user's responsibility to clear both vectors before calling this method.

Definition at line 361 of file eggVertexPool.cxx.

References EggVertexUV::has_w(), EggVertex::uv_begin(), and EggVertex::uv_end().

EggVertex * EggVertexPool::get_vertex ( int  index) const

Returns the vertex in the pool with the indicated index number, or NULL if no vertices have that index number.

Definition at line 130 of file eggVertexPool.cxx.

References EggVertex::is_forward_reference().

Referenced by EggMesherFanMaker::compute_angle(), EggMesherEdge::compute_box(), EggMesherEdge::compute_length(), EggMesherStrip::convex_quad(), has_vertex(), operator[](), remove_vertex(), and EggMesherFanMaker::unroll().

bool EggVertexPool::has_aux ( ) const

Returns true if any vertex in the pool has auxiliary data defined, false if none of them do.

Definition at line 337 of file eggVertexPool.cxx.

References EggVertex::has_aux().

bool EggVertexPool::has_colors ( ) const

Returns true if any vertex in the pool has a color defined, false if none of them do.

Definition at line 240 of file eggVertexPool.cxx.

bool EggVertexPool::has_defined_vertices ( ) const

Returns true if any vertices in the pool are fully defined vertices, false if all vertices are forward references.

Definition at line 110 of file eggVertexPool.cxx.

References EggVertex::is_forward_reference().

bool EggVertexPool::has_forward_vertices ( ) const

Returns true if any vertices in the pool are undefined forward-reference vertices, false if all vertices are defined.

Definition at line 90 of file eggVertexPool.cxx.

References EggVertex::is_forward_reference().

bool EggVertexPool::has_nonwhite_colors ( ) const

Returns true if any vertex in the pool has a color defined other than white, false if no vertices have colors, or if all colors are white.

Definition at line 260 of file eggVertexPool.cxx.

References EggAttributes::get_color().

bool EggVertexPool::has_normals ( ) const [virtual]

Returns true if any vertex in the pool has a normal defined, false if none of them do.

Reimplemented from EggNode.

Definition at line 221 of file eggVertexPool.cxx.

bool EggVertexPool::has_uvs ( ) const

Returns true if any vertex in the pool has a uv defined, false if none of them do.

Definition at line 318 of file eggVertexPool.cxx.

References EggVertex::has_uv().

bool EggVertexPool::has_vertex ( int  index) const [inline]

Returns true if the indicated vertex has been defined in the vertex pool, false otherwise.

This does not include forward references.

Definition at line 24 of file eggVertexPool.I.

References get_vertex().

static void EggVertexPool::init_type ( ) [inline, static]

This function is declared non-inline to work around a compiler bug in g++ 2.96.

Making it inline seems to cause problems in the optimizer.

Reimplemented from EggNode.

Definition at line 156 of file eggVertexPool.h.

References EggNode::init_type().

EggVertex * EggVertexPool::make_new_vertex ( const LPoint4d pos) [inline]

Allocates and returns a new vertex from the pool.

This is one of three ways to add new vertices to a vertex pool.

This flavor of make_new_vertex() explicitly sets the vertex position as it is allocated. It does not attempt to share vertices.

Definition at line 119 of file eggVertexPool.I.

References make_new_vertex(), and EggVertex::set_pos().

EggVertex * EggVertexPool::make_new_vertex ( double  pos) [inline]

Allocates and returns a new vertex from the pool.

This is one of three ways to add new vertices to a vertex pool.

This flavor of make_new_vertex() explicitly sets the vertex position as it is allocated. It does not attempt to share vertices.

Definition at line 65 of file eggVertexPool.I.

References make_new_vertex(), and EggVertex::set_pos().

EggVertex * EggVertexPool::make_new_vertex ( ) [inline]

Allocates and returns a new vertex from the pool.

This is one of three ways to add new vertices to a vertex pool.

Definition at line 48 of file eggVertexPool.I.

References add_vertex().

Referenced by make_new_vertex().

EggVertex * EggVertexPool::make_new_vertex ( const LPoint2d pos) [inline]

Allocates and returns a new vertex from the pool.

This is one of three ways to add new vertices to a vertex pool.

This flavor of make_new_vertex() explicitly sets the vertex position as it is allocated. It does not attempt to share vertices.

Definition at line 83 of file eggVertexPool.I.

References make_new_vertex(), and EggVertex::set_pos().

EggVertex * EggVertexPool::make_new_vertex ( const LPoint3d pos) [inline]

Allocates and returns a new vertex from the pool.

This is one of three ways to add new vertices to a vertex pool.

This flavor of make_new_vertex() explicitly sets the vertex position as it is allocated. It does not attempt to share vertices.

Definition at line 101 of file eggVertexPool.I.

References make_new_vertex(), and EggVertex::set_pos().

EggVertex * EggVertexPool::operator[] ( int  index) const [inline]

Returns the vertex in the pool with the indicated index number, or NULL if no vertices have that index number.

Definition at line 36 of file eggVertexPool.I.

References get_vertex().

void EggVertexPool::r_transform ( const LMatrix4d mat,
const LMatrix4d inv,
CoordinateSystem  to_cs 
) [protected, virtual]

This is called from within the egg code by transform().

It applies a transformation matrix to the current node in some sensible way, then continues down the tree.

The first matrix is the transformation to apply; the second is its inverse. The third parameter is the coordinate system we are changing to, or CS_default if we are not changing coordinate systems.

Reimplemented from EggNode.

Definition at line 884 of file eggVertexPool.cxx.

void EggVertexPool::r_transform_vertices ( const LMatrix4d mat) [protected, virtual]

This is called from within the egg code by transform_vertices_only()().

It applies a transformation matrix to the current node in some sensible way (if the current node is a vertex pool with vertices), then continues down the tree.

Reimplemented from EggNode.

Definition at line 897 of file eggVertexPool.cxx.

References transform().

int EggVertexPool::remove_unused_vertices ( )

Removes all vertices from the pool that are not referenced by at least one primitive.

Also collapses together equivalent vertices, and renumbers all vertices after the operation so their indices are consecutive, beginning at zero. Returns the number of vertices removed.

Definition at line 640 of file eggVertexPool.cxx.

References EggVertex::clear_grefs(), EggPrimitive::find(), EggVertex::pref_size(), and EggPrimitive::replace().

Referenced by EggLoader::make_polyset(), and EggGroupNode::remove_unused_vertices().

void EggVertexPool::remove_vertex ( EggVertex vertex)

Removes the vertex from the pool.

It is an error if the vertex is not already a member of the pool.

Definition at line 580 of file eggVertexPool.cxx.

References get_vertex().

void EggVertexPool::set_highest_index ( int  highest_index)

Artificially changes the "highest index number", so that a newly created vertex will begin at this number plus 1.

This can be used to default a vertex pool to start counting at 1 (or any other index number), instead of the default of 0. Use with caution.

Definition at line 191 of file eggVertexPool.cxx.

EggVertexPool::size_type EggVertexPool::size ( ) const
void EggVertexPool::sort_by_external_index ( )

Re-orders (and re-numbers) the vertices in this vertex pool so that they appear in increasing order by the optional external_index that has been assigned to each vertex.

Definition at line 825 of file eggVertexPool.cxx.

References begin(), end(), and size().

Referenced by EggLoader::make_polyset().

void EggVertexPool::transform ( const LMatrix4d mat)

Applies the indicated transformation matrix to all the vertices.

However, vertices that are attached to primitives that believe their vertices are in a local coordinate system are transformed only by the scale and rotation component. If a vertex happens to be attached both to a local and a global primitive, and the transformation includes a translation component, the vertex will be split.

Reimplemented from EggNode.

Definition at line 739 of file eggVertexPool.cxx.

References begin(), end(), EggVertex::get_num_global_coord(), EggVertex::get_num_local_coord(), LMatrix4d::get_row3(), LMatrix4d::set_row(), size(), and EggVertex::transform().

Referenced by r_transform_vertices().

void EggVertexPool::write ( ostream &  out,
int  indent_level 
) const [virtual]

Writes the vertex pool to the indicated output stream in Egg format.

Implements EggNode.

Definition at line 857 of file eggVertexPool.cxx.

References begin(), end(), and EggNamedObject::write_header().


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations