DGtal 1.4.0
Loading...
Searching...
No Matches
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)
35#define ImageAdapter_RECURSES
36
37#if !defined ImageAdapter_h
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
54namespace DGtal
55{
57// Template class ImageAdapter
103template <typename TImageContainer,
104 typename TNewDomain,
105 typename TFunctorD,
106 typename TNewValue,
107 typename TFunctorV,
108 typename TFunctorVm1>
110{
111
112 // ----------------------- Types ------------------------------
113
114public:
116
120
121 typedef TNewDomain Domain;
122 typedef typename TNewDomain::Point Point;
123 typedef TNewValue Value;
124
128
131
134
135 // ----------------------- Standard services ------------------------------
136
137public:
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
158 ImageAdapter( const ImageAdapter & other ) = default;
159
166 {
167#ifdef DEBUG_VERBOSE
168 trace.warning() << "ImageAdapter assignment " << std::endl;
169#endif
170 if (&other != this)
171 {
172 myImagePtr = other.myImagePtr;
174 myFD = other.myFD;
175 myFV = other.myFV;
176 myFVm1 = other.myFVm1;
178 }
179 return *this;
180 }
181
182
188
189 // ----------------------- Interface --------------------------------------
190public:
191
193
199 const Domain & domain() const
200 {
201 return (*mySubDomainPtr);
202 }
203
211 {
212 return ConstRange( *this );
213 }
214
222 {
223 return Range( *this );
224 }
225
227
228
239 {
240 ASSERT(this->domain().isInside(aPoint));
241
242 typename TImageContainer::Point point = myFD->operator()(aPoint);
243 if (myImagePtr->domain().isInside(point))
244 return myFV->operator()(myImagePtr->operator()(point));
245 else
246 return defaultValue;
247 }
248
249
250
252
261 void setValue(const Point &aPoint, const Value &aValue)
262 {
263 ASSERT(this->domain().isInside(aPoint));
264
265 myImagePtr->setValue(myFD->operator()(aPoint), myFVm1->operator()(aValue));
266 }
267
268
269
271
276 void selfDisplay ( std::ostream & out ) const;
277
282 bool isValid() const
283 {
284 return (myImagePtr->isValid() );
285 }
286
287
293 {
294 return myImagePtr;
295 }
296
302 void setDefaultValue ( Value aValue )
303 {
304 defaultValue = aValue;
305 }
306
308 {
309 return defaultValue;
310 }
311
312 // ------------------------- Protected Datas ------------------------------
313private:
318#ifdef DEBUG_VERBOSE
319 trace.warning() << "ImageAdapter Ctor default " << std::endl;
320#endif
321 }
322
323 // ------------------------- Private Datas --------------------------------
324protected:
325
328
333
337 const TFunctorD* myFD;
338
342 const TFunctorV* myFV;
343
347 const TFunctorVm1* myFVm1;
348
354
355
356private:
357
358
359 // ------------------------- Internals ------------------------------------
360private:
361
362}; // end of class ImageAdapter
363
364
371template <typename TImageContainer, typename TNewDomain, typename TFunctorD, typename TNewValue, typename TFunctorV, typename TFunctorVm1>
372std::ostream&
374
375} // namespace DGtal
376
377
379// Includes inline functions.
380#include "DGtal/images/ImageAdapter.ih"
381
382// //
384
385#endif // !defined ImageAdapter_h
386
387#undef ImageAdapter_RECURSES
388#endif // else defined(ImageAdapter_RECURSES)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition ConstAlias.h:187
Aim: model of CConstBidirectionalRangeFromPoint that adapts the domain of an image in order to iterat...
Aim: model of CConstBidirectionalRangeFromPoint and CBidirectionalRangeWithWritableIteratorFromPoint ...
Aim: implements an image adapter with a given domain (i.e. a subdomain) and 3 functors : g for domain...
void setDefaultValue(Value aValue)
ConstRange constRange() const
ImageAdapter< TImageContainer, TNewDomain, TFunctorD, TNewValue, TFunctorV, TFunctorVm1 > Self
DefaultImageRange< Self > Range
DefaultConstImageRange< Self > ConstRange
BOOST_CONCEPT_ASSERT((concepts::CDomain< TNewDomain >))
TImageContainer ImageContainer
Types copied from the container.
const TFunctorVm1 * myFVm1
void selfDisplay(std::ostream &out) const
TNewDomain::Point Point
ImageAdapter & operator=(const ImageAdapter &other)
ImageContainer * myImagePtr
Alias on the image container.
const ImageContainer * getPointer() const
void setValue(const Point &aPoint, const Value &aValue)
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctorD, Point, typename TImageContainer::Point >))
Value operator()(const Point &aPoint) const
ImageAdapter(ImageContainer &anImage, ConstAlias< Domain > aDomain, ConstAlias< TFunctorD > aFD, ConstAlias< TFunctorV > aFV, ConstAlias< TFunctorVm1 > aFVm1)
Value getDefaultValue() const
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctorVm1, Value, typename TImageContainer::Value >))
const Domain * mySubDomainPtr
ImageAdapter(const ImageAdapter &other)=default
bool isValid() const
const Domain & domain() const
const TFunctorV * myFV
BOOST_CONCEPT_ASSERT((concepts::CImage< TImageContainer >))
Checking concepts.
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctorV, typename TImageContainer::Value, Value >))
const TFunctorD * myFD
void setValue(const Point &aPoint, const Value &aValue)
const Domain & domain() const
std::ostream & warning()
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
Trace trace
Definition Common.h:153
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 the concept describing a read/write image, having an output iterator.
Definition CImage.h:103
Aim: Defines a unary functor, which associates arguments to results.
const Point aPoint(3, 4)
ImageContainerBySTLVector< HyperRectDomain< Z2i::Space >, std::unordered_set< Z2i::Point > > TImageContainer