library of assembled shared sources

http://lass.cocamware.com

parallelogram_3d.inl

Go to the documentation of this file.
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 
00045 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_SIMPLE_PARALLELOGRAM_3D_INL
00046 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_SIMPLE_PARALLELOGRAM_3D_INL
00047 
00048 #include "prim_common.h"
00049 #include "parallelogram_3d.h"
00050 #include "impl/plane_3d_impl_detail.h"
00051 
00052 namespace lass
00053 {
00054 namespace prim
00055 {
00056 
00057 /** constructs an empty parallelogram.
00058  *  support is origin and sizes are zero.
00059  */
00060 template <typename T>
00061 Parallelogram3D<T>::Parallelogram3D()
00062 {
00063 }
00064 
00065 
00066 
00067 /** Constructs a parallelogram with a support and two sizes
00068  */
00069 template <typename T>
00070 Parallelogram3D<T>::Parallelogram3D(const TPoint& iSupport, const TVector& iSizeU, 
00071                                     const TVector& iSizeV):
00072     support_(iSupport),
00073     sizeU_(iSizeU),
00074     sizeV_(iSizeV)
00075 {
00076 }
00077 
00078 
00079 
00080 template <typename T> inline
00081 const typename Parallelogram3D<T>::TPoint&
00082 Parallelogram3D<T>::support() const
00083 {
00084     return support_;
00085 }
00086 
00087 
00088 
00089 template <typename T> inline
00090 typename Parallelogram3D<T>::TPoint&
00091 Parallelogram3D<T>::support()
00092 {
00093     return support_;
00094 }
00095 
00096 
00097 
00098 template <typename T> inline
00099 const typename Parallelogram3D<T>::TVector&
00100 Parallelogram3D<T>::sizeU() const
00101 {
00102     return sizeU_;
00103 }
00104 
00105 
00106 
00107 template <typename T> inline
00108 typename Parallelogram3D<T>::TVector&
00109 Parallelogram3D<T>::sizeU()
00110 {
00111     return sizeU_;
00112 }
00113 
00114 
00115 
00116 template <typename T> inline
00117 const typename Parallelogram3D<T>::TVector&
00118 Parallelogram3D<T>::sizeV() const
00119 {
00120     return sizeV_;
00121 }
00122 
00123 
00124 
00125 template <typename T> inline
00126 typename Parallelogram3D<T>::TVector&
00127 Parallelogram3D<T>::sizeV()
00128 {
00129     return sizeV_;
00130 }
00131 
00132 
00133 
00134 template <typename T>
00135 const typename Parallelogram3D<T>::TPlane
00136 Parallelogram3D<T>::plane() const
00137 {
00138     return TPlane(cross(sizeU_, sizeV_), support_);
00139 }
00140 
00141 
00142 
00143 /** returns squared area of parallelogram to avoid the square root.
00144  *  @return num::sqr(area()) but faster :)
00145  */
00146 template <typename T>
00147 const typename Parallelogram3D<T>::TValue
00148 Parallelogram3D<T>::squaredArea() const
00149 {
00150     return cross(sizeU_, sizeV_).squaredNorm();
00151 }
00152 
00153 
00154 
00155 /** @copydoc SimplePolygon3D::area
00156  */
00157 template <typename T>
00158 const typename Parallelogram3D<T>::TValue
00159 Parallelogram3D<T>::area() const
00160 {
00161     return num::sqrt(squaredArea());
00162 }
00163 
00164 
00165 
00166 /** @copydoc SimplePolygon3D::perimeter
00167  */
00168 template <typename T>
00169 const typename Parallelogram3D<T>::TValue
00170 Parallelogram3D<T>::perimeter() const
00171 {
00172     return 2 * (sizeU_.norm() + sizeV_.norm());
00173 }
00174 
00175 
00176 
00177 template <typename T>
00178 const typename Parallelogram3D<T>::TPoint 
00179 Parallelogram3D<T>::point(TParam iU, TParam iV) const
00180 {
00181     return support_ + iU * sizeU_ + iV * sizeV_;
00182 }
00183 
00184 
00185 
00186 template <typename T> inline
00187 const typename Parallelogram3D<T>::TPoint
00188 Parallelogram3D<T>::point(const TUV& iUv) const
00189 {
00190     return point(iUv.x, iUv.y);
00191 }
00192 
00193 
00194 
00195 template <typename T>
00196 const typename Parallelogram3D<T>::TUV
00197 Parallelogram3D<T>::uv(const TPoint& iPoint) const
00198 {
00199     TVector reciprocalU;
00200     TVector reciprocalV;
00201     impl::Plane3DImplDetail::generateReciprocal(sizeU_, sizeV_, reciprocalU, reciprocalV);
00202     const TVector relative = iPoint - support_;
00203     return TUV(dot(relative, reciprocalU), dot(relative, reciprocalV));
00204 }
00205 
00206 
00207 
00208 /** @copydoc SimplePolygon3D::isSimple
00209  *  @par Parallelogram specific:
00210  *      A parallelogram is always simple
00211  */
00212 template <typename T>
00213 const bool Parallelogram3D<T>::isSimple() const
00214 {
00215     return true;
00216 }
00217 
00218 
00219 
00220 /** @copydoc SimplePolygon3D::isConvex
00221  *  @par Parallelogram specific:
00222  *      A parallelogram is always convex
00223  */
00224 template <typename T>
00225 const bool Parallelogram3D<T>::isConvex() const
00226 {
00227     return true;
00228 }
00229 
00230 
00231 
00232 /** @copydoc SimplePolygon3D::isReflex
00233  *  @par Parallelogram specific:
00234  *      A parallelogram never has reflex vertices
00235  */
00236 template <typename T>
00237 const bool Parallelogram3D<T>::isReflex(int iIndexOfVertex) const
00238 {
00239     return false;
00240 }
00241 
00242 
00243 
00244 // --- private -------------------------------------------------------------------------------------
00245 
00246 
00247 
00248 // --- free ----------------------------------------------------------------------------------------
00249 
00250 /** @relates lass::prim::Parallelogram3D
00251  */
00252 template <typename T>
00253 io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Parallelogram3D<T>& iParallelogram)
00254 {
00255     LASS_ENFORCE_STREAM(ioOStream) << "<Parallelogram3D>\n";
00256     ioOStream << "<support>" << iParallelogram.support() << "</support>\n";
00257     ioOStream << "<sizeU>" << iParallelogram.sizeU() << "</sizeU>\n";
00258     ioOStream << "<sizeV>" << iParallelogram.sizeV() << "</sizeV>\n";
00259     ioOStream << "</Parallelogram3D>\n";
00260     return ioOStream;
00261 }
00262 
00263 
00264 
00265 /** @relates lass::prim::Parallelogram3D
00266  */
00267 template <typename T>
00268 std::ostream& operator<<(std::ostream& ioOStream, const Parallelogram3D<T>& iParallelogram)
00269 {
00270     LASS_ENFORCE_STREAM(ioOStream) 
00271         << "{S=" << iParallelogram.support() << ", U=" << iParallelogram.sizeU() 
00272         << ", V=" << iParallelogram.sizeV() << "}";
00273     return ioOStream;
00274 }
00275 
00276 
00277 
00278 }
00279 
00280 }
00281 
00282 #endif
00283 
00284 // EOF

Generated on Mon Nov 10 14:20:35 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo