Volume Cartographer 2.27.0
UVMap.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <cstddef>
6#include <map>
7#include <memory>
8
9#include <opencv2/core.hpp>
10#include <opencv2/imgproc.hpp>
11
14
15namespace volcart
16{
18const static cv::Vec2d NULL_MAPPING{-1, -1};
19
51class UVMap
52{
53public:
55 using Pointer = std::shared_ptr<UVMap>;
56
58 enum class Origin { TopLeft = 0, TopRight, BottomLeft, BottomRight };
59
61 struct Ratio {
62 double width{1}, height{1}, aspect{1};
63 };
64
67 UVMap() = default;
68
70 explicit UVMap(Origin o);
71
73 template <typename... Args>
74 static auto New(Args... args) -> Pointer
75 {
76 return std::make_shared<UVMap>(std::forward<Args>(args)...);
77 }
82 [[nodiscard]] auto size() const -> std::size_t;
83
85 [[nodiscard]] auto empty() const -> bool;
94 void setOrigin(const Origin& o);
95
97 [[nodiscard]] auto origin() const -> Origin;
106 void set(std::size_t id, const cv::Vec2d& uv, const Origin& o);
107
113 void set(std::size_t id, const cv::Vec2d& uv);
114
120 [[nodiscard]] auto get(std::size_t id, const Origin& o) const -> cv::Vec2d;
121
127 [[nodiscard]] auto get(std::size_t id) const -> cv::Vec2d;
128
130 [[nodiscard]] auto contains(std::size_t id) const -> bool;
131
133 [[nodiscard]] auto as_map() const -> std::map<std::size_t, cv::Vec2d>;
138 [[nodiscard]] auto ratio() const -> Ratio;
139
141 void ratio(double a);
142
144 void ratio(double w, double h);
149 enum class Rotation { CW90 = 0, CW180, CCW90 };
150
152 enum class FlipAxis { Vertical = 0, Horizontal, Both };
153
155 enum class AlignmentAxis { None = 0, ZPos, ZNeg, YPos, YNeg, XPos, XNeg };
156
162 static auto Plot(const UVMap& uv, const Color& color = color::GREEN)
163 -> cv::Mat;
164
170 static auto Plot(
171 const UVMap& uv,
172 const ITKMesh::Pointer& mesh2D,
173 int width = -1,
174 int height = -1,
175 const Color& color = color::LIGHT_GRAY) -> cv::Mat;
176
199 static void AlignToAxis(
200 UVMap& uv, const ITKMesh::Pointer& mesh, AlignmentAxis axis);
201
203 static void Rotate(UVMap& uv, Rotation rotation);
204
210 static void Rotate(UVMap& uv, Rotation rotation, cv::Mat& texture);
211
218 static void Rotate(
219 UVMap& uv, double theta, const cv::Vec2d& center = {0.5, 0.5});
220
226 static void Rotate(
227 UVMap& uv,
228 double theta,
229 cv::Mat& texture,
230 const cv::Vec2d& center = {0.5, 0.5});
231
233 static void Flip(UVMap& uv, FlipAxis axis);
236private:
238 std::map<std::size_t, cv::Vec2d> map_;
240 Origin origin_{Origin::TopLeft};
243};
244} // namespace volcart
Stores per-vertex UV mappings.
Definition: UVMap.hpp:52
static void Rotate(UVMap &uv, Rotation rotation)
Rotate a UVMap by a multiple of 90 degrees.
static void Rotate(UVMap &uv, double theta, cv::Mat &texture, const cv::Vec2d &center={0.5, 0.5})
Rotate a UVMap by a specified angle.
std::shared_ptr< UVMap > Pointer
Definition: UVMap.hpp:55
static void Flip(UVMap &uv, FlipAxis axis)
Flip a UVMap across one or both of its axes.
UVMap(Origin o)
Construct and set origin.
static auto Plot(const UVMap &uv, const ITKMesh::Pointer &mesh2D, int width=-1, int height=-1, const Color &color=color::LIGHT_GRAY) -> cv::Mat
Plot the UV mesh on an image.
static void Rotate(UVMap &uv, double theta, const cv::Vec2d &center={0.5, 0.5})
Rotate a UVMap by a specified angle.
std::map< std::size_t, cv::Vec2d > map_
Definition: UVMap.hpp:238
void setOrigin(const Origin &o)
Set the origin of the UVMap.
Ratio ratio_
Definition: UVMap.hpp:242
auto contains(std::size_t id) const -> bool
Check if the vertex index has a UV mapping.
auto get(std::size_t id, const Origin &o) const -> cv::Vec2d
Get the UV value for a point by ID.
UVMap()=default
Default constructor.
void set(std::size_t id, const cv::Vec2d &uv, const Origin &o)
Set the UV value for a point by ID.
auto origin() const -> Origin
Get the current origin of the UVMap.
Origin origin_
Definition: UVMap.hpp:240
auto as_map() const -> std::map< std::size_t, cv::Vec2d >
auto empty() const -> bool
Return whether the UVMap is empty.
static void AlignToAxis(UVMap &uv, const ITKMesh::Pointer &mesh, AlignmentAxis axis)
Rotate a UVMap to align a specified volume axis to the -V direction of UV space.
static auto Plot(const UVMap &uv, const Color &color=color::GREEN) -> cv::Mat
Plot the UV points on an image.
static auto New(Args... args) -> Pointer
Definition: UVMap.hpp:74
auto ratio() const -> Ratio
Get the size information (aspect ratio, width, height)
static void Rotate(UVMap &uv, Rotation rotation, cv::Mat &texture)
Rotate a UVMap by a multiple of 90 degrees.
auto size() const -> std::size_t
Return the number of UV elements.
Volume Cartographer library
cv::Vec3b Color
Color type.
Definition: Color.hpp:18
static const cv::Vec2d NULL_MAPPING
Definition: UVMap.hpp:18