1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

removed rarely used fixed_size parameter from AutoBuffer type, added optional AutoBuffer* but to cvarrToMat in order to speedup CvSeq->Mat conversion; finished conversion of convex hull and related functions to C++

This commit is contained in:
Vadim Pisarevsky
2013-01-20 00:58:51 +04:00
parent 457fa52111
commit c197a46e7e
9 changed files with 206 additions and 654 deletions
+13 -5
View File
@@ -109,6 +109,8 @@ template<typename _Tp> class CV_EXPORTS MatIterator_;
template<typename _Tp> class CV_EXPORTS MatConstIterator_;
template<typename _Tp> class CV_EXPORTS MatCommaInitializer_;
template<typename _Tp> class CV_EXPORTS AutoBuffer;
CV_EXPORTS string format( const char* fmt, ... );
CV_EXPORTS string tempfile( const char* suffix CV_DEFAULT(0));
@@ -2061,7 +2063,8 @@ CV_EXPORTS void swap(Mat& a, Mat& b);
//! converts array (CvMat or IplImage) to cv::Mat
CV_EXPORTS Mat cvarrToMat(const CvArr* arr, bool copyData=false,
bool allowND=true, int coiMode=0);
bool allowND=true, int coiMode=0,
AutoBuffer<double>* buf=0);
//! extracts Channel of Interest from CvMat or IplImage and makes cv::Mat out of it.
CV_EXPORTS void extractImageCOI(const CvArr* arr, OutputArray coiimg, int coi=-1);
//! inserts single-channel cv::Mat into a multi-channel CvMat or IplImage
@@ -3081,7 +3084,7 @@ public:
\code
void my_func(const cv::Mat& m)
{
cv::AutoBuffer<float, 1000> buf; // create automatic buffer containing 1000 floats
cv::AutoBuffer<float> buf; // create automatic buffer containing 1000 floats
buf.allocate(m.rows); // if m.rows <= 1000, the pre-allocated buffer is used,
// otherwise the buffer of "m.rows" floats will be allocated
@@ -3090,16 +3093,22 @@ public:
}
\endcode
*/
template<typename _Tp, size_t fixed_size=4096/sizeof(_Tp)+8> class CV_EXPORTS AutoBuffer
template<typename _Tp> class CV_EXPORTS AutoBuffer
{
public:
typedef _Tp value_type;
enum { buffer_padding = (int)((16 + sizeof(_Tp) - 1)/sizeof(_Tp)) };
enum { fixed_size = 1024/sizeof(_Tp)+8, buffer_padding = (int)((16 + sizeof(_Tp) - 1)/sizeof(_Tp)) };
//! the default contructor
AutoBuffer();
//! constructor taking the real buffer size
AutoBuffer(size_t _size);
//! the copy constructor
AutoBuffer(const AutoBuffer<_Tp>& buf);
//! the assignment operator
AutoBuffer<_Tp>& operator = (const AutoBuffer<_Tp>& buf);
//! destructor. calls deallocate()
~AutoBuffer();
@@ -4318,7 +4327,6 @@ public:
int index;
};
class CV_EXPORTS Algorithm;
class CV_EXPORTS AlgorithmInfo;
struct CV_EXPORTS AlgorithmInfoData;
@@ -2534,23 +2534,46 @@ inline Point LineIterator::pos() const
/////////////////////////////// AutoBuffer ////////////////////////////////////////
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::AutoBuffer()
template<typename _Tp> inline AutoBuffer<_Tp>::AutoBuffer()
{
ptr = buf;
sz = fixed_size;
}
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::AutoBuffer(size_t _size)
template<typename _Tp> inline AutoBuffer<_Tp>::AutoBuffer(size_t _size)
{
ptr = buf;
sz = fixed_size;
allocate(_size);
}
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::~AutoBuffer()
template<typename _Tp>
inline AutoBuffer<_Tp>::AutoBuffer(const AutoBuffer<_Tp>& abuf )
{
ptr = buf;
sz = fixed_size;
allocate(abuf.size);
for( size_t i = 0; i < sz; i++ )
ptr[i] = abuf.ptr[i];
}
template<typename _Tp>
inline AutoBuffer<_Tp>& AutoBuffer<_Tp>::operator = (const AutoBuffer<_Tp>& abuf )
{
if( this != &abuf )
{
deallocate();
allocate(abuf.size);
for( size_t i = 0; i < sz; i++ )
ptr[i] = abuf.ptr[i];
}
return *this;
}
template<typename _Tp> inline AutoBuffer<_Tp>::~AutoBuffer()
{ deallocate(); }
template<typename _Tp, size_t fixed_size> inline void AutoBuffer<_Tp, fixed_size>::allocate(size_t _size)
template<typename _Tp> inline void AutoBuffer<_Tp>::allocate(size_t _size)
{
if(_size <= sz)
{
@@ -2565,17 +2588,17 @@ template<typename _Tp, size_t fixed_size> inline void AutoBuffer<_Tp, fixed_size
}
}
template<typename _Tp, size_t fixed_size> inline void AutoBuffer<_Tp, fixed_size>::deallocate()
template<typename _Tp> inline void AutoBuffer<_Tp>::deallocate()
{
if( ptr != buf )
{
delete[] ptr;
ptr = buf;
sz = 0;
sz = fixed_size;
}
}
template<typename _Tp, size_t fixed_size> inline void AutoBuffer<_Tp, fixed_size>::resize(size_t _size)
template<typename _Tp> inline void AutoBuffer<_Tp>::resize(size_t _size)
{
if(_size <= sz)
{
@@ -2598,13 +2621,13 @@ template<typename _Tp, size_t fixed_size> inline void AutoBuffer<_Tp, fixed_size
delete[] prevptr;
}
template<typename _Tp, size_t fixed_size> inline size_t AutoBuffer<_Tp, fixed_size>::size() const
template<typename _Tp> inline size_t AutoBuffer<_Tp>::size() const
{ return sz; }
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::operator _Tp* ()
template<typename _Tp> inline AutoBuffer<_Tp>::operator _Tp* ()
{ return ptr; }
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::operator const _Tp* () const
template<typename _Tp> inline AutoBuffer<_Tp>::operator const _Tp* () const
{ return ptr; }