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

CP3D.h

Go to the documentation of this file.
00001 /*
00002  * CP3D.h
00003  * $Id: CP3D.h,v 1.4 2001/11/15 16:54:52 guenth 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 #include <iostream.h>
00042 
00043 // Own
00045 #include "CV3D.h"
00046 #include "CP4D.h"
00047 
00048 // forward declarations
00050 class CV3D;
00051 
00052 
00053 
00054 
00059 class CP3D 
00060 {   
00061 public:
00062   static double epsilon;
00063 
00066   CP3D() { m_ard[0] = 0.0;
00067            m_ard[1] = 0.0;
00068            m_ard[2] = 0.0; };
00069 
00072   CP3D(double rdX, double rdY, double rdZ) { m_ard[0] = rdX;
00073                                              m_ard[1] = rdY;
00074                                              m_ard[2] = rdZ; }
00075 
00078   CP3D(const CP3D& Point) { m_ard[0] = Point[0];
00079                             m_ard[1] = Point[1];
00080                             m_ard[2] = Point[2]; }
00081 
00082 
00084   // OVERLOADED OPERATORS //
00086  
00089   operator CP4D() const;
00090 
00092   const CP3D& operator=(const CP3D&);
00093 
00098   int operator==(const CP3D&) const;
00099 
00103   int operator!=(const CP3D&) const;
00104 
00106   CP3D& operator+=(const CV3D&);
00107 
00109   CP3D& operator-=(const CV3D&);
00110   
00112   CP3D& operator*=(const CV3D&);
00113 
00115   CP3D& operator*=(double);
00116 
00118   CP3D& operator/=(double);
00119 
00121   CP3D operator+(const CV3D&) const;
00122 
00124   CP3D operator+(const CP3D&) const;  // eigentlich nur fuer affine Punkte
00125   
00127   CP3D operator-(const CV3D&) const;
00128 
00130   CV3D operator-(const CP3D&) const ;
00131 
00133   CP3D operator*(const CV3D&) const;  // scaling
00134 
00136   CP3D operator*(double) const;
00137 
00139   CP3D operator/(const CV3D&) const;
00140 
00142   CP3D operator/(double) const;
00143 
00147   double& operator [] (int i) { return m_ard[i]; };
00148 
00150   double operator[](int i) const { return m_ard[i]; };
00151 
00152 
00154   // METHODS //
00156   
00158   double getMinComponent(void) const    { return m_ard[getMinComponentCoord()]; };
00159  
00161   double getAbsMinComponent(void) const { return m_ard[getAbsMinComponentCoord()]; };
00162  
00164   double getMaxComponent(void) const    { return m_ard[getMaxComponentCoord()]; };
00165  
00167   double getAbsMaxComponent(void) const { return m_ard[getAbsMaxComponentCoord()]; };
00168  
00170   int getMinComponentCoord(void) const;
00171 
00173   int getAbsMinComponentCoord(void) const;
00174 
00176   int getMaxComponentCoord(void) const;
00177 
00179   int getAbsMaxComponentCoord(void) const;
00180 
00184   CV3D getCV3D() const;
00185 
00187   double getX(void) const  { return m_ard[0]; };
00188 
00190   double getY(void) const  { return m_ard[1]; };
00191 
00193   double getZ(void) const  { return m_ard[2]; };
00194 
00196   void setX(double rdX)    { m_ard[0] = rdX; return; };
00197 
00199   void setY(double rdY)    { m_ard[1] = rdY; return; };
00200 
00202   void setZ(double rdZ)    { m_ard[2] = rdZ; return; };
00203 
00206   void setCoord(double rdX, double rdY, double rdZ) { m_ard[0] = rdX; 
00207                                                       m_ard[1] = rdY;
00208                                                       m_ard[2] = rdZ; 
00209                                                       return; };
00210 
00212   // FRIENDS //
00214   
00216   friend CP3D AffinComb(const CP3D&, double, const CP3D&);
00217 
00219   friend CP3D AffinComb3(double r, const CP3D& R, 
00220                          double s, const CP3D& S,
00221                          double t, const CP3D T) { 
00222                                   return CP3D(r*R[0] + s*S[0] + t*T[0],
00223                                               r*R[1] + s*S[1] + t*T[1],
00224                                               r*R[2] + s*S[2] + t*T[2]); };
00225 
00227   friend double dist(const CP3D&, const CP3D&);
00228 
00230   friend double quaddist(const CP3D&, const CP3D&);
00231 
00233   friend CP3D Min(const CP3D&, const CP3D&);
00234 
00236   friend CP3D Max(const CP3D&, const CP3D&);
00237 
00239   friend CP3D operator*(double, const CP3D&);
00240 
00242   friend CP3D MidPoint(const CP3D&, const CP3D&);
00243 
00244 
00245   // output to stderr
00247   /** Prints a point to the standard output. */
00248   void print() const;
00249 
00251   friend inline ostream& operator<<(ostream&, const CP3D&);
00252 
00254   friend inline istream& operator>>(istream&, CP3D&);
00255 
00256 protected:
00257   double m_ard[3];
00258 };
00259 
00260 
00261 
00262 // Function   : operator=
00263 // Parameters : const CP3D& p1
00264 // Purpose    : assign another point to this point
00265 // Comments   : 
00266 inline const CP3D& CP3D::operator=(const CP3D& p1)
00267 /*******************************************************************/
00268 {
00269   m_ard[0] = p1.m_ard[0];
00270   m_ard[1] = p1.m_ard[1];
00271   m_ard[2] = p1.m_ard[2];
00272   return *this;
00273 }
00274 
00275 
00276 
00277 // Function   : getCV3D
00278 // Parameters : 
00279 // Purpose    : Convert CP3D to CV3D
00280 // Comments   : 
00281 inline CV3D CP3D::getCV3D() const
00282 /*******************************************************************/
00283 {
00284   return CV3D(m_ard[0], m_ard[1], m_ard[2]);
00285 }
00286 
00287 
00288 
00289 // Function   : operator<<
00290 // Parameters : ostream& s, const CP3D& pnt
00291 // Purpose    : 
00292 // Comments   : 
00293 inline ostream& operator<<(ostream& s, const CP3D& pnt)
00294 /*******************************************************************/
00295 {   
00296   return s << "(" << pnt.m_ard[0] << "," << pnt.m_ard[1] << "," << pnt.m_ard[2] << ")"; 
00297 }
00298 
00299 
00300 
00301 // Function   : operator>>
00302 // Parameters : istream& s, CP3D& pnt
00303 // Purpose    : 
00304 // Comments   : 
00305 inline istream& operator>>(istream& s, CP3D& pnt)
00306 /*******************************************************************/
00307 {   
00308   char c;
00309   return s >> c >> pnt.m_ard[0] >> c >> pnt.m_ard[1] >> c >> pnt.m_ard[2] >> c;
00310 }
00311 
00312 #endif

Generated on Wed Mar 5 18:23:25 2003 for QGLViewer by doxygen1.3-rc3