morton codes
来源:互联网 发布:淘宝休闲运动服 编辑:程序博客网 时间:2024/06/10 01:46
In case someone is using morton codes in 3d, so he needs to read one bit every 3, and 64 bits here is the function I used:
uint64_t morton3(uint64_t x) { x = x & 0x9249249249249249; x = (x | (x >> 2)) & 0x30c30c30c30c30c3; x = (x | (x >> 4)) & 0xf00f00f00f00f00f; x = (x | (x >> 8)) & 0x00ff0000ff0000ff; x = (x | (x >> 16)) & 0xffff00000000ffff; x = (x | (x >> 32)) & 0x00000000ffffffff; return x;}uint64_t bits; uint64_t x = morton3(bits)uint64_t y = morton3(bits>>1)uint64_t z = morton3(bits>>2)
///////////////////////////////////////////////
I'm looking for a fast way to compute a 3D Morton number. This site has a magic-number based trick for doing it for 2D Morton numbers, but it doesn't seem obvious how to extend it to 3D: http://www-graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN
So basically I have 3 10-bit numbers that I want to interleave into a single 30 bit number with a minimal number of operations.
///////
You can use the same technique. I'm assuming that variables contain 32-bit integers with the highest 22 bits set to
0
(which is a bit more restrictive than necessary). For each variablex
containing one of the three 10-bit integers we do the following:x = (x | (x << 16)) & 0x030000FF;x = (x | (x << 8)) & 0x0300F00F;x = (x | (x << 4)) & 0x030C30C3;x = (x | (x << 2)) & 0x09249249;
Then, with
x
,y
andz
the three manipulated 10-bit integers we get the result by taking:x | (y << 1) | (z << 2)
The way this technique works is as follows. Each of the
x = ...
lines above "splits" groups of bits in half such that there is enough space in between for the bits of the other integers. For example, if we consider three 4-bit integers, we split one with bits 1234 into 000012000034 where the zeros are reserved for the other integers. In the next step we split 12 and 34 in the same way to get 001002003004. Even though 10 bits doesn't make for a nice repeated division in two groups, you can just consider it 16 bits where you lose the highest ones in the end.As you can see from the first line, you actually only need that for each input integer
x
it holds thatx & 0x03000000 == 0
.
- morton codes
- Morton Code
- Morton Code
- Morton码反算行列号
- morton code 相关
- codes
- codes
- codes
- Andrew Morton on kernel development
- ASIS CTF 2017 Mary Morton
- 1989年的图灵奖获得者-William (Velvel) Morton Kahan
- Javascript Codes
- Keyboard Codes
- key codes
- Key Codes
- php codes
- Condition Codes
- Hamming Codes
- List的普通for loop delete 连续元素有遗漏的解决
- Android实时获取当前下载速度
- linux命令——scp 两台linux机器间文件或目录传输
- SCU2016-03 O题二分 + DLX可重复覆盖
- centos7下JDK安装
- morton codes
- 设计模式六大原则
- RabbitMQ(一): 详细介绍
- Intellij IDEA 使用技巧-- 快捷键
- addSubview和 insertSubView 区别
- 标签传播(LPA)算法及python基于igraph包的实现
- tomcat7 开机自启动,配置固定jdk
- $(document).ready(){}),$(function(){}),$(window).load()
- JAVA设计模式之单例模式