Panda3D
 All Classes Functions Variables Enumerations
eggMesherEdge.I
1 // Filename: eggMesherEdge.I
2 // Created by: drose (13Mar05)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: EggMesherEdge::Constructor
18 // Access: Public
19 // Description: Defines an edge as a pair of vertices. The _opposite
20 // pointer should be filled in explicitly by the caller.
21 ////////////////////////////////////////////////////////////////////
22 INLINE EggMesherEdge::
23 EggMesherEdge(int vi_a, int vi_b) : _vi_a(vi_a), _vi_b(vi_b) {
24  _opposite = NULL;
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: EggMesherEdge::Copy Constructor
29 // Access: Public
30 // Description:
31 ////////////////////////////////////////////////////////////////////
32 INLINE EggMesherEdge::
33 EggMesherEdge(const EggMesherEdge &copy) :
34  _vi_a(copy._vi_a),
35  _vi_b(copy._vi_b),
36  _strips(copy._strips),
37  _opposite(copy._opposite)
38 {
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: EggMesherEdge::contains_vertex
43 // Access: Public
44 // Description: Returns true if the edge contains the indicated
45 // vertex index, false otherwise.
46 ////////////////////////////////////////////////////////////////////
47 INLINE bool EggMesherEdge::
48 contains_vertex(int vi) const {
49  return (_vi_a == vi || _vi_b == vi);
50 }
51 
52 ////////////////////////////////////////////////////////////////////
53 // Function: EggMesherEdge::matches
54 // Access: Public
55 // Description: Returns true if this edge represents the same line
56 // segment as the other edge, in either direction.
57 ////////////////////////////////////////////////////////////////////
58 INLINE bool EggMesherEdge::
59 matches(const EggMesherEdge &other) const {
60  return ((_vi_a == other._vi_a && _vi_b == other._vi_b) ||
61  (_vi_b == other._vi_a && _vi_a == other._vi_b));
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: EggMesherEdge::common_ptr
66 // Access: Public
67 // Description: Returns an arbitrary pointer that is used to
68 // represent both this edge and its opposite.
69 // this->common_ptr() is guaranteed to be the same as
70 // this->_opposite->common_ptr().
71 ////////////////////////////////////////////////////////////////////
74  return min(this, _opposite);
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: EggMesherEdge::operator ==
79 // Access: Public
80 // Description:
81 ////////////////////////////////////////////////////////////////////
82 INLINE bool EggMesherEdge::
83 operator == (const EggMesherEdge &other) const {
84  return _vi_a == other._vi_a && _vi_b == other._vi_b;
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: EggMesherEdge::operator !=
89 // Access: Public
90 // Description:
91 ////////////////////////////////////////////////////////////////////
92 INLINE bool EggMesherEdge::
93 operator != (const EggMesherEdge &other) const {
94  return !operator == (other);
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: EggMesherEdge::operator <
99 // Access: Public
100 // Description: Defines an arbitrary ordering for edges, used for
101 // putting edges in a sorted container.
102 ////////////////////////////////////////////////////////////////////
103 INLINE bool EggMesherEdge::
104 operator < (const EggMesherEdge &other) const {
105  if (_vi_a != other._vi_a) {
106  return _vi_a < other._vi_a;
107  }
108  return _vi_b < other._vi_b;
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: EggMesherEdge::compute_length
113 // Access: Public
114 // Description: Returns the length of the edge in model units.
115 ////////////////////////////////////////////////////////////////////
116 INLINE double EggMesherEdge::
117 compute_length(const EggVertexPool *vertex_pool) const {
118  LPoint3d a = vertex_pool->get_vertex(_vi_a)->get_pos3();
119  LPoint3d b = vertex_pool->get_vertex(_vi_b)->get_pos3();
120  return (a - b).length();
121 }
122 
123 ////////////////////////////////////////////////////////////////////
124 // Function: EggMesherEdge::compute_box
125 // Access: Public
126 // Description: Returns a 3-component vector that represents the
127 // lengths of the sides of the smalled axis-aligned box
128 // that contains the edge. That is, the projection the
129 // edge onto each axis.
130 ////////////////////////////////////////////////////////////////////
132 compute_box(const EggVertexPool *vertex_pool) const {
133  LPoint3d a = vertex_pool->get_vertex(_vi_a)->get_pos3();
134  LPoint3d b = vertex_pool->get_vertex(_vi_b)->get_pos3();
135  LVector3d v = (a - b);
136  return LVecBase3d(fabs(v[0]), fabs(v[1]), fabs(v[2]));
137 }
EggVertex * get_vertex(int index) const
Returns the vertex in the pool with the indicated index number, or NULL if no vertices have that inde...
EggMesherEdge(int vi_a, int vi_b)
Defines an edge as a pair of vertices.
Definition: eggMesherEdge.I:23
LVertexd get_pos3() const
Valid if get_num_dimensions() returns 3 or 4.
Definition: eggVertex.I:160
double compute_length(const EggVertexPool *vertex_pool) const
Returns the length of the edge in model units.
bool contains_vertex(int vi) const
Returns true if the edge contains the indicated vertex index, false otherwise.
Definition: eggMesherEdge.I:48
bool matches(const EggMesherEdge &other) const
Returns true if this edge represents the same line segment as the other edge, in either direction...
Definition: eggMesherEdge.I:59
double length() const
Returns the length of the vector, by the Pythagorean theorem.
Definition: lvecBase3.h:2115
EggMesherEdge * common_ptr()
Returns an arbitrary pointer that is used to represent both this edge and its opposite.
Definition: eggMesherEdge.I:73
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:1455
Represents one edge of a triangle, as used by the EggMesher to discover connected triangles...
Definition: eggMesherEdge.h:32
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:746
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:531
bool operator<(const EggMesherEdge &other) const
Defines an arbitrary ordering for edges, used for putting edges in a sorted container.
A collection of vertices.
Definition: eggVertexPool.h:46
LVecBase3d compute_box(const EggVertexPool *vertex_pool) const
Returns a 3-component vector that represents the lengths of the sides of the smalled axis-aligned box...