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 //-----------------------------------------------------------------------------
39 template<typename TSpace>
41 DGtal::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 //-----------------------------------------------------------------------------
56 template<typename TSpace>
58 DGtal::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 //-----------------------------------------------------------------------------
83 template<typename TSpace>
85 DGtal::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 //-----------------------------------------------------------------------------
94 template<typename TSpace>
96 DGtal::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 //-----------------------------------------------------------------------------
112 template<typename TSpace>
114 DGtal::HyperRectDomain<TSpace>::~HyperRectDomain()
117 //-----------------------------------------------------------------------------
118 template<typename TSpace>
120 DGtal::HyperRectDomain<TSpace> &
121 DGtal::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 //-----------------------------------------------------------------------------
140 template<typename TSpace>
142 const typename DGtal::HyperRectDomain<TSpace>::Point &
143 DGtal::HyperRectDomain<TSpace>::lowerBound() const
148 //-----------------------------------------------------------------------------
149 template<typename TSpace>
152 DGtal::HyperRectDomain<TSpace>::isInside( const Point & p ) const
154 return myPredicate( p );
157 //-----------------------------------------------------------------------------
158 template<typename TSpace>
161 DGtal::HyperRectDomain<TSpace>::isEmpty() const
163 return ! myLowerBound.isLower(myUpperBound);
166 //-----------------------------------------------------------------------------
167 template<typename TSpace>
169 const typename DGtal::HyperRectDomain<TSpace>::Predicate &
170 DGtal::HyperRectDomain<TSpace>::predicate() const
175 //-----------------------------------------------------------------------------
176 template<typename TSpace>
178 const typename DGtal::HyperRectDomain<TSpace>::Point &
179 DGtal::HyperRectDomain<TSpace>::upperBound() const
184 //-----------------------------------------------------------------------------
185 template<typename TSpace>
188 DGtal::HyperRectDomain<TSpace>::selfDisplay ( std::ostream & out ) const
190 out << "[HyperRectDomain] = [" << myLowerBound << "]x["
191 << myUpperBound << "]";
194 //-----------------------------------------------------------------------------
195 template<typename TSpace>
198 DGtal::HyperRectDomain<TSpace>::isValid() const
203 //-----------------------------------------------------------------------------
204 template<typename TSpace>
207 DGtal::HyperRectDomain<TSpace>::className() const
209 return "HyperRectDomain";
212 //-----------------------------------------------------------------------------
213 template<typename TSpace>
216 DGtal::operator<< ( std::ostream & out,
217 const HyperRectDomain<TSpace> & object )
219 object.selfDisplay ( out );
223 ///////////////////////////////////////////////////////////////////////////////