From 507dabb5282f233271f449de60cae3b0fc9606aa Mon Sep 17 00:00:00 2001 From: ponchio Date: Fri, 18 Feb 2005 13:05:19 +0000 Subject: [PATCH] created --- apps/nexus/zcurve.h | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 apps/nexus/zcurve.h diff --git a/apps/nexus/zcurve.h b/apps/nexus/zcurve.h new file mode 100644 index 00000000..8aa5a9ff --- /dev/null +++ b/apps/nexus/zcurve.h @@ -0,0 +1,46 @@ +#ifndef VCG_ZCURVE_H + +#include + +namespace vcg { + +class ZCurve: public Box3f { +public: + + unsigned int side; + + ZCurve(): side(1024) {} + + void SetSide(int s) { assert(s <= (1<<10)); side = s; } + + unsigned int Pos(const Point3f &p) const { + assert(!IsNull()); + unsigned int position = 0; + + float x = (p[0] - min[0])/(max[0] - min[0]); + float y = (p[1] - min[1])/(max[1] - min[1]); + float z = (p[2] - min[2])/(max[2] - min[2]); + + unsigned int s = side; + while(s > 1) { + position *= 8; + x *= 2; + y *= 2; + z *= 2; + int dx = (int)floor(x); + int dy = (int)floor(y); + int dz = (int)floor(z); + position += dx + 2 * dy + 4 * dz; + x -= dx; + y -= dy; + z -= dz; + s /= 2; + } + return position; + } +}; + +} + + +#endif