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

vlnormal.h

Go to the documentation of this file.
00001 // $Id: vlnormal.h,v 1.4 2002/12/24 19:02:05 sarang Exp $
00002 //
00003 // OpenVL - A Library for working with volumetric datasets.
00004 //          http://openvl.sf.net
00005 //
00006 // Copyright (C) 2000-2002  Sarang Lakare <sarang#users.sf.net>
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library 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 GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems to openvl-devel@lists.sf.net or
00024 // at the OpenVL website.
00025 //
00026 
00027 #ifndef _vlNormal_h
00028 #define _vlNormal_h
00029 
00030 #include <iostream>
00031 #include <math.h>
00032 
00033 #include "vlvector.h"
00034 
00052 template <class T>
00053 class vlNormal : public vlVector<T>
00054 {
00055 public:
00057   vlNormal<T>(T const & x = 0, T const & y = 0, T const & z = 0);
00058 
00060   vlNormal<T>(vlTriple<T> const & triple);
00061 
00063   ~vlNormal<T>();
00064 
00066   T x() const { return m_x; }
00067 
00069   T y() const { return m_y; }
00070 
00072   T z() const { return m_z; }
00073 
00075   template <class S>
00076   void x(const S & value) { m_x = value; normalize(); }
00077 
00079   template <class S>
00080   void y(const S & value) { m_y = value; normalize(); }
00081 
00083   template <class S>
00084   void z(const S & value) { m_z = value; normalize(); }
00085 
00087   vlNormal<T> operator - () const;
00088 
00090   vlNormal<T> operator + (vlTriple<T> const & other) const;
00091 
00093   vlNormal<T> operator + (T const & value) const;
00094 
00096   vlNormal<T> operator - (vlTriple<T> const & other) const;
00097 
00099   vlNormal<T> operator - (T const & value) const;
00100 
00102   vlNormal<T> & operator += (vlTriple<T> const & other);
00103 
00105   vlNormal<T> & operator -= (vlTriple<T> const & other);
00106 
00108   void operator *= (T const & value);
00109   //vlNormal<T> operator *= (T const & value);
00110 
00112   void operator /= (T const & value);
00113   //vlNormal<T> operator /= (T const & value);
00114 
00116   vlNormal<T> operator * (T const & value) const;
00117 
00119   vlNormal<T> operator / (T const & value) const;
00120 
00122   vlNormal<T> cross(vlVector<T> const & other) const;
00123 
00125   void clamp(T const & min, T const & max);
00126 
00128   void scale(vlVector<T> const & other);
00129 };
00130 
00131 // include the inline definitions
00132 
00141 template <class T>
00142 vlNormal<T>::vlNormal(T const & x, T const & y, T const & z)
00143   : vlVector<T>(x, y, z)
00144 {
00145   // normalize the input
00146   normalize();
00147 }
00148 
00149 template <class T>
00150 vlNormal<T>::vlNormal(vlTriple<T> const & triple)
00151   : vlVector<T>(triple)
00152 {
00153   // normalize the input
00154   normalize();
00155 }
00156 
00162 template <class T>
00163 vlNormal<T>::~vlNormal()
00164 {
00165 
00166 }
00167 
00174 template <class T>
00175 inline vlNormal<T> vlNormal<T>::operator - () const {
00176   return vlNormal<T>(-m_x, -m_y, -m_z);
00177 }
00178 
00179 
00187 template <class T>
00188 inline vlNormal<T> vlNormal<T>::operator + (vlTriple<T> const & other) const {
00189   return vlNormal<T>(m_x+other.m_x, m_y+other.m_y, m_z+other.m_z);
00190 }
00191 
00192 
00200 template <class T>
00201 inline vlNormal<T> vlNormal<T>::operator + (T const & value) const {
00202     return vlNormal<T>(m_x+value, m_y+value, m_z+value);
00203 }
00204 
00205 
00213 template <class T>
00214 inline vlNormal<T> vlNormal<T>::operator - (vlTriple<T> const & other) const {
00215     return vlNormal<T>(m_x-other.m_x, m_y-other.m_y, m_z-other.m_z);
00216 }
00217 
00218 
00226 template <class T>
00227 inline vlNormal<T> vlNormal<T>::operator - (T const & value) const {
00228     return vlNormal<T>(m_x-value, m_y-value, m_z-value);
00229 }
00230        
00231 
00239 template <class T>
00240 inline vlNormal<T> & vlNormal<T>::operator += (vlTriple<T> const & other) {
00241     m_x+=other.m_x; m_y+=other.m_y; m_z+=other.m_z;
00242     normalize();
00243     return *this;
00244 }
00245 
00246 
00254 template <class T>
00255 inline vlNormal<T> & vlNormal<T>::operator -= (vlTriple<T> const & other) {
00256     m_x-=other.m_x; m_y-=other.m_y; m_z-=other.m_z;
00257     normalize();
00258     return *this;
00259 }
00260 
00261 
00269 template <class T>
00270 inline void vlNormal<T>::operator *= (T const & value) {
00271   m_x*=value;
00272   m_y*=value;
00273   m_z*=value;
00274   normalize();
00275   //return *this;
00276 }
00277 
00278 
00286 template <class T>
00287 inline void vlNormal<T>::operator /= (T const & value) {
00288   float factor = (value == static_cast<T>(0)) ? 1.0 : (1.0f/value);
00289   m_x = static_cast<T>(m_x*factor);
00290   m_y = static_cast<T>(m_y*factor);
00291   m_z = static_cast<T>(m_z*factor);
00292   normalize();
00293   //return *this;
00294 }
00295 
00296 
00303 template <>
00304 inline void vlNormal<float>::operator /= (float const & value) {
00305   float factor = (value == 0.0f) ? 1.0f : 1.0f/value;
00306   m_x *= factor;
00307   m_y *= factor;
00308   m_z *= factor;
00309   normalize();
00310 }
00311 
00312 
00319 template <>
00320 inline void vlNormal<double>::operator /= (double const & value) {
00321   double factor = (value == 0.0f) ? 1.0f : 1.0f/value;
00322   m_x *= factor;
00323   m_y *= factor;
00324   m_z *= factor;
00325   normalize();
00326 }
00327 
00328 
00336 template <class T>
00337 inline vlNormal<T> vlNormal<T>::operator * (T const & value) const {
00338   return vlNormal(m_x*value, m_y*value, m_z*value);
00339 }
00340 
00341 
00349 template <class T>
00350 inline vlNormal<T> vlNormal<T>::operator / (T const & value) const {
00351   T factor =
00352   (constValue == static_cast<T>(0)) ? static_cast<T>(1) : ((static_cast<T>(1))/value);
00353 
00354   return vlNormal(m_x*factor, m_y*factor, m_z*factor);
00355 }
00356 
00357 
00364 template <class T>
00365 inline vlNormal<T> vlNormal<T>::cross(vlVector<T> const & other) const
00366 {
00367   return vlNormal<T>((m_y*other.m_z - m_z*other.m_y),
00368                           (m_z*other.m_x - m_x*other.m_z),
00369                           (m_x*other.m_y - m_y*other.m_x));
00370 }
00371 
00372 
00379 template <class T>
00380 inline void vlNormal<T>::clamp(T const & min, T const & max)
00381 {
00382   // what does clamping mean for a normal?
00383 }
00384 
00385 
00391 template <class T>
00392 inline void vlNormal<T>::scale(vlVector<T> const & other)
00393 {
00394   // normal cannot be scaled.. so do nothing
00395 }
00396 
00397 
00399 typedef vlNormal<float> vlNormal3f;
00400 
00402 typedef vlNormal<double> vlNormal3d;
00403 
00404 #endif // _vlNormal_h

Generated on Fri Mar 18 11:33:14 2005 for OpenVL by doxygen 1.3.3