DGtal  1.5.beta
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 = std::reverse_iterator< ConstIterator >
 

Public Member Functions

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

Private Member Functions

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

Private Attributes

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

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 ); }
);
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.
MyPointD Point
Definition: testClone2.cpp:383
HyperRectDomain< Space > Domain

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.

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 103 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 122 of file ConstImageFunctorHolder.h.

◆ ConstReverseIterator

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

Definition at line 123 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 117 of file ConstImageFunctorHolder.h.

◆ Domain

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

Definition at line 112 of file ConstImageFunctorHolder.h.

◆ Functor

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

Definition at line 120 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 115 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 113 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 111 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 116 of file ConstImageFunctorHolder.h.

◆ Value

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

Definition at line 119 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 114 of file ConstImageFunctorHolder.h.

◆ Vertex

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

Definition at line 118 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 143 of file ConstImageFunctorHolder.h.

144  : myDomain( aDomain )
145  , myFunctor( std::forward<TGivenFunctor>(aFunctor) )
146  {
147  }
Functor myFunctor
The functor that generates the image.

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 197 of file ConstImageFunctorHolder.h.

198  {
199  return ConstRange( *this );
200  }
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 154 of file ConstImageFunctorHolder.h.

155  {
156  return myDomain;
157  }

References DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::myDomain.

◆ isValid()

template<typename TDomain , typename TValue , typename TFunctor >
constexpr 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 215 of file ConstImageFunctorHolder.h.

216  {
217  return true;
218  }

◆ 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 170 of file ConstImageFunctorHolder.h.

172  {
173  ASSERT_MSG(
174  myDomain.isInside(aPoint),
175  "The point is outside the domain."
176  );
177  return myFunctor( aPoint );
178  }
const Point aPoint(3, 4)

References aPoint(), DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::myDomain, and DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::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 182 of file ConstImageFunctorHolder.h.

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

References aPoint(), DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::myDomain, and DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::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 206 of file ConstImageFunctorHolder.h.

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

References DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::myDomain, and DGtal::functors::ConstImageFunctorHolder< TDomain, TValue, TFunctor >::myFunctor.

Field Documentation

◆ myDomain

◆ myFunctor

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

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