1
+ /* *
2
+ * @file Morton.h
3
+ * @author Quoc-Minh Ton-That ([email protected] )
4
+ * @brief This file contains functions to compute Morton codes.
5
+ * @date 2025-02-12
6
+ *
7
+ * @copyright Copyright (c) 2025
8
+ *
9
+ */
10
+
1
11
#ifndef PBAT_GEOMETRY_MORTON_H
2
12
#define PBAT_GEOMETRY_MORTON_H
3
13
11
21
namespace pbat {
12
22
namespace geometry {
13
23
14
- using MortonCodeType = std::uint32_t ;
15
-
16
- // NOTE:
17
- // We make these (otherwise non-templated) functions inline so that they
18
- // are compiled by nvcc whenever this header is included in cuda sources.
24
+ using MortonCodeType = std::uint32_t ; // /< Type used to represent Morton codes
19
25
20
- // Expands a 10-bit integer into 30 bits
21
- // by inserting 2 zeros after each bit.
26
+ /* *
27
+ * @brief Expands a 10-bit integer into 30 bits by inserting 2 zeros after each bit.
28
+ *
29
+ * @note We make this (otherwise non-templated) function inline so that it gets compiled by nvcc
30
+ * whenever this header is included in cuda sources.
31
+ *
32
+ * @param v 10-bit integer
33
+ * @return Expanded 30-bit integer
34
+ */
22
35
PBAT_HOST_DEVICE inline MortonCodeType ExpandBits (MortonCodeType v)
23
36
{
24
37
v = (v * 0x00010001u ) & 0xFF0000FFu ;
@@ -28,13 +41,32 @@ PBAT_HOST_DEVICE inline MortonCodeType ExpandBits(MortonCodeType v)
28
41
return v;
29
42
}
30
43
31
- // Calculates a 30-bit Morton code for the
32
- // given 3D point located within the unit cube [0,1].
44
+ namespace detail {
45
+
33
46
template <class Point >
34
- requires std::is_convertible_v<
35
- decltype (std::declval<Point>()[std::declval<int >()]),
36
- float > [[maybe_unused]] PBAT_HOST_DEVICE inline MortonCodeType
37
- Morton3D (Point x)
47
+ concept CMorton3dPoint = requires (Point p)
48
+ {
49
+ {
50
+ p[0 ]
51
+ } -> std::convertible_to<float >;
52
+ {
53
+ p[1 ]
54
+ } -> std::convertible_to<float >;
55
+ {
56
+ p[2 ]
57
+ } -> std::convertible_to<float >;
58
+ };
59
+
60
+ } // namespace detail
61
+
62
+ /* *
63
+ * @brief Calculates a 30-bit Morton code for the given 3D point located within the unit cube [0,1].
64
+ * @tparam Point Type of the point
65
+ * @param x 3D point located within the unit cube [0,1]
66
+ * @return Morton code of x
67
+ */
68
+ template <detail::CMorton3dPoint Point>
69
+ [[maybe_unused]] PBAT_HOST_DEVICE inline MortonCodeType Morton3D (Point x)
38
70
{
39
71
using namespace std ;
40
72
MortonCodeType xx =
0 commit comments