00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc 00008 * 477 Richmond Street West 00009 * Toronto, Ontario 00010 * Canada M5V 3E7 00011 * 416-504-9876 00012 * 00013 * NAME: UT_PolarSample.h ( VEX Library, C++) 00014 * 00015 * COMMENTS: Equal area polar mapping of a unit grid to a sphere 00016 * The sampler expects that the s,t coordinates passed in are in 00017 * the range 0-1. Anything outside this range will result in 00018 * speedy core dumps. 00019 * The direction passed in represents the pole of the mapping. 00020 * For example, to generate a hemispherical mapping around a 00021 * vector, simply pass in t values between 0 and 0.5. This will 00022 * generate a hemisphere around the direction vector passed in. 00023 */ 00024 00025 #ifndef __UT_PolarSample__ 00026 #define __UT_PolarSample__ 00027 00028 #include "UT_API.h" 00029 #include "UT_Vector3.h" 00030 00031 class UT_Interval; 00032 00033 class UT_API UT_PolarSample { 00034 public: 00035 UT_PolarSample(const UT_Vector3 &dir); 00036 UT_PolarSample(const UT_Vector3 &dir, 00037 const UT_Vector3 &framex, const UT_Vector3 &framey); 00038 UT_PolarSample(); 00039 ~UT_PolarSample() { } 00040 00041 // The polar sampler should be initialized with a direction vector. This 00042 // represents the axis around which the samples will be generated. 00043 void setDirection(const UT_Vector3 &dir); 00044 00045 // Alternatively, if the direction is "fixed", you can simply call this 00046 // method to set the frame of reference for the polar sampling. 00047 // The z-axis corresponds to the axis/normal for the samplers. 00048 void setDirection(const UT_Vector3 &x, const UT_Vector3 &y, 00049 const UT_Vector3 &z, int normalize=1); 00050 00051 // 00052 // Given an s, t coordinate compute an "equal area" projection of the 00053 // coordinate and pass the point on the sphere (or solid angle) back. For 00054 // solid angle sampling, the getSolidAngle() method should be used to 00055 // adjust the "t" coordinate. 00056 void compute(UT_Vector3 &d, fpreal s, fpreal t) const; 00057 00058 // 00059 // Given an s,t coordinate, compute an "equal area" projection of the 00060 // coordinate onto a unit disk (with a normal given by the direction 00061 // vector). 00062 void computeDisk(UT_Vector3 &d, fpreal s, fpreal t) const; 00063 00064 // 00065 // Given an s,t coordinate, compute an "equal area" projection onto the 00066 // unit disk. Unlike the full version, this only computes the XY 00067 // coordinates of the disk (without using the vectors specified). 00068 // The resulting x/y coordinates will be in the range [-1,1] 00069 static void computeDisk(fpreal &x, fpreal &y, fpreal s, fpreal t); 00070 00071 // 00072 // Compute the x/y interval for a given s/t interval. Uses the 00073 // disk mapping (above). 00074 static void computeDiskInterval(UT_Interval &x, UT_Interval &y, 00075 const UT_Interval &s, 00076 const UT_Interval &t); 00077 00078 // 00079 // This is a different implementation of computeDisk that uses a 00080 // quartered square to map points to the circle rather than a polar 00081 // mapping. Here, the t-value does not have any special meaning (for 00082 // computeDisk, t will be the resulting sample point radius.), so this 00083 // function can't always be used as a drop-in replacement for 00084 // computeDisk. The samples are better distributed, however. 00085 static void computeDisk2(fpreal &x, fpreal &y, fpreal s, fpreal t); 00086 00087 // 00088 // Given an s,t coordinate, compute an "equal area" projection onto the 00089 // unit disk. This version creates a vector from the coordinates on 00090 // the disk by finding the projections of this point onto the unit 00091 // sphere. 00092 void computeCosine(UT_Vector3 &d, fpreal s, fpreal t) const; 00093 00094 // You can map to the full sphere without specifying a direction to align 00095 // with if you choose. 00096 static void computeSphere(UT_Vector3 &d, fpreal s, fpreal t); 00097 00098 // The following method will return the appropriate "t" value for the 00099 // polar sampler to generate samples over the solid angle specified. 00100 // theta passed in should be the cone angle in radians (PI/2 for a 00101 // hemisphere). If you are using the computeCosine() method, pass true 00102 // for the cosine parameter. 00103 static fpreal getSolidAngle(fpreal theta, bool cosine); 00104 00105 00106 // 00107 // Access methods to find out what the frame of reference is. 00108 const UT_Vector3 &getX() const { return myX; } 00109 const UT_Vector3 &getY() const { return myY; } 00110 const UT_Vector3 &getZ() const { return myZ; } 00111 00112 private: 00113 UT_Vector3 myX, myY, myZ; 00114 }; 00115 00116 #endif
1.5.9