DGtal 1.3.0
Loading...
Searching...
No Matches
HyperRectDomain.ih
1/**
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.
6 *
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.
11 *
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/>.
14 *
15 **/
16
17/**
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
22 *
23 * @date 2010/05/25
24 *
25 * Implementation of inline methods defined in HyperRectDomain.h
26 *
27 * This file is part of the DGtal library.
28 */
29
30///////////////////////////////////////////////////////////////////////////////
31// IMPLEMENTATION of inline methods.
32///////////////////////////////////////////////////////////////////////////////
33
34//////////////////////////////////////////////////////////////////////////////
35#include <cstdlib>
36#include "DGtal/io/Color.h"
37
38//-----------------------------------------------------------------------------
39template<typename TSpace>
40inline
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,
46 myLowerBound,
47 myUpperBound),
48 myIteratorEnd(myUpperBound,
49 myLowerBound,
50 myUpperBound)
51{
52 ++myIteratorEnd;
53}
54
55//-----------------------------------------------------------------------------
56template<typename TSpace>
57inline
58DGtal::HyperRectDomain<TSpace>::HyperRectDomain ( const Point &lowerPoint,
59 const Point &upperPoint ) :
60 myLowerBound(lowerPoint),
61 myUpperBound(upperPoint),
62 myPredicate( myLowerBound, myUpperBound ),
63 myIteratorBegin(myLowerBound,
64 myLowerBound,
65 myUpperBound),
66 myIteratorEnd(myUpperBound,
67 myLowerBound,
68 myUpperBound)
69{
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)."
73 );
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."
77 );
78
79 ++myIteratorEnd;
80}
81
82//-----------------------------------------------------------------------------
83template<typename TSpace>
84inline
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<>()) )
90{
91}
92
93//-----------------------------------------------------------------------------
94template<typename TSpace>
95inline
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,
102 myLowerBound,
103 myUpperBound),
104 myIteratorEnd(myUpperBound,
105 myLowerBound,
106 myUpperBound)
107{
108 ++myIteratorEnd;
109}
110
111//-----------------------------------------------------------------------------
112template<typename TSpace>
113inline
114DGtal::HyperRectDomain<TSpace>::~HyperRectDomain()
115{}
116
117//-----------------------------------------------------------------------------
118template<typename TSpace>
119inline
120DGtal::HyperRectDomain<TSpace> &
121DGtal::HyperRectDomain<TSpace>
122::operator= ( const typename DGtal::HyperRectDomain<TSpace> & other )
123{
124 if ( this != &other )
125 {
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);
131 ++myIteratorEnd;
132 }
133 return *this;
134}
135
136//-----------------------------------------------------------------------------
137
138
139//-----------------------------------------------------------------------------
140template<typename TSpace>
141inline
142const typename DGtal::HyperRectDomain<TSpace>::Point &
143DGtal::HyperRectDomain<TSpace>::lowerBound() const
144{
145 return myLowerBound;
146}
147
148//-----------------------------------------------------------------------------
149template<typename TSpace>
150inline
151bool
152DGtal::HyperRectDomain<TSpace>::isInside( const Point & p ) const
153{
154 return myPredicate( p );
155}
156
157//-----------------------------------------------------------------------------
158template<typename TSpace>
159inline
160bool
161DGtal::HyperRectDomain<TSpace>::isEmpty() const
162{
163 return ! myLowerBound.isLower(myUpperBound);
164}
165
166//-----------------------------------------------------------------------------
167template<typename TSpace>
168inline
169const typename DGtal::HyperRectDomain<TSpace>::Predicate &
170DGtal::HyperRectDomain<TSpace>::predicate() const
171{
172 return myPredicate;
173}
174
175//-----------------------------------------------------------------------------
176template<typename TSpace>
177inline
178const typename DGtal::HyperRectDomain<TSpace>::Point &
179DGtal::HyperRectDomain<TSpace>::upperBound() const
180{
181 return myUpperBound;
182}
183
184//-----------------------------------------------------------------------------
185template<typename TSpace>
186inline
187void
188DGtal::HyperRectDomain<TSpace>::selfDisplay ( std::ostream & out ) const
189{
190 out << "[HyperRectDomain] = [" << myLowerBound << "]x["
191 << myUpperBound << "]";
192}
193
194//-----------------------------------------------------------------------------
195template<typename TSpace>
196inline
197bool
198DGtal::HyperRectDomain<TSpace>::isValid() const
199{
200 return true;
201}
202
203//-----------------------------------------------------------------------------
204template<typename TSpace>
205inline
206std::string
207DGtal::HyperRectDomain<TSpace>::className() const
208{
209 return "HyperRectDomain";
210}
211
212//-----------------------------------------------------------------------------
213template<typename TSpace>
214inline
215std::ostream&
216DGtal::operator<< ( std::ostream & out,
217 const HyperRectDomain<TSpace> & object )
218{
219 object.selfDisplay ( out );
220 return out;
221}
222
223///////////////////////////////////////////////////////////////////////////////
224
225