artkpFloat_float.h
Go to the documentation of this file.
00001 /* ========================================================================
00002  * PROJECT: ARToolKitPlus
00003  * ========================================================================
00004  * This work is based on the original ARToolKit developed by
00005  *   Hirokazu Kato
00006  *   Mark Billinghurst
00007  *   HITLab, University of Washington, Seattle
00008  * http://www.hitl.washington.edu/artoolkit/
00009  *
00010  * Copyright of the derived and new portions of this work
00011  *     (C) 2006 Graz University of Technology
00012  *
00013  * This framework is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This framework is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this framework; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  * For further information please contact 
00028  *   Dieter Schmalstieg
00029  *   <schmalstieg@icg.tu-graz.ac.at>
00030  *   Graz University of Technology, 
00031  *   Institut for Computer Graphics and Vision,
00032  *   Inffeldgasse 16a, 8010 Graz, Austria.
00033  * ========================================================================
00034  ** @author   Daniel Wagner
00035  *
00036  * $Id$
00037  * @file
00038  * ======================================================================== */
00039 
00040 
00041 #ifndef __ARTKPFLOAT_FLOAT_HEADERFILE__
00042 #define __ARTKPFLOAT_FLOAT_HEADERFILE__
00043 
00044 #include <math.h>
00045 
00046 
00047 // Floating point implementation of artkpFloat
00048 // Although this class will be very slow on any hardware
00049 // without an FPU the advantage is high precision.
00050 //
00051 template <typename BASETYPE_>
00052 class artkpFloat_float
00053 {
00054 public:
00055         typedef BASETYPE_ BASETYPE;
00056 
00057         artkpFloat_float()                                                                      {}
00058         artkpFloat_float(int nV)                                                        {  setInt(nV);  }
00059         artkpFloat_float(unsigned int nV)                                       {  setUnsignedInt(nV);  }
00060         artkpFloat_float(float nV)                                                      {  setFloat(nV);  }
00061         artkpFloat_float(double nV)                                                     {  setDouble(nV);  }
00062         artkpFloat_float(const artkpFloat_float& nOther)        {  v = nOther.v;  }
00063 
00064         // custom interface
00065         //
00066         bool isFixed()                                                                          {  return false;  };
00067 
00068         void setFixed(int nV)                                                   {  v = nV/65536.0f;  }
00069         void setInt(int nV)                                                             {  v = (BASETYPE)nV;  }
00070         void setUnsignedInt(int nV)                                             {  v = (BASETYPE)nV;  }
00071         void setFloat(float nV)                                                 {  v = nV;  }
00072         void setDouble(double nV)                                               {  v = (BASETYPE)nV;  }
00073         void setArtkpFloat(const artkpFloat_float& nOther)      {  v = nOther.v;  }
00074 
00075         int getByte() const         {  return (int)(v*255.0f);  }
00076         int getFixed() const        {  return (int)(v*65536.0f);  }
00077         int getInt() const                      {  return (int)v;  }
00078         float getFloat() const          {  return (float)v;  }
00079         double getDouble() const        {  return (double)v;  }
00080 
00081         operator double() const         {  return getDouble();  }
00082 
00083         void inverse(const artkpFloat_float& nOther)            {  v = BASETYPE(1)/nOther.v;  }
00084         void inverse()                                                                          {  v = BASETYPE(1)/v;  }
00085 
00086         void inverseSqrt(const artkpFloat_float& nOther)        {  v = BASETYPE(1)/(BASETYPE)sqrt(nOther.v);  }
00087         void inverseSqrt()                                                              {  v = BASETYPE(1)/(BASETYPE)sqrt(v);  }
00088 
00089         void multiplyBy255()                                                    {  v *= 255.0f;  }
00090 
00091 
00092         // some standard math.h routines applied to this class
00093         //
00094         friend inline const artkpFloat_float sqrt(const artkpFloat_float& nV)
00095                 {  return ::sqrt(nV.v);  }
00096         friend inline const artkpFloat_float cos(const artkpFloat_float& nV)
00097                 {  return ::cos(nV.v);  }
00098         friend inline const artkpFloat_float sin(const artkpFloat_float& nV)
00099                 {  return ::sin(nV.v);  }
00100         friend inline const artkpFloat_float acos(const artkpFloat_float& nV)
00101                 {  return ::acos(nV.v);  }
00102         friend inline const artkpFloat_float asin(const artkpFloat_float& nV)
00103                 {  return ::asin(nV.v);  }
00104         friend inline const artkpFloat_float atan2(const artkpFloat_float& nVa, const artkpFloat_float& nVb)
00105                 {  return ::atan2(nVa.v,nVb.v);  }
00106         friend inline const artkpFloat_float fabs(const artkpFloat_float& nV)
00107                 {  return ::fabs(nV.v);  }
00108         friend inline const artkpFloat_float pow(const artkpFloat_float& nVa, const artkpFloat_float& nVb)
00109                 {  return ::pow(nVa.v,nVb.v);  }
00110         friend inline const artkpFloat_float ceil(const artkpFloat_float& nV)
00111                 {  return ::ceil(nV.v);  }
00112 
00113         // overloaded operators
00114         //
00115         artkpFloat_float& operator=(unsigned int nV)                            {  setInt(nV);  return *this; }
00116         artkpFloat_float& operator=(int nV)                                                     {  setInt(nV);  return *this; }
00117         artkpFloat_float& operator=(float nV)                                           {  setFloat(nV);  return *this; }
00118         artkpFloat_float& operator=(double nV)                                          {  setDouble(nV);  return *this; }
00119         artkpFloat_float& operator=(const artkpFloat_float& nOther)     {  v = nOther.v;  return *this;  }
00120 
00121         artkpFloat_float operator-() const  {  artkpFloat_float w;  w.v = -v;  return w;  }
00122 
00123         artkpFloat_float& operator+=(int nV)    {  v+=(BASETYPE)nV;  return *this;  }
00124         artkpFloat_float& operator-=(int nV)    {  v-=(BASETYPE)nV;  return *this;  }
00125         artkpFloat_float& operator*=(int nV)    {  v*=(BASETYPE)nV;  return *this;  }
00126         artkpFloat_float& operator/=(int nV)    {  v/=(BASETYPE)nV;  return *this;  }
00127 
00128         artkpFloat_float& operator+=(float nV)  {  v+=nV;  return *this;  }
00129         artkpFloat_float& operator-=(float nV)  {  v-=nV;  return *this;  }
00130         artkpFloat_float& operator*=(float nV)  {  v*=nV;  return *this;  }
00131         artkpFloat_float& operator/=(float nV)  {  v/=nV;  return *this;  }
00132 
00133         artkpFloat_float& operator+=(double nV) {  v+=(BASETYPE)nV;  return *this;  }
00134         artkpFloat_float& operator-=(double nV) {  v-=(BASETYPE)nV;  return *this;  }
00135         artkpFloat_float& operator*=(double nV) {  v*=(BASETYPE)nV;  return *this;  }
00136         artkpFloat_float& operator/=(double nV) {  v/=(BASETYPE)nV;  return *this;  }
00137 
00138         artkpFloat_float& operator+=(const artkpFloat_float& nOther)    {  v+=nOther.v;  return *this;  }
00139         artkpFloat_float& operator-=(const artkpFloat_float& nOther)    {  v-=nOther.v;  return *this;  }
00140         artkpFloat_float& operator*=(const artkpFloat_float& nOther)    {  v*=nOther.v;  return *this;  }
00141         artkpFloat_float& operator/=(const artkpFloat_float& nOther)    {  v/=nOther.v;  return *this;  }
00142 
00143         artkpFloat_float& operator>>=(int nBits)        {  int tmp=1<<nBits;    v/=tmp;  return *this;  }
00144         artkpFloat_float& operator<<=(int nBits)        {  int tmp=1<<nBits;    v*=tmp;  return *this;  }
00145 
00146         bool operator==(const artkpFloat_float& nOther) const           {  return v==nOther.v;  }
00147         bool operator!=(const artkpFloat_float& nOther) const           {  return v!=nOther.v;  }
00148         bool operator<=(const artkpFloat_float& nOther) const           {  return v<=nOther.v;  }
00149         bool operator>=(const artkpFloat_float& nOther) const           {  return v>=nOther.v;  }
00150         bool operator<(const artkpFloat_float& nOther) const            {  return v<nOther.v;  }
00151         bool operator>(const artkpFloat_float& nOther) const            {  return v>nOther.v;  }
00152 
00153         bool operator==(int nOther) const               {  return v==(BASETYPE)nOther;  }
00154         bool operator!=(int nOther) const               {  return v!=(BASETYPE)nOther;  }
00155         bool operator<=(int nOther) const               {  return v<=(BASETYPE)nOther;  }
00156         bool operator>=(int nOther) const               {  return v>=(BASETYPE)nOther;  }
00157         bool operator<(int nOther) const                {  return v< (BASETYPE)nOther;  }
00158         bool operator>(int nOther) const                {  return v> (BASETYPE)nOther;  }
00159 
00160         bool operator==(float nOther) const             {  return v==nOther;  }
00161         bool operator!=(float nOther) const             {  return v!=nOther;  }
00162         bool operator<=(float nOther) const             {  return v<=nOther;  }
00163         bool operator>=(float nOther) const             {  return v>=nOther;  }
00164         bool operator<(float nOther) const              {  return v<nOther;  }
00165         bool operator>(float nOther) const              {  return v>nOther;  }
00166 
00167         friend inline const artkpFloat_float operator+(const artkpFloat_float& left, const artkpFloat_float& right)
00168                 {       return left.v+right.v;  }
00169         friend inline const artkpFloat_float operator+(const artkpFloat_float& left, float right)
00170                 {       return left.v+right;    }
00171         friend inline const artkpFloat_float operator+(float left, const artkpFloat_float& right)
00172                 {       return left+right.v;    }
00173 
00174         friend inline const artkpFloat_float operator-(const artkpFloat_float& left, const artkpFloat_float& right)
00175         {       return left.v-right.v;  }
00176         friend inline const artkpFloat_float operator-(const artkpFloat_float& left, float right)
00177         {       return left.v-right;    }
00178         friend inline const artkpFloat_float operator-(float left, const artkpFloat_float& right)
00179         {       return left-right.v;    }
00180 
00181         friend inline const artkpFloat_float operator*(const artkpFloat_float& left, const artkpFloat_float& right)
00182         {       return left.v*right.v;  }
00183         friend inline const artkpFloat_float operator*(const artkpFloat_float& left, float right)
00184         {       return left.v*right;    }
00185         friend inline const artkpFloat_float operator*(float left, const artkpFloat_float& right)
00186         {       return left*right.v;    }
00187 
00188         friend inline const artkpFloat_float operator/(const artkpFloat_float& left, const artkpFloat_float& right)
00189         {       return left.v/right.v;  }
00190         friend inline const artkpFloat_float operator/(const artkpFloat_float& left, float right)
00191         {       return left.v/right;    }
00192         friend inline const artkpFloat_float operator/(float left, const artkpFloat_float& right)
00193         {       return left/right.v;    }
00194 
00195 protected:
00196         BASETYPE v;
00197 };
00198 
00199 
00200 /*
00201 // binary operator +
00202 //
00203 template <typename BT>
00204 inline const artkpFloat_float<typename BT>
00205 operator+(const artkpFloat_float<typename BT>& left, const artkpFloat_float<typename BT>& right)
00206 {
00207         return artkpFloat_float<BT>(left.v+right.v);
00208 }
00209 
00210 template <typename BT>
00211 inline const artkpFloat_float<typename BT>
00212 operator+(const artkpFloat_float<typename BT>& left, float right)
00213 {
00214         return artkpFloat_float<BT>(left.v+right);
00215 }
00216 
00217 template <typename BT>
00218 inline const artkpFloat_float<typename BT>
00219 operator+(float left, const artkpFloat_float<typename BT>& right)
00220 {
00221         return artkpFloat_float<BT>(left+right.v);
00222 }
00223 
00224 
00225 
00226 // binary operator -
00227 //
00228 template <typename BT>
00229 inline const artkpFloat_float<typename BT>
00230 operator-(const artkpFloat_float<typename BT>& left, const artkpFloat_float<typename BT>& right)
00231 {
00232         return artkpFloat_float<BT>(left.v-right.v);
00233 }
00234 
00235 template <typename BT>
00236 inline const artkpFloat_float<typename BT>
00237 operator-(const artkpFloat_float<typename BT>& left, float right)
00238 {
00239         return artkpFloat_float<BT>(left.v-right);
00240 }
00241 
00242 template <typename BT>
00243 inline const artkpFloat_float<typename BT>
00244 operator-(float left, const artkpFloat_float<typename BT>& right)
00245 {
00246         return artkpFloat_float<BT>(left-right.v);
00247 }
00248 
00249 
00250 // binary operator *
00251 //
00252 template <typename BT>
00253 inline const artkpFloat_float<typename BT>
00254 operator*(const artkpFloat_float<typename BT>& left, const artkpFloat_float<typename BT>& right)
00255 {
00256         return artkpFloat_float<BT>(left.v*right.v);
00257 }
00258 
00259 template <typename BT>
00260 inline const artkpFloat_float<typename BT>
00261 operator*(const artkpFloat_float<typename BT>& left, float right)
00262 {
00263         return artkpFloat_float<BT>(left.v*right);
00264 }
00265 
00266 template <typename BT>
00267 inline const artkpFloat_float<typename BT>
00268 operator*(float left, const artkpFloat_float<typename BT>& right)
00269 {
00270         return artkpFloat_float<BT>(left*right.v);
00271 }
00272 
00273 
00274 // binary operator /
00275 //
00276 template <typename BT>
00277 inline const artkpFloat_float<typename BT>
00278 operator/(const artkpFloat_float<typename BT>& left, const artkpFloat_float<typename BT>& right)
00279 {
00280         return artkpFloat_float<BT>(left.v/right.v);
00281 }
00282 
00283 
00284 template <typename BT>
00285 inline const artkpFloat_float<typename BT>
00286 operator/(const artkpFloat_float<typename BT>& left, float right)
00287 {
00288         return artkpFloat_float<BT>(left.v/right);
00289 }
00290 
00291 template <typename BT>
00292 inline const artkpFloat_float<typename BT>
00293 operator/(float left, const artkpFloat_float<typename BT>& right)
00294 {
00295         return artkpFloat_float<BT>(left/right.v);
00296 }
00297 */
00298 
00299 
00300 /*
00301 // math.h methods
00302 //
00303 template <typename BT>
00304 inline const artkpFloat_float<typename BT>
00305 cos(const artkpFloat_float<typename BT>& nV)
00306 {
00307         return artkpFloat_float<BT>(::cos(nV.v));
00308 }
00309 
00310 
00311 template <typename BT>
00312 inline const artkpFloat_float<typename BT>
00313 sin(const artkpFloat_float<typename BT>& nV)
00314 {
00315         return artkpFloat_float<BT>(::sin(nV.v));
00316 }
00317 
00318 template <typename BT>
00319 inline const artkpFloat_float<typename BT>
00320 acos(const artkpFloat_float<typename BT>& nV)
00321 {
00322         return artkpFloat_float<BT>(::acos(nV.v));
00323 }
00324 
00325 template <typename BT>
00326 inline const artkpFloat_float<typename BT>
00327 asin(const artkpFloat_float<typename BT>& nV)
00328 {
00329         return artkpFloat_float<BT>(::asin(nV.v));
00330 }
00331 
00332 template <typename BT>
00333 inline const artkpFloat_float<typename BT>
00334 atan2(const artkpFloat_float<typename BT>& nVa, const artkpFloat_float<typename BT>& nVb)
00335 {
00336         return artkpFloat_float<BT>(::atan2(nVa.v, nVb.v));
00337 }
00338 
00339 template <typename BT>
00340 inline const artkpFloat_float<typename BT>
00341 fabs(const artkpFloat_float<typename BT>& nV)
00342 {
00343         return artkpFloat_float<BT>(::fabs(nV.v));
00344 }
00345 
00346 template <typename BT>
00347 inline const artkpFloat_float<typename BT>
00348 pow(const artkpFloat_float<typename BT>& nVa, const artkpFloat_float<typename BT>& nVb)
00349 {
00350         return artkpFloat_float<BT>(::pow(nVa.v, nVb.v));
00351 }
00352 
00353 template <typename BT>
00354 inline const artkpFloat_float<typename BT>
00355 sqrt(const artkpFloat_float<typename BT>& nV)
00356 {
00357         return artkpFloat_float<BT>(::sqrt(nV.v));
00358 }
00359 
00360 template <typename BT>
00361 inline const artkpFloat_float<typename BT>
00362 ceil(const artkpFloat_float<typename BT>& nV)
00363 {
00364         return artkpFloat_float<BT>(::ceil(nV.v));
00365 }
00366 */
00367 
00368 #endif //__ARTKPFLOAT_FLOAT_HEADERFILE__


tuw_artoolkitplus
Author(s): Markus Bader
autogenerated on Sun May 29 2016 02:50:12