mortonid.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * \file mortonid.hpp
  3. * \author Dhairya Malhotra, dhairya.malhotra@gmail.com
  4. * \date 2-11-2011
  5. * \brief This file contains definition of the class MortonId.
  6. */
  7. #include <vector>
  8. #include <stdint.h>
  9. #include <pvfmm_common.hpp>
  10. #ifndef _PVFMM_MORTONID_HPP_
  11. #define _PVFMM_MORTONID_HPP_
  12. namespace pvfmm{
  13. #ifndef MAX_DEPTH
  14. #define MAX_DEPTH 30
  15. #endif
  16. #if MAX_DEPTH < 7
  17. #define UINT_T uint8_t
  18. #define INT_T int8_t
  19. #elif MAX_DEPTH < 15
  20. #define UINT_T uint16_t
  21. #define INT_T int16_t
  22. #elif MAX_DEPTH < 31
  23. #define UINT_T uint32_t
  24. #define INT_T int32_t
  25. #elif MAX_DEPTH < 63
  26. #define UINT_T uint64_t
  27. #define INT_T int64_t
  28. #endif
  29. class MortonId{
  30. public:
  31. MortonId();
  32. MortonId(MortonId m, unsigned char depth);
  33. template <class T>
  34. MortonId(T x_f,T y_f, T z_f, unsigned char depth=MAX_DEPTH);
  35. template <class T>
  36. MortonId(T* coord, unsigned char depth=MAX_DEPTH);
  37. unsigned int GetDepth() const;
  38. template <class T>
  39. void GetCoord(T* coord);
  40. MortonId NextId() const;
  41. MortonId getAncestor(unsigned char ancestor_level) const;
  42. /**
  43. * \brief Returns the deepest first descendant.
  44. */
  45. MortonId getDFD(unsigned char level=MAX_DEPTH) const;
  46. void NbrList(std::vector<MortonId>& nbrs,unsigned char level, int periodic) const;
  47. std::vector<MortonId> Children() const;
  48. int operator<(const MortonId& m) const;
  49. int operator>(const MortonId& m) const;
  50. int operator==(const MortonId& m) const;
  51. int operator!=(const MortonId& m) const;
  52. int operator<=(const MortonId& m) const;
  53. int operator>=(const MortonId& m) const;
  54. int isAncestor(MortonId const & other) const;
  55. friend std::ostream& operator<<(std::ostream& out, const MortonId & mid);
  56. private:
  57. UINT_T x,y,z;
  58. unsigned char depth;
  59. };
  60. }//end namespace
  61. #include <mortonid.txx>
  62. #endif //_PVFMM_MORTONID_HPP_