replaced alloca() (a.k.a. cvStackAlloc) with AutoBuffer or vector() everywhere. cvStackAlloc() is still defined, but we do not need alloca() anymore to compile and run OpenCV (fixes #889 and may be some others)
This commit is contained in:
@@ -4040,6 +4040,53 @@ public:
|
||||
int index;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS AlgorithmImpl;
|
||||
|
||||
/*!
|
||||
Base class for high-level OpenCV algorithms
|
||||
*/
|
||||
class CV_EXPORTS Algorithm
|
||||
{
|
||||
public:
|
||||
virtual ~Algorithm();
|
||||
virtual string name() const;
|
||||
|
||||
template<typename _Tp> _Tp get(int paramId) const;
|
||||
template<typename _Tp> bool set(int paramId, const _Tp& value);
|
||||
string paramName(int paramId) const;
|
||||
string paramHelp(int paramId) const;
|
||||
int paramType(int paramId) const;
|
||||
int findParam(const string& name) const;
|
||||
template<typename _Tp> _Tp paramDefaultValue(int paramId) const;
|
||||
template<typename _Tp> bool paramRange(int paramId, _Tp& minVal, _Tp& maxVal) const;
|
||||
|
||||
virtual void getParams(vector<int>& ids) const;
|
||||
virtual void write(vector<uchar>& buf) const;
|
||||
virtual bool read(const vector<uchar>& buf);
|
||||
|
||||
typedef Algorithm* (*Constructor)(void);
|
||||
static void add(const string& name, Constructor create);
|
||||
static void getList(vector<string>& algorithms);
|
||||
static Ptr<Algorithm> create(const string& name);
|
||||
|
||||
protected:
|
||||
template<typename _Tp> void addParam(int propId, _Tp& value, bool readOnly, const string& name,
|
||||
const string& help=string(), const _Tp& defaultValue=_Tp(),
|
||||
_Tp (Algorithm::*getter)()=0, bool (Algorithm::*setter)(const _Tp&)=0);
|
||||
template<typename _Tp> void setParamRange(int propId, const _Tp& minVal, const _Tp& maxVal);
|
||||
|
||||
bool set_(int paramId, int argType, const void* value);
|
||||
void get_(int paramId, int argType, void* value);
|
||||
void paramDefaultValue_(int paramId, int argType, void* value);
|
||||
void paramRange_(int paramId, int argType, void* minval, void* maxval);
|
||||
void addParam_(int propId, int argType, void* value, bool readOnly, const string& name,
|
||||
const string& help, const void* defaultValue, void* getter, void* setter);
|
||||
void setParamRange_(int propId, int argType, const void* minVal, const void* maxVal);
|
||||
|
||||
Ptr<AlgorithmImpl> impl;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
@@ -266,15 +266,19 @@ CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
#ifdef __GNUC__
|
||||
#undef alloca
|
||||
#define alloca __builtin_alloca
|
||||
#define CV_HAVE_ALLOCA 1
|
||||
#elif defined WIN32 || defined _WIN32 || \
|
||||
defined WINCE || defined _MSC_VER || defined __BORLANDC__
|
||||
#include <malloc.h>
|
||||
#define CV_HAVE_ALLOCA 1
|
||||
#elif defined HAVE_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#define CV_HAVE_ALLOCA 1
|
||||
#elif defined HAVE_ALLOCA
|
||||
#include <stdlib.h>
|
||||
#define CV_HAVE_ALLOCA 1
|
||||
#else
|
||||
#error "No alloca!"
|
||||
#undef CV_HAVE_ALLOCA
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
@@ -285,8 +289,10 @@ CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
#define CV_DECL_ALIGNED(x)
|
||||
#endif
|
||||
|
||||
#if CV_HAVE_ALLOCA
|
||||
/* ! DO NOT make it an inline function */
|
||||
#define cvStackAlloc(size) cvAlignPtr( alloca((size) + CV_MALLOC_ALIGN), CV_MALLOC_ALIGN )
|
||||
#endif
|
||||
|
||||
#ifndef CV_IMPL
|
||||
#define CV_IMPL CV_EXTERN_C
|
||||
|
@@ -3550,6 +3550,51 @@ template<typename _Tp> static inline std::ostream& operator << (std::ostream& ou
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
template<typename _Tp> struct AlgorithmParamType {};
|
||||
template<> struct AlgorithmParamType<int> { enum { type = CV_PARAM_TYPE_INT }; };
|
||||
template<> struct AlgorithmParamType<double> { enum { type = CV_PARAM_TYPE_REAL }; };
|
||||
template<> struct AlgorithmParamType<string> { enum { type = CV_PARAM_TYPE_STRING }; };
|
||||
template<> struct AlgorithmParamType<Mat> { enum { type = CV_PARAM_TYPE_MAT }; };
|
||||
|
||||
template<typename _Tp> _Tp Algorithm::get(int paramId) const
|
||||
{
|
||||
_Tp value = _Tp();
|
||||
get_(paramId, AlgorithmParamType<_Tp>::type, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename _Tp> bool Algorithm::set(int paramId, const _Tp& value)
|
||||
{
|
||||
set_(paramId, AlgorithmParamType<_Tp>::type, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename _Tp> _Tp Algorithm::paramDefaultValue(int paramId) const
|
||||
{
|
||||
_Tp value = _Tp();
|
||||
paramDefaultValue_(paramId, AlgorithmParamType<_Tp>::type, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename _Tp> bool Algorithm::paramRange(int paramId, _Tp& minVal, _Tp& maxVal) const
|
||||
{
|
||||
return paramRange_(paramId, AlgorithmParamType<_Tp>::type, &minVal, &maxVal);
|
||||
}
|
||||
|
||||
template<typename _Tp> void Algorithm::addParam(int propId, _Tp& value, bool readOnly, const string& name,
|
||||
const string& help, const _Tp& defaultValue,
|
||||
_Tp (Algorithm::*getter)(), bool (Algorithm::*setter)(const _Tp&))
|
||||
{
|
||||
addParam_(propId, AlgorithmParamType<_Tp>::type, &value, readOnly, name, help, &defaultValue,
|
||||
(void*)getter, (void*)setter);
|
||||
}
|
||||
|
||||
template<typename _Tp> void Algorithm::setParamRange(int propId, const _Tp& minVal, const _Tp& maxVal)
|
||||
{
|
||||
setParamRange_(propId, AlgorithmParamType<_Tp>::type, &minVal, &maxVal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
@@ -793,7 +793,7 @@ CV_INLINE int cvIplDepth( int type )
|
||||
#define CV_TYPE_NAME_MATND "opencv-nd-matrix"
|
||||
|
||||
#define CV_MAX_DIM 32
|
||||
#define CV_MAX_DIM_HEAP (1 << 16)
|
||||
#define CV_MAX_DIM_HEAP 1024
|
||||
|
||||
typedef struct CvMatND
|
||||
{
|
||||
@@ -1868,6 +1868,8 @@ typedef struct CvModuleInfo
|
||||
}
|
||||
CvModuleInfo;
|
||||
|
||||
enum { CV_PARAM_TYPE_INT=0, CV_PARAM_TYPE_REAL=1, CV_PARAM_TYPE_STRING=2, CV_PARAM_TYPE_MAT=3 };
|
||||
|
||||
#endif /*_CXCORE_TYPES_H_*/
|
||||
|
||||
/* End of file. */
|
||||
|
Reference in New Issue
Block a user