DGtal  1.2.0
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)
35 #define ImageAdapter_RECURSES
36 
37 #if !defined ImageAdapter_h
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 
130  typedef TImageContainer ImageContainer;
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)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
Aim: model of CConstBidirectionalRangeFromPoint that adapts the domain of an image in order to iterat...
Aim: model of CConstBidirectionalRangeFromPoint and CBidirectionalRangeWithWritableIteratorFromPoint ...
Aim: implements an image adapter with a given domain (i.e. a subdomain) and 3 functors : g for domain...
Definition: ImageAdapter.h:110
void setDefaultValue(Value aValue)
Definition: ImageAdapter.h:302
ConstRange constRange() const
Definition: ImageAdapter.h:210
ImageAdapter< TImageContainer, TNewDomain, TFunctorD, TNewValue, TFunctorV, TFunctorVm1 > Self
Definition: ImageAdapter.h:115
DefaultImageRange< Self > Range
Definition: ImageAdapter.h:133
DefaultConstImageRange< Self > ConstRange
Definition: ImageAdapter.h:132
BOOST_CONCEPT_ASSERT((concepts::CDomain< TNewDomain >))
TImageContainer ImageContainer
Types copied from the container.
Definition: ImageAdapter.h:130
const TFunctorVm1 * myFVm1
Definition: ImageAdapter.h:347
void selfDisplay(std::ostream &out) const
TNewDomain::Point Point
Definition: ImageAdapter.h:122
ImageContainer * myImagePtr
Alias on the image container.
Definition: ImageAdapter.h:327
void setValue(const Point &aPoint, const Value &aValue)
Definition: ImageAdapter.h:261
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctorD, Point, typename TImageContainer::Point >))
Value operator()(const Point &aPoint) const
Definition: ImageAdapter.h:238
const Domain & domain() const
Definition: ImageAdapter.h:199
ImageAdapter(ImageContainer &anImage, ConstAlias< Domain > aDomain, ConstAlias< TFunctorD > aFD, ConstAlias< TFunctorV > aFV, ConstAlias< TFunctorVm1 > aFVm1)
Definition: ImageAdapter.h:139
Value getDefaultValue() const
Definition: ImageAdapter.h:307
const ImageContainer * getPointer() const
Definition: ImageAdapter.h:292
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctorVm1, Value, typename TImageContainer::Value >))
const Domain * mySubDomainPtr
Definition: ImageAdapter.h:332
ImageAdapter(const ImageAdapter &other)=default
bool isValid() const
Definition: ImageAdapter.h:282
const TFunctorV * myFV
Definition: ImageAdapter.h:342
BOOST_CONCEPT_ASSERT((concepts::CImage< TImageContainer >))
Checking concepts.
ImageAdapter & operator=(const ImageAdapter &other)
Definition: ImageAdapter.h:165
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctorV, typename TImageContainer::Value, Value >))
const TFunctorD * myFD
Definition: ImageAdapter.h:337
std::ostream & warning()
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
Trace trace
Definition: Common.h:154
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
Definition: CDomain.h:130
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:103
Aim: Defines a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:90
MyPointD Point
Definition: testClone2.cpp:383
const Point aPoint(3, 4)