DGtal  1.1.0
ImageContainerBySTLVector.h
1 
17 #pragma once
18 
36 #if defined(ImageContainerBySTLVector_RECURSES)
37 #error Recursive header files inclusion detected in ImageContainerBySTLVector.h
38 #else // defined(ImageContainerBySTLVector_RECURSES)
39 
40 #define ImageContainerBySTLVector_RECURSES
41 
42 #if !defined ImageContainerBySTLVector_h
43 
44 #define ImageContainerBySTLVector_h
45 
47 // Inclusions
48 #include <iostream>
49 #include <vector>
50 #include "DGtal/base/Common.h"
51 #include "DGtal/base/SimpleRandomAccessConstRangeFromPoint.h"
52 #include "DGtal/base/SimpleRandomAccessRangeFromPoint.h"
53 #include "DGtal/base/CLabel.h"
54 #include "DGtal/kernel/domains/CDomain.h"
55 #include "DGtal/kernel/SpaceND.h"
56 #include "DGtal/kernel/domains/HyperRectDomain.h"
57 #include "DGtal/kernel/NumberTraits.h"
58 
60 
61 namespace DGtal
62 {
63 
64 
72  template<typename TImage>
74  {
75 
76  public:
77 
78  typedef typename TImage::Point Point;
79  typedef typename TImage::Difference Difference;
80 
81  public:
82 
83  DistanceFunctorFromPoint( const TImage *aImagePtr): myImagePtr(aImagePtr)
84  {};
85 
87  {
88  return Difference ( myImagePtr->linearized ( aPoint ) );
89  }
90  private:
91  const TImage *myImagePtr;
92 
93  };
94 
96  // class ImageContainerBySTLVector
97 
124  template <typename TDomain, typename TValue>
125 
126  class ImageContainerBySTLVector: public std::vector<TValue>
127  {
128 
129  public:
130 
132 
135  typedef TDomain Domain;
136  typedef typename Domain::Point Point;
137  typedef typename Domain::Vector Vector;
138  typedef typename Domain::Integer Integer;
139  typedef typename Domain::Size Size;
140  typedef typename Domain::Dimension Dimension;
141  typedef Point Vertex;
142 
143  BOOST_STATIC_CONSTANT( Dimension, dimension = Domain::Space::dimension );
144 
146  BOOST_STATIC_ASSERT ( ( boost::is_same< Domain,
148 
151  typedef TValue Value;
152 
154 
155  private:
156 
159 
162 
164 
165  public:
166 
173  ImageContainerBySTLVector ( const Domain &aDomain );
174 
182 
191 
197 
198 
200 
201 
211  Value operator() ( const Point & aPoint ) const;
212 
221  void setValue ( const Point &aPoint, const Value &aValue );
222 
226  const Domain &domain() const;
227 
228 
232  Vector extent() const;
233 
238  void translateDomain ( const Vector& aShift );
239 
244  void selfDisplay ( std::ostream & out ) const;
245 
246 
250  bool isValid() const;
251 
252  // ------------- realization CDrawableWithBoard2D --------------------
253 
257  std::string className() const;
258 
259 
261  // built-in iterators
262  typedef typename std::vector<Value>::iterator Iterator;
263  typedef typename std::vector<Value>::const_iterator ConstIterator;
264  typedef typename std::vector<Value>::reverse_iterator ReverseIterator;
265  typedef typename std::vector<Value>::const_reverse_iterator ConstReverseIterator;
266  typedef typename std::vector<Value>::difference_type Difference;
267 
268  typedef typename std::vector<Value>::iterator OutputIterator;
269  typedef typename std::vector<Value>::reverse_iterator ReverseOutputIterator;
270 
274 
280 
286 
287 
289 
295  {
296 
297  friend class ImageContainerBySTLVector<Domain, Value>;
298 
299  public:
300 
302  typedef std::bidirectional_iterator_tag iterator_category;
303  typedef Value value_type;
304  typedef ptrdiff_t difference_type;
305  typedef Value* pointer;
306  typedef Value& reference;
307 
315  SpanIterator ( const Point & p ,
316  const Dimension aDim ,
317  ImageContainerBySTLVector<Domain, Value> *aMap ) : myMap ( aMap ), myDimension ( aDim )
318  {
319  myPos = aMap->linearized ( p );
320 
321  //We compute the myShift quantity
322  myShift = 1;
323 
324  for ( Dimension k = 0; k < myDimension ; k++ )
325  myShift *= aMap->myExtent[k];
326  }
327 
328 
334  inline
335  void setValue ( const Value aVal )
336  {
337  ( *myMap ) [ myPos ] = aVal;
338  }
339 
345  inline
346  const Value & operator*()
347  {
348  return ( *myMap ) [ myPos ];
349  }
350 
356  inline
357  bool operator== ( const SpanIterator &it ) const
358  {
359  return ( myPos == it.myPos );
360  }
361 
367  inline
368  bool operator!= ( const SpanIterator &it ) const
369  {
370  return ( myPos != it.myPos );
371  }
372 
377  inline
378  void next()
379  {
380  myPos += myShift;
381  }
382 
387  inline
388  void prev()
389  {
390  ASSERT ( ( long int ) myPos - myShift > 0 );
391  myPos -= myShift;
392  }
393 
398  inline
400  {
401  this->next();
402  return *this;
403  }
404 
409  inline
411  {
412  SpanIterator tmp = *this;
413  ++*this;
414  return tmp;
415  }
416 
421  inline
423  {
424  this->prev();
425  return *this;
426  }
427 
432  inline
434  {
435  SpanIterator tmp = *this;
436  --*this;
437  return tmp;
438  }
439 
440  private:
443 
446 
449 
452 
453  };
454 
461  void setValue ( SpanIterator &it, const Value &aValue )
462  {
463  it.setValue ( aValue );
464  }
465 
466 
476  SpanIterator spanBegin ( const Point &aPoint, const Dimension aDimension )
477  {
478  return SpanIterator ( aPoint, aDimension, this );
479  }
480 
491  SpanIterator spanEnd ( const Point &aPoint, const Dimension aDimension )
492  {
493  Point tmp = aPoint;
494  tmp[ aDimension ] = myDomain.upperBound() [ aDimension ] + 1;
495  return SpanIterator ( tmp, aDimension, this );
496  }
497 
504  Value getValue ( SpanIterator &it )
505  {
506  return ( *it );
507  };
508 
509 
510 
511 
517  Size linearized ( const Point &aPoint ) const;
518 
519 
520 
521  };
522 
529  template <typename Domain, typename V>
530  inline
531  std::ostream&
532  operator<< ( std::ostream & out, const ImageContainerBySTLVector<Domain, V> & object )
533  {
534  object.selfDisplay ( out );
535  return out;
536  }
537 
538 } // namespace DGtal
539 
540 
542 // Includes inline functions
543 #include "DGtal/images/ImageContainerBySTLVector.ih"
544 
545 // //
547 
548 #endif // !defined ImageContainerBySTLVector_h
549 
550 #undef ImageContainerBySTLVector_RECURSES
551 #endif // else defined(ImageContainerBySTLVector_RECURSES)
DGtal::ImageContainerBySTLVector::ReverseIterator
std::vector< Value >::reverse_iterator ReverseIterator
Definition: ImageContainerBySTLVector.h:264
DGtal::ImageContainerBySTLVector::myExtent
Vector myExtent
Domain extent (stored for linearization efficiency)
Definition: ImageContainerBySTLVector.h:161
DGtal::DistanceFunctorFromPoint::Point
TImage::Point Point
Definition: ImageContainerBySTLVector.h:78
DGtal::HyperRectDomain< Space >::Dimension
Space::Dimension Dimension
Definition: HyperRectDomain.h:116
DGtal::ImageContainerBySTLVector::ImageContainerBySTLVector
ImageContainerBySTLVector(const ImageContainerBySTLVector &other)
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition: HyperRectDomain.h:100
DGtal::ImageContainerBySTLVector::Domain
TDomain Domain
Definition: ImageContainerBySTLVector.h:135
DGtal::SimpleRandomAccessConstRangeFromPoint
Aim: model of CConstBidirectionalRangeFromPoint that adapts any range of elements bounded by two iter...
Definition: SimpleRandomAccessConstRangeFromPoint.h:74
DGtal::ImageContainerBySTLVector::Vertex
Point Vertex
Definition: ImageContainerBySTLVector.h:141
DGtal::ImageContainerBySTLVector::Value
TValue Value
Definition: ImageContainerBySTLVector.h:151
DGtal::ImageContainerBySTLVector::myDomain
Domain myDomain
Image domain.
Definition: ImageContainerBySTLVector.h:158
DGtal::ImageContainerBySTLVector::~ImageContainerBySTLVector
~ImageContainerBySTLVector()
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:127
DGtal::DistanceFunctorFromPoint::myImagePtr
const TImage * myImagePtr
Definition: ImageContainerBySTLVector.h:91
DGtal::ImageContainerBySTLVector::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(Dimension, dimension=Domain::Space::dimension)
DGtal::ImageContainerBySTLVector::SpanIterator::operator--
SpanIterator & operator--()
Definition: ImageContainerBySTLVector.h:422
aPoint
const Point aPoint(3, 4)
DGtal::ImageContainerBySTLVector::ImageContainerBySTLVector
ImageContainerBySTLVector(const Domain &aDomain)
DGtal::ImageContainerBySTLVector::SpanIterator::difference_type
ptrdiff_t difference_type
Definition: ImageContainerBySTLVector.h:304
DGtal::ImageContainerBySTLVector::ConstIterator
std::vector< Value >::const_iterator ConstIterator
Definition: ImageContainerBySTLVector.h:263
DGtal::ImageContainerBySTLVector::constRange
ConstRange constRange() const
DGtal::ImageContainerBySTLVector::spanBegin
SpanIterator spanBegin(const Point &aPoint, const Dimension aDimension)
Definition: ImageContainerBySTLVector.h:476
DGtal::ImageContainerBySTLVector::translateDomain
void translateDomain(const Vector &aShift)
DGtal::DistanceFunctorFromPoint::operator()
Difference operator()(const Point &aPoint) const
Definition: ImageContainerBySTLVector.h:86
DGtal::ImageContainerBySTLVector::domain
const Domain & domain() const
DGtal::ImageContainerBySTLVector::SpanIterator::pointer
Value * pointer
Definition: ImageContainerBySTLVector.h:305
DGtal::ImageContainerBySTLVector::setValue
void setValue(const Point &aPoint, const Value &aValue)
DGtal::ImageContainerBySTLVector::linearized
Size linearized(const Point &aPoint) const
DGtal::ImageContainerBySTLVector::BOOST_STATIC_ASSERT
BOOST_STATIC_ASSERT((boost::is_same< Domain, HyperRectDomain< typename Domain::Space > >::value))
domain should be rectangular
DGtal::ImageContainerBySTLVector::SpanIterator::myDimension
Dimension myDimension
Dimension on which the iterator must iterate.
Definition: ImageContainerBySTLVector.h:448
DGtal::ImageContainerBySTLVector::SpanIterator::setValue
void setValue(const Value aVal)
Definition: ImageContainerBySTLVector.h:335
DGtal::ImageContainerBySTLVector::OutputIterator
std::vector< Value >::iterator OutputIterator
Definition: ImageContainerBySTLVector.h:268
DGtal::ImageContainerBySTLVector::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CDomain< TDomain >))
domain
DGtal::ImageContainerBySTLVector::ConstRange
SimpleRandomAccessConstRangeFromPoint< ConstIterator, DistanceFunctorFromPoint< Self > > ConstRange
Definition: ImageContainerBySTLVector.h:272
DGtal::HyperRectDomain< Space >::Size
Space::Size Size
Definition: HyperRectDomain.h:117
DGtal::ImageContainerBySTLVector::Point
Domain::Point Point
Definition: ImageContainerBySTLVector.h:136
DGtal::ImageContainerBySTLVector::className
std::string className() const
DGtal::ImageContainerBySTLVector::SpanIterator::operator++
SpanIterator & operator++()
Definition: ImageContainerBySTLVector.h:399
DGtal::ImageContainerBySTLVector::SpanIterator::myMap
ImageContainerBySTLVector< Domain, Value > * myMap
Copy of the underlying images.
Definition: ImageContainerBySTLVector.h:445
DGtal::concepts::CDomain
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
Definition: CDomain.h:130
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::SimpleRandomAccessRangeFromPoint
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
Definition: SimpleRandomAccessRangeFromPoint.h:74
DGtal::ImageContainerBySTLVector::SpanIterator::prev
void prev()
Definition: ImageContainerBySTLVector.h:388
DGtal::ImageContainerBySTLVector::SpanIterator::operator*
const Value & operator*()
Definition: ImageContainerBySTLVector.h:346
DGtal::DistanceFunctorFromPoint::Difference
TImage::Difference Difference
Definition: ImageContainerBySTLVector.h:79
DGtal::ImageContainerBySTLVector::Iterator
std::vector< Value >::iterator Iterator
Definition: ImageContainerBySTLVector.h:262
DGtal::ImageContainerBySTLVector::isValid
bool isValid() const
DGtal::DistanceFunctorFromPoint::DistanceFunctorFromPoint
DistanceFunctorFromPoint(const TImage *aImagePtr)
Definition: ImageContainerBySTLVector.h:83
DGtal::ImageContainerBySTLVector::spanEnd
SpanIterator spanEnd(const Point &aPoint, const Dimension aDimension)
Definition: ImageContainerBySTLVector.h:491
DGtal::ImageContainerBySTLVector::range
Range range()
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::ImageContainerBySTLVector::SpanIterator::reference
Value & reference
Definition: ImageContainerBySTLVector.h:306
DGtal::concepts::CLabel
Aim: Define the concept of DGtal labels. Models of CLabel can be default-constructible,...
Definition: CLabel.h:93
DGtal::ImageContainerBySTLVector::Vector
Domain::Vector Vector
Definition: ImageContainerBySTLVector.h:137
DGtal::ImageContainerBySTLVector::ReverseOutputIterator
std::vector< Value >::reverse_iterator ReverseOutputIterator
Definition: ImageContainerBySTLVector.h:269
DGtal::ImageContainerBySTLVector::Dimension
Domain::Dimension Dimension
Definition: ImageContainerBySTLVector.h:140
DGtal::ImageContainerBySTLVector::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::ImageContainerBySTLVector::Size
Domain::Size Size
Definition: ImageContainerBySTLVector.h:139
DGtal::ImageContainerBySTLVector::setValue
void setValue(SpanIterator &it, const Value &aValue)
Definition: ImageContainerBySTLVector.h:461
DGtal::HyperRectDomain< Space >::Integer
Space::Integer Integer
Definition: HyperRectDomain.h:114
DGtal::PointVector< dim, Integer >
DGtal::ImageContainerBySTLVector::SpanIterator::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition: ImageContainerBySTLVector.h:302
DGtal::ImageContainerBySTLVector::SpanIterator::SpanIterator
SpanIterator(const Point &p, const Dimension aDim, ImageContainerBySTLVector< Domain, Value > *aMap)
Definition: ImageContainerBySTLVector.h:315
DGtal::ImageContainerBySTLVector::Self
ImageContainerBySTLVector< TDomain, TValue > Self
Definition: ImageContainerBySTLVector.h:131
DGtal::DistanceFunctorFromPoint
Definition: ImageContainerBySTLVector.h:74
DGtal::ImageContainerBySTLVector::operator()
Value operator()(const Point &aPoint) const
DGtal::ImageContainerBySTLVector::extent
Vector extent() const
DGtal::ImageContainerBySTLVector::SpanIterator::myShift
Size myShift
Padding variable.
Definition: ImageContainerBySTLVector.h:451
DGtal::ImageContainerBySTLVector::getValue
Value getValue(SpanIterator &it)
Definition: ImageContainerBySTLVector.h:504
DGtal::ImageContainerBySTLVector::operator=
ImageContainerBySTLVector & operator=(const ImageContainerBySTLVector &other)
DGtal::ImageContainerBySTLVector::SpanIterator
Definition: ImageContainerBySTLVector.h:295
DGtal::ImageContainerBySTLVector::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CLabel< TValue >))
range of values
DGtal::ImageContainerBySTLVector::SpanIterator::operator==
bool operator==(const SpanIterator &it) const
Definition: ImageContainerBySTLVector.h:357
DGtal::ImageContainerBySTLVector::ConstReverseIterator
std::vector< Value >::const_reverse_iterator ConstReverseIterator
Definition: ImageContainerBySTLVector.h:265
DGtal::ImageContainerBySTLVector::SpanIterator::myPos
Size myPos
Current Point in the domain.
Definition: ImageContainerBySTLVector.h:442
DGtal::ImageContainerBySTLVector::Range
SimpleRandomAccessRangeFromPoint< ConstIterator, Iterator, DistanceFunctorFromPoint< Self > > Range
Definition: ImageContainerBySTLVector.h:273
DGtal::ImageContainerBySTLVector::SpanIterator::operator!=
bool operator!=(const SpanIterator &it) const
Definition: ImageContainerBySTLVector.h:368
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::ImageContainerBySTLVector::Difference
std::vector< Value >::difference_type Difference
Definition: ImageContainerBySTLVector.h:266
DGtal::ImageContainerBySTLVector::Integer
Domain::Integer Integer
Definition: ImageContainerBySTLVector.h:138
DGtal::ImageContainerBySTLVector::SpanIterator::next
void next()
Definition: ImageContainerBySTLVector.h:378
DGtal::ImageContainerBySTLVector::SpanIterator::value_type
Value value_type
Definition: ImageContainerBySTLVector.h:303