DGtal  0.9.4beta
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 
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 
160  {
161 #ifdef DEBUG_VERBOSE
162  trace.warning() << "ImageAdapter assignment " << std::endl;
163 #endif
164  if (&other != this)
165  {
166  myImagePtr = other.myImagePtr;
168  myFD = other.myFD;
169  myFV = other.myFV;
170  myFVm1 = other.myFVm1;
171  defaultValue = other.defaultValue;
172  }
173  return *this;
174  }
175 
176 
182 
183  // ----------------------- Interface --------------------------------------
184 public:
185 
187 
193  const Domain & domain() const
194  {
195  return (*mySubDomainPtr);
196  }
197 
204  ConstRange constRange() const
205  {
206  return ConstRange( *this );
207  }
208 
215  Range range()
216  {
217  return Range( *this );
218  }
219 
221 
222 
232  Value operator()(const Point & aPoint) const
233  {
234  ASSERT(this->domain().isInside(aPoint));
235 
236  typename TImageContainer::Point point = myFD->operator()(aPoint);
237  if (myImagePtr->domain().isInside(point))
238  return myFV->operator()(myImagePtr->operator()(point));
239  else
240  return defaultValue;
241  }
242 
243 
244 
246 
255  void setValue(const Point &aPoint, const Value &aValue)
256  {
257  ASSERT(this->domain().isInside(aPoint));
258 
259  myImagePtr->setValue(myFD->operator()(aPoint), myFVm1->operator()(aValue));
260  }
261 
262 
263 
265 
270  void selfDisplay ( std::ostream & out ) const;
271 
276  bool isValid() const
277  {
278  return (myImagePtr->isValid() );
279  }
280 
281 
286  const ImageContainer * getPointer() const
287  {
288  return myImagePtr;
289  }
290 
296  void setDefaultValue ( Value aValue )
297  {
298  defaultValue = aValue;
299  }
300 
301  Value getDefaultValue () const
302  {
303  return defaultValue;
304  }
305 
306  // ------------------------- Protected Datas ------------------------------
307 private:
312 #ifdef DEBUG_VERBOSE
313  trace.warning() << "ImageAdapter Ctor default " << std::endl;
314 #endif
315  }
316 
317  // ------------------------- Private Datas --------------------------------
318 protected:
319 
321  ImageContainer * myImagePtr;
322 
326  const Domain *mySubDomainPtr;
327 
331  const TFunctorD* myFD;
332 
336  const TFunctorV* myFV;
337 
341  const TFunctorVm1* myFVm1;
342 
348 
349 
350 private:
351 
352 
353  // ------------------------- Internals ------------------------------------
354 private:
355 
356 }; // end of class ImageAdapter
357 
358 
365 template <typename TImageContainer, typename TNewDomain, typename TFunctorD, typename TNewValue, typename TFunctorV, typename TFunctorVm1>
366 std::ostream&
367 operator<< ( std::ostream & out, const ImageAdapter<TImageContainer, TNewDomain, TFunctorD, TNewValue, TFunctorV, TFunctorVm1> & object );
368 
369 } // namespace DGtal
370 
371 
373 // Includes inline functions.
374 #include "DGtal/images/ImageAdapter.ih"
375 
376 // //
378 
379 #endif // !defined ImageAdapter_h
380 
381 #undef ImageAdapter_RECURSES
382 #endif // else defined(ImageAdapter_RECURSES)
BOOST_CONCEPT_ASSERT((concepts::CImage< TImageContainer >))
Checking concepts.
Aim: model of CConstBidirectionalRangeFromPoint that adapts the domain of an image in order to iterat...
Aim: model of CConstBidirectionalRangeFromPoint and CBidirectionalRangeWithWritableIteratorFromPoint ...
Trace trace
Definition: Common.h:137
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
const TFunctorD * myFD
Definition: ImageAdapter.h:331
ImageAdapter< TImageContainer, TNewDomain, TFunctorD, TNewValue, TFunctorV, TFunctorVm1 > Self
Definition: ImageAdapter.h:115
Value operator()(const Point &aPoint) const
Definition: ImageAdapter.h:232
ImageAdapter(ImageContainer &anImage, ConstAlias< Domain > aDomain, ConstAlias< TFunctorD > aFD, ConstAlias< TFunctorV > aFV, ConstAlias< TFunctorVm1 > aFVm1)
Definition: ImageAdapter.h:139
ConstRange constRange() const
Definition: ImageAdapter.h:204
const Domain & domain() const
Definition: ImageAdapter.h:193
const Domain * mySubDomainPtr
Definition: ImageAdapter.h:326
Aim: Defines a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:89
void selfDisplay(std::ostream &out) const
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
Definition: CDomain.h:129
ImageContainer * myImagePtr
Alias on the image container.
Definition: ImageAdapter.h:321
ImageAdapter & operator=(const ImageAdapter &other)
Definition: ImageAdapter.h:159
Aim: implements an image adapter with a given domain (i.e. a subdomain) and 3 functors : g for domain...
Definition: ImageAdapter.h:109
const ImageContainer * getPointer() const
Definition: ImageAdapter.h:286
DefaultConstImageRange< Self > ConstRange
Definition: ImageAdapter.h:132
const TFunctorV * myFV
Definition: ImageAdapter.h:336
const TFunctorVm1 * myFVm1
Definition: ImageAdapter.h:341
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & warning()
void setDefaultValue(Value aValue)
Definition: ImageAdapter.h:296
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:102
TNewDomain::Point Point
Definition: ImageAdapter.h:122
TImageContainer ImageContainer
Types copied from the container.
Definition: ImageAdapter.h:130
Value getDefaultValue() const
Definition: ImageAdapter.h:301
bool isValid() const
Definition: ImageAdapter.h:276
void setValue(const Point &aPoint, const Value &aValue)
Definition: ImageAdapter.h:255
DefaultImageRange< Self > Range
Definition: ImageAdapter.h:133