HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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);
33 
34  // The polar sampler should be initialized with a direction vector. This
35  // represents the axis around which the samples will be generated.
36  void setDirection(const UT_Vector3T<T> &dir);
37 
38  // Alternatively, if the direction is "fixed", you can simply call this
39  // method to set the frame of reference for the polar sampling.
40  // The z-axis corresponds to the axis/normal for the samplers.
41  void setDirection(const UT_Vector3T<T> &x, const UT_Vector3T<T> &y,
42  const UT_Vector3T<T> &z, bool normalize=true);
43 
44  //
45  // Given an s, t coordinate compute an "equal area" projection of the
46  // coordinate and pass the point on the sphere (or solid angle) back. For
47  // solid angle sampling, the getSolidAngle() method should be used to
48  // adjust the "t" coordinate.
49  void compute(UT_Vector3T<T> &d, T s, T t) const;
50 
51  //
52  // Given an s,t coordinate, compute an "equal area" projection of the
53  // coordinate onto a unit disk (with a normal given by the direction
54  // vector).
55  void computeDisk(UT_Vector3T<T> &d, T s, T t) const;
56 
57  //
58  // Given an s,t coordinate, compute an "equal area" projection onto the
59  // unit disk. Unlike the full version, this only computes the XY
60  // coordinates of the disk (without using the vectors specified).
61  // The resulting x/y coordinates will be in the range [-1,1]
62  static void computeDisk(T &x, T &y, T s, T t);
63 
64  //
65  // Compute the x/y interval for a given s/t interval. Uses the
66  // disk mapping (above).
67  static void computeDiskInterval(UT_Interval &x, UT_Interval &y,
68  const UT_Interval &s,
69  const UT_Interval &t);
70 
71  //
72  // This is a different implementation of computeDisk that uses a
73  // quartered square to map points to the circle rather than a polar
74  // mapping. Here, the t-value does not have any special meaning (for
75  // computeDisk, t will be the resulting sample point radius.), so this
76  // function can't always be used as a drop-in replacement for
77  // computeDisk. The samples are better distributed, however.
78  static void computeDisk2(T &x, T &y, T s, T t);
79 
80  //
81  // Given an s,t coordinate, compute an "equal area" projection onto the
82  // unit disk. This version creates a vector from the coordinates on
83  // the disk by finding the projections of this point onto the unit
84  // sphere.
85  void computeCosine(UT_Vector3T<T> &d, T s, T t) const;
86 
87  // You can map to the full sphere without specifying a direction to align
88  // with if you choose.
89  static void computeSphere(UT_Vector3T<T> &d, T s, T t);
90 
91  // The following method will return the appropriate "t" value for the
92  // polar sampler to generate samples over the solid angle specified.
93  // theta passed in should be the cone angle in radians (PI/2 for a
94  // hemisphere). If you are using the computeCosine() method, pass true
95  // for the cosine parameter.
96  static T getSolidAngle(T theta, bool cosine);
97 
98 
99  //
100  // Access methods to find out what the frame of reference is.
101  const UT_Vector3T<T> &getX() const { return myX; }
102  const UT_Vector3T<T> &getY() const { return myY; }
103  const UT_Vector3T<T> &getZ() const { return myZ; }
104 
105 private:
106  UT_Vector3T<T> myX, myY, myZ;
107 };
108 
113 
114 #endif
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
GLdouble s
Definition: glad.h:3009
#define UT_API
Definition: UT_API.h:14
GLint y
Definition: glcorearb.h:103
3D Vector class.
GLint GLenum GLint x
Definition: glcorearb.h:409
GLdouble t
Definition: glad.h:2397
const UT_Vector3T< T > & getX() const
const UT_Vector3T< T > & getY() const
const UT_Vector3T< T > & getZ() const
constexpr T normalize(UT_FixedVector< T, D > &a) noexcept