Volume Cartographer 2.27.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Classes | Public Types | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
volcart::PerPixelMap Class Reference

A raster of a UVMap that provides a per-pixel mapping between a Volume and a Texture generated from that volume. More...

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

Collaboration diagram for volcart::PerPixelMap:
[legend]

Classes

struct  Coord2D
 
struct  PixelMap
 

Public Types

using Pointer = std::shared_ptr< PerPixelMap >
 

Public Member Functions

auto operator() (std::size_t y, std::size_t x) const -> const cv::Vec6d &
 Get the mapping for a pixel by x, y coordinate.
 
auto operator() (std::size_t y, std::size_t x) -> cv::Vec6d &
 Get the mapping for a pixel by x, y coordinate. More...
 
auto getMapping (std::size_t y, std::size_t x) const -> const cv::Vec6d &
 Get the mapping for a pixel by x, y coordinate. More...
 
auto getMapping (std::size_t y, std::size_t x) -> cv::Vec6d &
 Get the mapping for a pixel by x, y coordinate. More...
 
auto hasMapping (std::size_t y, std::size_t x) const -> bool
 Return whether there is a mapping for the pixel at x, y. More...
 
auto getAsPixelMap (std::size_t y, std::size_t x) -> PixelMap
 Get the mapping for a pixel as a PixelMap.
 
auto getMappings () const -> std::vector< PixelMap >
 Get a list of valid pixel mappings. More...
 
auto getMappingCoords () const -> std::vector< Coord2D >
 Get a list of pixel coordinates with valid mappings. More...
 
auto numMappings () const -> std::size_t
 Get the number of valid mappings. More...
 
void setDimensions (std::size_t h, std::size_t w)
 Set the dimensions of the map. More...
 
void setWidth (std::size_t w)
 Set the width of the map. More...
 
void setHeight (std::size_t h)
 Set the height of the map. More...
 
auto width () const -> std::size_t
 Get the width of the map.
 
auto height () const -> std::size_t
 Get the height of the map.
 
auto mask () const -> cv::Mat
 Get the pixel mask.
 
void setMask (const cv::Mat &m)
 Set the pixel mask. More...
 
auto cellMap () const -> cv::Mat
 Get the cell map image. More...
 
void setCellMap (const cv::Mat &m)
 Set the cell map image. More...
 

Static Public Member Functions

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.
 
static void WritePPM (const filesystem::path &path, const PerPixelMap &map)
 Write a PerPixelMap to disk.
 
static auto ReadPPM (const filesystem::path &path) -> PerPixelMap
 Read a PerPixelMap from disk.
 

Private Member Functions

void initialize_map_ ()
 

Private Attributes

std::size_t height_ {0}
 
std::size_t width_ {0}
 
OrderedPointSet< cv::Vec6d > map_
 
cv::Mat mask_
 
cv::Mat cellMap_
 
 PerPixelMap ()=default
 Default constructor.
 
 PerPixelMap (std::size_t height, std::size_t width)
 Constructor with width and height parameters.
 
auto initialized () const -> bool
 Return whether the PerPixelMap has been initialized. More...
 
template<typename... Args>
static auto New (Args... args) -> Pointer
 

Detailed Description

A raster of a UVMap that provides a per-pixel mapping between a Volume and a Texture generated from that volume.

Author
Seth Parker
Date
3/17/16

After a segmentation mesh is flattened, the resulting UV space is sampled at a specific resolution in order to generate a texture space (e.g. image). A texturing algorithm is responsible for filtering information from the volume and placing it into this space, the intended result being an image of a manuscript's text. The transformation that maps 2D coordinates in texture space to 3D coordinates in volume space is defined by the per-vertex transformation generated by flattening, however, there are numerous ways that the points between vertices can be mapped back into the volume. Since the calculation of this mapping can be expensive, it is often desirable to perform this operation only once.

The PerPixelMap (PPM) provides a method for storing the result of this calculation. It has the same dimensions as texture space, and each pixel holds the mapped, 3D position for that pixel in volume space. It additionally holds 3 extra double elements, typically used to store the surface normal vector for the 3D position (calculated from the segmentation mesh).

The position and normal vector are stored in a cv::Vec6d: {x, y, z, nx, ny, nz}.

The texturing::PPMGenerator class generates a PerPixelMap by mapping pixels through the barycentric coordinates of the mesh's triangular faces.

Definition at line 49 of file PerPixelMap.hpp.

Member Typedef Documentation

◆ Pointer

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

Pointer type

Definition at line 84 of file PerPixelMap.hpp.

Member Function Documentation

◆ cellMap()

auto volcart::PerPixelMap::cellMap ( ) const -> cv::Mat

Get the cell map image.

The cell map contains the face assignment for each pixel in the PPM. This is an optional feature, and older PPMs may not make this information available.

◆ getMapping() [1/2]

auto volcart::PerPixelMap::getMapping ( std::size_t  y,
std::size_t  x 
) -> cv::Vec6d &

