HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_PolarSample.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_PolarSample.h ( VEX Library, C++)
7  *
8  * COMMENTS: Equal area polar mapping of a unit grid to a sphere
9  * The sampler expects that the s,t coordinates passed in are in
10  * the range 0-1. Anything outside this range will result in
11  * speedy core dumps.
12  * The direction passed in represents the pole of the mapping.
13  * For example, to generate a hemispherical mapping around a
14  * vector, simply pass in t values between 0 and 0.5. This will
15  * generate a hemisphere around the direction vector passed in.
16  */
17 
18 #ifndef __UT_PolarSample__
19 #define __UT_PolarSample__
20 
21 #include "UT_API.h"
22 #include "UT_Vector3.h"
23 #include "UT_Interval.h"
24 
25 template <typename T>
27 {
28 public:
29  UT_PolarSampleT(const UT_Vector3T<T> &dir);
31  const UT_Vector3T<T> &framex, const UT_Vector3T<T> &framey);
34 
35  // The polar sampler should be initialized with a direction vector. This
36  // represents the axis around which the samples will be generated.
37  void setDirection(const UT_Vector3T<T> &dir);
38 
39  // Alternatively, if the direction is "fixed", you can simply call this
40  // method to set the frame of reference for the polar sampling.
41  // The z-axis corresponds to the axis/normal for the samplers.
42  void setDirection(const UT_Vector3T<T> &x, const UT_Vector3T<T> &y,
43  const UT_Vector3T<T> &z, bool normalize=true);
44 
45  //
46  // Given an s, t coordinate compute an "equal area" projection of the
47  // coordinate and pass the point on the sphere (or solid angle) back. For
48  // solid angle sampling, the getSolidAngle() method should be used to
49  // adjust the "t" coordinate.
50  void compute(UT_Vector3T<T> &d, T s, T t) const;
51 
52  //
53  // Given an s,t coordinate, compute an "equal area" projection of the
54  // coordinate onto a unit disk (with a normal given by the direction
55  // vector).
56  void computeDisk(UT_Vector3T<T> &d, T s, T t) const;
57 
58  //
59  // Given an s,t coordinate, compute an "equal area" projection onto the
60  // unit disk. Unlike the full version, this only computes the XY
61  // coordinates of the disk (without using the vectors specified).
62  // The resulting x/y coordinates will be in the range [-1,1]
63  static void computeDisk(T &x, T &y, T s, T t);
64 
65  //
66  // Compute the x/y interval for a given s/t interval. Uses the
67  // disk mapping (above).
68  static void computeDiskInterval(UT_Interval &x, UT_Interval &y,
69  const UT_Interval &s,
70  const UT_Interval &t);
71 
72  //
73  // This is a different implementation of computeDisk that uses a
74  // quartered square to map points to the circle rather than a polar
75  // mapping. Here, the t-value does not have any special meaning (for
76  // computeDisk, t will be the resulting sample point radius.), so this
77  // function can't always be used as a drop-in replacement for
78  // computeDisk. The samples are better distributed, however.
79  static void computeDisk2(T &x, T &y, T s, T t);
80 
81  //
82  // Given an s,t coordinate, compute an "equal area" projection onto the
83  // unit disk. This version creates a vector from the coordinates on
84  // the disk by finding the projections of this point onto the unit
85  // sphere.
86  void computeCosine(UT_Vector3T<T> &d, T s, T t) const;
87 
88  // You can map to the full sphere without specifying a direction to align
89  // with if you choose.
90  static void computeSphere(UT_Vector3T<T> &d, T s, T t);
91 
92  // The following method will return the appropriate "t" value for the
93  // polar sampler to generate samples over the solid angle specified.
94  // theta passed in should be the cone angle in radians (PI/2 for a
95  // hemisphere). If you are using the computeCosine() method, pass true
96  // for the cosine parameter.
97  static T getSolidAngle(T theta, bool cosine);
98 
99 
100  //
101  // Access methods to find out what the frame of reference is.
102  const UT_Vector3T<T> &getX() const { return myX; }
103  const UT_Vector3T<T> &getY() const { return myY; }
104  const UT_Vector3T<T> &getZ() const { return myZ; }
105 
106 private:
107  UT_Vector3T<T> myX, myY, myZ;
108 };
109 
114 
115 #endif
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
#define UT_API
Definition: UT_API.h:12
GLint y
Definition: glcorearb.h:102
3D Vector class.
GridType::Ptr normalize(const GridType &grid, bool threaded, InterruptT *interrupt)
Normalize the vectors of the given vector-valued grid.
const UT_Vector3T< T > & getX() const
GLint GLenum GLint x
Definition: glcorearb.h:408
const UT_Vector3T< T > & getY() const
const UT_Vector3T< T > & getZ() const