z-order-curve

How to use Morton Order(z order curve) in range search?

岁酱吖の 提交于 2020-02-18 05:06:10
问题 How to use Morton Order in range search? From the wiki, In the paragraph "Use with one-dimensional data structures for range searching", it says "the range being queried (x = 2, ..., 3, y = 2, ..., 6) is indicated by the dotted rectangle. Its highest Z-value (MAX) is 45. In this example, the value F = 19 is encountered when searching a data structure in increasing Z-value direction. ......BIGMIN (36 in the example).....only search in the interval between BIGMIN and MAX...." My questions are:

Benefits of nearest neighbor search with Morton-order?

时光总嘲笑我的痴心妄想 提交于 2020-01-12 18:35:56
问题 While working on the simulation of particle interactions, I stumbled across grid indexing in Morton-order (Z-order)(Wikipedia link) which is regarded to provide an efficient nearest neighbor cell search. The main reason that I've read is the almost sequential ordering of spatially close cells in memory. Being in the middle of a first implementation, I can not wrap my head around how to efficiently implement the algorithm for the nearest neighbors, especially in comparison to a basic uniform

2D Morton decode function 64bits

落爺英雄遲暮 提交于 2020-01-02 15:04:56
问题 The first function encodes [x, y] as 64bit wide Morton code where x and y are 32bit wide integers using Interleave bits by Binary Magic Numbers. What would be the reverse function? void xy2d_morton_64bits(uint64_t x, uint64_t y, uint64_t *d) { x = (x | (x << 16)) & 0x0000FFFF0000FFFF; x = (x | (x << 8)) & 0x00FF00FF00FF00FF; x = (x | (x << 4)) & 0x0F0F0F0F0F0F0F0F; x = (x | (x << 2)) & 0x3333333333333333; x = (x | (x << 1)) & 0x5555555555555555; y = (y | (y << 16)) & 0x0000FFFF0000FFFF; y =

2D morton code encode/decode 64bits

末鹿安然 提交于 2019-12-17 11:13:27
问题 How to encode/decode morton codes(z-order) given [x, y] as 32bit unsigned integers producing 64bit morton code, and vice verse ? I do have xy2d and d2xy but only for coordinates that are 16bits wide producing 32bit morton number. Searched a lot in net, but couldn't find. Please help. 回答1: If it is possible for you to use architecture specific instructions you'll likely be able to accelerate the operation beyond what is possible using bit-twiddeling hacks: For example if you write code for the

2D morton code encode/decode 64bits

元气小坏坏 提交于 2019-12-17 11:13:11
问题 How to encode/decode morton codes(z-order) given [x, y] as 32bit unsigned integers producing 64bit morton code, and vice verse ? I do have xy2d and d2xy but only for coordinates that are 16bits wide producing 32bit morton number. Searched a lot in net, but couldn't find. Please help. 回答1: If it is possible for you to use architecture specific instructions you'll likely be able to accelerate the operation beyond what is possible using bit-twiddeling hacks: For example if you write code for the

2D Morton decode function 64bits

不羁的心 提交于 2019-12-06 15:35:33
The first function encodes [x, y] as 64bit wide Morton code where x and y are 32bit wide integers using Interleave bits by Binary Magic Numbers. What would be the reverse function? void xy2d_morton_64bits(uint64_t x, uint64_t y, uint64_t *d) { x = (x | (x << 16)) & 0x0000FFFF0000FFFF; x = (x | (x << 8)) & 0x00FF00FF00FF00FF; x = (x | (x << 4)) & 0x0F0F0F0F0F0F0F0F; x = (x | (x << 2)) & 0x3333333333333333; x = (x | (x << 1)) & 0x5555555555555555; y = (y | (y << 16)) & 0x0000FFFF0000FFFF; y = (y | (y << 8)) & 0x00FF00FF00FF00FF; y = (y | (y << 4)) & 0x0F0F0F0F0F0F0F0F; y = (y | (y << 2)) &

Benefits of nearest neighbor search with Morton-order?

孤人 提交于 2019-12-04 05:26:59
While working on the simulation of particle interactions, I stumbled across grid indexing in Morton-order (Z-order)( Wikipedia link ) which is regarded to provide an efficient nearest neighbor cell search. The main reason that I've read is the almost sequential ordering of spatially close cells in memory. Being in the middle of a first implementation, I can not wrap my head around how to efficiently implement the algorithm for the nearest neighbors, especially in comparison to a basic uniform grid. Given a cell (x,y) it is trivial to obtain the 8 neighbor cell indices and compute the

How can I shuffle bits efficiently?

余生颓废 提交于 2019-11-30 12:59:53
问题 I need to shuffle a 16 bit unsigned integer in a way that the even indexes land in the lower byte, and the odd indexes land in the upper byte. input: fedcba98 76543210 (contiguously numbered) output: fdb97531 eca86420 (even and odd separated) My code looks like this at the moment: typedef unsigned short u16; u16 segregate(u16 x) { u16 g = (x & 0x0001); u16 h = (x & 0x0004) >> 1; u16 i = (x & 0x0010) >> 2; u16 j = (x & 0x0040) >> 3; u16 k = (x & 0x0100) >> 4; u16 l = (x & 0x0400) >> 5; u16 m =

How can I shuffle bits efficiently?

故事扮演 提交于 2019-11-30 05:01:19
I need to shuffle a 16 bit unsigned integer in a way that the even indexes land in the lower byte, and the odd indexes land in the upper byte. input: fedcba98 76543210 (contiguously numbered) output: fdb97531 eca86420 (even and odd separated) My code looks like this at the moment: typedef unsigned short u16; u16 segregate(u16 x) { u16 g = (x & 0x0001); u16 h = (x & 0x0004) >> 1; u16 i = (x & 0x0010) >> 2; u16 j = (x & 0x0040) >> 3; u16 k = (x & 0x0100) >> 4; u16 l = (x & 0x0400) >> 5; u16 m = (x & 0x1000) >> 6; u16 n = (x & 0x4000) >> 7; u16 o = (x & 0x0002) << 7; u16 p = (x & 0x0008) << 6;

How to efficiently de-interleave bits (inverse Morton)

微笑、不失礼 提交于 2019-11-27 20:09:30
This question: How to de-interleave bits (UnMortonizing?) has a good answer for extracting one of the two halves of a Morton number (just the odd bits), but I need a solution which extracts both parts (the odd bits and the even bits) in as few operations as possible. For my use I would need to take a 32 bit int and extract two 16 bit ints, where one is the even bits and the other is the odd bits shifted right by 1 bit, e.g. input, z: 11101101 01010111 11011011 01101110 output, x: 11100001 10110111 // odd bits shifted right by 1 y: 10111111 11011010 // even bits There seem to be plenty of