DGtal  0.9.3beta
ConstImageAdapter.h
1 
17 #pragma once
18 
36 #if defined(ConstImageAdapter_RECURSES)
37 #error Recursive header files inclusion detected in ConstImageAdapter.h
38 #else // defined(ConstImageAdapter_RECURSES)
39 
40 #define ConstImageAdapter_RECURSES
41 
42 #if !defined ConstImageAdapter_h
43 
44 #define ConstImageAdapter_h
45 
47 // Inclusions
48 #include <iostream>
49 #include "DGtal/base/Common.h"
50 #include "DGtal/base/ConstAlias.h"
51 #include "DGtal/base/ConceptUtils.h"
52 #include "DGtal/images/CImage.h"
53 #include "DGtal/kernel/domains/CDomain.h"
54 
55 #include "DGtal/images/DefaultConstImageRange.h"
57 
58 namespace DGtal
59 {
61 // Template class ConstImageAdapter
101 template <typename TImageContainer,
102  typename TNewDomain,
103  typename TFunctorD,
104  typename TNewValue, typename TFunctorV>
106 {
107 
108  // ----------------------- Types ------------------------------
109 
110 public:
112 
116 
117  typedef TNewDomain Domain;
118  typedef typename TNewDomain::Point Point;
119  typedef TNewValue Value;
120 
121 
124 
126  typedef TImageContainer ImageContainer;
127 
129 
130  // ----------------------- Standard services ------------------------------
131 
132 public:
133 
136  ConstAlias<Domain> aDomain,
139  ) :
140  myImagePtr(&anImage), mySubDomainPtr(&aDomain), myFD(&aFD), myFV(&aFV)
141  {
142  defaultValue = 0;
143 #ifdef DEBUG_VERBOSE
144  trace.warning() << "ConstImageAdapter Ctor fromRef " << std::endl;
145 #endif
146  }
147 
154  {
155 #ifdef DEBUG_VERBOSE
156  trace.warning() << "ConstImageAdapter assignment " << std::endl;
157 #endif
158  if (&other != this)
159  {
160  myImagePtr = other.myImagePtr;
162  myFD = other.myFD;
163  myFV = other.myFV;
164  defaultValue = other.defaultValue;
165  }
166  return *this;
167  }
168 
169 
175 
176  // ----------------------- Interface --------------------------------------
177 public:
178 
180 
186  const Domain & domain() const
187  {
188  return (*mySubDomainPtr);
189  }
190 
197  ConstRange constRange() const
198  {
199  return ConstRange( *this );
200  }
201 
203 
204 
214  Value operator()(const Point & aPoint) const
215  {
216  ASSERT(this->domain().isInside(aPoint));
217 
218  typename TImageContainer::Point point = myFD->operator()(aPoint);
219  if (myImagePtr->domain().isInside(point))
220  return myFV->operator()(myImagePtr->operator()(point));
221  else
222  return defaultValue;
223  }
224 
225 
227 
232  void selfDisplay ( std::ostream & out ) const;
233 
238  bool isValid() const
239  {
240  return (myImagePtr->isValid() );
241  }
242 
243 
247  std::string className() const;
248 
249 
254  const ImageContainer * getPointer() const
255  {
256  return myImagePtr;
257  }
258 
264  void setDefaultValue ( Value aValue )
265  {
266  defaultValue = aValue;
267  }
268 
269  Value getDefaultValue () const
270  {
271  return defaultValue;
272  }
273 
274  // ------------------------- Protected Datas ------------------------------
275 private:
280 #ifdef DEBUG_VERBOSE
281  trace.warning() << "ConstImageAdapter Ctor default " << std::endl;
282 #endif
283  }
284 
285  // ------------------------- Private Datas --------------------------------
286 protected:
287 
289  const ImageContainer * myImagePtr;
290 
294  const Domain *mySubDomainPtr;
295 
299  const TFunctorD* myFD;
300 
304  const TFunctorV* myFV;
305 
311 
312 private:
313 
314 
315  // ------------------------- Internals ------------------------------------
316 private:
317 
318 }; // end of class ConstImageAdapter
319 
320 
327 template <typename TImageContainer, typename TNewDomain, typename TFunctorD, typename TNewValue, typename TFunctorV>
328 std::ostream&
329 operator<< ( std::ostream & out, const ConstImageAdapter<TImageContainer, TNewDomain, TFunctorD, TNewValue, TFunctorV> & object );
330 
331 } // namespace DGtal
332 
333 
335 // Includes inline functions.
336 #include "DGtal/images/ConstImageAdapter.ih"
337 
338 // //
340 
341 #endif // !defined ConstImageAdapter_h
342 
343 #undef ConstImageAdapter_RECURSES
344 #endif // else defined(ConstImageAdapter_RECURSES)
Aim: model of CConstBidirectionalRangeFromPoint that adapts the domain of an image in order to iterat...
const ImageContainer * getPointer() const
Trace trace
Definition: Common.h:137
void setDefaultValue(Value aValue)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
void selfDisplay(std::ostream &out) const
ConstImageAdapter & operator=(const ConstImageAdapter &other)
Aim: Defines a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:89
BOOST_CONCEPT_ASSERT((concepts::CConstImage< TImageContainer >))
Checking concepts.
const Domain & domain() const
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
Definition: CDomain.h:129
const ImageContainer * myImagePtr
Alias on the image container.
ConstImageAdapter(ConstAlias< ImageContainer > anImage, ConstAlias< Domain > aDomain, ConstAlias< TFunctorD > aFD, ConstAlias< TFunctorV > aFV)
DGtal is the top-level namespace which contains all DGtal functions and types.
ConstRange constRange() const
DefaultConstImageRange< Self > ConstRange
std::ostream & warning()
Value operator()(const Point &aPoint) const
ConstImageAdapter< TImageContainer, TNewDomain, TFunctorD, TNewValue, TFunctorV > Self
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
Aim: Defines the concept describing a read-only image, which is a refinement of CPointFunctor.
Definition: CConstImage.h:94
TImageContainer ImageContainer
Types copied from the container.
std::string className() const