DGtal  1.5.beta
testVoronoiMapComplete.cpp File Reference
#include <limits>
#include <unordered_set>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtalCatch.h"
#include "DGtal/geometry/volumes/distance/VoronoiMapComplete.h"
#include "DGtal/geometry/volumes/distance/VoronoiMap.h"
Include dependency graph for testVoronoiMapComplete.cpp:

Go to the source code of this file.

Typedefs

typedef Z2i::DigitalSet DigitalSet
 
typedef Z2i::Point Point
 
typedef Z2i::Domain Domain
 
typedef VoronoiMapComplete< Z2i::Space, DigitalSet, Z2i::L2MetricCompleteVMap
 
typedef VoronoiMap< Z2i::Space, DigitalSet, Z2i::L2MetricVMap
 
typedef ImageContainerBySTLVector< HyperRectDomain< Z2i::Space >, std::unordered_set< Z2i::Point > > TImageContainer
 

Functions

TImageContainerbrut_force_voronoi_map_complete (DigitalSet &set)
 
 TEST_CASE ("Testing VoronoiMapComplete 2D")
 
 TEST_CASE ("No sites")
 
 TEST_CASE ("Testing Timings")
 

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
Robin Lamy
Date
2021/07/20

Functions for testing class VoronoiMapComplete.

This file is part of the DGtal library.

Definition in file testVoronoiMapComplete.cpp.

Typedef Documentation

◆ CompleteVMap

◆ DigitalSet

◆ Domain

Definition at line 42 of file testVoronoiMapComplete.cpp.

◆ Point

typedef Z2i::Point Point

Definition at line 41 of file testVoronoiMapComplete.cpp.

◆ TImageContainer

◆ VMap

Function Documentation

◆ brut_force_voronoi_map_complete()

TImageContainer* brut_force_voronoi_map_complete ( DigitalSet set)

Definition at line 50 of file testVoronoiMapComplete.cpp.

51 {
52  TImageContainer * voronoi_map = new TImageContainer( set.domain() );
53  std::vector<Point> Sites;
54  // Getting all voronoi sites in one vector
55  for ( Point point : set.domain() )
56  {
57  if ( !set( point ) )
58  {
59  Sites.push_back( point );
60  }
61  }
62  std::cout << std::endl;
63 
64  for ( Point point : set.domain() )
65  {
66 
67  std::unordered_set<Point> voronoi_points;
68  double voronoi_distance =
69  std::numeric_limits<int>::max(); // maximum int value
70  for ( Point site : Sites )
71  {
72  if ( ( point - site ).norm() < voronoi_distance )
73  {
74  voronoi_points.clear();
75  voronoi_points.insert( site );
76  voronoi_distance = ( point - site ).norm();
77  }
78  else if ( ( point - site ).norm() == voronoi_distance )
79  {
80  voronoi_points.insert( site );
81  }
82  }
83  voronoi_map->setValue( point, voronoi_points );
84  }
85  return voronoi_map;
86 }
void setValue(const Point &aPoint, const Value &aValue)
int max(int a, int b)
MyPointD Point
Definition: testClone2.cpp:383
ImageContainerBySTLVector< HyperRectDomain< Z2i::Space >, std::unordered_set< Z2i::Point > > TImageContainer

References DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::domain(), max(), and DGtal::ImageContainerBySTLVector< TDomain, TValue >::setValue().

Referenced by TEST_CASE().

◆ TEST_CASE() [1/3]

TEST_CASE ( "No sites"  )

Random set generation

Definition at line 189 of file testVoronoiMapComplete.cpp.

190 {
194  Point lowerBound( 0, 0 ), upperBound( 255, 255 );
195  Domain domain( lowerBound, upperBound );
196  DigitalSet set( domain );
197 
198  trace.beginBlock( "Complete Map (no site)" );
199  CompleteVMap vmap( set.domain(), set, Z2i::l2Metric );
200  trace.endBlock();
201  trace.beginBlock( "Partial Map (no site)" );
202  VMap partialmap( set.domain(), set, Z2i::l2Metric );
203  trace.endBlock();
204 }
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
void beginBlock(const std::string &keyword="")
double endBlock()
Aim: Implementation of the linear in time Voronoi map construction.
Aim: Implementation of the linear in time Voronoi map construction.
Definition: VoronoiMap.h:127
Trace trace
Definition: Common.h:153
Domain domain

