BLUE_NOISE.h

00001 
00002 // $Id: PDSampling.h,v 1.6 2006/07/06 23:13:18 zr Exp $
00003 
00004 #include "RNG.h"
00005 #include <cmath>
00006 #include <vector>
00007 
00008 #define kMaxPointsPerCell 9
00009 
00010 class RangeList;
00011 class ScallopedRegion;
00012 
00013 class Vec2 {
00014 public:
00015         Vec2() {};
00016         Vec2(float _x, float _y) : x(_x), y(_y) {};
00017 
00018         float x,y;
00019 
00020         float length() { return sqrt(x*x + y*y); }
00021 
00022         bool operator ==(const Vec2 &b) const { return x==b.x && y==b.y; }
00023         Vec2 operator +(Vec2 b) { return Vec2(x+b.x, y+b.y); }
00024         Vec2 operator -(Vec2 b) { return Vec2(x-b.x, y-b.y); }
00025         Vec2 operator *(Vec2 b) { return Vec2(x*b.x, y*b.y); }
00026         Vec2 operator /(Vec2 b) { return Vec2(x/b.x, y*b.y); }
00027 
00028         Vec2 operator +(float n) { return Vec2(x+n, y+n); }
00029         Vec2 operator -(float n) { return Vec2(x-n, y-n); }
00030         Vec2 operator *(float n) { return Vec2(x*n, y*n); }
00031         Vec2 operator /(float n) { return Vec2(x/n, y*n); }
00032 
00033         Vec2 &operator +=(Vec2 b) { x+=b.x; y+=b.y; return *this; }
00034         Vec2 &operator -=(Vec2 b) { x-=b.x; y-=b.y; return *this; }
00035         Vec2 &operator *=(Vec2 b) { x*=b.x; y*=b.y; return *this; }
00036         Vec2 &operator /=(Vec2 b) { x/=b.x; y/=b.y; return *this; }
00037 
00038         Vec2 &operator +=(float n) { x+=n; y+=n; return *this; }
00039         Vec2 &operator -=(float n) { x-=n; y-=n; return *this; }
00040         Vec2 &operator *=(float n) { x*=n; y*=n; return *this; }
00041         Vec2 &operator /=(float n) { x/=n; y/=n; return *this; }
00042 };
00043 
00048 class BLUE_NOISE {
00049 protected:
00050         RNG m_rng;
00051         std::vector<int> m_neighbors;
00052         
00053         int (*m_grid)[kMaxPointsPerCell];
00054         int m_gridSize;
00055         float m_gridCellSize;
00056         
00057 public:
00058         std::vector<Vec2> points;
00059         float radius;
00060         bool isTiled;
00061 
00062 public:
00063         BLUE_NOISE(float radius, bool isTiled=true, bool usesGrid=true);
00064         virtual ~BLUE_NOISE() { };
00065 
00066         //
00067 
00068         bool pointInDomain(Vec2 &a);
00069 
00070                 // return shortest distance between _a_ 
00071                 // and _b_ (accounting for tiling)
00072         float getDistanceSquared(Vec2 &a, Vec2 &b) { Vec2 v = getTiled(b-a); return v.x*v.x + v.y*v.y; }
00073         float getDistance(Vec2 &a, Vec2 &b) { return sqrt(getDistanceSquared(a, b)); }
00074 
00075                 // generate a random point in square
00076         Vec2 randomPoint();
00077 
00078                 // return tiled coordinates of _v_
00079         Vec2 getTiled(Vec2 v);
00080 
00081                 // return grid x,y for point
00082         void getGridXY(Vec2 &v, int *gx_out, int *gy_out);
00083 
00084                 // add _pt_ to point list and grid
00085         void addPoint(Vec2 pt);
00086 
00087                 // populate m_neighbors with list of
00088                 // all points within _radius_ of _pt_
00089                 // and return number of such points
00090         int findNeighbors(Vec2 &pt, float radius);
00091 
00092                 // return distance to closest neighbor within _radius_
00093         float findClosestNeighbor(Vec2 &pt, float radius);
00094 
00095                 // find available angle ranges on boundary for candidate 
00096                 // by subtracting occluded neighbor ranges from _rl_
00097         void findNeighborRanges(int index, RangeList &rl);
00098 
00099                 // extend point set by boundary sampling until domain is 
00100                 // full
00101         void maximize();
00102 
00103                 // apply one step of Lloyd relaxation
00104         void relax();
00105 
00106         void complete();
00107 
00108   void writeToBool(bool* noise, int size);
00109 };

Generated on Wed Oct 25 03:19:42 2006 for Lumos by  doxygen 1.4.6