Ocean
Ocean::CV::PixelPositionT< T > Class Template Reference

This class implements a 2D pixel position with pixel precision. More...

Inheritance diagram for Ocean::CV::PixelPositionT< T >:

Public Types

enum  RoughPixelDirection { RPD_INVALID , RPD_VERTICAL , RPD_HORIZONTAL , RPD_DIAGONAL }
 Definition of individual rough directions. More...
 

Public Member Functions

 PixelPositionT ()
 Creates an invalid pixel position object with invalid coordinates. More...
 
 PixelPositionT (const PixelPositionT< T > &position)
 Copy constructor. More...
 
 PixelPositionT (const T &x, const T &y)
 Creates a new coordinate object by two given coordinate values. More...
 
x () const
 Returns the horizontal coordinate position of this object. More...
 
y () const
 Returns the vertical coordinate position of this object. More...
 
T & x ()
 Returns the horizontal coordinate position of this object. More...
 
T & y ()
 Returns the vertical coordinate position of this object. More...
 
void setPosition (const T &x, const T &y)
 Sets the two coordinate values of this object. More...
 
unsigned int sqrDistance (const PixelPositionT< T > &position) const
 Returns the square difference between two pixel positions. More...
 
CV::PixelPositionT< T > neighbor (const CV::PixelDirection pixelDirection) const
 Returns the position of the pixel neighbor to this position. More...
 
PixelPositionT< T > north () const
 Returns the pixel position north to this position. More...
 
PixelPositionT< T > northWest () const
 Returns the pixel position north west to this position. More...
 
PixelPositionT< T > west () const
 Returns the pixel position west to this position. More...
 
PixelPositionT< T > southWest () const
 Returns the pixel position south west to this position. More...
 
PixelPositionT< T > south () const
 Returns the pixel position south to this position. More...
 
PixelPositionT< T > southEast () const
 Returns the pixel position south east to this position. More...
 
PixelPositionT< T > east () const
 Returns the pixel position east to this position. More...
 
PixelPositionT< T > northEast () const
 Returns the pixel position north east to this position. More...
 
PixelPositionT< T > half () const
 Returns this position divided by two. More...
 
PixelPositionT< T > twice () const
 Returns this position multiplied by two. More...
 
Vector2 vector () const
 Returns a sub-pixel accuracy vector of this pixel position. More...
 
bool isValid () const
 Returns whether this pixel position object holds two valid parameters. More...
 
bool inArea9 (const PixelPositionT< T > &position) const
 Returns whether this pixel position is equal to a second pixel position or is the direct neighbor in an 8-neighborhood. More...
 
bool isNeighbor4 (const PixelPositionT< T > &position) const
 Returns whether this pixel position is the direct neighbor to a second pixel position in an 4-neighborhood. More...
 
bool isNeighbor8 (const PixelPositionT< T > &position) const
 Returns whether this pixel position is the direct neighbor to a second pixel position in an 8-neighborhood. More...
 
index (const unsigned int width) const
 Returns the index of this position inside a frame with given width. More...
 
PixelPositionT< T > & operator= (const PixelPositionT< T > &position)
 Copy assignment operator. More...
 
PixelPositionT< T > operator+ (const PixelPositionT< T > &position) const
 Adds two pixel positions and returns the result as a new pixel position object. More...
 
PixelPositionT< T > & operator+= (const PixelPositionT< T > &position)
 Add a second pixel position to this position object. More...
 
PixelPositionT< T > operator- (const PixelPositionT< T > &position) const
 Subtracts two pixel positions and returns the result as a new pixel position object. More...
 
PixelPositionT< T > & operator-= (const PixelPositionT< T > &position)
 Subtracts a second pixel position from this position object. More...
 
PixelPositionT< T > operator* (const T factor) const
 Multiplies this pixel position by a scalar and returns the new resulting position. More...
 
PixelPositionT< T > & operator*= (const T factor)
 Multiplies this pixel position by a scalar. More...
 
PixelPositionT< T > operator/ (const T factor) const
 Divides this pixel position by a scalar and returns the new resulting position. More...
 
PixelPositionT< T > & operator/= (const T factor)
 Divides this pixel position by a scalar. More...
 
