DGtal 2.1.0
Loading...
Searching...
No Matches
DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue > Class Template Reference

Aim: Functor that subsamples an initial domain by given a grid size and a shift vector. By this way, for a given point considered in a new domain, it allows to recover the point coordinates in the source domain. Such functor can be usefull to apply basic image subsampling in any dimensions by using ImageAdapter class. More...

#include <DGtal/kernel/BasicPointFunctors.h>

Public Types

typedef TDomain::Space Space
 
typedef TDomain::Size Size
 
typedef TDomain::Integer IntergerDom
 
typedef Space::Dimension Dimension
 
typedef Space::Point Point
 

Public Member Functions

 BasicDomainSubSampler (const TDomain &aSourceDomain, const std::vector< TValue > &aGridSize, const Point &aGridShift)
 
Point operator() (const Point &aPoint) const
 
const TDomain & getSubSampledDomain ()
 

Private Attributes

TDomain mySourceDomain
 
TDomain myNewDomain
 
TDomain myGridSampleDomain
 
Point myGridShift
 
std::vector< TValue > myGridSize
 

Detailed Description

template<typename TDomain, typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
class DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >

Aim: Functor that subsamples an initial domain by given a grid size and a shift vector. By this way, for a given point considered in a new domain, it allows to recover the point coordinates in the source domain. Such functor can be usefull to apply basic image subsampling in any dimensions by using ImageAdapter class.

Description of template class 'BasicDomainSubSampler'

See also
tests/kernel/testBasicPointFunctors.cpp
Template Parameters
TDomainthe type of the domain.
TIntegerspecifies the integer number type used to define the space.
TValuespecify the type of the value which define the grid size (generally type int (default) when subsampling with large grid size and double to re sampling with grid size less than 1).
Examples
images/imageBasicSubsampling.cpp.

Definition at line 644 of file BasicPointFunctors.h.

Member Typedef Documentation

◆ Dimension

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
typedef Space::Dimension DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::Dimension

Definition at line 650 of file BasicPointFunctors.h.

◆ IntergerDom

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
typedef TDomain::Integer DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::IntergerDom

Definition at line 649 of file BasicPointFunctors.h.

◆ Point

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
typedef Space::Point DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::Point

Definition at line 651 of file BasicPointFunctors.h.

◆ Size

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
typedef TDomain::Size DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::Size

Definition at line 648 of file BasicPointFunctors.h.

◆ Space

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
typedef TDomain::Space DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::Space

Definition at line 647 of file BasicPointFunctors.h.

Constructor & Destructor Documentation

◆ BasicDomainSubSampler()

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::BasicDomainSubSampler ( const TDomain &  aSourceDomain,
const std::vector< TValue > &  aGridSize,
const Point aGridShift 
)
inline

Constructor. Construct the functor from a source domain, a grid size, and a shift vector. The points of the resulting domain are defined as the upper left of the sampling grid.

Parameters
aSourceDomainthe source domain.
aGridSizethe subsampling grid size.
aGridShiftthe shift applied to the sampling grid.

Definition at line 664 of file BasicPointFunctors.h.

665 : mySourceDomain(aSourceDomain),
666 myGridShift(aGridShift),
667 myGridSize(aGridSize)
668 {
669 Point domainUpperBound=aSourceDomain.upperBound();
670 Point domainLowerBound=aSourceDomain.lowerBound();
671
672 for (Dimension dim=0; dim< Space::dimension; dim++){
673 domainLowerBound[dim] = static_cast<IntergerDom>(floor(NumberTraits<IntergerDom>::castToDouble(domainLowerBound[dim]) /
675 domainUpperBound[dim] = static_cast<IntergerDom>(floor(NumberTraits<IntergerDom>::castToDouble(domainUpperBound[dim]) /
677 }
678 myNewDomain = TDomain(domainLowerBound,
679 domainUpperBound);
680 Point upperGrid;
681 for (Dimension dim=0; dim < Space::dimension; dim++)
682 upperGrid[dim] = myGridSize[dim];
683 myGridSampleDomain = TDomain(Point::diagonal(0), upperGrid);
684 };
static double castToDouble(const std::decay< T >::type &aT)
Cast method to double (for I/O or board export uses only).

References dim, DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::myGridSampleDomain, DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::myGridSize, and DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::myNewDomain.

Member Function Documentation

◆ getSubSampledDomain()

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
const TDomain & DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::getSubSampledDomain ( )
inline

This method can be usefull to directely recover the new domain associated to the resulting subsampled domain.

Returns
the new subsampled domain.
Examples
images/imageBasicSubsampling.cpp.

Definition at line 733 of file BasicPointFunctors.h.

733 {
734 return myNewDomain;
735 }

References DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::myNewDomain.

Referenced by main().

◆ operator()()

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
Point DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::operator() ( const Point aPoint) const
inline

The operator computes the coordinates of the point in the subsampled domain. By default it returns the first lower point of the window associated to the sampling grid. If the resulting point is outside the source domain it scans this window and returns a point belonging to the source domain. If such a point does not exits it return the point with null coordinates.

Parameters
aPointa point which should belong to the new domain.
Returns
the point to be taken in the subsampled domain.

Definition at line 701 of file BasicPointFunctors.h.

702 {
703 Point ptRes = Point::diagonal(0);
704 if(!myNewDomain.isInside(aPoint)){
705 trace.error() << " The point is not in the source domain: "<< aPoint << std::endl;
706 return ptRes;
707 }
708
709 for (Dimension dim=0; dim< Space::dimension; dim++){
710 ptRes[dim] = static_cast<TInteger>(floor(NumberTraits<TInteger>::castToDouble(aPoint[dim])*
712 }
713 ptRes +=myGridShift;
714
715 if(!mySourceDomain.isInside(ptRes)){
716 // we are looking for a point inside the domain
717 for(typename TDomain::ConstIterator it = myGridSampleDomain.begin();
718 it!= myGridSampleDomain.end(); it++){
719 if (mySourceDomain.isInside(ptRes+(*it)))
720 return ptRes+(*it);
721 }
722 }
723 return ptRes;
724 }
std::ostream & error()
Trace trace
const Point aPoint(3, 4)

References aPoint, dim, DGtal::Trace::error(), DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::myGridSampleDomain, DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::myGridShift, DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::myGridSize, DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::myNewDomain, DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::mySourceDomain, and DGtal::trace.

Field Documentation

◆ myGridSampleDomain

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
TDomain DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::myGridSampleDomain
private

◆ myGridShift

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
Point DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::myGridShift
private

◆ myGridSize

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
std::vector<TValue> DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::myGridSize
private

◆ myNewDomain

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
TDomain DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::myNewDomain
private

◆ mySourceDomain

template<typename TDomain , typename TInteger = DGtal::int32_t, typename TValue = typename TDomain::Size>
TDomain DGtal::functors::BasicDomainSubSampler< TDomain, TInteger, TValue >::mySourceDomain
private

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