diff options
Diffstat (limited to 'meowpp/gra/FeaturePoint.h')
-rw-r--r-- | meowpp/gra/FeaturePoint.h | 79 |
1 files changed, 60 insertions, 19 deletions
diff --git a/meowpp/gra/FeaturePoint.h b/meowpp/gra/FeaturePoint.h index 4b80a3d..c3ab8f3 100644 --- a/meowpp/gra/FeaturePoint.h +++ b/meowpp/gra/FeaturePoint.h @@ -75,6 +75,13 @@ public: } /*! + * @brief 回傳position (non-const reference) + */ + Vector<Scalar>& positionGet() { + return pos_; + } + + /*! * @brief 回傳description */ Vector<Description> const& description() const { @@ -82,6 +89,13 @@ public: } /*! + * @brief 回傳description (non-const reference) + */ + Vector<Description>& descriptionGet() { + return des_; + } + + /*! * @brief 修改position */ Vector<Scalar> const& position(Vector<Scalar> const& p) const { @@ -128,20 +142,6 @@ public: } /*! - * @brief 取得position - */ - Vector<Scalar>& positionGet() { - return pos_; - } - - /*! - * @brief 取得description - */ - Vector<Description>& descriptionGet() { - return des_; - } - - /*! * @brief same as copyFrom(fp) */ FeaturePoint& operator=(FeaturePoint const& fp) { @@ -163,11 +163,53 @@ public: } bool write(FILE* f, bool bin, unsigned int fg) const { - return false; + if (bin) { + double tmp; + 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 { + 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) { - return false; + if (bin) { + double tmp; + 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; + 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 { @@ -179,8 +221,7 @@ public: } char const* ctype() const { - static char const* ptr = typeid(*this).name(); - return ptr; + return typeid(*this).name(); } std::string type() const { @@ -188,6 +229,6 @@ public: } }; -} +} // meow #endif // gra_FeaturePoint_H__ |