HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_Edge.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GA_Edge.h (GA Library, C++)
7  *
8  * COMMENTS: This class represents an edge as two point offsets.
9  * Comparisons treat the edge as undirected.
10  */
11 
12 #ifndef __GA_Edge__
13 #define __GA_Edge__
14 
15 #include "GA_API.h"
16 #include "GA_Types.h"
17 #include <UT/UT_Map.h>
18 #include <UT/UT_Set.h>
19 #include <SYS/SYS_Hash.h>
20 
21 template<typename T,bool DIRECTED>
22 class GA_EdgeT
23 {
24 public:
26 
27  GA_EdgeT() : myP0(T(-1)), myP1(T(-1)) {}
28  GA_EdgeT(T pt0, T pt1) : myP0(pt0), myP1(pt1) {}
29  ~GA_EdgeT() {}
30 
31  T p0() const { return myP0; }
32  T &p0() { return myP0; }
33  T p1() const { return myP1; }
34  T &p1() { return myP1; }
35 
37  {
38  return sizeof(*this);
39  }
40 
41  bool isValid() const
42  { return GAisValid(myP0) && GAisValid(myP1); }
43 
44  /// Return whether this edge is the same undirected edge as the given edge.
45  bool operator==(const ThisType & e) const
46  {
47  if (DIRECTED)
48  {
49  return (myP0 == e.myP0 && myP1 == e.myP1);
50  }
51  else
52  {
53  return (myP0 == e.myP0 && myP1 == e.myP1)
54  || (myP0 == e.myP1 && myP1 == e.myP0);
55  }
56  }
57  bool operator!=(const ThisType & e) const
58  {
59  return !(*this == e);
60  }
61 
62  /// Hash function
63  size_t hash() const
64  {
65  size_t hash_val;
66  if (DIRECTED || myP0 < myP1)
67  {
68  hash_val = GA_Size(myP0);
69  SYShashCombine(hash_val, GA_Size(myP1));
70  }
71  else
72  {
73  hash_val = GA_Size(myP1);
74  SYShashCombine(hash_val, GA_Size(myP0));
75  }
76  return hash_val;
77  }
78 
79 private:
80  T myP0;
81  T myP1;
82 };
83 
84 template<typename T,bool DIRECTED>
86 {
87  return edge.hash();
88 }
89 
90 // Specialize the GA_EdgeT template for the known edge types
93 
96 
97 /// A helper specialization of UT_Map to support a map keyed by GA_Edge or GA_DirectedEdge
98 template <typename ToType>
100 
101 template <typename ToType>
103 
106 
107 #endif
GA_EdgeT(T pt0, T pt1)
Definition: GA_Edge.h:28
bool operator==(const ThisType &e) const
Return whether this edge is the same undirected edge as the given edge.
Definition: GA_Edge.h:45
Unsorted map container.
Definition: UT_Map.h:83
bool GAisValid(GA_Size v)
Definition: GA_Types.h:625
~GA_EdgeT()
Definition: GA_Edge.h:29
T & p1()
Definition: GA_Edge.h:34
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
bool isValid() const
Definition: GA_Edge.h:41
GA_EdgeT< T, DIRECTED > ThisType
Definition: GA_Edge.h:25
long long int64
Definition: SYS_Types.h:106
T & p0()
Definition: GA_Edge.h:32
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
T p1() const
Definition: GA_Edge.h:33
SYS_FORCE_INLINE size_t hash_value(const GA_EdgeT< T, DIRECTED > &edge)
Definition: GA_Edge.h:85
size_t hash() const
Hash function.
Definition: GA_Edge.h:63
int64 getMemoryUsage() const
Definition: GA_Edge.h:36
GA_EdgeT()
Definition: GA_Edge.h:27
bool operator!=(const ThisType &e) const
Definition: GA_Edge.h:57
T p0() const
Definition: GA_Edge.h:31