aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/gra/FeaturePoint.h
diff options
context:
space:
mode:
Diffstat (limited to 'meowpp/gra/FeaturePoint.h')
-rw-r--r--meowpp/gra/FeaturePoint.h49
1 files changed, 38 insertions, 11 deletions
diff --git a/meowpp/gra/FeaturePoint.h b/meowpp/gra/FeaturePoint.h
index b2cbd37..631a8e6 100644
--- a/meowpp/gra/FeaturePoint.h
+++ b/meowpp/gra/FeaturePoint.h
@@ -17,11 +17,13 @@ namespace meow {
*
* @author cat_leopard
*/
-template<class Scalar, class Description>
+template<class Scalar, class Description,
+class Position = Vector<Scalar>, class Feature = Vector<Description> >
+
class FeaturePoint: public ObjBase {
private:
- Vector<Scalar> pos_;
- Vector<Description> des_;
+ Position pos_;
+ Feature des_;
public:
/*!
* @brief constructor
@@ -39,6 +41,13 @@ public:
/*!
* @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_) {
}
@@ -70,35 +79,35 @@ public:
/*!
* @brief 回傳position
*/
- Vector<Scalar> position() const {
+ Position position() const {
return pos_;
}
/*!
* @brief 回傳position (non-const reference)
*/
- Vector<Scalar>& positionGet() {
+ Position& positionGet() {
return pos_;
}
/*!
* @brief 回傳description
*/
- Vector<Description> description() const {
+ Feature description() const {
return des_;
}
/*!
* @brief 回傳description (non-const reference)
*/
- Vector<Description>& descriptionGet() {
+ Feature& descriptionGet() {
return des_;
}
/*!
* @brief 修改position
*/
- Vector<Scalar> position(Vector<Scalar> const& p) const {
+ Position position(Position const& p) {
pos_.copyFrom(p);
return position();
}
@@ -106,7 +115,7 @@ public:
/*!
* @brief 修改description
*/
- Vector<Description> description(Vector<Description> const& d) {
+ Feature description(Feature const& d) {
des_.copyFrom(d);
return description();
}
@@ -121,8 +130,8 @@ public:
/*!
* @brief 回傳description的第i個Description
*/
- Description description(size_t i) const {
- return des_(i);
+ Description description(size_t index) const {
+ return des_(index);
}
/*!
@@ -165,6 +174,11 @@ public:
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;
}
@@ -174,6 +188,10 @@ public:
}
}
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;
}
@@ -189,6 +207,11 @@ public:
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(a, Scalar(0)));
+ description(Feature(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);
@@ -200,6 +223,10 @@ public:
}
else {
double tmp;
+ int a, b;
+ if (fscanf(f, "%d %d", &a, &b) < 2) return false;
+ position(Position(a, Scalar(0)));
+ description(Feature(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);