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"
39 template <
typename TPo
int,
typename TDomain >
41 typename TPoint::Scalar unary_kernel( TPoint
const& pt, TDomain
const&,
typename TPoint::Scalar cst )
43 return cst * pt.norm();
46 template <
typename TPo
int,
typename TDomain>
48 typename TPoint::Scalar binary_kernel( TPoint
const& pt, TDomain
const&
domain,
typename TPoint::Scalar cst )
50 return cst * (pt -
domain.lowerBound()).norm();
53 template <
typename TImage,
typename TFunction >
54 void 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);
121 TEST_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) );
134 TEST_CASE(
"2D Image from binary functor by rvalue",
"[2D][functor][binary][rvalue]" )
136 using namespace DGtal;
142 const double cst = 3.5;
147 TEST_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);
161 TEST_CASE(
"2D Image from binary lambda by rvalue",
"[2D][lambda][binary][rvalue]" )
163 using namespace DGtal;
169 const double cst = 3.5;
174 TEST_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); };
auto holdConstImageFunctor(TDomain const &aDomain, TFunctor &&aFunctor) -> ConstImageFunctorHolder< TDomain, TValue, decltype(holdFunctor(std::forward< TFunctor >(aFunctor)))>
ConstImageFunctorHolder construction helper with specification of the return type.
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.
bool checkImage(const Image &a, const Image &b)
TEST_CASE("int container traits", "[int][traits]")
ImageContainerBySTLVector< Domain, Value > Image
HyperRectDomain< Space > Domain
REQUIRE(domain.isInside(aPoint))