point.h

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 3 -*-
00002  *
00003  * Copyright (c) 2013, GREYC.
00004  * All rights reserved
00005  *
00006  * You may use this file under the terms of the BSD license as follows:
00007  *
00008  * "Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are
00010  * met:
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above copyright
00014  *     notice, this list of conditions and the following disclaimer in
00015  *     the documentation and/or other materials provided with the
00016  *     distribution.
00017  *   * Neither the name of the GREYC, nor the name of its
00018  *     contributors may be used to endorse or promote products
00019  *     derived from this software without specific prior written
00020  *     permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00026  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
00033  *
00034  *
00035  * For more information, refer to:
00036  * https://clouard.users.greyc.fr/Pandore
00037  */
00038 
00054 #ifndef __PPOINTH__
00055 #define __PPOINTH__
00056 
00057 namespace pandore {
00058 
00059    class Dimension1d;
00060    class Dimension2d;
00061    class Dimension3d;
00062    class Point1d;
00063    class Point2d;
00064    class Point3d;
00065 
00066    /* @brief A trait that returns the name of the object Point1d.
00067     *
00068     * TypeName is a trait that returns the name
00069     * of the object Point1d.
00070     */
00071    template<>
00072    struct TypeName< Point1d > {
00073          /*
00074           * Returns the name of the type.
00075           * @return     the string with the name.
00076           */
00077          static std::string Name() { return "Point1d"; }
00078    };
00079 
00080    /* @brief A trait that returns the name of the object Point2d.
00081     *
00082     * TypeName is a trait that returns the name
00083     * of the object Point2d.
00084     */
00085    template<>
00086    struct TypeName< Point2d > {
00091          static std::string Name() { return "Point2d"; }
00092    };
00093 
00094    /* @brief A trait that returns the name of the object Point3d.
00095     *
00096     * TypeName is a trait that returns the name
00097     * of the object Point3d.
00098     */
00099    template<>
00100    struct TypeName< Point3d > {
00105          static std::string Name() { return "Point3d"; }
00106    };
00107 
00121    class Point: public Pobject {
00122       protected:
00123          Point() {}
00124    
00125       public:
00126          ~Point() {}
00127 
00133          Pobject* Mask( const Pobject * /*mask*/ ) {
00134             return this;
00135          }
00136 
00143          Pobject* UnMask( const Pobject * /*mask*/, const Pobject * /*reference*/ ) {
00144             return this;
00145          } 
00146 
00153          Errc LoadAttributes( FILE* /*df*/ ) {
00154             return SUCCESS;
00155          }
00156 
00162          Errc SaveAttributes( FILE* /*df*/ ) const {
00163             return SUCCESS;
00164          }
00165    };
00166 
00182    class Point1d: public Point {
00183       public:
00185          Long x;
00186    
00192          Typobj Type() const { return Po_Point1d; } 
00193    
00198          std::string Name() const { return TypeName< Point1d >::Name(); }
00199   
00204          Point1d(): Point(), x(0) {}
00205 
00211          Point1d( Long x ): Point(), x(x) {}
00212 
00218          Point1d( const Point1d& p ): Point(), x(p.x) {}
00219 
00224          Point1d( const Dimension1d& d ): Point(), x(d.w) {}
00225 
00231          const Point1d& operator=( const Point1d& pt ) {
00232             x = pt.x;
00233             return *this;
00234          }
00235 
00242          bool operator==( const Point1d& pt ) const {
00243             return  pt.x == x;
00244          }
00245 
00251          bool operator!=( const Point1d& pt ) const {
00252             return !(pt == *this);
00253          }
00254 
00260          Point1d& operator+=( const Point1d& pt ) {
00261             x += pt.x;
00262             return *this;
00263          }
00264 
00270          Point1d& operator-=( const Point1d& pt ) {
00271             x -= pt.x;
00272             return *this;
00273          }
00274 
00280          Point1d& operator*=( const Point1d& pt ) {
00281             x *= pt.x;
00282             return *this;
00283          }
00284 
00290          Point1d& operator/=( const Point1d& pt ) {
00291             x /= pt.x;
00292             return *this;
00293          }
00294    
00302          Point1d operator+( const Point1d& pt ) const {
00303             return Point1d(x + pt.x);
00304          }
00305 
00313          Point1d operator-( const Point1d& pt ) const {
00314             return Point1d(x - pt.x);
00315          }
00316 
00324          Point1d operator*( const Point1d& pt ) const {
00325             return Point1d(x * pt.x);
00326          }
00327 
00335          Point1d operator/( const Point1d& pt ) const {
00336             return Point1d(x / pt.x);
00337          }
00338    
00342          Pobject* Clone() const {
00343             return new Point1d(x);
00344          }
00345    
00351          Errc LoadData( FILE *df ) {
00352             if (this->Fdecode(&x, sizeof(x), 1, df) < 1) {
00353                return FAILURE;
00354             }
00355             return SUCCESS;
00356          }
00357   
00363          Errc SaveData( FILE *df ) const {
00364             if (this->Fencode(&x, sizeof(x), 1, df) < 1) {
00365                return FAILURE;
00366             }
00367             return SUCCESS;
00368          }
00369    };
00370 
00386    class Point2d: public Point {
00387       public:
00389          Long x;
00391          Long y;
00392 
00398          Typobj Type() const { return Po_Point2d; } 
00399    
00404          std::string Name() const { return TypeName< Point2d >::Name(); }
00405    
00410          Point2d(): Point(), x(0), y(0) {}
00411 
00417          Point2d( Long i ): Point(), x(i), y(i) {}
00418 
00425          Point2d( Long y, Long x ): Point(), x(x), y(y) {}
00426 
00432          Point2d( const Point2d& p): Point(), x(p.x), y(p.y) {}
00433 
00438          Point2d( const Dimension2d& p): Point(), x(p.w), y(p.h) {}
00439 
00445          const Point2d& operator=( const Point2d& pt ) {
00446             x = pt.x;
00447             y = pt.y;
00448             return *this;
00449          }
00450 
00457          bool operator==( const Point2d& pt ) const {
00458             return  pt.x == x && pt.y == y;
00459          }
00460 
00466          bool operator!=( const Point2d& pt ) const {
00467             return !(pt == *this);
00468          }
00469    
00475          Point2d& operator+=( const Point2d& pt ) {
00476             x += pt.x;
00477             y += pt.y;
00478          return *this;
00479          }
00480 
00486          Point2d& operator-=( const Point2d& pt ) {
00487             x -= pt.x;
00488             y -= pt.y;
00489             return *this;
00490          }
00491 
00497          Point2d& operator/=( const Point2d& pt ) {
00498             x /= pt.x;
00499             y /= pt.y;
00500             return *this;
00501          }
00502 
00508          Point2d& operator*=( const Point2d& pt ) {
00509             x *= pt.x;
00510             y *= pt.y;
00511             return *this;
00512          }
00513 
00521          Point2d operator+( const Point2d& pt ) const {
00522             return Point2d(y + pt.y, x + pt.x);
00523          }
00524    
00532          Point2d operator-( const Point2d& pt ) const {
00533             return Point2d(y - pt.y, x - pt.x);
00534          }
00535    
00543          Point2d operator*( const Point2d& pt ) const {
00544             return Point2d(y * pt.y, x * pt.x);
00545          }
00546 
00554          Point2d operator/( const Point2d& pt ) const {
00555             return Point2d(y / pt.y, x / pt.x);
00556          }
00557 
00561          Pobject* Clone() const {
00562             return new Point2d(y, x);
00563          }
00564 
00570          Errc LoadData( FILE *df ) {
00571             if (Fdecode(&y, sizeof(y), 1, df) < 1) {
00572                return FAILURE;
00573             }
00574             if (Fdecode(&x, sizeof(x), 1, df) < 1) {
00575                return FAILURE;
00576             }
00577             return SUCCESS;
00578          }
00579 
00585          Errc SaveData( FILE *df ) const {
00586             if (this->Fencode(&y, sizeof(y), 1, df) < 1) {
00587                return FAILURE;
00588             }
00589             if (this->Fencode(&x, sizeof(x), 1, df) < 1) {
00590                return FAILURE;
00591             }
00592             return SUCCESS;
00593          }
00594    };
00595 
00611    class Point3d: public Point {
00612       public:
00614          Long z;
00616          Long y;
00618          Long x;
00619 
00625          Typobj Type() const { return Po_Point3d; } 
00626    
00631          std::string Name() const { return TypeName< Point3d >::Name(); }
00632   
00637          Point3d(): Point(), z(0), y(0), x(0) {}
00638 
00644          Point3d( Long i ): Point(), z(i), y(i), x(i) {}
00645 
00653          Point3d( Long z, Long y, Long x ): Point(), z(z), y(y), x(x) {}
00654 
00659          Point3d( const Dimension3d& p): Point(), z(p.d), y(p.h), x(p.w) {}
00660 
00666          Point3d( const Point3d& p): Point(), z(p.z), y(p.y), x(p.x) {}
00667 
00673          Point3d operator=( Point3d pt ) {
00674             x = pt.x;
00675             y = pt.y;
00676             z = pt.z;
00677             return *this; }
00678    
00685          bool operator==( const Point3d& pt ) const {
00686             return pt.x == x && pt.y == y && pt.z == z;
00687          }
00688          
00694          bool operator!=( const Point3d& pt ) const {
00695             return !(pt == *this);
00696          }
00697 
00703          Point3d& operator+=( const Point3d& pt ) {
00704             x += pt.x;
00705             y += pt.y;
00706             z += pt.z;
00707          return *this;
00708          }
00709 
00715          Point3d& operator-=( const Point3d& pt ) {
00716             x -= pt.x;
00717             y -= pt.y;
00718             z -= pt.z;
00719             return *this;
00720          }
00721 
00727          Point3d& operator*=( const Point3d& pt ) {
00728             x *= pt.x;
00729             y *= pt.y;
00730             z *= pt.z;
00731             return *this;
00732          }
00733 
00739          Point3d& operator/=( const Point3d& pt ) {
00740             x /= pt.x;
00741             y /= pt.y;
00742             z /= pt.z;
00743             return *this;
00744          }
00745 
00753          Point3d operator+( const Point3d& pt ) const { 
00754             return Point3d(z + pt.z, y + pt.y, x + pt.x); 
00755          }
00756    
00764          Point3d operator-( const Point3d& pt ) const {
00765             return Point3d(z - pt.z, y - pt.y, x - pt.x);
00766          }
00767    
00775          Point3d operator*( const Point3d& pt ) const {
00776             return Point3d(z * pt.z, y * pt.y, x * pt.x);
00777          }
00778    
00786          Point3d operator/( const Point3d& pt ) const {
00787             return Point3d(z / pt.z, y / pt.y, x / pt.x);
00788          }
00789 
00793          Pobject* Clone() const {
00794             return new Point3d(z, y, x);
00795          }
00796 
00802          Errc LoadData( FILE *df ) {
00803             if (this->Fdecode(&z, sizeof(z), 1, df) < 1) {
00804                return FAILURE;
00805             }
00806             if (this->Fdecode(&y, sizeof(y), 1, df) < 1) {
00807                return FAILURE;
00808             }
00809             if (this->Fdecode(&x, sizeof(x), 1, df) < 1) {
00810                return FAILURE;
00811             }
00812             return SUCCESS;
00813          }
00814 
00820          Errc SaveData( FILE *df ) const {
00821             if (this->Fencode(&z, sizeof(z), 1, df) < 1) {
00822                return FAILURE;
00823             }
00824             if (this->Fencode(&y, sizeof(y), 1, df) < 1) {
00825                return FAILURE;
00826             }
00827             if (this->Fencode(&x, sizeof(x), 1, df) < 1) {
00828                return FAILURE;
00829             }
00830             return SUCCESS;
00831          }
00832    };
00833    
00834 } //End of pandore:: namespace
00835 
00836 #endif // __PPOINTH__

The Pantheon project
Image Team GREYC Laboratory
UMR CNRS 6072 - ENSICAEN - University of Caen, France
This page was last modified on