DGtal 1.3.0
Loading...
Searching...
No Matches
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
58namespace DGtal
59{
61// Template class ConstImageAdapter
101template <typename TImageContainer,
102 typename TNewDomain,
103 typename TFunctorD,
104 typename TNewValue, typename TFunctorV>
106{
107
108 // ----------------------- Types ------------------------------
109
110public:
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
132public:
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;
171 }
172 return *this;
173 }
174
175
181
182 // ----------------------- Interface --------------------------------------
183public:
184
186
192 const Domain & domain() const
193 {
194 return (*mySubDomainPtr);
195 }
196
204 {
205 return ConstRange( *this );
206 }
207
209
210
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
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 ------------------------------
281private:
286#ifdef DEBUG_VERBOSE
287 trace.warning() << "ConstImageAdapter Ctor default " << std::endl;
288#endif
289 }
290
291 // ------------------------- Private Datas --------------------------------
292protected:
293
296
301
305 const TFunctorD* myFD;
306
310 const TFunctorV* myFV;
311
317
318private:
319
320
321 // ------------------------- Internals ------------------------------------
322private:
323
324}; // end of class ConstImageAdapter
325
326
333template <typename TImageContainer, typename TNewDomain, typename TFunctorD, typename TNewValue, typename TFunctorV>
334std::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)
std::string className() 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
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)
const ImageContainer * getPointer() const
ConstImageAdapter & operator=(const ConstImageAdapter &other)
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.
const Domain & domain() const
Aim: model of CConstBidirectionalRangeFromPoint that adapts the domain of an image in order to iterat...
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:154
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
const Point aPoint(3, 4)
ImageContainerBySTLVector< HyperRectDomain< Z2i::Space >, std::unordered_set< Z2i::Point > > TImageContainer