DGtal  0.9.2
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 //-----------------------------------------------------------------------------
39 template<typename TSpace>
40 inline
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,
46  myLowerBound,
47  myUpperBound),
48  myIteratorEnd(myUpperBound,
49  myLowerBound,
50  myUpperBound)
51 {
52  ++myIteratorEnd;
53 }
54 
55 //-----------------------------------------------------------------------------
56 template<typename TSpace>
57 inline
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,
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 //-----------------------------------------------------------------------------
83 template<typename TSpace>
84 inline
85 DGtal::HyperRectDomain<TSpace>
86 ::HyperRectDomain( const typename DGtal::HyperRectDomain<TSpace> &aDomain) :
87  myLowerBound(aDomain.lowerBound()),
88  myUpperBound(aDomain.upperBound()),
89  myPredicate( myLowerBound, myUpperBound ),
90  myIteratorBegin(myLowerBound,
91  myLowerBound,
92  myUpperBound),
93  myIteratorEnd(myUpperBound,
94  myLowerBound,
95  myUpperBound)
96 {
97  ++myIteratorEnd;
98 }
99 
100 //-----------------------------------------------------------------------------
101 template<typename TSpace>
102 inline
103 DGtal::HyperRectDomain<TSpace>::~HyperRectDomain()
104 {}
105 
106 //-----------------------------------------------------------------------------
107 template<typename TSpace>
108 inline
109 DGtal::HyperRectDomain<TSpace> &
110 DGtal::HyperRectDomain<TSpace>
111 ::operator= ( const typename DGtal::HyperRectDomain<TSpace> & other )
112 {
113  if ( this != &other )
114  {
115  myLowerBound = other.myLowerBound;
116  myUpperBound = other.myUpperBound;
117  myPredicate = other.myPredicate;
118  new(&myIteratorBegin) ConstIterator(myLowerBound,myLowerBound,myUpperBound);
119  new(&myIteratorEnd) ConstIterator(myUpperBound,myLowerBound,myUpperBound);
120  ++myIteratorEnd;
121  }
122  return *this;
123 }
124 
125 //-----------------------------------------------------------------------------
126 
127 
128 //-----------------------------------------------------------------------------
129 template<typename TSpace>
130 inline
131 const typename DGtal::HyperRectDomain<TSpace>::Point &
132 DGtal::HyperRectDomain<TSpace>::lowerBound() const
133 {
134  return myLowerBound;
135 }
136 
137 //-----------------------------------------------------------------------------
138 template<typename TSpace>
139 inline
140 bool
141 DGtal::HyperRectDomain<TSpace>::isInside( const Point & p ) const
142 {
143  return myPredicate( p );
144 }
145 
146 //-----------------------------------------------------------------------------
147 template<typename TSpace>
148 inline
149 bool
150 DGtal::HyperRectDomain<TSpace>::isEmpty() const
151 {
152  return ! myLowerBound.isLower(myUpperBound);
153 }
154 
155 //-----------------------------------------------------------------------------
156 template<typename TSpace>
157 inline
158 const typename DGtal::HyperRectDomain<TSpace>::Predicate &
159 DGtal::HyperRectDomain<TSpace>::predicate() const
160 {
161  return myPredicate;
162 }
163 
164 //-----------------------------------------------------------------------------
165 template<typename TSpace>
166 inline
167 const typename DGtal::HyperRectDomain<TSpace>::Point &
168 DGtal::HyperRectDomain<TSpace>::upperBound() const
169 {
170  return myUpperBound;
171 }
172 
173 //-----------------------------------------------------------------------------
174 template<typename TSpace>
175 inline
176 void
177 DGtal::HyperRectDomain<TSpace>::selfDisplay ( std::ostream & out ) const
178 {
179  out << "[HyperRectDomain] = [" << myLowerBound << "]x["
180  << myUpperBound << "]";
181 }
182 
183 //-----------------------------------------------------------------------------
184 template<typename TSpace>
185 inline
186 bool
187 DGtal::HyperRectDomain<TSpace>::isValid() const
188 {
189  return true;
190 }
191 
192 //-----------------------------------------------------------------------------
193 template<typename TSpace>
194 inline
195 std::string
196 DGtal::HyperRectDomain<TSpace>::className() const
197 {
198  return "HyperRectDomain";
199 }
200 
201 //-----------------------------------------------------------------------------
202 template<typename TSpace>
203 inline
204 std::ostream&
205 DGtal::operator<< ( std::ostream & out,
206  const HyperRectDomain<TSpace> & object )
207 {
208  object.selfDisplay ( out );
209  return out;
210 }
211 
212 ///////////////////////////////////////////////////////////////////////////////
213 
214