Templates -- Meow  1.2.11
A C++ template contains kinds of interesting classes and functions
Camera.h
Go to the documentation of this file.
1 #ifndef gra_Camera_H__
2 #define gra_Camera_H__
3 
4 #include "Photo.h"
5 #include "IdentityPoints.h"
6 #include "../Self.h"
7 #include "../math/utility.h"
8 #include "../math/LinearTransformations.h"
9 #include "../math/methods.h"
10 #include "../oo/ObjBase.h"
11 
12 namespace meow {
13 
22 template<class Pixel>
23 class Camera: public ObjBase {
24 public:
26 private:
27  struct Myself {
28  Photo<Pixel> photo_;
29  Rotation3D<double> rot_;
30  FixedPoints2D fixed2D_;
31 
32  Myself(): fixed2D_(2) {
33  }
34 
35  Myself(Myself const& v):
36  photo_(v.photo_), rot_(v.rot_), fixed2D_(v.fixed2D_) {
37  }
38 
39  ~Myself() {
40  }
41  };
42 
43  Self<Myself> const self;
44 public:
48  Camera(): self() {
49  }
50 
54  Camera(Camera const& b): self(b.self, Self<Myself>::COPY_FROM) {
55  }
56 
60  ~Camera() {
61  }
62 
66  Camera& copyFrom(Camera const& b) {
67  self().copyFrom(b.self);
68  return *this;
69  }
70 
75  self().referenceFrom(b.self);
76  return *this;
77  }
78 
82  Photo<Pixel> photo() const {
83  return self->photo_;
84  }
85 
90  return self()->photo_;
91  }
92 
97  self()->photo_.copyFrom(pho);
98  return photo();
99  }
100 
105  return self->rot_;
106  }
107 
112  return self()->rot_;
113  }
114 
119  self()->rot_.copyFrom(rot);
120  return rotation();
121  }
122 
127  return self->fixed2D_;
128  }
129 
134  return self()->fixed2D_;
135  }
136 
141  if (fps2d.dimension() == 2) {
142  self()->fixed2D_.copyFrom(fps2d);
143  }
144  return fixedPoints2D();
145  }
146 
151  return self->fixed2D_.identityPoint(i);
152  }
153 
157  bool inside(Vector3D<double> const& p) const {
158  return self->photo_.inside(
159  Vector3D<double>(rotation().transformate(p.matrix())));
160  }
161 
165  Pixel color(Vector3D<double> const& p) const {
166  return self->photo_.color(
167  Vector3D<double>(rotation().transformate(p.matrix())));
168  }
169 
173  Camera& operator=(Camera const& b) {
174  return copyFrom(b);
175  }
176 
181  bool write(FILE* f, bool bin, unsigned int fg) const {
182  if (bin) {
183  double tmp;
184  for (size_t i = 0; i < 3; ++i) {
185  if (fwrite(&(tmp = rotation().theta(i)), sizeof(tmp), 1, f) < 1)
186  return false;
187  }
188  }
189  else {
190  for (size_t i = 0; i < 3; ++i) {
191  if (fprintf(f, "%f ", rotation().theta(i)) < 1) return false;
192  }
193  fprintf(f, "\n");
194  }
195  return (fixedPoints2D().write(f, bin, fg) && photo().write(f, bin, fg));
196  }
197 
202  bool read(FILE* f, bool bin, unsigned int fg) {
203  if (bin) {
204  double tmp;
205  for (size_t i = 0; i < 3; ++i) {
206  if (fread(&tmp, sizeof(tmp), 1, f) < 1) {
207  return false;
208  }
209  rotationGet().theta(i, tmp);
210  }
211  }
212  else {
213  double a;
214  for (size_t i = 0; i < 3; ++i) {
215  if (fscanf(f, "%lf", &a) < 1) return false;
216  rotationGet().theta(i, a);
217  }
218  }
219  return (fixedPoints2DGet().read(f, bin, fg) && photoGet().read(f, bin, fg));
220  }
221 
226  ObjBase* create() const {
227  return new Camera();
228  }
229 
238  ObjBase* copyFrom(ObjBase const* b) {
239  return &(copyFrom(*(Camera const*)b));
240  }
241 
246  char const* ctype() const{
247  return typeid(*this).name();
248  }
249 
254  std::string type() const {
255  return std::string(ctype());
256  }
257 };
258 
259 } // meow
260 
261 #endif // gra_Camera_H__
Rotation3D & copyFrom(Rotation3D const &b)
Copy data.
size_t dimension() const
回傳dimension
Scalar const & theta(size_t i) const
Get the i -th theta.
Camera.
Definition: Camera.h:23
std::string type() const
回傳class的type
Definition: Camera.h:254
Photo< Pixel > photo() const
取得 photo
Definition: Camera.h:82
把一個 std::map<Identity, Point > 包起來
Rotation3D< double > rotation(Rotation3D< double > const &rot)
設定rotation
Definition: Camera.h:118
Camera & copyFrom(Camera const &b)
複製資料
Definition: Camera.h:66
bool inside(Vector3D< double > const &p) const
詢問某點是否在底片範圍內
Definition: Camera.h:157
Camera & operator=(Camera const &b)
same as copyFrom(b)
Definition: Camera.h:173
Rotation3D< double > rotation() const
取得rotation
Definition: Camera.h:104
bool write(FILE *f, bool bin, unsigned int fg) const
將資料寫入檔案
Definition: Camera.h:181
Rotation3D< double > & rotationGet()
取得rotation (non-constant)
Definition: Camera.h:111
Photo< Pixel > & photoGet()
取得 photo (non-constant)
Definition: Camera.h:89
一切物件的Base, 並要求每個物件都要有read, write, create, ... 等功能
Definition: ObjBase.h:15
Photo< Pixel > photo(Photo< Pixel > const &pho)
設定 photo
Definition: Camera.h:96
vector
Definition: Vector.h:19
ObjBase * create() const
new一個自己
Definition: Camera.h:226
char const * ctype() const
回傳class的type
Definition: Camera.h:246
Matrix< Scalar > matrix() const
return a 3x1 matrix form of itself
Definition: Vectors.h:458
Vector< double > fixedPoint2D(int i)
取得編號為i的fixed points 2d
Definition: Camera.h:150
Pixel color(Vector3D< double > const &p) const
取得底片color
Definition: Camera.h:165
Camera()
constructor
Definition: Camera.h:48
底片
Definition: Photo.h:31
ObjBase * copyFrom(ObjBase const *b)
複製資料
Definition: Camera.h:238
FixedPoints2D fixedPoints2D(FixedPoints2D const &fps2d) const
設定FixedPoint
Definition: Camera.h:140
IdentityPoints & copyFrom(IdentityPoints const &b)
複製資料
FixedPoints2D fixedPoints2D() const
取得所有FixedPoint
Definition: Camera.h:126
bool read(FILE *f, bool bin, unsigned int fg)
將資料讀入
Definition: Camera.h:202
Camera & referenceFrom(Camera const &b)
參照
Definition: Camera.h:74
Camera(Camera const &b)
copy constructor
Definition: Camera.h:54
FixedPoints2D & fixedPoints2DGet() const
取得所有FixedPoint(non-constant reference)
Definition: Camera.h:133
~Camera()
destructor
Definition: Camera.h:60
IdentityPoints< int, double, Vector2D< double > > FixedPoints2D
Definition: Camera.h:25