2D point (x, y) or size (width, height). More...
#include <SimdPoint.hpp>
Public Types | |
| typedef T | Type |
Public Member Functions | |
| Point () | |
| template<typename TX , typename TY > | |
| SIMD_CONSTEXPR | Point (TX tx, TY ty) |
| template<class TP , template< class > class TPoint> | |
| Point (const TPoint< TP > &p) | |
| template<class TS > | |
| Point (const cv::Size_< TS > &size) | |
| SIMD_CONSTEXPR | ~Point () |
| template<class TP , template< class > class TPoint> | |
| operator TPoint< TP > () const | |
| template<typename TP > | |
| Point & | operator= (const Point< TP > &p) |
| template<typename TP > | |
| Point & | operator+= (const Point< TP > &p) |
| template<typename TP > | |
| Point & | operator-= (const Point< TP > &p) |
| template<typename TA > | |
| Point & | operator*= (const TA &a) |
| Point & | operator/= (double a) |
| Point | operator<< (ptrdiff_t shift) const |
| Point | operator>> (ptrdiff_t shift) const |
| operator cv::Point2f () const | |
Data Fields | |
| T | x |
| Horizontal coordinate, or width when the point is a size. Grows to the right. | |
| T | y |
| Vertical coordinate, or height when the point is a size. Grows downward in image space. | |
Detailed Description
struct Simd::Point< T >
2D point (x, y) or size (width, height).
Point<T> stores two coordinates of type T. The usual image coordinate system has its origin at the top-left corner: X grows to the right and Y grows downward. That is how Simd::DrawLine, Simd::DrawRectangle, Simd::Font::Draw, View::At and contour anchors use a Point<ptrdiff_t>. The same type is also a size: x is the width and y is the height. View::Size(), Motion::Size, Pyramid::Recreate, Simd::Resize and Simd::TransformSize use it that way. Rectangle(point) treats the point as the bottom-right corner and sets the top-left corner to (0, 0), so Rectangle(view.Size()) is the full image. TestImageMatcher passes Rect(src.Size()) as the crop of Simd::ShiftBilinear.
Point() is the origin (0, 0). Motion measures the squared diagonal of a frame with SquaredDistance(model.frameSize, Point()), which is width*width + height*height. ShiftDetector treats Point() as an unset frame size. Simd::TransformSize returns Point<ptrdiff_t>() for an unknown transform.
Coordinates passed to the constructor are converted to T. Conversion of float or double to ptrdiff_t rounds to the nearest integer (half away from zero). Other conversions are a C-style cast. TestCheckCpp builds Point<ptrdiff_t>(1.4, 2.6), which becomes (1, 3), and Point<double>(1.4, 3.6), which keeps the fractional values. Assignment and the converting constructor copy x and y the same way. TestShift builds ShiftDetector::FPoint from an integer Point to compare a refined sub-pixel shift.
Point<double> is a sub-pixel shift. Simd::ShiftBilinear takes Point<double> as the shift along X and Y. The image-matcher test uses FPoint(Random() * 2 - 1, Random() * 2 - 1). ShiftDetector::FPoint is the refined shift added to the integer shift. Motion::FPoint is a different use of the same type: an ONVIF coordinate in [-1, 1] whose origin is the screen center and whose Y axis grows upward. Motion::FSize stores an ONVIF size in [0, 2]. Those ranges belong to the Motion aliases, not to Point itself.
Point<float> is the source position of a destination corner after the affine matrix in WarpAffine. The mapped point is Point(x * m[0] + y * m[1] + m[2], x * m[3] + y * m[4] + m[5]).
Arithmetic is component-wise. Motion flood-fill walks current + Point(-1, 0) and the other 4-neighbours, then reads View::At(neighbour). ExpandRoi scales a parent corner onto the next pyramid level with TopLeft() * 2 - Point(1, 1) and BottomRight() * 2 + Point(1, 1). Simd::SquaredDistance compares object centers and trajectory points without a square root. Pyramid::Scale halves a size with (x + 1) >> 1 on each coordinate; the Point shift operators shift both coordinates and do not add 1.
With SIMD_OPENCV_ENABLE, a point converts to and from cv::Point (x, y) and cv::Size (width, height), and it converts to cv::Point2f.
Using example:
OpenCV conversion (define SIMD_OPENCV_ENABLE before including this header):
Member Typedef Documentation
◆ Type
| typedef T Type |
Coordinate type. ptrdiff_t is a pixel or a size. double is a sub-pixel shift.
Constructor & Destructor Documentation
◆ Point() [1/4]
| SIMD_INLINE Point |
Creates a point (0, 0).
Point() is the image origin and an empty size. Motion measures the squared diagonal of a frame with SquaredDistance(frameSize, Point()). ShiftDetector compares the frame size with Point() before estimation.
◆ Point() [2/4]
| SIMD_CONSTEXPR Point | ( | TX | tx, |
| TY | ty | ||
| ) |
Creates a point from two coordinates.
Each coordinate is converted to T. float and double values converted to ptrdiff_t are rounded to the nearest integer, with halves rounded away from zero. Point<ptrdiff_t>(1.4, 2.6) is therefore (1, 3). Point<double> keeps the fractional values. Drawing, font placement, contour anchors and motion screen points pass integer pixel coordinates. Simd::Resize passes a size as Point(width, height). Motion builds ONVIF corners as FPoint(-1.0, 1.0). WarpAffine builds Point<float> from the affine mapping of a corner.
- Parameters
-
[in] tx - initial X value. It is the width when the point is a size. [in] ty - initial Y value. It is the height when the point is a size.
◆ Point() [3/4]
| Point | ( | const TPoint< TP > & | p | ) |
Creates a point from another point type that has x and y.
Both coordinates are converted to T. This copies between Point<ptrdiff_t> and Point<double>. TestShift wraps an integer shift in ShiftDetector::FPoint before SquaredDistance. With SIMD_OPENCV_ENABLE the same constructor reads cv::Point_<T>::x and cv::Point_<T>::y, so a Simd point can be assigned from cv::Point.
- Parameters
-
[in] p - a point of arbitrary type with x and y fields.
◆ Point() [4/4]
| Point | ( | const cv::Size_< TS > & | size | ) |
Creates a point from an OpenCV size.
x is set from size.width and y from size.height. Both values are converted to T, so a floating OpenCV size assigned to Point<ptrdiff_t> is rounded. This is the conversion used by simdPoint = cvSize.
- Note
- You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
- Parameters
-
[in] size - an OpenCV size. width becomes x and height becomes y.
◆ ~Point()
| SIMD_INLINE SIMD_CONSTEXPR ~Point |
Destroys the point. The destructor has no side effects.
Member Function Documentation
◆ operator TPoint< TP >()
| operator TPoint< TP > | ( | ) | const |
Converts this point to another point type constructed from (x, y).
Coordinates are converted to the target type. With SIMD_OPENCV_ENABLE this is how a Simd point is assigned to cv::Point and to cv::Size (cv::Size receives x as width and y as height).
- Returns
- a point of arbitrary type.
◆ operator=()
Copies another point into this point.
x and y are converted to T. Assigning Point<double> to Point<ptrdiff_t> rounds each coordinate.
- Parameters
-
[in] p - a point of arbitrary coordinate type.
- Returns
- a reference to itself.
◆ operator+=()
Adds another point to this point.
The added coordinates are converted to T and then added to x and y. The free operator + used by the motion flood-fill (current + Point(dx, dy)) builds a new point with the same component-wise sum.
- Parameters
-
[in] p - a point of arbitrary coordinate type.
- Returns
- a reference to itself.
◆ operator-=()
Subtracts another point from this point.
The subtracted coordinates are converted to T. The free operator - used by ExpandRoi (corner * 2 - Point(1, 1)) builds a new point with the same component-wise difference.
- Parameters
-
[in] p - a point of arbitrary coordinate type.
- Returns
- a reference to itself.
◆ operator*=()
| Point & operator*= | ( | const TA & | a | ) |
Multiplies both coordinates by a scalar.
Each product is converted back to T. A floating factor applied to Point<ptrdiff_t> is rounded. The free operator * used by ExpandRoi (TopLeft() * 2) returns a new point and does not modify this one. ShiftDetector doubles a coarse shift by writing shift.x and shift.y, one pyramid level at a time, rather than by calling this operator.
- Parameters
-
[in] a - a factor of arbitrary type.
- Returns
- a reference to itself.
◆ operator/=()
| SIMD_INLINE Point< T > & operator/= | ( | double | a | ) |
Divides both coordinates by a double precision value.
Each quotient is converted back to T. Point<ptrdiff_t> therefore rounds the result, including halves away from zero. The divisor is double; there is no overload for an integer divisor. Dividing two points by each other is the free operator / and is component-wise.
- Parameters
-
[in] a - a divider.
- Returns
- a reference to itself.
◆ operator<<()
| SIMD_INLINE Point< T > operator<< | ( | ptrdiff_t | shift | ) | const |
Returns a point with both coordinates shifted left by the same bit count.
The operator is meaningful for integer coordinate types. It returns a new point and does not modify this one. Pyramid::Scale does not use it: that function halves a size with (coordinate + 1) >> 1 so odd sizes round up.
- Parameters
-
[in] shift - a non-negative bit count.
- Returns
- a new point with shifted coordinates.
◆ operator>>()
| SIMD_INLINE Point< T > operator>> | ( | ptrdiff_t | shift | ) | const |
Returns a point with both coordinates shifted right by the same bit count.
The operator is meaningful for integer coordinate types. It returns a new point and does not modify this one. A right shift by 1 halves both coordinates and truncates toward negative infinity for non-negative values. Pyramid::Scale adds 1 before that shift.
- Parameters
-
[in] shift - a non-negative bit count.
- Returns
- a new point with shifted coordinates.
◆ operator cv::Point2f()
| SIMD_INLINE operator cv::Point2f |
Converts this point to cv::Point2f.
x and y are passed to the cv::Point2f constructor. This conversion is available only when SIMD_OPENCV_ENABLE is defined. Assignment to cv::Point and cv::Size uses the converting operator to an arbitrary point type.
- Note
- You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
- Returns
- a cv::Point2f with the same coordinates.