DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImageAdapter.h
1 
17 #pragma once
18 
36 #if defined(ImageAdapter_RECURSES)
37 #error Recursive header files inclusion detected in ImageAdapter.h
38 #else // defined(ImageAdapter_RECURSES)
39 
40 #define ImageAdapter_RECURSES
41 
42 #if !defined ImageAdapter_h
43 
44 #define ImageAdapter_h
45 
47 // Inclusions
48 #include <iostream>
49 #include "DGtal/base/Common.h"
50 #include "DGtal/base/ConceptUtils.h"
51 #include "DGtal/images/CImage.h"
52 #include "DGtal/kernel/domains/CDomain.h"
53 
54 #include "DGtal/images/DefaultConstImageRange.h"
55 #include "DGtal/images/DefaultImageRange.h"
57 
58 namespace DGtal
59 {
61 // Template class ImageAdapter
106 template <typename TImageContainer,
107  typename TNewDomain,
108  typename TFunctorD,
109  typename TNewValue,
110  typename TFunctorV,
111  typename TFunctorVm1>
113 {
114 
115  // ----------------------- Types ------------------------------
116 
117 public:
119 
123 
124  typedef TNewDomain Domain;
125  typedef typename TNewDomain::Point Point;
126  typedef TNewValue Value;
127 
130 
132  typedef TImageContainer ImageContainer;
133 
136 
137  // ----------------------- Standard services ------------------------------
138 
139 public:
140 
141  ImageAdapter(ImageContainer &anImage, const Domain &aDomain, const TFunctorD &aFD, const TFunctorV &aFV, const TFunctorVm1 &aFVm1):
142  myImagePtr(&anImage), mySubDomainPtr(&aDomain), myFD(&aFD), myFV(&aFV), myFVm1(&aFVm1)
143  {
144 #ifdef DEBUG_VERBOSE
145  trace.warning() << "ImageAdapter Ctor fromRef " << std::endl;
146 #endif
147  }
148 
155  {
156 #ifdef DEBUG_VERBOSE
157  trace.warning() << "ImageAdapter assignment " << std::endl;
158 #endif
159  if (&other != this)
160  {
161  myImagePtr = other.myImagePtr;
163  myFD = other.myFD;
164  myFV = other.myFV;
165  myFVm1 = other.myFVm1;
166  }
167  return *this;
168  }
169 
170 
176 
177  // ----------------------- Interface --------------------------------------
178 public:
179 
181 
187  const Domain & domain() const
188  {
189  return (*mySubDomainPtr);
190  }
191 
199  {
200  return ConstRange( *this );
201  }
202 
210  {
211  return Range( *this );
212  }
213 
215 
216 
226  Value operator()(const Point & aPoint) const
227  {
228  ASSERT(this->domain().isInside(aPoint));
229 
230  return myFV->operator()(myImagePtr->operator()(myFD->operator()(aPoint)));
231  }
232 
233 
235 
244  void setValue(const Point &aPoint, const typename TImageContainer::Value &aValue)
245  {
246  ASSERT(this->domain().isInside(aPoint));
247 
248  myImagePtr->setValue(myFD->operator()(aPoint), myFVm1->operator()(aValue));
249  }
250 
251 
252 
254 
259  void selfDisplay ( std::ostream & out ) const;
260 
268  bool isValid() const
269  {
270  return (myImagePtr->isValid() );
271  }
272 
273 
278  const ImageContainer * getPointer() const
279  {
280  return myImagePtr;
281  }
282 
283  // ------------------------- Protected Datas ------------------------------
284 private:
289 #ifdef DEBUG_VERBOSE
290  trace.warning() << "ImageAdapter Ctor default " << std::endl;
291 #endif
292  }
293 
294  // ------------------------- Private Datas --------------------------------
295 protected:
296 
299 
304 
308  const TFunctorD* myFD;
309 
313  const TFunctorV* myFV;
314 
318  const TFunctorVm1* myFVm1;
319 
320 
321 private:
322 
323 
324  // ------------------------- Internals ------------------------------------
325 private:
326 
327 }; // end of class ImageAdapter
328 
329 
336 template <typename TImageContainer, typename TNewDomain, typename TFunctorD, typename TNewValue, typename TFunctorV, typename TFunctorVm1>
337 std::ostream&
338 operator<< ( std::ostream & out, const ImageAdapter<TImageContainer, TNewDomain, TFunctorD, TNewValue, TFunctorV, TFunctorVm1> & object );
339 
340 } // namespace DGtal
341 
342 
344 // Includes inline functions.
345 #include "DGtal/images/ImageAdapter.ih"
346 
347 // //
349 
350 #endif // !defined ImageAdapter_h
351 
352 #undef ImageAdapter_RECURSES
353 #endif // else defined(ImageAdapter_RECURSES)