34 #include "DGtal/base/Common.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/images/CConstImage.h"
37 #include "DGtal/geometry/volumes/distance/VoronoiMap.h"
38 #include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
39 #include "DGtal/geometry/volumes/distance/InexactPredicateLpSeparableMetric.h"
40 #include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
41 #include "DGtal/kernel/BasicPointPredicates.h"
42 #include "DGtal/io/boards/Board2D.h"
43 #include "DGtal/io/colormaps/HueShadeColorMap.h"
47 using namespace DGtal;
53 template<
typename Po
int>
57 for(
unsigned int i=0; i< Point::dimension; i++)
58 res += std::pow ( (
double)abs(point[i]) , p);
60 return std::pow(res, 1.0/p);
63 template <
typename VoroMap>
64 void saveVoroMap(
const std::string &filename,
const VoroMap &output,
const double p)
68 const double maxdt =
mynorm( output.domain().upperBound() - output.domain().lowerBound(), p );
74 itend = output.domain().end();
79 hue(
mynorm(point- (*it),p))))
83 board.
saveSVG(filename.c_str());
94 template <
typename Po
int,
typename Domain >
97 auto const & lowerBound = aDomain.
lowerBound();
98 auto const & upperBound = aDomain.
upperBound();
101 aPoint[i] = (
aPoint[i] - 2*lowerBound[i] + upperBound[i] + 1 ) % ( upperBound[i] - lowerBound[i] + 1 ) + lowerBound[i];
116 template < std::
size_t N >
119 std::array<bool, N> periodicity;
120 for ( std::size_t i = 0, mask = 1 ; i < N ; ++i, mask *= 2 )
121 periodicity[i] = anInteger & mask;
132 template < std::
size_t N >
136 for ( std::size_t i = 0; i < N; ++i )
137 str += aPeriodicity[i] ?
'1' :
'0';
144 template <
typename Set,
typename Voro>
150 Point const extent = voro.domain().upperBound() - voro.domain().lowerBound() + Point::diagonal();
153 std::vector< typename Voro::PeriodicitySpec > periodicShift;
154 for ( std::size_t i = 0; i < ( 1u << Voro::Space::dimension ); ++i )
156 const auto periodicity = getPeriodicityFromInteger< Voro::Space::dimension >( i );
160 for (
typename Voro::Space::Dimension j = 0; j < periodicity.size(); ++j )
161 if ( periodicity[j] && ! voro.isPeriodic(j) )
168 periodicShift.push_back( periodicity );
172 for (
auto const& pt : voro.domain() )
175 const Point psite = voro(pt);
176 const auto dist = voro.metric()->rawDistance( pt, psite );
180 if ( std::find( aSet.begin(), aSet.end(), voro.projectPoint( psite ) ) == aSet.end() )
183 <<
" projected to " << voro.projectPoint( psite )
184 <<
" is not a valid site." << std::endl;
189 for (
auto site : aSet )
192 for (
auto const & periodicity : periodicShift )
194 auto currSite = site;
197 for (
typename Voro::Space::Dimension
dim = 0;
dim < Voro::Space::dimension ; ++
dim )
198 if ( periodicity[
dim] )
199 currSite[
dim] += ( pt[
dim] < currSite[
dim] ? -1 : 1 ) * extent[
dim];
202 const auto dbis = voro.metric()->rawDistance( pt, currSite );
206 <<
" Voro:" << psite <<
" (" << dist <<
")"
207 <<
" from set:" << site <<
"(" << dbis <<
")"
208 <<
" projected from " << currSite <<
"." << std::endl;
231 bool testVoronoiMap( std::array<bool, 2>
const& periodicity = { {
false,
false} } )
233 unsigned int nbok = 0;
247 mySet.insertNew( *it );
265 Voro2 voro(&
domain, &mySet, &l2, periodicity);
267 for(
int j=-10; j <= 10; j++)
269 for(
int i=-10; i<=10; i++)
274 trace.
info()<<
"Exporting to SVG"<<std::endl;
278 itend = voro.domain().end();
282 const unsigned char c = ( p[1]*13 + p[0] * 7) % 256;
305 template<
typename Set>
307 const std::string &name,
308 std::array<bool, 2>
const& periodicity = { {
false,
false} } )
310 unsigned int nbok = 0;
313 Set mySet(aSet.domain());
318 mySet.insertNew( *it );
330 Voro2 voro(aSet.domain(), mySet, l2, periodicity );
338 Voro6 voro6( aSet.domain(), mySet, l6, periodicity );
345 DT
dt( aSet.domain(), mySet, l2, periodicity );
349 if ( (aSet.domain().upperBound()[1] - aSet.domain().lowerBound()[1]) <20)
351 for(
int j= aSet.domain().lowerBound()[1]; j <= aSet.domain().upperBound()[1]; j++)
353 for(
int i=aSet.domain().lowerBound()[0]; i<=aSet.domain().upperBound()[0]; i++)
354 if ( aSet.find(
Z2i::Point(i,j) ) != aSet.end() )
363 for(
int j= aSet.domain().lowerBound()[1]; j <= aSet.domain().upperBound()[1]; j++)
365 for(
int i=aSet.domain().lowerBound()[0]; i<=aSet.domain().upperBound()[0]; i++)
372 board << voro.domain();
379 std::string filename =
"Voromap-" + name +
"-orig." +
formatPeriodicity(periodicity) +
".svg";
380 board.
saveSVG(filename.c_str());
383 board << voro.domain();
389 if ((p != (*it)) && (p != voro.domain().upperBound() + Z2i::Point::diagonal(1))
390 && (p != voro.domain().lowerBound()))
394 filename =
"Voromap-" + name +
"-diag." +
formatPeriodicity(periodicity) +
".svg";
395 board.
saveSVG(filename.c_str());
399 board << voro.domain();
404 unsigned char c = (p[1]*13 + p[0] * 7) % 256;
410 board.
saveSVG(filename.c_str());
412 filename =
"Voromap-" + name +
"-hue." +
formatPeriodicity(periodicity) +
".svg";
418 itend = voro6.domain().end();
426 filename =
"Voromap-diag-l6-" + name +
"." +
formatPeriodicity(periodicity) +
".svg";
427 board.
saveSVG(filename.c_str());
434 unsigned char c = (p[1]*13 + p[0] * 7) % 256;
440 board.
saveSVG(filename.c_str());
442 filename =
"Voromap-hue-l6-" + name +
"." +
formatPeriodicity(periodicity) +
".svg";
463 template<
typename Set>
466 std::array<bool, Set::dimension> periodicity;
467 periodicity.fill(
false );
471 template<
typename Set>
474 unsigned int nbok = 0;
477 Set mySet(aSet.domain());
480 itend = aSet.domain().end();
483 mySet.insertNew( *it );
496 Voro2 voro(aSet.domain(), mySet, l2, periodicity);
508 Voro3 voro3(aSet.domain(), mySet, l3, periodicity);
518 DT
dt(aSet.domain(), mySet, l2, periodicity);
539 for ( std::size_t i = 0; i < 4; ++i )
541 auto const periodicity = getPeriodicityFromInteger<2>(i);
561 for(
unsigned int i = 0 ; i < size; ++i)
563 Z2i::Point p( rand() % (b[0]) - a[0], rand() % (b[1]) + a[1] );
567 for ( std::size_t i = 0; i < 4; ++i )
569 auto const periodicity = getPeriodicityFromInteger<2>(i);
575 for(
unsigned int i = 0 ; i < size*size-size; ++i)
577 Z2i::Point p( rand() % (b[0]) - a[0], rand() % (b[1]) + a[1] );
581 for ( std::size_t i = 0; i < 4; ++i )
583 auto const periodicity = getPeriodicityFromInteger<2>(i);
607 for (
auto i = 0; i < 8; ++i )
609 auto const periodicity = getPeriodicityFromInteger<3>(i);
620 std::size_t
const N = 16;
629 for(
unsigned int i = 0 ; i < N; ++i)
632 rand() % (b[1]) + a[1],
633 rand() % (b[2]) + a[2] );
637 for ( std::size_t i = 0; i < 8; ++i )
639 auto const periodicity = getPeriodicityFromInteger<3>(i);
665 for ( std::size_t i = 0; i < 16; ++i )
667 auto const periodicity = getPeriodicityFromInteger<4>(i);
680 int main(
int argc,
char** argv )
684 for (
int i = 0; i < argc; ++i )
700 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Structure representing an RGB triple with alpha component.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
void insertNew(const Point &p)
void insert(const Point &p)
Container::const_iterator ConstIterator
ConstIterator type of the container;.
Aim: A container class for storing sets of digital points within some given domain.
void insertNew(const Point &p)
Aim: implements separable l_p metrics with exact predicates.
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Iterator for HyperRectDomain.
const ConstIterator & end() const
const ConstIterator & begin() const
const Point & lowerBound() const
const Point & upperBound() const
Space::Dimension Dimension
void beginBlock(const std::string &keyword="")
Aim: Implementation of the linear in time Voronoi map construction.
Board & setPenColor(const DGtal::Color &color)
void clear(const DGtal::Color &color=DGtal::Color::None)
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
MyDigitalSurface::ConstIterator ConstIterator
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
DGtal is the top-level namespace which contains all DGtal functions and types.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Aim: Defines the concept describing a read-only image, which is a refinement of CPointFunctor.
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)
double mynorm(const Point &point, const double p)
Point calcPointModuloDomain(Point aPoint, Domain const &aDomain)
int main(int argc, char **argv)
bool testVoronoiMap(std::array< bool, 2 > const &periodicity={ {false, false} })
bool testSimpleRandom3D()
std::string formatPeriodicity(std::array< bool, N > const &aPeriodicity)
void saveVoroMap(const std::string &filename, const VoroMap &output, const double p)
bool testVoronoiMapFromSites(const Set &aSet)
std::array< bool, N > getPeriodicityFromInteger(std::size_t anInteger)
bool testVoronoiMapFromSites2D(const Set &aSet, const std::string &name, std::array< bool, 2 > const &periodicity={ {false, false} })
bool testSimpleRandom2D()
bool checkVoronoi(const Set &aSet, const Voro &voro)
unsigned int dim(const Vector &z)