34#include "DGtal/base/Common.h"
35#include "DGtal/helpers/StdDefs.h"
36#include "DGtal/geometry/volumes/distance/PowerMap.h"
37#include "DGtal/geometry/volumes/distance/ExactPredicateLpPowerSeparableMetric.h"
38#include "DGtal/geometry/volumes/distance/ReverseDistanceTransformation.h"
39#include "DGtal/kernel/sets/DigitalSetDomain.h"
40#include "DGtal/images/ImageContainerBySTLMap.h"
41#include "DGtal/images/ImageContainerBySTLVector.h"
42#include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
62template < std::
size_t N >
65 std::array<bool, N> periodicity;
66 for ( std::size_t i = 0, mask = 1 ; i < N ; ++i, mask *= 2 )
67 periodicity[i] = anInteger & mask;
78template < std::
size_t N >
82 for ( std::size_t i = 0; i < N; ++i )
83 str += aPeriodicity[i] ?
'1' :
'0';
90template <
typename PowerMap>
96 Point const extent = aPowerMap.
domain().upperBound() - aPowerMap.
domain().lowerBound() + Point::diagonal();
99 std::vector< typename PowerMap::PeriodicitySpec > periodicShift;
100 for ( std::size_t i = 0; i < ( 1u << PowerMap::Space::dimension ); ++i )
102 const auto periodicity = getPeriodicityFromInteger< PowerMap::Space::dimension >( i );
106 for ( std::size_t j = 0; j < periodicity.size(); ++j )
107 if ( periodicity[j] && ! aPowerMap.
isPeriodic(j) )
114 periodicShift.push_back( periodicity );
121 auto const& metric = *(aPowerMap.
metricPtr());
125 for (
auto const& pt : image.domain() )
130 for (
auto const& pt : aPowerMap.
domain() )
133 const Point psite = aPowerMap(pt);
138 if ( std::find( aSet.
begin(), aSet.
end(), boundedPSite ) == aSet.
end() )
140 trace.
error() <<
"The PowerMap point " << psite
142 <<
" is not a valid site." << std::endl;
147 const auto dist = metric.powerDistance( pt, psite, image( boundedPSite ) );
150 for (
auto site : aSet )
153 for (
auto const & periodicity : periodicShift )
155 auto currSite = site;
158 for ( std::size_t
dim = 0;
dim < PowerMap::Space::dimension ; ++
dim )
159 if ( periodicity[
dim] )
160 currSite[
dim] += ( pt[
dim] < currSite[
dim] ? -1 : 1 ) * extent[
dim];
163 const auto dbis = metric.powerDistance( pt, currSite, image( site ) );
167 <<
" PowerMap:" << psite <<
"@" << image(boundedPSite) <<
" (" << dist <<
")"
168 <<
" from set:" << site <<
"@" << image(site) <<
" (" << dbis <<
")"
169 <<
" projected from " << currSite <<
"." << std::endl;
183bool testPowerMap( std::array<bool, 2>
const& aPeriodicity = {{
false,
false }} )
185 unsigned int nbok = 0;
201 Image image(
new SetDomain( set ) );
210 for(
unsigned int i=0; i<11; i++)
212 for(
unsigned int j=0; j<11; j++)
222 for(
unsigned int i=0; i<11; i++)
224 for(
unsigned int j=0; j<11; j++)
239 for(
unsigned int i=0; i<11; i++)
241 for(
unsigned int j=0; j<11; j++)
248 std::cerr<<std::endl;
253 for(
unsigned int i=0; i<11; i++)
255 for(
unsigned int j=0; j<11; j++)
265 std::cerr<<std::endl;
270 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
271 <<
"true == true" << std::endl;
288template <
typename Set >
291 std::array<bool, Set::dimension> periodicity;
292 periodicity.fill(
false );
296template <
typename Set >
299 unsigned int nbok = 0;
306 Image image(
new SetDomain( aSet ) );
310 for (
auto const & pt : image.domain() )
312 image.setValue( pt, weight );
320 Power2 power2( aSet.domain(), image, l2, periodicity);
332 Power3 power3( aSet.domain(), image, l3, periodicity);
342 RDT rdt(aSet.domain(), power2.weightImagePtr(), l2, periodicity);
362 for ( std::size_t i = 0; i < 4; ++i )
364 auto const periodicity = getPeriodicityFromInteger<2>(i);
388 for ( std::size_t i = 0; i < 8; ++i )
390 auto const periodicity = getPeriodicityFromInteger<3>(i);
403 Space4::Point a(0,0,0,0);
404 Space4::Point b(5,5,5,5);
410 sites.
insertNew( Space4::Point(1,4,1,1));
411 sites.
insertNew( Space4::Point(3,1,3,1));
412 sites.
insertNew( Space4::Point(0,0,0,0));
414 for ( std::size_t i = 0; i < 16; ++i )
416 auto const periodicity = getPeriodicityFromInteger<4>(i);
428int main(
int argc,
char** argv )
432 for (
int i = 0; i < argc; ++i )
446 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: A container class for storing sets of digital points within some given domain.
ConstIterator end() const
void insertNew(const Point &p)
ConstIterator begin() const
Aim: Constructs a domain limited to the given digital set.
Aim: implements weighted separable l_p metrics with exact predicates.
Aim: implements association bewteen points lying in a digital domain and values.
Aim: Implementation of the linear in time Power map construction.
const WeightImage * weightImagePtr() const
Point projectPoint(Point aPoint) const
bool isPeriodic(const Dimension n) const
const Domain & domain() const
const PowerSeparableMetric * metricPtr() const
void beginBlock(const std::string &keyword="")
ExactPredicateLpPowerSeparableMetric< Space, 2 > L2PowerMetric
T power(const T &aVal, const unsigned int exponent)
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
boost::int32_t int32_t
signed 32-bit integer.
Aim: Defines the concept describing a read-only image, which is a refinement of CPointFunctor.
std::string formatPeriodicity(std::array< bool, N > const &aPeriodicity)
std::array< bool, N > getPeriodicityFromInteger(std::size_t anInteger)
bool checkPowerMap(const PowerMap &aPowerMap)
bool testPowerMapFromSites(const Set &aSet)
bool testPowerMap(std::array< bool, 2 > const &aPeriodicity={{ false, false }})