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

CP3D.h

Go to the documentation of this file.
00001 /*
00002  * CP3D.h
00003  * $Id: CP3D.h,v 1.5 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 //  Description : Class CP3D
00031 //  Purpose     : Provides  funcionality
00032 
00033 
00034 #ifndef __CP3D_H
00035 #define __CP3D_H
00036 
00037 
00038 // System
00040 #include <math.h>
00041 #ifdef _MSC_VER
00042 #if _MSC_VER >= 1300
00043 #include <iostream>
00044 #endif
00045 #else
00046 #include <iostream.h>
00047 #endif
00048 
00049 
00050 // Own
00052 #include "CV3D.h"
00053 #include "CP4D.h"
00054 
00055 // forward declarations
00057 class CV3D;
00058 
00059 
00060 
00061 
00066 class CP3D 
00067 {   
00068 public:
00069   static double epsilon;
00070 
00073   CP3D() { m_ard[0] = 0.0;
00074            m_ard[1] = 0.0;
00075            m_ard[2] = 0.0; };
00076 
00079   CP3D(double rdX, double rdY, double rdZ) { m_ard[0] = rdX;
00080                                              m_ard[1] = rdY;
00081                                              m_ard[2] = rdZ; }
00082 
00085   CP3D(const CP3D& Point) { m_ard[0] = Point[0];
00086                             m_ard[1] = Point[1];
00087                             m_ard[2] = Point[2]; }
00088 
00089 
00091   // OVERLOADED OPERATORS //
00093  
00096   operator CP4D() const;
00097 
00099   const CP3D& operator=(const CP3D&);
00100 
00105   int operator==(const CP3D&) const;
00106 
00110   int operator!=(const CP3D&) const;
00111 
00113   CP3D& operator+=(const CV3D&);
00114 
00116   CP3D& operator-=(const CV3D&);
00117   
00119   CP3D& operator*=(const CV3D&);
00120 
00122   CP3D& operator*=(double);
00123 
00125   CP3D& operator/=(double);
00126 
00128   CP3D operator+(const CV3D&) const;
00129 
00131   CP3D operator+(const CP3D&) const;  // eigentlich nur fuer affine Punkte
00132   
00134   CP3D operator-(const CV3D&) const;
00135 
00137   CV3D operator-(const CP3D&) const ;
00138 
00140   CP3D operator*(const CV3D&) const;  // scaling
00141 
00143   CP3D operator*(double) const;
00144 
00146   CP3D operator/(const CV3D&) const;
00147 
00149   CP3D operator/(double) const;
00150 
00154   double& operator [] (int i) { return m_ard[i]; };
00155 
00157   double operator[](int i) const { return m_ard[i]; };
00158 
00159 
00161   // METHODS //
00163   
00165   double getMinComponent(void) const    { return m_ard[getMinComponentCoord()]; };
00166  
00168   double getAbsMinComponent(void) const { return m_ard[getAbsMinComponentCoord()]; };
00169  
00171   double getMaxComponent(void) const    { return m_ard[getMaxComponentCoord()]; };
00172  
00174   double getAbsMaxComponent(void) const { return m_ard[getAbsMaxComponentCoord()]; };
00175  
00177   int getMinComponentCoord(void) const;
00178 
00180   int getAbsMinComponentCoord(void) const;
00181 
00183   int getMaxComponentCoord(void) const;
00184 
00186   int getAbsMaxComponentCoord(void) const;
00187 
00191   CV3D getCV3D() const;
00192 
00194   double getX(void) const  { return m_ard[0]; };
00195 
00197   double getY(void) const  { return m_ard[1]; };
00198 
00200   double getZ(void) const  { return m_ard[2]; };
00201 
00203   void setX(double rdX)    { m_ard[0] = rdX; return; };
00204 
00206   void setY(double rdY)    { m_ard[1] = rdY; return; };
00207 
00209   void setZ(double rdZ)    { m_ard[2] = rdZ; return; };
00210 
00213   void setCoord(double rdX, double rdY, double rdZ) { m_ard[0] = rdX; 
00214                                                       m_ard[1] = rdY;
00215                                                       m_ard[2] = rdZ; 
00216                                                       return; };
00217 
00219   // FRIENDS //
00221   
00223   friend CP3D AffinComb(const CP3D&, double, const CP3D&);
00224 
00226   friend CP3D AffinComb3(double r, const CP3D& R, 
00227                          double s, const CP3D& S,
00228                          double t, const CP3D T) { 
00229                                   return CP3D(r*R[0] + s*S[0] + t*T[0],
00230                                               r*R[1] + s*S[1] + t*T[1],
00231                                               r*R[2] + s*S[2] + t*T[2]); };
00232 
00234   friend double dist(const CP3D&, const CP3D&);
00235 
00237   friend double quaddist(const CP3D&, const CP3D&);
00238 
00240   friend CP3D Min(const CP3D&, const CP3D&);
00241 
00243   friend CP3D Max(const CP3D&, const CP3D&);
00244 
00246   friend CP3D operator*(double, const CP3D&);
00247 
00249   friend CP3D MidPoint(const CP3D&, const CP3D&);
00250 
00251 
00252   // output to stderr
00254 
00255   void print() const;
00256 
00258   friend inline ostream& operator<<(ostream&, const CP3D&);
00259 
00261   friend inline istream& operator>>(istream&, CP3D&);
00262 
00263 protected:
00264   double m_ard[3];
00265 };
00266 
00267 
00268 
00269 // Function   : operator=
00270 // Parameters : const CP3D& p1
00271 // Purpose    : assign another point to this point
00272 // Comments   : 
00273 inline const CP3D& CP3D::operator=(const CP3D& p1)
00274 /*******************************************************************/
00275 {
00276   m_ard[0] = p1.m_ard[0];
00277   m_ard[1] = p1.m_ard[1];
00278   m_ard[2] = p1.m_ard[2];
00279   return *this;
00280 }
00281 
00282 
00283 
00284 // Function   : getCV3D
00285 // Parameters : 
00286 // Purpose    : Convert CP3D to CV3D
00287 // Comments   : 
00288 inline CV3D CP3D::getCV3D() const
00289 /*******************************************************************/
00290 {
00291   return CV3D(m_ard[0], m_ard[1], m_ard[2]);
00292 }
00293 
00294 
00295 
00296 // Function   : operator<<
00297 // Parameters : ostream& s, const CP3D& pnt
00298 // Purpose    : 
00299 // Comments   : 
00300 inline ostream& operator<<(ostream& s, const CP3D& pnt)
00301 /*******************************************************************/
00302 {   
00303   return s << "(" << pnt.m_ard[0] << "," << pnt.m_ard[1] << "," << pnt.m_ard[2] << ")"; 
00304 }
00305 
00306 
00307 
00308 // Function   : operator>>
00309 // Parameters : istream& s, CP3D& pnt
00310 // Purpose    : 
00311 // Comments   : 
00312 inline istream& operator>>(istream& s, CP3D& pnt)
00313 /*******************************************************************/
00314 {   
00315   char c;
00316   return s >> c >> pnt.m_ard[0] >> c >> pnt.m_ard[1] >> c >> pnt.m_ard[2] >> c;
00317 }
00318 
00319 #endif

Generated on Wed Sep 14 02:49:30 2005 for QGLViewer by  doxygen 1.4.4