aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/gra/IdentityPoints.h
diff options
context:
space:
mode:
Diffstat (limited to 'meowpp/gra/IdentityPoints.h')
-rw-r--r--meowpp/gra/IdentityPoints.h392
1 files changed, 0 insertions, 392 deletions
diff --git a/meowpp/gra/IdentityPoints.h b/meowpp/gra/IdentityPoints.h
deleted file mode 100644
index 029180f..0000000
--- a/meowpp/gra/IdentityPoints.h
+++ /dev/null
@@ -1,392 +0,0 @@
-#ifndef gra_IdentityPoints_H__
-#define gra_IdentityPoints_H__
-
-#include "../Self.h"
-#include "../math/Vector.h"
-#include "../oo/ObjBase.h"
-
-#include <map>
-#include <set>
-#include <utility>
-
-#include <cstdlib>
-
-namespace meow {
-
-/*!
- * @brief 把一個 \c std::map<Identity, Point > 包起來
- *
- * @author cat_leopard
- */
-template<class Identity, class Scalar, class Point = Vector<Scalar> >
-class IdentityPoints: public ObjBase {
-public:
-
- typedef typename std::vector<Identity> Identities;
- typedef typename std::vector<Point> Points;
-
- typedef typename std::pair<Identity, Point> IdentityPointPair;
- typedef typename std::vector<IdentityPointPair> IdentityPointPairs;
-
- typedef typename std::pair<Point, Point> PointPair;
- typedef typename std::vector<PointPair> PointPairs;
-
-private:
- typedef typename std::map<Identity, Point> IdentityPointsMap ;
- typedef typename IdentityPointsMap:: iterator IdentityPointsMapIter ;
- typedef typename IdentityPointsMap::const_iterator IdentityPointsMapIterK;
-
- struct Myself {
- IdentityPointsMap points_;
- size_t dimension_;
-
- Myself(size_t d): dimension_(d) {
- }
-
- Myself(Myself const& m): points_(m.points_), dimension_(m.dimension_) {
- }
-
- ~Myself() {
- }
- };
-
- Self<Myself> const self;
-public:
- /*!
- * @brief setup dimension
- */
- IdentityPoints(size_t d): self(Myself(d)) {
- }
-
- /*!
- * @brief constructor, 並且複製資料
- */
- IdentityPoints(IdentityPoints const& b):
- self(b.self, Self<Myself>::COPY_FROM) {
- }
-
- /*!
- * @brief destructor
- */
- ~IdentityPoints() {
- }
-
- /*!
- * @brief 複製資料
- */
- IdentityPoints& copyFrom(IdentityPoints const& b) {
- self().copyFrom(b.self);
- return *this;
- }
-
- /*!
- * @brief 參照
- */
- IdentityPoints& referenceFrom(IdentityPoints const& b) {
- self().referenceFrom(b.self);
- return *this;
- }
-
- /*!
- * @brief 清除一切identity points
- */
- void clear() {
- self()->points_.clear();
- }
-
- /*!
- * @brief 回傳有幾個identity points
- */
- size_t size() const {
- return self->points_.size();
- }
-
- /*!
- * @brief 回傳是否沒有identity points
- */
- bool empty() const {
- return (size() == 0u);
- }
-
- /*!
- * @brief 檢查某id是否有使用
- */
- bool exist(Identity const& id) const {
- return (self->points_.find(id) != self->points_.end());
- }
-
- /*!
- * @brief 回傳dimension
- */
- size_t dimension() const {
- return self->dimension_;
- }
-
- /*!
- * @brief 回傳所有 identity
- */
- Identities identities() const {
- Identities ret;
- for (IdentityPointsMapIterK
- it = self->points_.begin(), ed = self->points_.end(); it != ed; ++it) {
- ret.push_back(it->first);
- }
- return ret;
- }
-
- /*!
- * @brief 回傳所有 points
- */
- Points points() const {
- Points ret;
- for (IdentityPointsMapIterK
- it = self->points_.begin(), ed = self->points_.end(); it != ed; ++it) {
- ret.push_back(it->second);
- }
- return ret;
- }
-
- /*!
- * @brief 回傳所有pair
- */
- IdentityPointPairs pairs() const {
- IdentityPointPairs ret;
- for (IdentityPointsMapIterK
- it = self->points_.begin(), ed = self->points_.end(); it != ed; ++it) {
- ret.push_back(IdentityPointPair(it->first, it->second));
- }
- return ret;
- }
-
- /*!
- * @brief 取代所有pair
- */
- IdentityPointPairs pairs(IdentityPointPairs const& p) {
- clear();
- for (size_t i = 0, I = p.size(); i < I; ++i) {
- pointAdd(p[i].first, p[i].second);
- }
- return pairs();
- }
-
- /*!
- * @brief 加入所有pair
- */
- IdentityPointPairs pairsAdd(IdentityPointPairs const& p) {
- for (size_t i = 0, I = p.size(); i < I; ++i) {
- pointAdd(p[i].first, p[i].second);
- }
- return pairs();
- }
-
- /*!
- * @brief 取得一個identity point
- */
- Point point(Identity const& id) const {
- return (exist(id) ? self->points_.find(id)->second : Point());
- }
-
- /*!
- * @brief 取得一個 identity point (non-constant reference)
- */
- Point& point(Identity const& id) {
- static Point tmp(0);
- return (exist(id) ? self()->points_.find(id)->second : tmp);
- }
-
- /*!
- * @brief 修改一個identity point
- */
- Point point(Identity const& id, Point const& b) {
- if (b.dimension() == self->dimension_) {
- self()->points_[id].copyFrom(b);
- }
- return point(id);
- }
-
- /*!
- * @brief 新增一個identity point
- */
- Point pointAdd(Identity const& id, Point const& b) {
- if (b.dimension() == self->dimension_ && !exist(id)) {
- self()->points_[id].copyFrom(b);
- }
- return point(id);
- }
-
- /*!
- * @brief 刪除一個identity point
- */
- void pointDel(Identity const& id) {
- self()->points_.erase(id);
- }
-
- /*!
- * @brief intersection
- */
- Identities intersectIdentites(IdentityPoints const& b) {
- Identities ret;
- IdentityPointsMapIterK it1, ed1, it2, ed2;
- it1 = self->points_.begin();
- ed1 = self->points_.end ();
- it2 = b.self->points_.begin();
- ed2 = b.self->points_.end ();
- while (it1 != ed1 && it2 != ed2) {
- if (it1->first < it2->first) { ++it1; }
- else if(it1->first > it2->first) { ++it2; }
- else {
- ret.push_back(it1->first);
- ++it1;
- ++it2;
- }
- }
- return ret;
- }
-
- /*!
- * @brief intersection
- */
- PointPairs intersectPoints(IdentityPoints const& b) {
- PointPairs ret;
- IdentityPointsMapIterK it1, ed1, it2, ed2;
- it1 = self->points_.begin();
- ed1 = self->points_.end ();
- it2 = b.self->points_.begin();
- ed2 = b.self->points_.end ();
- while (it1 != ed1 && it2 != ed2) {
- if (it1->first < it2->first) { ++it1; }
- else if(it1->first > it2->first) { ++it2; }
- else {
- ret.push_back(PointPair(it1->second, it2->second));
- ++it1;
- ++it2;
- }
- }
- return ret;
- }
-
- /*!
- * @brief same as \c copyFrom(b)
- */
- IdentityPoints& operator=(IdentityPoints const& b) {
- return copyFrom(b);
- }
-
- /*! @brief 將資料寫入檔案
- *
- * @note 未完成
- */
- bool write(FILE* f, bool bin, unsigned int fg) const {
- if (bin) {
- long dim, ct;
- if (fwrite(&(dim = dimension()), sizeof(dim), 1, f) < 1) return false;
- if (fwrite(&(ct = size()), sizeof(ct), 1, f) < 1) return false;
- IdentityPointsMapIterK it = self->points_.begin();
- IdentityPointsMapIterK ed = self->points_.end ();
- for ( ; it != ed; ++it) {
- double tmp;
- if (fwrite(&(tmp = it->first), sizeof(tmp), 1, f) < 1) return false;
- for (long i = 0; i < dim; ++i) {
- if (fwrite(&(tmp = it->second(i)), sizeof(tmp), 1, f) < 1)
- return false;
- }
- }
- }
- else {
- if (fprintf(f, "%ld %lu\n", dimension(), size()) < 1) return false;
- IdentityPointsMapIterK it = self->points_.begin();
- IdentityPointsMapIterK ed = self->points_.end ();
- for ( ; it != ed; ++it) {
- if (fprintf(f, "%f ", (double)it->first) < 1) return false;
- for (long i = 0, I = dimension(); i < I; ++i) {
- if (fprintf(f, "%f ", (double)it->second(i)) < 1) return false;
- }
- fprintf(f, "\n");
- }
- }
- return true;
- }
-
- /*! @brief 將資料讀入
- *
- * @note 未完成
- */
- bool read(FILE* f, bool bin, unsigned int fg) {
- long dim, ct;
- if (bin) {
- if (fread(&dim, sizeof(dim), 1, f) < 1) return false;
- copyFrom(IdentityPoints(dim));
- if (fread(&ct, sizeof(ct), 1, f) < 1) return false;
- double id, tt;
- IdentityPointsMapIterK it = self->points_.begin();
- IdentityPointsMapIterK ed = self->points_.end ();
- Point tmp((size_t)dim, Scalar(0));
- for ( ; it != ed; ++it) {
- if (fread(&id, sizeof(id), 1, f) < 1) return false;
- for (size_t j = 0, J = dim; j < J; ++j) {
- if (fread(&tt, sizeof(tt), 1, f) < 1) return false;
- tmp.scalar(j, tt);
- }
- pointAdd((Identity)id, tmp);
- }
- }
- else {
- if (fscanf(f, "%ld %ld", &dim, &ct) < 2) return false;
- copyFrom(IdentityPoints(dim));
- double id, tt;
- IdentityPointsMapIterK it = self->points_.begin();
- IdentityPointsMapIterK ed = self->points_.end ();
- Point tmp((size_t)dim, Scalar(0));
- for ( ; it != ed; ++it) {
- if (fscanf(f, "%lf", &id) < 1) return false;
- for (int j = 0, J = dim; j < J; ++j) {
- if (fscanf(f, "%lf", &tt) < 1) return false;
- tmp.scalar(j, tt);
- }
- pointAdd((Identity)id, tmp);
- }
- }
- return true;
- }
-
- /*! @brief new一個自己
- *
- * @return 一個new出來的Bitmap<Pixel>
- */
- ObjBase* create() const {
- return new IdentityPoints(dimension());
- }
-
- /*! @brief 複製資料
- *
- * 輸入型別是 \c ObjBase \c const*
- * 這裡假設實體其實是 \c Bitmap.
- * 事實上這個method就只是幫忙轉型然後呼叫原本的\c copyFrom
- *
- * @param [in] b 資料來源
- * @return this
- */
- ObjBase* copyFrom(ObjBase const* b) {
- return &(copyFrom(*(IdentityPoints const*)b));
- }
-
- /*! @brief 回傳class的type
- *
- * @return \c char \c const\c * 形式的typename
- */
- char const* ctype() const {
- return typeid(*this).name();
- }
-
- /*! @brief 回傳class的type
- *
- * @return \c std::string 形式的typename
- */
- std::string type() const {
- return std::string(ctype());
- }
-};
-
-} // meow
-
-#endif // gra_IdentityPoints_H__