Volume Cartographer 2.27.0
Classes | Public Types | Private Attributes | List of all members
volcart::UVMap Class Reference

Stores per-vertex UV mappings. More...

#include <vc/core/types/UVMap.hpp>

Collaboration diagram for volcart::UVMap:
[legend]

Classes

struct  Ratio
 

Public Types

enum class  Origin { TopLeft = 0 , TopRight , BottomLeft , BottomRight }
 
using Pointer = std::shared_ptr< UVMap >
 

Public Member Functions

auto size () const -> std::size_t
 Return the number of UV elements.
 
auto empty () const -> bool
 Return whether the UVMap is empty.
 
void setOrigin (const Origin &o)
 Set the origin of the UVMap. More...
 
auto origin () const -> Origin
 Get the current origin of the UVMap.
 
void set (std::size_t id, const cv::Vec2d &uv, const Origin &o)
 Set the UV value for a point by ID. More...
 
void set (std::size_t id, const cv::Vec2d &uv)
 Set the UV value for a point by ID. More...
 
auto get (std::size_t id, const Origin &o) const -> cv::Vec2d
 Get the UV value for a point by ID. More...
 
auto get (std::size_t id) const -> cv::Vec2d
 Get the UV value for a point by ID. More...
 
auto contains (std::size_t id) const -> bool
 Check if the vertex index has a UV mapping.
 
auto as_map () const -> std::map< std::size_t, cv::Vec2d >
 
auto ratio () const -> Ratio
 Get the size information (aspect ratio, width, height)
 
void ratio (double a)
 Set the aspect ratio.
 
void ratio (double w, double h)
 Set the aspect ration by width and height parameters.
 

Private Attributes

std::map< std::size_t, cv::Vec2d > map_
 
Origin origin_ {Origin::TopLeft}
 
Ratio ratio_
 
enum class  Rotation { CW90 = 0 , CW180 , CCW90 }
 
enum class  FlipAxis { Vertical = 0 , Horizontal , Both }
 
enum class  AlignmentAxis {
  None = 0 , ZPos , ZNeg , YPos ,
  YNeg , XPos , XNeg
}
 
static auto Plot (const UVMap &uv, const Color &color=color::GREEN) -> cv::Mat
 Plot the UV points on an image. More...
 
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. More...
 
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. More...
 
static void Rotate (UVMap &uv, Rotation rotation)
 Rotate a UVMap by a multiple of 90 degrees.
 
static void Rotate (UVMap &uv, Rotation rotation, cv::Mat &texture)
 Rotate a UVMap by a multiple of 90 degrees. More...
 
static void Rotate (UVMap &uv, double theta, const cv::Vec2d &center={0.5, 0.5})
 Rotate a UVMap by a specified angle. More...
 
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. More...
 
static void Flip (UVMap &uv, FlipAxis axis)
 Flip a UVMap across one or both of its axes.
 
 UVMap ()=default
 Default constructor.
 
 UVMap (Origin o)
 Construct and set origin.
 
template<typename... Args>
static auto New (Args... args) -> Pointer
 

Detailed Description

Stores per-vertex UV mappings.

Author
Seth Parker
Date
10/20/15

A UV map stores the position of a vertex in 2D parameter space (often texture space). UV values are typically stored as floating point values in the range [0,1].

UV positions are assumed to be relative to an origin at one of the corners of parameter space: the top-left (0,0), top-right (1,0), bottom-left (0,1), or bottom-right (1,1). Internally, all mappings are stored relative to a storage origin. The set() functions transform UV values from the provided origin space to the storage origin space. Similarly, the get() functions transform UV values from the storage origin space to the provided origin space. This allows the class to provide on-the-fly conversion between different origin positions. By setting the origin prior to insertion and again prior to retrieval, mappings can be inserted relative to one origin but retrieved relative to another. When using the overloaded set(std::size_t, const cv::Vec2d&) and get(size_t) functions, the source and target origins are set using the constructor or setOrigin().

Since UV maps store relative position information, they are agnostic to size of the texture space to which they apply. The ratio functions provide a way to store the dimensions and aspect ratio of the texture space for later PerPixelMap and Texture generation.

Definition at line 51 of file UVMap.hpp.

Member Typedef Documentation

◆ Pointer

using volcart::UVMap::Pointer = std::shared_ptr<UVMap>

Pointer type

Definition at line 55 of file UVMap.hpp.

Member Enumeration Documentation

◆ AlignmentAxis

enum class volcart::UVMap::AlignmentAxis
strong

Align to axis enumeration

Definition at line 155 of file UVMap.hpp.

◆ FlipAxis

enum class volcart::UVMap::FlipAxis
strong

Flipping axis enumeration

Definition at line 152 of file UVMap.hpp.

◆ Origin

