DGtal 1.3.0
Loading...
Searching...
No Matches
TiledImage.h
1
17#pragma once
18
31#if defined(TiledImage_RECURSES)
32#error Recursive header files inclusion detected in TiledImage.h
33#else // defined(TiledImage_RECURSES)
35#define TiledImage_RECURSES
36
37#if !defined TiledImage_h
39#define TiledImage_h
40
42// Inclusions
43#include <iostream>
44#include "DGtal/base/Common.h"
45#include "DGtal/base/ConceptUtils.h"
46#include "DGtal/images/CImage.h"
47#include "DGtal/images/CImageFactory.h"
48#include "DGtal/images/CImageCacheReadPolicy.h"
49#include "DGtal/images/CImageCacheWritePolicy.h"
50#include "DGtal/base/Alias.h"
51
52#include "DGtal/images/ImageCache.h"
53
54#include "DGtal/base/TiledImageBidirectionalConstRangeFromPoint.h"
55#include "DGtal/base/TiledImageBidirectionalRangeFromPoint.h"
57
58namespace DGtal
59{
61 // Template class TiledImage
75 template <typename TImageContainer, typename TImageFactory, typename TImageCacheReadPolicy, typename TImageCacheWritePolicy>
77 {
78
79 // ----------------------- Types ------------------------------
80
81 public:
83
89
93 typedef typename ImageContainer::Point Point;
94 typedef typename ImageContainer::Value Value;
95
97
99 typedef TImageFactory ImageFactory;
100 typedef typename ImageFactory::OutputImage OutputImage;
101
102 typedef TImageCacheReadPolicy ImageCacheReadPolicy;
103 typedef TImageCacheWritePolicy ImageCacheWritePolicy;
105
106 // ----------------------- Standard services ------------------------------
107
108 public:
109
118 Alias<ImageCacheReadPolicy> aReadPolicy,
119 Alias<ImageCacheWritePolicy> aWritePolicy,
120 typename Domain::Integer N):
121 myN(N), myImageFactory(&anImageFactory), myReadPolicy(&aReadPolicy), myWritePolicy(&aWritePolicy)
122 {
124
125 m_lowerBound = myImageFactory->domain().lowerBound();
126 m_upperBound = myImageFactory->domain().upperBound();
127
128 for(typename DGtal::Dimension i=0; i<Domain::dimension; i++)
129 mySize[i] = (m_upperBound[i]-m_lowerBound[i]+1)/myN;
130 }
131
136 {
137 delete myImageCache;
138 }
139
140 private:
141
142 public:
143
148 TiledImage( const TiledImage &other )
149 {
150 myN = other.myN;
154
156
157 m_lowerBound = myImageFactory->domain().lowerBound();
158 m_upperBound = myImageFactory->domain().upperBound();
159
160 for(typename DGtal::Dimension i=0; i<Domain::dimension; i++)
161 mySize[i] = (m_upperBound[i]-m_lowerBound[i]+1)/myN;
162 }
163
169 TiledImage & operator=( const TiledImage & other )
170 {
171 if ( this != &other )
172 {
173 myN = other.myN;
177
179
180 m_lowerBound = myImageFactory->domain().lowerBound();
181 m_upperBound = myImageFactory->domain().upperBound();
182
183 for(typename DGtal::Dimension i=0; i<Domain::dimension; i++)
184 mySize[i] = (m_upperBound[i]-m_lowerBound[i]+1)/myN;
185 }
186
187 return *this;
188 }
189
190 // ----------------------- Interface --------------------------------------
191 public:
192
194
200 const Domain & domain() const
201 {
202 return myImageFactory->domain();
203 }
204
211 {
212 Point lowerBoundCords, upperBoundCoords;
213
214 for(typename DGtal::Dimension i=0; i<Domain::dimension; i++)
215 {
216 lowerBoundCords[i] = 0;
217 upperBoundCoords[i] = myN;
218
219 if (((m_upperBound[i]-m_lowerBound[i]+1) % myN) == 0)
220 upperBoundCoords[i]--;
221 }
222
223 return Domain(lowerBoundCords, upperBoundCoords);
224 }
225
227
232 class TiledIterator : public
233 std::iterator<std::bidirectional_iterator_tag, Value, ptrdiff_t, Value*, Value&>
234 {
235
237
238 public:
239
240 /*typedef std::bidirectional_iterator_tag iterator_category; // ???
241 typedef Value value_type;
242 typedef ptrdiff_t difference_type; // ???
243 typedef Value* pointer;
244 typedef Value& reference;*/
245
246 typedef typename ImageContainer::Range::/*Output*/Iterator TiledRangeIterator;
248
249 //TiledIterator();
250
257 TiledIterator ( BlockCoordsIterator aBlockCoordsIterator,
259 ImageCacheReadPolicy, ImageCacheWritePolicy> *aTiledImage ) : myTiledImage ( aTiledImage ),
260 myBlockCoordsIterator ( aBlockCoordsIterator )
261 {
263 {
265 myTiledRangeIterator = myTile->range().begin();
266 }
267 }
268
276 TiledIterator ( BlockCoordsIterator aBlockCoordsIterator,
277 const Point& aPoint,
279 ImageCacheReadPolicy, ImageCacheWritePolicy> *aTiledImage ) : myTiledImage ( aTiledImage ),
280 myBlockCoordsIterator ( aBlockCoordsIterator )
281 {
283 {
285 myTiledRangeIterator = myTile->range().begin(aPoint);
286 }
287 }
288
294 inline
296 {
297 return (*myTiledRangeIterator);
298 }
299
305 inline
306 bool operator== ( const TiledIterator &it ) const
307 {
308 return ( ( this->myBlockCoordsIterator == it.myBlockCoordsIterator ) && ( this->myTiledRangeIterator == it.myTiledRangeIterator ) );
309 }
310
316 inline
317 bool operator!= ( const TiledIterator &it ) const
318 {
320 return false;
321
322 return ( ( this->myBlockCoordsIterator != it.myBlockCoordsIterator ) || ( this->myTiledRangeIterator != it.myTiledRangeIterator ) );
323 }
324
329 inline
331 {
333
334 if ( myTiledRangeIterator != myTile->range().end() )
335 return;
336 else
337 {
339
341 return;
342
344 myTiledRangeIterator = myTile->range().begin();
345 }
346 }
347
352 inline
354 {
356 return *this;
357 }
358
363 inline
365 {
366 TiledIterator tmp = *this;
368 return tmp;
369 }
370
375 inline
377 {
378 // -- IF we are at the end... (reverse, --)
380 {
382
384
385 myTiledRangeIterator = myTile->range().end();
387
388 return;
389 }
390 // -- IF we are at the end... (reverse, --)
391
392 // ---
393
394 if ( myTiledRangeIterator != myTile->range().begin() )
395 {
397 return;
398 }
399 else
400 {
402 return;
403
405
407
408 myTiledRangeIterator = myTile->range().end();
410 }
411 }
412
417 inline
419 {
421 return *this;
422 }
423
427 inline
429 {
430 TiledIterator tmp = *this;
432 return tmp;
433 }
434
435 private:
438
441
444
447 };
448
449
452
453 typedef std::reverse_iterator<TiledIterator> ReverseTiledIterator;
456
457
459 {
460 return TiledIterator( this->domainBlockCoords().begin(), this );
461 }
462
463 OutputIterator begin()
464 {
465 return TiledIterator( this->domainBlockCoords().begin(), this );
466 }
467
468 ConstIterator begin(const Point& aPoint) const
469 {
470 Point coords = this->findBlockCoordsFromPoint(aPoint);
471 return TiledIterator( this->domainBlockCoords().begin(coords), aPoint, this );
472 }
473
475 {
476 Point coords = this->findBlockCoordsFromPoint(aPoint);
477 return TiledIterator( this->domainBlockCoords().begin(coords), aPoint, this );
478 }
479
481 {
482 return TiledIterator( this->domainBlockCoords().end(), this );
483 }
484
485 OutputIterator end()
486 {
487 return TiledIterator( this->domainBlockCoords().end(), this );
488 }
489
490 ConstReverseIterator rbegin() const
491 {
492 return ReverseTiledIterator( end() );
493 }
494
496 {
497 return ReverseTiledIterator( end() );
498 }
499
501 {
502 typename DGtal::Dimension i;
503
504 Point point2;
505 for(i=0; i<Domain::dimension; i++)
506 point2[i]=(m_upperBound[i]-aPoint[i])+m_lowerBound[i];
507
508 TiledIterator it( begin(point2) ); it++;
509 return ReverseTiledIterator(it);
510 }
511
513 {
514 typename DGtal::Dimension i;
515
516 Point point2;
517 for(i=0; i<Domain::dimension; i++)
518 point2[i]=(m_upperBound[i]-aPoint[i])+m_lowerBound[i];
519
520 TiledIterator it( begin(point2) ); it++;
521 return ReverseTiledIterator(it);
522 }
523
525 {
526 return ReverseTiledIterator( begin() );
527 }
528
530 {
531 return ReverseTiledIterator( begin() );
532 }
533
534 // ---
535
537 {
538 return OutputIterator( begin() );
539 }
540
542 {
543 return OutputIterator( begin(aPoint) );
544 }
545
547 {
548 return ReverseOutputIterator( end() );
549 }
550
552 {
554 }
555
557
560
566 {
567 return ConstRange( this );
568 }
569
575 {
576 return Range( this );
577 }
578
580
585 void selfDisplay ( std::ostream & out ) const;
586
591 bool isValid() const
592 {
593 return (myImageFactory->isValid() && myImageCache->isValid());
594 }
595
602 const Domain findSubDomain(const Point & aPoint) const
603 {
604 ASSERT(myImageFactory->domain().isInside(aPoint));
605
606 typename DGtal::Dimension i;
607
608 Point low;
609 for(i=0; i<Domain::dimension; i++)
610 {
611 low[i] = (aPoint[i]-m_lowerBound[i])/mySize[i];
612 }
613
614 Point dMin, dMax;
615 for(i=0; i<Domain::dimension; i++)
616 {
617 dMin[i] = (low[i]*mySize[i])+m_lowerBound[i];
618 dMax[i] = dMin[i] + (mySize[i]-1);
619
620 if (dMax[i] > m_upperBound[i]) // last tile
621 dMax[i] = m_upperBound[i];
622 }
623
624 Domain di(dMin, dMax);
625 return di;
626 }
627
635 {
636 ASSERT(myImageFactory->domain().isInside(aPoint));
637
638 typename DGtal::Dimension i;
639
640 Point low;
641 for(i=0; i<Domain::dimension; i++)
642 {
643 /*if ( (aPoint[i]-m_lowerBound[i]) < mySize[i] )
644 low[i] = 0;
645 else*/
646 low[i] = (aPoint[i]-m_lowerBound[i])/mySize[i];
647 }
648
649 return low;
650 }
651
658 const Domain findSubDomainFromBlockCoords(const Point & aCoord) const
659 {
660 ASSERT(domainBlockCoords().isInside(aCoord));
661
662 typename DGtal::Dimension i;
663
664 Point dMin, dMax;
665 for(i=0; i<Domain::dimension; i++)
666 {
667 dMin[i] = (aCoord[i]*mySize[i])+m_lowerBound[i];
668 dMax[i] = dMin[i] + (mySize[i]-1);
669
670 if (dMax[i] > m_upperBound[i]) // last tile
671 dMax[i] = m_upperBound[i];
672 }
673
674 Domain di(dMin, dMax);
675 return di;
676 }
677
685 {
686 ASSERT(domainBlockCoords().isInside(aCoord));
687
690 if (!tile)
691 {
694 tile = myImageCache->getPage(d);
695 }
696
697 return tile;
698 }
699
707 {
708 ASSERT(myImageFactory->domain().isInside(aPoint));
709
710 typename OutputImage::Value aValue;
711 bool res;
712
713 res = myImageCache->read(aPoint, aValue);
714
715 if (res)
716 return aValue;
717 else
718 {
720 Domain d;
721#ifdef DEBUG_VERBOSE
722 trace.info()<<"+";
723#endif
725
727
728 myImageCache->read(aPoint, aValue);
729
730 return aValue;
731 }
732
733 // Unspecified behavior, returning the default constructed value.
734 return aValue;
735 }
736
743 void setValue(const Point &aPoint, const Value &aValue)
744 {
745 ASSERT(myImageFactory->domain().isInside(aPoint));
746
747 if (myImageCache->write(aPoint, aValue))
748 return;
749 else
750 {
753 myImageCache->write(aPoint, aValue);
754 }
755 }
756
760 unsigned int getCacheMissRead()
761 {
763 }
764
768 unsigned int getCacheMissWrite()
769 {
771 }
772
777 {
779 }
780
781 // ------------------------- Private Datas --------------------------------
782 protected:
783
786
789
792
795
798
800 TImageCacheReadPolicy *myReadPolicy;
801
803 TImageCacheWritePolicy *myWritePolicy;
804
805 // ------------------------- Internals ------------------------------------
806
807 }; // end of class TiledImage
808
809
816 template <typename TImageContainer, typename TImageFactory, typename TImageCacheReadPolicy, typename TImageCacheWritePolicy>
817 std::ostream&
819
820} // namespace DGtal
821
822
824// Includes inline functions.
825#include "DGtal/images/TiledImage.ih"
826
827// //
829
830#endif // !defined TiledImage_h
831
832#undef TiledImage_RECURSES
833#endif // else defined(TiledImage_RECURSES)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: Alias.h:183
Iterator for HyperRectDomain.
Aim: implements an images cache with 'read and write' policies.
Definition: ImageCache.h:78
void clearCacheAndResetCacheMisses()
Definition: ImageCache.h:235
bool read(const Point &aPoint, Value &aValue) const
bool isValid() const
Definition: ImageCache.h:156
unsigned int getCacheMissRead()
Definition: ImageCache.h:203
void update(const Domain &aDomain)
bool write(const Point &aPoint, const Value &aValue)
void incCacheMissWrite()
Definition: ImageCache.h:227
ImageContainer * getPage(const Domain &aDomain) const
void incCacheMissRead()
Definition: ImageCache.h:219
unsigned int getCacheMissWrite()
Definition: ImageCache.h:211
std::vector< Value >::difference_type Difference
SimpleRandomAccessRangeFromPoint< ConstIterator, Iterator, DistanceFunctorFromPoint< Self > > Range
Aim: model of CConstBidirectionalRangeFromPoint that adapts a TiledImage range of elements bounded by...
Aim: model of CBidirectionalRangeFromPoint that adapts a TiledImage range of elements bounded by two ...
Domain::Iterator BlockCoordsIterator
Definition: TiledImage.h:247
TiledIterator & operator--()
Definition: TiledImage.h:418
bool operator!=(const TiledIterator &it) const
Definition: TiledImage.h:317
bool operator==(const TiledIterator &it) const
Definition: TiledImage.h:306
TiledIterator(BlockCoordsIterator aBlockCoordsIterator, const Point &aPoint, const TiledImage< ImageContainer, ImageFactory, ImageCacheReadPolicy, ImageCacheWritePolicy > *aTiledImage)
Definition: TiledImage.h:276
ImageContainer * myTile
Alias on the current tile.
Definition: TiledImage.h:440
BlockCoordsIterator myBlockCoordsIterator
Current block coords iterator.
Definition: TiledImage.h:446
TiledIterator & operator++()
Definition: TiledImage.h:353
const TiledImage * myTiledImage
TiledImage pointer.
Definition: TiledImage.h:437
TiledIterator(BlockCoordsIterator aBlockCoordsIterator, const TiledImage< ImageContainer, ImageFactory, ImageCacheReadPolicy, ImageCacheWritePolicy > *aTiledImage)
Definition: TiledImage.h:257
ImageContainer::Range::Iterator TiledRangeIterator
Definition: TiledImage.h:246
TiledRangeIterator myTiledRangeIterator
Current tiled range iterator.
Definition: TiledImage.h:443
Aim: implements a tiled image from a "bigger/original" one from an ImageFactory.
Definition: TiledImage.h:77
ConstIterator begin() const
Definition: TiledImage.h:458
OutputIterator begin()
Definition: TiledImage.h:463
TiledIterator ConstIterator
Definition: TiledImage.h:450
ImageContainer * findTileFromBlockCoords(const Point &aCoord) const
Definition: TiledImage.h:684
TImageCacheReadPolicy ImageCacheReadPolicy
Definition: TiledImage.h:102
std::reverse_iterator< TiledIterator > ReverseTiledIterator
Definition: TiledImage.h:453
TImageCacheWritePolicy ImageCacheWritePolicy
Definition: TiledImage.h:103
bool isValid() const
Definition: TiledImage.h:591
TImageCacheReadPolicy * myReadPolicy
TImageCacheReadPolicy pointer.
Definition: TiledImage.h:800
ImageContainer::Point Point
Definition: TiledImage.h:93
ReverseTiledIterator ReverseOutputIterator
Definition: TiledImage.h:455
ReverseTiledIterator ConstReverseIterator
Definition: TiledImage.h:454
BOOST_CONCEPT_ASSERT((concepts::CImageCacheReadPolicy< TImageCacheReadPolicy >))
ConstReverseIterator rend() const
Definition: TiledImage.h:524
unsigned int getCacheMissRead()
Definition: TiledImage.h:760
TiledImage< TImageContainer, TImageFactory, TImageCacheReadPolicy, TImageCacheWritePolicy > Self
Definition: TiledImage.h:82
const Domain findSubDomain(const Point &aPoint) const
Definition: TiledImage.h:602
ImageFactory * myImageFactory
ImageFactory pointer.
Definition: TiledImage.h:791
const Domain domainBlockCoords() const
Definition: TiledImage.h:210
ConstReverseIterator rend()
Definition: TiledImage.h:529
TiledImageBidirectionalConstRangeFromPoint< TiledImage > ConstRange
Definition: TiledImage.h:558
const Domain findSubDomainFromBlockCoords(const Point &aCoord) const
Definition: TiledImage.h:658
BOOST_CONCEPT_ASSERT((concepts::CImageFactory< TImageFactory >))
ImageContainer::Difference Difference
Definition: TiledImage.h:96
ImageFactory::OutputImage OutputImage
Definition: TiledImage.h:100
void selfDisplay(std::ostream &out) const
ReverseOutputIterator routputIterator(const Point &aPoint)
Definition: TiledImage.h:551
MyImageCache * myImageCache
ImageCache pointer.
Definition: TiledImage.h:794
OutputIterator end()
Definition: TiledImage.h:485
ReverseOutputIterator routputIterator()
Definition: TiledImage.h:546
Domain::Integer myN
Number of tiles per dimension.
Definition: TiledImage.h:785
ImageContainer::Value Value
Definition: TiledImage.h:94
TiledImageBidirectionalRangeFromPoint< TiledImage > Range
Definition: TiledImage.h:559
const Domain & domain() const
Definition: TiledImage.h:200
ConstIterator begin(const Point &aPoint) const
Definition: TiledImage.h:468
TiledImage(const TiledImage &other)
Definition: TiledImage.h:148
OutputIterator outputIterator()
Definition: TiledImage.h:536
OutputIterator outputIterator(const Point &aPoint)
Definition: TiledImage.h:541
void setValue(const Point &aPoint, const Value &aValue)
Definition: TiledImage.h:743
TImageCacheWritePolicy * myWritePolicy
TImageCacheWritePolicy pointer.
Definition: TiledImage.h:803
ConstRange constRange() const
Definition: TiledImage.h:565
ReverseOutputIterator rbegin(const Point &aPoint)
Definition: TiledImage.h:512
ConstReverseIterator rbegin(const Point &aPoint) const
Definition: TiledImage.h:500
ImageCache< OutputImage, ImageFactory, ImageCacheReadPolicy, ImageCacheWritePolicy > MyImageCache
Definition: TiledImage.h:104
TiledImage & operator=(const TiledImage &other)
Definition: TiledImage.h:169
TImageContainer ImageContainer
Types copied from the container.
Definition: TiledImage.h:91
Point mySize
Width of a tile (for each dimension)
Definition: TiledImage.h:788
ReverseOutputIterator rbegin()
Definition: TiledImage.h:495
TiledIterator OutputIterator
Definition: TiledImage.h:451
ConstIterator end() const
Definition: TiledImage.h:480
ConstReverseIterator rbegin() const
Definition: TiledImage.h:490
Point m_lowerBound
domain lower and upper bound
Definition: TiledImage.h:797
TiledImage(Alias< ImageFactory > anImageFactory, Alias< ImageCacheReadPolicy > aReadPolicy, Alias< ImageCacheWritePolicy > aWritePolicy, typename Domain::Integer N)
Definition: TiledImage.h:117
void clearCacheAndResetCacheMisses()
Definition: TiledImage.h:776
ImageContainer::Domain Domain
Definition: TiledImage.h:92
BOOST_CONCEPT_ASSERT((concepts::CImage< TImageContainer >))
Checking concepts.
OutputIterator begin(const Point &aPoint)
Definition: TiledImage.h:474
Value operator()(const Point &aPoint) const
Definition: TiledImage.h:706
TImageFactory ImageFactory
Types.
Definition: TiledImage.h:99
BOOST_CONCEPT_ASSERT((concepts::CImageCacheWritePolicy< TImageCacheWritePolicy >))
unsigned int getCacheMissWrite()
Definition: TiledImage.h:768
const Point findBlockCoordsFromPoint(const Point &aPoint) const
Definition: TiledImage.h:634
std::ostream & info()
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::uint32_t Dimension
Definition: Common.h:137
Trace trace
Definition: Common.h:154
Aim: Defines the concept describing a cache read policy.
Aim: Defines the concept describing a cache write policy.
Aim: Defines the concept describing an image factory.
Definition: CImageFactory.h:91
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:103
const Point aPoint(3, 4)
ImageContainerBySTLVector< HyperRectDomain< Z2i::Space >, std::unordered_set< Z2i::Point > > TImageContainer