library of assembled shared sources |
http://lass.cocamware.com |
00001 /** @file 00002 * @author Bram de Greve (bramz@users.sourceforge.net) 00003 * @author Tom De Muer (tomdemuer@users.sourceforge.net) 00004 * 00005 * *** BEGIN LICENSE INFORMATION *** 00006 * 00007 * The contents of this file are subject to the Common Public Attribution License 00008 * Version 1.0 (the "License"); you may not use this file except in compliance with 00009 * the License. You may obtain a copy of the License at 00010 * http://lass.sourceforge.net/cpal-license. The License is based on the 00011 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 00012 * use of software over a computer network and provide for limited attribution for 00013 * the Original Developer. In addition, Exhibit A has been modified to be consistent 00014 * with Exhibit B. 00015 * 00016 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 00017 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific 00018 * language governing rights and limitations under the License. 00019 * 00020 * The Original Code is LASS - Library of Assembled Shared Sources. 00021 * 00022 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer. 00023 * The Original Developer is the Initial Developer. 00024 * 00025 * All portions of the code written by the Initial Developer are: 00026 * Copyright (C) 2004-2007 the Initial Developer. 00027 * All Rights Reserved. 00028 * 00029 * Contributor(s): 00030 * 00031 * Alternatively, the contents of this file may be used under the terms of the 00032 * GNU General Public License Version 2 or later (the GPL), in which case the 00033 * provisions of GPL are applicable instead of those above. If you wish to allow use 00034 * of your version of this file only under the terms of the GPL and not to allow 00035 * others to use your version of this file under the CPAL, indicate your decision by 00036 * deleting the provisions above and replace them with the notice and other 00037 * provisions required by the GPL License. If you do not delete the provisions above, 00038 * a recipient may use your version of this file under either the CPAL or the GPL. 00039 * 00040 * *** END LICENSE INFORMATION *** 00041 */ 00042 00043 00044 /** @defgroup NormalizingPolicy NormalizingPolicy 00045 * @brief policies to specify if direction vectors (and normals) should be normalized. 00046 * @author Bram de Greve 00047 * @date 2003 00048 * 00049 * For direction vectors and normal vectors, you can be in the situation you want to 00050 * have them normalized (unit length) and that you want this to be done automatically. 00051 * Or you can be in the situation where you want them to be anything but normalized. 00052 * These policies will let you set this. 00053 * 00054 * The content of the policies are rather implementation details, clients shouldn't 00055 * worry about it. 00056 * 00057 * @note these policies can be used for vectors of any dimension. 00058 */ 00059 00060 /** @struct lass::prim::Normalized 00061 * @ingroup NormalizingPolicy 00062 * @brief Policy to auto-normalize normals. 00063 * @author Bram de Greve [BdG] 00064 * @date 2003 00065 * 00066 * Using this policy will automatically normalize all direction vectors and normals. 00067 * That way, you don't have to bother what you have as input, you know that they will 00068 * be normalized anyway. Also, for the implementation of the primitives, optimized 00069 * routines are provided that take advantage of the knowledge that the vectors are 00070 * normalized. But this are implementation details you should not worry about. 00071 */ 00072 00073 /** @struct lass::prim::Unnormalized 00074 * @ingroup NormalizingPolicy 00075 * @brief Policy to keep normals unnormalized. 00076 * @author Bram de Greve [BdG] 00077 * @date 2003 00078 * 00079 * Using this policy will keep direction vectors and normals at their original length. 00080 * You can do this for precision reasons, for speed issues, or any other reason that 00081 * is yours. However, the maths will still be correct, because the implementations 00082 * will know of this unnormalized vectors, and will correct with extra factors where 00083 * necessary. But, these corrections can sometimes be faster than using normalized 00084 * vectors for start, because they often can avoid the square root. 00085 */ 00086 00087 /** @struct lass::prim::IsAlreadyNormalized 00088 * @ingroup NormalizingPolicy 00089 * @date 2006 00090 * 00091 * Empty argument to tell a function the client assures the vector coming in is already 00092 * normalized, so the function doesn't has to. 00093 */ 00094 00095 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_NORMALIZING_POLICY_H 00096 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_NORMALIZING_POLICY_H 00097 00098 #include "prim_common.h" 00099 00100 00101 00102 namespace lass 00103 { 00104 00105 namespace prim 00106 { 00107 00108 struct Normalized 00109 { 00110 /** Normalize a vector iSubject 00111 */ 00112 template<typename VectorType> 00113 static void normalize(VectorType& ioSubject) 00114 { 00115 ioSubject.normalize(); 00116 } 00117 00118 /** Normalize iSubject, and scale iExtraValue as well so iExtraValue / iSubject.norm() is constant. 00119 * Typically used by cartesian equations. 00120 * @post iExtraValue / iSubject.norm() is the same as before the call. 00121 */ 00122 template<typename VectorType, typename ValueType> 00123 static void normalizeAndScale(VectorType& ioSubject, ValueType& ioExtraValue) 00124 { 00125 const typename VectorType::TValue norm = ioSubject.norm(); 00126 LASS_ASSERT(norm != VectorType::TNumTraits::zero); 00127 ioExtraValue /= norm; 00128 ioSubject /= norm; 00129 } 00130 00131 /** since iNormObject should be normalized by now, we can "divide by 1". 00132 * @return iValue 00133 * @pre iNormObject is supposed to be normalized! 00134 */ 00135 template<typename ValueType, typename VectorType> 00136 static ValueType divideByNorm(ValueType iValue, const VectorType& /*iNormObject*/) 00137 { 00138 return iValue; 00139 } 00140 00141 /** since iNormObject should be normalized by now, we can "divide by 1". 00142 * @return iValue 00143 * @pre iNormObject is supposed to be normalized! 00144 */ 00145 template<typename ValueType, typename VectorType> 00146 static ValueType divideBySquaredNorm(ValueType iValue, const VectorType& /*iNormObject*/) 00147 { 00148 return iValue; 00149 } 00150 }; 00151 00152 00153 00154 struct Unnormalized 00155 { 00156 /** Don't normalize normals we want to keep unnormalized! :) 00157 * this is a noop. 00158 */ 00159 template<typename VectorType> 00160 static void normalize(VectorType& /*ioSubject*/) 00161 { 00162 } 00163 00164 00165 /** Don't normalize and don't scale 00166 */ 00167 template<typename VectorType, typename ValueType> 00168 static void normalizeAndScale(VectorType& /*ioSubject*/, ValueType& /*ioExtraValue*/) 00169 { 00170 } 00171 00172 /** @return iValue divided by the norm of iNormObject 00173 */ 00174 template<typename ValueType, typename VectorType> 00175 static ValueType divideByNorm(ValueType iValue, const VectorType& iNormObject) 00176 { 00177 return iValue / iNormObject.norm(); 00178 } 00179 00180 /** @return iValue divided by the squared norm of iNormObject 00181 */ 00182 template<typename ValueType, typename VectorType> 00183 static ValueType divideBySquaredNorm(ValueType iValue, const VectorType& iNormObject) 00184 { 00185 return iValue / iNormObject.squaredNorm(); 00186 } 00187 }; 00188 00189 00190 00191 struct IsAlreadyNormalized 00192 { 00193 }; 00194 00195 00196 00197 00198 } 00199 00200 } 00201 00202 #endif
Generated on Mon Nov 10 14:20:31 2008 for Library of Assembled Shared Sources by 1.5.7.1 |