43#include <unordered_set>
45#include "DGtal/base/Common.h"
46#include "DGtal/kernel/SpaceND.h"
47#include "DGtal/kernel/domains/HyperRectDomain.h"
48#include "DGtal/kernel/sets/CDigitalSet.h"
49#include "DGtal/kernel/sets/CDigitalSetArchetype.h"
50#include "DGtal/kernel/domains/CDomain.h"
51#include "DGtal/kernel/domains/CDomainArchetype.h"
52#include "DGtal/kernel/sets/DigitalSetBySTLVector.h"
53#include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
54#include "DGtal/kernel/sets/DigitalSetByAssociativeContainer.h"
55#include "DGtal/kernel/sets/DigitalSetFromMap.h"
56#include "DGtal/kernel/sets/DigitalSetSelector.h"
57#include "DGtal/kernel/sets/DigitalSetDomain.h"
58#include "DGtal/kernel/sets/DigitalSetInserter.h"
60#include "DGtal/images/ImageContainerBySTLMap.h"
62#include "DGtal/helpers/StdDefs.h"
64#include "DGtal/io/boards/Board2D.h"
66#include "DGtal/kernel/PointHashFunctions.h"
74#define INBLOCK_TEST(x) \
75 nbok += ( x ) ? 1 : 0; \
77 trace.info() << "(" << nbok << "/" << nb << ") " \
80#define INBLOCK_TEST2(x,y) \
81 nbok += ( x ) ? 1 : 0; \
83 trace.info() << "(" << nbok << "/" << nb << ") " \
102 typedef Z2::Point
Point;
103 Point p1( -10, -10 );
110 SpecificSet mySet(
domain );
122 board.
saveSVG(
"myset-export.svg");
128 board.
saveSVG(
"simpleSet-grid.svg");
135 board.
saveSVG(
"simpleSet-paving.svg");
141 board <<
CustomStyle( mySet.className(),
new MyDomainStyleCustomRed );
143 board.
saveSVG(
"simpleSet-color.svg");
148template <
typename DigitalSetType >
153 typedef typename DigitalSetType::Domain
Domain;
155 typedef typename Point::Coordinate Coordinate;
156 unsigned int nbok = 0;
160 DigitalSetType set1( aSet1 );
161 nbok += ( (set1.size() == 0)&&(set1.empty()) ) ? 1 : 0;
163 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
164 <<
"Empty set: " << set1 << std::endl;
168 Coordinate t [] = { 4, 3, 3 , 4};
169 Coordinate t2[] = { 2, 5, 3 , 5};
170 Coordinate t3[] = { 2, 5, 3 , 4} ;
182 nbok += set1.size() == 3 ? 1 : 0;
184 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
185 <<
"Insertion (3 elements): " << set1 << std::endl;
189 for (
typename DigitalSetType::Iterator it = set1.begin();
190 it != set1.end(); ++it)
192 if (v.find( *it ) == v.end())
195 nbok += (flag) ? 1 : 0;
197 trace.
info() <<
"Iterate: (" << nbok <<
"/" << nb <<
") "
201 auto & container = set1.container();
206 nbok += ( (set1.size() == 2)
207 &&(set1.find( b ) == set1.end()) )? 1 : 0;
209 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
210 <<
"Erase one element by key (2 remain): " << set1 << std::endl;
212 typename DigitalSetType::Iterator it = set1.find( c );
214 nbok += ( (set1.size() == 1)
215 &&(set1.find( c ) == set1.end()) )? 1 : 0;
217 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
218 <<
"Erase one element by iterator (1 remain): " << set1 << std::endl;
221 DigitalSetType set2( aSet2 );
223 set1.computeComplement(inserter);
224 nbok += (set2.size() == (set2.domain().size()-1))? 1 : 0;
226 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
227 <<
"Complement: " << set2 << std::endl;
230 nbok += (set2.size() == (set2.domain().size()))? 1 : 0;
232 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
233 <<
"Union: " << set2 << std::endl;
237 nbok += ( (set1.size() == 0)&&(set1.empty()) ) ? 1 : 0;
239 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
240 <<
"Cleared set: " << set1 << std::endl;
242 set1.assignFromComplement(set2);
243 nbok += ( (set1.size() == 0)&&(set1.empty()) ) ? 1 : 0;
245 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
251template <
typename DigitalDomain,
int props >
253 const std::string & comment )
255 unsigned int nbok = 0;
261 < DigitalDomain, props >::Type SpecificSet;
262 SpecificSet set1(
domain );
265 nbok += set1.size() == 2 ? 1 : 0;
267 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
268 << comment <<
" (2 elements): " << set1 << std::endl;
278 unsigned int nbok = 0;
283 typedef Z2::Point
Point;
284 Point p1( -10, -10 );
291 SpecificSet disk(
domain );
299 if ( (*it - c ).norm() < 5.0 )
301 disk.insertNew( *it );
311 board.
saveSVG(
"disk-set.svg" );
319 unsigned int nbok = 0;
324 typedef Z2::Point
Point;
325 Point p1( -49, -49 );
332 SpecificSet disk(
domain );
341 if ( (*it - c ).norm() < 50.0 )
343 disk.insertNew( *it );
347 trace.
info() <<
"disk.size()=" << disk.size() << std::endl;
353 RestrictedDomain disk_domain( disk );
355 unsigned int nb_in_domain = 0;
356 for ( RestrictedDomain::ConstIterator it = disk_domain.begin();
357 it != disk_domain.end();
387 typedef Space4Type::Point
Point;
389 Space4Type::Integer t[] = { 1, 2, 3 , 4};
391 Space4Type::Integer t2[] = { 5, 5, 3 , 5};
402 bool okVector = testDigitalSet< DigitalSetBySTLVector<Domain> >
407 bool okSet = testDigitalSet< DigitalSetBySTLSet<Domain> >
416 bool okMap = testDigitalSet< DigitalSetFromMap<Map> >( setFromMap, setFromMap2 );
420 typedef std::set<Point> Container;
421 bool okAssoctestSet = testDigitalSet< DigitalSetByAssociativeContainer<Domain,Container> >
426 typedef std::unordered_set<Point> ContainerU;
427 bool okUnorderedSet = testDigitalSet< DigitalSetByAssociativeContainer<Domain,ContainerU> >
441 (
domain,
"Medium set + High belonging test" );
449 bool res = okVector && okSet && okMap
450 && okSelectorSmall && okSelectorBig && okSelectorMediumHBel
451 && okDigitalSetDomain && okDigitalSetDraw && okDigitalSetDrawSnippet
452 && okUnorderedSet && okAssoctestSet;
454 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: A container class for storing sets of digital points within some given domain.
Aim: Realizes the concept CDigitalSet by using the STL container std::vector.
Aim: Constructs a domain limited to the given digital set.
Aim: An adapter for viewing an associative image container like ImageContainerBySTLMap as a simple di...
Aim: this output iterator class is designed to allow algorithms to insert points in the digital set....
Iterator for HyperRectDomain.
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
const ConstIterator & begin() const
const Point & lowerBound() const
const Point & upperBound() const
std::string className() const
const ConstIterator & end() const
void beginBlock(const std::string &keyword="")
Aim: The archetype of a container class for storing sets of digital points within some given domain.
Aim: The archetype of a class that represents a digital domain, i.e. a non mutable subset of points o...
Board & setPenColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
void clear(const DGtal::Color &color=DGtal::Color::None)
Board & setFillColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Shape & scale(double sx, double sy)
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Automatically defines an adequate digital set type according to the hints given by the user.
DigitalSetByAssociativeContainer< Domain, std::unordered_set< typename Domain::Point > > Type
virtual void setStyle(Board2D &) const
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Aim: Represents a set of points within the given domain. This set of points is modifiable by the user...
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
std::unordered_map< Cell, CubicalCellData > Map
bool testDigitalSetDomain()
bool testDigitalSetConcept()
bool testDigitalSet(const DigitalSetType &aSet1, const DigitalSetType &aSet2)
bool testDigitalSetDraw()
bool testDigitalSetBoardSnippet()
bool testDigitalSetSelector(const DigitalDomain &domain, const std::string &comment)
HyperRectDomain< Space > Domain