Go to the documentation of this file.
31 template <
class TPixel,
class TAllocator>
34 template <
class TPixel,
class TAllocator>
54 template <
class TPixel>
68 :
ImageView(ImageLayout::makeFromSize<TPixel>(image_size),
ptr) {}
71 [[nodiscard]]
auto isEmpty() const ->
bool {
return this->
ptr_ ==
nullptr; }
88 [[nodiscard]]
auto area() const ->
size_t {
return layout().area(); }
89 [[nodiscard]]
auto width() const ->
int {
return layout().width(); }
90 [[nodiscard]]
auto height() const ->
int {
return layout().height(); }
92 return layout().pitchBytes();
95 return layout().sizeBytes();
111 [[nodiscard]]
auto rowPtr(
int v)
const -> TPixel
const* {
131 [[nodiscard]]
auto operator()(
int u,
int v)
const -> TPixel
const& {
135 [[nodiscard]]
auto operator()(Eigen::Vector2i uv)
const -> TPixel
const& {
140 [[nodiscard]]
auto ptr() const -> TPixel const* {
return ptr_; }
155 template <
class TFunc>
156 void visit(TFunc
const& user_function)
const {
160 TPixel
const* p = this->
rowPtr(v);
162 for (; p != end_of_row; ++p) {
169 template <
class TReduceOp,
class TVal>
170 [[nodiscard]]
auto reduce(TReduceOp
const& reduce_op, TVal val = TVal{})
const
175 TPixel
const* p = this->
rowPtr(v);
177 for (; p != end_of_row; ++p) {
185 template <
class TShortCircuitReduceOp,
class TVal>
187 TShortCircuitReduceOp
const& short_circuit_reduce_op,
188 TVal val = TVal{})
const -> TVal {
192 TPixel
const* p = this->
rowPtr(v);
194 for (; p != end_of_row; ++p) {
195 if (short_circuit_reduce_op(*p, val)) {
220 if (!(this->
imageSize() == rhs.imageSize())) {
224 TPixel
const* p = this->
rowPtr(v);
225 TPixel
const* rhs_p = rhs.rowPtr(v);
228 for (; p != end_of_row; ++p, ++rhs_p) {
245 template <
class TT,
class TAllocator>
248 template <
class TT,
class TAllocator>
254 template <
class TPixel>
257 [](TPixel v,
auto& min_max) {
266 template <
class TPixel>
272 template <
class TPixel>
273 [[nodiscard]]
auto checkedPixelAccess(
274 ImageView<TPixel>
const& view,
277 std::string
const& file,
279 std::string
const&
str) -> TPixel
const& {
280 if (!view.colInBounds(u) || !view.rowInBounds(v)) {
283 "pixel `{},{}` not in image with size {} x {}",
286 view.imageSize().width,
287 view.imageSize().height);
289 ::fmt::print(stderr,
"{}",
str);
299 #define SOPHUS_PIXEL_MUT(img, u, v, ...) \
300 ::sophus::details::checkedPixelAccessMut( \
301 img, u, v, __FILE__, __LINE__, SOPHUS_FORMAT(__VA_ARGS__))
auto height() const -> int
Definition: layout.h:55
#define SOPHUS_ASSERT(...)
Definition: common.h:40
auto width() const -> int
Definition: image_view.h:89
auto isEmpty() const -> bool
Returns true if view is empty.
Definition: image_view.h:71
TPixel Pixel
Definition: image_view.h:56
void visit(TFunc const &user_function) const
Performs reduction / fold on image view.
Definition: image_view.h:156
auto pitchBytes() const -> size_t
Definition: layout.h:57
void setViewToEmpty()
Resets view such that it is empty.
Definition: image_view.h:239
str
Definition: event_service.py:547
Image read-only access to pixels and shared ownership, hence cheap to copy. Type is nullable.
Definition: image.h:31
Layout of the image: width, height and pitch in bytes.
Definition: layout.h:23
Image MutImage, owning images types.
Definition: num_diff.h:20
auto area() const -> size_t
Definition: image_view.h:88
auto ptr() const -> TPixel const *
Returns pointer to first pixel.
Definition: image_view.h:140
A view of an (immutable) image, which does not own the data.
Definition: image_view.h:55
auto rowInBounds(int v) const -> bool
Returns true if v is in [0, height).
Definition: image_view.h:104
auto hasSameData(ImageView const &rhs) const -> bool
Returns true both views have the same size and contain the same data.
Definition: image_view.h:219
auto width() const -> int
Definition: layout.h:54
auto layout() const -> ImageLayout const &
Returns ImageLayout. It is {{0,0}, 0} is view is empty.
Definition: image_view.h:86
auto imageSize() const -> sophus::ImageSize const &
Returns ImageSize. It is {0,0} if view is empty.
Definition: image_view.h:80
static auto empty() noexcept -> Region< TPoint >
Creates and empty region.
Definition: region.h:72
ImageView()=default
Default constructor creates an empty image.
auto operator!=(ImageView const &rhs) const -> bool=delete
The in-equality operator is deleted to avoid confusion.
A image with write access to pixels and exclusive ownership. There is no copy constr / copy assignmen...
Definition: image_view.h:32
auto colInBounds(int u) const -> bool
Returns true if u is in [0, width).
Definition: image_view.h:99
auto operator()(Eigen::Vector2i uv) const -> TPixel const &
Definition: image_view.h:135
ImageView(sophus::ImageSize image_size, TPixel const *ptr) noexcept
Creates view from image size and pointer to first pixel. The image is assumed to be contiguous and th...
Definition: image_view.h:67
auto imageCoordsInterval(ImageSize image_size, int border=0) -> Region2I
Definition: image_size.h:61
#define SOPHUS_ASSERT_LE(...)
Definition: common.h:44
auto pitchBytes() const -> size_t
Definition: image_view.h:91
auto isContiguous() const -> bool
Returns true if view is contiguous.
Definition: image_view.h:74
auto isFinite(TPoint const &p) -> bool
Definition: vector_space.h:74
auto operator==(ImageView const &rhs) const -> bool=delete
The equality operator is deleted to avoid confusion. Since ImageView is a "shallow-copy" type,...
auto reduce(TReduceOp const &reduce_op, TVal val=TVal{}) const -> TVal
Performs reduction / fold on image view.
Definition: image_view.h:170
ImageLayout layout_
Definition: image_view.h:241
auto sizeBytes() const -> size_t
Definition: image_view.h:94
ImageView(ImageLayout layout, TPixel const *ptr) noexcept
Creates view from layout and pointer to first pixel.
Definition: image_view.h:62
auto rowPtr(int v) const -> TPixel const *
Returns v-th row pointer.
Definition: image_view.h:111
auto height() const -> int
Definition: image_view.h:90
Region2< int > Region2I
Definition: region.h:27
auto operator()(int u, int v) const -> TPixel const &
Returns pixel u, v.
Definition: image_view.h:131
auto imageSize() const -> sophus::ImageSize const &
Definition: layout.h:51
TPixel const * ptr_
Definition: image_view.h:242
Image size, hence its width and height.
Definition: image_size.h:21
A region is a closed interval [a, b] with a being the lower bound (=min) and b being the upper bound ...
Definition: region.h:19
auto shortCircuitReduce(TShortCircuitReduceOp const &short_circuit_reduce_op, TVal val=TVal{}) const -> TVal
Performs reduction / fold on image view with short circuit condition.
Definition: image_view.h:186
auto subview(Eigen::Vector2i uv, sophus::ImageSize size) const -> ImageView
Returns subview.
Definition: image_view.h:143