Panda3D
eggVertex.h
1 // Filename: eggVertex.h
2 // Created by: drose (16Jan99)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef EGGVERTEX_H
16 #define EGGVERTEX_H
17 
18 #include "pandabase.h"
19 
20 #include "eggObject.h"
21 #include "eggAttributes.h"
22 #include "eggMorphList.h"
23 #include "eggVertexUV.h"
24 #include "eggVertexAux.h"
25 
26 #include "referenceCount.h"
27 #include "luse.h"
28 #include "pset.h"
29 #include "iterator_types.h"
30 
31 class EggVertexPool;
32 class EggGroup;
33 class EggPrimitive;
34 
35 
36 ////////////////////////////////////////////////////////////////////
37 // Class : EggVertex
38 // Description : Any one-, two-, three-, or four-component vertex,
39 // possibly with attributes such as a normal.
40 ////////////////////////////////////////////////////////////////////
41 class EXPCL_PANDAEGG EggVertex : public EggObject, public EggAttributes {
42 public:
43  typedef pset<EggGroup *> GroupRef;
47 
49  typedef uv_iterator const_uv_iterator;
50  typedef UVMap::size_type uv_size_type;
51 
53  typedef aux_iterator const_aux_iterator;
54  typedef AuxMap::size_type aux_size_type;
55 
56 
57 PUBLISHED:
58  EggVertex();
59  EggVertex(const EggVertex &copy);
60  EggVertex &operator = (const EggVertex &copy);
61  virtual ~EggVertex();
62 
63  INLINE EggVertexPool *get_pool() const;
64 
65  INLINE bool is_forward_reference() const;
66 
67  // The pos might have 1, 2, 3, or 4 dimensions. That complicates
68  // things a bit.
69  INLINE void set_pos(double pos);
70  INLINE void set_pos(const LPoint2d &pos);
71  INLINE void set_pos(const LPoint3d &pos);
72  INLINE void set_pos(const LPoint4d &pos);
73  INLINE void set_pos4(const LPoint4d &pos);
74 
75  // get_pos[123] return the pos as the corresponding type. It is an
76  // error to call any of these without first verifying that
77  // get_num_dimensions() matches the desired type. However,
78  // get_pos4() may always be called; it returns the pos as a
79  // four-component point in homogeneous space (with a 1.0 in the last
80  // position if the pos has fewer than four components).
81  INLINE int get_num_dimensions() const;
82  INLINE double get_pos1() const;
83  INLINE LPoint2d get_pos2() const;
84  INLINE LVertexd get_pos3() const;
85  INLINE LPoint4d get_pos4() const;
86 
87  INLINE bool has_uv() const;
88  INLINE LTexCoordd get_uv() const;
89  INLINE void set_uv(const LTexCoordd &texCoord);
90  INLINE void clear_uv();
91  bool has_uv(const string &name) const;
92  bool has_uvw(const string &name) const;
93  LTexCoordd get_uv(const string &name) const;
94  const LTexCoord3d &get_uvw(const string &name) const;
95  void set_uv(const string &name, const LTexCoordd &texCoord);
96  void set_uvw(const string &name, const LTexCoord3d &texCoord);
97  const EggVertexUV *get_uv_obj(const string &name) const;
98  EggVertexUV *modify_uv_obj(const string &name);
99  void set_uv_obj(EggVertexUV *vertex_uv);
100  void clear_uv(const string &name);
101 
102  INLINE bool has_aux() const;
103  INLINE void clear_aux();
104  bool has_aux(const string &name) const;
105  const LVecBase4d &get_aux(const string &name) const;
106  void set_aux(const string &name, const LVecBase4d &aux);
107  const EggVertexAux *get_aux_obj(const string &name) const;
108  EggVertexAux *modify_aux_obj(const string &name);
109  void set_aux_obj(EggVertexAux *vertex_aux);
110  void clear_aux(const string &name);
111 
112  static PT(EggVertex) make_average(const EggVertex *first,
113  const EggVertex *second);
114 
115 public:
116  INLINE const_uv_iterator uv_begin() const;
117  INLINE const_uv_iterator uv_end() const;
118  INLINE uv_size_type uv_size() const;
119 
120  INLINE const_aux_iterator aux_begin() const;
121  INLINE const_aux_iterator aux_end() const;
122  INLINE aux_size_type aux_size() const;
123 
124 PUBLISHED:
125  INLINE int get_index() const;
126 
127  INLINE void set_external_index(int external_index);
128  INLINE int get_external_index() const;
129  INLINE void set_external_index2(int external_index2);
130  INLINE int get_external_index2() const;
131 
132  void write(ostream &out, int indent_level) const;
133  INLINE bool sorts_less_than(const EggVertex &other) const;
134  int compare_to(const EggVertex &other) const;
135 
136  int get_num_local_coord() const;
137  int get_num_global_coord() const;
138 
139  void transform(const LMatrix4d &mat);
140 
141 public:
142  GroupRef::const_iterator gref_begin() const;
143  GroupRef::const_iterator gref_end() const;
144  GroupRef::size_type gref_size() const;
145 PUBLISHED:
146  bool has_gref(const EggGroup *group) const;
147 
148  void copy_grefs_from(const EggVertex &other);
149  void clear_grefs();
150 
151 public:
152  PrimitiveRef::const_iterator pref_begin() const;
153  PrimitiveRef::const_iterator pref_end() const;
154  PrimitiveRef::size_type pref_size() const;
155 PUBLISHED:
156  int has_pref(const EggPrimitive *prim) const;
157 
158 #ifdef _DEBUG
159  void test_gref_integrity() const;
160  void test_pref_integrity() const;
161 #else
162  void test_gref_integrity() const { }
163  void test_pref_integrity() const { }
164 #endif // _DEBUG
165 
166  void output(ostream &out) const;
167 
168  EggMorphVertexList _dxyzs;
169 
170 private:
171  EggVertexPool *_pool;
172  bool _forward_reference;
173  int _index;
174  int _external_index, _external_index2;
175  LPoint4d _pos;
176  short _num_dimensions;
177  GroupRef _gref;
178  PrimitiveRef _pref;
179 
180  UVMap _uv_map;
181  AuxMap _aux_map;
182 
183 public:
184  static TypeHandle get_class_type() {
185  return _type_handle;
186  }
187  static void init_type() {
188  EggObject::init_type();
189  EggAttributes::init_type();
190  register_type(_type_handle, "EggVertex",
191  EggObject::get_class_type(),
192  EggAttributes::get_class_type());
193  }
194  virtual TypeHandle get_type() const {
195  return get_class_type();
196  }
197  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
198 
199 private:
200  static TypeHandle _type_handle;
201 
202  friend class EggVertexPool;
203  friend class EggGroup;
204  friend class EggPrimitive;
205 };
206 
207 INLINE ostream &operator << (ostream &out, const EggVertex &vert) {
208  vert.output(out);
209  return out;
210 }
211 
212 ////////////////////////////////////////////////////////////////////
213 // Class : UniqueEggVertices
214 // Description : An STL function object for sorting vertices into
215 // order by properties. Returns true if the two
216 // referenced EggVertex pointers are in sorted order,
217 // false otherwise.
218 ////////////////////////////////////////////////////////////////////
219 class EXPCL_PANDAEGG UniqueEggVertices {
220 public:
221  INLINE bool operator ()(const EggVertex *v1, const EggVertex *v2) const;
222 };
223 
224 #include "eggVertex.I"
225 
226 #endif
227 
228 
229 
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
Definition: eggPrimitive.h:51
The set of UV&#39;s that may or may not be assigned to a vertex.
Definition: eggVertexUV.h:32
An STL function object for sorting vertices into order by properties.
Definition: eggVertex.h:219
This is an iterator adaptor that converts any iterator that returns a pair (e.g.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
This is a four-component point in space.
Definition: lpoint4.h:457
void transform(const LMatrix4d &mat)
Applies the indicated transformation matrix to the attributes.
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:1677
This is a two-component point in space.
Definition: lpoint2.h:424
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
Definition: eggGroup.h:36
The set of attributes that may be applied to vertices as well as polygons, such as surface normal and...
Definition: eggAttributes.h:37
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
Definition: eggVertex.h:41
The set of named auxiliary data that may or may not be assigned to a vertex.
Definition: eggVertexAux.h:33
void write(ostream &out, int indent_level) const
Writes the attributes to the indicated output stream in Egg format.
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:544
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
bool sorts_less_than(const EggAttributes &other) const
An ordering operator to compare two vertices for sorting order.
A collection of vertices.
Definition: eggVertexPool.h:46
The highest-level base class in the egg directory.
Definition: eggObject.h:31
int compare_to(const EggAttributes &other) const
An ordering operator to compare two vertices for sorting order.