HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_HilbertSequence.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_HilbertSequence.h (UT Library, C++)
7  *
8  * COMMENTS: A class that generates a 2D Hilbert Curve within a given
9  * rectangle.
10  */
11 
12 #ifndef __UT_HILBERTSEQUENCE_H_INCLUDED__
13 #define __UT_HILBERTSEQUENCE_H_INCLUDED__
14 
15 #include "UT_API.h"
16 
18 {
19 public:
20  UT_HilbertCurve2D(int level = 0);
21 
22  // Get the coordinates of a point on the Hilbert curve at the given
23  // distance along the curve. Returns false if the distance exceeds the
24  // curve length, as defined by its level.
25  bool getPointFromDistance(int d, int &xp, int &yp) const;
26 
27  /// Retrieve the distance along the curve given coordinates of a point on
28  /// the curve. If the coordinates are outside of the curve's bounding
29  /// square, as defined by its level, the distance returned is -1.
30  int getDistanceFromPoint(int xp, int yp) const;
31 
32  /// Advance the from the point at the given coordinates, to the next point
33  /// along the curve and return those new coordinates. If the point is
34  /// already at the end of the curve, this call returns false and the
35  /// coordinates are left untouched.
36  bool advancePointAlongCurve(int &xp, int &yp) const;
37 
38  int getLevel() const { return myLevel; }
39  int getSize() const { return mySize; }
40  int getLength() const { return mySize * mySize; }
41 
42 private:
43  int myLevel;
44  int mySize;
45 };
46 
48 {
49 public:
50  /// Initializes sequence data with the given parameters
51  /// @param res_x @n Sequence resolution in x
52  /// @param res_y @n Sequence resolution in y
53  UT_HilbertSequence2D(int res_x = 0, int res_y = 0);
54 
56  {
57  public:
58  iterator();
59  iterator(const UT_HilbertSequence2D &sequence);
60 
61  int getDistance() const { return myDistance; }
62  int getIndex() const { return myIndex; }
63  void getCoord(int &x, int &y) const;
64 
65  void rewind();
66  void advance();
67  bool atEnd() const;
68 
69  iterator &operator++() { advance(); return *this; }
70  // No post increment as it is harmful
71  protected:
72  private:
73  int myResX, myResY;
74  int myDistance;
75  int myIndex;
76  int myCoordX, myCoordY;
77  UT_HilbertCurve2D myCurve;
78  };
79 
80  iterator begin() const { return iterator(*this); }
81 
82  int getXRes() const { return myResX; }
83  int getYRes() const { return myResY; }
84 
85 private:
86  int myResX;
87  int myResY;
88 };
89 
90 #endif // __UT_HILBERTSEQUENCE_H_INCLUDED__
png_infop png_uint_32 * res_x
Definition: png.h:2429
png_infop png_uint_32 png_uint_32 * res_y
Definition: png.h:2429
iterator begin() const
GLint level
Definition: glcorearb.h:107
#define UT_API
Definition: UT_API.h:12
GLint y
Definition: glcorearb.h:102
GLint GLenum GLint x
Definition: glcorearb.h:408
int getLength() const