Move cv::Scalar_ to types.hpp
This commit is contained in:
@@ -455,8 +455,6 @@ public:
|
||||
Vec cross(const Vec& v) const;
|
||||
//! convertion to another data type
|
||||
template<typename T2> operator Vec<T2, cn>() const;
|
||||
//! conversion to 4-element CvScalar.
|
||||
operator CvScalar() const;
|
||||
|
||||
/*! element access */
|
||||
const _Tp& operator [](int i) const;
|
||||
@@ -503,43 +501,6 @@ typedef Vec<double, 4> Vec4d;
|
||||
typedef Vec<double, 6> Vec6d;
|
||||
|
||||
|
||||
//////////////////////////////// Scalar_ ///////////////////////////////
|
||||
|
||||
/*!
|
||||
The template scalar class.
|
||||
|
||||
This is partially specialized cv::Vec class with the number of elements = 4, i.e. a short vector of four elements.
|
||||
Normally, cv::Scalar ~ cv::Scalar_<double> is used.
|
||||
*/
|
||||
template<typename _Tp> class CV_EXPORTS Scalar_ : public Vec<_Tp, 4>
|
||||
{
|
||||
public:
|
||||
//! various constructors
|
||||
Scalar_();
|
||||
Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
|
||||
Scalar_(const CvScalar& s);
|
||||
Scalar_(_Tp v0);
|
||||
|
||||
//! returns a scalar with all elements set to v0
|
||||
static Scalar_<_Tp> all(_Tp v0);
|
||||
//! conversion to the old-style CvScalar
|
||||
operator CvScalar() const;
|
||||
|
||||
//! conversion to another data type
|
||||
template<typename T2> operator Scalar_<T2>() const;
|
||||
|
||||
//! per-element product
|
||||
Scalar_<_Tp> mul(const Scalar_<_Tp>& t, double scale=1 ) const;
|
||||
|
||||
// returns (v0, -v1, -v2, -v3)
|
||||
Scalar_<_Tp> conj() const;
|
||||
|
||||
// returns true iff v1 == v2 == v3 == 0
|
||||
bool isReal() const;
|
||||
};
|
||||
|
||||
typedef Scalar_<double> Scalar;
|
||||
|
||||
CV_EXPORTS void scalarToRawData(const Scalar& s, void* buf, int type, int unroll_to=0);
|
||||
|
||||
|
||||
@@ -570,19 +531,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
template<typename _Tp> class DataType<Scalar_<_Tp> >
|
||||
{
|
||||
public:
|
||||
typedef Scalar_<_Tp> value_type;
|
||||
typedef Scalar_<typename DataType<_Tp>::work_type> work_type;
|
||||
typedef _Tp channel_type;
|
||||
enum { generic_type = 0, depth = DataDepth<channel_type>::value, channels = 4,
|
||||
fmt = ((channels-1)<<8) + DataDepth<channel_type>::fmt,
|
||||
type = CV_MAKETYPE(depth, channels) };
|
||||
typedef Vec<channel_type, channels> vec_type;
|
||||
};
|
||||
|
||||
|
||||
//////////////////// generic_type ref-counting pointer class for C/C++ objects ////////////////////////
|
||||
|
||||
/*!
|
||||
|
@@ -1171,15 +1171,6 @@ inline Vec<_Tp, cn>::operator Vec<T2, cn>() const
|
||||
return v;
|
||||
}
|
||||
|
||||
template<typename _Tp, int cn> inline Vec<_Tp, cn>::operator CvScalar() const
|
||||
{
|
||||
CvScalar s = {{0,0,0,0}};
|
||||
int i;
|
||||
for( i = 0; i < std::min(cn, 4); i++ ) s.val[i] = this->val[i];
|
||||
for( ; i < 4; i++ ) s.val[i] = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename _Tp, int cn> inline const _Tp& Vec<_Tp, cn>::operator [](int i) const
|
||||
{
|
||||
CV_DbgAssert( (unsigned)i < (unsigned)cn );
|
||||
@@ -1894,12 +1885,11 @@ template<typename _Tp> inline Scalar_<_Tp>::Scalar_()
|
||||
template<typename _Tp> inline Scalar_<_Tp>::Scalar_(_Tp v0, _Tp v1, _Tp v2, _Tp v3)
|
||||
{ this->val[0] = v0; this->val[1] = v1; this->val[2] = v2; this->val[3] = v3; }
|
||||
|
||||
template<typename _Tp> inline Scalar_<_Tp>::Scalar_(const CvScalar& s)
|
||||
template<typename _Tp> template<typename _Tp2, int cn> inline Scalar_<_Tp>::Scalar_(const Vec<_Tp2, cn>& v)
|
||||
{
|
||||
this->val[0] = saturate_cast<_Tp>(s.val[0]);
|
||||
this->val[1] = saturate_cast<_Tp>(s.val[1]);
|
||||
this->val[2] = saturate_cast<_Tp>(s.val[2]);
|
||||
this->val[3] = saturate_cast<_Tp>(s.val[3]);
|
||||
int i;
|
||||
for( i = 0; i < (cn < 4 ? cn : 4); i++ ) this->val[i] = cv::saturate_cast<_Tp>(v.val[i]);
|
||||
for( ; i < 4; i++ ) this->val[i] = 0;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline Scalar_<_Tp>::Scalar_(_Tp v0)
|
||||
@@ -1907,8 +1897,6 @@ template<typename _Tp> inline Scalar_<_Tp>::Scalar_(_Tp v0)
|
||||
|
||||
template<typename _Tp> inline Scalar_<_Tp> Scalar_<_Tp>::all(_Tp v0)
|
||||
{ return Scalar_<_Tp>(v0, v0, v0, v0); }
|
||||
template<typename _Tp> inline Scalar_<_Tp>::operator CvScalar() const
|
||||
{ return cvScalar(this->val[0], this->val[1], this->val[2], this->val[3]); }
|
||||
|
||||
template<typename _Tp> template<typename T2> inline Scalar_<_Tp>::operator Scalar_<T2>() const
|
||||
{
|
||||
|
@@ -521,6 +521,68 @@ public:
|
||||
|
||||
|
||||
|
||||
//////////////////////////////// Scalar_ ///////////////////////////////
|
||||
|
||||
/*!
|
||||
The template scalar class.
|
||||
|
||||
This is partially specialized cv::Vec class with the number of elements = 4, i.e. a short vector of four elements.
|
||||
Normally, cv::Scalar ~ cv::Scalar_<double> is used.
|
||||
*/
|
||||
template<typename _Tp> class CV_EXPORTS Scalar_ : public Vec<_Tp, 4>
|
||||
{
|
||||
public:
|
||||
//! various constructors
|
||||
Scalar_();
|
||||
Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
|
||||
Scalar_(_Tp v0);
|
||||
|
||||
template<typename _Tp2, int cn>
|
||||
Scalar_(const Vec<_Tp2, cn>& v);
|
||||
|
||||
//! returns a scalar with all elements set to v0
|
||||
static Scalar_<_Tp> all(_Tp v0);
|
||||
|
||||
//! conversion to another data type
|
||||
template<typename T2> operator Scalar_<T2>() const;
|
||||
|
||||
//! per-element product
|
||||
Scalar_<_Tp> mul(const Scalar_<_Tp>& t, double scale=1 ) const;
|
||||
|
||||
// returns (v0, -v1, -v2, -v3)
|
||||
Scalar_<_Tp> conj() const;
|
||||
|
||||
// returns true iff v1 == v2 == v3 == 0
|
||||
bool isReal() const;
|
||||
};
|
||||
|
||||
/*!
|
||||
\typedef
|
||||
*/
|
||||
typedef Scalar_<double> Scalar;
|
||||
|
||||
/*!
|
||||
traits
|
||||
*/
|
||||
template<typename _Tp> class DataType< Scalar_<_Tp> >
|
||||
{
|
||||
public:
|
||||
typedef Scalar_<_Tp> value_type;
|
||||
typedef Scalar_<typename DataType<_Tp>::work_type> work_type;
|
||||
typedef _Tp channel_type;
|
||||
|
||||
enum { generic_type = 0,
|
||||
depth = DataType<channel_type>::value,
|
||||
channels = 4,
|
||||
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
|
||||
typedef Vec<channel_type, channels> vec_type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/////////////////////////////// KeyPoint ////////////////////////////////
|
||||
|
||||
/*!
|
||||
|
@@ -1014,6 +1014,22 @@ CV_INLINE CvSlice cvSlice( int start, int end )
|
||||
typedef struct CvScalar
|
||||
{
|
||||
double val[4];
|
||||
|
||||
#ifdef __cplusplus
|
||||
CvScalar() {}
|
||||
CvScalar(double d0, double d1 = 0, double d2 = 0, double d3 = 0) { val[0] = d0; val[1] = d1; val[2] = d2; val[3] = d3; }
|
||||
template<typename _Tp>
|
||||
CvScalar(const cv::Scalar_<_Tp>& s) { val[0] = s.val[0]; val[1] = s.val[1]; val[2] = s.val[2]; val[3] = s.val[3]; }
|
||||
template<typename _Tp>
|
||||
operator cv::Scalar_<_Tp>() const { return cv::Scalar_<_Tp>(cv::saturate_cast<_Tp>(val[0]), cv::saturate_cast<_Tp>(val[1]), cv::saturate_cast<_Tp>(val[2]), cv::saturate_cast<_Tp>(val[3])); }
|
||||
template<typename _Tp, int cn>
|
||||
CvScalar(const cv::Vec<_Tp, cn>& v)
|
||||
{
|
||||
int i;
|
||||
for( i = 0; i < (cn < 4 ? cn : 4); i++ ) val[i] = v.val[i];
|
||||
for( ; i < 4; i++ ) val[i] = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
CvScalar;
|
||||
|
||||
|
Reference in New Issue
Block a user