bool operator< (const PixelPositionT< T > &position) const
 Compares two pixel position objects. More...
 
bool operator== (const PixelPositionT< T > &position) const
 Returns whether two pixel position objects are equal. More...
 
bool operator!= (const PixelPositionT< T > &position) const
 Returns whether two pixel position objects are not equal. More...
 
 operator bool () const
 Returns whether this pixel position object holds two valid parameters. More...
 
size_t operator() (const PixelPositionT< T > &pixelPosition) const
 Hash function. More...
 
 PixelPositionT ()
 
bool isValid () const
 
bool isValid () const
 
bool isValid () const
 
bool isValid () const
 
PixelPositionT< unsigned int > vector2pixelPosition (const Vector2 &value)
 
PixelPositionT< int > vector2pixelPosition (const Vector2 &value)
 

Static Public Member Functions

static PixelDirection direction (const PixelPositionT< T > &pixel0, const PixelPositionT< T > &pixel1)
 Returns the pixel direction of two successive pixels in a dense contour. More...
 
static RoughPixelDirection roughDirection (const PixelPositionT< T > &pixel0, const PixelPositionT< T > &pixel1)
 Returns the rough pixel direction of two successive pixels in a dense contour. More...
 
static Vector2 pixelPosition2vector (const PixelPositionT< T > &pixelPosition)
 Converts a pixel position into a 2D vector. More...
 
static Vectors2 pixelPositions2vectors (const std::vector< PixelPositionT< T >> &pixelPositions)
 Converts several pixel positions to 2D vectors. More...
 
static PixelPositionT< T > vector2pixelPosition (const Vector2 &value)
 Converts a 2D vector into a pixel position. More...
 
static std::vector< PixelPositionT< T > > vectors2pixelPositions (const Vectors2 &values)
 Converts several 2D vectors into pixel positions. More...
 
static std::vector< PixelPositionT< T > > vectors2pixelPositions (const Vectors2 &values, const unsigned int width, const unsigned int height)
 Converts several 2D vectors into pixel positions. More...
 
template<typename TTarget >
static std::vector< PixelPositionT< TTarget > > pixelPositions2pixelPositions (const std::vector< PixelPositionT< T >> &pixelPositions)
 Converts pixels positions with a data type T to pixel positions with another data type. More...
 

Protected Attributes

x_
 Horizontal coordinate value of this object, in pixel. More...
 
y_
 Vertical coordinate value of this object, in pixel. More...
 

Detailed Description

template<typename T>
class Ocean::CV::PixelPositionT< T >

This class implements a 2D pixel position with pixel precision.

Template Parameters
TThe data type that is used to store the elements of a pixel coordinate
See also
PixelPosition, PixelPositionI

Member Enumeration Documentation

◆ RoughPixelDirection

Definition of individual rough directions.

Enumerator
RPD_INVALID 

Invalid direction.

RPD_VERTICAL 

Vertical direction.

RPD_HORIZONTAL 

Horizontal direction.

RPD_DIAGONAL 

Vertical direction.

Constructor & Destructor Documentation

◆ PixelPositionT() [1/4]

template<typename T >
Ocean::CV::PixelPositionT< T >::PixelPositionT
inline

Creates an invalid pixel position object with invalid coordinates.

◆ PixelPositionT() [2/4]

template<typename T >
Ocean::CV::PixelPositionT< T >::PixelPositionT ( const PixelPositionT< T > &  position)
inline

Copy constructor.

Parameters
positionThe position to copy

◆ PixelPositionT() [3/4]

template<typename T >
Ocean::CV::PixelPositionT< T >::PixelPositionT ( const T &  x,
const T &  y 
)
inline

Creates a new coordinate object by two given coordinate values.

Parameters
xHorizontal position in pixel
yVertical position in pixel

◆ PixelPositionT() [4/4]

Member Function Documentation

◆ direction()

template<typename T >
PixelDirection Ocean::CV::PixelPositionT< T >::direction ( const PixelPositionT< T > &  pixel0,
const PixelPositionT< T > &  pixel1 
)
inlinestatic

Returns the pixel direction of two successive pixels in a dense contour.

Parameters
pixel0First pixel
pixel1Following pixel
Returns
Resulting pixel direction

◆ east()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::east
inline

