Panda3D

eggVertex.h

00001 // Filename: eggVertex.h
00002 // Created by:  drose (16Jan99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef EGGVERTEX_H
00016 #define EGGVERTEX_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "eggObject.h"
00021 #include "eggAttributes.h"
00022 #include "eggMorphList.h"
00023 #include "eggVertexUV.h"
00024 #include "eggVertexAux.h"
00025 
00026 #include "referenceCount.h"
00027 #include "luse.h"
00028 #include "pset.h"
00029 #include "iterator_types.h"
00030 
00031 class EggVertexPool;
00032 class EggGroup;
00033 class EggPrimitive;
00034 
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //       Class : EggVertex
00038 // Description : Any one-, two-, three-, or four-component vertex,
00039 //               possibly with attributes such as a normal.
00040 ////////////////////////////////////////////////////////////////////
00041 class EXPCL_PANDAEGG EggVertex : public EggObject, public EggAttributes {
00042 public:
00043   typedef pset<EggGroup *> GroupRef;
00044   typedef pmultiset<EggPrimitive *> PrimitiveRef;
00045   typedef pmap< string, PT(EggVertexUV) > UVMap;
00046   typedef pmap< string, PT(EggVertexAux) > AuxMap;
00047 
00048   typedef second_of_pair_iterator<UVMap::const_iterator> uv_iterator;
00049   typedef uv_iterator const_uv_iterator;
00050   typedef UVMap::size_type uv_size_type;
00051 
00052   typedef second_of_pair_iterator<AuxMap::const_iterator> aux_iterator;
00053   typedef aux_iterator const_aux_iterator;
00054   typedef AuxMap::size_type aux_size_type;
00055 
00056 
00057 PUBLISHED:
00058   EggVertex();
00059   EggVertex(const EggVertex &copy);
00060   EggVertex &operator = (const EggVertex &copy);
00061   virtual ~EggVertex();
00062 
00063   INLINE EggVertexPool *get_pool() const;
00064 
00065   INLINE bool is_forward_reference() const;
00066 
00067   // The pos might have 1, 2, 3, or 4 dimensions.  That complicates
00068   // things a bit.
00069   INLINE void set_pos(double pos);
00070   INLINE void set_pos(const LPoint2d &pos);
00071   INLINE void set_pos(const LPoint3d &pos);
00072   INLINE void set_pos(const LPoint4d &pos);
00073   INLINE void set_pos4(const LPoint4d &pos);
00074 
00075   // get_pos[123] return the pos as the corresponding type.  It is an
00076   // error to call any of these without first verifying that
00077   // get_num_dimensions() matches the desired type.  However,
00078   // get_pos4() may always be called; it returns the pos as a
00079   // four-component point in homogeneous space (with a 1.0 in the last
00080   // position if the pos has fewer than four components).
00081   INLINE int get_num_dimensions() const;
00082   INLINE double get_pos1() const;
00083   INLINE LPoint2d get_pos2() const;
00084   INLINE LVertexd get_pos3() const;
00085   INLINE LPoint4d get_pos4() const;
00086 
00087   INLINE bool has_uv() const;
00088   INLINE LTexCoordd get_uv() const;
00089   INLINE void set_uv(const LTexCoordd &texCoord);
00090   INLINE void clear_uv();
00091   bool has_uv(const string &name) const;
00092   bool has_uvw(const string &name) const;
00093   LTexCoordd get_uv(const string &name) const;
00094   const LTexCoord3d &get_uvw(const string &name) const;
00095   void set_uv(const string &name, const LTexCoordd &texCoord);
00096   void set_uvw(const string &name, const LTexCoord3d &texCoord);
00097   const EggVertexUV *get_uv_obj(const string &name) const;
00098   EggVertexUV *modify_uv_obj(const string &name);
00099   void set_uv_obj(EggVertexUV *vertex_uv);
00100   void clear_uv(const string &name);
00101 
00102   INLINE bool has_aux() const;
00103   INLINE void clear_aux();
00104   bool has_aux(const string &name) const;
00105   const LVecBase4d &get_aux(const string &name) const;
00106   void set_aux(const string &name, const LVecBase4d &aux);
00107   const EggVertexAux *get_aux_obj(const string &name) const;
00108   EggVertexAux *modify_aux_obj(const string &name);
00109   void set_aux_obj(EggVertexAux *vertex_aux);
00110   void clear_aux(const string &name);
00111 
00112 public:
00113   INLINE const_uv_iterator uv_begin() const;
00114   INLINE const_uv_iterator uv_end() const;
00115   INLINE uv_size_type uv_size() const;
00116 
00117   INLINE const_aux_iterator aux_begin() const;
00118   INLINE const_aux_iterator aux_end() const;
00119   INLINE aux_size_type aux_size() const;
00120 
00121 PUBLISHED:
00122   INLINE int get_index() const;
00123 
00124   INLINE void set_external_index(int external_index);
00125   INLINE int get_external_index() const;
00126 
00127   void write(ostream &out, int indent_level) const;
00128   INLINE bool sorts_less_than(const EggVertex &other) const;
00129   int compare_to(const EggVertex &other) const;
00130 
00131   int get_num_local_coord() const;
00132   int get_num_global_coord() const;
00133 
00134   void transform(const LMatrix4d &mat);
00135 
00136 public:
00137   GroupRef::const_iterator gref_begin() const;
00138   GroupRef::const_iterator gref_end() const;
00139   GroupRef::size_type gref_size() const;
00140 PUBLISHED:
00141   bool has_gref(const EggGroup *group) const;
00142 
00143   void copy_grefs_from(const EggVertex &other);
00144   void clear_grefs();
00145 
00146 public:
00147   PrimitiveRef::const_iterator pref_begin() const;
00148   PrimitiveRef::const_iterator pref_end() const;
00149   PrimitiveRef::size_type pref_size() const;
00150 PUBLISHED:
00151   int has_pref(const EggPrimitive *prim) const;
00152 
00153 #ifdef _DEBUG
00154   void test_gref_integrity() const;
00155   void test_pref_integrity() const;
00156 #else
00157   void test_gref_integrity() const { }
00158   void test_pref_integrity() const { }
00159 #endif  // _DEBUG
00160 
00161   void output(ostream &out) const;
00162 
00163   EggMorphVertexList _dxyzs;
00164 
00165 private:
00166   EggVertexPool *_pool;
00167   bool _forward_reference;
00168   int _index;
00169   int _external_index;
00170   LPoint4d _pos;
00171   short _num_dimensions;
00172   GroupRef _gref;
00173   PrimitiveRef _pref;
00174 
00175   UVMap _uv_map;
00176   AuxMap _aux_map;
00177 
00178 public:
00179   static TypeHandle get_class_type() {
00180     return _type_handle;
00181   }
00182   static void init_type() {
00183     EggObject::init_type();
00184     EggAttributes::init_type();
00185     register_type(_type_handle, "EggVertex",
00186                   EggObject::get_class_type(),
00187                   EggAttributes::get_class_type());
00188   }
00189   virtual TypeHandle get_type() const {
00190     return get_class_type();
00191   }
00192   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00193 
00194 private:
00195   static TypeHandle _type_handle;
00196 
00197   friend class EggVertexPool;
00198   friend class EggGroup;
00199   friend class EggPrimitive;
00200 };
00201 
00202 INLINE ostream &operator << (ostream &out, const EggVertex &vert) {
00203   vert.output(out);
00204   return out;
00205 }
00206 
00207 ////////////////////////////////////////////////////////////////////
00208 //       Class : UniqueEggVertices
00209 // Description : An STL function object for sorting vertices into
00210 //               order by properties.  Returns true if the two
00211 //               referenced EggVertex pointers are in sorted order,
00212 //               false otherwise.
00213 ////////////////////////////////////////////////////////////////////
00214 class EXPCL_PANDAEGG UniqueEggVertices {
00215 public:
00216   INLINE bool operator ()(const EggVertex *v1, const EggVertex *v2) const;
00217 };
00218 
00219 #include "eggVertex.I"
00220 
00221 #endif
00222 
00223 
00224 
 All Classes Functions Variables Enumerations