Panda3D
 All Classes Functions Variables Enumerations
eggMesherEdge.I
00001 // Filename: eggMesherEdge.I
00002 // Created by:  drose (13Mar05)
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 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: EggMesherEdge::Constructor
00018 //       Access: Public
00019 //  Description: Defines an edge as a pair of vertices.  The _opposite
00020 //               pointer should be filled in explicitly by the caller.
00021 ////////////////////////////////////////////////////////////////////
00022 INLINE EggMesherEdge::
00023 EggMesherEdge(int vi_a, int vi_b) : _vi_a(vi_a), _vi_b(vi_b) {
00024   _opposite = NULL;
00025 }
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: EggMesherEdge::Copy Constructor
00029 //       Access: Public
00030 //  Description: 
00031 ////////////////////////////////////////////////////////////////////
00032 INLINE EggMesherEdge::
00033 EggMesherEdge(const EggMesherEdge &copy) :
00034   _vi_a(copy._vi_a),
00035   _vi_b(copy._vi_b),
00036   _strips(copy._strips),
00037   _opposite(copy._opposite)
00038 {
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: EggMesherEdge::contains_vertex
00043 //       Access: Public
00044 //  Description: Returns true if the edge contains the indicated
00045 //               vertex index, false otherwise.
00046 ////////////////////////////////////////////////////////////////////
00047 INLINE bool EggMesherEdge::
00048 contains_vertex(int vi) const {
00049   return (_vi_a == vi || _vi_b == vi);
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: EggMesherEdge::matches
00054 //       Access: Public
00055 //  Description: Returns true if this edge represents the same line
00056 //               segment as the other edge, in either direction.
00057 ////////////////////////////////////////////////////////////////////
00058 INLINE bool EggMesherEdge::
00059 matches(const EggMesherEdge &other) const {
00060   return ((_vi_a == other._vi_a && _vi_b == other._vi_b) ||
00061           (_vi_b == other._vi_a && _vi_a == other._vi_b));
00062 }
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function: EggMesherEdge::common_ptr
00066 //       Access: Public
00067 //  Description: Returns an arbitrary pointer that is used to
00068 //               represent both this edge and its opposite.
00069 //               this->common_ptr() is guaranteed to be the same as
00070 //               this->_opposite->common_ptr().
00071 ////////////////////////////////////////////////////////////////////
00072 INLINE EggMesherEdge *EggMesherEdge::
00073 common_ptr() {
00074   return min(this, _opposite);
00075 }
00076 
00077 ////////////////////////////////////////////////////////////////////
00078 //     Function: EggMesherEdge::operator ==
00079 //       Access: Public
00080 //  Description: 
00081 ////////////////////////////////////////////////////////////////////
00082 INLINE bool EggMesherEdge::
00083 operator == (const EggMesherEdge &other) const {
00084   return _vi_a == other._vi_a && _vi_b == other._vi_b;
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: EggMesherEdge::operator !=
00089 //       Access: Public
00090 //  Description: 
00091 ////////////////////////////////////////////////////////////////////
00092 INLINE bool EggMesherEdge::
00093 operator != (const EggMesherEdge &other) const {
00094   return !operator == (other);
00095 }
00096 
00097 ////////////////////////////////////////////////////////////////////
00098 //     Function: EggMesherEdge::operator <
00099 //       Access: Public
00100 //  Description: Defines an arbitrary ordering for edges, used for
00101 //               putting edges in a sorted container.
00102 ////////////////////////////////////////////////////////////////////
00103 INLINE bool EggMesherEdge::
00104 operator < (const EggMesherEdge &other) const {
00105   if (_vi_a != other._vi_a) {
00106     return _vi_a < other._vi_a;
00107   }
00108   return _vi_b < other._vi_b;
00109 }
00110 
00111 ////////////////////////////////////////////////////////////////////
00112 //     Function: EggMesherEdge::compute_length
00113 //       Access: Public
00114 //  Description: Returns the length of the edge in model units.
00115 ////////////////////////////////////////////////////////////////////
00116 INLINE double EggMesherEdge::
00117 compute_length(const EggVertexPool *vertex_pool) const {
00118   LPoint3d a = vertex_pool->get_vertex(_vi_a)->get_pos3();
00119   LPoint3d b = vertex_pool->get_vertex(_vi_b)->get_pos3();
00120   return (a - b).length();
00121 }
00122 
00123 ////////////////////////////////////////////////////////////////////
00124 //     Function: EggMesherEdge::compute_box
00125 //       Access: Public
00126 //  Description: Returns a 3-component vector that represents the
00127 //               lengths of the sides of the smalled axis-aligned box
00128 //               that contains the edge.  That is, the projection the
00129 //               edge onto each axis.
00130 ////////////////////////////////////////////////////////////////////
00131 INLINE LVecBase3d EggMesherEdge::
00132 compute_box(const EggVertexPool *vertex_pool) const {
00133   LPoint3d a = vertex_pool->get_vertex(_vi_a)->get_pos3();
00134   LPoint3d b = vertex_pool->get_vertex(_vi_b)->get_pos3();
00135   LVector3d v = (a - b);
00136   return LVecBase3d(fabs(v[0]), fabs(v[1]), fabs(v[2]));
00137 }
 All Classes Functions Variables Enumerations