SourceXtractorPlusPlus
0.15
Please provide a description of the project.
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
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),
74
m_read_height
(h) {};
75
76
ImageAccessor
(
const
Image<T>
& img,
AccessHint
hint =
TOP_LEFT
,
int
w = 64,
int
h = 64)
77
:
m_image
(&img),
m_hint
(hint),
m_read_width
(w),
m_read_height
(h) {};
78
82
ImageAccessor
(
const
ImageAccessor<T>
&) =
delete
;
83
87
ImageAccessor
(
ImageAccessor<T>
&&) =
default
;
88
92
ImageAccessor<T>
&
operator=
(
const
ImageAccessor<T>
&) =
delete
;
93
100
T
getValue
(
int
x
,
int
y
) {
101
selectChunk
(
PixelCoordinate
(x, y));
102
x -=
m_chunk_min
.
m_x
;
103
y -=
m_chunk_min
.
m_y
;
104
return
m_chunk
->getValue(x, y);
105
}
106
107
T
getValue
(
const
PixelCoordinate
& coord) {
108
selectChunk
(coord);
109
return
m_chunk
->getValue(coord -
m_chunk_min
);
110
}
111
112
/*
113
* Forward these methods directly to the wrapped image
114
*/
115
116
std::string
getRepr
()
const override
{
117
return
m_image
->getRepr();
118
}
119
120
int
getWidth
()
const override
{
121
return
m_image
->getWidth();
122
}
123
124
int
getHeight
()
const override
{
125
return
m_image
->getHeight();
126
}
127
128
std::shared_ptr<ImageChunk<T>
>
getChunk
(
int
x
,
int
y
,
int
width
,
int
height
)
const override
{
129
return
m_image
->getChunk(x, y, width, height);
130
};
131
132
private
:
133
const
Image<T>
*
m_image
;
134
std::shared_ptr<const Image<T>
>
m_keep_alive
;
135
std::shared_ptr<const ImageChunk<T>
>
m_chunk
;
136
PixelCoordinate
m_chunk_min
,
m_chunk_max
;
137
AccessHint
m_hint
;
138
int
m_read_width
,
m_read_height
;
139
144
void
selectChunk
(
const
PixelCoordinate
& coord) {
145
if
(
m_chunk
&& coord >=
m_chunk_min
&& coord <=
m_chunk_max
) {
146
return
;
147
}
148
nextCoordinates
(coord);
149
m_chunk
=
m_image
->getChunk(
m_chunk_min
,
m_chunk_max
);
150
}
151
155
void
nextCoordinates
(
const
PixelCoordinate
& coord) {
156
if
(!
m_chunk
) {
157
m_chunk_min
=
firstCoordinates
(coord);
158
}
159
else
{
160
switch
(
m_hint
) {
161
case
TOP_LEFT
:
162
case
CENTERED
:
163
m_chunk_min
.
m_x
= coord.
m_x
;
164
m_chunk_min
.
m_y
= coord.
m_y
;
165
break
;
166
case
BOTTOM_RIGHT
:
167
m_chunk_min
.
m_x
= coord.
m_x
-
m_read_width
+ 1;
168
m_chunk_min
.
m_y
= coord.
m_y
-
m_read_height
+ 1;
169
break
;
170
}
171
}
172
// Make sure we don't leave the image
173
m_chunk_min
.
clip
(
m_image
->getWidth(),
m_image
->getHeight());
174
// Max pixel
175
m_chunk_max
.
m_x
=
m_chunk_min
.
m_x
+
m_read_width
;
176
m_chunk_max
.
m_y
=
m_chunk_min
.
m_y
+
m_read_height
;
177
m_chunk_max
.
clip
(
m_image
->getWidth(),
m_image
->getHeight());
178
}
179
180
PixelCoordinate
firstCoordinates
(
const
PixelCoordinate
& coord) {
181
switch
(
m_hint
) {
182
case
CENTERED
:
183
return
PixelCoordinate
(coord.
m_x
-
m_read_width
/ 2, coord.
m_y
-
m_read_height
/ 2);
184
case
TOP_LEFT
:
185
return
coord;
186
case
BOTTOM_RIGHT
:
187
return
PixelCoordinate
(coord.
m_x
-
m_read_width
, coord.
m_y
-
m_read_height
);
188
}
189
return
coord;
190
}
191
};
192
193
}
// end of namespace SourceXtractor
194
195
#endif // _SEFRAMEWORK_IMAGE_IMAGEACCESSOR_H
SourceXtractor::ImageAccessor::selectChunk
void selectChunk(const PixelCoordinate &coord)
Definition:
ImageAccessor.h:144
SourceXtractor::ImageAccessor::getChunk
std::shared_ptr< ImageChunk< T > > getChunk(int x, int y, int width, int height) const override
Definition:
ImageAccessor.h:128
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:76
SourceXtractor::ImageAccessor::m_chunk_max
PixelCoordinate m_chunk_max
Definition:
ImageAccessor.h:136
SourceXtractor::ImageAccessor::getValue
T getValue(const PixelCoordinate &coord)
Definition:
ImageAccessor.h:107
SourceXtractor::ImageAccessor::m_read_width
int m_read_width
Definition:
ImageAccessor.h:138
SourceXtractor::ImageAccessor::m_chunk_min
PixelCoordinate m_chunk_min
Definition:
ImageAccessor.h:136
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:137
SourceXtractor::ImageAccessor::getWidth
int getWidth() const override
Returns the width of the image in pixels.
Definition:
ImageAccessor.h:120
SourceXtractor::ImageAccessor::m_read_height
int m_read_height
Definition:
ImageAccessor.h:138
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:135
SourceXtractor::ImageAccessor::getHeight
int getHeight() const override
Returns the height of the image in pixels.
Definition:
ImageAccessor.h:124
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:116
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::AccessHint
AccessHint
Definition:
ImageAccessor.h:48
std::move
T move(T...args)
SourceXtractor::ImageAccessor::firstCoordinates
PixelCoordinate firstCoordinates(const PixelCoordinate &coord)
Definition:
ImageAccessor.h:180
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:134
SourceXtractor::ImageAccessor::nextCoordinates
void nextCoordinates(const PixelCoordinate &coord)
Definition:
ImageAccessor.h:155
SourceXtractor::Image
Interface representing an image.
Definition:
Image.h:43
SourceXtractor::ImageAccessor::m_image
const Image< T > * m_image
Definition:
ImageAccessor.h:130
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:100
SourceXtractor::PixelCoordinate::m_x
int m_x
Definition:
PixelCoordinate.h:38
Generated by
1.8.5