File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor > Class Template Reference

Transform a point-dependent (and possibly domain-dependent) functor into a constant image. More...

#include <DGtal/images/ConstImageFunctorHolder.h>

Data Structures

class  ConstRange
 Constant range on a ConstImageFunctorHolder. More...

Public Types

using Self = ConstImageFunctorHolder<TDomain, TValue, TFunctor>
using Domain = TDomain
using Point = typename Domain::Point
using Vector = typename Domain::Vector
using Integer = typename Domain::Integer
using Size = typename Domain::Size
using Dimension = typename Domain::Dimension
using Vertex = Point
using Value = TValue
using Functor = TFunctor
using ConstIterator = boost::transform_iterator< std::reference_wrapper<const Self>, typename Domain::ConstIterator >
using ConstReverseIterator = boost::reverse_iterator< ConstIterator >

Public Member Functions

 BOOST_STATIC_CONSTANT (Dimension, dimension=Domain::Space::dimension)
template<class TGivenFunctor>
 ConstImageFunctorHolder (Domain const &aDomain, TGivenFunctor &&aFunctor)
 Constructor.
Domain const & domain () const
 Returns the associated domain.
template<typename TPoint>
auto operator() (TPoint const &aPoint) const -> decltype(myFunctor(aPoint))
 Evaluates the functor at the given point.
template<typename TPoint>
auto operator() (TPoint const &aPoint) const -> decltype(myFunctor(aPoint, myDomain))
ConstRange constRange () const
 Returns a constant range over this image.
void selfDisplay (std::ostream &out) const
 Writes/Displays the object on an output stream.
constexpr bool isValid () const
 Checks the validity/consistency of the object.

Private Member Functions

 BOOST_CONCEPT_ASSERT ((DGtal::concepts::CDomain< TDomain >))

Private Attributes

Domain myDomain
 The image domain.
Functor myFunctor
 The functor that generates the image.

Detailed Description

template<typename TDomain, typename TValue, typename TFunctor>
class DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >

Transform a point-dependent (and possibly domain-dependent) functor into a constant image.

Template Parameters
TDomainDomain type.
TValueValue type returned by the functor.
TFunctorType of the functor.

The functor must accept a point, and eventually a domain, and return a value whose type is Value.

Warning
This class is not meant to be directly constructed by the user. As illustrated below, use instead the holdConstImageFunctor helper that will choose the more appropriate storage type for the functor depending on the given callable object.

A typical usage would be:

const Domain domain1(Point(1,1), Point(16,16));
domain1,
[] (Point const& pt) { return 25 * ( std::cos( (pt - Point(4,4)).norm() ) + 1 ); }
);

resulting in:

Image generated from a point-dependent lambda.

In you want to use a function instead of a functor or lambda, consider wrapping it into a lambda to avoid a performance penalty due to the fact that a pointer to a function cannot be inlined:

auto image = DGtal::holdConstImageFunctor(
[] (Point const& pt) { return my_function(pt); }
);
Domain const & domain() const
Returns the associated domain.
Image image(domain)

This example is illustrated in Constant image from a function, functor or lambda and you can find more informations about how to use this class appropriately in the module about Using functions, functors and lambdas in DGtal .

See also
holdConstImageFunctor, FunctorHolder, Using functions, functors and lambdas in DGtal
exampleConstImageFunctorHolder.cpp

Definition at line 104 of file ConstImageFunctorHolder.h.

Member Typedef Documentation

◆ ConstIterator

template<typename TDomain, typename TValue, typename TFunctor>
using DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::ConstIterator = boost::transform_iterator< std::reference_wrapper<const Self>, typename Domain::ConstIterator >

Definition at line 123 of file ConstImageFunctorHolder.h.

◆ ConstReverseIterator

template<typename TDomain, typename TValue, typename TFunctor>
using DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::ConstReverseIterator = boost::reverse_iterator< ConstIterator >

Definition at line 124 of file ConstImageFunctorHolder.h.

◆ Dimension

template<typename TDomain, typename TValue, typename TFunctor>
using DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::Dimension = typename Domain::Dimension

Definition at line 118 of file ConstImageFunctorHolder.h.

◆ Domain

template<typename TDomain, typename TValue, typename TFunctor>
using DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::Domain = TDomain

Definition at line 113 of file ConstImageFunctorHolder.h.

◆ Functor

template<typename TDomain, typename TValue, typename TFunctor>
using DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::Functor = TFunctor

Definition at line 121 of file ConstImageFunctorHolder.h.

◆ Integer

template<typename TDomain, typename TValue, typename TFunctor>
using DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::Integer = typename Domain::Integer

Definition at line 116 of file ConstImageFunctorHolder.h.

◆ Point

template<typename TDomain, typename TValue, typename TFunctor>
using DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::Point = typename Domain::Point

Definition at line 114 of file ConstImageFunctorHolder.h.

◆ Self

template<typename TDomain, typename TValue, typename TFunctor>
using DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::Self = ConstImageFunctorHolder<TDomain, TValue, TFunctor>

Definition at line 112 of file ConstImageFunctorHolder.h.

