Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

photon.inl

Go to the documentation of this file.
00001 /*
00002     toxic - A Global Illumination Renderer
00003     Copyright (C) 2003-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of toxic.
00007 
00008     toxic is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     toxic is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with toxic; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 inline
00024 Photon::Photon() :
00025     m_flags(0)
00026 {
00027 }
00028 
00029 inline
00030 void Photon::SetPosition(const sheep::Point3 &position) {
00031     m_position[0] = static_cast<sheep::float32>(position.m_x);
00032     m_position[1] = static_cast<sheep::float32>(position.m_y);
00033     m_position[2] = static_cast<sheep::float32>(position.m_z);
00034 }
00035 
00036 inline
00037 sheep::Point3 Photon::GetPosition() const {
00038     return sheep::Point3(m_position[0], m_position[1], m_position[2]);
00039 }
00040 
00041 inline
00042 void Photon::SetPower(const Color3 &power) {
00043 #ifdef COMPRESS_PHOTON_POWER
00044     power.ConvertToRGBE(&m_power[0], &m_power[1], &m_power[2], &m_power[3]);
00045 #else
00046     m_power[0] = static_cast<sheep::float32>(power.m_r);
00047     m_power[1] = static_cast<sheep::float32>(power.m_g);
00048     m_power[2] = static_cast<sheep::float32>(power.m_b);
00049 #endif  // COMPRESS_PHOTON_POWER
00050 }
00051 
00052 inline
00053 void Photon::ScalePower(sheep::Real scale) {
00054 #ifdef COMPRESS_PHOTON_POWER
00055     Color3 c = Color3::ConvertFromRGBE(m_power[0], m_power[1], m_power[2], m_power[3]);
00056 
00057     c *= scale;
00058 
00059     c.ConvertToRGBE(
00060         &m_power[0],
00061         &m_power[1],
00062         &m_power[2],
00063         &m_power[3]);
00064 #else
00065     m_power[0] *= static_cast<sheep::float32>(scale);
00066     m_power[1] *= static_cast<sheep::float32>(scale);
00067     m_power[2] *= static_cast<sheep::float32>(scale);
00068 #endif  // COMPRESS_PHOTON_POWER
00069 }
00070 
00071 inline
00072 Color3 Photon::GetPower() const {
00073 #ifdef COMPRESS_PHOTON_POWER
00074     return Color3::ConvertFromRGBE(m_power[0], m_power[1], m_power[2], m_power[3]);
00075 #else
00076     return Color3(m_power[0], m_power[1], m_power[2]);
00077 #endif  // COMPRESS_PHOTON_POWER
00078 }
00079 
00080 inline
00081 void Photon::SetIncidentDirection(const sheep::Vector3 &direction) {
00082     PackDirection(direction, &m_qphi, &m_qtheta);
00083 }
00084 
00085 inline
00086 sheep::Vector3 Photon::GetIncidentDirection() const {
00087     return UnpackDirection(m_qphi, m_qtheta);
00088 }
00089 
00090 inline
00091 void Photon::SetSplittingPlaneAxis(int axis) {
00092     assert(axis >= 0 && axis < 4);
00093     m_flags &= ~ sheep::uint16(3);  // reset bits 1 and 0
00094     m_flags |= axis;    // copy bits 1-0 of axis to bits 1-0 of m_flags
00095 }
00096 
00097 inline
00098 int Photon::GetSplittingPlaneAxis() const {
00099     // Return bits 1 and 0.
00100     return m_flags & 3;
00101 }
00102 
00103 #ifdef ENABLE_RADIANCES_PRECOMPUTATION
00104 
00105 inline
00106 bool Photon::HasPrecomputedRadiance() const {
00107     // Return bit 2.
00108     return (m_flags & 4) != 0;
00109 }
00110 
00111 inline
00112 void Photon::SetPrecomputedRadiance(const Color3 &radiance) {
00113 #ifdef COMPRESS_PRECOMPUTED_RADIANCES
00114     radiance.ConvertToRGBE(&m_radiance[0], &m_radiance[1], &m_radiance[2], &m_radiance[3]);
00115 #else
00116     m_radiance[0] = static_cast<sheep::float32>(radiance.m_r);
00117     m_radiance[1] = static_cast<sheep::float32>(radiance.m_g);
00118     m_radiance[2] = static_cast<sheep::float32>(radiance.m_b);
00119 #endif  // COMPRESS_PRECOMPUTED_RADIANCES
00120 
00121     m_flags |= 4;   // set bit 2
00122 }
00123 
00124 inline
00125 Color3 Photon::GetPrecomputedRadiance() const {
00126     assert(HasPrecomputedRadiance());
00127 
00128 #ifdef COMPRESS_PRECOMPUTED_RADIANCES
00129     return Color3::ConvertFromRGBE(m_radiance[0], m_radiance[1], m_radiance[2], m_radiance[3]);
00130 #else
00131     return Color3(m_radiance[0], m_radiance[1], m_radiance[2]);
00132 #endif  // COMPRESS_PRECOMPUTED_RADIANCES
00133 }
00134 
00135 inline
00136 void Photon::SetSurfaceNormal(const sheep::Vector3 &normal) {
00137     PackDirection(normal, &m_qnormal);
00138 }
00139 
00140 inline
00141 sheep::Vector3 Photon::GetSurfaceNormal() const {
00142     return UnpackDirection(m_qnormal);
00143 }
00144 
00145 #endif  // ENABLE_RADIANCES_PRECOMPUTATION
00146 
00147 inline
00148 void Photon::WriteToStream(sheep::BinaryStream &os) const {
00149     // Position (12 bytes).
00150     os.Write(m_position[0]);
00151     os.Write(m_position[1]);
00152     os.Write(m_position[2]);
00153 
00154 #ifdef COMPRESS_PHOTON_POWER
00155     // Compressed power (4 bytes).
00156     os.Write(m_power[0]);
00157     os.Write(m_power[1]);
00158     os.Write(m_power[2]);
00159     os.Write(m_power[3]);
00160 #else
00161     // Full precision power (12 bytes).
00162     os.Write(m_power[0]);
00163     os.Write(m_power[1]);
00164     os.Write(m_power[2]);
00165 #endif  // COMPRESS_PHOTON_POWER
00166 
00167     // Compressed incident direction (2 bytes).
00168     os.Write(m_qphi);
00169     os.Write(m_qtheta);
00170 
00171 #ifdef ENABLE_RADIANCES_PRECOMPUTATION
00172 #ifdef COMPRESS_PRECOMPUTED_RADIANCES
00173     // Compressed precomputed radiance (4 bytes).
00174     os.Write(m_radiance[0]);
00175     os.Write(m_radiance[1]);
00176     os.Write(m_radiance[2]);
00177     os.Write(m_radiance[3]);
00178 #else
00179     // Full precision precomputed radiance (12 bytes).
00180     os.Write(m_radiance[0]);
00181     os.Write(m_radiance[1]);
00182     os.Write(m_radiance[2]);
00183 #endif  // COMPRESS_PRECOMPUTED_RADIANCES
00184     // Normal of the surface at the photon position (1 byte).
00185     os.Write(m_qnormal);
00186 #endif  // ENABLE_RADIANCES_PRECOMPUTATION
00187 
00188     // Various flags and data (2 bytes).
00189     os.Write(m_flags);
00190 
00191     // Ignore padding bytes.
00192 }
00193 
00194 inline
00195 void Photon::ReadFromStream(sheep::BinaryStream &is) {
00196     // Position (12 bytes).
00197     is.Read(&m_position[0]);
00198     is.Read(&m_position[1]);
00199     is.Read(&m_position[2]);
00200 
00201 #ifdef COMPRESS_PHOTON_POWER
00202     // Compressed power (4 bytes).
00203     is.Read(&m_power[0]);
00204     is.Read(&m_power[1]);
00205     is.Read(&m_power[2]);
00206     is.Read(&m_power[3]);
00207 #else
00208     // Full precision power (12 bytes).
00209     is.Read(&m_power[0]);
00210     is.Read(&m_power[1]);
00211     is.Read(&m_power[2]);
00212 #endif  // COMPRESS_PHOTON_POWER
00213 
00214     // Compressed incident direction (2 bytes).
00215     is.Read(&m_qphi);
00216     is.Read(&m_qtheta);
00217 
00218 #ifdef ENABLE_RADIANCES_PRECOMPUTATION
00219 #ifdef COMPRESS_PRECOMPUTED_RADIANCES
00220     // Compressed precomputed radiance (4 bytes).
00221     is.Read(&m_radiance[0]);
00222     is.Read(&m_radiance[1]);
00223     is.Read(&m_radiance[2]);
00224     is.Read(&m_radiance[3]);
00225 #else
00226     // Full precision precomputed radiance (12 bytes).
00227     is.Read(&m_radiance[0]);
00228     is.Read(&m_radiance[1]);
00229     is.Read(&m_radiance[2]);
00230 #endif  // COMPRESS_PRECOMPUTED_RADIANCES
00231     // Normal of the surface at the photon position (1 byte).
00232     is.Read(&m_qnormal);
00233 #endif  // ENABLE_RADIANCES_PRECOMPUTATION
00234 
00235     // Various flags and data (2 bytes).
00236     is.Read(&m_flags);
00237 
00238     // Leave padding bytes undefined.
00239 }

Generated on Tue May 11 01:31:51 2004 for toxic by doxygen 1.3.6