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