DGtal  0.9.3
Functions
testHyperRectDomain.cpp File Reference
#include <cstdio>
#include <cmath>
#include <iostream>
#include <fstream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/PointVector.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/base/CConstBidirectionalRange.h"
Include dependency graph for testHyperRectDomain.cpp:

Go to the source code of this file.

Functions

bool testSimpleHyperRectDomain ()
 
bool testIterator ()
 
bool testReverseIterator ()
 
bool testSTLCompat ()
 
bool testEmptyDomain ()
 
int main ()
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr )
Guillaume Damiand
Date
2010/05/25

This file is part of the DGtal library

Definition in file testHyperRectDomain.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 360 of file testHyperRectDomain.cpp.

References testEmptyDomain(), testIterator(), testReverseIterator(), testSimpleHyperRectDomain(), and testSTLCompat().

361 {
363  return 0;
364  else
365  return 1;
366 }
bool testSTLCompat()
bool testEmptyDomain()
bool testIterator()
bool testReverseIterator()
bool testSimpleHyperRectDomain()

◆ testEmptyDomain()

bool testEmptyDomain ( )

Definition at line 288 of file testHyperRectDomain.cpp.

References DGtal::Trace::beginBlock(), domain(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

289 {
290  typedef SpaceND<3> TSpace;
291  typedef TSpace::Point TPoint;
292  typedef HyperRectDomain<TSpace> TDomain;
293 
294  unsigned int nb = 0;
295  unsigned int nbok = 0;
296 
297  trace.beginBlock( "Test empty domain." );
298 
299  const TDomain nonempty_domain( TPoint::diagonal(0), TPoint::diagonal(0) );
300  ++nb; nbok += nonempty_domain.isEmpty() ? 0 : 1;
301  trace.info() << "(" << nbok << "/" << nb << ") Creating non-empty domain & checking isEmpty." << std::endl;
302 
303  const TDomain default_domain;
304  ++nb; nbok += default_domain.isEmpty() ? 1 : 0;
305  trace.info() << "(" << nbok << "/" << nb << ") Creating default empty domain & checking isEmpty." << std::endl;
306 
307  const TDomain domain( TPoint::diagonal(1), TPoint::diagonal(0) );
308  ++nb; nbok += domain.isEmpty() ? 1 : 0;
309  trace.info() << "(" << nbok << "/" << nb << ") Creating default custom domain & checking isEmpty." << std::endl;
310 
311  ++nb; nbok += domain.size() == 0 ? 1 : 0;
312  trace.info() << "(" << nbok << "/" << nb << ") Empty domain has size = " << domain.size() << std::endl;
313 
314  ++nb; nbok += domain.begin() == domain.end() ? 1 : 0;
315  trace.info() << "(" << nbok << "/" << nb << ") Checking that begin() == end()" << std::endl;
316 
317  ++nb; nbok += domain.rbegin() == domain.rend() ? 1 : 0;
318  trace.info() << "(" << nbok << "/" << nb << ") Checking that rbegin() == rend()" << std::endl;
319 
320  TDomain::ConstSubRange range = domain.subRange( 0, 1, 2, domain.lowerBound() );
321  ++nb; nbok += range.begin() == range.end() ? 1 : 0;
322  trace.info() << "(" << nbok << "/" << nb << ") Checking that begin() == end() for sub-range {0,1,2}" << std::endl;
323 
324  ++nb; nbok += range.rbegin() == range.rend() ? 1 : 0;
325  trace.info() << "(" << nbok << "/" << nb << ") Checking that rbegin() == rend() for sub-range {0,1,2}" << std::endl;
326 
327  range = domain.subRange( 2, 1, 0, domain.lowerBound() );
328  ++nb; nbok += range.begin() == range.end() ? 1 : 0;
329  trace.info() << "(" << nbok << "/" << nb << ") Checking that begin() == end() for sub-range {2,1,0}" << std::endl;
330 
331  ++nb; nbok += range.rbegin() == range.rend() ? 1 : 0;
332  trace.info() << "(" << nbok << "/" << nb << ") Checking that rbegin() == rend() for sub-range {2,1,0}" << std::endl;
333 
334  range = domain.subRange( 0, 2, domain.lowerBound() );
335  ++nb; nbok += range.begin() == range.end() ? 1 : 0;
336  trace.info() << "(" << nbok << "/" << nb << ") Checking that begin() == end() for sub-range {0,2}" << std::endl;
337 
338  ++nb; nbok += range.rbegin() == range.rend() ? 1 : 0;
339  trace.info() << "(" << nbok << "/" << nb << ") Checking that rbegin() == rend() for sub-range {0,2}" << std::endl;
340 
341  range = domain.subRange( 2, 0, domain.lowerBound() );
342  ++nb; nbok += range.begin() == range.end() ? 1 : 0;
343  trace.info() << "(" << nbok << "/" << nb << ") Checking that begin() == end() for sub-range {2,0}" << std::endl;
344 
345  ++nb; nbok += range.rbegin() == range.rend() ? 1 : 0;
346  trace.info() << "(" << nbok << "/" << nb << ") Checking that rbegin() == rend() for sub-range {2,0}" << std::endl;
347 
348  range = domain.subRange( 1, domain.lowerBound() );
349  ++nb; nbok += range.begin() == range.end() ? 1 : 0;
350  trace.info() << "(" << nbok << "/" << nb << ") Checking that begin() == end() for sub-range {1}" << std::endl;
351 
352  ++nb; nbok += range.rbegin() == range.rend() ? 1 : 0;
353  trace.info() << "(" << nbok << "/" << nb << ") Checking that rbegin() == rend() for sub-rang {1}" << std::endl;
354 
355  trace.endBlock();
356  return nb == nbok;
357 
358 }
void beginBlock(const std::string &keyword="")
const ConstIterator & end() const
ConstSubRange subRange(const std::vector< Dimension > &permutation) const
const Domain domain(Point(1, 2), Point(6, 5))
Trace trace
Definition: Common.h:137
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
ConstReverseIterator rend() const
ConstReverseIterator rbegin() const
const ConstIterator & begin() const
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()
const Point & lowerBound() const

◆ testIterator()

bool testIterator ( )

Definition at line 102 of file testHyperRectDomain.cpp.

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::info(), DGtal::HyperRectDomain< TSpace >::isValid(), DGtal::HyperRectDomain< TSpace >::rbegin(), DGtal::HyperRectDomain< TSpace >::rend(), DGtal::HyperRectDomain< TSpace >::subRange(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

103 {
104  typedef SpaceND<2> TSpace;
105  typedef TSpace::Point Point;
106  Point a ( 1, 1);
107  Point b ( 5, 5);
108  Point c (2, 2);
109 
110  trace.beginBlock ( "HyperRectDomain Iterator" );
111  HyperRectDomain<TSpace> myHyperRectDomain ( a, b );
112 
113  trace.info() << myHyperRectDomain << std::endl;
114 
115  trace.emphase() << "Iterator 2d: ";
116  for ( HyperRectDomain<TSpace>::ConstIterator it = myHyperRectDomain.begin();
117  it != myHyperRectDomain.end(); ++it )
118  trace.warning() << ( *it ) << std::endl;
119 
120  trace.emphase() << "Reverse Iterator 2d: ";
121  for ( HyperRectDomain<TSpace>::ConstReverseIterator it = myHyperRectDomain.rbegin(),
122  itend = myHyperRectDomain.rend(); it != itend; ++it )
123  trace.warning() << ( *it ) << std::endl;
124 
125  trace.emphase() << "Iterator 2d (permutation initializer list): ";
127  it = myHyperRectDomain.subRange( {1, 0} ).begin();
128  it != myHyperRectDomain.subRange( {1, 0} ).end(); ++it )
129  trace.warning() << ( *it ) << std::endl;
130  trace.emphase() << "Reverse Iterator 2d (permutation initializer list): ";
132  it = myHyperRectDomain.subRange( {1, 0} ).rbegin(),
133  itend=myHyperRectDomain.subRange( {1, 0} ).rend(); it!=itend; ++it )
134  trace.warning() << ( *it ) << std::endl;
135 
136  trace.emphase() << "Iterator 2d (permutation+starting initializer list): ";
138  it = myHyperRectDomain.subRange( {1, 0} ).begin(c);
139  it != myHyperRectDomain.subRange( {1, 0} ).end(); ++it )
140  trace.warning() << ( *it ) << std::endl;
141  trace.emphase() << "Reverse Iterator 2d (permutation+starting initializer list): ";
143  it = myHyperRectDomain.subRange( {1, 0} ).rbegin(c),
144  itend=myHyperRectDomain.subRange( {1, 0} ).rend(); it !=itend ; ++it )
145  trace.warning() << ( *it ) << std::endl;
146 
147  trace.emphase() << "Iterator 2d (span initializer list): ";
149  it = myHyperRectDomain.subRange( {1} ).begin();
150  it != myHyperRectDomain.subRange( {1} ).end(); ++it )
151  trace.warning() << ( *it ) << std::endl;
152  trace.emphase() << "Reverse Iterator 2d (span initializer list): ";
154  it = myHyperRectDomain.subRange( {1} ).rbegin(),
155  itend=myHyperRectDomain.subRange( {1} ).rend(); it != itend; ++it )
156  trace.warning() << ( *it ) << std::endl;
157 
158  trace.emphase() << "Iterator 2d (span+starting initializer list): ";
160  it = myHyperRectDomain.subRange( {1} , c ).begin(c);
161  it != myHyperRectDomain.subRange( {1} , c ).end(); ++it )
162  trace.warning() << ( *it ) << std::endl;
163  trace.emphase() << "Reverse Iterator 2d (span+starting initializer list): ";
165  it = myHyperRectDomain.subRange( {1} , c ).rbegin(c),
166  itend=myHyperRectDomain.subRange( {1} , c ).rend(); it !=itend; ++it )
167  trace.warning() << ( *it ) << std::endl;
168 
169  trace.emphase() << "Iterator 4d: ";
170  typedef SpaceND<4> TSpace4D;
171  typedef TSpace4D::Point Point4D;
172 
173  TSpace4D::Integer t[] = {1, 1, 1, 1};
174  Point4D a4D ( t );
175  TSpace4D::Integer t2[] = {3, 3, 3, 3};
176  Point4D b4D ( t2 );
177 
178  HyperRectDomain<TSpace4D> myHyperRectDomain4D ( a4D, b4D );
179  trace.emphase() << myHyperRectDomain4D << std::endl;
181  it = myHyperRectDomain4D.begin();
182  it != myHyperRectDomain4D.end(); ++it )
183  trace.info() << ( *it ) << std::endl;
184 
185  trace.emphase() << "Reverse Iterator 4d: ";
187  it = myHyperRectDomain4D.rbegin(),
188  itend=myHyperRectDomain4D.rend(); it != itend; ++it )
189  trace.info() << ( *it ) << std::endl;
190 
191 
192  trace.emphase() << "Iterator 4d by using order different from lexicographic initializer list: ";
194  it = myHyperRectDomain4D.subRange( {3, 2, 1, 0}).begin();
195  it != myHyperRectDomain4D.subRange( {3, 2, 1, 0}).end(); ++it )
196  trace.info() << ( *it ) << std::endl;
197 
198  trace.emphase() << "Decreasing Iterator 4d by using order different from lexicographic initializer list: ";
200  it1 = myHyperRectDomain4D.subRange( {3, 2, 1, 0}).begin();
202  it2 = myHyperRectDomain4D.subRange( {3, 2, 1, 0}).end();
203  --it1;
204  --it2;
205  for ( ; it1 != it2; --it2 )
206  trace.info() << ( *it2 ) << std::endl;
207 
208  trace.emphase() << "Iterator on a subset of 4d by using order different from lexicographic initializer list: ";
210  it3 = myHyperRectDomain4D.subRange( {1, 3}).begin();
211  it3 != myHyperRectDomain4D.subRange( {1, 3}).end(); ++it3 )
212  trace.info() << ( *it3 ) << std::endl;
213 
214  trace.emphase() << "Decreasing iterator on a subset of 4d by using order different from lexicographic initializer list: ";
216  it4 = myHyperRectDomain4D.subRange({1, 3}).begin();
218  it5 = myHyperRectDomain4D.subRange({1, 3}).end();
219  --it4;
220  --it5;
221  for ( ; it4 != it5; --it5 )
222  trace.info() << ( *it5 ) << std::endl;
223 
224  return myHyperRectDomain.isValid();
225 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
std::ostream & emphase()
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & warning()
std::ostream & info()

