Volume Cartographer 2.27.0
PerPixelMap.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <cstddef>
6#include <memory>
7
8#include <opencv2/core.hpp>
9
13
14namespace volcart
15{
50{
52 struct Coord2D {
54 Coord2D() = default;
56 Coord2D(std::size_t y, std::size_t x) : y{y}, x{x} {}
58 std::size_t y;
60 std::size_t x;
61 };
62
64 struct PixelMap : public Coord2D {
66 PixelMap() = default;
67
69 PixelMap(std::size_t y, std::size_t x, cv::Vec6d value)
70 : Coord2D{y, x}
71 , pos{value[0], value[1], value[2]}
72 , normal{value[3], value[4], value[5]}
73 {
74 }
75
77 cv::Vec3d pos;
79 cv::Vec3d normal;
80 };
81
82public:
84 using Pointer = std::shared_ptr<PerPixelMap>;
85
88 PerPixelMap() = default;
89
91 PerPixelMap(std::size_t height, std::size_t width);
92
94 template <typename... Args>
95 static auto New(Args... args) -> Pointer
96 {
97 return std::make_shared<PerPixelMap>(std::forward<Args>(args)...);
98 }
99
105 [[nodiscard]] auto initialized() const -> bool;
110 auto operator()(std::size_t y, std::size_t x) const -> const cv::Vec6d&;
111
113 auto operator()(std::size_t y, std::size_t x) -> cv::Vec6d&;
114
116 [[nodiscard]] auto getMapping(std::size_t y, std::size_t x) const
117 -> const cv::Vec6d&;
118
120 auto getMapping(std::size_t y, std::size_t x) -> cv::Vec6d&;
121
127 [[nodiscard]] auto hasMapping(std::size_t y, std::size_t x) const -> bool;
128
130 auto getAsPixelMap(std::size_t y, std::size_t x) -> PixelMap;
131
144 [[nodiscard]] auto getMappings() const -> std::vector<PixelMap>;
145
163 [[nodiscard]] auto getMappingCoords() const -> std::vector<Coord2D>;
164
171 [[nodiscard]] auto numMappings() const -> std::size_t;
181 void setDimensions(std::size_t h, std::size_t w);
182
187 void setWidth(std::size_t w);
188
193 void setHeight(std::size_t h);
194
196 [[nodiscard]] auto width() const -> std::size_t;
197
199 [[nodiscard]] auto height() const -> std::size_t;
204 [[nodiscard]] auto mask() const -> cv::Mat;
205
216 void setMask(const cv::Mat& m);
217
225 [[nodiscard]] auto cellMap() const -> cv::Mat;
226
232 void setCellMap(const cv::Mat& m);
237 static void WritePPM(const filesystem::path& path, const PerPixelMap& map);
238
240 static auto ReadPPM(const filesystem::path& path) -> PerPixelMap;
244 static auto Crop(
245 const PerPixelMap& map,
246 std::size_t originY,
247 std::size_t originX,
248 std::size_t height,
249 std::size_t width) -> PerPixelMap;
250
251private:
258
260 std::size_t height_{0};
262 std::size_t width_{0};
265
272 cv::Mat mask_;
273
275 cv::Mat cellMap_;
276};
277} // namespace volcart
A raster of a UVMap that provides a per-pixel mapping between a Volume and a Texture generated from t...
Definition: PerPixelMap.hpp:50
PerPixelMap(std::size_t height, std::size_t width)
Constructor with width and height parameters.
static auto ReadPPM(const filesystem::path &path) -> PerPixelMap
Read a PerPixelMap from disk.
static auto New(Args... args) -> Pointer
Definition: PerPixelMap.hpp:95
auto cellMap() const -> cv::Mat
Get the cell map image.
auto hasMapping(std::size_t y, std::size_t x) const -> bool
Return whether there is a mapping for the pixel at x, y.
static void WritePPM(const filesystem::path &path, const PerPixelMap &map)
Write a PerPixelMap to disk.
void setHeight(std::size_t h)
Set the height of the map.
std::shared_ptr< PerPixelMap > Pointer
Definition: PerPixelMap.hpp:84
auto mask() const -> cv::Mat
Get the pixel mask.
auto getMapping(std::size_t y, std::size_t x) const -> const cv::Vec6d &
Get the mapping for a pixel by x, y coordinate.
auto getMappings() const -> std::vector< PixelMap >
Get a list of valid pixel mappings.
auto initialized() const -> bool
Return whether the PerPixelMap has been initialized.
auto numMappings() const -> std::size_t
Get the number of valid mappings.
auto height() const -> std::size_t
Get the height of the map.
auto getMappingCoords() const -> std::vector< Coord2D >
Get a list of pixel coordinates with valid mappings.
void setCellMap(const cv::Mat &m)
Set the cell map image.
OrderedPointSet< cv::Vec6d > map_
void setDimensions(std::size_t h, std::size_t w)
Set the dimensions of the map.
auto getAsPixelMap(std::size_t y, std::size_t x) -> PixelMap
Get the mapping for a pixel as a PixelMap.
void setWidth(std::size_t w)
Set the width of the map.
PerPixelMap()=default
Default constructor.
static auto Crop(const PerPixelMap &map, std::size_t originY, std::size_t originX, std::size_t height, std::size_t width) -> PerPixelMap
Create a cropped PPM.
void setMask(const cv::Mat &m)
Set the pixel mask.
auto width() const -> std::size_t
Get the width of the map.
Volume Cartographer library
Coord2D(std::size_t y, std::size_t x)
Definition: PerPixelMap.hpp:56
PixelMap(std::size_t y, std::size_t x, cv::Vec6d value)
Definition: PerPixelMap.hpp:69