Panda3D
Loading...
Searching...
No Matches
eggVertexPool.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 eggVertexPool.h
10 * @author drose
11 * @date 1999-01-16
12 */
13
14#ifndef EGGVERTEXPOOL_H
15#define EGGVERTEXPOOL_H
16
17#include "pandabase.h"
18
19#include "eggVertex.h"
20#include "eggNode.h"
21#include "pt_EggVertex.h"
22
23#include "pointerTo.h"
24#include "pset.h"
25#include "pvector.h"
26#include "pmap.h"
27#include "lmatrix.h"
28#include "iterator_types.h"
29
30/**
31 * A collection of vertices. There may be any number of vertex pools in a
32 * single egg structure. The vertices in a single pool need not necessarily
33 * have any connection to each other, but it is necessary that any one
34 * primitive (e.g. a polygon) must pull all its vertices from the same pool.
35 *
36 * An EggVertexPool is an STL-style container of pointers to EggVertex's.
37 * Functions add_vertex() and remove_vertex() are provided to manipulate the
38 * list. The list may also be operated on (read-only) via iterators and
39 * begin()/end().
40 */
41class EXPCL_PANDA_EGG EggVertexPool : public EggNode {
42
43 // This is a bit of private interface stuff that must be here as a forward
44 // reference. This allows us to define the EggVertexPool as an STL
45 // container.
46
47private:
48 // IndexVertices is the main storage mechanism of the vertex pool. It
49 // stores a reference-counting pointer to each vertex, ordered by vertex
50 // index number.
51 typedef pmap<int, PT_EggVertex> IndexVertices;
52
53 // UniqueVertices is an auxiliary indexing mechanism. It stores the same
54 // vertex pointers as IndexVertices (although these pointers are not
55 // reference-counted), this time ordered by vertex properties. This makes
56 // it easy to determine when one or more vertices already exist in the pool
57 // with identical properties.
58 typedef pmultiset<EggVertex *, UniqueEggVertices> UniqueVertices;
59
60public:
62 typedef iterator const_iterator;
63 typedef IndexVertices::size_type size_type;
64
65 // Here begins the actual public interface to EggVertexPool.
66
67PUBLISHED:
68 explicit EggVertexPool(const std::string &name);
69 EggVertexPool(const EggVertexPool &copy);
70 ~EggVertexPool();
71
72 INLINE bool has_vertex(int index) const;
73
74 bool has_forward_vertices() const;
75 bool has_defined_vertices() const;
76
77 // Returns NULL if there is no such vertex.
78 EggVertex *get_vertex(int index) const;
79 INLINE EggVertex *operator [](int index) const;
80
81 // Returns a forward reference if there is no such vertex.
82 EggVertex *get_forward_vertex(int index);
83
84 // Returns 0 if the pool is empty.
85 int get_highest_index() const;
86 void set_highest_index(int highest_index);
87
88 int get_num_dimensions() const;
89 bool has_normals() const;
90 bool has_colors() const;
91 bool has_nonwhite_colors() const;
92 void check_overall_color(bool &has_overall_color, LColor &overall_color) const;
93 bool has_uvs() const;
94 bool has_aux() const;
95 void get_uv_names(vector_string &uv_names, vector_string &uvw_names,
96 vector_string &tbn_names) const;
97 void get_aux_names(vector_string &aux_names) const;
98
99public:
100 // Can be used to traverse all the vertices in index number order.
101 iterator begin() const;
102 iterator end() const;
103 bool empty() const;
104
105PUBLISHED:
106 size_type size() const;
107
108 // add_vertex() adds a freshly-allocated vertex. It is up to the user to
109 // allocate the vertex.
110 EggVertex *add_vertex(EggVertex *vertex, int index = -1);
111
112 // make_new_vertex() allocates and returns a new vertex from the pool.
113 INLINE EggVertex *make_new_vertex();
114 INLINE EggVertex *make_new_vertex(double pos);
115 INLINE EggVertex *make_new_vertex(const LPoint2d &pos);
116 INLINE EggVertex *make_new_vertex(const LPoint3d &pos);
117 INLINE EggVertex *make_new_vertex(const LPoint4d &pos);
118
119 // create_unique_vertex() creates a new vertex if there is not already one
120 // identical to the indicated vertex, or returns the existing one if there
121 // is.
122 EggVertex *create_unique_vertex(const EggVertex &copy);
123 EggVertex *find_matching_vertex(const EggVertex &copy);
124
125 void remove_vertex(EggVertex *vertex);
128
129 void transform(const LMatrix4d &mat);
131
132 void write(std::ostream &out, int indent_level) const;
133
134protected:
135 virtual void r_transform(const LMatrix4d &mat, const LMatrix4d &inv,
136 CoordinateSystem to_cs);
137 virtual void r_transform_vertices(const LMatrix4d &mat);
138
139private:
140 UniqueVertices _unique_vertices;
141 IndexVertices _index_vertices;
142 int _highest_index;
143
144
145public:
146
147 static TypeHandle get_class_type() {
148 return _type_handle;
149 }
150 static void init_type() {
151 EggNode::init_type();
152 register_type(_type_handle, "EggVertexPool",
153 EggNode::get_class_type());
154 }
155 virtual TypeHandle get_type() const {
156 return get_class_type();
157 }
158 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
159
160private:
161 static TypeHandle _type_handle;
162
163friend class EggVertex;
164};
165
166typedef pvector< PT(EggVertexPool) > EggVertexPools;
167
168#include "eggVertexPool.I"
169
170#endif
void transform(const LMatrix4d &mat)
Applies the indicated transformation to the node and all of its descendants.
Definition eggNode.I:253
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
A collection of vertices.
bool has_colors() const
Returns true if any vertex in the pool has a color defined, false if none of them do.
void remove_vertex(EggVertex *vertex)
Removes the vertex from the pool.
bool has_normals() const
Returns true if any vertex in the pool has a normal defined, false if none of them do.
int remove_unused_vertices()
Removes all vertices from the pool that are not referenced by at least one primitive.
int get_highest_index() const
Returns the highest index number used by any vertex in the pool (except forward references).
EggVertex * find_matching_vertex(const EggVertex &copy)
If the EggVertexPool already has a vertex matching the indicated vertex, returns it; otherwise,...
bool has_defined_vertices() const
Returns true if any vertices in the pool are fully defined vertices, false if all vertices are forwar...
void sort_by_external_index()
Re-orders (and re-numbers) the vertices in this vertex pool so that they appear in increasing order b...
bool has_aux() const
Returns true if any vertex in the pool has auxiliary data defined, false if none of them do.
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.
size_type size() const
Returns the number of vertices in the pool.
bool has_nonwhite_colors() const
Returns true if any vertex in the pool has a color defined other than white, false if no vertices hav...
bool has_uvs() const
Returns true if any vertex in the pool has a uv defined, false if none of them do.
iterator end() 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.
bool has_vertex(int index) const
Returns true if the indicated vertex has been defined in the vertex pool, false otherwise.
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.
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 U...
EggVertex * get_vertex(int index) const
Returns the vertex in the pool with the indicated index number, or NULL if no vertices have that inde...
int get_num_dimensions() const
Returns the maximum number of dimensions used by any vertex in the pool.
iterator begin() const
Returns an iterator that can be used to traverse through all the vertices in the pool.
EggVertex * make_new_vertex()
Allocates and returns a new 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 nu...
EggVertex * add_vertex(EggVertex *vertex, int index=-1)
Adds the indicated vertex to the pool.
EggVertex * create_unique_vertex(const EggVertex &copy)
Creates a new vertex in the pool that is a copy of the indicated one and returns it.
bool has_forward_vertices() const
Returns true if any vertices in the pool are undefined forward-reference vertices,...
bool empty() const
Returns true if the pool is empty.
EggVertex * get_forward_vertex(int index)
Returns the vertex in the pool with the indicated index number.
void write(std::ostream &out, int indent_level) const
Writes the vertex pool to the indicated output stream in Egg format.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
This is our own Panda specialization on the default STL multiset.
Definition pset.h:108
This is an iterator adaptor that converts any iterator that returns a pair (e.g.
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.
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.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...