point.h

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 3 -*-
00002  *
00003  * Copyright (c), 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 
00044 #ifndef __PPOINTH__
00045 #define __PPOINTH__
00046 
00047 namespace pandore {
00048 
00049    class Dimension1d;
00050    class Dimension2d;
00051    class Dimension3d;
00052    class Point1d;
00053    class Point2d;
00054    class Point3d;
00055 
00056    /* @brief A trait that returns the name of the object Point1d.
00057     *
00058     * TypeName is a trait that returns the name
00059     * of the object Point1d.
00060     */
00061    template<>
00062    struct TypeName< Point1d > {
00063          /*
00064           * Returns the name of the type.
00065           * @return     the string with the name.
00066           */
00067          static std::string Name() { return "Point1d"; }
00068    };
00069 
00070    /* @brief A trait that returns the name of the object Point2d.
00071     *
00072     * TypeName is a trait that returns the name
00073     * of the object Point2d.
00074     */
00075    template<>
00076    struct TypeName< Point2d > {
00081          static std::string Name() { return "Point2d"; }
00082    };
00083 
00084    /* @brief A trait that returns the name of the object Point3d.
00085     *
00086     * TypeName is a trait that returns the name
00087     * of the object Point3d.
00088     */
00089    template<>
00090    struct TypeName< Point3d > {
00095          static std::string Name() { return "Point3d"; }
00096    };
00097 
00111    class Point: public Pobject {
00112       protected:
00113          Point() {}
00114    
00115       public:
00116          ~Point() {}
00117 
00123          Pobject* Mask( const Pobject * /*mask*/ ) {
00124             return this;
00125          }
00126 
00133          Pobject* UnMask( const Pobject * /*mask*/, const Pobject * /*reference*/ ) {
00134             return this;
00135          } 
00136 
00143          Errc LoadAttributes( FILE* /*df*/ ) {
00144             return SUCCESS;
00145          }
00146 
00152          Errc SaveAttributes( FILE* /*df*/ ) const {
00153             return SUCCESS;
00154          }
00155    };
00156 
00172    class Point1d: public Point {
00173       public:
00175          Long x;
00176    
00182          Typobj Type() const { return Po_Point1d; } 
00183    
00188          std::string Name() const { return TypeName< Point1d >::Name(); }
00189   
00194          Point1d(): Point(), x(0) {}
00195 
00201          Point1d( Long x ): Point(), x(x) {}
00202 
00208          Point1d( const Point1d& p ): Point(), x(p.x) {}
00209 
00214          Point1d( const Dimension1d& d ): Point(), x(d.w) {}
00215 
00221          const Point1d& operator=( const Point1d& pt ) {
00222             x = pt.x;
00223             return *this;
00224          }
00225 
00232          bool operator==( const Point1d& pt ) const {
00233             return  pt.x == x;
00234          }
00235 
00241          bool operator!=( const Point1d& pt ) const {
00242             return !(pt == *this);
00243          }
00244 
00250          Point1d& operator+=( const Point1d& pt ) {
00251             x += pt.x;
00252             return *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    
00292          Point1d operator+( const Point1d& pt ) const {
00293             return Point1d(x + pt.x);
00294          }
00295 
00303          Point1d operator-( const Point1d& pt ) const {
00304             return Point1d(x - pt.x);
00305          }
00306 
00314          Point1d operator*( const Point1d& pt ) const {
00315             return Point1d(x * pt.x);
00316          }
00317 
00325          Point1d operator/( const Point1d& pt ) const {
00326             return Point1d(x / pt.x);
00327          }
00328    
00332          Pobject* Clone() const {
00333             return new Point1d(x);
00334          }
00335    
00341          Errc LoadData( FILE *df ) {
00342             if (this->Fdecode(&x, sizeof(x), 1, df) < 1) {
00343                return FAILURE;
00344             }
00345             return SUCCESS;
00346          }
00347   
00353          Errc SaveData( FILE *df ) const {
00354             if (this->Fencode(&x, sizeof(x), 1, df) < 1) {
00355                return FAILURE;
00356             }
00357             return SUCCESS;
00358          }
00359    };
00360 
00376    class Point2d: public Point {
00377       public:
00379          Long x;
00381          Long y;
00382 
00388          Typobj Type() const { return Po_Point2d; } 
00389    
00394          std::string Name() const { return TypeName< Point2d >::Name(); }
00395    
00400          Point2d(): Point(), x(0), y(0) {}
00401 
00407          Point2d( Long i ): Point(), x(i), y(i) {}
00408 
00415          Point2d( Long y, Long x ): Point(), x(x), y(y) {}
00416 
00422          Point2d( const Point2d& p): Point(), x(p.x), y(p.y) {}
00423 
00428          Point2d( const Dimension2d& p): Point(), x(p.w), y(p.h) {}
00429 
00435          const Point2d& operator=( const Point2d& pt ) {
00436             x = pt.x;
00437             y = pt.y;
00438             return *this;
00439          }
00440 
00447          bool operator==( const Point2d& pt ) const {
00448             return  pt.x == x && pt.y == y;
00449          }
00450 
00456          bool operator!=( const Point2d& pt ) const {
00457             return !(pt == *this);
00458          }
00459    
00465          Point2d& operator+=( const Point2d& pt ) {
00466             x += pt.x;
00467             y += pt.y;
00468          return *this;
00469          }
00470 
00476          Point2d& operator-=( const Point2d& pt ) {
00477             x -= pt.x;
00478             y -= pt.y;
00479             return *this;
00480          }
00481 
00487          Point2d& operator/=( const Point2d& pt ) {
00488             x /= pt.x;
00489             y /= pt.y;
00490             return *this;
00491          }
00492 
00498          Point2d& operator*=( const Point2d& pt ) {
00499             x *= pt.x;
00500             y *= pt.y;
00501             return *this;
00502          }
00503 
00511          Point2d operator+( const Point2d& pt ) const {
00512             return Point2d(y + pt.y, x + pt.x);
00513          }
00514    
00522          Point2d operator-( const Point2d& pt ) const {
00523             return Point2d(y - pt.y, x - pt.x);
00524          }
00525    
00533          Point2d operator*( const Point2d& pt ) const {
00534             return Point2d(y * pt.y, x * pt.x);
00535          }
00536 
00544          Point2d operator/( const Point2d& pt ) const {
00545             return Point2d(y / pt.y, x / pt.x);
00546          }
00547 
00551          Pobject* Clone() const {
00552             return new Point2d(y, x);
00553          }
00554 
00560          Errc LoadData( FILE *df ) {
00561             if (Fdecode(&y, sizeof(y), 1, df) < 1) {
00562                return FAILURE;
00563             }
00564             if (Fdecode(&x, sizeof(x), 1, df) < 1) {
00565                return FAILURE;
00566             }
00567             return SUCCESS;
00568          }
00569 
00575          Errc SaveData( FILE *df ) const {
00576             if (this->Fencode(&y, sizeof(y), 1, df) < 1) {
00577                return FAILURE;
00578             }
00579             if (this->Fencode(&x, sizeof(x), 1, df) < 1) {
00580                return FAILURE;
00581             }
00582             return SUCCESS;
00583          }
00584    };
00585 
00601    class Point3d: public Point {
00602       public:
00604          Long z;
00606          Long y;
00608          Long x;
00609 
00615          Typobj Type() const { return Po_Point3d; } 
00616    
00621          std::string Name() const { return TypeName< Point3d >::Name(); }
00622   
00627          Point3d(): Point(), z(0), y(0), x(0) {}
00628 
00634          Point3d( Long i ): Point(), z(i), y(i), x(i) {}
00635 
00643          Point3d( Long z, Long y, Long x ): Point(), z(z), y(y), x(x) {}
00644 
00649          Point3d( const Dimension3d& p): Point(), z(p.d), y(p.h), x(p.w) {}
00650 
00656          Point3d( const Point3d& p): Point(), z(p.z), y(p.y), x(p.x) {}
00657 
00663          Point3d operator=( Point3d pt ) {
00664             x = pt.x;
00665             y = pt.y;
00666             z = pt.z;
00667             return *this; }
00668    
00675          bool operator==( const Point3d& pt ) const {
00676             return pt.x == x && pt.y == y && pt.z == z;
00677          }
00678          
00684          bool operator!=( const Point3d& pt ) const {
00685             return !(pt == *this);
00686          }
00687 
00693          Point3d& operator+=( const Point3d& pt ) {
00694             x += pt.x;
00695             y += pt.y;
00696             z += pt.z;
00697          return *this;
00698          }
00699 
00705          Point3d& operator-=( const Point3d& pt ) {
00706             x -= pt.x;
00707             y -= pt.y;
00708             z -= pt.z;
00709             return *this;
00710          }
00711 
00717          Point3d& operator*=( const Point3d& pt ) {
00718             x *= pt.x;
00719             y *= pt.y;
00720             z *= pt.z;
00721             return *this;
00722          }
00723 
00729          Point3d& operator/=( const Point3d& pt ) {
00730             x /= pt.x;
00731             y /= pt.y;
00732             z /= pt.z;
00733             return *this;
00734          }
00735 
00743          Point3d operator+( const Point3d& pt ) const { 
00744             return Point3d(z + pt.z, y + pt.y, x + pt.x); 
00745          }
00746    
00754          Point3d operator-( const Point3d& pt ) const {
00755             return Point3d(z - pt.z, y - pt.y, x - pt.x);
00756          }
00757    
00765          Point3d operator*( const Point3d& pt ) const {
00766             return Point3d(z * pt.z, y * pt.y, x * pt.x);
00767          }
00768    
00776          Point3d operator/( const Point3d& pt ) const {
00777             return Point3d(z / pt.z, y / pt.y, x / pt.x);
00778          }
00779 
00783          Pobject* Clone() const {
00784             return new Point3d(z, y, x);
00785          }
00786 
00792          Errc LoadData( FILE *df ) {
00793             if (this->Fdecode(&z, sizeof(z), 1, df) < 1) {
00794                return FAILURE;
00795             }
00796             if (this->Fdecode(&y, sizeof(y), 1, df) < 1) {
00797                return FAILURE;
00798             }
00799             if (this->Fdecode(&x, sizeof(x), 1, df) < 1) {
00800                return FAILURE;
00801             }
00802             return SUCCESS;
00803          }
00804 
00810          Errc SaveData( FILE *df ) const {
00811             if (this->Fencode(&z, sizeof(z), 1, df) < 1) {
00812                return FAILURE;
00813             }
00814             if (this->Fencode(&y, sizeof(y), 1, df) < 1) {
00815                return FAILURE;
00816             }
00817             if (this->Fencode(&x, sizeof(x), 1, df) < 1) {
00818                return FAILURE;
00819             }
00820             return SUCCESS;
00821          }
00822    };
00823    
00824 } //End of pandore:: namespace
00825 
00826 #endif // __PPOINTH__

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