DGtal  1.4.2
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)
40 #define ConstImageAdapter_RECURSES
41 
42 #if !defined ConstImageAdapter_h
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 
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 
152  ConstImageAdapter( const ConstImageAdapter & other ) = default;
153 
160  {
161 #ifdef DEBUG_VERBOSE
162  trace.warning() << "ConstImageAdapter assignment " << std::endl;
163 #endif
164  if (&other != this)
165  {
166  myImagePtr = other.myImagePtr;
168  myFD = other.myFD;
169  myFV = other.myFV;
170  defaultValue = other.defaultValue;
171  }
172  return *this;
173  }
174 
175 
181 
182  // ----------------------- Interface --------------------------------------
183 public:
184 
186 
192  const Domain & domain() const
193  {
194  return (*mySubDomainPtr);
195  }
196 
204  {
205  return ConstRange( *this );
206  }
207 
209 
210 
220  Value operator()(const Point & aPoint) const
221  {
222  ASSERT(this->domain().isInside(aPoint));
223 
224  typename TImageContainer::Point point = myFD->operator()(aPoint);
225  if (myImagePtr->domain().isInside(point))
226  return myFV->operator()(myImagePtr->operator()(point));
227  else
228  return defaultValue;
229  }
230 
231 
233 
238  void selfDisplay ( std::ostream & out ) const;
239 
244  bool isValid() const
245  {
246  return (myImagePtr->isValid() );
247  }
248 
249 
253  std::string className() const;
254 
255 
260  const ImageContainer * getPointer() const
261  {
262  return myImagePtr;
263  }
264 
270  void setDefaultValue ( Value aValue )
271  {
272  defaultValue = aValue;
273  }
274 
276  {
277  return defaultValue;
278  }
279 
280  // ------------------------- Protected Datas ------------------------------
281 private:
286 #ifdef DEBUG_VERBOSE
287  trace.warning() << "ConstImageAdapter Ctor default " << std::endl;
288 #endif
289  }
290 
291  // ------------------------- Private Datas --------------------------------
292 protected:
293 
296 
301 
305  const TFunctorD* myFD;
306 
310  const TFunctorV* myFV;
311 
317 
318 private:
319 
320 
321  // ------------------------- Internals ------------------------------------
322 private:
323 
324 }; // end of class ConstImageAdapter
325 
326 
333 template <typename TImageContainer, typename TNewDomain, typename TFunctorD, typename TNewValue, typename TFunctorV>
334 std::ostream&
336 
337 } // namespace DGtal
338 
339 
341 // Includes inline functions.
342 #include "DGtal/images/ConstImageAdapter.ih"
343 
344 // //
346 
347 #endif // !defined ConstImageAdapter_h
348 
349 #undef ConstImageAdapter_RECURSES
350 #endif // else defined(ConstImageAdapter_RECURSES)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
const ImageContainer * myImagePtr
Alias on the image container.
void setDefaultValue(Value aValue)
ConstImageAdapter & operator=(const ConstImageAdapter &other)
std::string className() const
const ImageContainer * getPointer() const
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctorV, typename TImageContainer::Value, Value >))
ConstImageAdapter< TImageContainer, TNewDomain, TFunctorD, TNewValue, TFunctorV > Self
DefaultConstImageRange< Self > ConstRange
ConstImageAdapter(const ConstImageAdapter &other)=default
const Domain & domain() const
void selfDisplay(std::ostream &out) const
ConstRange constRange() const
BOOST_CONCEPT_ASSERT((concepts::CDomain< TNewDomain >))
Value operator()(const Point &aPoint) const
ConstImageAdapter(ConstAlias< ImageContainer > anImage, ConstAlias< Domain > aDomain, ConstAlias< TFunctorD > aFD, ConstAlias< TFunctorV > aFV)
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctorD, Point, typename TImageContainer::Point >))
TImageContainer ImageContainer
Types copied from the container.
BOOST_CONCEPT_ASSERT((concepts::CConstImage< TImageContainer >))
Checking concepts.
Aim: model of CConstBidirectionalRangeFromPoint that adapts the domain of an image in order to iterat...
std::ostream & warning()
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
Trace trace
Definition: Common.h:153
Aim: Defines the concept describing a read-only image, which is a refinement of CPointFunctor.
Definition: CConstImage.h:95
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 a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:90
MyPointD Point
Definition: testClone2.cpp:383
const Point aPoint(3, 4)
ImageContainerBySTLVector< HyperRectDomain< Z2i::Space >, std::unordered_set< Z2i::Point > > TImageContainer