enum class volcart::UVMap::Origin
strong

Origin corner position enumeration

Definition at line 58 of file UVMap.hpp.

◆ Rotation

enum class volcart::UVMap::Rotation
strong

Rotation preset enumeration

Definition at line 149 of file UVMap.hpp.

Member Function Documentation

◆ AlignToAxis()

static void volcart::UVMap::AlignToAxis ( UVMap uv,
const ITKMesh::Pointer &  mesh,
AlignmentAxis  axis 
)
static

Rotate a UVMap to align a specified volume axis to the -V direction of UV space.

We want to rotate the virtually unwrapped image so that the bottom of the content page is at the bottom of the virtually unwrapped image (  v ~= 1.) and the top of the page is at the top of the image (  v ~= 0.). As a consequence, this function aligns the given 3D axis to the -V direction of UV space rather than the +V direction.

Usually, we want the alignment axis to be the volume's +Z axis. It is a convention in CT data for the +Z axis to travel the length of the sample, from the bottom to the top. Without a priori knowledge, we assume that the bottom of the sample corresponds to the bottom of the content page, thus the +Z axis should align to the -V direction of UV space.

Parameters
uvThe UVMap to be rotated.
meshOriginal 3D mesh for the given UVMap. Used as reference for the vertices' 3D positions.
axisVolume axis to align to the -V axis.

◆ as_map()

auto volcart::UVMap::as_map ( ) const -> std::map< std::size_t, cv::Vec2d >

Access to underlying data. For serialization only.

◆ get() [1/2]

auto volcart::UVMap::get ( std::size_t  id) const -> cv::Vec2d

Get the UV value for a point by ID.

Point is retrieved relative to the origin returned by origin().

◆ get() [2/2]

auto volcart::UVMap::get ( std::size_t  id,
const Origin o 
) const -> cv::Vec2d

Get the UV value for a point by ID.

Point is retrieved relative to the provided origin.

◆ New()

template<typename... Args>
static auto volcart::UVMap::New ( Args...  args) -> Pointer
inlinestatic

Static New function for all constructors of T

Definition at line 74 of file UVMap.hpp.

◆ Plot() [1/2]

static auto volcart::UVMap::Plot ( const UVMap uv,
const Color color = color::GREEN 
) -> cv::Mat
static

Plot the UV points on an image.

For debug purposes only.

◆ Plot() [2/2]

static auto volcart::UVMap::Plot ( const UVMap uv,
const ITKMesh::Pointer &  mesh2D,
int  width = -1,
int  height = -1,
const Color color = color::LIGHT_GRAY 
) -> cv::Mat
static

Plot the UV mesh on an image.

For debug purposes only.

◆ Rotate() [1/3]

static void volcart::UVMap::Rotate ( UVMap uv,
double  theta,
const cv::Vec2d &  center = {0.5, 0.5} 
)
static

Rotate a UVMap by a specified angle.

Theta is in radians. Rotation is performed in UV space and is counter-clockwise relative to the provided center position.

◆ Rotate() [2/3]

static void volcart::UVMap::Rotate ( UVMap uv,
double  theta,
cv::Mat &  texture,
const cv::Vec2d &  center = {0.5, 0.5} 
)
static

Rotate a UVMap by a specified angle.

Theta is in radians. Rotation is performed in UV space and is counter-clockwise relative to the provided center position.

This function is an overload which also rotates the texture image.

◆ Rotate() [3/3]

static void volcart::UVMap::Rotate ( UVMap uv,
Rotation  rotation,
cv::Mat &  texture 
)
static

Rotate a UVMap by a multiple of 90 degrees.

This function is an overload which also rotates the texture image.

◆ set() [1/2]

void volcart::UVMap::set ( std::size_t  id,
const cv::Vec2d &  uv 
)

Set the UV value for a point by ID.

Point is inserted relative to the origin returned by origin().

◆ set() [2/2]

void volcart::UVMap::set ( std::size_t  id,
const cv::Vec2d &  uv,
const Origin o 
)

Set the UV value for a point by ID.

Point is inserted relative to the provided origin.

◆ setOrigin()

void volcart::UVMap::setOrigin ( const Origin o)

Set the origin of the UVMap.

UV values inserted and retrieved after a call to setOrigin() will be relative to this value.

Member Data Documentation

◆ map_

std::map<std::size_t, cv::Vec2d> volcart::UVMap::map_
private

UV storage

Definition at line 238 of file UVMap.hpp.

◆ origin_

Origin volcart::UVMap::origin_ {Origin::TopLeft}
private

Origin for set and get functions

Definition at line 240 of file UVMap.hpp.

◆ ratio_

Ratio volcart::UVMap::ratio_
private

Aspect ratio

Definition at line 242 of file UVMap.hpp.


The documentation for this class was generated from the following file: