2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file HyperRectDomain.ih
19 * @author David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr )
20 * @author Guillaume Damiand
21 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
25 * Implementation of inline methods defined in HyperRectDomain.h
27 * This file is part of the DGtal library.
30///////////////////////////////////////////////////////////////////////////////
31// IMPLEMENTATION of inline methods.
32///////////////////////////////////////////////////////////////////////////////
34//////////////////////////////////////////////////////////////////////////////
36#include "DGtal/io/Color.h"
38//-----------------------------------------------------------------------------
39template<typename TSpace>
41DGtal::HyperRectDomain<TSpace>::HyperRectDomain()
42 : myLowerBound(Point::zero),
43 myUpperBound(Point::zero - Point::diagonal(1)), // So that it gives an empty domain.
44 myPredicate( myLowerBound, myUpperBound ),
45 myIteratorBegin(myLowerBound,
48 myIteratorEnd(myUpperBound,
55//-----------------------------------------------------------------------------
56template<typename TSpace>
58DGtal::HyperRectDomain<TSpace>::HyperRectDomain ( const Point &lowerPoint,
59 const Point &upperPoint ) :
60 myLowerBound(lowerPoint),
61 myUpperBound(upperPoint),
62 myPredicate( myLowerBound, myUpperBound ),
63 myIteratorBegin(myLowerBound,
66 myIteratorEnd(myUpperBound,
70 ASSERT_MSG( // For an empty domain, lower = upper + diag(1) so that begin() == end().
71 myLowerBound.isLower(myUpperBound) || myLowerBound == myUpperBound + Point::diagonal(1),
72 "The lower bound must be lower than the upper bound or, for an empty domain, be equal to the upper bound + diagonal(1)."
74 ASSERT_MSG( // Check that begin() == end() for empty domains.
75 ConstIterator(myUpperBound+Point::diagonal(1), myUpperBound+Point::diagonal(1), myUpperBound) == ++ConstIterator(myUpperBound, myUpperBound+Point::diagonal(1), myUpperBound),
76 "ConstIterator is not compatible with the definition of an empty domain."
82//-----------------------------------------------------------------------------
83template<typename TSpace>
85DGtal::HyperRectDomain<TSpace>::HyperRectDomain (
86 const typename Space::RealPoint &lowerPoint,
87 const typename Space::RealPoint &upperPoint ) :
88 HyperRectDomain( Point(lowerPoint, functors::Floor<>()),
89 Point(upperPoint, functors::Ceil<>()) )
93//-----------------------------------------------------------------------------
94template<typename TSpace>
96DGtal::HyperRectDomain<TSpace>
97::HyperRectDomain( const typename DGtal::HyperRectDomain<TSpace> &aDomain) :
98 myLowerBound(aDomain.lowerBound()),
99 myUpperBound(aDomain.upperBound()),
100 myPredicate( myLowerBound, myUpperBound ),
101 myIteratorBegin(myLowerBound,
104 myIteratorEnd(myUpperBound,
111//-----------------------------------------------------------------------------
112template<typename TSpace>
114DGtal::HyperRectDomain<TSpace>::~HyperRectDomain()
117//-----------------------------------------------------------------------------
118template<typename TSpace>
120DGtal::HyperRectDomain<TSpace> &
121DGtal::HyperRectDomain<TSpace>
122::operator= ( const typename DGtal::HyperRectDomain<TSpace> & other )
124 if ( this != &other )
126 myLowerBound = other.myLowerBound;
127 myUpperBound = other.myUpperBound;
128 myPredicate = other.myPredicate;
129 new(&myIteratorBegin) ConstIterator(myLowerBound,myLowerBound,myUpperBound);
130 new(&myIteratorEnd) ConstIterator(myUpperBound,myLowerBound,myUpperBound);
136//-----------------------------------------------------------------------------
139//-----------------------------------------------------------------------------
140template<typename TSpace>
142const typename DGtal::HyperRectDomain<TSpace>::Point &
143DGtal::HyperRectDomain<TSpace>::lowerBound() const
148//-----------------------------------------------------------------------------
149template<typename TSpace>
152DGtal::HyperRectDomain<TSpace>::isInside( const Point & p ) const
154 return myPredicate( p );
157//-----------------------------------------------------------------------------
158template<typename TSpace>
161DGtal::HyperRectDomain<TSpace>::isEmpty() const
163 return ! myLowerBound.isLower(myUpperBound);
166//-----------------------------------------------------------------------------
167template<typename TSpace>
169const typename DGtal::HyperRectDomain<TSpace>::Predicate &
170DGtal::HyperRectDomain<TSpace>::predicate() const
175//-----------------------------------------------------------------------------
176template<typename TSpace>
178const typename DGtal::HyperRectDomain<TSpace>::Point &
179DGtal::HyperRectDomain<TSpace>::upperBound() const
184//-----------------------------------------------------------------------------
185template<typename TSpace>
188DGtal::HyperRectDomain<TSpace>::selfDisplay ( std::ostream & out ) const
190 out << "[HyperRectDomain] = [" << myLowerBound << "]x["
191 << myUpperBound << "]";
194//-----------------------------------------------------------------------------
195template<typename TSpace>
198DGtal::HyperRectDomain<TSpace>::isValid() const
203//-----------------------------------------------------------------------------
204template<typename TSpace>
207DGtal::HyperRectDomain<TSpace>::className() const
209 return "HyperRectDomain";
212//-----------------------------------------------------------------------------
213template<typename TSpace>
216DGtal::operator<< ( std::ostream & out,
217 const HyperRectDomain<TSpace> & object )
219 object.selfDisplay ( out );
223///////////////////////////////////////////////////////////////////////////////