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.
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.
59
60public:
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);
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);
126 int remove_unused_vertices();
127 void add_unused_vertices_to_prim(EggPrimitive *prim);
128
129 void transform(const LMatrix4d &mat);
130 void sort_by_external_index();
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
167
168#include "eggVertexPool.I"
169
170#endif
A base class for things that may be directly added into the egg hierarchy.
Definition eggNode.h:36
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.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
Definition eggVertex.h:39
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
This is our own Panda specialization on the default STL map.
Definition pmap.h:49
This is our own Panda specialization on the default STL multiset.
Definition pset.h:108
This is our own Panda specialization on the default STL vector.
Definition pvector.h:42
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(),...