DGtal  1.5.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)
40 #define ImageContainerBySTLVector_RECURSES
41 
42 #if !defined ImageContainerBySTLVector_h
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 
282 
288 
293  const Container & container() const { return static_cast<Parent>(*this); };
298  Container & container() { return static_cast<Parent>(*this); };
299 
300 
302 
308  {
309 
310  friend class ImageContainerBySTLVector<Domain, Value>;
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 
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)
DistanceFunctorFromPoint(const TImage *aImagePtr)
Difference operator()(const Point &aPoint) const
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
ImageContainerBySTLVector< Domain, Value > * myMap
Copy of the underlying images.
Dimension myDimension
Dimension on which the iterator must iterate.
SpanIterator(const Point &p, const Dimension aDim, ImageContainerBySTLVector< Domain, Value > *aMap)
ImageContainerBySTLVector(const Domain &aDomain)
const Domain & domain() const
std::vector< Value >::const_reverse_iterator ConstReverseIterator
Value operator()(const Point &aPoint) const
const Vector & extent() const
BOOST_STATIC_ASSERT((boost::is_same< Domain, HyperRectDomain< typename Domain::Space > >::value))
domain should be rectangular
std::vector< Value >::reverse_iterator ReverseOutputIterator
ImageContainerBySTLVector & operator=(const ImageContainerBySTLVector &other)
void setValue(const Point &aPoint, const Value &aValue)
std::vector< Value >::difference_type Difference
ImageContainerBySTLVector(const ImageContainerBySTLVector &other)
void selfDisplay(std::ostream &out) const
std::string className() const
BOOST_CONCEPT_ASSERT((concepts::CLabel< TValue >))
range of values
std::vector< Value >::iterator OutputIterator
ImageContainerBySTLVector< TDomain, TValue > Self
std::vector< Value >::const_iterator ConstIterator
std::vector< Value >::iterator Iterator
SpanIterator spanEnd(const Point &aPoint, const Dimension aDimension)
SimpleRandomAccessRangeFromPoint< ConstIterator, Iterator, DistanceFunctorFromPoint< Self > > Range
SimpleRandomAccessConstRangeFromPoint< ConstIterator, DistanceFunctorFromPoint< Self > > ConstRange
std::vector< Value >::reverse_iterator ReverseIterator
void translateDomain(const Vector &aShift)
void setValue(SpanIterator &it, const Value &aValue)
Vector myExtent
Domain extent (stored for linearization efficiency)
SpanIterator spanBegin(const Point &aPoint, const Dimension aDimension)
Size linearized(const Point &aPoint) const
BOOST_STATIC_CONSTANT(Dimension, dimension=Domain::Space::dimension)
BOOST_CONCEPT_ASSERT((concepts::CDomain< TDomain >))
domain
Aim: model of CConstBidirectionalRangeFromPoint that adapts any range of elements bounded by two iter...
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
Definition: CDomain.h:130
Aim: Define the concept of DGtal labels. Models of CLabel can be default-constructible,...
Definition: CLabel.h:93
MyPointD Point
Definition: testClone2.cpp:383
const Point aPoint(3, 4)