Returns the pixel position east to this position.

Returns
East pixel position

◆ half()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::half
inline

Returns this position divided by two.

Returns
Half position

◆ inArea9()

template<typename T >
bool Ocean::CV::PixelPositionT< T >::inArea9 ( const PixelPositionT< T > &  position) const
inline

Returns whether this pixel position is equal to a second pixel position or is the direct neighbor in an 8-neighborhood.

Parameters
positionSecond pixel position to check
Returns
True, if so

◆ index()

template<typename T >
T Ocean::CV::PixelPositionT< T >::index ( const unsigned int  width) const
inline

Returns the index of this position inside a frame with given width.

The index is determined according to a frame stored in row aligned order.
The result is determined by y() * width + x().

Parameters
widthThe width to be used for index determination
Returns
Resulting index

◆ isNeighbor4()

template<typename T >
bool Ocean::CV::PixelPositionT< T >::isNeighbor4 ( const PixelPositionT< T > &  position) const
inline

Returns whether this pixel position is the direct neighbor to a second pixel position in an 4-neighborhood.

Parameters
positionSecond pixel position to check
Returns
True, if so

◆ isNeighbor8()

template<typename T >
bool Ocean::CV::PixelPositionT< T >::isNeighbor8 ( const PixelPositionT< T > &  position) const
inline

Returns whether this pixel position is the direct neighbor to a second pixel position in an 8-neighborhood.

Parameters
positionSecond pixel position to check
Returns
True, if so

◆ isValid() [1/5]

template<typename T >
bool Ocean::CV::PixelPositionT< T >::isValid ( ) const
inline

Returns whether this pixel position object holds two valid parameters.

Returns
True, if so

◆ isValid() [2/5]

bool Ocean::CV::PixelPositionT< uint32_t >::isValid ( ) const
inline

◆ isValid() [3/5]

bool Ocean::CV::PixelPositionT< uint64_t >::isValid ( ) const
inline

◆ isValid() [4/5]

bool Ocean::CV::PixelPositionT< int32_t >::isValid ( ) const
inline

◆ isValid() [5/5]

bool Ocean::CV::PixelPositionT< int64_t >::isValid ( ) const
inline

◆ neighbor()

template<typename T >
CV::PixelPositionT< T > Ocean::CV::PixelPositionT< T >::neighbor ( const CV::PixelDirection  pixelDirection) const

Returns the position of the pixel neighbor to this position.

Parameters
pixelDirectionThe direction in which the neighbor will be located, must be valid
Returns
The position of the neighbor pixel

◆ north()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::north
inline

Returns the pixel position north to this position.

Returns
North pixel position

◆ northEast()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::northEast
inline

Returns the pixel position north east to this position.

Returns
North east pixel position

◆ northWest()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::northWest
inline

Returns the pixel position north west to this position.

Returns
North west pixel position

◆ operator bool()

template<typename T >
Ocean::CV::PixelPositionT< T >::operator bool
inlineexplicit

Returns whether this pixel position object holds two valid parameters.

Returns
True, if so

◆ operator!=()

template<typename T >
bool Ocean::CV::PixelPositionT< T >::operator!= ( const PixelPositionT< T > &  position) const
inline

Returns whether two pixel position objects are not equal.

Parameters
positionSecond pixel position object to be compared
Returns
True, if so

◆ operator()()

template<typename T >
size_t Ocean::CV::PixelPositionT< T >::operator() ( const PixelPositionT< T > &  pixelPosition) const
inline

Hash function.

Parameters
pixelPositionThe pixel position for which the hash value will be determined
Returns
The resulting hash value

◆ operator*()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::operator* ( const T  factor) const
inline

Multiplies this pixel position by a scalar and returns the new resulting position.

Parameters
factorThe multiplication factor, with range (-infinity, infinity)
Returns
The resulting new position

◆ operator*=()

template<typename T >
PixelPositionT< T > & Ocean::CV::PixelPositionT< T >::operator*= ( const T  factor)
inline

Multiplies this pixel position by a scalar.

Parameters
factorThe multiplication factor, with range (-infinity, infinity)
Returns
The reference to this modified position

◆ operator+()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::operator+ ( const PixelPositionT< T > &  position) const
inline

