SourceXtractorPlusPlus
0.19
SourceXtractor++, the next generation SExtractor
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
SEFramework
SEFramework
Image
ImageAccessor.h
Go to the documentation of this file.
1
18
#ifndef _SEFRAMEWORK_IMAGE_IMAGEACCESSOR_H
19
#define _SEFRAMEWORK_IMAGE_IMAGEACCESSOR_H
20
21
#include "
SEFramework/Image/Image.h
"
22
#include "
SEFramework/Image/ImageChunk.h
"
23
24
namespace
SourceXtractor {
25
40
template
<
typename
T>
41
class
ImageAccessor
:
public
Image
<T> {
42
public
:
43
48
enum
AccessHint
{
49
TOP_LEFT
,
//< The first coordinate is likely the top left corner of what is going to be needed
50
CENTERED
,
//< The first coordinate is likely the center of a region
51
BOTTOM_RIGHT
,
//< The first coordinate is likely the bottom right corner
52
};
53
55
~ImageAccessor
() =
default
;
56
72
explicit
ImageAccessor
(
std::shared_ptr
<
const
Image<T>
> img,
AccessHint
hint =
TOP_LEFT
,
int
w = 64,
int
h = 1)
73
:
m_image
(img.get()),
m_keep_alive
(std::
move
(img)),
m_hint
(hint),
m_read_width
(w),
m_read_height
(h){};
74
75
explicit
ImageAccessor
(
const
Image<T>
& img,
AccessHint
hint =
TOP_LEFT
,
int
w = 64,
int
h = 64)
76
:
m_image
(&img),
m_hint
(hint),
m_read_width
(w),
m_read_height
(h){};
77
81
ImageAccessor
(
const
ImageAccessor<T>
&) =
delete
;
82
86
ImageAccessor
(
ImageAccessor<T>
&&) =
default
;
87
91
ImageAccessor<T>
&
operator=
(
const
ImageAccessor<T>
&) =
delete
;
92
99
T
getValue
(
int
x
,
int
y
) {
100
selectChunk
(
PixelCoordinate
(x, y));
101
x -=
m_chunk_min
.
m_x
;
102
y -=
m_chunk_min
.
m_y
;
103
return
m_chunk
->getValue(x, y);
104
}
105
106
T
getValue
(
const
PixelCoordinate
& coord) {
107
selectChunk
(coord);
108
return
m_chunk
->getValue(coord -
m_chunk_min
);
109
}
110
111
/*
112
* Forward these methods directly to the wrapped image
113
*/
114
115
std::string
getRepr
()
const override
{
116
return
m_image
->getRepr();
117
}
118
119
int
getWidth
()
const override
{
120
return
m_image
->getWidth();
121
}
122
123
int
getHeight
()
const override
{
124
return
m_image
->getHeight();
125
}
126
127
std::shared_ptr<ImageChunk<T>
>
getChunk
(
int
x
,
int
y
,
int
width
,
int
height
)
const override
{
128
return
m_image
->getChunk(x, y, width, height);
129
};
130
131
private
:
132
const
Image<T>
*
m_image
;
133
std::shared_ptr<const Image<T>
>
m_keep_alive
;
134
std::shared_ptr<const ImageChunk<T>
>
m_chunk
;
135
PixelCoordinate
m_chunk_min
,
m_chunk_max
;
136
AccessHint
m_hint
;
137
int
m_read_width
,
m_read_height
;
138
143
void
selectChunk
(
const
PixelCoordinate
& coord) {
144
if
(
m_chunk
&& coord >=
m_chunk_min
&& coord <=
m_chunk_max
) {
145
return
;
146
}
147
nextCoordinates
(coord);
148
m_chunk
=
m_image
->getChunk(
m_chunk_min
,
m_chunk_max
);
149
}
150
154
void
nextCoordinates
(
const
PixelCoordinate
& coord) {
155
if
(!
m_chunk
) {
156
m_chunk_min
=
firstCoordinates
(coord);
157
}
158
else
{
159
switch
(
m_hint
) {
160
case
TOP_LEFT
:
161
case
CENTERED
:
162
m_chunk_min
.
m_x
= coord.
m_x
;
163
m_chunk_min
.
m_y
= coord.
m_y
;
164
break
;
165
case
BOTTOM_RIGHT
:
166
m_chunk_min
.
m_x
= coord.
m_x
-
m_read_width
+ 1;
167
m_chunk_min
.
m_y
= coord.
m_y
-
m_read_height
+ 1;
168
break
;
169
}
170
}
171
// Make sure we don't leave the image
172
m_chunk_min
.
clip
(
m_image
->getWidth(),
m_image
->getHeight());
173
// Max pixel
174
m_chunk_max
.
m_x
=
m_chunk_min
.
m_x
+
m_read_width
;
175
m_chunk_max
.
m_y
=
m_chunk_min
.
m_y
+
m_read_height
;
176
m_chunk_max
.
clip
(
m_image
->getWidth(),
m_image
->getHeight());
177
}
178
179
PixelCoordinate
firstCoordinates
(
const
PixelCoordinate
& coord) {
180
switch
(
m_hint
) {
181
case
CENTERED
:
182
return
PixelCoordinate
(coord.
m_x
-
m_read_width
/ 2, coord.
m_y
-
m_read_height
/ 2);
183
case
TOP_LEFT
:
184
return
coord;
185
case
BOTTOM_RIGHT
:
186
return
PixelCoordinate
(coord.
m_x
-
m_read_width
, coord.
m_y
-
m_read_height
);
187
}
188
return
coord;
189
}
190
};
191
192
}
// end of namespace SourceXtractor
193
194
#endif // _SEFRAMEWORK_IMAGE_IMAGEACCESSOR_H
SourceXtractor::ImageAccessor::selectChunk
void selectChunk(const PixelCoordinate &coord)
Definition:
ImageAccessor.h:143
SourceXtractor::ImageAccessor::getChunk
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const override
Definition:
ImageAccessor.h:127
SourceXtractor::PixelCoordinate::m_y
int m_y
Definition:
PixelCoordinate.h:38
std::shared_ptr
SourceXtractor::ImageAccessor::TOP_LEFT
Definition:
ImageAccessor.h:49
SourceXtractor::ImageAccessor::ImageAccessor
ImageAccessor(const Image< T > &img, AccessHint hint=TOP_LEFT, int w=64, int h=64)
Definition:
ImageAccessor.h:75
SourceXtractor::ImageAccessor::m_chunk_max
PixelCoordinate m_chunk_max
Definition:
ImageAccessor.h:135
SourceXtractor::ImageAccessor::getValue
T getValue(const PixelCoordinate &coord)
Definition:
ImageAccessor.h:106
SourceXtractor::ImageAccessor::m_read_width
int m_read_width
Definition:
ImageAccessor.h:137
SourceXtractor::ImageAccessor::m_chunk_min
PixelCoordinate m_chunk_min
Definition:
ImageAccessor.h:135
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition:
MoffatModelFittingTask.cpp:94
SourceXtractor::PixelCoordinate::clip
bool clip(int w, int h)
Definition:
PixelCoordinate.h:90
SourceXtractor::ImageAccessor::m_hint
AccessHint m_hint
Definition:
ImageAccessor.h:136
SourceXtractor::ImageAccessor::getWidth
int getWidth() const override
Returns the width of the image in pixels.
Definition:
ImageAccessor.h:119
SourceXtractor::ImageAccessor::m_read_height
int m_read_height
Definition:
ImageAccessor.h:137
y
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
Definition:
MoffatModelFittingTask.cpp:94
SourceXtractor::ImageAccessor::m_chunk
std::shared_ptr< const ImageChunk< T > > m_chunk
Definition:
ImageAccessor.h:134
SourceXtractor::ImageAccessor::getHeight
int getHeight() const override
Returns the height of the image in pixels.
Definition:
ImageAccessor.h:123
std::string
STL class.
SourceXtractor::ImageAccessor::~ImageAccessor
~ImageAccessor()=default
Image.h
SourceXtractor::ImageAccessor::getRepr
std::string getRepr() const override
Get a string identifying this image in a human readable manner.
Definition:
ImageAccessor.h:115
SourceXtractor::ImageAccessor::BOTTOM_RIGHT
Definition:
ImageAccessor.h:51
SourceXtractor::PixelCoordinate
A pixel coordinate made of two integers m_x and m_y.
Definition:
PixelCoordinate.h:37
SourceXtractor::ImageAccessor< SourceXtractor::WriteableImage::PixelType >::AccessHint
AccessHint
Definition:
ImageAccessor.h:48
std::move
T move(T...args)
SourceXtractor::ImageAccessor::firstCoordinates
PixelCoordinate firstCoordinates(const PixelCoordinate &coord)
Definition:
ImageAccessor.h:179
SourceXtractor::ImageAccessor
Definition:
ImageAccessor.h:41
SourceXtractor::ImageAccessor::CENTERED
Definition:
ImageAccessor.h:50
ImageChunk.h
SourceXtractor::ImageAccessor::operator=
ImageAccessor< T > & operator=(const ImageAccessor< T > &)=delete
ModelFitting::height
height
Definition:
CompactModelBase.icpp:19
SourceXtractor::ImageAccessor::m_keep_alive
std::shared_ptr< const Image< T > > m_keep_alive
Definition:
ImageAccessor.h:133
SourceXtractor::ImageAccessor::nextCoordinates
void nextCoordinates(const PixelCoordinate &coord)
Definition:
ImageAccessor.h:154
SourceXtractor::Image
Interface representing an image.
Definition:
Image.h:43
SourceXtractor::ImageAccessor::m_image
const Image< T > * m_image
Definition:
ImageAccessor.h:129
SourceXtractor::ImageAccessor::ImageAccessor
ImageAccessor(std::shared_ptr< const Image< T >> img, AccessHint hint=TOP_LEFT, int w=64, int h=1)
Definition:
ImageAccessor.h:72
ModelFitting::width
width
Definition:
CompactModelBase.icpp:19
SourceXtractor::ImageAccessor::getValue
T getValue(int x, int y)
Definition:
ImageAccessor.h:99
SourceXtractor::PixelCoordinate::m_x
int m_x
Definition:
PixelCoordinate.h:38
Generated by
1.8.5