00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "hilbertpx.h"
00024 #include "error.h"
00025
00026 using namespace lux;
00027
00028 void HilbertPixelSampler::HilberCurve(
00029 int n,
00030 int xo, int yo,
00031 int xd, int yd, int xp, int yp,
00032 int xEnd, int yEnd) {
00033 if (n <= 1) {
00034 if((xo <= xEnd) && (yo <= yEnd)) {
00035 PxLoc px;
00036 px.x = xo; px.y = yo;
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 Pxa.push_back(px);
00051 TotalPx++;
00052 }
00053 } else {
00054 int n2 = n >> 1;
00055
00056 HilberCurve(n2,
00057 xo,
00058 yo,
00059 xp, yp, xd, yd, xEnd, yEnd);
00060 HilberCurve(n2,
00061 xo + xp * n2,
00062 yo + yp * n2,
00063 xd, yd, xp, yp, xEnd, yEnd);
00064 HilberCurve(n2,
00065 xo + xp * n2 + xd * n2,
00066 yo + yp * n2 + yd * n2,
00067 xd, yd, xp, yp, xEnd, yEnd);
00068 HilberCurve(n2,
00069 xo + xp * (n2 - 1) + xd * (n - 1),
00070 yo + yp * (n2 - 1) + yd * (n - 1),
00071 -xp, -yp, -xd, -yd, xEnd, yEnd);
00072 }
00073 }
00074
00075
00076 HilbertPixelSampler::HilbertPixelSampler(
00077 int xStart, int xEnd,
00078 int yStart, int yEnd) {
00079 int xSize = xEnd - xStart + 1;
00080 int ySize = yEnd - yStart + 1;
00081
00082 TotalPx = 0;
00083
00084 int n = max<int>(xSize, ySize);
00085 if (!IsPowerOf2(n))
00086 n = RoundUpPow2(n);
00087 HilberCurve(n, xStart, yStart, 0, 1, 1, 0, xEnd, yEnd);
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 }
00106
00107 u_int HilbertPixelSampler::GetTotalPixels() {
00108 return TotalPx;
00109 }
00110
00111 bool HilbertPixelSampler::GetNextPixel(int &xPos, int &yPos, u_int *use_pos) {
00112 u_int pos = (*use_pos);
00113 bool hasMorePixel = true;
00114 if(pos == TotalPx - 1)
00115 hasMorePixel = false;
00116
00117 xPos = Pxa[pos].x;
00118 yPos = Pxa[pos].y;
00119
00120 return hasMorePixel;
00121 }