Point3D.hpp
Go to the documentation of this file.
00001 //
00002 // Point3D.hpp
00003 // A 3-dimensional cartesian point.
00004 //
00005 
00006 
00007 #ifndef POINT3D_HPP
00008 #define POINT3D_HPP
00009 
00010 #include <cassert>
00011 #include <sstream>
00012 #include <iosfwd> // for istream, ostream
00013 #include <utility> // for std::pair<T,T>
00014 #include "../BasicDatatypes.hpp"
00015 #include "../tools/MathToolbox.hpp"             // for fuzzyCompare
00016 
00017 namespace datatypes
00018 {
00019         
00020 class Point2D;
00021 
00022 
00025 class Point3D : public BasicData
00026 {
00027 public:
00029         typedef double floatingpoint_type;
00030 
00031 private:
00032         double m_x;
00033         double m_y;
00034         double m_z;
00035 
00036 public:
00038         Point3D(double x, double y, double z)
00039                 : m_x(x)
00040                 , m_y(y)
00041                 , m_z(z)
00042         {m_datatype = Datatype_Point3D;}
00043 
00045         Point3D()
00046                 : m_x(0.0)
00047                 , m_y(0.0)
00048                 , m_z(0.0)
00049         {m_datatype = Datatype_Point3D;}
00050 
00052         explicit Point3D(const Point2D& p);
00053         
00054         // Estimate the memory usage of this object
00055         inline virtual const UINT32 getUsedMemory() const {return sizeof(*this);};
00056 
00057 
00058 
00060         //\{
00061 
00062         bool isZero() const;                            
00063         double getX() const { return m_x; }     
00064         double getY() const { return m_y; }     
00065         double getZ() const { return m_z; }     
00066 
00067         double length() const;                          
00068         double distFromOrigin() const;          
00069 
00070         double getAngleAroundX() const; 
00071         double getAngleAroundY() const; 
00072         double getAngleAroundZ() const; 
00073 
00075         Point2D toPoint2D() const;
00076         //\}
00077 
00079         //\{
00080 
00081         void setX(double x) { m_x = x; }        
00082         void setY(double y) { m_y = y; }        
00083         void setZ(double z) { m_z = z; }        
00084         void setXYZ(double x, double y, double z) { m_x = x; m_y = y; m_z = z; } 
00085 
00086         void rotateAroundX(double rollAngle);   
00087         void rotateAroundY(double pitchAngle);  
00088         void rotateAroundZ(double dYawAngle);   
00089 
00090         void normalize();       
00091 
00092         Point3D & operator+= ( const Point3D & point ); 
00093         Point3D & operator-= ( const Point3D & point ); 
00094         Point3D & operator/= ( double divisor );
00095         //\}
00096 
00097 
00099         //\{
00100         double dist( const Point3D& point ) const;              
00101         //\}
00102 
00103 
00105         //\{
00106         static Point3D vectorProduct(const Point3D& v1, const Point3D& v2);     
00107         static Point3D calcIntersectionPointOfVectorWithPlane(const Point3D& PlaneStartpoint,
00108                         const Point3D& PlaneNormal,
00109                         const Point3D& VectorStartpoint,
00110                         const Point3D& VectorDirection);
00111         static double getDistanceBetweenPoints(const Point3D& pt1, const Point3D& pt2); 
00112         //\}
00113 
00114 
00116         //\{
00117 
00119 
00122         std::istream& read (std::istream& is);  // , UINT32 version);   ///< Reads a Point3D from an input stream
00123         void read (const BYTE*& buf);   // , UINT32 version);                   ///< Reads a Point3D from a memory buffer and increments the buffer pointer
00124         std::ostream& write (std::ostream& os) const;   // , UINT32 version) const;     ///< Writes a Point3D to an output stream
00125         void write (BYTE*& buf) const;  //, UINT32 version) const;                      ///< Writes a Point2D to a memory buffer and increments the buffer pointer
00126         std::string toString() const;                                                   
00127 
00128         //\}
00129 
00130         static std::streamsize getSerializedSize();     // UINT32 version);     ///< Returns the number of bytes this object needs in serialized form
00131 
00132         friend inline bool operator==(const Point3D &, const Point3D &);
00133         friend inline bool operator!=(const Point3D &, const Point3D &);
00134         friend inline const Point3D operator+(const Point3D &, const Point3D &);
00135         friend inline const Point3D operator-(const Point3D &, const Point3D &);
00136         friend inline double operator*(const Point3D &, const Point3D &);
00137         friend inline const Point3D operator*(double, const Point3D &);
00138         friend inline const Point3D operator*(const Point3D &, double);
00139         friend inline const Point3D operator-(const Point3D &);
00140         friend inline const Point3D operator/(const Point3D &, double);
00141 };
00142 
00143 std::ostream& operator<<(std::ostream& os, const Point3D& point);       
00144 
00145 // Inline functions
00146 
00147 inline Point3D & Point3D::operator+= ( const Point3D & point )
00148 {
00149         m_x += point.m_x;
00150         m_y += point.m_y;
00151         m_z += point.m_z;
00152         return *this;
00153 }
00154 
00155 inline Point3D & Point3D::operator-= ( const Point3D & point )
00156 {
00157         m_x -= point.m_x;
00158         m_y -= point.m_y;
00159         m_z -= point.m_z;
00160         return *this;
00161 }
00162 
00163 inline Point3D & Point3D::operator/= ( double divisor )
00164 {
00165         assert(!fuzzyCompare(divisor, 0.0));
00166         m_x /= divisor;
00167         m_y /= divisor;
00168         m_z /= divisor;
00169 
00170         return *this;
00171 }
00172 
00173 inline bool operator==(const Point3D &p1, const Point3D &p2)
00174 {
00175         return (fuzzyCompare(p1.m_x, p2.m_x)
00176                         || (isNaN(p1.m_x) && isNaN(p2.m_x)))
00177                    && (fuzzyCompare(p1.m_y, p2.m_y)
00178                            || (isNaN(p1.m_y) && isNaN(p2.m_y)))
00179                    && (fuzzyCompare(p1.m_z, p2.m_z)
00180                            || (isNaN(p1.m_z) && isNaN(p2.m_z)));
00181 }
00182 inline bool operator!=(const Point3D &p1, const Point3D &p2)
00183 {
00184         return ! operator==(p1, p2);
00185 }
00186 
00187 inline const Point3D operator+(const Point3D &p1, const Point3D &p2)
00188 {
00189         return Point3D(p1.m_x + p2.m_x, p1.m_y + p2.m_y, p1.m_z + p2.m_z);
00190 }
00191 
00192 
00193 inline const Point3D operator-(const Point3D &p1, const Point3D &p2)
00194 {
00195         return Point3D(p1.m_x - p2.m_x, p1.m_y - p2.m_y, p1.m_z - p2.m_z);
00196 }
00197 
00198 // wert = v1 * v2
00199 inline double operator*(const Point3D &p1, const Point3D &p2)
00200 {
00201         return ((p1.m_x * p2.m_x) + (p1.m_y * p2.m_y) + (p1.m_z * p2.m_z));
00202 }
00203 
00204 
00205 inline const Point3D operator*(const Point3D &p, double factor)
00206 {
00207         return Point3D(p.m_x * factor, p.m_y * factor, p.m_z * factor);
00208 }
00209 
00210 inline const Point3D operator*(double factor, const Point3D &p)
00211 {
00212         return Point3D(p.m_x * factor, p.m_y * factor, p.m_z * factor);
00213 }
00214 
00215 
00216 inline const Point3D operator-(const Point3D &p)
00217 {
00218         return Point3D(-p.m_x, -p.m_y, -p.m_z);
00219 }
00220 
00221 inline const Point3D operator/(const Point3D &p, double divisor)
00222 {
00223         assert(fuzzyCompare(divisor, 0.0) == false);
00224         return Point3D(p.m_x / divisor, p.m_y / divisor, p.m_z / divisor);
00225 }
00226 
00227 // ////////////////////////////////////////////////////////////
00228 
00229 }       // namespace datatypes
00230 
00231 
00232 #endif
00233 


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Wed Jun 14 2017 04:04:50