DGtal  1.3.beta
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 
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)
DGtal::ConstImageAdapter::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::ConstImageAdapter::myFV
const TFunctorV * myFV
Definition: ConstImageAdapter.h:310
DGtal::ConstAlias
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
DGtal::ConstImageAdapter::Domain
TNewDomain Domain
Definition: ConstImageAdapter.h:117
DGtal::ConstImageAdapter::operator()
Value operator()(const Point &aPoint) const
Definition: ConstImageAdapter.h:220
DGtal::ConstImageAdapter::ConstRange
DefaultConstImageRange< Self > ConstRange
Definition: ConstImageAdapter.h:128
DGtal::ConstImageAdapter::className
std::string className() const
aPoint
const Point aPoint(3, 4)
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::ConstImageAdapter
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
Definition: ConstImageAdapter.h:105
DGtal::ConstImageAdapter::Value
TNewValue Value
Definition: ConstImageAdapter.h:119
DGtal::ConstImageAdapter::mySubDomainPtr
const Domain * mySubDomainPtr
Definition: ConstImageAdapter.h:300
DGtal::ConstImageAdapter::ConstImageAdapter
ConstImageAdapter()
Definition: ConstImageAdapter.h:285
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::ConstImageAdapter::getDefaultValue
Value getDefaultValue() const
Definition: ConstImageAdapter.h:275
DGtal::DefaultConstImageRange
Aim: model of CConstBidirectionalRangeFromPoint that adapts the domain of an image in order to iterat...
Definition: DefaultConstImageRange.h:76
DGtal::ConstImageAdapter::domain
const Domain & domain() const
Definition: ConstImageAdapter.h:192
DGtal::ConstImageAdapter::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CConstImage< TImageContainer >))
Checking concepts.
DGtal::ConstImageAdapter::setDefaultValue
void setDefaultValue(Value aValue)
Definition: ConstImageAdapter.h:270
DGtal::ConstImageAdapter::Self
ConstImageAdapter< TImageContainer, TNewDomain, TFunctorD, TNewValue, TFunctorV > Self
Definition: ConstImageAdapter.h:111
DGtal::concepts::CDomain
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
Definition: CDomain.h:129
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::ConstImageAdapter::defaultValue
Value defaultValue
Definition: ConstImageAdapter.h:316
DGtal::ConstImageAdapter::getPointer
const ImageContainer * getPointer() const
Definition: ConstImageAdapter.h:260
DGtal::ConstImageAdapter::myFD
const TFunctorD * myFD
Definition: ConstImageAdapter.h:305
DGtal::ConstImageAdapter::myImagePtr
const ImageContainer * myImagePtr
Alias on the image container.
Definition: ConstImageAdapter.h:295
DGtal::ConstImageAdapter::ImageContainer
TImageContainer ImageContainer
Types copied from the container.
Definition: ConstImageAdapter.h:126
DGtal::ConstImageAdapter::isValid
bool isValid() const
Definition: ConstImageAdapter.h:244
DGtal::ConstImageAdapter::operator=
ConstImageAdapter & operator=(const ConstImageAdapter &other)
Definition: ConstImageAdapter.h:159
DGtal::ConstImageAdapter::~ConstImageAdapter
~ConstImageAdapter()
Definition: ConstImageAdapter.h:180
DGtal::ConstImageAdapter::ConstImageAdapter
ConstImageAdapter(ConstAlias< ImageContainer > anImage, ConstAlias< Domain > aDomain, ConstAlias< TFunctorD > aFD, ConstAlias< TFunctorV > aFV)
Definition: ConstImageAdapter.h:134
DGtal::Trace::warning
std::ostream & warning()
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::ConstImageAdapter::constRange
ConstRange constRange() const
Definition: ConstImageAdapter.h:203
DGtal::ConstImageAdapter::Point
TNewDomain::Point Point
Definition: ConstImageAdapter.h:118
DGtal::concepts::CUnaryFunctor
Aim: Defines a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:89
DGtal::concepts::CConstImage
Aim: Defines the concept describing a read-only image, which is a refinement of CPointFunctor.
Definition: CConstImage.h:94