aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/gra/Photo.h
diff options
context:
space:
mode:
Diffstat (limited to 'meowpp/gra/Photo.h')
-rw-r--r--meowpp/gra/Photo.h78
1 files changed, 57 insertions, 21 deletions
diff --git a/meowpp/gra/Photo.h b/meowpp/gra/Photo.h
index 15768aa..1837727 100644
--- a/meowpp/gra/Photo.h
+++ b/meowpp/gra/Photo.h
@@ -1,8 +1,11 @@
#ifndef gra_Photo_H__
#define gra_Photo_H__
+#include "Bitmap.h"
+
#include "../Self.h"
+#include "../geo/Vectors.h"
#include "../math/utility.h"
#include "../math/Matrix.h"
#include "../math/Transformations.h"
@@ -20,7 +23,7 @@ namespace meow {
/*!
* @brief 底片
*
- * 基本上就是一個 \c Photo 加上 \c focal
+ * 基本上就是一個 \c Bitmap 加上 \c focal
*
* @author cat_leopard
*/
@@ -33,13 +36,9 @@ private:
PhotoProjection<double> proj_;
Myself(): proj_(3) {
}
- ~Myself() {
+ Myself(Myself const& b): bmp_(b.bmp_), c_(b.c_), proj_(b.proj_) {
}
- Myself& copyFrom(Myself const& b) {
- bmp_ .copyFrom(b. bmp_);
- c_ .copyFrom(b. c_);
- proj_.copyFrom(b.proj_);
- return *this;
+ ~Myself() {
}
};
@@ -57,7 +56,7 @@ public:
*
* focal 預設為 1
*/
- Photo(): self(true) {
+ Photo(): self() {
self()->proj_.focal(1.0);
}
@@ -68,8 +67,7 @@ public:
*
* @param [in] b 資料來源
*/
- Photo(Photo const& b): self(false) {
- copyFrom(b);
+ Photo(Photo const& b): self(b.self, Self<Myself>::COPY_FROM) {
}
/*!
@@ -79,7 +77,7 @@ public:
*
* @param [in] bmp 給定的圖片
*/
- Photo(Bitmap<Pixel> const& bmp): self(true) {
+ Photo(Bitmap<Pixel> const& bmp): self() {
reset(bmp);
}
@@ -91,7 +89,7 @@ public:
* @param [in] bmp 給定的圖片
* @param [in] f 給定的焦距
*/
- Photo(Bitmap<Pixel> const& bmp, double f): self(true) {
+ Photo(Bitmap<Pixel> const& bmp, double f): self() {
reset(bmp, f);
}
@@ -104,8 +102,7 @@ public:
* @param [in] f 給定的焦距
* @param [in] c 中心點作標
*/
- Photo(Bitmap<Pixel> const& bmp, double f, Vector2D<double> const& c):
- self(true) {
+ Photo(Bitmap<Pixel> const& bmp, double f, Vector2D<double> const& c): self() {
reset(bmp, f, c);
}
@@ -196,7 +193,7 @@ public:
* @return 新的 \c bitmap
*/
Bitmap<Pixel> const& bitmap(Bitmap<Pixel> const& bmp) {
- self()->bmp_ = bmp;
+ self()->bmp_.copyFrom(bmp);
return bitmap();
}
@@ -219,6 +216,23 @@ public:
}
/*!
+ * @brief 回傳相應的 photo projection
+ */
+ PhotoProjection<double> projection() const {
+ return self->proj_;
+ }
+
+ /*!
+ * @brief 設定 photo projection
+ */
+ PhotoProjection<double> projection(PhotoProjection<double> const& p) {
+ if (p.dimension() == 3) {
+ self()->proj_ = p;
+ }
+ return projection();
+ }
+
+ /*!
* @brief 取得照片中心點底片座標
*
* @return 一個二維vector
@@ -299,6 +313,7 @@ public:
* @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())));
}
@@ -352,7 +367,18 @@ public:
* @note 未完成
*/
bool write(FILE* f, bool bin, unsigned int fg) const {
- return false;
+ if (bitmap().write(f, bin, fg) == false) return false;
+ if (bin) {
+ double tmp;
+ if (fwrite(&(tmp = center().x()), sizeof(tmp), 1, f) < 1) return false;
+ if (fwrite(&(tmp = center().y()), sizeof(tmp), 1, f) < 1) return false;
+ if (fwrite(&(tmp = focal()), sizeof(tmp), 1, f) < 1) return false;
+ }
+ else {
+ if (fprintf(f, "%f %f\n", center().x(), center().y()) < 2) return false;
+ if (fprintf(f, "%f\n", focal()) < 1) return false;
+ }
+ return true;
}
/*! @brief 將資料讀入
@@ -360,12 +386,23 @@ public:
* @note 未完成
*/
bool read(FILE* f, bool bin, unsigned int fg) {
- return false;
+ if (bitmapGet().read(f, bin, fg) == false) return false;
+ double tmp[3];
+ if (bin) {
+ if (fread(tmp, sizeof(double), 3, f) < 3) return false;
+ }
+ else {
+ if (fscanf(f, "%lf %lf %lf", tmp + 0, tmp + 1, tmp + 2) < 3) return false;
+ }
+ centerGet().x(tmp[0]);
+ centerGet().y(tmp[1]);
+ focal(tmp[2]);
+ return true;
}
/*! @brief new一個自己
*
- * @return 一個new出來的Bitmap<Pixel>
+ * @return 一個new出來的Photo<Pixel>
*/
ObjBase* create() const {
return new Photo();
@@ -389,8 +426,7 @@ public:
* @return \c char \c const\c * 形式的typename
*/
char const* ctype() const{
- static char const* ptr = typeid(*this).name();
- return ptr;
+ return typeid(*this).name();
}
/*! @brief 回傳class的type
@@ -402,6 +438,6 @@ public:
}
};
-}
+} // meow
#endif // gra_Photo_H__