dimension.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 
00053 #ifndef __PDIMENSIONH__
00054 #define __PDIMENSIONH__
00055 
00056 namespace pandore {
00057 
00058    class Dimension1d;
00059    class Dimension2d;
00060    class Dimension3d;
00061 
00062 /* @brief A trait that returns the name of the object Dimension1d.
00063  *
00064  * TypeName is a trait that returns the name
00065  * of the object Dimension1d.
00066  */
00067    template<>
00068    struct TypeName< Dimension1d > {
00069          /*
00070           * Returns the name of the type.
00071           * @return     the string with the name.
00072           */
00073          static ::std::string Name() { return "Dimension1d"; }
00074    };
00075 
00076    /* @brief A trait that returns the name of the object Dimension2d.
00077     *
00078     * TypeName is a trait that returns the name
00079     * of the object Dimension2d.
00080     */
00081    template<>
00082    struct TypeName< Dimension2d > {
00083          /*
00084           * Returns the name of the type.
00085           * @return     the string with the name.
00086           */
00087          static std::string Name() { return "Dimension2d"; }
00088    };
00089 
00090    /* @brief A trait that returns the name of the object Dimension3d.
00091     *
00092     * TypeName is a trait that returns the name
00093     * of the object Dimension3d.
00094     */
00095    template<>
00096    struct TypeName< Dimension3d > {
00097          /*
00098           * Returns the name of the type.
00099           * @return     the string with the name.
00100           */
00101          static std::string Name() { return "Dimension3d"; }
00102    };
00103 
00116    class Dimension: public Pobject {
00117       protected:
00118          Dimension() {}
00119    
00120       public:
00121          ~Dimension() {}
00122 
00128          Pobject* Mask( const Pobject * /*mask*/ ) {
00129             return this;
00130          }
00131 
00138          Pobject* UnMask( const Pobject * /*mask*/, const Pobject * /*reference*/ ) {
00139             return this; 
00140          } 
00141 
00148          Errc LoadAttributes( FILE* /*df*/ ) {
00149             return SUCCESS;
00150          }
00151 
00157          Errc SaveAttributes( FILE* /*df*/ ) const {
00158             return SUCCESS;
00159          }
00160    };
00161 
00176    class Dimension1d: public Dimension {
00177       public:
00179          Long w;
00180 
00186          Typobj Type() const { return Po_Dimension1d; } 
00187    
00192          std::string Name() const { return TypeName< Dimension1d >::Name(); }
00193 
00197          Dimension1d(): Dimension(), w(0) {}
00198    
00203          Dimension1d( Long width ): Dimension(), w(width) {}
00204 
00209          Dimension1d( const Dimension1d& d ): Dimension(), w(d.w) {}
00210 
00216          const Dimension1d& operator=( const Dimension1d& d ) {
00217             w = d.w;
00218             return *this;
00219          }
00220 
00226          bool operator==( const Dimension1d& d ) const {
00227             return d.w == w;
00228          }
00229 
00235          bool operator!=( const Dimension1d& d ) const {
00236             return !(d == *this);
00237          }
00238 
00245          Dimension1d operator+( int x ) const {
00246             return Dimension1d(w + x);
00247          }
00248 
00255          Dimension1d operator-( int x ) const {
00256             return Dimension1d(w - x);
00257          }
00258 
00265          Dimension1d operator*( int x ) const {
00266             return Dimension1d(w * x);
00267          }
00268 
00275          Dimension1d operator/( int x ) const {
00276             return Dimension1d(w / x);
00277          }
00278          
00282          Pobject* Clone() const {
00283             return new Dimension1d(w);
00284          }   
00285 
00291          Errc LoadData( FILE *df ) {
00292             if (this->Fdecode(&w, sizeof(w), 1, df) < 1) {
00293                return FAILURE;
00294             }
00295             return SUCCESS;
00296          }
00297   
00303          Errc SaveData( FILE *df ) const {
00304             if (this->Fencode(&w, sizeof(w), 1, df) < 1) {
00305                return FAILURE;
00306             }
00307             return SUCCESS;
00308          }
00309    };
00310 
00318    inline const Dimension1d operator*( int x, const Dimension1d &d ) {
00319       return Dimension1d(d.w * x);
00320    }
00321    
00336    class Dimension2d: public Dimension {
00337       public:
00339          Long w;
00341          Long h;
00342 
00348          Typobj Type() const { return Po_Dimension2d; } 
00349    
00354          std::string Name() const { return TypeName< Dimension2d >::Name();  }
00355 
00359          Dimension2d(): Dimension(), w(0), h(0) {}
00360 
00366          Dimension2d( Long height, Long width ): Dimension(), w(width), h(height) {}
00367 
00372          Dimension2d( const Dimension2d& d ): Dimension(), w(d.w), h(d.h) {}
00373 
00379          const Dimension2d& operator=( const Dimension2d& d ) {
00380             w = d.w;
00381             h = d.h;
00382 
00383             return *this;
00384          }
00385    
00391          bool operator==( const Dimension2d& d ) const {
00392             return  d.w == w && d.h == h;
00393          }
00394 
00400          bool operator!=( const Dimension2d& d ) const {
00401             return !(d == *this);
00402          }
00403    
00410          Dimension2d operator+( int x ) const {
00411             return Dimension2d(h + x, w + x);
00412          }
00413    
00420          Dimension2d operator-( int x ) const {
00421             return Dimension2d(h - x, w - x);
00422          }
00423 
00430          Dimension2d operator*( int x ) const {
00431             return Dimension2d(h * x, w * x);
00432          }
00433    
00440          Dimension2d operator/( int x ) const {
00441             return Dimension2d(h / x, w / x);
00442          }
00443 
00447          Pobject* Clone() const {
00448             return new Dimension2d(h, w);
00449          }   
00450    
00456          Errc LoadData( FILE *df ) {
00457             if (Fdecode(&h, sizeof(h), 1, df) < 1) {
00458                return FAILURE;
00459             }
00460             if (Fdecode(&w, sizeof(w), 1, df) < 1) {
00461                return FAILURE;
00462             }
00463             return SUCCESS;
00464          }
00465 
00471          Errc SaveData( FILE *df ) const {
00472             if (this->Fencode(&h, sizeof(h), 1, df) < 1) {
00473                return FAILURE;
00474             }
00475             if (this->Fencode(&w, sizeof(w), 1, df) < 1) {
00476                return FAILURE;
00477             }
00478             return SUCCESS;
00479          }
00480    };
00481 
00489    inline const Dimension2d operator*( int x, const Dimension2d &d ) {
00490       return Dimension2d(d.h * x, d.w * x);
00491    }
00492    
00507    class Dimension3d: public Dimension {
00508       public:
00510          Long d;
00512          Long h;
00514          Long w;
00515 
00521          Typobj Type() const { return Po_Dimension3d; } 
00522    
00527          std::string Name() const { return TypeName< Dimension3d >::Name(); }
00528 
00533          Dimension3d(): Dimension(), d(0), h(0), w(0) {}
00534 
00541          Dimension3d( Long depth, Long height, Long width ): Dimension(), d(depth), h(height), w(width) {}
00542 
00547          Dimension3d( const Dimension3d &d ): Dimension(), d(d.d), h(d.h), w(d.w) {}
00548 
00554          Dimension3d operator=( const Dimension3d &x ) {
00555             w = x.w; h = x.h; d = x.d;
00556             return *this;
00557          }
00558    
00564          bool operator==( const Dimension3d &x ) const{
00565             return x.w == w && x.h == h && x.d == d;
00566          }
00567    
00573          bool operator!=( const Dimension3d &x ) const {
00574             return !(x == *this);
00575          }
00576    
00583          Dimension3d operator+( int x ) const {
00584             return Dimension3d(d + x, h + x, w + x);
00585          }
00586    
00593          Dimension3d operator-( int x ) const {
00594             return Dimension3d(d - x, h - x, w - x);
00595          }
00596 
00603          Dimension3d operator*( int x ) const {
00604             return Dimension3d(d * x, h * x, w * x);
00605          }
00606          
00613          Dimension3d operator/( int x ) const {
00614             return Dimension3d(d / x, h / x, w / x);
00615          }
00616 
00620          Pobject* Clone() const {
00621             return new Dimension3d(d, h, w);
00622          }
00623 
00629          Errc LoadData( FILE *df ) {
00630             if (this->Fdecode(&d, sizeof(d), 1, df) < 1) {
00631                return FAILURE;
00632             }
00633             if (this->Fdecode(&h, sizeof(h), 1, df) < 1) {
00634                return FAILURE;
00635             }
00636             if (this->Fdecode(&w, sizeof(w), 1, df) < 1) {
00637                return FAILURE;
00638             }
00639             return SUCCESS;
00640          }
00641 
00647          Errc SaveData( FILE *df ) const {
00648             if (this->Fencode(&d, sizeof(d), 1, df) < 1) {
00649                return FAILURE;
00650             }
00651             if (this->Fencode(&h, sizeof(h), 1, df) < 1) {
00652                return FAILURE;
00653             }
00654             if (this->Fencode(&w, sizeof(w), 1, df) < 1) {
00655                return FAILURE;
00656             }
00657             return SUCCESS;
00658          }
00659    };
00660 
00668    inline const Dimension3d operator*( int x, const Dimension3d &d ) {
00669       return Dimension3d(d.d * x, d.h * x, d.w * x);
00670    }
00671 
00672 } //End of pandore:: namespace
00673 
00674 #endif // __PDIMENSIONH__

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