mirror of https://github.com/opencv/opencv.git
cv::Complex, cv::Point_ and cv::Point3_ are moved.pull/747/head
parent
19f8f85c51
commit
13b31b0804
19 changed files with 314 additions and 251 deletions
@ -0,0 +1,251 @@ |
|||||||
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||||
|
//
|
||||||
|
// By downloading, copying, installing or using the software you agree to this license.
|
||||||
|
// If you do not agree to this license, do not download, install,
|
||||||
|
// copy or use the software.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||||
|
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||||
|
// Third party copyrights are property of their respective owners.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
// are permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// * The name of the copyright holders may not be used to endorse or promote products
|
||||||
|
// derived from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// This software is provided by the copyright holders and contributors "as is" and
|
||||||
|
// any express or implied warranties, including, but not limited to, the implied
|
||||||
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||||
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||||
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||||
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||||
|
// loss of use, data, or profits; or business interruption) however caused
|
||||||
|
// and on any theory of liability, whether in contract, strict liability,
|
||||||
|
// or tort (including negligence or otherwise) arising in any way out of
|
||||||
|
// the use of this software, even if advised of the possibility of such damage.
|
||||||
|
//
|
||||||
|
//M*/
|
||||||
|
|
||||||
|
#ifndef __OPENCV_CORE_TYPES_HPP__ |
||||||
|
#define __OPENCV_CORE_TYPES_HPP__ |
||||||
|
|
||||||
|
#include <climits> |
||||||
|
|
||||||
|
#ifndef OPENCV_NOSTL |
||||||
|
# include <complex> |
||||||
|
#endif |
||||||
|
|
||||||
|
#include "opencv2/core/cvdef.h" |
||||||
|
#include "opencv2/core/cvstd.hpp" |
||||||
|
|
||||||
|
namespace cv |
||||||
|
{ |
||||||
|
template<typename _Tp> class CV_EXPORTS Size_; |
||||||
|
template<typename _Tp> class CV_EXPORTS Point_; |
||||||
|
template<typename _Tp> class CV_EXPORTS Rect_; |
||||||
|
|
||||||
|
template<typename _Tp, int cn> class CV_EXPORTS Vec; |
||||||
|
//template<typename _Tp, int m, int n> class CV_EXPORTS Matx;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////// saturate_cast (used in image & signal processing) ///////////////////
|
||||||
|
|
||||||
|
template<typename _Tp> static inline _Tp saturate_cast(uchar v) { return _Tp(v); } |
||||||
|
template<typename _Tp> static inline _Tp saturate_cast(schar v) { return _Tp(v); } |
||||||
|
template<typename _Tp> static inline _Tp saturate_cast(ushort v) { return _Tp(v); } |
||||||
|
template<typename _Tp> static inline _Tp saturate_cast(short v) { return _Tp(v); } |
||||||
|
template<typename _Tp> static inline _Tp saturate_cast(unsigned v) { return _Tp(v); } |
||||||
|
template<typename _Tp> static inline _Tp saturate_cast(int v) { return _Tp(v); } |
||||||
|
template<typename _Tp> static inline _Tp saturate_cast(float v) { return _Tp(v); } |
||||||
|
template<typename _Tp> static inline _Tp saturate_cast(double v) { return _Tp(v); } |
||||||
|
|
||||||
|
template<> inline uchar saturate_cast<uchar>(schar v) { return (uchar)std::max((int)v, 0); } |
||||||
|
template<> inline uchar saturate_cast<uchar>(ushort v) { return (uchar)std::min((unsigned)v, (unsigned)UCHAR_MAX); } |
||||||
|
template<> inline uchar saturate_cast<uchar>(int v) { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); } |
||||||
|
template<> inline uchar saturate_cast<uchar>(short v) { return saturate_cast<uchar>((int)v); } |
||||||
|
template<> inline uchar saturate_cast<uchar>(unsigned v) { return (uchar)std::min(v, (unsigned)UCHAR_MAX); } |
||||||
|
template<> inline uchar saturate_cast<uchar>(float v) { int iv = cvRound(v); return saturate_cast<uchar>(iv); } |
||||||
|
template<> inline uchar saturate_cast<uchar>(double v) { int iv = cvRound(v); return saturate_cast<uchar>(iv); } |
||||||
|
|
||||||
|
template<> inline schar saturate_cast<schar>(uchar v) { return (schar)std::min((int)v, SCHAR_MAX); } |
||||||
|
template<> inline schar saturate_cast<schar>(ushort v) { return (schar)std::min((unsigned)v, (unsigned)SCHAR_MAX); } |
||||||
|
template<> inline schar saturate_cast<schar>(int v) { return (schar)((unsigned)(v-SCHAR_MIN) <= (unsigned)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); } |
||||||
|
template<> inline schar saturate_cast<schar>(short v) { return saturate_cast<schar>((int)v); } |
||||||
|
template<> inline schar saturate_cast<schar>(unsigned v) { return (schar)std::min(v, (unsigned)SCHAR_MAX); } |
||||||
|
template<> inline schar saturate_cast<schar>(float v) { int iv = cvRound(v); return saturate_cast<schar>(iv); } |
||||||
|
template<> inline schar saturate_cast<schar>(double v) { int iv = cvRound(v); return saturate_cast<schar>(iv); } |
||||||
|
|
||||||
|
template<> inline ushort saturate_cast<ushort>(schar v) { return (ushort)std::max((int)v, 0); } |
||||||
|
template<> inline ushort saturate_cast<ushort>(short v) { return (ushort)std::max((int)v, 0); } |
||||||
|
template<> inline ushort saturate_cast<ushort>(int v) { return (ushort)((unsigned)v <= (unsigned)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); } |
||||||
|
template<> inline ushort saturate_cast<ushort>(unsigned v) { return (ushort)std::min(v, (unsigned)USHRT_MAX); } |
||||||
|
template<> inline ushort saturate_cast<ushort>(float v) { int iv = cvRound(v); return saturate_cast<ushort>(iv); } |
||||||
|
template<> inline ushort saturate_cast<ushort>(double v) { int iv = cvRound(v); return saturate_cast<ushort>(iv); } |
||||||
|
|
||||||
|
template<> inline short saturate_cast<short>(ushort v) { return (short)std::min((int)v, SHRT_MAX); } |
||||||
|
template<> inline short saturate_cast<short>(int v) { return (short)((unsigned)(v - SHRT_MIN) <= (unsigned)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); } |
||||||
|
template<> inline short saturate_cast<short>(unsigned v) { return (short)std::min(v, (unsigned)SHRT_MAX); } |
||||||
|
template<> inline short saturate_cast<short>(float v) { int iv = cvRound(v); return saturate_cast<short>(iv); } |
||||||
|
template<> inline short saturate_cast<short>(double v) { int iv = cvRound(v); return saturate_cast<short>(iv); } |
||||||
|
|
||||||
|
template<> inline int saturate_cast<int>(float v) { return cvRound(v); } |
||||||
|
template<> inline int saturate_cast<int>(double v) { return cvRound(v); } |
||||||
|
|
||||||
|
// we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc.
|
||||||
|
template<> inline unsigned saturate_cast<unsigned>(float v) { return cvRound(v); } |
||||||
|
template<> inline unsigned saturate_cast<unsigned>(double v) { return cvRound(v); } |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////// Complex //////////////////////////////
|
||||||
|
|
||||||
|
/*!
|
||||||
|
A complex number class. |
||||||
|
|
||||||
|
The template class is similar and compatible with std::complex, however it provides slightly |
||||||
|
more convenient access to the real and imaginary parts using through the simple field access, as opposite |
||||||
|
to std::complex::real() and std::complex::imag(). |
||||||
|
*/ |
||||||
|
template<typename _Tp> class CV_EXPORTS Complex |
||||||
|
{ |
||||||
|
public: |
||||||
|
|
||||||
|
//! constructors
|
||||||
|
Complex(); |
||||||
|
Complex( _Tp _re, _Tp _im=0 ); |
||||||
|
|
||||||
|
//! conversion to another data type
|
||||||
|
template<typename T2> operator Complex<T2>() const; |
||||||
|
//! conjugation
|
||||||
|
Complex conj() const; |
||||||
|
|
||||||
|
_Tp re, im; //< the real and the imaginary parts
|
||||||
|
|
||||||
|
#ifndef OPENCV_NOSTL |
||||||
|
Complex( const std::complex<_Tp>& c ); |
||||||
|
operator std::complex<_Tp>() const; |
||||||
|
#endif |
||||||
|
}; |
||||||
|
|
||||||
|
/*!
|
||||||
|
\typedef |
||||||
|
*/ |
||||||
|
typedef Complex<float> Complexf; |
||||||
|
typedef Complex<double> Complexd; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////// Point_ ////////////////////////////////
|
||||||
|
|
||||||
|
/*!
|
||||||
|
template 2D point class. |
||||||
|
|
||||||
|
The class defines a point in 2D space. Data type of the point coordinates is specified |
||||||
|
as a template parameter. There are a few shorter aliases available for user convenience. |
||||||
|
See cv::Point, cv::Point2i, cv::Point2f and cv::Point2d. |
||||||
|
*/ |
||||||
|
template<typename _Tp> class CV_EXPORTS Point_ |
||||||
|
{ |
||||||
|
public: |
||||||
|
typedef _Tp value_type; |
||||||
|
|
||||||
|
// various constructors
|
||||||
|
Point_(); |
||||||
|
Point_(_Tp _x, _Tp _y); |
||||||
|
Point_(const Point_& pt); |
||||||
|
Point_(const Size_<_Tp>& sz); |
||||||
|
Point_(const Vec<_Tp, 2>& v); |
||||||
|
|
||||||
|
Point_& operator = (const Point_& pt); |
||||||
|
//! conversion to another data type
|
||||||
|
template<typename _Tp2> operator Point_<_Tp2>() const; |
||||||
|
|
||||||
|
//! conversion to the old-style C structures
|
||||||
|
operator Vec<_Tp, 2>() const; |
||||||
|
|
||||||
|
//! dot product
|
||||||
|
_Tp dot(const Point_& pt) const; |
||||||
|
//! dot product computed in double-precision arithmetics
|
||||||
|
double ddot(const Point_& pt) const; |
||||||
|
//! cross-product
|
||||||
|
double cross(const Point_& pt) const; |
||||||
|
//! checks whether the point is inside the specified rectangle
|
||||||
|
bool inside(const Rect_<_Tp>& r) const; |
||||||
|
|
||||||
|
_Tp x, y; //< the point coordinates
|
||||||
|
}; |
||||||
|
|
||||||
|
/*!
|
||||||
|
\typedef |
||||||
|
*/ |
||||||
|
typedef Point_<int> Point2i; |
||||||
|
typedef Point_<float> Point2f; |
||||||
|
typedef Point_<double> Point2d; |
||||||
|
typedef Point2i Point; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////// Point3_ ////////////////////////////////
|
||||||
|
|
||||||
|
/*!
|
||||||
|
template 3D point class. |
||||||
|
|
||||||
|
The class defines a point in 3D space. Data type of the point coordinates is specified |
||||||
|
as a template parameter. |
||||||
|
|
||||||
|
\see cv::Point3i, cv::Point3f and cv::Point3d |
||||||
|
*/ |
||||||
|
template<typename _Tp> class CV_EXPORTS Point3_ |
||||||
|
{ |
||||||
|
public: |
||||||
|
typedef _Tp value_type; |
||||||
|
|
||||||
|
// various constructors
|
||||||
|
Point3_(); |
||||||
|
Point3_(_Tp _x, _Tp _y, _Tp _z); |
||||||
|
Point3_(const Point3_& pt); |
||||||
|
explicit Point3_(const Point_<_Tp>& pt); |
||||||
|
Point3_(const Vec<_Tp, 3>& v); |
||||||
|
|
||||||
|
Point3_& operator = (const Point3_& pt); |
||||||
|
//! conversion to another data type
|
||||||
|
template<typename _Tp2> operator Point3_<_Tp2>() const; |
||||||
|
//! conversion to cv::Vec<>
|
||||||
|
operator Vec<_Tp, 3>() const; |
||||||
|
|
||||||
|
//! dot product
|
||||||
|
_Tp dot(const Point3_& pt) const; |
||||||
|
//! dot product computed in double-precision arithmetics
|
||||||
|
double ddot(const Point3_& pt) const; |
||||||
|
//! cross product of the 2 3D points
|
||||||
|
Point3_ cross(const Point3_& pt) const; |
||||||
|
|
||||||
|
_Tp x, y, z; //< the point coordinates
|
||||||
|
}; |
||||||
|
|
||||||
|
/*!
|
||||||
|
\typedef |
||||||
|
*/ |
||||||
|
typedef Point3_<int> Point3i; |
||||||
|
typedef Point3_<float> Point3f; |
||||||
|
typedef Point3_<double> Point3d; |
||||||
|
|
||||||
|
} // cv
|
||||||
|
|
||||||
|
#endif //__OPENCV_CORE_TYPES_HPP__
|
Loading…
Reference in new issue