227 Z-Order 2D curve for 32-bit integer values.
229 Code is ported from AladinSrc.jar version 11.024,
230 ZOrderCurve2DImpls.java.
231 AladinSrc.jar is licensed with GPLv3, see
232 http://aladin.u-strasbg.fr/COPYING
234 From the original documentation:
235 "Z-Order Curve (ZOC) implementation in which the vertical coordinate
236 carry the most significant bit (VMSB). This implementation is based
237 on a lookup table (LOOKUP). We assume that each discritized
238 coordinates is coded on maximum 32 bits (INT)."
240 LUPT_TO_HASH = np.array([
241 0x0000, 0x0001, 0x0004, 0x0005, 0x0010, 0x0011, 0x0014, 0x0015, 0x0040, 0x0041, 0x0044,
242 0x0045, 0x0050, 0x0051, 0x0054, 0x0055, 0x0100, 0x0101, 0x0104, 0x0105, 0x0110, 0x0111,
243 0x0114, 0x0115, 0x0140, 0x0141, 0x0144, 0x0145, 0x0150, 0x0151, 0x0154, 0x0155, 0x0400,
244 0x0401, 0x0404, 0x0405, 0x0410, 0x0411, 0x0414, 0x0415, 0x0440, 0x0441, 0x0444, 0x0445,
245 0x0450, 0x0451, 0x0454, 0x0455, 0x0500, 0x0501, 0x0504, 0x0505, 0x0510, 0x0511, 0x0514,
246 0x0515, 0x0540, 0x0541, 0x0544, 0x0545, 0x0550, 0x0551, 0x0554, 0x0555, 0x1000, 0x1001,
247 0x1004, 0x1005, 0x1010, 0x1011, 0x1014, 0x1015, 0x1040, 0x1041, 0x1044, 0x1045, 0x1050,
248 0x1051, 0x1054, 0x1055, 0x1100, 0x1101, 0x1104, 0x1105, 0x1110, 0x1111, 0x1114, 0x1115,
249 0x1140, 0x1141, 0x1144, 0x1145, 0x1150, 0x1151, 0x1154, 0x1155, 0x1400, 0x1401, 0x1404,
250 0x1405, 0x1410, 0x1411, 0x1414, 0x1415, 0x1440, 0x1441, 0x1444, 0x1445, 0x1450, 0x1451,
251 0x1454, 0x1455, 0x1500, 0x1501, 0x1504, 0x1505, 0x1510, 0x1511, 0x1514, 0x1515, 0x1540,
252 0x1541, 0x1544, 0x1545, 0x1550, 0x1551, 0x1554, 0x1555, 0x4000, 0x4001, 0x4004, 0x4005,
253 0x4010, 0x4011, 0x4014, 0x4015, 0x4040, 0x4041, 0x4044, 0x4045, 0x4050, 0x4051, 0x4054,
254 0x4055, 0x4100, 0x4101, 0x4104, 0x4105, 0x4110, 0x4111, 0x4114, 0x4115, 0x4140, 0x4141,
255 0x4144, 0x4145, 0x4150, 0x4151, 0x4154, 0x4155, 0x4400, 0x4401, 0x4404, 0x4405, 0x4410,
256 0x4411, 0x4414, 0x4415, 0x4440, 0x4441, 0x4444, 0x4445, 0x4450, 0x4451, 0x4454, 0x4455,
257 0x4500, 0x4501, 0x4504, 0x4505, 0x4510, 0x4511, 0x4514, 0x4515, 0x4540, 0x4541, 0x4544,
258 0x4545, 0x4550, 0x4551, 0x4554, 0x4555, 0x5000, 0x5001, 0x5004, 0x5005, 0x5010, 0x5011,
259 0x5014, 0x5015, 0x5040, 0x5041, 0x5044, 0x5045, 0x5050, 0x5051, 0x5054, 0x5055, 0x5100,
260 0x5101, 0x5104, 0x5105, 0x5110, 0x5111, 0x5114, 0x5115, 0x5140, 0x5141, 0x5144, 0x5145,
261 0x5150, 0x5151, 0x5154, 0x5155, 0x5400, 0x5401, 0x5404, 0x5405, 0x5410, 0x5411, 0x5414,
262 0x5415, 0x5440, 0x5441, 0x5444, 0x5445, 0x5450, 0x5451, 0x5454, 0x5455, 0x5500, 0x5501,
263 0x5504, 0x5505, 0x5510, 0x5511, 0x5514, 0x5515, 0x5540, 0x5541, 0x5544, 0x5545, 0x5550,
264 0x5551, 0x5554, 0x5555], dtype=np.int16)
266 LUPT_TO_IJ_INT = np.array([
267 0x000000000, 0x000000001, 0x100000000, 0x100000001, 0x000000002, 0x000000003,
268 0x100000002, 0x100000003, 0x200000000, 0x200000001, 0x300000000, 0x300000001,
269 0x200000002, 0x200000003, 0x300000002, 0x300000003, 0x000000004, 0x000000005,
270 0x100000004, 0x100000005, 0x000000006, 0x000000007, 0x100000006, 0x100000007,
271 0x200000004, 0x200000005, 0x300000004, 0x300000005, 0x200000006, 0x200000007,
272 0x300000006, 0x300000007, 0x400000000, 0x400000001, 0x500000000, 0x500000001,
273 0x400000002, 0x400000003, 0x500000002, 0x500000003, 0x600000000, 0x600000001,
274 0x700000000, 0x700000001, 0x600000002, 0x600000003, 0x700000002, 0x700000003,
275 0x400000004, 0x400000005, 0x500000004, 0x500000005, 0x400000006, 0x400000007,
276 0x500000006, 0x500000007, 0x600000004, 0x600000005, 0x700000004, 0x700000005,
277 0x600000006, 0x600000007, 0x700000006, 0x700000007, 0x000000008, 0x000000009,
278 0x100000008, 0x100000009, 0x00000000A, 0x00000000B, 0x10000000A, 0x10000000B,
279 0x200000008, 0x200000009, 0x300000008, 0x300000009, 0x20000000A, 0x20000000B,
280 0x30000000A, 0x30000000B, 0x00000000C, 0x00000000D, 0x10000000C, 0x10000000D,
281 0x00000000E, 0x00000000F, 0x10000000E, 0x10000000F, 0x20000000C, 0x20000000D,
282 0x30000000C, 0x30000000D, 0x20000000E, 0x20000000F, 0x30000000E, 0x30000000F,
283 0x400000008, 0x400000009, 0x500000008, 0x500000009, 0x40000000A, 0x40000000B,
284 0x50000000A, 0x50000000B, 0x600000008, 0x600000009, 0x700000008, 0x700000009,
285 0x60000000A, 0x60000000B, 0x70000000A, 0x70000000B, 0x40000000C, 0x40000000D,
286 0x50000000C, 0x50000000D, 0x40000000E, 0x40000000F, 0x50000000E, 0x50000000F,
287 0x60000000C, 0x60000000D, 0x70000000C, 0x70000000D, 0x60000000E, 0x60000000F,
288 0x70000000E, 0x70000000F, 0x800000000, 0x800000001, 0x900000000, 0x900000001,
289 0x800000002, 0x800000003, 0x900000002, 0x900000003, 0xA00000000, 0xA00000001,
290 0xB00000000, 0xB00000001, 0xA00000002, 0xA00000003, 0xB00000002, 0xB00000003,
291 0x800000004, 0x800000005, 0x900000004, 0x900000005, 0x800000006, 0x800000007,
292 0x900000006, 0x900000007, 0xA00000004, 0xA00000005, 0xB00000004, 0xB00000005,
293 0xA00000006, 0xA00000007, 0xB00000006, 0xB00000007, 0xC00000000, 0xC00000001,
294 0xD00000000, 0xD00000001, 0xC00000002, 0xC00000003, 0xD00000002, 0xD00000003,
295 0xE00000000, 0xE00000001, 0xF00000000, 0xF00000001, 0xE00000002, 0xE00000003,
296 0xF00000002, 0xF00000003, 0xC00000004, 0xC00000005, 0xD00000004, 0xD00000005,
297 0xC00000006, 0xC00000007, 0xD00000006, 0xD00000007, 0xE00000004, 0xE00000005,
298 0xF00000004, 0xF00000005, 0xE00000006, 0xE00000007, 0xF00000006, 0xF00000007,
299 0x800000008, 0x800000009, 0x900000008, 0x900000009, 0x80000000A, 0x80000000B,
300 0x90000000A, 0x90000000B, 0xA00000008, 0xA00000009, 0xB00000008, 0xB00000009,
301 0xA0000000A, 0xA0000000B, 0xB0000000A, 0xB0000000B, 0x80000000C, 0x80000000D,
302 0x90000000C, 0x90000000D, 0x80000000E, 0x80000000F, 0x90000000E, 0x90000000F,
303 0xA0000000C, 0xA0000000D, 0xB0000000C, 0xB0000000D, 0xA0000000E, 0xA0000000F,
304 0xB0000000E, 0xB0000000F, 0xC00000008, 0xC00000009, 0xD00000008, 0xD00000009,
305 0xC0000000A, 0xC0000000B, 0xD0000000A, 0xD0000000B, 0xE00000008, 0xE00000009,
306 0xF00000008, 0xF00000009, 0xE0000000A, 0xE0000000B, 0xF0000000A, 0xF0000000B,
307 0xC0000000C, 0xC0000000D, 0xD0000000C, 0xD0000000D, 0xC0000000E, 0xC0000000F,
308 0xD0000000E, 0xD0000000F, 0xE0000000C, 0xE0000000D, 0xF0000000C, 0xF0000000D,
309 0xE0000000E, 0xE0000000F, 0xF0000000E, 0xF0000000F], dtype=np.int64)
316 Compute the hash value from x/y.
321 x coordinate along the horizontal axis.
322 Must fit within the 32-bit integer range.
324 y coordinate along the vertical axis.
325 Must fit within the 32-bit integer range.
330 The space-filling hash value associated with the
333 return self.ij2hash(np.int32(x), np.int32(y))
337 Compute the hash value from discretized i, j.
342 i discretized coordinate along the horizontal axis.
343 Must fit within the 32-bit integer range.
345 j discretized coordinate along the vertical axis.
346 Must fit within the 32-bit integer range.
351 The space-filling hash value associated with the
354 return (self.
i02hash(np.int32(j)) << 1) | self.
i02hash(np.int32(i))
358 Special case of ij2hash in which the discretized coordinate along
359 the vertical axis equals zero.
364 i discretized coordinate along the horizontal axis.
365 Must fit within the 32-bit integer range.
370 The space-filling hash value associated with the
373 val1 = np.int64(self.
LUPT_TO_HASH[np.uint32(i) >> np.uint32(24)] << np.int64(48))
374 val2 = np.int64(self.
LUPT_TO_HASH[(np.uint32(i) & 0x00FF0000) >> np.uint32(16)] << np.uint64(32))
375 val3 = np.int64(self.
LUPT_TO_HASH[(np.uint32(i) & 0x0000FF00) >> np.uint32(8)] << np.uint64(16))
376 val4 = np.int64(self.
LUPT_TO_HASH[np.uint32(i) & 0x000000FF])
377 return val1 | val2 | val3 | val4
381 Transforms the given space-filling hash value into a single value
382 from which the 2d coordinates can be extracted using ij2i and ij2j.
387 Space-filling hash value
392 Single value from which 2d coordinates can be extracted.
395 np.int32((np.uint64(h)
396 & np.uint64(0xFF00000000000000)) >> np.uint64(56))] << np.int64(28)
398 np.int32((np.uint64(h)
399 & np.uint64(0x00FF000000000000)) >> np.uint64(48))] << np.int64(24)
401 np.int32((np.uint64(h)
402 & np.uint64(0x0000FF0000000000)) >> np.uint64(40))] << np.int64(20)
404 np.int32((np.uint64(h)
405 & np.uint64(0x000000FF00000000)) >> np.uint64(32))] << np.int64(16)
407 np.int32((np.uint64(h)
408 & np.uint64(0x00000000FF000000)) >> np.uint64(24))] << np.int64(12)
410 np.int32((np.uint64(h)
411 & np.uint64(0x0000000000FF0000)) >> np.uint64(16))] << np.int64(8)
413 np.int32((np.uint64(h)
414 & np.uint64(0x000000000000FF00)) >> np.uint64(8))] << np.int64(4)
416 np.int32((np.uint64(h)
417 & np.uint64(0x00000000000000FF)))]
418 return val1 | val2 | val3 | val4 | val5 | val6 | val7 | val8
422 Special case of hash2ij in which the discretized coordinate along
423 the vertical axis is zero.
428 Space-filling hash value.
433 Single value from which 2d coordinates can be extracted.
435 assert (0xFFFFFFFF33333333 & np.int64(_hash)) == 0
440 Extract the discretized horizontal coordinate from hash2ij.
445 The ij result of hash2ij.
450 Discretized horizontal coordinate stored in ij.
456 Extract the discretized vertical coordinate from hash2ij.
461 The ij result of hash2ij.
466 Discretized vertical coordinate stored in ij.
468 return np.int32(np.uint64(ij) >> np.uint64(32))