Get the mapping for a pixel by x, y coordinate.

◆ getMapping() [2/2]

auto volcart::PerPixelMap::getMapping ( std::size_t  y,
std::size_t  x 
) const -> const cv::Vec6d &

Get the mapping for a pixel by x, y coordinate.

◆ getMappingCoords()

auto volcart::PerPixelMap::getMappingCoords ( ) const -> std::vector< Coord2D >

Get a list of pixel coordinates with valid mappings.

Convenience function for accessing PPM data as pixel coordinates.

Unlike getMappings(), this function only returns the pixel coordinates which have mappings. Use this function with getMapping() or getAsPixelMap() in high-performance loops:

for(auto [y, x] : ppm.getMappingCoords()) {
const auto& m = ppm.getMapping(y, x);
cv::Vec3d pos{m[0], m[1], m[2]};
cv::Vec3d normal{m[3], m[4], m[5]};
}

◆ getMappings()

auto volcart::PerPixelMap::getMappings ( ) const -> std::vector< PixelMap >

Get a list of valid pixel mappings.

Convenience function for accessing PPM data as logical pixels with position and normal values. Valid mappings are determined by the PPM's mask.

Warning
This function returns a copy of the valid PPM mappings which can lead to high-memory usage for large PPMs. When memory and performance are important, prefer using getMappingCoords() with getMapping() or getAsPixelMap().

◆ hasMapping()

auto volcart::PerPixelMap::hasMapping ( std::size_t  y,
std::size_t  x 
) const -> bool

Return whether there is a mapping for the pixel at x, y.

Returns true is the pixel mask has not been set or is empty

◆ initialize_map_()

void volcart::PerPixelMap::initialize_map_ ( )
private

Initialize the map for value assignment

Does nothing if either the height or width are 0.

◆ initialized()

auto volcart::PerPixelMap::initialized ( ) const -> bool

Return whether the PerPixelMap has been initialized.

The map is initialized as soon as its width and height have been set.

◆ New()

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

Static New function for all constructors of T

Definition at line 95 of file PerPixelMap.hpp.

◆ numMappings()

auto volcart::PerPixelMap::numMappings ( ) const -> std::size_t

Get the number of valid mappings.

Valid mappings are determined by the number of non-zero pixels in the PPM's mask. If the mask is not set, all pixels are valid.

◆ operator()()

auto volcart::PerPixelMap::operator() ( std::size_t  y,
std::size_t  x 
) -> cv::Vec6d &

Get the mapping for a pixel by x, y coordinate.

◆ setCellMap()

void volcart::PerPixelMap::setCellMap ( const cv::Mat &  m)

Set the cell map image.

The cell map contains the face assignment for each pixel in the PPM. This is an optional feature, and older PPMs may not make this information available.

◆ setDimensions()

void volcart::PerPixelMap::setDimensions ( std::size_t  h,
std::size_t  w 
)

Set the dimensions of the map.

Warning
Changing the size of the PerPixelMap will clear it of data. Setting either dimension to 0 will result in undefined behavior.

◆ setHeight()

void volcart::PerPixelMap::setHeight ( std::size_t  h)

Set the height of the map.

Warning
Changing the size of the PerPixelMap will clear it of data. Setting either dimension to 0 will result in undefined behavior.

◆ setMask()

void volcart::PerPixelMap::setMask ( const cv::Mat &  m)

Set the pixel mask.

If the pixel mask is not set or is empty, every pixel is assumed to have a mapping.

Not every pixel in the PerPixelMap will have a mapped value. The pixel mask is an 8bpc, single channel image that indicates which pixels do and do not have mappings. 0 = No mapping, 255 = Has mapping.

◆ setWidth()

void volcart::PerPixelMap::setWidth ( std::size_t  w)

Set the width of the map.

Warning
Changing the size of the PerPixelMap will clear it of data. Setting either dimension to 0 will result in undefined behavior.

Member Data Documentation

◆ cellMap_

cv::Mat volcart::PerPixelMap::cellMap_
private

Cell map

Definition at line 275 of file PerPixelMap.hpp.

◆ height_

std::size_t volcart::PerPixelMap::height_ {0}
private

Height of the map

Definition at line 260 of file PerPixelMap.hpp.

◆ map_

OrderedPointSet<cv::Vec6d> volcart::PerPixelMap::map_
private

Map data storage

Definition at line 264 of file PerPixelMap.hpp.

◆ mask_

cv::Mat volcart::PerPixelMap::mask_
private

Pixel mask

The pixel mask is an 8bpc, single channel image that indicates which pixels do and do not have mappings. 0 = No mapping, 255 = Has mapping.

Definition at line 272 of file PerPixelMap.hpp.

◆ width_

std::size_t volcart::PerPixelMap::width_ {0}
private

Width of the map

Definition at line 262 of file PerPixelMap.hpp.


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