VR-Forces 4.0.4 Class Documentation
include/geometry/point.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 ** Copyright (c) 2003 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *******************************************************************************/
00005 /*******************************************************************************
00006 ** $RCSfile: point.h,v $ $Revision: 1.27 $ $State: Exp $
00007 *******************************************************************************/
00008 
00009 #ifndef point_H_
00010 #define point_H_
00011 
00012 #ifndef NO_VRLINK
00013 #include <vlutil/vlConfig.h>
00014 #include <vlutil/vlString.h>
00015 #include <vlutil/vlUtil.h>
00016 #endif
00017 
00018 #include <stdio.h>
00019 #include <iostream>
00020 #include "geometry/geometryDefines.h"
00021 
00022 class DtVector;
00023 class Dt4dPoint;
00024 class DtPoint;
00025 
00026 typedef DtPoint DtVertex;
00027 
00028 // DtPoint represents points in 3-space. 
00029 // DtPoint may rely on vrlink (for things like DtString and DtVector).
00030 // This class has no virtual functions, in order to minimize its run-time 
00031 // size.  (A terrain database can have millions of DtPoints, so the 
00032 // vtable ptr can matter).
00033 
00034 class DT_DLL_geometry DtPoint
00035 {
00036 
00037 public:
00038 //   friend std::ostream& operator<<(std::ostream& os, const DtPoint& point);
00039 //   friend std::istream& operator>>(std::istream& is, DtPoint& point);
00040 
00041 
00042    DtPoint(
00043       const double& x = 0.0,
00044       const double& y = 0.0,
00045       const double& z = 0.0);
00046 
00047    enum DtPointIndex {
00048       DtPX = 0,
00049       DtPY = 1,
00050       DtPZ = 2,
00051       DtMAXPointIndex
00052    };
00053 
00054    DtPoint(const DtPoint& orig);
00055    DtPoint(const DtVector& orig);
00056    DtPoint(const Dt4dPoint& orig);
00057 
00058    virtual ~DtPoint();
00059 
00060    DtPoint& operator=(const DtPoint& rhs);
00061    DtPoint& operator=(const DtVector& rhs);
00062    DtPoint& operator=(const Dt4dPoint& rhs);
00063 
00064    const double& operator[](const int& index) const;
00065    double& operator[](const int& index);
00066 
00067    const double& operator[](const DtPointIndex& index) const;
00068    double& operator[](const DtPointIndex& index);
00069 
00070    bool operator==(const DtPoint& rhs) const;
00071    bool operator!=(const DtPoint& rhs) const;
00072 
00073    DtPoint operator*(const double& rhs) const;
00074    DtPoint& operator*=(const double& rhs);
00075 
00076    DtPoint operator/(const double& rhs) const;
00077    DtPoint& operator/=(const double& rhs);
00078 
00079    DtPoint operator+(const DtPoint& rhs) const;
00080    DtPoint& operator+=(const DtPoint& rhs);
00081 
00082    DtPoint operator+(const DtVector& rhs) const;
00083    DtPoint& operator+=(const DtVector& rhs);
00084 
00085    DtPoint operator-(const DtPoint& rhs) const;
00086    DtPoint& operator-=(const DtPoint& rhs);
00087 
00088    DtPoint operator-(const DtVector& rhs) const;
00089    DtPoint& operator-=(const DtVector& rhs);
00090 
00091    // compares two points and returns true if the distance between them
00092    // is within the tolerance value.
00093    bool approxEq(const DtPoint& p, const double& tolerance) const;
00094 
00095    const double& x() const;
00096    const double& y() const;
00097    const double& z() const;
00098 
00099    void set( const double& x, const double& y, const double& z);
00100    void setX(const double& x);
00101    void setY(const double& y);
00102    void setZ(const double& z);
00103 
00104    // Distance from this point to end point.
00105    double distanceTo(const DtPoint & end) const;
00106    double distanceSquaredTo(const DtPoint & end) const;
00107 
00108    // Distance from this point to end point.  Ignores Z values.
00109    double xyDistanceTo(const DtPoint & end) const;
00110    double xyDistanceSquaredTo(const DtPoint & end) const;
00111 
00112    // Distance from this point to line defined by points A and B. Ignores Z.
00113    double xyDistanceToLine(const DtPoint& pointA, const DtPoint& pointB) const;
00114    double xyDistanceToLineSquared(const DtPoint& pointA, const DtPoint& pointB) const;
00115 
00116    // Assuming that this point is the end point of a vector
00117    // starting at (0,0,0), This function normalizes that
00118    // vector and sets this point to the normalized end point.
00119    void normalize();
00120 
00121    // Distance from this point to the origin (0,0,0) point.
00122    double magnitudeSquared() const;
00123 
00124    DtVector difference(const DtPoint& p) const;
00125 
00126 #ifndef NO_VRLINK
00127    DtString string() const;  
00128 #endif
00129 
00130    bool readFrom(FILE* fp);
00131    bool writeTo(FILE* fp);
00132 
00133    void dump(const char* label) const;
00134 
00135 protected:
00136    double myRep[3]; 
00137 };
00138 
00139 DT_DLL_geometry std::ostream& operator<<(std::ostream& os, const DtPoint& point);
00140 DT_DLL_geometry std::istream& operator>>(std::istream& is, DtPoint& point);
00141 
00142 inline DtPoint::DtPoint(const double& x, const double& y, const double& z)
00143 {
00144    myRep[DtPX] = x;
00145    myRep[DtPY] = y;
00146    myRep[DtPZ] = z;
00147 }
00148 
00149 inline DtPoint::~DtPoint()
00150 {
00151 }
00152 
00153 inline const double& DtPoint::operator[](const int& index) const
00154 {
00155    return myRep[index];
00156 }
00157 
00158 inline double& DtPoint::operator[](const int& index) 
00159 { 
00160    return myRep[index];
00161 }
00162 
00163 inline const double& DtPoint::operator[](const DtPointIndex& index) const 
00164 {
00165    return myRep[index];
00166 }
00167 
00168 inline double& DtPoint::operator[](const DtPointIndex& index) 
00169 { 
00170    return myRep[index];
00171 }
00172 
00173 inline void DtPoint::set( const double& x, const double& y, const double& z)
00174 { 
00175    myRep[DtPX] = x;
00176    myRep[DtPY] = y;
00177    myRep[DtPZ] = z;
00178 }
00179 
00180 inline const double& DtPoint::x() const
00181 {
00182    return myRep[DtPX];
00183 }
00184 
00185 inline void DtPoint::setX(const double& x)
00186 {
00187    myRep[DtPX] = x;
00188 }
00189 
00190 inline const double& DtPoint::y() const
00191 {
00192    return myRep[DtPY];
00193 }
00194 
00195 inline void DtPoint::setY(const double& y)
00196 {
00197    myRep[DtPY] = y;
00198 }
00199 
00200 inline const double& DtPoint::z() const
00201 {
00202    return myRep[DtPZ];
00203 }
00204 
00205 inline void DtPoint::setZ(const double& z)
00206 {
00207    myRep[DtPZ] = z;
00208 }
00209 
00210 #endif

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)