MeshLib
 
Loading...
Searching...
No Matches
MR::DistanceMap Class Reference

#include <MRDistanceMap.h>

+ Inheritance diagram for MR::DistanceMap:

Public Member Functions

 DistanceMap ()=default
 
MRMESH_API DistanceMap (size_t resX, size_t resY)
 
MRMESH_API DistanceMap (const MR::Matrix< float > &m)
 make from 2d array
 
MRMESH_API bool isValid (size_t x, size_t y) const
 checks if X,Y element is valid (i.e. not std::numeric_limits<float>::lowest(); passing invalid coords to this is UB)
 
MRMESH_API bool isValid (size_t i) const
 checks if index element is valid (i.e. not std::numeric_limits<float>::lowest(); passing an invalid coord to this is UB)
 
bool isInBounds (size_t x, size_t y) const
 Returns true if (X,Y) coordinates are in bounds.
 
bool isInBounds (size_t i) const
 Returns true if a flattened coordinate is in bounds.
 
MRMESH_API std::optional< float > get (size_t x, size_t y) const
 returns value in (X,Y) element, returns nullopt if not valid (see isValid()), UB if out of bounds.
 
MRMESH_API std::optional< float > get (size_t i) const
 returns value of index element, returns nullopt if not valid (see isValid()), UB if out of bounds.
 
float & getValue (size_t x, size_t y)
 
float getValue (size_t x, size_t y) const
 
float & getValue (size_t i)
 
float getValue (size_t i) const
 
float * data ()
 
const float * data () const
 
MRMESH_API std::optional< float > getInterpolated (float x, float y) const
 finds interpolated value.
 
MRMESH_API std::optional< Vector3funproject (size_t x, size_t y, const AffineXf3f &toWorld) const
 
MRMESH_API std::optional< Vector3funprojectInterpolated (float x, float y, const AffineXf3f &toWorld) const
 finds 3d coordinates of the Point on the model surface for the (x,y) interpolated value
 
MRMESH_API void negate ()
 replaces every valid element in the map with its negative value
 
MRMESH_API DistanceMap max (const DistanceMap &rhs) const
 
MRMESH_API const DistanceMapmergeMax (const DistanceMap &rhs)
 replaces values with cell-wise maximum values. Invalid values remain only if both corresponding cells are invalid
 
MRMESH_API DistanceMap min (const DistanceMap &rhs) const
 returns new Distance Map with cell-wise minimum values. Invalid values remain only if both corresponding cells are invalid
 
MRMESH_API const DistanceMapmergeMin (const DistanceMap &rhs)
 replaces values with cell-wise minimum values. Invalid values remain only if both corresponding cells are invalid
 
MRMESH_API DistanceMap operator- (const DistanceMap &rhs) const
 returns new Distance Map with cell-wise subtracted values. Invalid values remain only if both corresponding cells are invalid
 
MRMESH_API const DistanceMapoperator-= (const DistanceMap &rhs)
 replaces values with cell-wise subtracted values. Invalid values remain only if both corresponding cells are invalid
 
MRMESH_API void set (size_t x, size_t y, float val)
 sets value in (X,Y) element (the coords must be valid, UB otherwise)
 
MRMESH_API void set (size_t i, float val)
 sets value in index element (the coord must be valid, UB otherwise)
 
MRMESH_API void set (std::vector< float > data)
 sets all values at one time
 
MRMESH_API void unset (size_t x, size_t y)
 invalidates value in (X,Y) element (the coords must be valid, UB otherwise)
 
MRMESH_API void unset (size_t i)
 invalidates value in index element (the coord must be valid, UB otherwise)
 
MRMESH_API void invalidateAll ()
 invalidates all elements
 
MRMESH_API void clear ()
 clears data, sets resolutions to zero
 
MRMESH_API DistanceMap getDerivativeMap () const
 returns new derivatives map without directions
 
MRMESH_API std::pair< DistanceMap, DistanceMapgetXYDerivativeMaps () const
 returns new derivative maps with X and Y axes direction
 
MRMESH_API std::vector< std::pair< size_t, size_t > > getLocalMaximums () const
 computes single derivative map from XY spaces combined. Returns local maximums then
 
size_t resX () const
 returns X resolution
 
size_t resY () const
 returns Y resolution
 
size_t numPoints () const
 returns the number of pixels
 
MRMESH_API std::pair< float, float > getMinMaxValues () const
 
MRMESH_API std::pair< size_t, size_t > getMinIndex () const
 
MRMESH_API std::pair< size_t, size_t > getMaxIndex () const
 
size_t heapBytes () const
 returns the amount of memory this object occupies on heap
 
- Public Member Functions inherited from MR::RectIndexer
constexpr RectIndexer () noexcept=default
 
 RectIndexer (const Vector2i &dims)
 