◆ testReverseIterator()

bool testReverseIterator ( )

Definition at line 228 of file testHyperRectDomain.cpp.

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::HyperRectDomain< TSpace >::isValid(), and DGtal::trace.

Referenced by main().

229 {
230  typedef SpaceND<4> TSpace4D;
231  typedef TSpace4D::Point Point4D;
232  TSpace4D::Integer t[] = {1, 1, 1, 1};
233  Point4D a4D (t);
234  TSpace4D::Integer t2[] = {3, 3, 3, 3};
235  Point4D b4D (t2);
236 
237  trace.beginBlock ( "Test reverse iterator" );
238 
239  HyperRectDomain<TSpace4D> myHyperRectDomain4D ( a4D, b4D );
240  trace.emphase() << myHyperRectDomain4D << std::endl;
241 
242  trace.emphase() << "Increasing order: ";
243 
245  it = myHyperRectDomain4D.begin();
246  for ( ; it != myHyperRectDomain4D.end(); ++it )
247  trace.info() << ( *it ) << std::endl;
248 
249  trace.emphase() << "Now decreasing order: ";
251  it2 = myHyperRectDomain4D.begin();
252  --it;
253  --it2;
254  for ( ; it != it2; --it )
255  trace.info() << ( *it ) << std::endl;
256 
257  trace.endBlock();
258 
259  return myHyperRectDomain4D.isValid();
260 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
std::ostream & emphase()
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()

◆ testSimpleHyperRectDomain()

bool testSimpleHyperRectDomain ( )

Simple test of HyperRectDomain construction.

Empty domain using the default constructor

Domain characterized by points a and b

Definition at line 53 of file testHyperRectDomain.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::HyperRectDomain< TSpace >::isValid(), DGtal::HyperRectDomain< TSpace >::size(), and DGtal::trace.

Referenced by main().

54 {
55 
56  typedef SpaceND<4> Space4Type;
57  typedef Space4Type::Point Point;
58 
59  Space4Type::Integer t [] = { 1, 2, 3 , 4};
60  Point a ( t );
61  Space4Type::Integer t2[] = { 5, 5, 3 , 4};
62  Point b ( t2 );
63 
64  trace.beginBlock ( "HyperRectDomain init" );
65 
66  // Checking that HyperRectDomain is a model of CDomain.
67  typedef HyperRectDomain<Space4Type> HRDomain4;
68  BOOST_CONCEPT_ASSERT(( concepts::CDomain< HRDomain4 > ));
69  BOOST_CONCEPT_ASSERT(( concepts::CConstBidirectionalRange<HRDomain4> ));
70 
72  HyperRectDomain<Space4Type> myEmptyDomain;
73  trace.info() << "Empty Domain: " << myEmptyDomain << std::endl;
74 
76  HyperRectDomain<Space4Type> myHyperRectDomain ( a, b );
77  trace.info() << myHyperRectDomain << std::endl;
78 
79  trace.info() << "Domain Size= " << myHyperRectDomain.size() << std::endl;
80 
81 
82  trace.endBlock();
83 
84 
85  trace.beginBlock("Test Copy Constructor");
86  HyperRectDomain<Space4Type> myHyperRectDomainBis( myHyperRectDomain );
87  trace.info() << "Domain Size= " << myHyperRectDomainBis.size() << std::endl;
88  trace.endBlock();
89 
90  trace.beginBlock("Test Assignement");
91  HyperRectDomain<Space4Type> myHyperRectDomainTer;
92 
93  myHyperRectDomainTer = myHyperRectDomain;
94 
95  trace.info() << "Domain Size= " << myHyperRectDomainTer.size() << std::endl;
96  trace.endBlock();
97 
98  return myHyperRectDomain.isValid();
99 
100 }
void beginBlock(const std::string &keyword="")
Aim: Defines the concept describing a bidirectional const range.
Trace trace
Definition: Common.h:137
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
Definition: CDomain.h:129
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()

◆ testSTLCompat()

bool testSTLCompat ( )

Definition at line 264 of file testHyperRectDomain.cpp.

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::HyperRectDomain< TSpace >::isValid(), and DGtal::trace.

Referenced by main().

265 {
266  typedef SpaceND<4> TSpace4D;
267  typedef TSpace4D::Point Point4D;
268  TSpace4D::Integer t[] = {1, 1, 1, 1};
269  Point4D a4D (t);
270  TSpace4D::Integer t2[] = {3, 3, 3, 3};
271  Point4D b4D (t2);
272 
273  trace.beginBlock ( "TestSTL Compatibility" );
274 
275  HyperRectDomain<TSpace4D> myHyperRectDomain4D ( a4D, b4D );
276  trace.emphase() << myHyperRectDomain4D << std::endl;
277 
278  std::copy ( myHyperRectDomain4D.begin(),
279  myHyperRectDomain4D.end(),
280  ostream_iterator<Point4D> ( trace.info(), " " ) );
281 
282  trace.info() << std::endl;
283  trace.endBlock();
284 
285  return myHyperRectDomain4D.isValid();
286 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
std::ostream & emphase()
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()