Viewport.h
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @class Viewport 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @author Matthew Jacobs (jacobs.mh@gmail.com) 00005 @date Fall 2008 00006 00007 @brief 00008 Represents a square domain over [0,1]^2, overlaid with a conceptual grid 00009 of uniformly-sized tiles (representing pixels) 00010 <!-------------------------------------------------------------------->**/ 00011 00012 #ifndef VIEWPORT_H_ 00013 #define VIEWPORT_H_ 00014 00015 #include <utils/PropertyMap.h> 00016 #include <common/math/Point.h> 00017 00018 struct Viewport { 00019 00020 ///@name Constructors 00021 //@{----------------------------------------------------------------- 00022 00023 inline Viewport(unsigned width, unsigned height) 00024 : m_width(width), m_height(height), 00025 m_invWidth(1.0 / width), m_invHeight(1.0 / height) 00026 { } 00027 00028 inline Viewport(unsigned noSamples) { 00029 const unsigned side = sqrt(noSamples); 00030 00031 m_width = side; 00032 m_height = side; 00033 00034 m_invWidth = 1.0 / side; 00035 m_invHeight = m_invWidth; 00036 } 00037 00038 inline Viewport() 00039 : m_width(1), m_height(1), m_invWidth(1), m_invHeight(1) 00040 { } 00041 00042 00043 //@}----------------------------------------------------------------- 00044 ///@name Accessors 00045 //@{----------------------------------------------------------------- 00046 00047 /// @returns the number of bins within one row of this domain 00048 inline unsigned getWidth() const { 00049 return m_width; 00050 } 00051 00052 /// @returns the number of bins within one column of this domain 00053 inline unsigned getHeight() const { 00054 return m_height; 00055 } 00056 00057 /// @returns the horizontal length of a single bin in this domain 00058 inline real_t getInvWidth() const { 00059 return m_invWidth; 00060 } 00061 00062 /// @returns the vertical length of a single bin in this domain 00063 inline real_t getInvHeight() const { 00064 return m_invHeight; 00065 } 00066 00067 /** 00068 * @returns the integer bin along this domain which contains the given @p pt 00069 * lying in the unit interval after being mapped to an image of the width 00070 * and height of this domain 00071 */ 00072 inline void getBin(const Point2 &pt, unsigned &outX, unsigned &outY) const { 00073 outX = CAP(floor(pt[0] * m_width ), 0, m_width - 1); 00074 outY = CAP(floor(pt[1] * m_height), 0, m_height - 1); 00075 } 00076 00077 00078 //@}----------------------------------------------------------------- 00079 ///@name Mutators 00080 //@{----------------------------------------------------------------- 00081 00082 /// Sets the number of rows and columns in this domain 00083 inline void setSize(unsigned width, unsigned height) { 00084 setWidth(width); 00085 setHeight(height); 00086 } 00087 00088 /// Sets the number of bins in one row of this domain 00089 inline void setWidth(unsigned width) { 00090 m_width = width; 00091 m_invWidth = 1.0 / width; 00092 } 00093 00094 /// Sets the number of bins in one column of this domain 00095 inline void setHeight(unsigned height) { 00096 m_height = height; 00097 m_invHeight = 1.0 / height; 00098 } 00099 00100 00101 //@}----------------------------------------------------------------- 00102 00103 private: 00104 unsigned m_width; 00105 unsigned m_height; 00106 00107 real_t m_invWidth; 00108 real_t m_invHeight; 00109 }; 00110 00111 #endif // VIEWPORT_H_ 00112
Generated on 28 Feb 2009 for Milton by
1.5.6