DGtal  1.3.beta
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  typedef std::vector<TValue> Parent;
133  typedef Parent Container;
134 
137  typedef TDomain Domain;
138  typedef typename Domain::Point Point;
139  typedef typename Domain::Vector Vector;
140  typedef typename Domain::Integer Integer;
141  typedef typename Domain::Size Size;
142  typedef typename Domain::Dimension Dimension;
143  typedef Point Vertex;
144 
145  BOOST_STATIC_CONSTANT( Dimension, dimension = Domain::Space::dimension );
146 
148  BOOST_STATIC_ASSERT ( ( boost::is_same< Domain,
150 
153  typedef TValue Value;
154 
156 
157  private:
158 
161 
164 
166 
167  public:
168 
175  ImageContainerBySTLVector ( const Domain &aDomain );
176 
184 
193 
199 
200 
202 
203 
213  Value operator() ( const Point & aPoint ) const;
214 
223  void setValue ( const Point &aPoint, const Value &aValue );
224 
228  const Domain &domain() const;
229 
230 
234  const Vector &extent() const;
235 
240  void translateDomain ( const Vector& aShift );
241 
246  void selfDisplay ( std::ostream & out ) const;
247 
248 
252  bool isValid() const;
253 
254  // ------------- realization CDrawableWithBoard2D --------------------
255 
259  std::string className() const;
260 
261 
263  // built-in iterators
264  typedef typename std::vector<Value>::iterator Iterator;
265  typedef typename std::vector<Value>::const_iterator ConstIterator;
266  typedef typename std::vector<Value>::reverse_iterator ReverseIterator;
267  typedef typename std::vector<Value>::const_reverse_iterator ConstReverseIterator;
268  typedef typename std::vector<Value>::difference_type Difference;
269 
270  typedef typename std::vector<Value>::iterator OutputIterator;
271  typedef typename std::vector<Value>::reverse_iterator ReverseOutputIterator;
272 
276 
281  ConstRange constRange() const;
282 
287  Range range();
288 
293  const Container & container() const { return static_cast<Parent>(*this); };
298  Container & container() { return static_cast<Parent>(*this); };
299 
300 
302 
308  {
309 
311 
312  public:
313 
315  typedef std::bidirectional_iterator_tag iterator_category;
316  typedef Value value_type;
317  typedef ptrdiff_t difference_type;
318  typedef Value* pointer;
319  typedef Value& reference;
320 
328  SpanIterator ( const Point & p ,
329  const Dimension aDim ,
330  ImageContainerBySTLVector<Domain, Value> *aMap ) : myMap ( aMap ), myDimension ( aDim )
331  {
332  myPos = aMap->linearized ( p );
333 
334  //We compute the myShift quantity
335  myShift = 1;
336 
337  for ( Dimension k = 0; k < myDimension ; k++ )
338  myShift *= aMap->myExtent[k];
339  }
340 
341 
347  inline
348  void setValue ( const Value aVal )
349  {
350  ( *myMap ) [ myPos ] = aVal;
351  }
352 
358  inline
359  const Value & operator*()
360  {
361  return ( *myMap ) [ myPos ];
362  }
363 
369  inline
370  bool operator== ( const SpanIterator &it ) const
371  {
372  return ( myPos == it.myPos );
373  }
374 
380  inline
381  bool operator!= ( const SpanIterator &it ) const
382  {
383  return ( myPos != it.myPos );
384  }
385 
390  inline
391  void next()
392  {
393  myPos += myShift;
394  }
395 
400  inline
401  void prev()
402  {
403  ASSERT ( ( long int ) myPos - myShift > 0 );
404  myPos -= myShift;
405  }
406 
411  inline
413  {
414  this->next();
415  return *this;
416  }
417 
422  inline
424  {
425  SpanIterator tmp = *this;
426  ++*this;
427  return tmp;
428  }
429 
434  inline
436  {
437  this->prev();
438  return *this;
439  }
440 
445  inline
447  {
448  SpanIterator tmp = *this;
449  --*this;
450  return tmp;
451  }
452 
453  private:
456 
459 
462 
465 
466  };
467 
474  void setValue ( SpanIterator &it, const Value &aValue )
475  {
476  it.setValue ( aValue );
477  }
478 
479 
489  SpanIterator spanBegin ( const Point &aPoint, const Dimension aDimension )
490  {
491  return SpanIterator ( aPoint, aDimension, this );
492  }
493 
504  SpanIterator spanEnd ( const Point &aPoint, const Dimension aDimension )
505  {
506  Point tmp = aPoint;
507  tmp[ aDimension ] = myDomain.upperBound() [ aDimension ] + 1;
508  return SpanIterator ( tmp, aDimension, this );
509  }
510 
517  Value getValue ( SpanIterator &it )
518  {
519  return ( *it );
520  };
521 
522 
523 
524 
530  Size linearized ( const Point &aPoint ) const;
531 
532 
533 
534  };
535 
542  template <typename Domain, typename V>
543  inline
544  std::ostream&
545  operator<< ( std::ostream & out, const ImageContainerBySTLVector<Domain, V> & object )
546  {
547  object.selfDisplay ( out );
548  return out;
549  }
550 
551 } // namespace DGtal
552 
553 
555 // Includes inline functions
556 #include "DGtal/images/ImageContainerBySTLVector.ih"
557 
558 // //
560 
561 #endif // !defined ImageContainerBySTLVector_h
562 
563 #undef ImageContainerBySTLVector_RECURSES
564 #endif // else defined(ImageContainerBySTLVector_RECURSES)
DGtal::ImageContainerBySTLVector::ReverseIterator
std::vector< Value >::reverse_iterator ReverseIterator
Definition: ImageContainerBySTLVector.h:266
DGtal::ImageContainerBySTLVector::myExtent
Vector myExtent
Domain extent (stored for linearization efficiency)
Definition: ImageContainerBySTLVector.h:163
DGtal::DistanceFunctorFromPoint::Point
TImage::Point Point
Definition: ImageContainerBySTLVector.h:78
DGtal::HyperRectDomain< Space >::Dimension
Space::Dimension Dimension
Definition: HyperRectDomain.h:116
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition: HyperRectDomain.h:99
DGtal::ImageContainerBySTLVector::Domain
TDomain Domain
Definition: ImageContainerBySTLVector.h:137
DGtal::SimpleRandomAccessConstRangeFromPoint
Aim: model of CConstBidirectionalRangeFromPoint that adapts any range of elements bounded by two iter...
Definition: SimpleRandomAccessConstRangeFromPoint.h:73
DGtal::ImageContainerBySTLVector::Vertex
Point Vertex
Definition: ImageContainerBySTLVector.h:143
DGtal::ImageContainerBySTLVector::Value
TValue Value
Definition: ImageContainerBySTLVector.h:153
DGtal::ImageContainerBySTLVector::myDomain
Domain myDomain
Image domain.
Definition: ImageContainerBySTLVector.h:160
DGtal::ImageContainerBySTLVector::~ImageContainerBySTLVector
~ImageContainerBySTLVector()
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
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:435
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:317
DGtal::ImageContainerBySTLVector::ConstIterator
std::vector< Value >::const_iterator ConstIterator
Definition: ImageContainerBySTLVector.h:265
DGtal::ImageContainerBySTLVector::constRange
ConstRange constRange() const
DGtal::ImageContainerBySTLVector::spanBegin
SpanIterator spanBegin(const Point &aPoint, const Dimension aDimension)
Definition: ImageContainerBySTLVector.h:489
DGtal::ImageContainerBySTLVector::extent
const Vector & extent() const
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:318
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:461
DGtal::ImageContainerBySTLVector::SpanIterator::setValue
void setValue(const Value aVal)
Definition: ImageContainerBySTLVector.h:348
DGtal::ImageContainerBySTLVector::OutputIterator
std::vector< Value >::iterator OutputIterator
Definition: ImageContainerBySTLVector.h:270
Size
HalfEdgeDataStructure::Size Size
Definition: testHalfEdgeDataStructure.cpp:50
DGtal::ImageContainerBySTLVector::Parent
std::vector< TValue > Parent
Definition: ImageContainerBySTLVector.h:132
DGtal::ImageContainerBySTLVector::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CDomain< TDomain >))
domain
DGtal::ImageContainerBySTLVector::Container
Parent Container
Definition: ImageContainerBySTLVector.h:133
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::ImageContainerBySTLVector::ConstRange
SimpleRandomAccessConstRangeFromPoint< ConstIterator, DistanceFunctorFromPoint< Self > > ConstRange
Definition: ImageContainerBySTLVector.h:274
DGtal::HyperRectDomain< Space >::Size
Space::Size Size
Definition: HyperRectDomain.h:117
DGtal::ImageContainerBySTLVector::Point
Domain::Point Point
Definition: ImageContainerBySTLVector.h:138
DGtal::ImageContainerBySTLVector::className
std::string className() const
DGtal::ImageContainerBySTLVector::SpanIterator::operator++
SpanIterator & operator++()
Definition: ImageContainerBySTLVector.h:412
DGtal::ImageContainerBySTLVector::SpanIterator::myMap
ImageContainerBySTLVector< Domain, Value > * myMap
Copy of the underlying images.
Definition: ImageContainerBySTLVector.h:458
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:129
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::SimpleRandomAccessRangeFromPoint
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
Definition: SimpleRandomAccessRangeFromPoint.h:73
DGtal::ImageContainerBySTLVector::SpanIterator::prev
void prev()
Definition: ImageContainerBySTLVector.h:401
DGtal::ImageContainerBySTLVector::SpanIterator::operator*
const Value & operator*()
Definition: ImageContainerBySTLVector.h:359
DGtal::DistanceFunctorFromPoint::Difference
TImage::Difference Difference
Definition: ImageContainerBySTLVector.h:79
DGtal::ImageContainerBySTLVector::Iterator
std::vector< Value >::iterator Iterator
Definition: ImageContainerBySTLVector.h:264
DGtal::ImageContainerBySTLVector::isValid
bool isValid() const
DGtal::ImageContainerBySTLVector::container
Container & container()
Definition: ImageContainerBySTLVector.h:298
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:504
DGtal::ImageContainerBySTLVector::range
Range range()
DGtal::ImageContainerBySTLVector::SpanIterator::reference
Value & reference
Definition: ImageContainerBySTLVector.h:319
DGtal::concepts::CLabel
Aim: Define the concept of DGtal labels. Models of CLabel can be default-constructible,...
Definition: CLabel.h:91
DGtal::ImageContainerBySTLVector::Vector
Domain::Vector Vector
Definition: ImageContainerBySTLVector.h:139
DGtal::ImageContainerBySTLVector::ReverseOutputIterator
std::vector< Value >::reverse_iterator ReverseOutputIterator
Definition: ImageContainerBySTLVector.h:271
DGtal::ImageContainerBySTLVector::Dimension
Domain::Dimension Dimension
Definition: ImageContainerBySTLVector.h:142
DGtal::ImageContainerBySTLVector::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::ImageContainerBySTLVector::Size
Domain::Size Size
Definition: ImageContainerBySTLVector.h:141
DGtal::ImageContainerBySTLVector::setValue
void setValue(SpanIterator &it, const Value &aValue)
Definition: ImageContainerBySTLVector.h:474
DGtal::ImageContainerBySTLVector::container
const Container & container() const
Definition: ImageContainerBySTLVector.h:293
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:315
DGtal::ImageContainerBySTLVector::SpanIterator::SpanIterator
SpanIterator(const Point &p, const Dimension aDim, ImageContainerBySTLVector< Domain, Value > *aMap)
Definition: ImageContainerBySTLVector.h:328
DGtal::ImageContainerBySTLVector::Self
ImageContainerBySTLVector< TDomain, TValue > Self
Definition: ImageContainerBySTLVector.h:131
DGtal::DistanceFunctorFromPoint
Definition: ImageContainerBySTLVector.h:73
DGtal::ImageContainerBySTLVector::operator()
Value operator()(const Point &aPoint) const
DGtal::ImageContainerBySTLVector::SpanIterator::myShift
Size myShift
Padding variable.
Definition: ImageContainerBySTLVector.h:464
DGtal::ImageContainerBySTLVector::getValue
Value getValue(SpanIterator &it)
Definition: ImageContainerBySTLVector.h:517
DGtal::ImageContainerBySTLVector::operator=
ImageContainerBySTLVector & operator=(const ImageContainerBySTLVector &other)
DGtal::ImageContainerBySTLVector::SpanIterator
Definition: ImageContainerBySTLVector.h:307
DGtal::ImageContainerBySTLVector::SpanIterator::operator==
bool operator==(const SpanIterator &it) const
Definition: ImageContainerBySTLVector.h:370
DGtal::ImageContainerBySTLVector::ConstReverseIterator
std::vector< Value >::const_reverse_iterator ConstReverseIterator
Definition: ImageContainerBySTLVector.h:267
DGtal::ImageContainerBySTLVector::SpanIterator::myPos
Size myPos
Current Point in the domain.
Definition: ImageContainerBySTLVector.h:455
DGtal::ImageContainerBySTLVector::Range
SimpleRandomAccessRangeFromPoint< ConstIterator, Iterator, DistanceFunctorFromPoint< Self > > Range
Definition: ImageContainerBySTLVector.h:275
DGtal::ImageContainerBySTLVector::SpanIterator::operator!=
bool operator!=(const SpanIterator &it) const
Definition: ImageContainerBySTLVector.h:381
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::ImageContainerBySTLVector::Difference
std::vector< Value >::difference_type Difference
Definition: ImageContainerBySTLVector.h:268
DGtal::ImageContainerBySTLVector::Integer
Domain::Integer Integer
Definition: ImageContainerBySTLVector.h:140
DGtal::ImageContainerBySTLVector::SpanIterator::next
void next()
Definition: ImageContainerBySTLVector.h:391
DGtal::ImageContainerBySTLVector::SpanIterator::value_type
Value value_type
Definition: ImageContainerBySTLVector.h:316