diff options
Diffstat (limited to 'meowpp/gra/FeaturePoint.h')
-rw-r--r-- | meowpp/gra/FeaturePoint.h | 262 |
1 files changed, 0 insertions, 262 deletions
diff --git a/meowpp/gra/FeaturePoint.h b/meowpp/gra/FeaturePoint.h deleted file mode 100644 index 68ac65e..0000000 --- a/meowpp/gra/FeaturePoint.h +++ /dev/null @@ -1,262 +0,0 @@ -#ifndef gra_FeaturePoint_H__ -#define gra_FeaturePoint_H__ - -#include "../oo/ObjBase.h" - -#include "../math/Vector.h" - -#include <string> -#include <typeinfo> -#include <cstdlib> -#include <cstdio> - -namespace meow { - -/*! - * @brief 特徵點 - * - * @author cat_leopard - */ -template <class Scalar, class Description, - class Position = Vector<Scalar >, - class Feature = Vector<Description> > - -class FeaturePoint: public ObjBase { -private: - Position pos_; - Feature des_; -public: - /*! - * @brief constructor - */ - FeaturePoint() { - } - - /*! - * @brief constructor - */ - FeaturePoint(size_t pDim, size_t dDim): - pos_(pDim, Scalar(0)), des_(dDim, Description(0)) { - } - - /*! - * @brief constructor - */ - FeaturePoint(Position const& v, Feature const& d): - pos_(v), des_(d) { - } - - /*! - * @brief constructor - */ - FeaturePoint(FeaturePoint const& fp): - pos_(fp.pos_), des_(fp.des_) { - } - - /*! - * @brief destructor - */ - ~FeaturePoint() { - } - - /*! - * @brief 複製 - */ - FeaturePoint& copyFrom(FeaturePoint const& fp) { - pos_.copyFrom(fp.pos_); - des_.copyFrom(fp.des_); - return *this; - } - - /*! - * @brief 參照 - */ - FeaturePoint& referenceFrom(FeaturePoint const& fp) { - pos_.referenceFrom(fp.pos_); - des_.referenceFrom(fp.des_); - return *this; - } - - /*! - * @brief 回傳position - */ - Position position() const { - return pos_; - } - - /*! - * @brief 回傳position (non-const reference) - */ - Position& positionGet() { - return pos_; - } - - /*! - * @brief 回傳description - */ - Feature description() const { - return des_; - } - - /*! - * @brief 回傳description (non-const reference) - */ - Feature& descriptionGet() { - return des_; - } - - /*! - * @brief 修改position - */ - Position position(Position const& p) { - pos_.copyFrom(p); - return position(); - } - - /*! - * @brief 修改description - */ - Feature description(Feature const& d) { - des_.copyFrom(d); - return description(); - } - - /*! - * @brief 回傳position的第i個scalar - */ - Scalar position(size_t index) const { - return position()(index); - } - - /*! - * @brief 回傳description的第i個Description - */ - Description description(size_t index) const { - return des_(index); - } - - /*! - * @brief 修改position的第i個scalar - */ - Scalar position(size_t i, Scalar const& s) { - pos_.scalar(i, s); - return position()(i); - } - - /*! - * @brief 修改description的第i個Description - */ - Description description(size_t i, Description const& d) { - des_.scalar(i, d); - return description()(i); - } - - /*! - * @brief same as copyFrom(fp) - */ - FeaturePoint& operator=(FeaturePoint const& fp) { - return copyFrom(fp); - } - - /*! - * @brief same as position(i) - */ - Scalar const& operator()(size_t i) const { - return position(i); - } - - /*! - * @brief same as description(i) - */ - Description operator[](size_t i) const { - return description(i); - } - - bool write(FILE* f, bool bin, unsigned int fg) const { - if (bin) { - double tmp; - int a, b; - a = position().dimension(); - b = description().dimension(); - if (fwrite(&a, sizeof(a), 1, f) < 1) return false; - if (fwrite(&b, sizeof(b), 1, f) < 1) return false; - for (size_t i = 0, I = position().dimension(); i < I; ++i) { - if (fwrite(&(tmp = position(i)), sizeof(tmp), 1, f) < 1) return false; - } - for (size_t i = 0, I = description().dimension(); i < I; ++i) { - if (fwrite(&(tmp = description(i)), sizeof(tmp), 1, f) < 1) - return false; - } - } - else { - int a, b; - a = position().dimension(); - b = description().dimension(); - if (fprintf(f, "%d %d\n", a, b) < 2) return false; - for (size_t i = 0, I = position().dimension(); i < I; ++i) { - if (fprintf(f, "%f ", (double)position(i)) < 1) return false; - } - fprintf(f, "\n"); - for (size_t i = 0, I = description().dimension(); i < I; ++i) { - if (fprintf(f, "%f ", (double)description(i)) < 1) return false; - } - fprintf(f, "\n"); - } - return true; - } - - bool read(FILE* f, bool bin, unsigned int fg) { - if (bin) { - double tmp; - int a, b; - if (fread(&a, sizeof(a), 1, f) < 1) return false; - if (fread(&b, sizeof(b), 1, f) < 1) return false; - position(Position((size_t)a, Scalar(0))); - description(Feature((size_t)b, Description(0))); - for (size_t i = 0, I = position().dimension(); i < I; ++i) { - if (fread(&tmp, sizeof(tmp), 1, f) < 1) return false; - position(i, tmp); - } - for (size_t i = 0, I = description().dimension(); i < I; ++i) { - if (fread(&tmp, sizeof(tmp), 1, f) < 1) return false; - description(i, tmp); - } - } - else { - double tmp; - int a, b; - if (fscanf(f, "%d %d", &a, &b) < 2) return false; - position(Position((size_t)a, Scalar(0))); - description(Feature((size_t)b, Description(0))); - for (size_t i = 0, I = position().dimension(); i < I; ++i) { - if (fscanf(f, "%lf", &tmp) < 1) return false; - position(i, tmp); - } - for (size_t i = 0, I = description().dimension(); i < I; ++i) { - if (fscanf(f, "%lf", &tmp) < 1) return false; - description(i, tmp); - } - } - return true; - } - - ObjBase* create() const { - return new FeaturePoint(); - } - - ObjBase* copyFrom(ObjBase const& b) { - return &(copyFrom(*(FeaturePoint const*)b)); - } - - char const* ctype() const { - return typeid(*this).name(); - } - - std::string type() const { - return std::string(ctype()); - } -}; - -} // meow - -#endif // gra_FeaturePoint_H__ |