DGtal  1.3.beta
ImageAdapter.h
1 
17 #pragma once
18 
31 #if defined(ImageAdapter_RECURSES)
32 #error Recursive header files inclusion detected in ImageAdapter.h
33 #else // defined(ImageAdapter_RECURSES)
34 
35 #define ImageAdapter_RECURSES
36 
37 #if !defined ImageAdapter_h
38 
39 #define ImageAdapter_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/base/ConstAlias.h"
46 #include "DGtal/base/ConceptUtils.h"
47 #include "DGtal/images/CImage.h"
48 #include "DGtal/kernel/domains/CDomain.h"
49 
50 #include "DGtal/images/DefaultConstImageRange.h"
51 #include "DGtal/images/DefaultImageRange.h"
53 
54 namespace DGtal
55 {
57 // Template class ImageAdapter
103 template <typename TImageContainer,
104  typename TNewDomain,
105  typename TFunctorD,
106  typename TNewValue,
107  typename TFunctorV,
108  typename TFunctorVm1>
110 {
111 
112  // ----------------------- Types ------------------------------
113 
114 public:
116 
120 
121  typedef TNewDomain Domain;
122  typedef typename TNewDomain::Point Point;
123  typedef TNewValue Value;
124 
128 
131 
134 
135  // ----------------------- Standard services ------------------------------
136 
137 public:
138 
140  ImageContainer &anImage,
141  ConstAlias<Domain> aDomain,
145  ) :
146  myImagePtr(&anImage), mySubDomainPtr(&aDomain), myFD(&aFD), myFV(&aFV), myFVm1(&aFVm1)
147  {
148  defaultValue = 0;
149 #ifdef DEBUG_VERBOSE
150  trace.warning() << "ImageAdapter Ctor fromRef " << std::endl;
151 #endif
152  }
153 
158  ImageAdapter( const ImageAdapter & other ) = default;
159 
166  {
167 #ifdef DEBUG_VERBOSE
168  trace.warning() << "ImageAdapter assignment " << std::endl;
169 #endif
170  if (&other != this)
171  {
172  myImagePtr = other.myImagePtr;
174  myFD = other.myFD;
175  myFV = other.myFV;
176  myFVm1 = other.myFVm1;
177  defaultValue = other.defaultValue;
178  }
179  return *this;
180  }
181 
182 
188 
189  // ----------------------- Interface --------------------------------------
190 public:
191 
193 
199  const Domain & domain() const
200  {
201  return (*mySubDomainPtr);
202  }
203 
211  {
212  return ConstRange( *this );
213  }
214 
222  {
223  return Range( *this );
224  }
225 
227 
228 
238  Value operator()(const Point & aPoint) const
239  {
240  ASSERT(this->domain().isInside(aPoint));
241 
242  typename TImageContainer::Point point = myFD->operator()(aPoint);
243  if (myImagePtr->domain().isInside(point))
244  return myFV->operator()(myImagePtr->operator()(point));
245  else
246  return defaultValue;
247  }
248 
249 
250 
252 
261  void setValue(const Point &aPoint, const Value &aValue)
262  {
263  ASSERT(this->domain().isInside(aPoint));
264 
265  myImagePtr->setValue(myFD->operator()(aPoint), myFVm1->operator()(aValue));
266  }
267 
268 
269 
271 
276  void selfDisplay ( std::ostream & out ) const;
277 
282  bool isValid() const
283  {
284  return (myImagePtr->isValid() );
285  }
286 
287 
292  const ImageContainer * getPointer() const
293  {
294  return myImagePtr;
295  }
296 
302  void setDefaultValue ( Value aValue )
303  {
304  defaultValue = aValue;
305  }
306 
308  {
309  return defaultValue;
310  }
311 
312  // ------------------------- Protected Datas ------------------------------
313 private:
318 #ifdef DEBUG_VERBOSE
319  trace.warning() << "ImageAdapter Ctor default " << std::endl;
320 #endif
321  }
322 
323  // ------------------------- Private Datas --------------------------------
324 protected:
325 
328 
333 
337  const TFunctorD* myFD;
338 
342  const TFunctorV* myFV;
343 
347  const TFunctorVm1* myFVm1;
348 
354 
355 
356 private:
357 
358 
359  // ------------------------- Internals ------------------------------------
360 private:
361 
362 }; // end of class ImageAdapter
363 
364 
371 template <typename TImageContainer, typename TNewDomain, typename TFunctorD, typename TNewValue, typename TFunctorV, typename TFunctorVm1>
372 std::ostream&
374 
375 } // namespace DGtal
376 
377 
379 // Includes inline functions.
380 #include "DGtal/images/ImageAdapter.ih"
381 
382 // //
384 
385 #endif // !defined ImageAdapter_h
386 
387 #undef ImageAdapter_RECURSES
388 #endif // else defined(ImageAdapter_RECURSES)
DGtal::ImageAdapter::Value
TNewValue Value
Definition: ImageAdapter.h:123
DGtal::ImageAdapter::Range
DefaultImageRange< Self > Range
Definition: ImageAdapter.h:133
DGtal::ConstAlias
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
DGtal::ImageAdapter::Self
ImageAdapter< TImageContainer, TNewDomain, TFunctorD, TNewValue, TFunctorV, TFunctorVm1 > Self
Definition: ImageAdapter.h:115
DGtal::ImageAdapter::getDefaultValue
Value getDefaultValue() const
Definition: ImageAdapter.h:307
aPoint
const Point aPoint(3, 4)
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::ImageContainerBySTLVector::domain
const Domain & domain() const
DGtal::ImageContainerBySTLVector::setValue
void setValue(const Point &aPoint, const Value &aValue)
DGtal::ImageAdapter::operator()
Value operator()(const Point &aPoint) const
Definition: ImageAdapter.h:238
DGtal::ImageAdapter::myFV
const TFunctorV * myFV
Definition: ImageAdapter.h:342
DGtal::ImageAdapter::constRange
ConstRange constRange() const
Definition: ImageAdapter.h:210
DGtal::ImageAdapter::setDefaultValue
void setDefaultValue(Value aValue)
Definition: ImageAdapter.h:302
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::ImageAdapter
Aim: implements an image adapter with a given domain (i.e. a subdomain) and 3 functors : g for domain...
Definition: ImageAdapter.h:109
DGtal::DefaultConstImageRange
Aim: model of CConstBidirectionalRangeFromPoint that adapts the domain of an image in order to iterat...
Definition: DefaultConstImageRange.h:76
DGtal::ImageAdapter::myImagePtr
ImageContainer * myImagePtr
Alias on the image container.
Definition: ImageAdapter.h:327
DGtal::ImageAdapter::isValid
bool isValid() const
Definition: ImageAdapter.h:282
DGtal::DefaultImageRange
Aim: model of CConstBidirectionalRangeFromPoint and CBidirectionalRangeWithWritableIteratorFromPoint ...
Definition: DefaultImageRange.h:76
DGtal::ImageAdapter::myFD
const TFunctorD * myFD
Definition: ImageAdapter.h:337
DGtal::ImageAdapter::operator=
ImageAdapter & operator=(const ImageAdapter &other)
Definition: ImageAdapter.h:165
DGtal::ImageAdapter::domain
const Domain & domain() const
Definition: ImageAdapter.h:199
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::ImageAdapter::setValue
void setValue(const Point &aPoint, const Value &aValue)
Definition: ImageAdapter.h:261
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::ImageAdapter::ImageAdapter
ImageAdapter()
Definition: ImageAdapter.h:317
DGtal::ImageAdapter::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::ImageAdapter::mySubDomainPtr
const Domain * mySubDomainPtr
Definition: ImageAdapter.h:332
DGtal::ImageAdapter::Point
TNewDomain::Point Point
Definition: ImageAdapter.h:122
DGtal::ImageContainerBySTLVector::isValid
bool isValid() const
DGtal::ImageAdapter::ImageContainer
TImageContainer ImageContainer
Types copied from the container.
Definition: ImageAdapter.h:130
DGtal::ImageAdapter::defaultValue
Value defaultValue
Definition: ImageAdapter.h:353
DGtal::ImageAdapter::Domain
TNewDomain Domain
Definition: ImageAdapter.h:121
DGtal::ImageAdapter::myFVm1
const TFunctorVm1 * myFVm1
Definition: ImageAdapter.h:347
DGtal::ImageAdapter::ImageAdapter
ImageAdapter(ImageContainer &anImage, ConstAlias< Domain > aDomain, ConstAlias< TFunctorD > aFD, ConstAlias< TFunctorV > aFV, ConstAlias< TFunctorVm1 > aFVm1)
Definition: ImageAdapter.h:139
DGtal::PointVector< dim, Integer >
DGtal::ImageAdapter::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CImage< TImageContainer >))
Checking concepts.
TImageContainer
ImageContainerBySTLVector< HyperRectDomain< Z2i::Space >, std::unordered_set< Z2i::Point > > TImageContainer
Definition: testVoronoiMapComplete.cpp:49
DGtal::Trace::warning
std::ostream & warning()
DGtal::ImageAdapter::ConstRange
DefaultConstImageRange< Self > ConstRange
Definition: ImageAdapter.h:132
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::ImageAdapter::~ImageAdapter
~ImageAdapter()
Definition: ImageAdapter.h:187
DGtal::ImageAdapter::range
Range range()
Definition: ImageAdapter.h:221
DGtal::concepts::CUnaryFunctor
Aim: Defines a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:89
DGtal::ImageAdapter::getPointer
const ImageContainer * getPointer() const
Definition: ImageAdapter.h:292
DGtal::concepts::CImage
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:102