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

CP4D.h

Go to the documentation of this file.
00001 /*
00002  * CP4D.h
00003  * $Id: CP4D.h,v 1.4 2003/06/24 14:50:02 anxo Exp $
00004  *
00005  * Copyright (C) 1999, 2000 Michael Meissner
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * As a special exception to the GPL, the QGLViewer authors (Markus
00022  * Janich, Michael Meissner, Richard Guenther, Alexander Buck and Thomas
00023  * Woerner) give permission to link this program with Qt (non-)commercial
00024  * edition, and distribute the resulting executable, without including
00025  * the source code for the Qt (non-)commercial edition in the source
00026  * distribution.
00027  *
00028  */
00029 
00030 
00031 #ifndef __CP4D_H
00032 #define __CP4D_H
00033 
00034 
00035 
00036 // System
00038 #include <math.h>
00039 #ifdef _MSC_VER
00040 #if _MSC_VER >= 1300
00041 #include <iostream>
00042 #endif
00043 #else
00044 #include <iostream.h>
00045 #endif
00046 
00047 // Own
00049 #include "CV4D.h"
00050 
00051 // forward declarations
00053 class CP3D;
00054 
00055 
00060 class CP4D {   
00061 public:
00062   static double epsilon;
00063 
00066   CP4D() { m_ard[0] = 0.0;
00067            m_ard[1] = 0.0;
00068            m_ard[2] = 0.0;
00069            m_ard[3] = 0.0; };
00070 
00073   CP4D(double rdX, double rdY, double rdZ) { m_ard[0] = rdX;
00074                                              m_ard[1] = rdY;
00075                                              m_ard[2] = rdZ;
00076                                              m_ard[3] = 1; };
00077 
00080   CP4D(double rdX, double rdY, double rdZ, double rdW) { m_ard[0] = rdX;
00081                                                          m_ard[1] = rdY;
00082                                                          m_ard[2] = rdZ;
00083                                                          m_ard[3] = rdW; };
00084 
00087   CP4D(const CP4D& Point) { m_ard[0] = Point[0];
00088                             m_ard[1] = Point[1];
00089                             m_ard[2] = Point[2];
00090                             m_ard[3] = Point[3]; };
00091 
00092 
00093 
00095   // OVERLOADED OPERATORS //
00097 
00100   operator CP3D() const;
00101 
00103   const CP4D& operator=(const CP4D&);
00104 
00109   int operator==(const CP4D&);
00110 
00114   int operator!=(const CP4D&);
00115 
00117   CP4D& operator+=(const CV4D&);
00118 
00120   CP4D& operator-=(const CV4D&);
00121 
00123   CV4D operator-(const CP4D&) const;
00124 
00126   CP4D operator+(const CV4D&) const;
00127 
00129   CP4D operator-(const CV4D&) const;
00130 
00132   CP4D operator-() const;
00133 
00137   double& operator[](int i) { return m_ard[i]; };
00138 
00140   double operator[](int i) const { return m_ard[i]; };
00141 
00142 
00143 
00145   // METHODS //
00147 
00151   CV4D getCV4D() const;
00152 
00154   double getX() const   { return m_ard[0]; };
00155   
00157   double getY() const   { return m_ard[1]; };
00158   
00160   double getZ() const   { return m_ard[2]; };
00161   
00163   double getW() const   { return m_ard[3]; };
00164 
00166   void setX(double rdX) { m_ard[0] = rdX; };
00167 
00169   void setY(double rdY) { m_ard[1] = rdY; };
00170 
00172   void setZ(double rdZ) { m_ard[2] = rdZ; };
00173 
00175   void setW(double rdW) { m_ard[3] = rdW; };
00176 
00179   void setCoord(double rdX, double rdY, double rdZ, double rdW) { m_ard[0] = rdX; 
00180                                                                   m_ard[1] = rdY;
00181                                                                   m_ard[2] = rdZ; 
00182                                                                   m_ard[3] = rdW; 
00183                                                                   return; };
00184 
00186   void print() const;
00187   
00188 
00189 
00191   // FRIENDS //
00193  
00195   friend ostream& operator<<(ostream&, const CP4D&); 
00196 
00198   friend istream& operator>>(istream&, CP4D&); 
00199 
00200   /*
00201     CP4D operator*(double& a)
00202     { CP4D pnt;pnt.m_ard[0]=a*m_ard[0]; pnt.m_ard[1]=a*m_ard[1]; pnt.m_ard[2]=a*m_ard[2]; return pnt;}
00203     friend CP4D operator*(double a,CP4D& p1)
00204     { return CP4D(a*p1.m_ard[0], a*p1.m_ard[1], a*p1.m_ard[2]); }
00205     friend CP4D  AffinComb(CP4D&,double,CP4D&);
00206     friend double dist(CP4D&, CP4D&);
00207   */
00208 
00210   friend inline CP4D AffinComb3(double, const CP4D&, 
00211                                 double, const CP4D&,
00212                                 double, const CP4D&);
00213  
00214 
00215 private:
00216   friend class CP3D;
00217 
00218 protected:
00219   double m_ard[4];
00220 };
00221 
00222 
00223 
00224 
00225 
00226 // Function   : operator=
00227 // Parameters : const CP4D& cPoint
00228 // Purpose    : 
00229 // Comments   :
00230 inline const CP4D& CP4D::operator=(const CP4D& cPoint) {
00231 /*******************************************************************/
00232   m_ard[0] = cPoint.m_ard[0];
00233   m_ard[1] = cPoint.m_ard[1];
00234   m_ard[2] = cPoint.m_ard[2];
00235   m_ard[3] = cPoint.m_ard[3];
00236 
00237   return *this;
00238 }
00239 
00240 
00241 
00242 // Function   : getCV4D
00243 // Parameters : 
00244 // Purpose    : 
00245 // Comments   :
00246 inline CV4D CP4D::getCV4D() const
00247 /*******************************************************************/
00248 {
00249   return CV4D(m_ard[0], m_ard[1], m_ard[2], m_ard[3]);
00250 }
00251   
00252 
00253 
00254 // Function   : AffinComb3
00255 // Parameters : double r, const CP4D& R, double s, const CP4D& S,
00256 //              double t, const CP4D &T
00257 // Purpose    : 
00258 // Comments   :
00259 inline CP4D AffinComb3(double r, const CP4D& R, double s, const CP4D& S,
00260                        double t, const CP4D &T)
00261 /*******************************************************************/
00262 {
00263   return CP4D(r*R[0] + s*S[0] + t*T[0],
00264               r*R[1] + s*S[1] + t*T[1],
00265               r*R[2] + s*S[2] + t*T[2],
00266               r*R[3] + s*S[3] + t*T[3]);
00267 }
00268 
00269 #endif

Generated on Wed Nov 17 23:15:19 2004 for QGLViewer by  doxygen 1.3.9.1