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 
00025 #include "referenceCount.h"
00026 #include "luse.h"
00027 #include "pset.h"
00028 #include "iterator_types.h"
00029 
00030 class EggVertexPool;
00031 class EggGroup;
00032 class EggPrimitive;
00033 
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //       Class : EggVertex
00037 // Description : Any one-, two-, three-, or four-component vertex,
00038 //               possibly with attributes such as a normal.
00039 ////////////////////////////////////////////////////////////////////
00040 class EXPCL_PANDAEGG EggVertex : public EggObject, public EggAttributes {
00041 public:
00042   typedef pset<EggGroup *> GroupRef;
00043   typedef pmultiset<EggPrimitive *> PrimitiveRef;
00044   typedef pmap< string, PT(EggVertexUV) > UVMap;
00045 
00046   typedef second_of_pair_iterator<UVMap::const_iterator> uv_iterator;
00047   typedef uv_iterator const_uv_iterator;
00048   typedef UVMap::size_type uv_size_type;
00049 
00050 PUBLISHED:
00051   EggVertex();
00052   EggVertex(const EggVertex &copy);
00053   EggVertex &operator = (const EggVertex &copy);
00054   virtual ~EggVertex();
00055 
00056   INLINE EggVertexPool *get_pool() const;
00057 
00058   INLINE bool is_forward_reference() const;
00059 
00060   // The pos might have 1, 2, 3, or 4 dimensions.  That complicates
00061   // things a bit.
00062   INLINE void set_pos(double pos);
00063   INLINE void set_pos(const LPoint2d &pos);
00064   INLINE void set_pos(const LPoint3d &pos);
00065   INLINE void set_pos(const LPoint4d &pos);
00066   INLINE void set_pos4(const LPoint4d &pos);
00067 
00068   // get_pos[123] return the pos as the corresponding type.  It is an
00069   // error to call any of these without first verifying that
00070   // get_num_dimensions() matches the desired type.  However,
00071   // get_pos4() may always be called; it returns the pos as a
00072   // four-component point in homogeneous space (with a 1.0 in the last
00073   // position if the pos has fewer than four components).
00074   INLINE int get_num_dimensions() const;
00075   INLINE double get_pos1() const;
00076   INLINE LPoint2d get_pos2() const;
00077   INLINE Vertexd get_pos3() const;
00078   INLINE LPoint4d get_pos4() const;
00079 
00080   INLINE bool has_uv() const;
00081   INLINE TexCoordd get_uv() const;
00082   INLINE void set_uv(const TexCoordd &texCoord);
00083   INLINE void clear_uv();
00084   bool has_uv(const string &name) const;
00085   bool has_uvw(const string &name) const;
00086   TexCoordd get_uv(const string &name) const;
00087   const TexCoord3d &get_uvw(const string &name) const;
00088   void set_uv(const string &name, const TexCoordd &texCoord);
00089   void set_uvw(const string &name, const TexCoord3d &texCoord);
00090   const EggVertexUV *get_uv_obj(const string &name) const;
00091   EggVertexUV *modify_uv_obj(const string &name);
00092   void set_uv_obj(EggVertexUV *vertex_uv);
00093   void clear_uv(const string &name);
00094 
00095 public:
00096   INLINE const_uv_iterator uv_begin() const;
00097   INLINE const_uv_iterator uv_end() const;
00098   INLINE uv_size_type uv_size() const;
00099 
00100 PUBLISHED:
00101   INLINE int get_index() const;
00102 
00103   INLINE void set_external_index(int external_index);
00104   INLINE int get_external_index() const;
00105 
00106   void write(ostream &out, int indent_level) const;
00107   INLINE bool sorts_less_than(const EggVertex &other) const;
00108   int compare_to(const EggVertex &other) const;
00109 
00110   int get_num_local_coord() const;
00111   int get_num_global_coord() const;
00112 
00113   void transform(const LMatrix4d &mat);
00114 
00115 public:
00116   GroupRef::const_iterator gref_begin() const;
00117   GroupRef::const_iterator gref_end() const;
00118   GroupRef::size_type gref_size() const;
00119 PUBLISHED:
00120   bool has_gref(const EggGroup *group) const;
00121 
00122   void copy_grefs_from(const EggVertex &other);
00123   void clear_grefs();
00124 
00125 public:
00126   PrimitiveRef::const_iterator pref_begin() const;
00127   PrimitiveRef::const_iterator pref_end() const;
00128   PrimitiveRef::size_type pref_size() const;
00129 PUBLISHED:
00130   int has_pref(const EggPrimitive *prim) const;
00131 
00132 #ifndef NDEBUG
00133   void test_gref_integrity() const;
00134   void test_pref_integrity() const;
00135 #else
00136   void test_gref_integrity() const { }
00137   void test_pref_integrity() const { }
00138 #endif  // NDEBUG
00139 
00140   void output(ostream &out) const;
00141 
00142   EggMorphVertexList _dxyzs;
00143 
00144 private:
00145   EggVertexPool *_pool;
00146   bool _forward_reference;
00147   int _index;
00148   int _external_index;
00149   LPoint4d _pos;
00150   short _num_dimensions;
00151   GroupRef _gref;
00152   PrimitiveRef _pref;
00153 
00154   UVMap _uv_map;
00155 
00156 public:
00157   static TypeHandle get_class_type() {
00158     return _type_handle;
00159   }
00160   static void init_type() {
00161     EggObject::init_type();
00162     EggAttributes::init_type();
00163     register_type(_type_handle, "EggVertex",
00164                   EggObject::get_class_type(),
00165                   EggAttributes::get_class_type());
00166   }
00167   virtual TypeHandle get_type() const {
00168     return get_class_type();
00169   }
00170   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00171 
00172 private:
00173   static TypeHandle _type_handle;
00174 
00175   friend class EggVertexPool;
00176   friend class EggGroup;
00177   friend class EggPrimitive;
00178 };
00179 
00180 INLINE ostream &operator << (ostream &out, const EggVertex &vert) {
00181   vert.output(out);
00182   return out;
00183 }
00184 
00185 ////////////////////////////////////////////////////////////////////
00186 //       Class : UniqueEggVertices
00187 // Description : An STL function object for sorting vertices into
00188 //               order by properties.  Returns true if the two
00189 //               referenced EggVertex pointers are in sorted order,
00190 //               false otherwise.
00191 ////////////////////////////////////////////////////////////////////
00192 class EXPCL_PANDAEGG UniqueEggVertices {
00193 public:
00194   INLINE bool operator ()(const EggVertex *v1, const EggVertex *v2) const;
00195 };
00196 
00197 #include "eggVertex.I"
00198 
00199 #endif
00200 
00201 
00202 
 All Classes Functions Variables Enumerations