All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
MortonKey.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "VectorMathDecl.h"
7 #include <string>
8 #include <functional>
9 
10 namespace Eegeo
11 {
12  namespace Streaming
13  {
14  struct MortonKey
15  {
16  private:
17  s64 value;
18  public:
19  explicit MortonKey(int rootFaceIndex);
20 
21  int Depth() const;
22  MortonKey Push(int quadrant) const;
23  MortonKey Pop(int timesToPop=1) const;
24 
25  int Element(int index) const;
26  int At(int index) const;
27  bool operator ==(const MortonKey& other) const;
28  bool operator !=(const MortonKey& other) const;
29  bool operator <(const MortonKey& other) const;
30  bool IsParentOfKey(const MortonKey& potentialChildKey) const;
31  double WidthInMetres() const;
32  std::string ToString() const;
33  int Face() const;
34  bool CoversEcefPoint(const Eegeo::dv3& ecefPosition) const;
35  s64 RawValue() const { return value; }
36 
37  static MortonKey CreateFromRawValue(s64 rawKey);
38  static MortonKey CreateFromString(const char* keyString);
39  };
40 
42  {
43  public:
44  inline bool operator()(const MortonKey& a, const MortonKey& b) const
45  {
46  return a.RawValue() < b.RawValue();
47  }
48  };
49 
51  {
52  inline std::size_t operator()(const Eegeo::Streaming::MortonKey& mortonKey) const
53  {
54  return std::hash<s64>{}(mortonKey.RawValue());
55  }
56  };
57 
58  }
59 }