Panda3D
eggMesherEdge.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file eggMesherEdge.I
10  * @author drose
11  * @date 2005-03-13
12  */
13 
14 /**
15  * Defines an edge as a pair of vertices. The _opposite pointer should be
16  * filled in explicitly by the caller.
17  */
18 INLINE EggMesherEdge::
19 EggMesherEdge(int vi_a, int vi_b) : _vi_a(vi_a), _vi_b(vi_b) {
20  _opposite = nullptr;
21 }
22 
23 /**
24  *
25  */
26 INLINE EggMesherEdge::
27 EggMesherEdge(const EggMesherEdge &copy) :
28  _vi_a(copy._vi_a),
29  _vi_b(copy._vi_b),
30  _strips(copy._strips),
31  _opposite(copy._opposite)
32 {
33 }
34 
35 /**
36  * Returns true if the edge contains the indicated vertex index, false
37  * otherwise.
38  */
39 INLINE bool EggMesherEdge::
40 contains_vertex(int vi) const {
41  return (_vi_a == vi || _vi_b == vi);
42 }
43 
44 /**
45  * Returns true if this edge represents the same line segment as the other
46  * edge, in either direction.
47  */
48 INLINE bool EggMesherEdge::
49 matches(const EggMesherEdge &other) const {
50  return ((_vi_a == other._vi_a && _vi_b == other._vi_b) ||
51  (_vi_b == other._vi_a && _vi_a == other._vi_b));
52 }
53 
54 /**
55  * Returns an arbitrary pointer that is used to represent both this edge and
56  * its opposite. this->common_ptr() is guaranteed to be the same as
57  * this->_opposite->common_ptr().
58  */
61  return std::min(this, _opposite);
62 }
63 
64 /**
65  *
66  */
67 INLINE bool EggMesherEdge::
68 operator == (const EggMesherEdge &other) const {
69  return _vi_a == other._vi_a && _vi_b == other._vi_b;
70 }
71 
72 /**
73  *
74  */
75 INLINE bool EggMesherEdge::
76 operator != (const EggMesherEdge &other) const {
77  return !operator == (other);
78 }
79 
80 /**
81  * Defines an arbitrary ordering for edges, used for putting edges in a sorted
82  * container.
83  */
84 INLINE bool EggMesherEdge::
85 operator < (const EggMesherEdge &other) const {
86  if (_vi_a != other._vi_a) {
87  return _vi_a < other._vi_a;
88  }
89  return _vi_b < other._vi_b;
90 }
91 
92 /**
93  * Returns the length of the edge in model units.
94  */
95 INLINE double EggMesherEdge::
96 compute_length(const EggVertexPool *vertex_pool) const {
97  LPoint3d a = vertex_pool->get_vertex(_vi_a)->get_pos3();
98  LPoint3d b = vertex_pool->get_vertex(_vi_b)->get_pos3();
99  return (a - b).length();
100 }
101 
102 /**
103  * Returns a 3-component vector that represents the lengths of the sides of
104  * the smalled axis-aligned box that contains the edge. That is, the
105  * projection the edge onto each axis.
106  */
107 INLINE LVecBase3d EggMesherEdge::
108 compute_box(const EggVertexPool *vertex_pool) const {
109  LPoint3d a = vertex_pool->get_vertex(_vi_a)->get_pos3();
110  LPoint3d b = vertex_pool->get_vertex(_vi_b)->get_pos3();
111  LVector3d v = (a - b);
112  return LVecBase3d(fabs(v[0]), fabs(v[1]), fabs(v[2]));
113 }
EggMesherEdge(int vi_a, int vi_b)
Defines an edge as a pair of vertices.
Definition: eggMesherEdge.I:19
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...
LVertexd get_pos3() const
Valid if get_num_dimensions() returns 3 or 4.
Definition: eggVertex.I:131
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...
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:49
bool contains_vertex(int vi) const
Returns true if the edge contains the indicated vertex index, false otherwise.
Definition: eggMesherEdge.I:40
bool operator<(const EggMesherEdge &other) const
Defines an arbitrary ordering for edges, used for putting edges in a sorted container.
Definition: eggMesherEdge.I:85
EggMesherEdge * common_ptr()
Returns an arbitrary pointer that is used to represent both this edge and its opposite.
Definition: eggMesherEdge.I:60
Represents one edge of a triangle, as used by the EggMesher to discover connected triangles.
Definition: eggMesherEdge.h:29
double compute_length(const EggVertexPool *vertex_pool) const
Returns the length of the edge in model units.
Definition: eggMesherEdge.I:96
A collection of vertices.
Definition: eggVertexPool.h:41