References DGtal::Trace::beginBlock(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::domain(), domain, DGtal::Trace::endBlock(), DGtal::Z2i::l2Metric, and DGtal::trace.

◆ TEST_CASE() [2/3]

TEST_CASE ( "Testing Timings"  )

Random set generation

Definition at line 206 of file testVoronoiMapComplete.cpp.

207 {
211  Point lowerBound( 0, 0 ), upperBound( 255, 255 );
212  Domain domain( lowerBound, upperBound );
213 
214  DigitalSet set( domain );
215  int point_setup_index = 0;
216  int x;
217  int y;
218 
219  while ( point_setup_index < 5000 )
220  {
221  x = rand() % 256;
222  y = rand() % 256;
223  set.insert( Point( x, y ) );
224  point_setup_index++;
225  }
226  std::cout << std::endl;
227  trace.beginBlock( "Complete Map" );
228  CompleteVMap vmap( set.domain(), set, Z2i::l2Metric );
229  trace.endBlock();
230 
231  size_t maxsize = 0;
232  for ( auto & v : vmap.constRange() )
233  maxsize = std::max( maxsize, v.size() );
234  trace.info() << "Max number of co-cyclic points = " << maxsize << std::endl;
235 
236  trace.beginBlock( "Partial Map" );
237  VMap partialmap( set.domain(), set, Z2i::l2Metric );
238  trace.endBlock();
239 }
std::ostream & info()
Z2i::Point Point

References DGtal::Trace::beginBlock(), DGtal::VoronoiMapComplete< TSpace, TPointPredicate, TSeparableMetric, TImageContainer >::constRange(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::domain(), domain, DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insert(), DGtal::Z2i::l2Metric, max(), and DGtal::trace.

◆ TEST_CASE() [3/3]

TEST_CASE ( "Testing VoronoiMapComplete 2D"  )

Random set generation

Voronoi Map Complete from class generation

Voronoi Map Complete from brut force generation

Definition at line 91 of file testVoronoiMapComplete.cpp.

92 {
96  Point lowerBound( 0, 0 ), upperBound( 31, 31 );
97  Domain domain( lowerBound, upperBound );
98 
99  DigitalSet set( domain );
100  int point_setup_index = 0;
101  int x;
102  int y;
103 
104  while ( point_setup_index < 400 )
105  {
106  x = rand() % 32;
107  y = rand() % 32;
108  set.insert( Point( x, y ) );
109  point_setup_index++;
110  }
111 
115  CompleteVMap vmap( set.domain(), set, Z2i::l2Metric );
116 
120  TImageContainer * brut_force_vmap = brut_force_voronoi_map_complete( set );
121 
122  SECTION(
123  "Testing that VoronoiMapComplete class gives the right voronoi sites sets" )
124  {
125  for ( Point point : set )
126  {
127  std::unordered_set<Point> brut_force_set =
128  brut_force_vmap->operator()( point );
129  CompleteVMap::Value class_set = vmap( point );
130 
131  // Cheking that all voronoi sites from the brut force set are in the
132  // algorithm set
133  for ( Point voronoi_point : brut_force_set )
134  {
135  REQUIRE( std::find( class_set.begin(), class_set.end(),
136  voronoi_point ) != class_set.end() );
137  }
138 
139  // Cheking that all voronoi sites from the algorithm set are in the brut
140  // force set
141  for ( Point voronoi_point : class_set )
142  {
143  REQUIRE( std::find( brut_force_set.begin(), brut_force_set.end(),
144  voronoi_point ) != brut_force_set.end() );
145  }
146  }
147  }
148 
149  SECTION(
150  "Testing Complete Voronoi Map from Discrete Bisector Function paper" )
151  {
152  Point _lowerBound( 0, 0 ), _upperBound( 6, 7 );
153  Domain _domain( _lowerBound, _upperBound );
154  DigitalSet _set( _domain );
155  for ( Point point : _set.domain() )
156  {
157  if ( point != Point( 1, 0 ) && point != Point( 5, 0 ) &&
158  point != Point( 2, 2 ) && point != Point( 4, 4 ) &&
159  point != Point( 0, 6 ) && point != Point( 6, 6 ) &&
160  point != Point( 3, 7 ) )
161  _set.insert( point );
162  }
163 
164  TImageContainer * brutForceVoronoiMap =
166  CompleteVMap _vmap( _set.domain(), _set, Z2i::l2Metric );
167 
168  for ( Point point : _set )
169  {
170  std::unordered_set<Point> brut_force_set =
171  brutForceVoronoiMap->operator()( point );
172  CompleteVMap::Value class_set = _vmap( point );
173 
174  // Cheking that all voronoi sites from the brut force set are in the
175  // algorithm set
176  for ( Point voronoi_point : brut_force_set )
177  REQUIRE( std::find( class_set.begin(), class_set.end(),
178  voronoi_point ) != class_set.end() );
179 
180  // Cheking that all voronoi sites from the algorithm set are in the brut
181  // force set
182  for ( Point voronoi_point : class_set )
183  REQUIRE( std::find( brut_force_set.begin(), brut_force_set.end(),
184  voronoi_point ) != brut_force_set.end() );
185  }
186  }
187 }
OutputImage::Value Value
Definition of the image value type.
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))
TImageContainer * brut_force_voronoi_map_complete(DigitalSet &set)

References brut_force_voronoi_map_complete(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::domain(), domain, DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insert(), DGtal::Z2i::l2Metric, REQUIRE(), and SECTION().