a_camera_model.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef A_CAMERA_MODEL_H
00024 #define A_CAMERA_MODEL_H
00025
00026 #include "claraty/camera_model.h"
00027 #include "claraty/point.h"
00028 #include "claraty/2d_point.h"
00029 #include <sstream>
00030 #include "claraty/fdm_parse_tree.h"
00031
00032 namespace claraty {
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 class A_Camera_Model : public Camera_Model {
00048
00049 private:
00050 int _image_width;
00051 int _image_height;
00052
00053 public:
00054
00055 A_Camera_Model() {};
00056 A_Camera_Model(int width, int height, Frame * frame)
00057 : Camera_Model (frame),
00058 _image_width(width),
00059 _image_height(height) {};
00060
00061
00062
00063 Camera_Model * clone() const {return new A_Camera_Model(*this); }
00064 static Camera_Model * build() {return new A_Camera_Model; }
00065
00066 int get_image_width() { return _image_width; }
00067 int get_image_height() { return _image_height; }
00068
00069 void ray_to_pixel (const Ray & vector,
00070 Pixel_Coord & pixel_coord) const;
00071 void pixel_to_ray (const Pixel_Coord & pixel_coord,
00072 Ray & vector) const;
00073
00074 std::string get_typename () const {return "A_Camera_Model";}
00075
00076 bool map_model (Camera_Model & mapped_model,
00077 Map_Op & map_op) const {return false;}
00078
00079 bool io(FDM_Map m);
00080
00081 };
00082
00083
00084
00085
00086
00087
00088 void A_Camera_Model::
00089 ray_to_pixel(const Ray & ray,
00090 Pixel_Coord & pixel_coord) const
00091 {
00092 pixel_coord(0) = ray(0) / ray(2);
00093 pixel_coord(1) = ray(1) / ray(2);
00094
00095 pixel_coord += 0.01;
00096 };
00097
00098
00099
00100
00101
00102
00103
00104 void A_Camera_Model::
00105 pixel_to_ray(const Pixel_Coord & pixel_coord,
00106 Ray & ray) const
00107 {
00108 float x = pixel_coord(0);
00109 float y = pixel_coord(1);
00110
00111 float _fx = 1.0, _fy = 1.0;
00112
00113 ray(0) = (x - _image_width/2) / _fx;
00114 ray(1) = (y - _image_height/2) / _fy;
00115 ray(2) = 1.0;
00116
00117 ray.normalize();
00118 };
00119
00120
00121
00122 bool io_object(FDM_Map map, std::auto_ptr<A_Camera_Model>& model);
00123
00124
00125
00126 std::istream& operator >> (std::istream& str, A_Camera_Model & m);
00127 std::ostream& operator << (std::ostream& str, const A_Camera_Model & m);
00128
00129
00130
00131
00132 inline bool A_Camera_Model::
00133 io(FDM_Map m)
00134 {
00135 bool ok = Camera_Model::io(m);
00136
00137 double dummy;
00138
00139 if (m.is_read()) {
00140 std::string distString;
00141
00142 ok &= m.field("distortion", distString);
00143
00144 std::istringstream dist(distString);
00145
00146 for (int i = 0; i < 4; i++)
00147 dist >> dummy;
00148 return ok;
00149 }
00150 ok &= m.field("width", _image_width);
00151 ok &= m.field("height", _image_height);
00152 return ok;
00153 }
00154
00155
00156
00157 inline
00158 std::ostream& operator<<(std::ostream& os, const A_Camera_Model& model)
00159 {
00160 FDM_Parse_Tree::write_object(model, os);
00161 return(os);
00162 }
00163
00164
00165
00166 inline
00167 std::istream& operator>>(std::istream& is, A_Camera_Model& model)
00168 {
00169 FDM_Parse_Tree::read_object(model, is);
00170 return(is);
00171 }
00172
00173
00174
00175
00176
00177 }
00178
00179 #endif // CAMERA_MODEL_H