diff options
Diffstat (limited to 'meowpp')
37 files changed, 550 insertions, 399 deletions
diff --git a/meowpp/Self.h b/meowpp/Self.h index aefc7a3..6518c79 100644 --- a/meowpp/Self.h +++ b/meowpp/Self.h @@ -35,7 +35,7 @@ namespace meow { * } * }; * - * Self<Myself> const self; // Here we use 'constant' data type in + * Self<Myself> const self; // Here we use 'constant' data type in * // order to have a coutious coding style * // and allow the COR mechanism to clone * // data only when we really want to @@ -114,48 +114,75 @@ private: class Body { private: struct Kernel { - Data data_; - int counter_; + Data* data_; + size_t counter_; + Body const* master_; - Kernel( ): data_( ), counter_(1) { } - Kernel(Data const& data): data_(data), counter_(1) { } - ~Kernel() { } + Kernel(Body const* master): + data_(new Data( )), counter_(1), master_(master) { + } + + Kernel(Body const* master, Data const& d): + data_(new Data(d)), counter_(1), master_(master) { + } + + ~Kernel() { + } }; Kernel* pointer_; - int counter_; + size_t counter_; + + void clear() { + --(pointer_->counter_); + if (pointer_->counter_ <= 0) { + delete pointer_; + } + } public: - Body( ): pointer_(new Kernel( )), counter_(1) { } - Body(Data const& d): pointer_(new Kernel(d)), counter_(1) { } - Body(Body const& b): pointer_(b.pointer_ ), counter_(1) { - ++pointer_->counter_; + Body( ): pointer_(new Kernel(this )), counter_(1) { } + Body(Data const& d): pointer_(new Kernel(this, d)), counter_(1) { } + Body(Body const& b): pointer_(b.pointer_ ), counter_(1) { + ++(pointer_->counter_); } + ~Body() { clear(); } + Body& copyFrom(Body const& b) { clear(); pointer_ = b.pointer_; ++(pointer_->counter_); return *this; } - void clear() { - --(pointer_->counter_); - if (pointer_->counter_ <= 0) { - delete pointer_; - } - } - int attach() { return ++counter_; } - int detach() { return --counter_; } + Data const* access() const { - return &(pointer_->data_); + return pointer_->data_; } + Data* modify() { if (pointer_->counter_ > 1) { - --pointer_->counter_; - pointer_ = new Kernel(pointer_->data_); + --(pointer_->counter_); + Kernel* dupl = new Kernel(this, *pointer_->data_); + if (pointer_->master_ == this || pointer_->master_ == NULL) { + std::swap(pointer_->pointer_, dupl->pointer_); + pointer_->master_ = NULL; + } + pointer_ = dupl; } - return &(pointer_->data_); + else if (pointer_->master_ == NULL) { + pointer_->master_ = this; + } + return pointer_->data_; + } + + int attach() { + return ++counter_; + } + + int detach() { + return --counter_; } }; diff --git a/meowpp/colors/Color3_Space.h b/meowpp/colors/Color3_Space.h index 94cae39..80a6b32 100644 --- a/meowpp/colors/Color3_Space.h +++ b/meowpp/colors/Color3_Space.h @@ -10,7 +10,7 @@ namespace meow { /*! - * @brief 以三個channel所組成的色彩空間 + * @brief Base class of color space with 3 channels. * * @author cat_leopard */ @@ -20,49 +20,127 @@ protected: Vector3D<T> min_; Vector3D<T> max_; Vector3D<T> val_; + + /*! + * @brief Constructor + * + * @param [in] min_bound Minimum value of each channels. + * @param [in] max_bound Maximum value of each channels. + * @param [in] init_value Initial value of each channels. + */ Color3_Space(Vector3D<T> const& min_bound, Vector3D<T> const& max_bound, - Vector3D<T> const& init_value) { - min_ = min_bound; - max_ = max_bound; - val_ = init_value; + Vector3D<T> const& init_value): + min_(min_bound), max_(max_bound), val_(init_value) { } - Color3_Space(Color3_Space const& b) { - min_ = b.min_; - max_ = b.max_; - val_ = b.val_; + + /*! + * @brief Copy constructor + * + * @param [in] b Data to copy from. + */ + Color3_Space(Color3_Space const& b): + min_(b.min_), max_(b.max_), val_(b.val_) { } + + /*! + * @brief Copy method + * + * We copy the value only, not include \c min_bound and \c max_bound. + * + * @param [in] b Value to copy from. + * @return \c *this + */ Color3_Space<T>& copyFrom(Color3_Space<T> const& b) { val_ = b.val_; return *this; } public: + //! @brief Destructor virtual ~Color3_Space() { } - Vector3D<T> const& minV() const { return min_; } - Vector3D<T> const& maxV() const { return max_; } - Vector3D<T> const& valV() const { return val_; } - Vector3D<T> const& valV(Vector3D<T> const& vv) { val_ = vv; return val(); } - Vector3D<T> & valVGet() { return val_; } + + //! @brief minimum bound of each channels. + Vector3D<T> const& minV() const { + return min_; + } + + //! @brief maximum bound of each channels. + Vector3D<T> const& maxV() const { + return max_; + } + + //! @brief value of each channels. + Vector3D<T> const& valV() const { + return val_; + } + + /*! + * @brief Set the value of each channels. + * + * @param [in] vv new value + * @return new value + */ + Vector3D<T> const& valV(Vector3D<T> const& vv) { + val_ = vv; + return val(); + } + + //! @brief Get the non-constant reference of each channels. + Vector3D<T>& valVGet() { + return val_; + } + + /*! + * @brief Return the minimum of the \c i -th channel. + * + * @param [in] id index of the channel. + * @return new value + */ T const& min(size_t id) const { return minV()(id); } - T const& max(size_t id) const { return maxV()(id); } - T const& val(size_t id) const { return valV()(id); } + + /*! + * @brief Return the maximum of the \c i -th channel. + * + * @param [in] id index of the channel. + * @return new value + */ + T const& max(size_t id) const { + return maxV()(id); + } + + /*! + * @brief Return the value of the \c i -th channel. + * + * @param [in] id index of the channel. + * @return new value + */ + T const& val(size_t id) const { + return valV()(id); + } + + /*! + * @brief Set the value of \c i -th channel. + * + * @param [in] i index of the channel + * @param [in] c new value + */ T const& val(size_t i, T const& c) { if (i == 0) val_.x(c); else if (i == 1) val_.y(c); else if (i == 2) val_.z(c); return val(i); } + + /*! + * @brief Get the non-constant reference of value of the \c i -th channel. + * + * @param [in] id index of the channel + */ T& valGet(size_t id) { if (id == 0) return valVGet().xGet(); else if (id == 1) return valVGet().yGet(); else return valVGet().zGet(); } - Matrix<T> matrix() const { - Matrix<T> ret(3, 1); - for (size_t i = 0; i < 3; i++) { - ret(i, 0, val(i)); - } - } }; } // meow diff --git a/meowpp/dsa/BinaryIndexTree.h b/meowpp/dsa/BinaryIndexTree.h index 5525c62..1d2d9e8 100644 --- a/meowpp/dsa/BinaryIndexTree.h +++ b/meowpp/dsa/BinaryIndexTree.h @@ -97,6 +97,6 @@ public: } }; -} +} // meow #endif // dsa_BinaryIndexTree_H__ diff --git a/meowpp/dsa/DisjointSet.h b/meowpp/dsa/DisjointSet.h index 9be9c35..1711d7d 100644 --- a/meowpp/dsa/DisjointSet.h +++ b/meowpp/dsa/DisjointSet.h @@ -130,6 +130,6 @@ public: } }; -} +} // meow #endif // dsa_DisjointSet_H__ diff --git a/meowpp/dsa/HashTable.h b/meowpp/dsa/HashTable.h index 5f343f5..ed97d6d 100644 --- a/meowpp/dsa/HashTable.h +++ b/meowpp/dsa/HashTable.h @@ -212,6 +212,6 @@ public: } }; -} +} // meow #endif // dsa_HashTable_H__ diff --git a/meowpp/dsa/KD_Tree.h b/meowpp/dsa/KD_Tree.h index e3bd73b..e5a51dc 100644 --- a/meowpp/dsa/KD_Tree.h +++ b/meowpp/dsa/KD_Tree.h @@ -298,6 +298,6 @@ public: } }; -} +} // meow #endif // dsa_KD_Tree_H__ diff --git a/meowpp/dsa/MergeableHeap.h b/meowpp/dsa/MergeableHeap.h index 0967edd..91b8d8b 100644 --- a/meowpp/dsa/MergeableHeap.h +++ b/meowpp/dsa/MergeableHeap.h @@ -163,6 +163,6 @@ public: } }; -} +} // meow #endif // dsa_MergeableHeap_H__ diff --git a/meowpp/dsa/SegmentTree.h b/meowpp/dsa/SegmentTree.h index 64eab4c..305c4c3 100644 --- a/meowpp/dsa/SegmentTree.h +++ b/meowpp/dsa/SegmentTree.h @@ -189,6 +189,6 @@ public: } }; -} +} // meow #endif // dsa_SegmentTree_H__ diff --git a/meowpp/dsa/SplayTree.h b/meowpp/dsa/SplayTree.h index 40a2a0b..483b965 100644 --- a/meowpp/dsa/SplayTree.h +++ b/meowpp/dsa/SplayTree.h @@ -1146,6 +1146,6 @@ public: } }; -} +} // meow #endif // dsa_SplayTree_h__ diff --git a/meowpp/dsa/VP_Tree.h b/meowpp/dsa/VP_Tree.h index 9c85930..3d85327 100644 --- a/meowpp/dsa/VP_Tree.h +++ b/meowpp/dsa/VP_Tree.h @@ -332,6 +332,6 @@ public: } }; -} +} // meow #endif // dsa_VP_Tree_H__ diff --git a/meowpp/geo/Vectors.h b/meowpp/geo/Vectors.h index 0f09ee6..78fcc42 100644 --- a/meowpp/geo/Vectors.h +++ b/meowpp/geo/Vectors.h @@ -91,6 +91,16 @@ public: return *this; } + //! @brief access the \c i -th scalar (0 => x, 1 => y) + Scalar const& scalar(size_t i) const { + return (i == 0 ? x() : (i == 1 ? y() : Scalar(0))); + } + + //! @brief modivy the \c i -th scalar (0 => x, 1 => y) + Scalar const& scalar(size_t i, Scalar const& s) { + return (i == 0 ? x(s) : (i == 1 ? y(s) : s)); + } + //! @brief return \a +(*this) Vector2D positive() const { return *this; @@ -347,6 +357,16 @@ public: return *this; } + //! @brief access the \c i -th scalar (0 => x, 1 => y, 2 => z) { + Scalar const& scalar(size_t i) const { + return (i == 0 ? x() : (i == 1 ? y() : (i == 2 ? z() : Scalar(0)))); + } + + //! @brief modivy the \c i -th scalar (0 => x, 1 => y, 2 => z) + Scalar const& scalar(size_t i, Scalar const& s) { + return (i == 0 ? x(s) : (i == 1 ? y(s) : (i == 2 ? z(s) : s ))); + } + //! @brief return \a +(*this) Vector3D positive() const { return *this; @@ -471,7 +491,7 @@ public: return ret; } - //! @brief return a 3x1 matrix form of itself + //! @brief return a 4x1 matrix form of itself Matrix<Scalar> matrix(Scalar const& homo) const { static Matrix<Scalar> ret(4, 1, Scalar(0)); ret(0, 0, x()); @@ -505,6 +525,6 @@ public: Vector3D& operator/=(Scalar const& s) { return dived(s); } }; -} +} // meow #endif // geo_Vectors_H__ diff --git a/meowpp/gra/Bitmap.h b/meowpp/gra/Bitmap.h index 59136c2..1457df8 100644 --- a/meowpp/gra/Bitmap.h +++ b/meowpp/gra/Bitmap.h @@ -14,6 +14,8 @@ namespace meow { +const unsigned int kBitmapReadWritePixels = 0x1; + /*! * @brief 二維點陣資料 * @@ -36,7 +38,7 @@ private: factor[width] = 1.0; return factor; } - + //! 回傳gradiance的權重 static std::vector<double> gradianceFactor1(double sigma) { double sigma2 = squ(sigma), ss = sigma * 2; @@ -49,7 +51,7 @@ private: factor[width] = 0.0; return factor; } - + //! 針對某一方向用某種權重模糊 Bitmap xyBlur(std::vector<double> const& factor, ssize_t dx, ssize_t dy) const { @@ -100,7 +102,7 @@ public: /*! * @brief destructor */ - ~Bitmap(){ + ~Bitmap() { } /*! @@ -237,7 +239,7 @@ public: /*! * @brief 回傳矩陣形式 */ - Matrix<Pixel> const& matrix() const { + Matrix<Pixel> matrix() const { return matrix_; } @@ -251,7 +253,7 @@ public: /*! * @brief 直接設定 */ - Matrix<Pixel> const& matrix(Matrix<Pixel> const& p) { + Matrix<Pixel> matrix(Matrix<Pixel> const& p) { matrix_.copyFrom(p); return matrix(); } @@ -275,9 +277,8 @@ public: * @param [in] radiusX 高斯模糊的X軸方向的sigma * @return *this */ - Bitmap<Pixel>& gaussianed(double radiusY, double radiusX) { - copyFrom(gaussian(radiusY, radiusX)); - return *this; + Bitmap& gaussianed(double radiusY, double radiusX) { + return copyFrom(gaussian(radiusY, radiusX)); } /*! @@ -287,7 +288,7 @@ public: * @param [in] radiusX 高斯模糊的X軸方向的sigma * @return 一個\c Bitmap , 是自己被偏微分後的結果 */ - Bitmap<Pixel> gradianceX(double radiusY, double radiusX) const { + Bitmap gradianceX(double radiusY, double radiusX) const { return (xyBlur(gaussianFactor1(radiusY), 1, 0). xyBlur(gradianceFactor1(radiusX), 0, 1)); } @@ -352,7 +353,7 @@ public: * @note 未完成, 輸入參數 fg 無用 */ bool write(FILE* f, bool bin, unsigned int fg) const { - if (fg & 1) + if (fg & kBitmapReadWritePixels) return false; if (bin) { long tmp; @@ -371,7 +372,7 @@ public: * @note 未完成, 輸入參數 fg 無用 */ bool read(FILE* f, bool bin, unsigned int fg) { - if (fg & 1) + if (fg & kBitmapReadWritePixels) return false; long tmp1, tmp2; if (bin) { @@ -423,6 +424,7 @@ public: } }; + } // meow #endif // gra_Bitmap_H__ diff --git a/meowpp/gra/BundleAdjustment.h b/meowpp/gra/BundleAdjustment.h index 9dd01b7..13fe0b1 100644 --- a/meowpp/gra/BundleAdjustment.h +++ b/meowpp/gra/BundleAdjustment.h @@ -17,16 +17,16 @@ template<class Pixel> struct SceneInfo { Eye<Pixel>* eye; unsigned long flag; - + SceneInfo(): eye(NULL), flag(0) { } - + SceneInfo(Eye<Pixel>* e, unsigned long f): eye(e), flag(f) { } - + SceneInfo(SceneInfo const& si): eye(si.eye), flag(si.flag) { } - + ~SceneInfo() { } }; @@ -39,11 +39,11 @@ protected: public: virtual ~BundleAdjustment() { } - + virtual bool adjustEye(std::vector<SceneInfo<Pixel> >* seq) const { return false; } - + virtual bool adjustFixedPoint(std::vector<SceneInfo<Pixel> >* seq) const { return false; } diff --git a/meowpp/gra/BundleAdjustment_LM.h b/meowpp/gra/BundleAdjustment_LM.h index 7a86666..15eaac5 100644 --- a/meowpp/gra/BundleAdjustment_LM.h +++ b/meowpp/gra/BundleAdjustment_LM.h @@ -25,7 +25,7 @@ private: size_t to_i; Matrix<double> to_m; }; - + class NoOffsetController { private: std::vector<MatchPair >* pairs_; diff --git a/meowpp/gra/Camera.h b/meowpp/gra/Camera.h index 2b6347c..174b196 100644 --- a/meowpp/gra/Camera.h +++ b/meowpp/gra/Camera.h @@ -14,7 +14,7 @@ namespace meow { /*! * @brief Camera * - * 實際上就是一個 \c Photo 加上一個 \c Rotation3D. + * 實際上就是一個 \c Photo 加上一個 \c Rotation3D. * 另外附有 fixedPoint, 可以用來定位時參考 * * @author cat_leopard @@ -46,7 +46,7 @@ public: */ Camera(): self() { } - + /*! * @brief copy constructor */ @@ -58,7 +58,7 @@ public: */ ~Camera() { } - + /*! * @brief 複製資料 */ @@ -66,7 +66,7 @@ public: self().copyFrom(b.self); return *this; } - + /*! * @brief 參照 */ @@ -90,7 +90,7 @@ public: } /*! - * @brief 設定 photo + * @brief 設定 photo */ Photo<Pixel> const& photo(Photo<Pixel> const& pho) { self()->photo_.copyFrom(pho); @@ -165,7 +165,7 @@ public: return self->photo_.color( Vector3D<double>(rotation().transformate(p.matrix()))); } - + /*! * @brief same as \c copyFrom(b) */ diff --git a/meowpp/gra/Eye.h b/meowpp/gra/Eye.h index 2621a16..0d62892 100644 --- a/meowpp/gra/Eye.h +++ b/meowpp/gra/Eye.h @@ -10,7 +10,7 @@ namespace meow { /*! * @brief 一個 \c Camera 加上一個offset transformation - * + * * @author cat_leopard */ template<class Pixel> @@ -19,78 +19,78 @@ private: struct Myself { Camera<Pixel> cam_; Vector3D<double> ofs_; - + Myself(): cam_(), ofs_(0.0, 0.0, 0.0) { } - + Myself(Camera<Pixel> const& c, Vector3D<double> const& o): cam_(c), ofs_(o){ } - + Myself(Myself const& b): cam_(b.cam_), ofs_(b.ofs_) { } - + ~Myself() { } }; - + Self<Myself> const self; public: Eye(): self() { } - + Eye(Eye const& b): self(b.self(), Self<Myself>::COPY_FROM) { } - + Eye(Camera<Pixel> const& c, Vector3D<double> const& o): self(Myself(c, o)) { } - + ~Eye() { } - + Eye& copyFrom(Eye const& e) { self().copyFrom(e.self); return *this; } - + Eye& referenceFrom(Eye const& e) { self().referenceFrom(e.self); return *this; } - + Camera<Pixel> const& camera() const { return self->cam_; } - + Camera<Pixel>& cameraGet() { return self()->cam_; } - + Camera<Pixel> const& camera(Camera<Pixel> const& c) { self()->cam_.copyFrom(c); return camera(); } - + Vector3D<double> const& offset() const { return self->ofs_; } - + Vector3D<double>& offsetGet() { return self()->ofs_; } - + Vector3D<double> const& offset(Vector3D<double> const& ofs) { self()->ofs_ = ofs; return offset(); } - + bool inside(Vector3D<double> const& v) const { return camera().inside(v - offset()); } - + Eye& operator=(Eye const& e) { return copyFrom(e); } - + /*! @brief 將資料寫入檔案 * * @note 未完成 diff --git a/meowpp/gra/FeaturePointsDetector_Harris.h b/meowpp/gra/FeaturePointsDetector_Harris.h index 11529f0..e7c6b91 100644 --- a/meowpp/gra/FeaturePointsDetector_Harris.h +++ b/meowpp/gra/FeaturePointsDetector_Harris.h @@ -62,104 +62,104 @@ public: //! @brief constructor 使用預設參數 FPD_Harris(): self() { } - + //! @brief constructor 參數複製自另一個 FeaturePointsDetector_Harris FPD_Harris(FPD_Harris const& fps): self(fps.self, Self<Myself>::COPY_FROM) { } - + //! @brief 解構子 ~FPD_Harris() { } - + //! @brief 複製 FPD_Harris& copyFrom(FPD_Harris const& fps) { self().copyFrom(fps.self); return *this; } - + //! @brief 參照 FPD_Harris& referenceFrom(FPD_Harris const& fps) { self().referenceFrom(fps.self); return *this; } - + //! @brief K double paramK() const { return self->ratioK_; } - + //! @brief R double paramR() const { return self->thresholdR_; } - + //! @brief W double paramW() const { return self->sizeW_; } - + //! @brief N double paramN() const { return self->noiseN_; } - + //! @brief G double paramG() const { return self->featureG_; } - + //! @brief L double paramL() const { return self->lightL_; } - + //! @brief bound size_t paramB() const { return self->boundB_; } - + //! @brief K double paramK(double k) { self()->ratioK_ = k; return paramK(); } - + //! @brief R double paramR(double r) { self()->thresholdR_ = r; return paramR(); } - + //! @brief W double paramW(double w) { self()->sizeW_ = w; return paramW(); } - + //! @brief N double paramN(double n){ self()->noiseN_ = n; return paramN(); } - + //! @brief L double paramL(double l) { self()->lightL_ = l; return paramL(); } - + //! @brief G double paramG(double g) { self()->featureG_ = g; return paramG(); } - + //! @brief B size_t paramB(size_t b) { self()->boundB_ = b; return paramB(); } - + /*! @brief 找出特徵點 * * @param [in] bmp 要抓特徵點的點陣圖 @@ -167,11 +167,11 @@ public: */ MyFeaturePoints detect(Bitmap<Pixel> const& bmp) const { Bitmap<Pixel> input = bmp; - + // gradiance Bitmap<Pixel> input_gx(input.gradianceX(0, self->noiseN_)); Bitmap<Pixel> input_gy(input.gradianceY(self->noiseN_, 0)); - + // get Matrix I for each pixel Bitmap<double> Ixx(input.height(), input.width(), 0.0); Bitmap<double> Iyy(input.height(), input.width(), 0.0); @@ -185,12 +185,12 @@ public: Ixy.pixel(y, x, gx * gy); } } - + // blur Ixx.gaussianed(self->sizeW_, self->sizeW_); Iyy.gaussianed(self->sizeW_, self->sizeW_); Ixy.gaussianed(self->sizeW_, self->sizeW_); - + // filter too flat or on edge Bitmap<double> R(input.height(), input.width(), 0.0); Bitmap<bool> good(input.height(), input.width(), false); @@ -204,7 +204,7 @@ public: good.pixel(y, x, (r >= self->thresholdR_)); } } - + // find union neighbor DisjointSet dsj(input.size()); ssize_t dy[2] = {0, 1}; @@ -234,7 +234,7 @@ public: max_i[ri] = i; } } - + // blur before get description input.gaussianed(self->featureG_, self->featureG_); @@ -280,17 +280,17 @@ public: } return ret; } - + //! @brief same as \c copyFrom(fps) FPD_Harris& operator=(FPD_Harris const& fps) { return copyFrom(fps); } - + //! @brief same as \c detect(bmp) MyFeaturePoints operator()(Bitmap<Pixel> const& bmp) const { return detect(bmp); } - + /*! @brief 寫到檔案裡 * * 未完成 @@ -299,7 +299,7 @@ public: // TODO return false; } - + /*! @brief 將資料讀入 * * 未完成 @@ -308,7 +308,7 @@ public: // TODO return false; } - + /*! @brief new一個自己 * * @return 一個new出來的FeaturePointsDetector_Harris<Pixel> @@ -316,7 +316,7 @@ public: ObjBase* create() const { return (ObjBase*)new FPD_Harris<Pixel>(); } - + /*! @brief 複製資料 * * 輸入型別是 \c ObjBase \c const* @@ -329,7 +329,7 @@ public: ObjBase* copyFrom(ObjBase const* b) { return &(copyFrom(*(FPD_Harris const*)b)); } - + /*! @brief 回傳class的type * * @return \c char \c const\c * 形式的typename @@ -337,7 +337,7 @@ public: char const* ctype() const { return typeid(*this).name(); } - + /*! @brief 回傳class的type * * @return \c std::string 形式的typename diff --git a/meowpp/gra/FeaturePointsMatch.h b/meowpp/gra/FeaturePointsMatch.h index ffdbe53..f9637ac 100644 --- a/meowpp/gra/FeaturePointsMatch.h +++ b/meowpp/gra/FeaturePointsMatch.h @@ -36,7 +36,7 @@ public: virtual FeaturePointIndexPairs match(size_t dimension, FeaturePointss const& from, FeaturePointss const& to) const = 0; - + virtual FeaturePointIndexPairs match(size_t dimension, FeaturePointss const& fpss) const = 0; }; diff --git a/meowpp/gra/FeaturePointsMatch_K_Match.h b/meowpp/gra/FeaturePointsMatch_K_Match.h index f1fff12..ff59562 100644 --- a/meowpp/gra/FeaturePointsMatch_K_Match.h +++ b/meowpp/gra/FeaturePointsMatch_K_Match.h @@ -45,7 +45,7 @@ private: return (*ptr_)[id_][index_][id]; } }; - + struct Myself { size_t k_; Myself() { @@ -147,7 +147,7 @@ public: } return ret; } - + FPMKM& operator=(FPMKM const& b) { return copyFrom(b); } diff --git a/meowpp/gra/Photo.h b/meowpp/gra/Photo.h index 1837727..78063ec 100644 --- a/meowpp/gra/Photo.h +++ b/meowpp/gra/Photo.h @@ -21,10 +21,10 @@ namespace meow { /*! - * @brief 底片 - * + * @brief 底片 + * * 基本上就是一個 \c Bitmap 加上 \c focal - * + * * @author cat_leopard */ template<class Pixel> @@ -34,16 +34,19 @@ private: Bitmap<Pixel> bmp_; Vector2D<double> c_; PhotoProjection<double> proj_; + Myself(): proj_(3) { } + Myself(Myself const& b): bmp_(b.bmp_), c_(b.c_), proj_(b.proj_) { } + ~Myself() { } }; - + Self<Myself> const self; - + /*! * @brief 取得bitmap座標 */ @@ -53,51 +56,51 @@ private: public: /*! * @brief constructor - * + * * focal 預設為 1 */ Photo(): self() { self()->proj_.focal(1.0); } - + /*! * @brief constructor - * + * * 複製資料 - * + * * @param [in] b 資料來源 */ Photo(Photo const& b): self(b.self, Self<Myself>::COPY_FROM) { } - + /*! * @brief constructor - * + * * 直接給定圖片, 焦距用猜的 - * + * * @param [in] bmp 給定的圖片 */ Photo(Bitmap<Pixel> const& bmp): self() { reset(bmp); } - + /*! * @brief constructor - * + * * 直接給定圖片與焦距 - * + * * @param [in] bmp 給定的圖片 * @param [in] f 給定的焦距 */ Photo(Bitmap<Pixel> const& bmp, double f): self() { reset(bmp, f); } - + /*! * @brief constructor - * + * * 直接給定圖片, 焦距與中心點位置 - * + * * @param [in] bmp 給定的圖片 * @param [in] f 給定的焦距 * @param [in] c 中心點作標 @@ -105,38 +108,38 @@ public: Photo(Bitmap<Pixel> const& bmp, double f, Vector2D<double> const& c): self() { reset(bmp, f, c); } - + /*! * @brief destructor */ ~Photo() { } - + /*! * @brief 複製資料 - * + * * @param [in] b 資料來源 */ Photo& copyFrom(Photo const& b) { self().copyFrom(b.self); return *this; } - + /*! * @brief 參照 - * + * * @param [in] b 參照來源 */ Photo& referneceFrom(Photo const& b) { self().referenceFrom(b.self); return *this; } - + /*! * @brief 重設bitmap, focal 用猜的 - * + * * focal直接代對角線, center代bitmap中心點 - * + * * @param [in] bmp 新的 \c bitmap */ void reset(Bitmap<Pixel> const& bmp) { @@ -144,7 +147,7 @@ public: focal(sqrt(squ(width()) + squ(height()))); center(Vector2D<double>(bmp.width() / 2, bmp.height() / 2)); } - + /*! * @brief 重設bitmap, focal * @@ -158,10 +161,10 @@ public: focal(f); center(Vector2D<double>(bmp.width() / 2, bmp.height() / 2)); } - + /*! * @brief 重設bitmap, focal, center - * + * * @param [in] bmp 新的 \c bitmap * @param [in] f 新的 \c focal * @param [in] c 新的中心點作標 @@ -171,24 +174,24 @@ public: focal(f); center(c); } - + /*! * @brief 回傳\c bitmap */ Bitmap<Pixel> const& bitmap() const { return self->bmp_; } - + /*! * @brief 回傳\c bitmap 的參照(非constant) */ Bitmap<Pixel>& bitmapGet() { return self()->bmp_; } - + /*! * @brief 設定bitmap - * + * * @param [in] bmp 新的 bitmap * @return 新的 \c bitmap */ @@ -196,17 +199,17 @@ public: self()->bmp_.copyFrom(bmp); return bitmap(); } - + /*! * @brief 回傳focal length */ double focal() const { return self->proj_.focal(); } - + /*! * @brief 設定 focal length - * + * * @param [in] f 新的 focal length * @return 新的 \c focal length */ @@ -214,14 +217,14 @@ public: self()->proj_.focal(f); return focal(); } - + /*! * @brief 回傳相應的 photo projection */ PhotoProjection<double> projection() const { return self->proj_; } - + /*! * @brief 設定 photo projection */ @@ -231,7 +234,7 @@ public: } return projection(); } - + /*! * @brief 取得照片中心點底片座標 * @@ -240,7 +243,7 @@ public: Vector2D<double> const& center() const { return self->c_; } - + /*! * @brief 取得照片中心點底片座標 (non-constant reference) * @@ -249,7 +252,7 @@ public: Vector2D<double>& centerGet() { return self()->c_; } - + /*! * @brief 設定照片中心點底片座標 * @@ -261,28 +264,28 @@ public: self()->c_ = c; return center(); } - + /*! * @brief 回傳bitmap寬 */ size_t width() const { return self->bmp_.width(); } - + /*! * @brief 回傳bitmap高 */ size_t height() const { return self->bmp_.height(); } - + /*! * @brief 回傳bitmap的某pixel */ Pixel pixel(size_t y, size_t x) const { return self->bmp_.pixel(y, x); } - + /*! * @brief 設定某pixel */ @@ -290,12 +293,12 @@ public: self()->bmp_.pixel(y, x, p); return pixel(y, x); } - + /*! * @brief 檢查某點是否在底片範圍內 * * @param [in] yx 底片座標 - * + * * @return \c true/false */ bool inside(Vector2D<double> const& yx) const { @@ -304,19 +307,19 @@ public: ssize_t w_max = (ssize_t)width () - 1; return (0 <= c.y() && c.y() <= h_max && 0 <= c.x() && c.x() <= w_max); } - + /*! * @brief 檢查某點是否在底片範圍內 * * @param [in] p 大地座標 - * + * * @return \c true/false */ bool inside(Vector3D<double> const& p) const { if (p.z() > 0) return false; return inside(Vector2D<double>(self->proj_.transformate(p.matrix()))); } - + /*! * @brief 取得給照片座標中某點的色彩 * @@ -342,7 +345,7 @@ public: } return sum; } - + /*! * @brief 取得給照片座標中某點的色彩 * @@ -354,14 +357,14 @@ public: Pixel color(Vector3D<double> const& p) const { return color(Vector2D<double>(self->proj_.transformate(p.matrix()))); } - + /*! * @brief same as \c .copyFrom(b) */ Photo& operator=(Photo const& b) { return copyFrom(b); } - + /*! @brief 將資料寫入檔案 * * @note 未完成 @@ -380,7 +383,7 @@ public: } return true; } - + /*! @brief 將資料讀入 * * @note 未完成 @@ -407,7 +410,7 @@ public: ObjBase* create() const { return new Photo(); } - + /*! @brief 複製資料 * * 輸入型別是 \c ObjBase \c const* @@ -420,7 +423,7 @@ public: ObjBase* copyFrom(ObjBase const* b) { return &(copyFrom(*(Photo*)b)); } - + /*! @brief 回傳class的type * * @return \c char \c const\c * 形式的typename @@ -428,7 +431,7 @@ public: char const* ctype() const{ return typeid(*this).name(); } - + /*! @brief 回傳class的type * * @return \c std::string 形式的typename @@ -437,7 +440,7 @@ public: return std::string(ctype()); } }; - + } // meow #endif // gra_Photo_H__ diff --git a/meowpp/gra/ViewPort.h b/meowpp/gra/ViewPort.h index c8ac734..16d8ae1 100644 --- a/meowpp/gra/ViewPort.h +++ b/meowpp/gra/ViewPort.h @@ -9,7 +9,7 @@ namespace meow { * @brief 未完待續 */ class ViewPort: public ObjBase { - + }; diff --git a/meowpp/gra/WatchBall.h b/meowpp/gra/WatchBall.h index f3d2044..8bccf7f 100644 --- a/meowpp/gra/WatchBall.h +++ b/meowpp/gra/WatchBall.h @@ -45,19 +45,19 @@ public: */ WatchBall(): self() { } - + /*! * @brief copy constructor */ WatchBall(WatchBall const& b): self(b.self, Self<Myself>::COPY_FROM) { } - + /*! * @brief destructor */ ~WatchBall() { } - + /*! * @brief copy data */ @@ -65,7 +65,7 @@ public: self().copyFrom(b.self); return *this; } - + /*! * @brief reference */ @@ -73,28 +73,28 @@ public: self().referenceFrom(b.self); return *this; } - + /*! * @brief 取得有幾個camera */ size_t cameraSize() const { return self->cameras_.size(); } - + /*! * @brief 取得 cameras */ Cameras const& cameras() const { return self->cameras_; } - + /*! * @brief 取得 cameras (non-constant) */ Cameras& camerasGet() { return self()->cameras_; } - + /*! * @brief 設定 camera */ @@ -102,21 +102,21 @@ public: self()->cameras_ = c; return cameras(); } - + /*! * @brief 取得第i個camera */ Camera<Pixel> const& camera(size_t i) const { return cameras()[i]; } - + /*! * @brief 取得第i個camera (non-constant reference) */ Camera<Pixel>& camera(size_t i) { return cameras()[i]; } - + /*! * @brief 設定第i個camera */ @@ -124,21 +124,21 @@ public: cameras()[i] = c; return camera(i); } - + /*! * @brief 取得offset */ Vector3D<double> const& offset() const { return self->offset_; } - + /*! * @brief 取得offset (non-constant reference) */ Vector3D<double>& offset() { return self()->offset_; } - + /*! * @brief 設定offset */ @@ -146,7 +146,7 @@ public: self()->offset_ = ofs; return offset(); } - + /*! * @brief 取得底片color */ @@ -162,7 +162,7 @@ public: } return (ct > 0 ? sum / ct : sum); } - + /*! * @brief 輸出展開圖 * @@ -186,14 +186,14 @@ public: } return ret; } - + /*! * @brief same as \c copyFrom(b) */ WatchBall& operator=(WatchBall const& b) { return copyFrom(b); } - + /*! @brief 將資料寫入檔案 * * @note 未完成 @@ -201,7 +201,7 @@ public: bool write(FILE* f, bool bin, unsigned int fg) const { return false; } - + /*! @brief 將資料讀入 * * @note 未完成 @@ -217,7 +217,7 @@ public: ObjBase* create() const { return new WatchBall(); } - + /*! * @brief 複製資料 * @@ -230,7 +230,7 @@ public: ObjBase* copyFrom(ObjBase const* b) { return &(copyFrom(*(WatchBall*)b)); } - + /*! @brief 回傳class的type * * @return \c char \c const\c * 形式的typename @@ -239,7 +239,7 @@ public: static char const* ptr = typeid(*this).name(); return ptr; } - + /*! @brief 回傳class的type * * @return \c std::string 形式的typename diff --git a/meowpp/math/!readme.asciidoc b/meowpp/math/!readme.asciidoc index 5ae6b89..062b45d 100644 --- a/meowpp/math/!readme.asciidoc +++ b/meowpp/math/!readme.asciidoc @@ -33,7 +33,7 @@ ===== Transformation.h -各種轉換的 Base Class, 這裡所謂的 *Transformation* 形式上不一定要是 Linear, +各種轉換的 Base Class, 這裡所謂的 *Transformation* 形式上不一定要是 Linear, 但原則上都是 *input a vector, output a vector* 其中input/output的dimension可以 不同. diff --git a/meowpp/math/LinearTransformation.h b/meowpp/math/LinearTransformation.h index f51630e..0dc3735 100644 --- a/meowpp/math/LinearTransformation.h +++ b/meowpp/math/LinearTransformation.h @@ -47,7 +47,7 @@ protected: Transformation<Scalar>(b), matrix_(b.matrix_) { } - + /*! * @brief Copy settings, matrix from another LinearTransformation * @@ -58,7 +58,7 @@ protected: matrix_.copyFrom(b.matrix_); return *this; } - + /*! * @brief Reference settings, matrix from another LinearTransformation * @@ -69,7 +69,7 @@ protected: matrix_.referenceFrom(b.matrix_); return *this; } - + /*! * @brief setup the matrix */ @@ -77,14 +77,14 @@ protected: matrix_.copyFrom(m); return matrix(); } - + public: /*! * Destructor */ virtual ~LinearTransformation() { } - + /*! * @brief Return the matrix form of this transformation * @@ -93,7 +93,7 @@ public: virtual Matrix<Scalar> const& matrix() const { return matrix_; } - + /*! * @brief Return the inverse of the matrix form of this transformate * diff --git a/meowpp/math/LinearTransformations.h b/meowpp/math/LinearTransformations.h index e882a6c..4bf9a36 100644 --- a/meowpp/math/LinearTransformations.h +++ b/meowpp/math/LinearTransformations.h @@ -22,19 +22,19 @@ private: struct Myself { Vector3D<Scalar> theta_; bool need_; - + Myself(): theta_(0, 0, 0), need_(true) { } - + Myself(Myself const& b): theta_(b.theta_), need_(b.need_) { } - + ~Myself() { } }; - + Self<Myself> const self; - + void calcMatrix() const { if (self->need_) { Matrix<Scalar> tmp(3, 3, 0.0); @@ -61,27 +61,27 @@ private: self()->need_ = false; } } - + public: /*! * Constructor with no rotation */ Rotation3D(): LinearTransformation<Scalar>(3u, 3u, 3u), self() { } - + /*! * Constructor and copy data */ Rotation3D(Rotation3D const& b): LinearTransformation<Scalar>(b), self(b.self, Self<Myself>::COPY_FROM) { } - + /*! * Destructor */ ~Rotation3D() { } - + /*! * @brief Copy data * @@ -93,7 +93,7 @@ public: self().copyFrom(b.self); return *this; } - + /*! * @brief Reference data * @@ -119,7 +119,7 @@ public: Scalar parameter(size_t i, Scalar const& s) { return theta(i, s); } - + /*! * @brief Get the \c i -th theta * @@ -131,7 +131,7 @@ public: Scalar const& theta(size_t i) const { return self->theta_(i); } - + /*! * @brief Set the \c i -th theta * @@ -163,7 +163,7 @@ public: theta(i, n(i) * angle); } } - + /*! * @brief Concat another rotation transformation * @param [in] r another rotation transformation @@ -174,10 +174,10 @@ public: } return *this; } - + /*! * @brief Do the transformate - + * Assume: * - The input vector is \f$ (x ,y ,z ) \f$ * - The output vector is \f$ (x',y',z') \f$ @@ -214,7 +214,7 @@ public: calcMatrix(); return LinearTransformation<Scalar>::matrix() * x; } - + /*! * @brief Return the jacobian matrix (derivate by the input vector) * of this transformate @@ -244,7 +244,7 @@ public: calcMatrix(); return LinearTransformation<Scalar>::matrix(); } - + /*! * @brief Return the jacobian matrix of this transformate * @@ -344,7 +344,7 @@ public: Matrix<Scalar> transformateInv(Matrix<Scalar> const& x) const { return matrixInv() * x; } - + /*! * @brief Return the jacobian matrix of the inverse form of this transformate * @@ -354,7 +354,7 @@ public: Matrix<Scalar> jacobianInv(Matrix<Scalar> const& x) const { return matrixInv(); } - + /*! * @brief Return the jacobian matrix of the inverse form of this transformate * @@ -392,13 +392,13 @@ public: calcMatrix(); return LinearTransformation<Scalar>::matrix().transpose(); } - + //! @brief same as \c copyFrom(b) Rotation3D& operator=(Rotation3D const& b) { return copyFrom(b); } }; -} +} // meow #endif // math_LinearTransformations_H__ diff --git a/meowpp/math/Matrix.h b/meowpp/math/Matrix.h index 09832d8..94f23a3 100644 --- a/meowpp/math/Matrix.h +++ b/meowpp/math/Matrix.h @@ -28,12 +28,15 @@ private: Myself(): rows_(0), cols_(0), entries_(0) { } + Myself(Myself const& b): rows_(b.rows_), cols_(b.cols_), entries_(b.entries_) { } + Myself(size_t r, size_t c, Entry const& e): rows_(r), cols_(c), entries_(r * c, e) { } + ~Myself() { } @@ -199,7 +202,7 @@ public: self()->entries_[self->index(r, c)] = e; return entry(r, c); } - + //! @brief Get the entry at \a r x \a c EntryRef entryGet(size_t r, size_t c) { return self()->entries_[self->index(r, c)]; @@ -351,7 +354,7 @@ public: entry(r, c, (r == c ? Entry(1) : Entry(0))); return *this; } - + /*! * @brief Let itself be an diagonal form of original itself */ @@ -364,7 +367,7 @@ public: } return *this; } - + /*! * @brief Return a matrix which is a diangonal form of me */ diff --git a/meowpp/math/Transformation.h b/meowpp/math/Transformation.h index 011db8c..086cb03 100644 --- a/meowpp/math/Transformation.h +++ b/meowpp/math/Transformation.h @@ -27,17 +27,17 @@ private: size_t outputCols_; size_t psize_; - Myself() { - } Myself(Myself const& b): inputRows_(b.inputRows_), inputCols_(b.inputCols_), outputRows_(b.outputRows_), outputCols_(b.outputCols_), psize_(b.psize_) { } + Myself(size_t ir, size_t ic, size_t or_, size_t oc, size_t ps): inputRows_(ir), inputCols_(ic), outputRows_(or_), outputCols_(oc), psize_(ps) { } + ~Myself() { } }; diff --git a/meowpp/math/Transformations.h b/meowpp/math/Transformations.h index b9583f9..99d6483 100644 --- a/meowpp/math/Transformations.h +++ b/meowpp/math/Transformations.h @@ -55,12 +55,14 @@ private: Myself(size_t d): dimension_(1), radius_(1) { } + Myself(size_t d, Scalar const& r): dimension_(d), radius_(r) { } + Myself(Myself const& m): dimension_(m.dimension_), radius_(m.radius_) { } }; - + Self<Myself> const self; public: /*! @@ -70,7 +72,7 @@ public: BallProjection(BallProjection const& b): Transformation<Scalar>(b), self(b.self, Self<Myself>::COPY_FROM) { } - + /*! * Constructor and setup, radius = 1 * @param [in] d Dimension of the input/output vector @@ -79,7 +81,7 @@ public: self(Myself(d)) { radius(1); } - + /*! * Constructor and setup * @param [in] d Dimension of the input/output vector @@ -89,7 +91,7 @@ public: self(Myself(d, r)) { radius(r); } - + /*! * @brief Copy settings from another one * @param [in] b Another one @@ -100,7 +102,7 @@ public: copyFrom(b); return *this; } - + /*! * @brief Reference settings from another one * @param [in] b Another one @@ -132,7 +134,7 @@ public: Scalar radius() const { return self->radius_; } - + /*! * @brief Setup the radius * @@ -143,7 +145,7 @@ public: self()->radius_ = r; return radius(); } - + /*! * @brief Get the dimension of this projection */ @@ -151,7 +153,7 @@ public: return self->dimension_; } - + /*! * @brief Project the input vector(s) onto the hyper-sphere and return it. * @@ -159,7 +161,7 @@ public: * method will think that you want to transform multiple vector once * and the number of columns of the output matrix will be the same of * the number of columns of the input one. - * + * * @param [in] x The input matrix. * @return The output matrix. * @note Take into account that too much safty checking will lead to @@ -181,7 +183,7 @@ public: } return ret; } - + /*! * @brief Return the jacobian matrix (derivate by the input vector) * of this projection. @@ -226,7 +228,7 @@ public: } return ret; } - + /*! * @brief Return the jacobian matrix (derivate by radius) of this projection. * @@ -263,14 +265,14 @@ public: } return ret / Scalar(sqrt(double(sum))); } - + /*! * @brief Same as \c copyFrom(b) */ BallProjection& operator=(BallProjection const& b) { return copyFrom(b); } - + /*! * @brief Same as \c transformate(v) */ @@ -325,30 +327,30 @@ private: struct Myself { Scalar focal_; size_t dimension_; - + Myself() { } - + Myself(size_t d, Scalar f): focal_(f), dimension_(d) { } - + Myself(Myself const& b): focal_(b.focal_), dimension_(b.dimension_) { } - + ~Myself() { } }; - + Self<Myself> const self; public: /*! * Constructor, focal = 1 */ - PhotoProjection(size_t dimension): + PhotoProjection(size_t dimension): Transformation<Scalar>(dimension, 1, dimension, 1, 1), self(Myself(dimension, 1)) { } - + /*! * Constructor */ @@ -356,14 +358,14 @@ public: Transformation<Scalar>(dimension, 1, dimension, 1, 1), self(Myself(dimension, f)) { } - + /*! * Constructor, copy settings from another PhotoProjection. */ PhotoProjection(PhotoProjection const& p): Transformation<Scalar>(p), self(p.self, Self<Myself>::COPY_FROM) { } - + /*! * Copy settings from another one * @param [in] b another one @@ -374,7 +376,7 @@ public: self().copyFrom(b.self); return *this; } - + /*! * Reference settings from another one * @param [in] b another one @@ -418,7 +420,7 @@ public: self()->focal_ = f; return focal(); } - + /*! * @brief Get the dimension of this projection */ @@ -429,13 +431,13 @@ public: /*! * @brief Project the input vector(s) onto the plane * - * The equation of the plane is \f$ x_N = -f \f$, where the \f$ N \f$ + * The equation of the plane is \f$ x_N = -f \f$, where the \f$ N \f$ * is the dimension of this projection and f is the focal length. \n * If the number of columns of the input matrix is larger than 1, this * method will think that you want to transform multiple vector once * and the number of columns of the output matrix will be the same of * the number of columns of the input one. - * + * * @param [in] x The input matrix. * @return The output matrix. * @note Take into account that too much safty checking will lead to @@ -452,9 +454,9 @@ public: } return ret; } - + /*! - * @brief Return the jacobian matrix (derivate by the input vector) + * @brief Return the jacobian matrix (derivate by the input vector) * of this projection. * * This method only allow a vector-like matrix be input. @@ -490,7 +492,7 @@ public: } return ret; } - + /*! * @brief Return the jacobian matrix (derivate by the focus length) * of this projection. @@ -527,14 +529,14 @@ public: } return ret; } - + /*! * @brief Same as \c copyFrom(b) */ PhotoProjection& operator=(PhotoProjection const& b) { return copyFrom(b); } - + /*! * @brief Same as \c transformate(v) */ @@ -543,6 +545,6 @@ public: } }; -} +} // meow #endif // Transformations_H__ diff --git a/meowpp/math/Vector.h b/meowpp/math/Vector.h index caa64fd..4dd95a5 100644 --- a/meowpp/math/Vector.h +++ b/meowpp/math/Vector.h @@ -92,7 +92,7 @@ public: } //! @brief Return a \a dimension x 1 matrix form of it - Matrix<Scalar> const& matrix() const { + Matrix<Scalar> matrix() const { return matrix_; } @@ -121,35 +121,35 @@ public: return (dimension() > 0); } - //! @brief return \a i -th entry - Scalar entry(size_t i) const { + //! @brief return \a i -th scalar + Scalar scalar(size_t i) const { return matrix_.entry(i, 0); } /*! - * @brief change \a i -th entry + * @brief change \a i -th scalar * * @param [in] i i-th * @param [in] s new value */ - Scalar entry(size_t i, Scalar const& s) { + Scalar scalar(size_t i, Scalar const& s) { matrix_.entry(i, 0, s); return entry(i); } - - //! @brief return \a i -th entry with non-constant type - ScalarRef entryGet(size_t i) { + + //! @brief return \a i -th scalar with non-constant type + ScalarRef scalarGet(size_t i) { return matrix_.entryGet(i); } /*! - * @brief change \a i -th to \a j -th entries + * @brief change \a i -th to \a j -th scalars * * @param [in] i i-th * @param [in] j j-th * @param [in] s new value */ - void entries(size_t i, size_t j, Scalar const& s) { + void scalars(size_t i, size_t j, Scalar const& s) { for (size_t it = i; it <= j; ++it) { matrix_.entry(it, 0, s); } diff --git a/meowpp/math/methods.h b/meowpp/math/methods.h index 5b67594..c10a7d8 100644 --- a/meowpp/math/methods.h +++ b/meowpp/math/methods.h @@ -42,7 +42,7 @@ namespace meow { * * So in this function we choose * \f$ M = \lceil \frac{\log(1 - P)}{\log(1 - p_0^N)} \rceil \f$ - * + * * @param [in] data The whole data sett * @param [in] w Weight function to give a floating number for a given * parameters which means how best this solution is. Negitave @@ -93,7 +93,7 @@ inline std::vector<Data> ransac(std::vector<Data> const& data, /* - * @brief Run the \b Levenberg-Marquardt method to solve a non-linear + * @brief Run the \b Levenberg-Marquardt method to solve a non-linear * least squares problem. * * Assume: diff --git a/meowpp/oo/ObjArray.h b/meowpp/oo/ObjArray.h index b58b89c..804f65f 100644 --- a/meowpp/oo/ObjArray.h +++ b/meowpp/oo/ObjArray.h @@ -24,30 +24,31 @@ class ObjArray: public ObjBase { private: struct Myself { std::vector<T> array_; + Myself() { } - ~Myself() { + + Myself(Myself const& b): array_(b.array_) { } - Myself& copyFrom(Myself const& b) { - array_ = b.array_; - return *this; + + Myself(size_t sz, T const& e): array_(sz, e) { + } + + ~Myself() { } }; Self<Myself> const self; public: - ObjArray(): self(true) { + ObjArray(): self() { } - ObjArray(ObjArray const& a): self(false) { - self().copyFrom(a.self); + ObjArray(ObjArray const& a): self(a.self, Self<Myself>::COPY_FROM) { } - ObjArray(std::vector<T> const& a): self(true) { - self()->array_ = a; + ObjArray(std::vector<T> const& a): self(a) { } - ObjArray(size_t sz, T const& e): self(true) { - self()->array_.resize(sz, e); + ObjArray(size_t sz, T const& e): self(Myself(sz, e)) { } ~ObjArray() { @@ -84,15 +85,16 @@ public: self()->array_.clear(); } - T const& entry(size_t i) const { + T entry(size_t i) const { return self->array_[i]; } - T const& entry(size_t i, T const& e) { + + T entry(size_t i, T const& e) { self()->array_[i] = e; return entry(i); } - T const& putBack(T const& e) { + T putBack(T const& e) { self()->array_.push_back(e); return entry(size() - 1); } @@ -107,11 +109,11 @@ public: return copyFrom(a); } - T const& operator[](size_t i) const { + T operator[](size_t i) const { return self->array_[i]; } - T& operator[](size_t i) { + std::vector<T>::reference operator[](size_t i) { return self()->array_[i]; } @@ -135,7 +137,7 @@ public: if (fread(&sz, sizeof(size_t), 1, f) < 1) return false; } else { - if (fscanf(f, "%lu\n", &sz) < 0) return false; + if (fscanf(f, "%lu\n", &sz) < 1) return false; } size(sz); for (size_t i = 0; i < sz; i++) { @@ -149,7 +151,7 @@ public: } ObjBase* copyFrom(ObjBase const* b) { - return &(copyFrom(*b)); + return &(copyFrom(*(ObjArray const*)b)); } char const* ctype() const { @@ -161,6 +163,6 @@ public: } }; -} +} // meow #endif // oo_ObjArray_H__ diff --git a/meowpp/oo/ObjBase.h b/meowpp/oo/ObjBase.h index 0ae9427..253afb6 100644 --- a/meowpp/oo/ObjBase.h +++ b/meowpp/oo/ObjBase.h @@ -14,10 +14,14 @@ namespace meow { */ class ObjBase { protected: - ObjBase(){ } + + /*! + * @brief Constructor with doing nothing + */ + ObjBase() { } public: - virtual ~ObjBase(){ } - + virtual ~ObjBase() { } + /*! * @brief 將物件寫入檔案, 預設implement為直接回傳 \c false * @@ -29,7 +33,7 @@ public: virtual bool write(FILE* f, bool bin, unsigned int fg) const { return false; } - + /*! * @brief 將物件從檔案讀出, 預設implement為直接回傳 \c false * @@ -41,14 +45,14 @@ public: virtual bool read(FILE* f, bool bin, unsigned int fg) { return false; } - + /*! * @brief 回傳一個new出來的物件, 預設implement為直接回傳 \c NULL */ virtual ObjBase* create() const { return NULL; } - + /*! * @brief 複製, 預設使用operator= * @@ -59,29 +63,28 @@ public: (*this) = (*b); return this; } - + /*! * @brief 用C-style string回傳這個class的type name */ virtual char const* ctype() const { return typeid(*this).name(); } - + /*! * @brief 用std::string回傳這個class的type name */ virtual std::string type() const { - static std::string s(ctype()); - return s; + return std::string(ctype()); } - + /*! * @brief 用C-style string回傳base的type name */ static char const* ctypeBase() { return typeid(ObjBase).name(); } - + /*! * @brief 用std::string回傳base的type name */ diff --git a/meowpp/oo/ObjDictionary.h b/meowpp/oo/ObjDictionary.h index 39e103e..f43be58 100644 --- a/meowpp/oo/ObjDictionary.h +++ b/meowpp/oo/ObjDictionary.h @@ -24,26 +24,27 @@ class ObjDictionary: public ObjBase { private: struct Myself { std::map<Key, Value> dictionary_; + Myself() { } - ~Myself() { + + Myself(Myself const& b): dictionary_(b.dictionary_) { } - Myself& copyFrom(Myself const& b) { - dictionary_ = b.dictionary_; - return *this; + + ~Myself() { } }; + Self<Myself> const self; public: - ObjDictionary(): self(true) { + ObjDictionary(): self() { } - ObjDictionary(ObjDictionary const& d): self(false) { + ObjDictionary(ObjDictionary const& d): self(d.self, Self<Myself>::COPY_FROM) { self.copyFrom(b.self); } - ObjDictionary(std::map<Key, Value> const& d): self(true) { - self()->dictionary_ = d; + ObjDictionary(std::map<Key, Value> const& d): self(Myself(d)) { } ~ObjDictionary() { @@ -62,6 +63,7 @@ public: size_t size() const { return self->dictionary_.size(); } + bool empty() const { return self->dictionary_.empty(); } @@ -70,8 +72,16 @@ public: self()->dictionary_.clear(); } + std::map<Key, Value>::const_iterator first() const { + return self()->dictionary_.begin(); + } + + std::map<Key, Value>::iterator first() { + return self()->dictionary_.begin(); + } + std::map<Key, Value>::const_iterator end() const { - return self->dictionary_.end(); + return self()->dictionary_.end(); // OAO!!! } std::map<Key, Value>::iterator end() { @@ -79,7 +89,7 @@ public: } std::map<Key, Value>::const_iterator find(Key const& k) const { - return self->dictionary_.find(k); + return self()->dictionary_.find(k); // OAO!!! } std::map<Key, Value>::iterator find(Key const& k) { @@ -97,8 +107,8 @@ public: ObjDictionary& operator=(ObjDictionary const& a) { return copyFrom(a); } - - Value& operator[](Key const& k) { + + Value operator[](Key const& k) { return self()->dictionary_[k]; } @@ -110,8 +120,7 @@ public: else { if (fprintf(f, "%lu\n", sz) < 1) return false; } - for (std::map<Key, Value>::const_iterator - it = self->dictionary_.begin(); it != self->dictionary_.end(); ++it) { + for (std::map<Key, Value>::const_iterator it = begin(); it != end(); ++it) { if (it->first .write(f, bin, fg) == false) return false; if (it->second.write(f, bin, fg) == false) return false; } @@ -135,19 +144,19 @@ public: } return true; } - + ObjBase* create() const { return new ObjDictionary(); } - + ObjBase* copyFrom(ObjBase const* b) { - return &(copyFrom(*(ObjDictionary*)b)); + return &(copyFrom(*(ObjDictionary const*)b)); } - + char const* ctype() const { return typeid(*this).name(); } - + std::string type() const { return std::string(ctype()); } diff --git a/meowpp/oo/ObjProperties.h b/meowpp/oo/ObjProperties.h index 1d1ac64..01e01d0 100644 --- a/meowpp/oo/ObjProperties.h +++ b/meowpp/oo/ObjProperties.h @@ -14,9 +14,9 @@ class ObjProperties: public ObjBase { private: public: ObjProperties(); - + ObjProperties(ObjProperties const& p); - + virtual ~ObjProperties(); size_t propertySize() const; @@ -26,27 +26,27 @@ public: void propertyClear(); ObjBase const* property(std::string name) const; - + ObjBase* property(std::string name); bool propertyAdd(std::string name, ObjBase* obj, bool autoRemove); - + bool propertyDel(std::string name); - + ObjProperties& properties() const; - + ObjProperties& properties(ObjProperties const& p); - + bool write(FILE* f, bool bin, unsigned int fg) const; - + bool read(FILE* f, bool bin, unsigned int fg); - + ObjBase* create() const; - + ObjBase* copyFrom(ObjBase const* b); - + char const* ctype() const; - + std::string type() const; }; diff --git a/meowpp/oo/ObjSelector.h b/meowpp/oo/ObjSelector.h index 58d86a0..f08cfe4 100644 --- a/meowpp/oo/ObjSelector.h +++ b/meowpp/oo/ObjSelector.h @@ -25,7 +25,7 @@ private: ObjSelector* parent_; ObjBase const* pointer_; bool autoDelete_; - // + Info(ObjSelector* parent, ObjBase const* ptr, bool autoDelete) { @@ -33,6 +33,7 @@ private: pointer_ = ptr; autoDelete_ = autoDelete; } + ~Info() { if (autoDelete_) { delete pointer_; @@ -44,11 +45,11 @@ private: }; friend struct Info; - typedef typename std::map<std::string, Info*> Funcs; - typedef typename std::map<std::string, Info*>::iterator FuncsIterator; + typedef typename std::map<std::string, Info*> Infos; + typedef typename std::map<std::string, Info*>::iterator InfosIterator; - static Funcs& funcs() { - static Funcs f; + static Infos& funcs() { + static Infos f; return f; } static Info* add(std::string name, @@ -69,14 +70,14 @@ public: static void add(std::string name, ObjBase* obj, bool autoDelete) { add(name, NULL, obj, autoDelete); } - + /*! * @brief 新增(註冊) 一個Class (必須要繼承自 \c ObjBase) 並且默認type為name */ static void add(ObjBase* obj, bool autoDelete) { add(obj->type(), NULL, obj, autoDelete); } - + /*! * @brief 依照name刪除之前註冊過得Class */ @@ -86,7 +87,7 @@ public: funcs().erase(name); } } - + /*! * @brief 取得之前註冊過得Class */ @@ -94,7 +95,7 @@ public: if (funcs().find(name) == funcs().end()) return NULL; return funcs()[name]->pointer_; } - + /*! * @brief 回傳一個之前註冊過得Class new出來的實體 */ @@ -103,12 +104,12 @@ public: if(ptr == NULL) return NULL; return ptr->create(); } - + /*! * @brief 利用type檢查是否有註冊過同種類的Class */ static bool exist(ObjBase* obj) { - for (FuncsIterator it = funcs().begin(); it != funcs().end(); it++) { + for (InfosIterator it = funcs().begin(); it != funcs().end(); it++) { if (it->second->pointer_ == obj || (it->second->pointer_ != NULL && it->second->pointer_->type() == obj->type())) { @@ -117,12 +118,12 @@ public: } return false; } - + /*! * @brief 利用type尋找name */ static std::string name(ObjBase* obj) { - for (FuncsIterator it = funcs().begin(); it != funcs().end(); it++) { + for (InfosIterator it = funcs().begin(); it != funcs().end(); it++) { if (it->second->pointer_ == obj || (it->second->pointer_ != NULL && it->second->pointer_->type() == obj->type())) { @@ -131,17 +132,17 @@ public: } return std::string(); } - + /*! * @brief 回傳所有註冊過的name */ static std::vector<std::string> names() { std::vector<std::string> ret; - for (FuncsIterator it = funcs().begin(); it != funcs().end(); it++) + for (InfosIterator it = funcs().begin(); it != funcs().end(); it++) ret.push_back(it->first); return ret; } - + /*! * @brief 宣告一個ObjSelector實體, 並且註冊一個 ObjBase */ @@ -149,7 +150,7 @@ public: me_.first = name; me_.second = add(me_.first, this, obj, autoDelete); } - + /*! * @brief 宣告一個ObjSelector實體, 並且註冊一個 ObjBase */ @@ -157,14 +158,14 @@ public: me_.first = obj->type(); me_.second = add(me_.first, this, obj, autoDelete); } - + //! 解構子 ~ObjSelector() { if (me_.second != NULL) { del(me_.first); } } - + /*! * @brief 將一個物件寫到檔案裡(該物件必須要有註冊過) */ @@ -181,7 +182,7 @@ public: } return obj->write(f, binary, fg); } - + /*! * @brief 從檔案中讀取一個物件(該物件必須要有註冊過) */ @@ -208,6 +209,6 @@ public: static const size_t kGlobalSeletorID = 0; -} +} // meow #endif // oo_ObjSelector_H__ diff --git a/meowpp/oo/ObjTypes.h b/meowpp/oo/ObjTypes.h index 48a4a07..ba2d358 100644 --- a/meowpp/oo/ObjTypes.h +++ b/meowpp/oo/ObjTypes.h @@ -19,30 +19,30 @@ class ObjType: public ObjBase { private: struct Myself { Type data_; + Myself() { } + Myself(Type const& t): data_(t) { } + ~Myself() { } - Myself copyFrom(Myself const& b) { - data_ = b.data_; - } }; - Self<data_> const self; + Self<Type> const self; public: //! @brief constructor ObjType(): self() { } - + //! @brief constructor, 並且給值 ObyType(Type const& t): self(Myself(t)) { } - + //! @brief constructor, 並且copy資料 - ObjType(ObjType const& a): self(a.self, COPY_FROM) { + ObjType(ObjType const& a): self(a.self, Self<Type>::COPY_FROM) { } - + ~ObjType() { } @@ -55,11 +55,11 @@ public: self().referenceFrom(a.self); return *this; } - - Type const& access() const { + + Type access() const { return self->data_; } - + Type& modify() { return self()->data_; } @@ -67,11 +67,11 @@ public: ObjType& operator=(ObjType const& a) { return copyFrom(a); } - - Type const& operator()() const { + + Type operator()() const { return access(); } - + Type& operator()() { return modify(); } @@ -79,23 +79,23 @@ public: bool write(FILE* f, bool bin, unsigned int fg) const { return ReaderWriter::write(f, bin, fg, self->data_); } - + bool read(FILE* f, bool bin, unsigned int fg) { return ReaderWriter::read(f, bin, fg, &(self()->data_)); } - + ObjBase* create() const { return new ObjType(); } - + ObjBase* copyFrom(ObjBase const* b) { - return &(copyFrom(&(ObjType const*)b)); + return &(copyFrom(*(ObjType const*)b)); } - + char const* ctype() const { return typeid(*this).name(); } - + std::string type() const { return std::string(ctype()); } @@ -177,7 +177,7 @@ public: } static bool read(FILE* f, bool bin, unsigned int fg, std::string* k) { size_t len; - char buf[2048]; + char buf[81920]; if (bin) { if (fread(&len, sizeof(len) , 1, f) < 1) return false; if (fread( buf, sizeof(char), len, f) < len) return false; diff --git a/meowpp/utility.h b/meowpp/utility.h index 83c7554..02cf6a2 100644 --- a/meowpp/utility.h +++ b/meowpp/utility.h @@ -11,7 +11,8 @@ namespace meow { /*! - * @brief 有.from.first, .from.second, .to.first, .to.second + * @brief A structur with memember \c .from.first , \c .from.second , + * \c .to.first , \c .to.second * * @author cathook */ @@ -19,7 +20,7 @@ template<class F1, class F2 = F1, class T1 = F1, class T2 = T1> struct PairToPair { std::pair<F1, F2> from; std::pair<T1, T2> to; - + PairToPair() { } PairToPair(PairToPair const& pp): from(pp.from), to(pp.to) { |