DGtal  0.9.3beta
Public Types | Public Member Functions | Private Attributes
DGtal::EstimatorCache< TEstimator, TContainer > Class Template Reference

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

Public Types

typedef TEstimator Estimator
 
typedef TContainer Container
 
typedef Estimator::Surfel Surfel
 
typedef Estimator::Quantity Quantity
 
typedef EstimatorCache< Estimator, ContainerSelf
 

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
 
EstimatormyEstimator
 
bool myInit
 

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

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.

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.

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.

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.

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

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.
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  {}
bool myInit
Init flag.
Estimator * myEstimator
Alias of the estimator.
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  {}
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  {}
bool myInit
Init flag.
Container myContainer
Instance of estimator.
Estimator * myEstimator
Alias of the estimator.

Member Function Documentation

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
DGtal::EstimatorCache< TEstimator, TContainer >::BOOST_CONCEPT_ASSERT ( (concepts::CSurfelLocalEstimator< TEstimator >)  )
template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
DGtal::EstimatorCache< TEstimator, TContainer >::BOOST_CONCEPT_ASSERT ( (boost::PairAssociativeContainer< TContainer >)  )
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.

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

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

184  {
185  ASSERT_MSG(myInit, " init() method must have been called first.");
186  return myContainer.find( *it )->second;
187  }
bool myInit
Init flag.
Container myContainer
Instance of estimator.
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.

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

198  {
199  ASSERT_MSG(myInit, " init() method must have been called first.");
200  return myContainer.find( s )->second;
201  }
bool myInit
Init flag.
Container myContainer
Instance of estimator.
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.

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

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  }
bool myInit
Init flag.
Quantity eval(const SurfelConstIterator it) const
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.

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

237  {
238  return myEstimator->h();
239  }
Estimator * myEstimator
Alias of the estimator.
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.

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

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  }
bool myInit
Init flag.
Container myContainer
Instance of estimator.
Estimator * myEstimator
Alias of the estimator.
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.

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

268  {
269  return myEstimator && myEstimator->isValid();
270  }
Estimator * myEstimator
Alias of the estimator.
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.

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

137  {
138  myContainer = other.myContainer;
139  myEstimator = other.myEstimator;
140  myInit = other.myInit;
141 
142  return *this;
143  }
bool myInit
Init flag.
Container myContainer
Instance of estimator.
Estimator * myEstimator
Alias of the estimator.
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.

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

259  {
260  out<< "[EstimatorCache] number of surfels="<<myContainer.size();
261  }
Container myContainer
Instance of estimator.
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.

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

249  {
250  ASSERT_MSG(myInit, " init() method must have been called first.");
251  return myContainer.size();
252  }
bool myInit
Init flag.
Container myContainer
Instance of estimator.

Field Documentation

template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
Container DGtal::EstimatorCache< TEstimator, TContainer >::myContainer
private
template<typename TEstimator , typename TContainer = std::map<typename TEstimator::Surfel, typename TEstimator::Quantity>>
Estimator* DGtal::EstimatorCache< TEstimator, TContainer >::myEstimator
private
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: