DGtal 0.3.0

HyperRectDomain.h

Go to the documentation of this file.
00001 
00017 #pragma once
00018 
00032 #if defined(HyperRectDomain_RECURSES)
00033 #error Recursive header files inclusion detected in HyperRectDomain.h
00034 #else // defined(HyperRectDomain_RECURSES)
00035 
00036 #define HyperRectDomain_RECURSES
00037 
00038 #if !defined HyperRectDomain_h
00039 
00040 #define HyperRectDomain_h
00041 
00043 // Inclusions
00044 #include <iostream>
00045 #ifdef WITH_VISU3D_QGLVIEWER
00046 #include "DGtal/3dViewer/DGtalQGLViewer.h"
00047 #endif
00048 
00049 #include "DGtal/base/Common.h"
00050 #include "DGtal/kernel/CSpace.h"
00051 #include "DGtal/kernel/BasicPointPredicates.h"
00052 #include "DGtal/kernel/domains/CDomain.h"
00053 #include "DGtal/kernel/domains/HyperRectDomain_Iterator.h"
00054 #include "DGtal/kernel/IntegerTraits.h"
00055 #include "DGtal/io/DGtalBoard.h"
00056 
00057 
00058 
00059 
00060 
00061 
00062 namespace DGtal
00063 {
00065   // class HyperRectDomain
00099   template<typename TSpace>
00100   class HyperRectDomain
00101   {
00102     // ----------------------- Standard services ------------------------------
00103   public:
00104 
00105     BOOST_CONCEPT_ASSERT(( CSpace<TSpace> ));
00106 
00107 
00108     // typedef TSpace DigitalSpace;
00109     // typedef TSpace Space;
00110     typedef TSpace Space;
00111 
00112     // static constants
00113     static const typename Space::Dimension dimension = Space::dimension;
00114 
00115     typedef HyperRectDomain<Space> Domain;
00116     typedef typename Space::Point Point;
00117     typedef typename Space::Integer Integer;
00118     typedef typename Space::Vector Vector;
00119     typedef typename Space::Dimension Dimension;
00120     typedef typename Space::Size Size;
00121     typedef typename Point::Coordinate Coordinate; // TODO REVOIR LES NOMS.... RECUPERER DANS SPACE
00122 
00124     typedef typename IntegerTraits<Integer>::IsBounded IsBounded;
00125 
00127     typedef HyperRectDomain_Iterator<Point> ConstIterator;
00128     typedef myreverse_iterator<ConstIterator> ReverseConstIterator;
00129   
00130     typedef IsWithinPointPredicate<Point> Predicate;
00131 
00135     HyperRectDomain();
00136 
00142     HyperRectDomain ( const Point &aPointA, const Point &aPointB );
00143 
00144 
00148     ~HyperRectDomain();
00149 
00155     HyperRectDomain ( const HyperRectDomain & other );
00156 
00157 
00164     HyperRectDomain & operator= ( const HyperRectDomain & other );
00165 
00173     struct ConstRange 
00174     {
00175       typedef typename Domain::ConstIterator        ConstIterator;
00176       typedef typename Domain::ReverseConstIterator ReverseConstIterator;
00177 
00182       ConstRange(const HyperRectDomain<TSpace>& domain)
00183         : myDomain(domain),
00184           myIteratorBegin(domain.myLowerBound,
00185                           domain.myLowerBound,
00186                           domain.myUpperBound),
00187           myIteratorEnd(domain.myUpperBound,
00188                         domain.myLowerBound,
00189                         domain.myUpperBound)
00190       { ++myIteratorEnd; }
00191 
00192       /*
00193        * begin method.
00194        * @return ConstIterator on the beginning of the range.
00195        */
00196       const ConstIterator& begin() const
00197       { return myIteratorBegin; }
00198 
00199       /*
00200        * begin method from a given point.
00201        * @param aPoint the initial point.
00202        * @return a ConstIterator initialized to aPoint.
00203        * @pre aPoint must belong to the range.
00204        */
00205       ConstIterator begin(const Point& aPoint) const
00206       { ASSERT(myDomain.isInside(aPoint));
00207         return ConstIterator(aPoint, 
00208                               myDomain.myLowerBound, myDomain.myUpperBound); }
00209 
00210       /*
00211        * end method.
00212        * @return ConstIterator on the end of the range.
00213        */
00214       const ConstIterator& end() const
00215       { return myIteratorEnd; }
00216 
00217       /*
00218        * reverse begin method.
00219        * @return ConstIterator on the beginning of the reverse range.
00220        */
00221       ReverseConstIterator rbegin() const
00222       { return ReverseConstIterator(end()); }
00223 
00224       /*
00225        * reverse begin method from a given point.
00226        * @param aPoint the initial point.
00227        * @return a ConstIterator initialized to aPoint.
00228        * @pre aPoint must belong to the range.
00229        */
00230       ReverseConstIterator rbegin(const Point& aPoint) const
00231       {  ASSERT(myDomain.isInside(aPoint));
00232         ConstIterator it(begin(aPoint)); ++it;
00233         return ReverseConstIterator(it); }
00234 
00235       /*
00236        * reverse end method.
00237        * @return ConstIterator on the end of the reverse range.
00238        */
00239       ReverseConstIterator rend() const
00240       { return ReverseConstIterator(begin()); }
00241 
00242     private:
00244       const HyperRectDomain<TSpace>& myDomain;
00246       ConstIterator myIteratorBegin;
00248       ConstIterator myIteratorEnd;
00249     };
00250 
00252     const ConstRange& range() const
00253     { return myRange; }
00254 
00256     const ConstIterator& begin() const
00257     { return myRange.begin(); }
00258 
00260     const ConstIterator& end() const
00261     { return myRange.end(); }
00262 
00271     struct ConstSubRange 
00272     {
00273       typedef HyperRectDomain_subIterator<Point> ConstIterator;
00274       typedef myreverse_iterator<ConstIterator> ReverseConstIterator;
00275 
00284       ConstSubRange(const HyperRectDomain<TSpace>& domain,
00285                     const std::vector<Dimension> & permutation,
00286                     const Point & startingPoint)
00287         : myLowerBound(domain.myLowerBound),
00288           myUpperBound(domain.myUpperBound),
00289           myStartingPoint(startingPoint)
00290       {
00291         myPermutation.reserve( permutation.size() );
00292         std::copy(permutation.begin(),permutation.end(),
00293                  std::back_inserter(myPermutation));
00294         myLowerBound.partialCopyInv(myStartingPoint, myPermutation);
00295         myUpperBound.partialCopyInv(myStartingPoint, myPermutation);
00296       }
00297 
00298 #ifdef CPP0X_INITIALIZER_LIST
00299 
00307       ConstSubRange(const HyperRectDomain<TSpace>& domain,
00308                     std::initializer_list<Dimension> permutation,
00309                     const Point & startingPoint)
00310         : myLowerBound(domain.myLowerBound),
00311           myUpperBound(domain.myUpperBound),
00312           myStartingPoint(startingPoint)
00313       {
00314         myPermutation.reserve( permutation.size() );
00315         for ( const unsigned int *c = permutation.begin();
00316             c != permutation.end(); ++c )
00317           {
00318             myPermutation.push_back( *c );
00319           }
00320         myLowerBound.partialCopyInv(myStartingPoint, myPermutation);
00321         myUpperBound.partialCopyInv(myStartingPoint, myPermutation);
00322       }
00323 #endif
00324 
00332        ConstSubRange(const HyperRectDomain<TSpace>& domain,
00333                     Dimension adim,
00334                     const Point & startingPoint)
00335         : myLowerBound(domain.myLowerBound),
00336           myUpperBound(domain.myUpperBound),
00337           myStartingPoint(startingPoint)
00338       {
00339         myPermutation.push_back( adim );
00340         myLowerBound.partialCopyInv(myStartingPoint, myPermutation);
00341         myUpperBound.partialCopyInv(myStartingPoint, myPermutation);
00342       }
00343       
00352       ConstSubRange(const HyperRectDomain<TSpace>& domain,
00353                     Dimension adim1, Dimension adim2,
00354                     const Point & startingPoint)
00355         : myLowerBound(domain.myLowerBound),
00356           myUpperBound(domain.myUpperBound),
00357           myStartingPoint(startingPoint)
00358       {
00359         myPermutation.push_back( adim1 );
00360         myPermutation.push_back( adim2 );
00361         myLowerBound.partialCopyInv(myStartingPoint, myPermutation);
00362         myUpperBound.partialCopyInv(myStartingPoint, myPermutation);
00363       }
00364       
00374       ConstSubRange(const HyperRectDomain<TSpace>& domain,
00375                     Dimension adim1, Dimension adim2, Dimension adim3,
00376                     const Point & startingPoint)
00377         : myLowerBound(domain.myLowerBound),
00378           myUpperBound(domain.myUpperBound),
00379           myStartingPoint(startingPoint)
00380       {
00381         myPermutation.push_back( adim1 );
00382         myPermutation.push_back( adim2 );
00383         myPermutation.push_back( adim3 );
00384         myLowerBound.partialCopyInv(myStartingPoint, myPermutation);
00385         myUpperBound.partialCopyInv(myStartingPoint, myPermutation);
00386       }
00387       
00388       /*
00389        * begin method.
00390        * @return ConstIterator on the beginning of the range.
00391        */
00392       ConstIterator begin() const
00393       { return ConstIterator(myLowerBound, myLowerBound,
00394                               myUpperBound, myPermutation); }
00395       
00396       /*
00397        * begin method from a given point.
00398        * @param aPoint the initial point.
00399        * @return a ConstIterator initialized to aPoint.
00400        * @pre aPoint must belong to the range.
00401        */
00402       ConstIterator begin(const Point& aPoint) const
00403       { 
00404         ASSERT(aPoint.partialEqualInv(myLowerBound, myPermutation) );
00405         ASSERT(myLowerBound<=aPoint && aPoint<=myUpperBound);
00406         return ConstIterator(aPoint, myLowerBound,
00407                               myUpperBound, myPermutation);
00408       }
00409 
00410       /*
00411        * end method.
00412        * @return ConstIterator on the end of the range.
00413        */
00414       ConstIterator end() const
00415       {
00416         ConstIterator it = ConstIterator(myUpperBound, myLowerBound,
00417                                            myUpperBound, myPermutation);
00418         ++it;
00419         return it;
00420       }
00421 
00422       /*
00423        * reverse begin method.
00424        * @return ConstIterator on the beginning of the reverse range.
00425        */
00426       ReverseConstIterator rbegin() const
00427       { return ReverseConstIterator(end()); }
00428 
00429       /*
00430        * reverse begin method from a given point.
00431        * @param aPoint the initial point.
00432        * @return a ConstIterator initialized to aPoint.
00433        * @pre aPoint must belong to the range.
00434        */
00435       ReverseConstIterator rbegin(const Point& aPoint) const
00436       { ConstIterator it(begin(aPoint)); ++it;
00437         return ReverseConstIterator(it); }
00438 
00439       /*
00440        * reverse end method.
00441        * @return ConstIterator on the end of the reverse range.
00442        */
00443       ReverseConstIterator rend() const
00444       { return ReverseConstIterator(begin()); }
00445 
00446     private:
00448       Point                  myLowerBound;
00450       Point                  myUpperBound;
00452       Point                  myStartingPoint;
00454       std::vector<Dimension> myPermutation;
00455    };
00456 
00463     ConstSubRange subRange(const std::vector<Dimension> & permutation) const
00464     { return ConstSubRange(*this, permutation, myLowerBound); }
00465 
00474     ConstSubRange subRange(const std::vector<Dimension> & permutation,
00475                            const Point & startingPoint) const
00476     { return ConstSubRange(*this, permutation, startingPoint); }
00477     
00485     ConstSubRange subRange(Dimension adim,
00486                            const Point & startingPoint) const
00487     { return ConstSubRange(*this, adim, startingPoint); }
00488     
00497     ConstSubRange subRange(Dimension adim1, Dimension adim2,
00498                            const Point & startingPoint) const
00499     { return ConstSubRange(*this, adim1, adim2, startingPoint); }
00500     
00510     ConstSubRange subRange(Dimension adim1, Dimension adim2, Dimension adim3,
00511                            const Point & startingPoint) const
00512     { return ConstSubRange(*this, adim1, adim2, adim3, startingPoint); }
00513     
00514 #ifdef CPP0X_INITIALIZER_LIST
00515 
00521     ConstSubRange subRange(std::initializer_list<Dimension> permutation)
00522     { return ConstSubRange(*this, permutation, myLowerBound); }
00523 
00532     ConstSubRange subRange(std::initializer_list<Dimension> permutation,
00533                            const Point & startingPoint)
00534     { return ConstSubRange(*this, permutation, startingPoint); }
00535 #endif
00536     
00537     // ----------------------- Interface --------------------------------------
00538   public:
00543     Point size() const
00544     {
00545       Point p;
00546       for(typename Point::Iterator it=p.begin(), itend=p.end();
00547       it != itend; ++it)
00548         (*it) = 1;
00549 
00550       return (myUpperBound - myLowerBound) + p;
00551     }
00552 
00557     const Point &lowerBound() const;
00558 
00563     const Point &upperBound() const ;
00564 
00569     bool isInside( const Point & p ) const;
00570 
00578     const Predicate & predicate() const;
00579 
00580 
00581     // ------------------------- Private Datas --------------------------------
00582   private:
00583 
00587     struct DefaultDrawStylePaving : public DrawableWithDGtalBoard
00588     {
00589       virtual void selfDraw(DGtalBoard & aBoard) const
00590       {
00591         aBoard.setPenColorRGBi(160, 160, 160);
00592         aBoard.setFillColorRGBi(255, 255, 255);
00593         aBoard.setLineStyle(DGtalBoard::Shape::SolidStyle);
00594       }
00595     };
00596 
00600     struct DefaultDrawStyleGrid : public DrawableWithDGtalBoard
00601     {
00602       virtual void selfDraw(DGtalBoard & aBoard) const
00603       {
00604         aBoard.setPenColorRGBi(160, 160, 160);
00605         aBoard.setFillColorRGBi(160, 160, 160);
00606         aBoard.setLineStyle(DGtalBoard::Shape::DashStyle);
00607       }
00608     };
00609 
00610     // --------------- CDrawableWithDGtalBoard realization --------------------
00611   public:
00612     
00617     DrawableWithDGtalBoard* defaultStyle( std::string mode = "" ) const;
00618     
00622     std::string styleName() const;
00623 
00628     void selfDraw( DGtalBoard & board ) const;
00629 
00630 
00636     void selfDrawAsGrid( DGtalBoard & board) const;
00637 
00638     
00644     void selfDrawAsPaving( DGtalBoard & board ) const;
00645     
00646 
00647 
00648 
00649 #ifdef WITH_VISU3D_QGLVIEWER
00650 
00655     DrawableWithDGtalQGLViewer* defaultStyleQGL( std::string mode = "" ) const;
00656 
00661     void selfDrawQGL(  DGtalQGLViewer & viewer ) const;
00662     void selfDrawAsGridQGL( DGtalQGLViewer & viewer  ) const;
00663     void selfDrawAsPavingQGL( DGtalQGLViewer & viewer ) const;
00664     void selfDrawAsPavingPointsQGL( DGtalQGLViewer & viewer ) const;
00665     void selfDrawAsBoundingBox ( DGtalQGLViewer & viewer) const;
00666 
00667 #endif
00668 
00669 
00670     
00675     void selfDisplay ( std::ostream & out ) const;
00676     
00681     bool isValid() const;
00682     
00683     
00684     
00685     // ------------------------- Hidden services ------------------------------
00686   private:
00688     Point myLowerBound;
00690     Point myUpperBound;
00691 
00693     Predicate myPredicate;
00694 
00696     ConstRange myRange;
00697   }; // end of class HyperRectDomain
00698 
00699 
00700 
00701 
00702 
00708 #ifdef WITH_VISU3D_QGLVIEWER
00709 
00710   struct DrawPavingVoxel3D : public DrawableWithDGtalQGLViewer {
00711       void selfDrawQGL( DGtalQGLViewer & viewer ) const
00712       {
00713         viewer.myModes[ "HyperRectDomain" ] = "Paving";
00714       }
00715   };
00716   
00717   
00718   struct DrawGridVoxel3D : public DrawableWithDGtalQGLViewer {
00719     void selfDrawQGL( DGtalQGLViewer & viewer ) const
00720     {
00721       viewer.myModes[ "HyperRectDomain" ] = "Grid";
00722     }
00723   };
00724 
00725 
00726 
00727 #endif
00728 
00729 
00736   template<typename TSpace>
00737   std::ostream&
00738       operator<< ( std::ostream& out, const HyperRectDomain<TSpace> & object );
00739 
00740 
00745   struct DrawDomainGrid : public DrawWithBoardModifier {
00746     void selfDraw( DGtalBoard & board ) const
00747     {
00748       board.myModes[ "HyperRectDomain" ] = "Grid";
00749     }
00750   };
00751 
00756   struct DrawDomainPaving : public DrawWithBoardModifier {
00757     void selfDraw( DGtalBoard & board ) const
00758     {
00759       board.myModes[ "HyperRectDomain" ] = "Paving";
00760     }
00761   };
00762   
00763 
00764 } // namespace DGtal
00765 
00766 
00768 // Includes inline functions.
00769 #include "DGtal/kernel/domains/HyperRectDomain.ih"
00770 
00771 //                                                                           //
00773 
00774 #endif // !defined HyperRectDomain_h
00775 
00776 #undef HyperRectDomain_RECURSES
00777 #endif // else defined(HyperRectDomain_RECURSES)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines