31#include "DGtal/kernel/SpaceND.h"
32#include "DGtal/kernel/domains/HyperRectDomain.h"
33#include "DGtal/images/CConstImage.h"
35#include "DGtal/images/ConstImageFunctorHolder.h"
37#include "DGtalCatch.h"
39template <
typename TPo
int,
typename TDomain >
41typename TPoint::Scalar unary_kernel( TPoint
const& pt, TDomain
const&,
typename TPoint::Scalar cst )
43 return cst * pt.norm();
46template <
typename TPo
int,
typename TDomain>
48typename TPoint::Scalar binary_kernel( TPoint
const& pt, TDomain
const&
domain,
typename TPoint::Scalar cst )
50 return cst * (pt -
domain.lowerBound()).norm();
53template <
typename TImage,
typename TFunction >
54void checkImage( TImage
const& anImage, TFunction
const& fn )
67 std::cout << anImage << std::endl;
71 for (
auto const& pt :
domain )
76 auto pt_it =
domain.begin();
77 auto im_it = anImage.constRange().begin();
78 for ( ; pt_it !=
domain.end(); ++pt_it, ++im_it )
81 REQUIRE( im_it == anImage.constRange().end() );
86 auto pt_it =
domain.rbegin();
87 auto im_it = anImage.constRange().rbegin();
88 for ( ; pt_it !=
domain.rend(); ++pt_it, ++im_it )
91 REQUIRE( im_it == anImage.constRange().rend() );
99 explicit UnaryFunctor(
double c) : cst(c) {}
101 template <
typename Po
int>
102 double operator() (
Point const& pt)
const
104 return unary_kernel(pt, 0, cst);
112 explicit BinaryFunctor(
double c) : cst(c) {}
114 template <
typename Po
int,
typename Domain>
115 double operator() (
Point const& pt,
Domain const &d)
const
117 return binary_kernel(pt, d, cst);
121TEST_CASE(
"2D Image from unary functor by rvalue",
"[2D][functor][unary][rvalue]" )
123 using namespace DGtal;
129 const double cst = 3.5;
130 auto image = functors::holdConstImageFunctor<double>(
domain, UnaryFunctor(cst) );
131 checkImage(image, [&cst] (
Point pt,
Domain d) {
return unary_kernel(pt, d, cst); });
134TEST_CASE(
"2D Image from binary functor by rvalue",
"[2D][functor][binary][rvalue]" )
136 using namespace DGtal;
142 const double cst = 3.5;
143 auto image = functors::holdConstImageFunctor(
domain, BinaryFunctor(cst) );
144 checkImage(image, [&cst] (
Point pt,
Domain d) {
return binary_kernel(pt, d, cst); });
147TEST_CASE(
"2D Image from binary functor by lvalue",
"[2D][functor][binary][lvalue]" )
149 using namespace DGtal;
155 const double cst = 3.5;
156 const auto fn = BinaryFunctor(cst);
157 auto image = functors::holdConstImageFunctor(
domain, fn );
158 checkImage(image, [&cst] (
Point pt,
Domain d) {
return binary_kernel(pt, d, cst); });
161TEST_CASE(
"2D Image from binary lambda by rvalue",
"[2D][lambda][binary][rvalue]" )
163 using namespace DGtal;
169 const double cst = 3.5;
170 auto image = functors::holdConstImageFunctor(
domain, [cst] (
Point const& pt,
Domain const& d) {
return binary_kernel(pt, d, cst); } );
171 checkImage(image, [&cst] (
Point pt,
Domain d) {
return binary_kernel(pt, d, cst); });
174TEST_CASE(
"2D Image from binary std::function by lvalue",
"[2D][function][binary][lvalue]" )
176 using namespace DGtal;
182 const double cst = 3.5;
183 std::function<double(
Point,
Domain)> fn = [cst] (
Point const& pt,
Domain const& d) {
return binary_kernel(pt, d, cst); };
184 auto image = functors::holdConstImageFunctor(
domain, fn );
185 checkImage(image, [&cst] (
Point pt,
Domain d) {
return binary_kernel(pt, d, cst); });
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: Defines the concept describing a read-only image, which is a refinement of CPointFunctor.
TEST_CASE("int container traits", "[int][traits]")
ImageContainerBySTLVector< Domain, Value > Image
HyperRectDomain< Space > Domain
REQUIRE(domain.isInside(aPoint))