-
-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb273f6
commit ca2cdb8
Showing
17 changed files
with
1,568 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//----------------------------------------------- | ||
// | ||
// This file is part of the Siv3D Engine. | ||
// | ||
// Copyright (c) 2008-2023 Ryo Suzuki | ||
// Copyright (c) 2016-2023 OpenSiv3D Project | ||
// | ||
// Licensed under the MIT License. | ||
// | ||
//----------------------------------------------- | ||
|
||
# pragma once | ||
# include "Common.hpp" | ||
# include "PointVector.hpp" | ||
|
||
namespace s3d | ||
{ | ||
/// @brief 32-bit にエンコードされたモートン順序 | ||
using Morton32 = uint32; | ||
|
||
/// @brief 64-bit にエンコードされたモートン順序 | ||
using Morton64 = uint64; | ||
|
||
namespace Morton | ||
{ | ||
/// @brief 2D 座標を 32-bit のモートン順序にエンコードして返します。 | ||
/// @param x X 座標 | ||
/// @param y Y 座標 | ||
/// @return モートン順序 | ||
[[nodiscard]] | ||
Morton32 Encode2D32(uint16 x, uint16 y) noexcept; | ||
|
||
/// @brief 2D 座標を 64-bit のモートン順序にエンコードして返します。 | ||
/// @param x X 座標 | ||
/// @param y Y 座標 | ||
/// @return モートン順序 | ||
[[nodiscard]] | ||
Morton64 Encode2D64(uint32 x, uint32 y) noexcept; | ||
|
||
/// @brief 2D 座標を 32-bit のモートン順序にエンコードして返します。 | ||
/// @param pos 座標 | ||
/// @return モートン順序 | ||
[[nodiscard]] | ||
Morton32 Encode2D32(Point pos) noexcept; | ||
|
||
/// @brief 2D 座標を 64-bit のモートン順序にエンコードして返します。 | ||
/// @param pos 座標 | ||
/// @return モートン順序 | ||
[[nodiscard]] | ||
Morton64 Encode2D64(Point pos) noexcept; | ||
|
||
/// @brief 32-bit のモートン順序を 2D 座標にデコードして返します。 | ||
/// @param morton モートン順序 | ||
/// @return 2D 座標 | ||
[[nodiscard]] | ||
Point Decode2D32(Morton32 morton) noexcept; | ||
|
||
/// @brief 64-bit のモートン順序を 2D 座標にデコードして返します。 | ||
/// @param morton モートン順序 | ||
/// @return 2D 座標 | ||
[[nodiscard]] | ||
Point Decode2D64(Morton64 morton) noexcept; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//----------------------------------------------- | ||
// | ||
// This file is part of the Siv3D Engine. | ||
// | ||
// Copyright (c) 2008-2023 Ryo Suzuki | ||
// Copyright (c) 2016-2023 OpenSiv3D Project | ||
// | ||
// Licensed under the MIT License. | ||
// | ||
//----------------------------------------------- | ||
|
||
# include <ThirdParty/libmorton/morton.h> | ||
# include <Siv3D/Morton.hpp> | ||
|
||
namespace s3d | ||
{ | ||
namespace Morton | ||
{ | ||
Morton32 Encode2D32(const uint16 x, const uint16 y) noexcept | ||
{ | ||
return libmorton::morton2D_32_encode(x, y); | ||
} | ||
|
||
Morton64 Encode2D64(const uint32 x, const uint32 y) noexcept | ||
{ | ||
return libmorton::morton2D_64_encode(x, y); | ||
} | ||
|
||
Morton32 Encode2D32(const Point pos) noexcept | ||
{ | ||
return libmorton::morton2D_32_encode(static_cast<std::uint_fast16_t>(pos.x), static_cast<std::uint_fast16_t>(pos.y)); | ||
} | ||
|
||
Morton64 Encode2D64(const Point pos) noexcept | ||
{ | ||
return libmorton::morton2D_64_encode(static_cast<std::uint_fast32_t>(pos.x), static_cast<std::uint_fast32_t>(pos.y)); | ||
} | ||
|
||
Point Decode2D32(const Morton32 morton) noexcept | ||
{ | ||
std::uint_fast16_t x, y; | ||
libmorton::morton2D_32_decode(morton, x, y); | ||
return{ x, y }; | ||
} | ||
|
||
Point Decode2D64(const Morton64 morton) noexcept | ||
{ | ||
std::uint_fast32_t x, y; | ||
libmorton::morton2D_64_decode(morton, x, y); | ||
return{ x, y }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#pragma once | ||
|
||
// This file will always contain inline functions which point to the fastest Morton encoding/decoding implementation | ||
// IF you just want to use the fastest method to encode/decode morton codes, include this header. | ||
|
||
// If you want to experiment with alternative methods (which might be slower, all depending on hardware / your data set) | ||
// check the individual headers below. | ||
|
||
#include "morton2D.h" | ||
#include "morton3D.h" | ||
|
||
#if defined(__BMI2__) || defined(__AVX2__) | ||
#include "morton_BMI.h" | ||
#elif defined(__AVX512BITALG__) | ||
#include "morton_AVX512BITALG.h" | ||
#endif | ||
|
||
namespace libmorton { | ||
// Functions under this are stubs which will always point to fastest implementation at the moment | ||
//----------------------------------------------------------------------------------------------- | ||
|
||
// ENCODING | ||
#if defined(__BMI2__) || defined(__AVX2__) | ||
inline uint_fast32_t morton2D_32_encode(const uint_fast16_t x, const uint_fast16_t y) { | ||
return m2D_e_BMI<uint_fast32_t, uint_fast16_t>(x, y); | ||
} | ||
inline uint_fast64_t morton2D_64_encode(const uint_fast32_t x, const uint_fast32_t y) { | ||
return m2D_e_BMI<uint_fast64_t, uint_fast32_t>(x, y); | ||
} | ||
inline uint_fast32_t morton3D_32_encode(const uint_fast16_t x, const uint_fast16_t y, const uint_fast16_t z) { | ||
return m3D_e_BMI<uint_fast32_t, uint_fast16_t>(x, y, z); | ||
} | ||
inline uint_fast64_t morton3D_64_encode(const uint_fast32_t x, const uint_fast32_t y, const uint_fast32_t z) { | ||
return m3D_e_BMI<uint_fast64_t, uint_fast32_t>(x, y, z); | ||
} | ||
#elif defined(__AVX512BITALG__) | ||
inline uint_fast32_t morton2D_32_encode(const uint_fast16_t x, const uint_fast16_t y) { | ||
return m2D_e_BITALG<uint_fast32_t, uint_fast16_t>(x, y); | ||
} | ||
inline uint_fast64_t morton2D_64_encode(const uint_fast32_t x, const uint_fast32_t y) { | ||
return m2D_e_BITALG<uint_fast64_t, uint_fast32_t>(x, y); | ||
} | ||
inline uint_fast32_t morton3D_32_encode(const uint_fast16_t x, const uint_fast16_t y, const uint_fast16_t z) { | ||
return m3D_e_BITALG<uint_fast32_t, uint_fast16_t>(x, y, z); | ||
} | ||
inline uint_fast64_t morton3D_64_encode(const uint_fast32_t x, const uint_fast32_t y, const uint_fast32_t z) { | ||
return m3D_e_BITALG<uint_fast64_t, uint_fast32_t>(x, y, z); | ||
} | ||
#else | ||
inline uint_fast32_t morton2D_32_encode(const uint_fast16_t x, const uint_fast16_t y) { | ||
return m2D_e_magicbits_combined(x, y); | ||
} | ||
inline uint_fast64_t morton2D_64_encode(const uint_fast32_t x, const uint_fast32_t y) { | ||
return m2D_e_sLUT<uint_fast64_t, uint_fast32_t>(x, y); | ||
} | ||
inline uint_fast32_t morton3D_32_encode(const uint_fast16_t x, const uint_fast16_t y, const uint_fast16_t z) { | ||
return m3D_e_sLUT<uint_fast32_t, uint_fast16_t>(x, y, z); | ||
} | ||
inline uint_fast64_t morton3D_64_encode(const uint_fast32_t x, const uint_fast32_t y, const uint_fast32_t z) { | ||
return m3D_e_sLUT<uint_fast64_t, uint_fast32_t>(x, y, z); | ||
} | ||
#endif | ||
|
||
// DECODING | ||
|
||
#if defined(__BMI2__) || defined(__AVX2__) | ||
inline void morton2D_32_decode(const uint_fast32_t morton, uint_fast16_t& x, uint_fast16_t& y) { | ||
m2D_d_BMI<uint_fast32_t, uint_fast16_t>(morton, x, y); | ||
} | ||
inline void morton2D_64_decode(const uint_fast64_t morton, uint_fast32_t& x, uint_fast32_t& y) { | ||
m2D_d_BMI<uint_fast64_t, uint_fast32_t>(morton, x, y); | ||
} | ||
inline void morton3D_32_decode(const uint_fast32_t morton, uint_fast16_t& x, uint_fast16_t& y, uint_fast16_t& z) { | ||
m3D_d_BMI<uint_fast32_t, uint_fast16_t>(morton, x, y, z); | ||
} | ||
inline void morton3D_64_decode(const uint_fast64_t morton, uint_fast32_t& x, uint_fast32_t& y, uint_fast32_t& z) { | ||
m3D_d_BMI<uint_fast64_t, uint_fast32_t>(morton, x, y, z); | ||
} | ||
#elif defined(__AVX512BITALG__) | ||
inline void morton2D_32_decode(const uint_fast32_t morton, uint_fast16_t& x, uint_fast16_t& y) { | ||
m2D_d_BITALG<uint_fast32_t, uint_fast16_t>(morton, x, y); | ||
} | ||
inline void morton2D_64_decode(const uint_fast64_t morton, uint_fast32_t& x, uint_fast32_t& y) { | ||
m2D_d_BITALG<uint_fast64_t, uint_fast32_t>(morton, x, y); | ||
} | ||
inline void morton3D_32_decode(const uint_fast32_t morton, uint_fast16_t& x, uint_fast16_t& y, uint_fast16_t& z) { | ||
m3D_d_BITALG<uint_fast32_t, uint_fast16_t>(morton, x, y, z); | ||
} | ||
inline void morton3D_64_decode(const uint_fast64_t morton, uint_fast32_t& x, uint_fast32_t& y, uint_fast32_t& z) { | ||
m3D_d_BITALG<uint_fast64_t, uint_fast32_t>(morton, x, y, z); | ||
} | ||
#else | ||
inline void morton2D_32_decode(const uint_fast32_t morton, uint_fast16_t& x, uint_fast16_t& y) { | ||
m2D_d_magicbits_combined(morton, x, y); | ||
} | ||
inline void morton2D_64_decode(const uint_fast64_t morton, uint_fast32_t& x, uint_fast32_t& y) { | ||
m2D_d_sLUT<uint_fast64_t, uint_fast32_t>(morton, x, y); | ||
} | ||
inline void morton3D_32_decode(const uint_fast32_t morton, uint_fast16_t& x, uint_fast16_t& y, uint_fast16_t& z) { | ||
m3D_d_sLUT<uint_fast32_t, uint_fast16_t>(morton, x, y, z); | ||
} | ||
inline void morton3D_64_decode(const uint_fast64_t morton, uint_fast32_t& x, uint_fast32_t& y, uint_fast32_t& z) { | ||
m3D_d_sLUT<uint_fast64_t, uint_fast32_t>(morton, x, y, z); | ||
} | ||
#endif | ||
} |
Oops, something went wrong.