Page MenuHomec4science

morton.c
No OneTemporary

File Metadata

Created
Fri, Nov 8, 10:44

morton.c

#ifndef lint
static const char RCSid[] = "$Id$";
#endif
/*
=========================================================================
Routines to generate and compare Morton Codes, i.e. indices on space
filling Z-curves.
Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
(c) Lucerne University of Applied Sciences and Arts,
supported by the Swiss National Science Foundation
(SNSF #147053, "Daylight Redirecting Components",
SNSF #179067, "Light Fields for Spatio-Temporal Glare Assessment")
=========================================================================
$Id$
*/
#if !defined(_WIN32) && !defined(_WIN64) || defined(PMAP_OOC)
/* No Windoze support for now */
#include "morton.h"
MortonIdx Key2Morton3D (const FVECT key, const FVECT org, RREAL scale)
/* Compute Morton code (Z-curve index) of length 3 * MORTON3D_BITS bits
for 3D key within bounding box defined by org and scaled to maximum
index with scale */
{
unsigned i;
MortonIdx k [3];
/* Normalise key and map each dim to int of MORTON3D_BITS */
for (i = 0; i < 3; i++)
k [i] = scale * (key [i] - org [i]);
/* Interleave each dim with zeros and merge */
return (Morton3DBitInterleave(k [0]) |
Morton3DBitInterleave(k [1]) << 1 |
Morton3DBitInterleave(k [2]) << 2
);
}
MortonIdx Key2Morton2D (const RREAL key [2], const RREAL org [2], RREAL scale)
/* Compute Morton code (Z-curve index) of length 2 * MORTON2D_BITS bits
for 2D key within bounding box defined by org and scaled to maximum
index with scale */
{
unsigned i;
MortonIdx k [2];
/* Normalise key and map each dim to int of MORTON2D_BITS */
for (i = 0; i < 2; i++)
k [i] = scale * (key [i] - org [i]);
/* Interleave each dim with zeros and merge */
return (Morton2DBitInterleave(k [0]) | Morton2DBitInterleave(k [1]) << 1);
}
#endif /* NIX / PMAP_OOC */

Event Timeline