Wildmeshing Toolkit
Loading...
Searching...
No Matches
src
wmtk
utils
Morton.h
1
/*
2
This file is part of NSEssentials.
3
4
Use of this source code is granted via a BSD-style license, which can be found
5
in License.txt in the repository root.
6
7
@author Nico Schertler
8
*/
9
10
#pragma once
11
#ifdef NSE_BUILD_SHARED
12
#ifndef NSE_EXPORT
13
#ifdef _WIN32
14
#ifdef nsessentials_EXPORTS
15
/* We are building this library */
16
#define NSE_EXPORT __declspec(dllexport)
17
#else
18
/* We are using this library */
19
#define NSE_EXPORT __declspec(dllimport)
20
#endif
21
#else
22
#define NSE_EXPORT
23
#endif
24
#endif
25
#else
26
#define NSE_EXPORT
27
#endif
28
#include <stdint.h>
29
#include <cinttypes>
30
31
namespace
Resorting {
32
33
// Represents a three-dimensional 64-bit Morton Code.
34
class
NSE_EXPORT
MortonCode64
35
{
36
public
:
37
MortonCode64
();
38
39
MortonCode64
(int32_t x, int32_t y, int32_t z);
40
41
MortonCode64
(uint32_t x, uint32_t y, uint32_t z);
42
43
MortonCode64
(uint64_t);
44
45
// Decodes the code into its three coordinates.
46
void
decode(int32_t& x, int32_t& y, int32_t& z)
const
;
47
48
// Negates the specified coordinate.
49
template
<
int
DIM>
50
MortonCode64
InvertDimension()
const
;
51
52
// Under the assumption that all entries are positive
53
MortonCode64
DivideDimensionBy2(
int
dim)
const
;
54
MortonCode64
Negate()
const
;
55
56
MortonCode64
operator+(
const
MortonCode64
rhs)
const
;
57
MortonCode64
operator+(
const
int64_t rhs)
const
;
58
MortonCode64
& operator+=(
const
MortonCode64
rhs);
59
MortonCode64
operator-(
const
MortonCode64
rhs)
const
;
60
61
// Applies the bitshift to every dimension, assumes all entries to be positive
62
MortonCode64
operator>>(
int
shift)
const
;
63
MortonCode64
operator<<(
int
shift)
const
;
64
65
bool
operator<(
const
MortonCode64
rhs)
const
{
return
data < rhs.data; }
66
bool
operator>(
const
MortonCode64
rhs)
const
{
return
data > rhs.data; }
67
bool
operator<=(
const
MortonCode64
rhs)
const
{
return
data <= rhs.data; }
68
bool
operator>=(
const
MortonCode64
rhs)
const
{
return
data >= rhs.data; }
69
bool
operator==(
const
MortonCode64
rhs)
const
{
return
data == rhs.data; }
70
bool
operator!=(
const
MortonCode64
rhs)
const
{
return
data != rhs.data; }
71
72
explicit
operator
uint64_t()
const
{
return
data; }
73
74
static
const
MortonCode64
Zero;
75
static
const
MortonCode64
UnitX;
76
static
const
MortonCode64
UnitY;
77
static
const
MortonCode64
UnitZ;
78
79
private
:
80
uint64_t data;
81
};
82
83
}
// namespace Resorting
Resorting::MortonCode64
Definition
Morton.h:35
Generated by
1.9.8