void resize (const Vector2i &dims)
 
const Vector2i & dims () const
 
size_t size () const
 
Vector2i toPos (PixelId id) const
 
Vector2i toPos (size_t id) const
 
PixelId toPixelId (const Vector2i &pos) const
 
size_t toIndex (const Vector2i &pos) const
 
bool areNeigbors (PixelId v0, PixelId v1) const
 returns true if v1 is within at most 4 neighbors of v0
 
bool areNeigbors (const Vector2i &pos0, const Vector2i &pos1) const
 
PixelId getNeighbor (PixelId v, OutEdge2 toNei) const
 returns id of v's neighbor specified by the edge
 
MRMESH_API PixelId getNeighbor (PixelId v, const Vector2i &pos, OutEdge2 toNei) const
 

Additional Inherited Members

- Protected Attributes inherited from MR::RectIndexer
Vector2i dims_
 
size_t size_ = 0
 = dims_.x * dims_.y
 

Detailed Description

this class allows to store distances from the plane in particular pixels validVerts keeps only pixels with mesh-intersecting rays from them

Constructor & Destructor Documentation

◆ DistanceMap() [1/3]

MR::DistanceMap::DistanceMap ( )
default

◆ DistanceMap() [2/3]

MRMESH_API MR::DistanceMap::DistanceMap ( size_t resX,
size_t resY )
nodiscard

Preferable constructor with resolution arguments Access by the index (i) is equal to (y*resX + x)

◆ DistanceMap() [3/3]

MRMESH_API MR::DistanceMap::DistanceMap ( const MR::Matrix< float > & m)
nodiscard

make from 2d array

Member Function Documentation

◆ clear()

MRMESH_API void MR::DistanceMap::clear ( )

clears data, sets resolutions to zero

◆ data() [1/2]

float * MR::DistanceMap::data ( )
inline

◆ data() [2/2]

const float * MR::DistanceMap::data ( ) const
inline

◆ get() [1/2]

MRMESH_API std::optional< float > MR::DistanceMap::get ( size_t i) const
nodiscard

returns value of index element, returns nullopt if not valid (see isValid()), UB if out of bounds.

◆ get() [2/2]

MRMESH_API std::optional< float > MR::DistanceMap::get ( size_t x,
size_t y ) const
nodiscard

returns value in (X,Y) element, returns nullopt if not valid (see isValid()), UB if out of bounds.

◆ getDerivativeMap()

MRMESH_API DistanceMap MR::DistanceMap::getDerivativeMap ( ) const
nodiscard

returns new derivatives map without directions

◆ getInterpolated()

MRMESH_API std::optional< float > MR::DistanceMap::getInterpolated ( float x,
float y ) const
nodiscard

finds interpolated value.

https://en.wikipedia.org/wiki/Bilinear_interpolation getInterpolated( 0.5f, 0.5f ) == get( 0, 0 ) see https://docs.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-coordinates for details all 4 elements around this point should be valid, returns nullopt if at least one is not valid

Parameters
x,yshould be in resolution range [0;resX][0;resY]. If x,y are out of bounds, returns nullopt.

◆ getLocalMaximums()

MRMESH_API std::vector< std::pair< size_t, size_t > > MR::DistanceMap::getLocalMaximums ( ) const
nodiscard

computes single derivative map from XY spaces combined. Returns local maximums then

◆ getMaxIndex()

MRMESH_API std::pair< size_t, size_t > MR::DistanceMap::getMaxIndex ( ) const
nodiscard

finds maximum value X,Y returns [-1.-1] if all values are invalid

◆ getMinIndex()

MRMESH_API std::pair< size_t, size_t > MR::DistanceMap::getMinIndex ( ) const
nodiscard

finds minimum value X,Y returns [-1.-1] if all values are invalid

◆ getMinMaxValues()

MRMESH_API std::pair< float, float > MR::DistanceMap::getMinMaxValues ( ) const
nodiscard

finds minimum and maximum values returns min_float and max_float if all values are invalid

◆ getValue() [1/4]

float & MR::DistanceMap::getValue ( size_t i)
inlinenodiscard

◆ getValue() [2/4]

float MR::DistanceMap::getValue ( size_t i) const
inlinenodiscard

◆ getValue() [3/4]

float & MR::DistanceMap::getValue ( size_t x,
size_t y )
inlinenodiscard

returns value in (X,Y) element without check on valid use this only if you sure that distance map has no invalid values or for serialization

◆ getValue() [4/4]

float MR::DistanceMap::getValue ( size_t x,
size_t y ) const
inlinenodiscard

◆ getXYDerivativeMaps()

MRMESH_API std::pair< DistanceMap, DistanceMap > MR::DistanceMap::getXYDerivativeMaps ( ) const
nodiscard

returns new derivative maps with X and Y axes direction