◆ Size

template<typename TDomain, typename TValue, typename TFunctor>
using DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::Size = typename Domain::Size

Definition at line 117 of file ConstImageFunctorHolder.h.

◆ Value

template<typename TDomain, typename TValue, typename TFunctor>
using DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::Value = TValue

Definition at line 120 of file ConstImageFunctorHolder.h.

◆ Vector

template<typename TDomain, typename TValue, typename TFunctor>
using DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::Vector = typename Domain::Vector

Definition at line 115 of file ConstImageFunctorHolder.h.

◆ Vertex

template<typename TDomain, typename TValue, typename TFunctor>
using DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::Vertex = Point

Definition at line 119 of file ConstImageFunctorHolder.h.

Constructor & Destructor Documentation

◆ ConstImageFunctorHolder()

template<typename TDomain, typename TValue, typename TFunctor>
template<class TGivenFunctor>
DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::ConstImageFunctorHolder ( Domain const & aDomain,
TGivenFunctor && aFunctor )
inlineexplicit

Constructor.

Parameters
aDomainThe domain of the image.
aFunctorThe functor taking point as parameter.

Definition at line 144 of file ConstImageFunctorHolder.h.

145 : myDomain( aDomain )
147 {
148 }
Transform a point-dependent (and possibly domain-dependent) functor into a constant image.
Functor myFunctor
The functor that generates the image.

References myDomain, and myFunctor.

Member Function Documentation

◆ BOOST_CONCEPT_ASSERT()

template<typename TDomain, typename TValue, typename TFunctor>
DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::BOOST_CONCEPT_ASSERT ( (DGtal::concepts::CDomain< TDomain >) )
private

◆ BOOST_STATIC_CONSTANT()

template<typename TDomain, typename TValue, typename TFunctor>
DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::BOOST_STATIC_CONSTANT ( Dimension ,
dimension = Domain::Space::dimension )

◆ constRange()

template<typename TDomain, typename TValue, typename TFunctor>
ConstRange DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::constRange ( ) const
inline

Returns a constant range over this image.

Definition at line 198 of file ConstImageFunctorHolder.h.

199 {
200 return ConstRange( *this );
201 }
Image::ConstRange ConstRange

◆ domain()

template<typename TDomain, typename TValue, typename TFunctor>
Domain const & DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::domain ( ) const
inline

Returns the associated domain.

Definition at line 155 of file ConstImageFunctorHolder.h.

156 {
157 return myDomain;
158 }

References myDomain.

◆ isValid()

template<typename TDomain, typename TValue, typename TFunctor>
bool DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::isValid ( ) const
inlineconstexpr

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

Definition at line 216 of file ConstImageFunctorHolder.h.

217 {
218 return true;
219 }

◆ operator()() [1/2]

template<typename TDomain, typename TValue, typename TFunctor>
template<typename TPoint>
auto DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::operator() ( TPoint const & aPoint) const -> decltype( myFunctor( aPoint ) )
inline

Evaluates the functor at the given point.

Template Parameters
TPointpoint type (auto-deduced).
Parameters
aPointthe point.
Returns
the value at aPoint.
Note
There are two overloads of this operator, automatically dispatched depending on the arity of the functor.

Definition at line 171 of file ConstImageFunctorHolder.h.

173 {
175 myDomain.isInside(aPoint),
176 "The point is outside the domain."
177 );
178 return myFunctor( aPoint );
179 }

References aPoint, myDomain, and myFunctor.

◆ operator()() [2/2]

template<typename TDomain, typename TValue, typename TFunctor>
template<typename TPoint>
auto DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::operator() ( TPoint const & aPoint) const -> decltype( myFunctor( aPoint, myDomain ) )
inline

Definition at line 183 of file ConstImageFunctorHolder.h.

185 {
187 myDomain.isInside(aPoint),
188 "The point is outside the domain."
189 );
190 return myFunctor( aPoint, myDomain );
191 }

References aPoint, myDomain, and myFunctor.

◆ selfDisplay()

template<typename TDomain, typename TValue, typename TFunctor>
void DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::selfDisplay ( std::ostream & out) const
inline

Writes/Displays the object on an output stream.

Parameters
outthe output stream where the object is written.

Definition at line 207 of file ConstImageFunctorHolder.h.

208 {
209 out << "[ConstImageFunctorHolder] holding a " << myFunctor << " on domain " << myDomain;
210 }

References myDomain, and myFunctor.

Field Documentation

◆ myDomain

template<typename TDomain, typename TValue, typename TFunctor>
Domain DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::myDomain
private

The image domain.

Definition at line 133 of file ConstImageFunctorHolder.h.

Referenced by ConstImageFunctorHolder(), domain(), operator()(), operator()(), and selfDisplay().

◆ myFunctor

template<typename TDomain, typename TValue, typename TFunctor>
Functor DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::myFunctor
private

The functor that generates the image.

Definition at line 134 of file ConstImageFunctorHolder.h.

Referenced by ConstImageFunctorHolder(), operator()(), operator()(), and selfDisplay().


The documentation for this class was generated from the following file: