DGtal  0.9.3beta
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > > Class Template Reference

#include <DGtal/images/ArrayImageAdapter.h>

Inheritance diagram for DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >:
[legend]
Collaboration diagram for DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >:
[legend]

Public Types

using Self = ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >
 
using ArrayIterator = TArrayIterator
 
using Value = typename std::iterator_traits< ArrayIterator >::value_type
 
using Reference = typename std::iterator_traits< ArrayIterator >::reference
 
using ConstReference = const Reference
 
using Domain = HyperRectDomain< TSpace >
 
using Point = typename Domain::Point
 
using Dimension = typename Domain::Dimension
 
using Size = typename Domain::Size
 
using Vector = typename Domain::Vector
 
using Vertex = Point
 
using Integer = typename Domain::Integer
 
using Linearizer = DGtal::Linearizer< Domain, ColMajorStorage >
 
using Iterator = typename IteratorCompletionTraits< Self >::Iterator
 
using ConstIterator = typename IteratorCompletionTraits< Self >::ConstIterator
 
- Public Types inherited from DGtal::IteratorCompletion< ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > > >
typedef IteratorCompletionTraits< ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > > >::Iterator Iterator
 
typedef IteratorCompletionTraits< ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > > >::ConstIterator ConstIterator
 
typedef IteratorCompletionTraits< ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > > >::DistanceFunctor DistanceFunctor
 
typedef boost::reverse_iterator< IteratorReverseIterator
 
typedef boost::reverse_iterator< ConstIteratorConstReverseIterator
 
typedef SimpleRandomAccessRangeFromPoint< ConstIterator, Iterator, DistanceFunctorRange
 
typedef SimpleRandomAccessConstRangeFromPoint< ConstIterator, DistanceFunctorConstRange
 
typedef std::ptrdiff_t Difference
 

Public Member Functions

 BOOST_STATIC_CONSTANT (Dimension, dimension=Domain::dimension)
 
 ArrayImageAdapter ()
 
 ArrayImageAdapter (ArrayIterator anArrayIterator, Domain const &aFullDomain, Domain const &aViewDomain)
 
 ArrayImageAdapter (ArrayIterator anArrayIterator, Domain const &aFullDomain)
 
 ArrayImageAdapter (Self const &other, Domain const &aViewDomain)
 
Domain domain () const
 
Domain fullDomain () const
 
Value getValue (Point const &aPoint) const
 
void setValue (Point const &aPoint, Value aValue)
 
Value operator() (Point const &aPoint) const
 
Iterator begin ()
 
ConstIterator begin () const
 
ConstIterator cbegin () const
 
Iterator end ()
 
ConstIterator end () const
 
ConstIterator cend () const
 
Reference dereference (Point const &, typename Point::Coordinate aFullIndex)
 
ConstReference dereference (Point const &, typename Point::Coordinate aFullIndex) const
 
void selfDisplay (std::ostream &out) const
 
bool isValid () const
 
- Public Member Functions inherited from DGtal::IteratorCompletion< ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > > >
ReverseIterator rbegin ()
 
ConstReverseIterator rbegin () const
 
ConstReverseIterator crbegin () const
 
ReverseIterator rend ()
 
ConstReverseIterator rend () const
 
ConstReverseIterator crend () const
 
Range range ()
 
ConstRange constRange () const
 

Private Member Functions

 BOOST_CONCEPT_ASSERT ((boost_concepts::RandomAccessTraversalConcept< TArrayIterator >))
 

Private Attributes

ArrayIterator myArrayIterator
 
Domain myFullDomain
 
Domain myViewDomain
 

Friends

template<class >
class ArrayImageIterator
 

Additional Inherited Members

- Protected Member Functions inherited from DGtal::IteratorCompletion< ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > > >
 ~IteratorCompletion ()
 

Detailed Description

template<typename TArrayIterator, typename TSpace>
class DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >

Aim: Image adapter for generic arrays with sub-domain view capability.

Description of template class 'ArrayImageAdapter'

This creates an image (concepts::CImage compatible) given a random-access iterator (that can be a T* pointer) that fully spans an array of data, and two domains:

The available iterators for this image can return the corresponding point and are faster than using an iterator over the domain (see ArrayImageIterator). Reverse iterators and ranges are defined in the inherited class IteratorCompletion.

Some helpers are available (see makeArrayImageAdapterFromIterator and makeArrayImageAdapterFromImage) for easy construction (with template deduction) from an iterator or an CConstImage model.

It is important to note that, since this class only adapts an already existing storage to an image, all copy operations (constructor and operator) lead to shallow copies.

The following code snippet demonstrates how to use ArrayImageAdapter from converting a native C-array to an image:

using Space = SpaceND<2>;
using Domain = HyperRectDomain<Space>;
using Value = double;
const Domain domain{ {0, 1}, {4, 3} };
Value* data = new Value[ domain.size() ];
// Convert this allocated memory to a CImage model.
ArrayImageAdapter< Value*, Domain > image( data, domain );
// Alternative syntax using the helpers:
// auto image = makeArrayImageAdapterFromIterator( data, domain );
// Fill the image with first coordinate of the point
for ( auto it = image.begin(); it != image.end(); ++it )
{
*it = it.getPoint()[0];
}
// Get a constant view on a sub-domain.
const Domain sub_domain{ {1, 1}, {3, 2} };
ArrayImageAdapter< Value const*, Domain > cst_image( data, domain, sub_domain );
// Alternative syntax using the helpers:
// auto const cst_image = makeArrayImageAdapterFromImage( image, sub_domain );
// Display it.
for ( auto value : cst_image )
{
std::cout << value << " ";
}
std::cout << std::endl;

Another usage example is illustrated in the image module documentation, ArrayImageAdapter.

Remarks
The given random-access iterator can be either mutable or constant.
Warning
The array must be column-major ordered (but row-major order could be later accepted via template parameter, if needed ?)
The domain must be an HyperRectDomain.
Template Parameters
TArrayIteratorType of a random-access iterator over the datas (can be a T* pointer).
TSpaceType of the space associated to the HyperRectDomain (auto-deduced from TDomain template, see ArrayImageAdapter).
See also
makeArrayImageAdapterFromIterator
makeArrayImageAdapterFromImage
exampleArrayImageAdapter.cpp

Definition at line 116 of file ArrayImageAdapter.h.

Member Typedef Documentation

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::ArrayIterator = TArrayIterator

The given random-access iterator's type.

Definition at line 126 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::ConstIterator = typename IteratorCompletionTraits<Self>::ConstIterator

Constant iterator base on ArrayImageIterator.

Definition at line 146 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::ConstReference = const Reference

Constant reference type.

Definition at line 129 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::Dimension = typename Domain::Dimension

Dimension type.

Definition at line 134 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::Domain = HyperRectDomain<TSpace>

Domain type.

Definition at line 132 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::Integer = typename Domain::Integer

Integer type.

Definition at line 138 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::Iterator = typename IteratorCompletionTraits<Self>::Iterator

Mutable iterator based on ArrayImageIterator.

Definition at line 145 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::Linearizer = DGtal::Linearizer<Domain, ColMajorStorage>

Linearization of the points.

Definition at line 141 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::Point = typename Domain::Point

Point type.

Definition at line 133 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::Reference = typename std::iterator_traits<ArrayIterator>::reference

Mutable reference type.

Definition at line 128 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::Self = ArrayImageAdapter<TArrayIterator, HyperRectDomain<TSpace> >

Self type.

Definition at line 125 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::Size = typename Domain::Size

Size type.

Definition at line 135 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::Value = typename std::iterator_traits<ArrayIterator>::value_type

The value type stored in the image.

Definition at line 127 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::Vector = typename Domain::Vector

Vector type.

Definition at line 136 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
using DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::Vertex = Point

Vertex type.

Definition at line 137 of file ArrayImageAdapter.h.

Constructor & Destructor Documentation

template<typename TArrayIterator , typename TSpace >
DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::ArrayImageAdapter ( )
inline

Default constructor.

Empty allocated memory on empty domains.

Definition at line 152 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::ArrayImageAdapter ( ArrayIterator  anArrayIterator,
Domain const &  aFullDomain,
Domain const &  aViewDomain 
)
inline

Constructor from iterator, full domain and viewable domain.

Parameters
anArrayIteratorA random-access iterator on the datas.
aFullDomainThe domain span by the given iterator.
aViewDomainThe viewable domain of this image.

Definition at line 164 of file ArrayImageAdapter.h.

165  : myArrayIterator(anArrayIterator)
166  , myFullDomain{ aFullDomain }
167  , myViewDomain{ aViewDomain }
168  {
169  ASSERT_MSG(
170  aFullDomain.lowerBound().isLower( aViewDomain.lowerBound() )
171  && aFullDomain.upperBound().isUpper( aViewDomain.upperBound() ),
172  "The viewable domain must be included into the full domain."
173  );
174  }
ArrayIterator myArrayIterator
Pointer to the allocated memory.
template<typename TArrayIterator , typename TSpace >
DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::ArrayImageAdapter ( ArrayIterator  anArrayIterator,
Domain const &  aFullDomain 
)
inline

Constructor from iterator and full domain.

The viewable domain is then the full domain.

Parameters
anArrayIteratorA random-access iterator on the datas.
aFullDomainThe domain span by the given iterator.

Definition at line 183 of file ArrayImageAdapter.h.

184  : ArrayImageAdapter( anArrayIterator, aFullDomain, aFullDomain )
185  {
186  }
template<typename TArrayIterator , typename TSpace >
DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::ArrayImageAdapter ( Self const &  other,
Domain const &  aViewDomain 
)
inline

Copy constructor with other viewable domain.

The full domain will be the same as the copied ArrayImageAdapter. Only the viewable domain will be modified.

Warning
Since this class in only a view on a independant storage, it does a shallow copy.
Parameters
otherAn another ArrayImageAdapter instance.
aViewDomainA new viewable domain for this image.

Definition at line 197 of file ArrayImageAdapter.h.

198  : ArrayImageAdapter( other.myArrayIterator, other.myFullDomain, aViewDomain )
199  {}

Member Function Documentation

template<typename TArrayIterator , typename TSpace >
Iterator DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::begin ( )
inline
Returns
a mutable iterator pointing to the lower bound of the viewable domain.

Definition at line 266 of file ArrayImageAdapter.h.

267  {
268  return Iterator{ this, myFullDomain, myViewDomain };
269  }
typename IteratorCompletionTraits< Self >::Iterator Iterator
Mutable iterator based on ArrayImageIterator.
template<typename TArrayIterator , typename TSpace >
ConstIterator DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::begin ( ) const
inline
Returns
a constant iterator pointing to the lower bound of the viewable domain.

Definition at line 275 of file ArrayImageAdapter.h.

276  {
277  return ConstIterator{ this, myFullDomain, myViewDomain };
278  }
template<typename TArrayIterator , typename TSpace >
DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::BOOST_CONCEPT_ASSERT ( (boost_concepts::RandomAccessTraversalConcept< TArrayIterator >)  )
private
template<typename TArrayIterator , typename TSpace >
DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::BOOST_STATIC_CONSTANT ( Dimension  ,
dimension  = Domain::dimension 
)

Rank of the space.

template<typename TArrayIterator , typename TSpace >
ConstIterator DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::cbegin ( ) const
inline
Returns
a constant iterator pointing to the lower bound of the viewable domain.

Definition at line 284 of file ArrayImageAdapter.h.

285  {
286  return ConstIterator{ this, myFullDomain, myViewDomain };
287  }
template<typename TArrayIterator , typename TSpace >
ConstIterator DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::cend ( ) const
inline
Returns
a constant iterator pointing after the upper bound of the viewable domain.

Definition at line 311 of file ArrayImageAdapter.h.

312  {
313  return ConstIterator{ this, myFullDomain, myViewDomain, true };
314  }
template<typename TArrayIterator , typename TSpace >
Reference DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::dereference ( Point const &  ,
typename Point::Coordinate  aFullIndex 
)
inline

Dereference of a mutable iterator.

Parameters
[in]aFullIndexLinearized index of the point.
Returns
a mutable reference to the value associated to the point.

Definition at line 325 of file ArrayImageAdapter.h.

326  {
327  ASSERT_MSG(
328  aFullIndex >= 0 && static_cast<typename Domain::Size>(aFullIndex) < myFullDomain.size(),
329  "linearized index out of bounds !"
330  );
331  return myArrayIterator[aFullIndex];
332  }
ArrayIterator myArrayIterator
Pointer to the allocated memory.
template<typename TArrayIterator , typename TSpace >
ConstReference DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::dereference ( Point const &  ,
typename Point::Coordinate  aFullIndex 
) const
inline

Dereference of a constant iterator.

Parameters
[in]aFullIndexLinearized index of the point.
Returns
a constant reference to the value associated to the point.

Definition at line 340 of file ArrayImageAdapter.h.

341  {
342  ASSERT_MSG(
343  aFullIndex >= 0 && static_cast<typename Domain::Size>(aFullIndex) < myFullDomain.size(),
344  "linearized index out of bounds !"
345  );
346  return myArrayIterator[aFullIndex];
347  }
ArrayIterator myArrayIterator
Pointer to the allocated memory.
template<typename TArrayIterator , typename TSpace >
Domain DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::domain ( ) const
inline
Returns
the image viewable domain.

Definition at line 205 of file ArrayImageAdapter.h.

206  {
207  return myViewDomain;
208  }
template<typename TArrayIterator , typename TSpace >
Iterator DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::end ( )
inline
Returns
an mutable iterator pointing after the upper bound of the viewable domain.

Definition at line 293 of file ArrayImageAdapter.h.

294  {
295  return Iterator{ this, myFullDomain, myViewDomain, true };
296  }
typename IteratorCompletionTraits< Self >::Iterator Iterator
Mutable iterator based on ArrayImageIterator.
template<typename TArrayIterator , typename TSpace >
ConstIterator DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::end ( ) const
inline
Returns
a constant iterator pointing after the upper bound of the viewable domain.

Definition at line 302 of file ArrayImageAdapter.h.

303  {
304  return ConstIterator{ this, myFullDomain, myViewDomain, true };
305  }
template<typename TArrayIterator , typename TSpace >
Domain DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::fullDomain ( ) const
inline
Returns
the full domain where the allocated memory is defined.

Definition at line 214 of file ArrayImageAdapter.h.

215  {
216  return myFullDomain;
217  }
template<typename TArrayIterator , typename TSpace >
Value DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::getValue ( Point const &  aPoint) const
inline

Reads a value given a point lying inside the full domain.

Parameters
[in]aPointThe point.
Returns
a constant value.

Definition at line 225 of file ArrayImageAdapter.h.

226  {
227  ASSERT_MSG(
228  myFullDomain.isInside(aPoint),
229  "The point is outside the full domain."
230  );
231 
232  return myArrayIterator[ Linearizer::getIndex(aPoint, myFullDomain) ];
233  }
bool isInside(const Point &p) const
ArrayIterator myArrayIterator
Pointer to the allocated memory.
template<typename TArrayIterator , typename TSpace >
bool DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::isValid ( ) const
inline

Checks the validity/consistency of the object.

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

Definition at line 364 of file ArrayImageAdapter.h.

365  {
366  return true;
367  }
template<typename TArrayIterator , typename TSpace >
Value DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::operator() ( Point const &  aPoint) const
inline

Reads a value given a point lying inside the full domain.

Parameters
[in]aPointThe point.
Returns
a constant value.

Definition at line 257 of file ArrayImageAdapter.h.

258  {
259  return getValue(aPoint);
260  }
template<typename TArrayIterator , typename TSpace >
void DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::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 355 of file ArrayImageAdapter.h.

356  {
357  out << "[ArrayImageAdapter] with full domain " << myFullDomain << " and viewable domain " << myViewDomain;
358  }
template<typename TArrayIterator , typename TSpace >
void DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::setValue ( Point const &  aPoint,
Value  aValue 
)
inline

Sets a value given a point lying inside the full domain.

Parameters
[in]aPointThe point.
[in]aValueThe value.

Definition at line 241 of file ArrayImageAdapter.h.

242  {
243  ASSERT_MSG(
244  myFullDomain.isInside(aPoint),
245  "The point is outside the full domain."
246  );
247 
248  myArrayIterator[ Linearizer::getIndex(aPoint, myFullDomain) ] = aValue;
249  }
bool isInside(const Point &p) const
ArrayIterator myArrayIterator
Pointer to the allocated memory.

Friends And Related Function Documentation

template<typename TArrayIterator , typename TSpace >
template<class >
friend class ArrayImageIterator
friend

Definition at line 144 of file ArrayImageAdapter.h.

Field Documentation

template<typename TArrayIterator , typename TSpace >
ArrayIterator DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::myArrayIterator
private

Pointer to the allocated memory.

Definition at line 371 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
Domain DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::myFullDomain
private

Definition (full) domain.

Definition at line 372 of file ArrayImageAdapter.h.

template<typename TArrayIterator , typename TSpace >
Domain DGtal::ArrayImageAdapter< TArrayIterator, HyperRectDomain< TSpace > >::myViewDomain
private

Viewable domain.

Definition at line 373 of file ArrayImageAdapter.h.


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