Adds two pixel positions and returns the result as a new pixel position object.

Parameters
positionSecond pixel position to add
Returns
Resulting pixel position sum

◆ operator+=()

template<typename T >
PixelPositionT< T > & Ocean::CV::PixelPositionT< T >::operator+= ( const PixelPositionT< T > &  position)
inline

Add a second pixel position to this position object.

Parameters
positionSecond pixel position to add
Returns
Reference to this changed position object

◆ operator-()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::operator- ( const PixelPositionT< T > &  position) const
inline

Subtracts two pixel positions and returns the result as a new pixel position object.

Parameters
positionSecond pixel position to subtract
Returns
Resulting pixel position

◆ operator-=()

template<typename T >
PixelPositionT< T > & Ocean::CV::PixelPositionT< T >::operator-= ( const PixelPositionT< T > &  position)
inline

Subtracts a second pixel position from this position object.

Parameters
positionSecond pixel position to subtract
Returns
Reference to this changed position object

◆ operator/()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::operator/ ( const T  factor) const
inline

Divides this pixel position by a scalar and returns the new resulting position.

Parameters
factorThe division factor, with range (-infinity, infinity) \ {0}
Returns
The resulting new position

◆ operator/=()

template<typename T >
PixelPositionT< T > & Ocean::CV::PixelPositionT< T >::operator/= ( const T  factor)
inline

Divides this pixel position by a scalar.

Parameters
factorThe division factor, with range (-infinity, infinity) \ {0}
Returns
The reference to this modified position

◆ operator<()

template<typename T >
bool Ocean::CV::PixelPositionT< T >::operator< ( const PixelPositionT< T > &  position) const
inline

Compares two pixel position objects.

Parameters
positionSecond pixel position object to be compared
Returns
True, if this one is lesser than the right one

◆ operator=()

template<typename T >
PixelPositionT< T > & Ocean::CV::PixelPositionT< T >::operator= ( const PixelPositionT< T > &  position)
inline

Copy assignment operator.

Parameters
positionThe position to copy

◆ operator==()

template<typename T >
bool Ocean::CV::PixelPositionT< T >::operator== ( const PixelPositionT< T > &  position) const
inline

Returns whether two pixel position objects are equal.

Parameters
positionSecond pixel position object to be compared
Returns
True, if so

◆ pixelPosition2vector()

template<typename T >
Vector2 Ocean::CV::PixelPositionT< T >::pixelPosition2vector ( const PixelPositionT< T > &  pixelPosition)
inlinestatic

Converts a pixel position into a 2D vector.

Parameters
pixelPositionPixel position to be converted
Returns
Resulting 2D vector

◆ pixelPositions2pixelPositions()

template<typename T >
template<typename TTarget >
std::vector< PixelPositionT< TTarget > > Ocean::CV::PixelPositionT< T >::pixelPositions2pixelPositions ( const std::vector< PixelPositionT< T >> &  pixelPositions)
inlinestatic

Converts pixels positions with a data type T to pixel positions with another data type.

Beware: This function does not handle out-of-range issues. Thus, ensure that the target data types can covers the locations of the source positions.

Parameters
pixelPositionsThe pixel positions to convert
Returns
The resulting converted pixel positions
Template Parameters
TTargetData type of the target pixel positions

◆ pixelPositions2vectors()

template<typename T >
Vectors2 Ocean::CV::PixelPositionT< T >::pixelPositions2vectors ( const std::vector< PixelPositionT< T >> &  pixelPositions)
inlinestatic

Converts several pixel positions to 2D vectors.

Parameters
pixelPositionsPixel positions to be converted
Returns
Resulting 2D vectors

◆ roughDirection()

template<typename T >
PixelPositionT< T >::RoughPixelDirection Ocean::CV::PixelPositionT< T >::roughDirection ( const PixelPositionT< T > &  pixel0,
const PixelPositionT< T > &  pixel1 
)
inlinestatic

Returns the rough pixel direction of two successive pixels in a dense contour.

Parameters
pixel0First pixel
pixel1Following pixel
Returns
Resulting rough pixel direction

◆ setPosition()

template<typename T >
void Ocean::CV::PixelPositionT< T >::setPosition ( const T &  x,
const T &  y 
)
inline

