8 #include "../geo/Vectors.h"
9 #include "../math/utility.h"
10 #include "../math/Matrix.h"
11 #include "../math/Transformations.h"
13 #include "../oo/ObjBase.h"
39 Myself(Myself
const& b): bmp_(b.bmp_), c_(b.c_), proj_(b.proj_) {
60 self()->proj_.focal(1.0);
131 self().referenceFrom(b.self);
196 self()->bmp_.copyFrom(bmp);
204 return self->proj_.focal();
214 self()->proj_.focal(f);
269 return self->bmp_.width();
276 return self->bmp_.height();
282 Pixel
pixel(
size_t y,
size_t x)
const {
283 return self->bmp_.pixel(y, x);
289 Pixel
pixel(
size_t y,
size_t x, Pixel
const& p) {
290 self()->bmp_.pixel(y, x, p);
303 ssize_t h_max = (ssize_t)
height() - 1;
304 ssize_t w_max = (ssize_t)
width () - 1;
305 return (0 <= c.
y() && c.
y() <= h_max && 0 <= c.
x() && c.
x() <= w_max);
316 if (p.
z() > 0)
return false;
330 if (!
inside(yx))
return Pixel(0);
334 double h[2] = {1 - (c.
y() - y0), c.
y() - y0};
335 double w[2] = {1 - (c.
x() - x0), c.
x() - x0};
337 for (
int dy = 0; dy < 2; dy++)
338 for (
int dx = 0; dx < 2; dx++) {
339 sum = sum +
bitmap().pixel(
340 std::min(y0 + dy, (
int)
height() - 1),
341 std::min(x0 + dx, (
int)
width () - 1)) * (w[dy] * h[dx]);
369 bool write(FILE* f,
bool bin,
unsigned int fg)
const {
370 if (
bitmap().
write(f, bin, fg) ==
false)
return false;
373 if (fwrite(&(tmp =
center().x()),
sizeof(tmp), 1, f) < 1)
return false;
374 if (fwrite(&(tmp =
center().y()),
sizeof(tmp), 1, f) < 1)
return false;
375 if (fwrite(&(tmp =
focal()),
sizeof(tmp), 1, f) < 1)
return false;
378 if (fprintf(f,
"%f %f\n",
center().x(),
center().y()) < 2)
return false;
379 if (fprintf(f,
"%f\n",
focal()) < 1)
return false;
388 bool read(FILE* f,
bool bin,
unsigned int fg) {
392 if (fread(tmp,
sizeof(
double), 3, f) < 3)
return false;
395 if (fscanf(f,
"%lf %lf %lf", tmp + 0, tmp + 1, tmp + 2) < 3)
return false;
429 return typeid(*this).name();
437 return std::string(
ctype());
443 #endif // gra_Photo_H__
PhotoProjection< double > projection(PhotoProjection< double > const &p)
設定 photo projection
double focal() const
回傳focal length
Bitmap< Pixel > const & bitmap() const
回傳bitmap
void reset(Bitmap< Pixel > const &bmp, double f)
重設bitmap, focal
Vector2D< double > & centerGet()
取得照片中心點底片座標 (non-constant reference)
PhotoProjection< double > projection() const
回傳相應的 photo projection
ObjBase * create() const
new一個自己
size_t height() const
回傳高度
Scalar const & x() const
access x
char const * ctype() const
回傳class的type
Scalar const & z() const
access z
Bitmap< Pixel > const & bitmap(Bitmap< Pixel > const &bmp)
設定bitmap
std::string type() const
回傳class的type
bool read(FILE *f, bool bin, unsigned int fg)
將資料讀入
double focal(double f)
設定 focal length
void reset(Bitmap< Pixel > const &bmp)
重設bitmap, focal 用猜的
Pixel pixel(size_t y, size_t x) const
回傳bitmap的某pixel
size_t dimension() const
Get the dimension of this projection.
size_t width() const
回傳bitmap寬
size_t width() const
回傳寬度
Photo(Bitmap< Pixel > const &bmp, double f)
constructor
Photo(Bitmap< Pixel > const &bmp)
constructor
一切物件的Base, 並要求每個物件都要有read, write, create, ... 等功能
Photo & referneceFrom(Photo const &b)
參照
Photo & copyFrom(Photo const &b)
複製資料
Matrix< Scalar > matrix() const
return a 3x1 matrix form of itself
Bitmap< Pixel > & bitmapGet()
回傳bitmap 的參照(非constant)
Pixel color(Vector2D< double > const &yx) const
取得給照片座標中某點的色彩
Pixel color(Vector3D< double > const &p) const
取得給照片座標中某點的色彩
Photo(Bitmap< Pixel > const &bmp, double f, Vector2D< double > const &c)
constructor
Pixel pixel(size_t y, size_t x, Pixel const &p)
設定某pixel
Vector2D< double > const & center(Vector2D< double > const &c)
設定照片中心點底片座標
void reset(Bitmap< Pixel > const &bmp, double f, Vector2D< double > const &c)
重設bitmap, focal, center
ObjBase * copyFrom(ObjBase const *b)
複製資料
Photo & operator=(Photo const &b)
same as .copyFrom(b)
bool write(FILE *f, bool bin, unsigned int fg) const
將資料寫入檔案
Scalar const & y() const
access y
Vector2D< double > const & center() const
取得照片中心點底片座標
bool inside(Vector2D< double > const &yx) const
檢查某點是否在底片範圍內
Photo(Photo const &b)
constructor
bool inside(Vector3D< double > const &p) const
檢查某點是否在底片範圍內
size_t height() const
回傳bitmap高