OpenStructure
Loading...
Searching...
No Matches
image_handle.hh
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// This file is part of the OpenStructure project <www.openstructure.org>
3//
4// Copyright (C) 2008-2020 by the OpenStructure authors
5// Copyright (C) 2003-2010 by the IPLT authors
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License as published by the Free
9// Software Foundation; either version 3.0 of the License, or (at your option)
10// any later version.
11// This library is distributed in the hope that it will be useful, but WITHOUT
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14// details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with this library; if not, write to the Free Software Foundation, Inc.,
18// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19//------------------------------------------------------------------------------
20
21/*
22 basic image handle, manages shared instances of an image
23
24 offers the Image interface
25
26 Author: Ansgar Philippsen, Andreas Schenk
27*/
28
29#ifndef IMG_IMAGE_HANDLE_H
30#define IMG_IMAGE_HANDLE_H
31
32#include <boost/shared_ptr.hpp>
33
35#include <ost/message.hh>
36#include <ost/base.hh>
37
38#include "data.hh"
39#include "observable.hh"
40#include "extent_iterator.hh"
41
44
46
47namespace test_image {
49}
50
51namespace ost { namespace img {
52
53using image_state::ImageStateBase;
55using image_state::ImageStateNonModVisitorBase;
56using image_state::ImageStateModIPVisitorBase;
57using image_state::ImageStateConstModIPVisitorBase;
58using image_state::ImageStateModOPVisitorBase;
59using image_state::ImageStateConstModOPVisitorBase;
60using image_state::ImageStateMorphVisitorBase;
61
62// fw declarations
63class Point;
64class Extent;
65class Size;
66class NonModAlgorithm;
67class ModIPAlgorithm;
68class ConstModIPAlgorithm;
69class ModOPAlgorithm;
70class ConstModOPAlgorithm;
71class DataObserver;
72
74class DLLEXPORT InvalidImageHandle: public Error {
75public:
76 InvalidImageHandle(): Error("Attempt to use invalid ImageHandle") {}
77};
78
79// fw
80class ConstImageHandle;
81
83
113
114 // for internal observer checking
116
117 // for access to Sampling
118 friend class ConstImageHandle;
119
121 typedef boost::shared_ptr<DataObservable> ObsPtr;
122
123 typedef boost::shared_ptr<ImageStateBasePtr> StatePtrPtr;
124
125public:
127
133
135
139
141
146
148
153 ImageHandle Copy(bool cc=true) const;
154
156
160 ImageHandle Extract(const Extent& e) const;
161
163
169 void Paste(const Data& d);
170
172
179 void Set(const ImageHandle& h);
180
183
185
193 void Reset(const Extent &e, DataType type=REAL,DataDomain dom=SPATIAL);
194
196 bool IsValid() const;
197
199 long MemSize() const;
201
202
207 virtual DataType GetType() const;
208
210 virtual DataDomain GetDomain() const;
211
213
216 virtual Extent GetExtent() const;
217
219
224 virtual Point GetSpatialOrigin() const;
225
227 /*
228 For images in the frequency domain, a modification of the spatial origin
229 usually has drastic consequences, since all values are affected by a phase shift.
230 */
231 void SetSpatialOrigin(const Point& p);
232
234 /*
235 See Extent for difference in even and odd dimensions. Only
236 has an effect for spatial images, since frequency data always
237 has origin in center.
238
239 May have effect on values if image is in frequency domain.
240 */
243
245 /*
246 This method returns the aboslute coordinate of the real space spatial
247 origin even when the map is in frequency space
248 */
249 Vec3 GetAbsoluteOrigin() const;
250
252 /*
253 This method sets the aboslutes coordinate of the real space spatial
254 origin even when the map is in frequency space
255 */
256 void SetAbsoluteOrigin(const Vec3& c) ;
257
259 /*
260 Returns the physical dimensions of a given Point based on
261 the sampling of the current domain and the absolute coordinates
262 of the origin of the image
263 */
264 Vec3 IndexToCoord(const Point &p) const;
265
267 /*
268 Returns the location within the Data that corresponds to
269 the given physical coordinate, bases on the sampling of
270 the current domain and the absolute coordinates
271 of the origin of the image
272 */
273 Vec3 CoordToIndex(const Vec3& c) const;
274
276 /*
277 Returns the physical dimensions of a Vec containing fractional Point
278 coordinates. The returned value is based on
279 the sampling of the current domain and the absolute coordinates
280 of the origin of the image
281 */
282 Vec3 FractionalIndexToCoord(const Vec3 &p) const;
283
291 virtual Real GetReal(const Point& p) const;
292
295 void SetReal(const Point &p, Real r);
296
298 virtual Complex GetComplex(const Point& p) const;
299
301 void SetComplex(const Point &p, const Complex& c);
303
305 virtual Real GetIntpolReal(const Vec3 &v) const;
306 virtual Real GetIntpolReal(const Vec2 &v) const;
307 virtual Real GetIntpolReal(const Real &d) const;
308
310 virtual Complex GetIntpolComplex(const Vec3 &v) const;
311 virtual Complex GetIntpolComplex(const Vec2 &v) const;
312 virtual Complex GetIntpolComplex(const Real &d) const;
313
314
315
321 virtual void Attach(DataObserver *o) const;
322
324 virtual void Detach(DataObserver *o) const;
325
327 virtual void Notify() const;
328 virtual void Notify(const Extent& e) const;
329 virtual void Notify(const Point& p) const;
330
331
338
340
343 void Apply(NonModAlgorithm& a) const;
344
346
350 void ApplyIP(NonModAlgorithm& a) const;
351
354
356
361
364
366
371
373
380
382
386
388
395
397
402
403
411
434
436
442 bool operator==(const ImageHandle& ih) const;
443 bool operator!=(const ImageHandle& ih) const;
445
457
458 void Reciproce();
459
464
466
470 ImageStateBasePtr& ImageStatePtr();
471 const ImageStateBasePtr& ImageStatePtr() const;
473
474protected:
476 ImageHandle(const StatePtrPtr& spp);
477
481 virtual const PixelSampling& Sampling() const;
482
484 static ImageHandle Create(const Extent& e, DataType type, DataDomain dom);
485
486private:
487 // this is all there is to it: two shared_ptr<> instances
488 StatePtrPtr impl_;
489 ObsPtr obs_;
490
491 bool equal(const ImageHandle& ih) const;
492};
493
494
496
505/*
506 In contrast to ConstData and Data, which use is-a inheritance,
507 ConstImageHandle implements its functionality using an instance
508 of ImageHandle as a private member variable, and an implicit
509 copy ctor and assignement op. This avoids Diamond-of-Death
510 virtual inheritance.
511
512 On the downside, the complete ConstData interface needs to be
513 retyped and forwarded to the ImageHandle instance. It is a reference
514 to this instance that is returned for the 'upcasting' to const Data&
515*/
517 friend class ImageHandle;
518public:
520 operator const Data& () const {return handle_;}
521
524
526
530
532
537
539
544
546
550
552
553 ImageHandle Copy(bool cc=true) const;
554
556 ImageHandle Extract(const Extent& e) const;
557
559 bool IsValid() const;
560
562 long MemSize() const;
564
570
573
576
580
582 Vec3 GetAbsoluteOrigin() const;
583
585 Vec3 IndexToCoord(const Point &p) const;
586
588 Vec3 CoordToIndex(const Vec3& c) const;
589
591 Vec3 FractionalIndexToCoord(const Vec3 &p) const;
592
597 Real GetReal(const Point& p) const;
598
600 Complex GetComplex(const Point& p) const;
602
604 virtual Real GetIntpolReal(const Vec3 &v) const;
605 virtual Real GetIntpolReal(const Vec2 &v) const;
606 virtual Real GetIntpolReal(const Real &d) const;
607
609 virtual Complex GetIntpolComplex(const Vec3 &v) const;
610 virtual Complex GetIntpolComplex(const Vec2 &v) const;
611 virtual Complex GetIntpolComplex(const Real &d) const;
612
613
617 void Attach(DataObserver *o) const;
618
620 void Detach(DataObserver *o) const;
621
623 void Notify() const;
624 void Notify(const Extent& e) const;
625 void Notify(const Point& p) const;
626
627
632
634 void Apply(NonModAlgorithm& a) const;
635 void ApplyIP(NonModAlgorithm& a) const;
636
639
642
645
649
656
659
662
665
668
674
678 bool operator==(const ConstImageHandle& ih) const;
679 bool operator==(const ImageHandle& ih) const;
680 bool operator!=(const ConstImageHandle& ih) const;
681 bool operator!=(const ImageHandle& ih) const;
683
684 const ImageStateBasePtr& ImageStatePtr() const;
685
686protected:
687
691 const PixelSampling& Sampling() const;
692
693private:
694 // actual implementation
695 ImageHandle handle_;
696
697 bool equal(const ConstImageHandle& h) const;
698 bool equal(const ImageHandle& h) const;
699};
700
701
709// the other comparison ops are handled as member operators
712
727
732
733
734}} // namespace img
735
736#endif
Abstract base class for read-only data.
Definition data.hh:70
read-only ImageHandle implementation
ConstImageHandle()
Empty, ie invalid handle.
bool operator==(const ConstImageHandle &ih) const
DataDomain GetDomain() const
see ImageHandle::GetDomain()
ConstImageHandle & operator=(const ConstImageHandle &h)
Assign another image based on handle.
void Detach(DataObserver *o) const
see ImageHandle::Detach()
void Attach(DataObserver *o) const
see ImageHandle::Attach()
const ImageStateBasePtr & ImageStatePtr() const
Extent GetExtent() const
see ImageHandle::GetExtent()
const PixelSampling & Sampling() const
see ImageHandle::Sampling()
long MemSize() const
Returns size in bytes of allocated memory.
Complex GetComplex(const Point &p) const
see ImageHandle::GetComplex()
ConstImageHandle(const ImageHandle &h)
Initialize with an existing non-const handle.
void Notify(const Point &p) const
Point GetSpatialOrigin() const
see ImageHandle::GetSpatialOrigin()
ExtentIterator GetIterator() const
Get ExtentIterator.
ImageHandle Extract(const Extent &e) const
see ImageHandle::Copy(const Extent&)
virtual Complex GetIntpolComplex(const Real &d) const
bool operator!=(const ConstImageHandle &ih) const
ImageHandle StateApply(const ImageStateConstModOPVisitorBase &v) const
see ImageHandle::StateApply(ImageStateConstModOPVisitorBase&)
ImageHandle Copy(bool cc=true) const
see ImageHandle::Copy(bool)
bool operator!=(const ImageHandle &ih) const
Vec3 FractionalIndexToCoord(const Vec3 &p) const
See ImageHandle::FractionalIndexToCoord()
ImageHandle Apply(ModIPAlgorithm &a) const
see ImageHandle::Apply(ModIPAlgorithm&)
void Notify() const
see ImageHandle::Notify()
void Apply(NonModAlgorithm &a) const
see ImageHandle::Apply(NonModAlgorithm&)
virtual Complex GetIntpolComplex(const Vec2 &v) const
Real GetReal(const Point &p) const
see ImageHandle::GetReal()
Vec3 CoordToIndex(const Vec3 &c) const
see ImageHandle::CoordToIndex()
PixelSampling & Sampling()
see ImageHandle::Sampling()
void Notify(const Extent &e) const
ImageHandle Apply(const ConstModOPAlgorithm &a) const
see ImageHandle::Apply(const ConstModOPAlgorithm)
virtual Complex GetIntpolComplex(const Vec3 &v) const
Get interpolated complex value from 3D,2D or 1D vec.
Vec3 IndexToCoord(const Point &p) const
see ImageHandle::IndexToCoord()
ImageHandle Apply(const ConstModIPAlgorithm &a) const
see ImageHandle::Apply(const ConstModIPAlgorithm&)
bool IsValid() const
Returns true if handle is valid.
void ApplyIP(NonModAlgorithm &a) const
ImageHandle StateApply(ImageStateModOPVisitorBase &v) const
see ImageHandle::StateApply(ImageStateModOPVisitorBase&)
ImageHandle StateApply(const ImageStateConstModIPVisitorBase &v) const
see ImageHandle::StateApply(ImageStateConstModIPVisitorBase&)
ConstImageHandle & operator=(const ImageHandle &h)
Assign another image based on a non-const handle.
ImageHandle StateApply(ImageStateMorphVisitorBase &v) const
see ImageHandle::StateApply(ImageStateMorphVisitorBase&)
bool operator==(const ImageHandle &ih) const
Vec3 GetAbsoluteOrigin() const
see ImageHandle::GetAbsoluteOrigin()
ConstImageHandle(const ConstImageHandle &h)
Initialize with an existing handle.
ImageHandle Apply(ModOPAlgorithm &a) const
see ImageHandle::Apply(ModOPAlgorithm)
ImageHandle StateApply(ImageStateModIPVisitorBase &v) const
see ImageHandle::StateApply(ImageStateModIPVisitorBase&)
DataType GetType() const
see ImageHandle::GetType()
virtual Real GetIntpolReal(const Real &d) const
void StateApply(ImageStateNonModVisitorBase &v) const
see ImageHandle::StateApply(ImageStateNonModVisitorBase&)
virtual Real GetIntpolReal(const Vec3 &v) const
Get interpolated real value from 3D,2D or 1D vec.
virtual Real GetIntpolReal(const Vec2 &v) const
In-place modification const algorithm.
out-of-place modification const algorithm
Abstract base class for data.
Definition data.hh:253
Abstract base class of data observer.
Defines lower and upper valid indices.
Definition extent.hh:60
Manage shared instances of images.
virtual void Notify(const Extent &e) const
void ApplyIP(ModIPAlgorithm &a)
Apply in-place Algorithm in-place.
ImageHandle & operator*=(Real v)
ImageHandle & operator=(const ImageHandle &h)
Assign another image based on handle.
virtual const PixelSampling & Sampling() const
see Data::Sampling()
ImageHandle & operator+=(const Complex &v)
void SetAbsoluteOrigin(const Vec3 &c)
Sets the absolute coordinate for the spatial origin of the image.
virtual void Notify() const
Notify each observer that state has changed.
ImageHandle & operator*=(const Complex &v)
void Set(const ImageHandle &h)
sets content of image to that of the given one
const ImageStateBasePtr & ImageStatePtr() const
long MemSize() const
Returns size in bytes of allocated memory.
virtual void Detach(DataObserver *o) const
Detach observer.
friend ImageHandle DoCreateImage(const Extent &e, DataType type, DataDomain dom)
virtual Complex GetComplex(const Point &p) const
Retrieve value at given Point as a Complex.
ImageHandle(const ImageHandle &h)
Initialize with an existing handle.
ImageHandle & operator-=(const Complex &v)
void StateApplyIP(ImageStateModOPVisitorBase &v)
Applies out-of-place visitor in-place.
void StateApplyIP(const ImageStateConstModIPVisitorBase &v)
Applies in-place const visitor in-place.
void SetComplex(const Point &p, const Complex &c)
Set explicit complex value.
void ApplyIP(const ConstModOPAlgorithm &a)
Apply out-of-place const Algorithm in-place.
ExtentIterator GetIterator() const
Get ExtentIterator.
ImageHandle Extract(const Extent &e) const
return a handle to a new image containing a partial copy
ImageStateBasePtr & ImageStatePtr()
virtual Complex GetIntpolComplex(const Real &d) const
ImageHandle StateApply(const ImageStateConstModOPVisitorBase &v) const
Applies out-of-place const visitor out-of-place.
ImageHandle(const StatePtrPtr &spp)
Initialization based on a StatePtrPtr.
ImageHandle()
Creates an empty, ie invalid handle.
ImageHandle Copy(bool cc=true) const
return a handle that manages a new instance of the image
static ImageHandle Create(const Extent &e, DataType type, DataDomain dom)
used by CreateImage factory function
void SetSpatialOrigin(const Point &p)
set spatial origin of image
void StateApplyIP(ImageStateMorphVisitorBase &v)
Applies morph visitor in-place.
bool operator!=(const ImageHandle &ih) const
ImageHandle & operator*=(const ConstImageHandle &h)
void CenterSpatialOrigin()
set origin in center
Vec3 FractionalIndexToCoord(const Vec3 &p) const
Index to coordinate conversion.
virtual DataType GetType() const
Return data type: REAL or COMPLEX.
virtual Point GetSpatialOrigin() const
return spatial origin of the image
ImageHandle & operator+=(const ConstImageHandle &h)
ImageHandle & operator+=(Real v)
ImageHandle Apply(ModIPAlgorithm &a) const
Apply in-place Algorithm, return new image with modifications.
void Apply(NonModAlgorithm &a) const
Apply a const algorithm to this image.
virtual Real GetReal(const Point &p) const
Retrieve value at given Point as a Real.
virtual Complex GetIntpolComplex(const Vec2 &v) const
virtual Extent GetExtent() const
retrieve Extent
Vec3 CoordToIndex(const Vec3 &c) const
Convert coordinates back to (fractional) indices.
ImageHandle & operator-=(Real v)
virtual DataDomain GetDomain() const
Return domain: SPATIAL, FREQUENCY or HALF_FREQUENCY.
void ApplyIP(const ConstModIPAlgorithm &a)
Apply in-place const Algorithm in-place.
ImageHandle Apply(const ConstModOPAlgorithm &a) const
Apply out-of-place const Algorithm.
virtual Complex GetIntpolComplex(const Vec3 &v) const
Get interpolated complex value from 3D,2D or 1D vec.
ImageHandle & operator/=(Real v)
Vec3 IndexToCoord(const Point &p) const
Index to coordinate conversion.
ImageHandle Apply(const ConstModIPAlgorithm &a) const
Apply in-place const Algorithm, return new image with modifications.
ImageHandle & operator/=(const Complex &v)
bool IsValid() const
Returns true if handle is valid.
void ApplyIP(NonModAlgorithm &a) const
Apply a const algorithm to this image.
ImageHandle StateApply(ImageStateModOPVisitorBase &v) const
Applies out-of-place visitor out-of-place.
void ApplyIP(ModOPAlgorithm &a)
Apply out-of-place Algorithm in-place.
ImageHandle & operator-=(const ConstImageHandle &h)
ImageHandle StateApply(const ImageStateConstModIPVisitorBase &v) const
Applies in-place const visitor out-of-place.
void StateApplyIP(ImageStateModIPVisitorBase &v)
Applies in-place visitor in-place.
void SetReal(const Point &p, Real r)
ImageHandle StateApply(ImageStateMorphVisitorBase &v) const
Applies morph visitor out-of-place.
void Swap(ImageHandle &h)
swap guts with another handle
bool operator==(const ImageHandle &ih) const
Vec3 GetAbsoluteOrigin() const
Get absolute coordinate for the spatial origin of the image.
void Paste(const Data &d)
pastes given data to this image, using data extent
virtual void Attach(DataObserver *o) const
Attach observer.
void StateApplyIP(const ImageStateConstModOPVisitorBase &v)
Applies out-of-place const visitor in-place.
void Reset(const Extent &e, DataType type=REAL, DataDomain dom=SPATIAL)
Reset image state to given size, type and domain.
ImageHandle Apply(ModOPAlgorithm &a) const
Apply out-of-place Algorithm.
ImageHandle StateApply(ImageStateModIPVisitorBase &v) const
Applies in-place visitor out-of-place.
virtual Real GetIntpolReal(const Real &d) const
void StateApply(ImageStateNonModVisitorBase &v) const
Apply non-modifying state visitor.
virtual void Notify(const Point &p) const
virtual Real GetIntpolReal(const Vec3 &v) const
Get interpolated real value from 3D,2D or 1D vec.
virtual PixelSampling & Sampling()
see Data::Sampling()
virtual Real GetIntpolReal(const Vec2 &v) const
ImageHandle & operator/=(const ConstImageHandle &h)
Exception thrown upon invalid image handle usage.
In-place modification algorithm.
out-of-place modification algorithm
Non-modifying Algorithm, abstract base class.
templated observable class
Definition observable.hh:44
Helper class to handle pixel sampling.
class encapsulating 1D to 3D point
Definition point.hh:47
in-place modifying image state const visitor base class
out-of-place modifying image state const visitor base class
in-place modifying image state visitor base class
out-of-place modifying image state visitor base class
morphing image state visitor base class
non-modifying image state visitor base class
#define DLLEXPORT_OST_IMG_BASE
float Real
Definition base.hh:44
std::complex< Real > Complex
Definition base.hh:51
boost::shared_ptr< ImageStateBase > ImageStateBasePtr
DLLEXPORT_OST_IMG_BASE ImageHandle operator-(const ConstImageHandle &h, Real v)
DLLEXPORT_OST_IMG_BASE ImageHandle operator/(const ConstImageHandle &h, Real v)
DLLEXPORT_OST_IMG_BASE ImageHandle operator+(const ConstImageHandle &h, Real v)
DataDomain
underlying data type
Definition data_types.hh:42
DLLEXPORT_OST_IMG_BASE ImageHandle operator*(const ConstImageHandle &h, Real v)
DLLEXPORT_OST_IMG_BASE bool operator!=(const ImageHandle &lhs, const ConstImageHandle &rhs)
DLLEXPORT_OST_IMG_BASE bool operator==(const ImageHandle &lhs, const ConstImageHandle &rhs)
Definition base.dox:1
void test_Observer()