Sets the two coordinate values of this object.

Parameters
xHorizontal coordinate value to set, in pixel
yVertical coordinate value to be set, in pixel

◆ south()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::south
inline

Returns the pixel position south to this position.

Returns
South pixel position

◆ southEast()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::southEast
inline

Returns the pixel position south east to this position.

Returns
South east pixel position

◆ southWest()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::southWest
inline

Returns the pixel position south west to this position.

Returns
South west pixel position

◆ sqrDistance()

template<typename T >
unsigned int Ocean::CV::PixelPositionT< T >::sqrDistance ( const PixelPositionT< T > &  position) const
inline

Returns the square difference between two pixel positions.

Parameters
positionSecond position to determine the difference for
Returns
Square difference in pixel

◆ twice()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::twice
inline

Returns this position multiplied by two.

Returns
Double position

◆ vector()

template<typename T >
Vector2 Ocean::CV::PixelPositionT< T >::vector
inline

Returns a sub-pixel accuracy vector of this pixel position.

Returns
Vector object

◆ vector2pixelPosition() [1/3]

template<typename T >
static PixelPositionT<T> Ocean::CV::PixelPositionT< T >::vector2pixelPosition ( const Vector2 value)
inlinestatic

Converts a 2D vector into a pixel position.

The pixel positions are rounded.

Parameters
valueThe value to be converted, with range [0, infinity)x[0, infinity)
Returns
Resulting pixel position

◆ vector2pixelPosition() [2/3]

PixelPositionT< unsigned int > Ocean::CV::PixelPositionT< unsigned int >::vector2pixelPosition ( const Vector2 value)
inline

◆ vector2pixelPosition() [3/3]

PixelPositionT< int > Ocean::CV::PixelPositionT< int >::vector2pixelPosition ( const Vector2 value)
inline

◆ vectors2pixelPositions() [1/2]

template<typename T >
std::vector< PixelPositionT< T > > Ocean::CV::PixelPositionT< T >::vectors2pixelPositions ( const Vectors2 values)
inlinestatic

Converts several 2D vectors into pixel positions.

The pixel positions are rounded.

Parameters
valuesThe values to be converted, with range [0, infinity)x[0, infinity)
Returns
Resulting pixel positions

◆ vectors2pixelPositions() [2/2]

template<typename T >
std::vector< PixelPositionT< T > > Ocean::CV::PixelPositionT< T >::vectors2pixelPositions ( const Vectors2 values,
const unsigned int  width,
const unsigned int  height 
)
inlinestatic

Converts several 2D vectors into pixel positions.

The pixel positions are rounded and clipped to the given frame dimension.

Parameters
valuesThe values to be converted, with range [0, infinity)x[0, infinity)
widthThe width of the clipping area, in pixel
heightThe height of the clipping area, in pixel
Returns
Resulting pixel positions

◆ west()

template<typename T >
PixelPositionT< T > Ocean::CV::PixelPositionT< T >::west
inline

Returns the pixel position west to this position.

Returns
West pixel position

◆ x() [1/2]

template<typename T >
T & Ocean::CV::PixelPositionT< T >::x
inline

Returns the horizontal coordinate position of this object.

Returns
Horizontal coordinate position in pixel
See also
y().

◆ x() [2/2]

template<typename T >
T Ocean::CV::PixelPositionT< T >::x
inline

Returns the horizontal coordinate position of this object.

Returns
Horizontal coordinate position in pixel
See also
y().

◆ y() [1/2]

template<typename T >
T & Ocean::CV::PixelPositionT< T >::y
inline

Returns the vertical coordinate position of this object.

Returns
Vertical coordinate position in pixel
See also
x().

◆ y() [2/2]

template<typename T >
T Ocean::CV::PixelPositionT< T >::y
inline

Returns the vertical coordinate position of this object.

Returns
Vertical coordinate position in pixel
See also
x().

Field Documentation

◆ x_

template<typename T >
T Ocean::CV::PixelPositionT< T >::x_
protected

Horizontal coordinate value of this object, in pixel.

◆ y_

template<typename T >
T Ocean::CV::PixelPositionT< T >::y_
protected

Vertical coordinate value of this object, in pixel.


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