| 1 |
rschregle |
2.2 |
#ifndef lint
|
| 2 |
|
|
static const char RCSid[] = "$Id$";
|
| 3 |
|
|
#endif
|
| 4 |
|
|
|
| 5 |
|
|
|
| 6 |
rschregle |
2.1 |
/*
|
| 7 |
|
|
=========================================================================
|
| 8 |
|
|
Routines to generate and compare Morton Codes, i.e. indices on space
|
| 9 |
|
|
filling Z-curves.
|
| 10 |
|
|
|
| 11 |
|
|
Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
|
| 12 |
|
|
(c) Lucerne University of Applied Sciences and Arts,
|
| 13 |
|
|
supported by the Swiss National Science Foundation (SNSF, #147053)
|
| 14 |
|
|
=========================================================================
|
| 15 |
|
|
|
| 16 |
rschregle |
2.2 |
$Id: oocmorton.c,v 2.1 2016/05/17 17:39:47 rschregle Exp $
|
| 17 |
rschregle |
2.1 |
*/
|
| 18 |
|
|
|
| 19 |
|
|
|
| 20 |
rschregle |
2.2 |
#if !defined(_WIN32) && !defined(_WIN64) || defined(PMAP_OOC)
|
| 21 |
|
|
/* No Windoze support for now */
|
| 22 |
rschregle |
2.1 |
|
| 23 |
|
|
#include "oocmorton.h"
|
| 24 |
|
|
|
| 25 |
|
|
|
| 26 |
|
|
|
| 27 |
|
|
OOC_MortonIdx OOC_Key2Morton (const FVECT key, const FVECT org, RREAL scale)
|
| 28 |
|
|
/* Compute Morton code (Z-curve index) of length 3 * OOC_MORTON_BITS bits
|
| 29 |
|
|
* for 3D key within bounding box defined by org and scaled to maximum index
|
| 30 |
|
|
* with scale */
|
| 31 |
|
|
{
|
| 32 |
|
|
unsigned i;
|
| 33 |
|
|
OOC_MortonIdx k [3];
|
| 34 |
|
|
|
| 35 |
|
|
/* Normalise key and map each dim to int of OOC_MORTON_BITS */
|
| 36 |
|
|
for (i = 0; i < 3; i++)
|
| 37 |
|
|
k [i] = scale * (key [i] - org [i]);
|
| 38 |
|
|
|
| 39 |
|
|
/* Interleave each dim with zeros and merge */
|
| 40 |
|
|
return OOC_BitInterleave(k [0]) | OOC_BitInterleave(k [1]) << 1 |
|
| 41 |
|
|
OOC_BitInterleave(k [2]) << 2;
|
| 42 |
|
|
}
|
| 43 |
rschregle |
2.2 |
|
| 44 |
|
|
#endif /* NIX / PMAP_OOC */
|