◆ heapBytes()

size_t MR::DistanceMap::heapBytes ( ) const
inlinenodiscard

returns the amount of memory this object occupies on heap

◆ invalidateAll()

MRMESH_API void MR::DistanceMap::invalidateAll ( )

invalidates all elements

◆ isInBounds() [1/2]

bool MR::DistanceMap::isInBounds ( size_t i) const
inlinenodiscard

Returns true if a flattened coordinate is in bounds.

◆ isInBounds() [2/2]

bool MR::DistanceMap::isInBounds ( size_t x,
size_t y ) const
inlinenodiscard

Returns true if (X,Y) coordinates are in bounds.

◆ isValid() [1/2]

MRMESH_API bool MR::DistanceMap::isValid ( size_t i) const
nodiscard

checks if index element is valid (i.e. not std::numeric_limits<float>::lowest(); passing an invalid coord to this is UB)

◆ isValid() [2/2]

MRMESH_API bool MR::DistanceMap::isValid ( size_t x,
size_t y ) const
nodiscard

checks if X,Y element is valid (i.e. not std::numeric_limits<float>::lowest(); passing invalid coords to this is UB)

◆ max()

MRMESH_API DistanceMap MR::DistanceMap::max ( const DistanceMap & rhs) const
nodiscard

boolean operators returns new Distance Map with cell-wise maximum values. Invalid values remain only if both corresponding cells are invalid

◆ mergeMax()

MRMESH_API const DistanceMap & MR::DistanceMap::mergeMax ( const DistanceMap & rhs)

replaces values with cell-wise maximum values. Invalid values remain only if both corresponding cells are invalid

◆ mergeMin()

MRMESH_API const DistanceMap & MR::DistanceMap::mergeMin ( const DistanceMap & rhs)

replaces values with cell-wise minimum values. Invalid values remain only if both corresponding cells are invalid

◆ min()

MRMESH_API DistanceMap MR::DistanceMap::min ( const DistanceMap & rhs) const
nodiscard

returns new Distance Map with cell-wise minimum values. Invalid values remain only if both corresponding cells are invalid

◆ negate()

MRMESH_API void MR::DistanceMap::negate ( )

replaces every valid element in the map with its negative value

◆ numPoints()

size_t MR::DistanceMap::numPoints ( ) const
inlinenodiscard

returns the number of pixels

◆ operator-()

MRMESH_API DistanceMap MR::DistanceMap::operator- ( const DistanceMap & rhs) const
nodiscard

returns new Distance Map with cell-wise subtracted values. Invalid values remain only if both corresponding cells are invalid

◆ operator-=()

MRMESH_API const DistanceMap & MR::DistanceMap::operator-= ( const DistanceMap & rhs)

replaces values with cell-wise subtracted values. Invalid values remain only if both corresponding cells are invalid

◆ resX()

size_t MR::DistanceMap::resX ( ) const
inlinenodiscard

returns X resolution

◆ resY()

size_t MR::DistanceMap::resY ( ) const
inlinenodiscard

returns Y resolution

◆ set() [1/3]

MRMESH_API void MR::DistanceMap::set ( size_t i,
float val )

sets value in index element (the coord must be valid, UB otherwise)

◆ set() [2/3]

MRMESH_API void MR::DistanceMap::set ( size_t x,
size_t y,
float val )

sets value in (X,Y) element (the coords must be valid, UB otherwise)

◆ set() [3/3]

MRMESH_API void MR::DistanceMap::set ( std::vector< float > data)

sets all values at one time

◆ unproject()

MRMESH_API std::optional< Vector3f > MR::DistanceMap::unproject ( size_t x,
size_t y,
const AffineXf3f & toWorld ) const
nodiscard

finds 3d coordinates of the Point on the model surface for the (x,y) pixel Use the same params with distance map creation (x,y) must be in bounds, the behavior is undefined otherwise.

◆ unprojectInterpolated()

MRMESH_API std::optional< Vector3f > MR::DistanceMap::unprojectInterpolated ( float x,
float y,
const AffineXf3f & toWorld ) const
nodiscard

finds 3d coordinates of the Point on the model surface for the (x,y) interpolated value

Parameters
x,yshould be in resolution range [0;resX][0;resY].

getInterpolated( 0.5f, 0.5f ) == get( 0, 0 ) see https://docs.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-coordinates for details all 4 elements around this point should be valid, returns nullopt if at least one is not valid If x,y are out of bounds, returns nullopt.

◆ unset() [1/2]

MRMESH_API void MR::DistanceMap::unset ( size_t i)

invalidates value in index element (the coord must be valid, UB otherwise)

◆ unset() [2/2]

MRMESH_API void MR::DistanceMap::unset ( size_t x,
size_t y )

invalidates value in (X,Y) element (the coords must be valid, UB otherwise)


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