DGtal 1.3.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes
DGtal::EstimatorCache< TEstimator, TContainer > Class Template Reference

Aim: this class adapts any local surface estimator to cache the estimated values in a associative container (Surfel <-> estimated value). More...

#include <DGtal/geometry/surfaces/estimation/EstimatorCache.h>

Public Types

typedef TEstimator Estimator
 Estimator type. More...
 
typedef TContainer Container
 Container type. More...
 
typedef Estimator::Surfel Surfel
 Surfel type. More...
 
typedef Estimator::Quantity Quantity
 Quantity type. More...
 
typedef EstimatorCache< Estimator, ContainerSelf
 Self. More...
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CSurfelLocalEstimator< TEstimator >))
 
 BOOST_CONCEPT_ASSERT ((boost::PairAssociativeContainer< TContainer >))
 
 EstimatorCache ()
 
 EstimatorCache (Alias< Estimator > anEstimator)
 
 ~EstimatorCache ()
 
 EstimatorCache (const Self &other)
 
Selfoperator= (const Self &other)
 
template<typename SurfelConstIterator >
void init (const double aH, SurfelConstIterator itb, SurfelConstIterator ite)
 
template<typename SurfelConstIterator >
Quantity eval (const SurfelConstIterator it) const
 
Quantity eval (const Surfel s) const
 
template<typename SurfelConstIterator , typename OutputIterator >
OutputIterator eval (SurfelConstIterator itb, SurfelConstIterator ite, OutputIterator result) const
 
double h () const
 
Container::size_type size () const
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 

Private Attributes

Container myContainer
 Instance of estimator. More...
 
EstimatormyEstimator
 Alias of the estimator. More...
 
bool myInit
 Init flag. More...
 

Detailed Description

template<typename TEstimator, typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
class DGtal::EstimatorCache< TEstimator, TContainer >

Aim: this class adapts any local surface estimator to cache the estimated values in a associative container (Surfel <-> estimated value).

Description of template class 'EstimatorCache'

The use-case of this class is when you want to estimate the same quantity several times.

This class implements eval() methods for surfel iterators as in concepts::CSurfelLocalEstimator concept. Addtitionnaly, we also have an eval method from a surfel.

This class is also a model of concepts::CSurfelLocalEstimator

See also
testEstimatorCache.cpp
Template Parameters
TEstimatorany model of CSurfelLocalEstimator
TContainerthe associative container to use (default type: std::map<Surfel,Quantity>)

Definition at line 77 of file EstimatorCache.h.

Member Typedef Documentation

◆ Container

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
typedef TContainer DGtal::EstimatorCache< TEstimator, TContainer >::Container

Container type.

Definition at line 88 of file EstimatorCache.h.

◆ Estimator

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
typedef TEstimator DGtal::EstimatorCache< TEstimator, TContainer >::Estimator

Estimator type.

Definition at line 84 of file EstimatorCache.h.

◆ Quantity

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
typedef Estimator::Quantity DGtal::EstimatorCache< TEstimator, TContainer >::Quantity

Quantity type.

Definition at line 97 of file EstimatorCache.h.

◆ Self

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
typedef EstimatorCache<Estimator,Container> DGtal::EstimatorCache< TEstimator, TContainer >::Self

Self.

Definition at line 100 of file EstimatorCache.h.

◆ Surfel

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
typedef Estimator::Surfel DGtal::EstimatorCache< TEstimator, TContainer >::Surfel

Surfel type.

Definition at line 94 of file EstimatorCache.h.

Constructor & Destructor Documentation

◆ EstimatorCache() [1/3]

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
DGtal::EstimatorCache< TEstimator, TContainer >::EstimatorCache ( )
inline

Default constructor.

Definition at line 105 of file EstimatorCache.h.

105 : myInit(false)
106 {}
bool myInit
Init flag.

◆ EstimatorCache() [2/3]

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
DGtal::EstimatorCache< TEstimator, TContainer >::EstimatorCache ( Alias< Estimator anEstimator)
inline

Constructor from estimator instance.

Definition at line 112 of file EstimatorCache.h.

112 : myEstimator(&anEstimator),
113 myInit(false)
114 {}
Estimator * myEstimator
Alias of the estimator.

◆ ~EstimatorCache()

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
DGtal::EstimatorCache< TEstimator, TContainer >::~EstimatorCache ( )
inline

Destructor.

Definition at line 119 of file EstimatorCache.h.

120 {}

◆ EstimatorCache() [3/3]

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
DGtal::EstimatorCache< TEstimator, TContainer >::EstimatorCache ( const Self other)
inline

Copy constructor.

Definition at line 125 of file EstimatorCache.h.

125 : myContainer(other.myContainer),
126 myEstimator(other.myEstimator),
127 myInit(other.myInit)
128 {}
Container myContainer
Instance of estimator.

Member Function Documentation

◆ BOOST_CONCEPT_ASSERT() [1/2]

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
DGtal::EstimatorCache< TEstimator, TContainer >::BOOST_CONCEPT_ASSERT ( (boost::PairAssociativeContainer< TContainer >)  )

◆ BOOST_CONCEPT_ASSERT() [2/2]

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
DGtal::EstimatorCache< TEstimator, TContainer >::BOOST_CONCEPT_ASSERT ( (concepts::CSurfelLocalEstimator< TEstimator >)  )

◆ eval() [1/3]

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
Quantity DGtal::EstimatorCache< TEstimator, TContainer >::eval ( const Surfel  s) const
inline

Cached evaluation of the estimator at a surfel s

Precondition
init() method must have been called first.
Parameters
[in]sthe iterator to the surfel to estimate.
Returns
the estimated quantity.

Definition at line 197 of file EstimatorCache.h.

198 {
199 ASSERT_MSG(myInit, " init() method must have been called first.");
200 return myContainer.find( s )->second;
201 }

References DGtal::EstimatorCache< TEstimator, TContainer >::myContainer, and DGtal::EstimatorCache< TEstimator, TContainer >::myInit.

◆ eval() [2/3]

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
template<typename SurfelConstIterator >
Quantity DGtal::EstimatorCache< TEstimator, TContainer >::eval ( const SurfelConstIterator  it) const
inline

Cached evaluation of the estimator at iterator it

Precondition
init() method must have been called first.
Template Parameters
SurfelConstIteratora const iterator on surfels.
Parameters
[in]itthe iterator to the surfel to estimate.
Returns
the estimated quantity.

Definition at line 183 of file EstimatorCache.h.

184 {
185 ASSERT_MSG(myInit, " init() method must have been called first.");
186 return myContainer.find( *it )->second;
187 }

References DGtal::EstimatorCache< TEstimator, TContainer >::myContainer, and DGtal::EstimatorCache< TEstimator, TContainer >::myInit.

Referenced by DGtal::EstimatorCache< TEstimator, TContainer >::eval().

◆ eval() [3/3]

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
template<typename SurfelConstIterator , typename OutputIterator >
OutputIterator DGtal::EstimatorCache< TEstimator, TContainer >::eval ( SurfelConstIterator  itb,
SurfelConstIterator  ite,
OutputIterator  result 
) const
inline

Cached range evaluation of the estimator between itb and ite.

Precondition
init() method must have been called first.
Template Parameters
SurfelConstIteratora const iterator on surfels.
Parameters
[in]itbthe begin iterator to the surfel to estimate.
[in]itethe end iterator to the surfel to estimate.
[in]resultan output iterator on the result.
Returns
the estimated quantity.

Definition at line 218 of file EstimatorCache.h.

221 {
222 ASSERT_MSG(myInit, " init() method must have been called first.");
223 for(SurfelConstIterator it = itb; it != ite; ++it)
224 *result++ = this->eval(it);
225
226 return result;
227 }
Quantity eval(const SurfelConstIterator it) const

References DGtal::EstimatorCache< TEstimator, TContainer >::eval(), and DGtal::EstimatorCache< TEstimator, TContainer >::myInit.

◆ h()

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
double DGtal::EstimatorCache< TEstimator, TContainer >::h ( ) const
inline
Returns
the gridstep.
Precondition
init() method must have been called first.

Definition at line 236 of file EstimatorCache.h.

237 {
238 return myEstimator->h();
239 }

References DGtal::EstimatorCache< TEstimator, TContainer >::myEstimator.

◆ init()

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
template<typename SurfelConstIterator >
void DGtal::EstimatorCache< TEstimator, TContainer >::init ( const double  aH,
SurfelConstIterator  itb,
SurfelConstIterator  ite 
)
inline

Estimator initialization. This method initializes the underlying estimator and caches all estimated quantity between itb and ite.

Template Parameters
SurfelConstIteratora const iterator on surfels.
Parameters
[in]aHthe gridstep
[in]iteiterator on the first surfel of the surface.
[in]itbiterator after the last surfel of the surface.

Definition at line 158 of file EstimatorCache.h.

159 {
160 ASSERT(myEstimator);
161 myEstimator->init(aH,itb,ite);
162 myContainer.clear();
163
164 //We estimate and store the quantities
165 //(since SurfelConstIterator models are usually SinglePass, we
166 //cannot use the optimized "range" eval on the estimator)
167 for(SurfelConstIterator it = itb; it != ite; ++it)
168 myContainer.insert( std::pair<Surfel, Quantity>(*it, myEstimator->eval(it) ) );
169
170 myInit = true;
171 }

References DGtal::EstimatorCache< TEstimator, TContainer >::myContainer, DGtal::EstimatorCache< TEstimator, TContainer >::myEstimator, and DGtal::EstimatorCache< TEstimator, TContainer >::myInit.

◆ isValid()

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
bool DGtal::EstimatorCache< TEstimator, TContainer >::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 267 of file EstimatorCache.h.

268 {
269 return myEstimator && myEstimator->isValid();
270 }

References DGtal::EstimatorCache< TEstimator, TContainer >::myEstimator.

◆ operator=()

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
Self & DGtal::EstimatorCache< TEstimator, TContainer >::operator= ( const Self other)
inline

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'. Forbidden by default.

Definition at line 136 of file EstimatorCache.h.

137 {
138 myContainer = other.myContainer;
139 myEstimator = other.myEstimator;
140 myInit = other.myInit;
141
142 return *this;
143 }

References DGtal::EstimatorCache< TEstimator, TContainer >::myContainer, DGtal::EstimatorCache< TEstimator, TContainer >::myEstimator, and DGtal::EstimatorCache< TEstimator, TContainer >::myInit.

◆ selfDisplay()

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
void DGtal::EstimatorCache< TEstimator, TContainer >::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 258 of file EstimatorCache.h.

259 {
260 out<< "[EstimatorCache] number of surfels="<<myContainer.size();
261 }

References DGtal::EstimatorCache< TEstimator, TContainer >::myContainer.

◆ size()

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
Container::size_type DGtal::EstimatorCache< TEstimator, TContainer >::size ( ) const
inline
Precondition
init() method must have been called first.
Returns
the number of cached elements.

Definition at line 248 of file EstimatorCache.h.

249 {
250 ASSERT_MSG(myInit, " init() method must have been called first.");
251 return myContainer.size();
252 }

References DGtal::EstimatorCache< TEstimator, TContainer >::myContainer, and DGtal::EstimatorCache< TEstimator, TContainer >::myInit.

Field Documentation

◆ myContainer

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
Container DGtal::EstimatorCache< TEstimator, TContainer >::myContainer
private

◆ myEstimator

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
Estimator* DGtal::EstimatorCache< TEstimator, TContainer >::myEstimator
private

◆ myInit

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
bool DGtal::EstimatorCache< TEstimator, TContainer >::myInit
private

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