2 #ifndef vpgl_rational_camera_hxx_ 3 #define vpgl_rational_camera_hxx_ 11 # include <vcl_msvc_warnings.h> 25 rational_coeffs_.fill(0);
26 rational_coeffs_[DEN_U][19]=1;
27 rational_coeffs_[DEN_V][19]=1;
28 rational_coeffs_[NEU_U][9]=1;
29 rational_coeffs_[NEU_V][15]=1;
31 scale_offsets_.resize(5, soff);
40 this->set_coefficients(rational_coeffs);
41 this->set_scale_offsets(scale_offsets);
47 std::vector<T>
const& den_u,
48 std::vector<T>
const& neu_v,
49 std::vector<T>
const& den_v,
50 const T x_scale,
const T x_off,
51 const T y_scale,
const T y_off,
52 const T z_scale,
const T z_off,
53 const T u_scale,
const T u_off,
54 const T v_scale,
const T v_off
57 for (
unsigned i = 0; i<20; ++i)
59 rational_coeffs_[NEU_U][i] = neu_u[i];
60 rational_coeffs_[DEN_U][i] = den_u[i];
61 rational_coeffs_[NEU_V][i] = neu_v[i];
62 rational_coeffs_[DEN_V][i] = den_v[i];
64 scale_offsets_.resize(5);
79 const T x_scale,
const T x_off,
80 const T y_scale,
const T y_off,
81 const T z_scale,
const T z_off,
82 const T u_scale,
const T u_off,
83 const T v_scale,
const T v_off
86 for (
unsigned i = 0; i<20; ++i)
88 rational_coeffs_[NEU_U][i] = T(neu_u[i]);
89 rational_coeffs_[DEN_U][i] = T(den_u[i]);
90 rational_coeffs_[NEU_V][i] = T(neu_v[i]);
91 rational_coeffs_[DEN_V][i] = T(den_v[i]);
93 scale_offsets_.resize(5);
111 for (
unsigned j = 0; j<4; ++j)
112 for (
unsigned i = 0; i<20; ++i)
113 rational_coeffs_[j][i] = rational_coeffs[j][i];
120 scale_offsets_=scale_offsets;
126 std::vector<std::vector<T> > result(4);
127 for (
unsigned j = 0; j<4; ++j)
129 result[j].resize(20);
130 for (
unsigned i = 0; i<20; ++i)
131 result[j][i]=rational_coeffs_[j][i];
201 T sx = scale_offsets_[X_INDX].normalize(x);
202 T sy = scale_offsets_[Y_INDX].normalize(y);
203 T sz = scale_offsets_[Z_INDX].normalize(z);
205 T su = polys[NEU_U]/polys[DEN_U];
206 T sv = polys[NEU_V]/polys[DEN_V];
208 u = scale_offsets_[U_INDX].un_normalize(su);
209 v = scale_offsets_[V_INDX].un_normalize(sv);
218 this->project(world_point[0], world_point[1], world_point[2],
219 image_point[0], image_point[1]);
228 this->project(world_point.
x(), world_point.
y(), world_point.
z(), u,
v);
242 s <<
"vpgl_rational_camera:\n" 243 <<
"------------------------\n" 244 <<
"xoff = " << sox.
offset()
245 <<
" yoff = " << soy.
offset()
246 <<
" zoff = " << soz.
offset() <<
'\n' 247 <<
"xscale = " << sox.
scale()
248 <<
" yscale = " << soy.
scale()
249 <<
" zscale = " << soz.
scale() <<
'\n' 251 <<
"uoff = " << sou.
offset()
252 <<
" voff = " << sov.
offset() <<
'\n' 253 <<
"uscale = " << sou.
scale()
254 <<
" vscale = " << sov.
scale() <<
"\n\n" 257 <<
"[0] " << rational_coeffs_[0][0]
258 <<
" [1] " << rational_coeffs_[0][1]
259 <<
" [2] " << rational_coeffs_[0][2]
260 <<
" [3] " << rational_coeffs_[0][3] <<
'\n' 261 <<
"[4] " << rational_coeffs_[0][4]
262 <<
" [5] " << rational_coeffs_[0][5]
263 <<
" [6] " << rational_coeffs_[0][6]
264 <<
" [7] " << rational_coeffs_[0][7] <<
'\n' 265 <<
"[8] " << rational_coeffs_[0][8]
266 <<
" [9] " << rational_coeffs_[0][9]
267 <<
" [10] " << rational_coeffs_[0][10]
268 <<
" [11] " << rational_coeffs_[0][11] <<
'\n' 269 <<
"[12] " << rational_coeffs_[0][12]
270 <<
" [13] " << rational_coeffs_[0][13]
271 <<
" [14] " << rational_coeffs_[0][14]
272 <<
" [15] " << rational_coeffs_[0][15] <<
'\n' 273 <<
"[16] " << rational_coeffs_[0][16]
274 <<
" [17] " << rational_coeffs_[0][17]
275 <<
" [18] " << rational_coeffs_[0][18]
276 <<
" [19] " << rational_coeffs_[0][19] <<
"\n\n" 279 <<
"[0] " << rational_coeffs_[1][0]
280 <<
" [1] " << rational_coeffs_[1][1]
281 <<
" [2] " << rational_coeffs_[1][2]
282 <<
" [3] " << rational_coeffs_[1][3] <<
'\n' 283 <<
"[4] " << rational_coeffs_[1][4]
284 <<
" [5] " << rational_coeffs_[1][5]
285 <<
" [6] " << rational_coeffs_[1][6]
286 <<
" [7] " << rational_coeffs_[1][7] <<
'\n' 287 <<
"[8] " << rational_coeffs_[1][8]
288 <<
" [9] " << rational_coeffs_[1][9]
289 <<
" [10] " << rational_coeffs_[1][10]
290 <<
" [11] " << rational_coeffs_[1][11] <<
'\n' 291 <<
"[12] " << rational_coeffs_[1][12]
292 <<
" [13] " << rational_coeffs_[1][13]
293 <<
" [14] " << rational_coeffs_[1][14]
294 <<
" [15] " << rational_coeffs_[1][15] <<
'\n' 295 <<
"[16] " << rational_coeffs_[1][16]
296 <<
" [17] " << rational_coeffs_[1][17]
297 <<
" [18] " << rational_coeffs_[1][18]
298 <<
" [19] " << rational_coeffs_[1][19] <<
"\n\n" 301 <<
"[0] " << rational_coeffs_[2][0]
302 <<
" [1] " << rational_coeffs_[2][1]
303 <<
" [2] " << rational_coeffs_[2][2]
304 <<
" [3] " << rational_coeffs_[2][3]<<
'\n' 305 <<
"[4] " << rational_coeffs_[2][4]
306 <<
" [5] " << rational_coeffs_[2][5]
307 <<
" [6] " << rational_coeffs_[2][6]
308 <<
" [7] " << rational_coeffs_[2][7] <<
'\n' 309 <<
"[8] " << rational_coeffs_[2][8]
310 <<
" [9] " << rational_coeffs_[2][9]
311 <<
" [10] " << rational_coeffs_[2][10]
312 <<
" [11] " << rational_coeffs_[2][11] <<
'\n' 313 <<
"[12] " << rational_coeffs_[2][12]
314 <<
" [13] " << rational_coeffs_[2][13]
315 <<
" [14] " << rational_coeffs_[2][14]
316 <<
" [15] " << rational_coeffs_[2][15]<<
'\n' 317 <<
"[16] " << rational_coeffs_[2][16]
318 <<
" [17] " << rational_coeffs_[2][17]
319 <<
" [18] " << rational_coeffs_[2][18]
320 <<
" [19] " << rational_coeffs_[2][19] <<
"\n\n" 323 <<
"[0] " << rational_coeffs_[3][0]
324 <<
" [1] " << rational_coeffs_[3][1]
325 <<
" [2] " << rational_coeffs_[3][2]
326 <<
" [3] " << rational_coeffs_[3][3]<<
'\n' 327 <<
"[4] " << rational_coeffs_[3][4]
328 <<
" [5] " << rational_coeffs_[3][5]
329 <<
" [6] " << rational_coeffs_[3][6]
330 <<
" [7] " << rational_coeffs_[3][7] <<
'\n' 331 <<
"[8] " << rational_coeffs_[3][8]
332 <<
" [9] " << rational_coeffs_[3][9]
333 <<
" [10] " << rational_coeffs_[3][10]
334 <<
" [11] " << rational_coeffs_[3][11] <<
'\n' 335 <<
"[12] " << rational_coeffs_[3][12]
336 <<
" [13] " << rational_coeffs_[3][13]
337 <<
" [14] " << rational_coeffs_[3][14]
338 <<
" [15] " << rational_coeffs_[3][15]<<
'\n' 339 <<
"[16] " << rational_coeffs_[3][16]
340 <<
" [17] " << rational_coeffs_[3][17]
341 <<
" [18] " << rational_coeffs_[3][18]
342 <<
" [19] " << rational_coeffs_[3][19] <<
'\n' 343 <<
"------------------------------------------------\n\n";
349 std::ofstream file_out;
350 file_out.open(cam_path.c_str());
351 if (!file_out.good()) {
352 std::cerr <<
"error: bad filename: " << cam_path << std::endl;
355 file_out.precision(12);
379 file_out <<
"satId = \"????\";\n" 380 <<
"bandId = \"RGB\";\n" 381 <<
"SpecId = \"RPC00B\";\n" 382 <<
"BEGIN_GROUP = IMAGE\n" 384 <<
" lineOffset = " << offset(V_INDX) <<
'\n' 385 <<
" sampOffset = " << offset(U_INDX) <<
'\n' 386 <<
" latOffset = " << offset(Y_INDX) <<
'\n' 387 <<
" longOffset = " << offset(X_INDX) <<
'\n' 388 <<
" heightOffset = " << offset(Z_INDX) <<
'\n' 389 <<
" lineScale = " << scale(V_INDX) <<
'\n' 390 <<
" sampScale = " << scale(U_INDX) <<
'\n' 391 <<
" latScale = " << scale(Y_INDX) <<
'\n' 392 <<
" longScale = " << scale(X_INDX) <<
'\n' 393 <<
" heightScale = " << scale(Z_INDX) <<
'\n';
395 file_out <<
" lineNumCoef = (";
396 for (
int i=0; i<20; i++) {
397 file_out <<
"\n " << coeffs[NEU_V][map[i]];
401 file_out <<
");\n lineDenCoef = (";
402 for (
int i=0; i<20; i++) {
403 file_out <<
"\n " << coeffs[DEN_V][map[i]];
407 file_out <<
");\n sampNumCoef = (";
408 for (
int i=0; i<20; i++) {
409 file_out <<
"\n " << coeffs[NEU_U][map[i]];
413 file_out <<
");\n sampDenCoef = (";
414 for (
int i=0; i<20; i++) {
415 file_out <<
"\n " << coeffs[DEN_U][map[i]];
420 <<
"END_GROUP = IMAGE\n" 438 std::ifstream file_inp;
439 file_inp.open(cam_path.c_str());
440 if (!file_inp.good()) {
441 std::cout <<
"error: bad filename: " << cam_path << std::endl;
452 std::vector<T> neu_u;
453 std::vector<T> den_u;
454 std::vector<T> neu_v;
455 std::vector<T> den_v;
456 T x_scale,x_off,y_scale,y_off,z_scale,z_off,u_scale,u_off,v_scale,v_off;
461 while (!istr.eof()) {
464 if (input==
"sampScale") {
468 if (input==
"sampOffset") {
473 if (input==
"lineScale") {
477 if (input==
"lineOffset") {
482 if (input==
"longScale") {
486 if (input==
"longOffset") {
491 if (input==
"latScale") {
495 if (input==
"latOffset") {
500 if (input==
"heightScale") {
504 if (input==
"heightOffset") {
510 if (input==
"lineNumCoef") {
513 for (
int i=0; i<20; i++) {
515 neu_v.push_back(temp_dbl);
516 istr.getline(bulk,200);
520 if (input==
"lineDenCoef") {
523 for (
int i=0; i<20; i++) {
525 den_v.push_back(temp_dbl);
526 istr.getline(bulk,200);
530 if (input==
"sampNumCoef") {
533 for (
int i=0; i<20; i++) {
535 neu_u.push_back(temp_dbl);
536 istr.getline(bulk,200);
540 if (input==
"sampDenCoef") {
543 for (
int i=0; i<20; i++) {
545 den_u.push_back(temp_dbl);
546 istr.getline(bulk,200);
552 if (input!=
"END_GROUP")
585 if ((neu_u.size() != 20) || (den_u.size() != 20)) {
586 std::cerr <<
"the input is not a valid rational camera\n";
591 for (
int j=0; j<20; j++) {
592 temp_vector[j] = neu_u[j];
594 for (
int j=0; j<20; j++) {
595 neu_u[map[j]] = temp_vector[j];
597 for (
int j=0; j<20; j++) {
598 temp_vector[j] = den_u[j];
600 for (
int j=0; j<20; j++) {
601 den_u[map[j]] = temp_vector[j];
603 for (
int j=0; j<20; j++) {
604 temp_vector[j] = neu_v[j];
606 for (
int j=0; j<20; j++) {
607 neu_v[map[j]] = temp_vector[j];
609 for (
int j=0; j<20; j++) {
610 temp_vector[j] = den_v[j];
612 for (
int j=0; j<20; j++) {
613 den_v[map[j]] = temp_vector[j];
617 x_scale, x_off, y_scale, y_off, z_scale, z_off,
618 u_scale, u_off, v_scale, v_off);
628 istr.open(cam_path.c_str());
630 std::cout <<
"error: bad filename: " << cam_path << std::endl;
634 std::vector<T> neu_u;
635 std::vector<T> den_u;
636 std::vector<T> neu_v;
637 std::vector<T> den_v;
638 T x_scale,x_off,y_scale,y_off,z_scale,z_off,u_scale,u_off,v_scale,v_off;
643 while (!istr.eof()) {
646 if (input==
"SAMP_SCALE:") {
650 if (input==
"SAMP_OFF:") {
655 if (input==
"LINE_SCALE:") {
659 if (input==
"LINE_OFF:") {
664 if (input==
"LONG_SCALE:") {
668 if (input==
"LONG_OFF:") {
673 if (input==
"LAT_SCALE:") {
677 if (input==
"LAT_OFF:") {
682 if (input==
"HEIGHT_SCALE:") {
686 if (input==
"HEIGHT_OFF:") {
692 if (input==
"LINE_NUM_COEFF_1:") {
696 neu_v.push_back(temp_dbl);
697 for (
int i=1; i<20; i++) {
700 neu_v.push_back(temp_dbl);
701 istr.getline(bulk,200);
705 if (input==
"LINE_DEN_COEFF_1:") {
709 den_v.push_back(temp_dbl);
710 for (
int i=1; i<20; i++) {
713 den_v.push_back(temp_dbl);
714 istr.getline(bulk,200);
718 if (input==
"SAMP_NUM_COEFF_1:") {
722 neu_u.push_back(temp_dbl);
723 for (
int i=1; i<20; i++) {
726 neu_u.push_back(temp_dbl);
727 istr.getline(bulk,200);
731 if (input==
"SAMP_DEN_COEFF_1:") {
735 den_u.push_back(temp_dbl);
736 for (
int i=1; i<20; i++) {
739 den_u.push_back(temp_dbl);
740 istr.getline(bulk,200);
768 if ((neu_u.size() != 20) || (den_u.size() != 20)) {
769 std::cerr <<
"the input is not a valid rational camera\n";
774 for (
int j=0; j<20; j++) {
775 temp_vector[j] = neu_u[j];
777 for (
int j=0; j<20; j++) {
778 neu_u[map[j]] = temp_vector[j];
780 for (
int j=0; j<20; j++) {
781 temp_vector[j] = den_u[j];
783 for (
int j=0; j<20; j++) {
784 den_u[map[j]] = temp_vector[j];
786 for (
int j=0; j<20; j++) {
787 temp_vector[j] = neu_v[j];
789 for (
int j=0; j<20; j++) {
790 neu_v[map[j]] = temp_vector[j];
792 for (
int j=0; j<20; j++) {
793 temp_vector[j] = den_v[j];
795 for (
int j=0; j<20; j++) {
796 den_v[map[j]] = temp_vector[j];
800 x_scale, x_off, y_scale, y_off, z_scale, z_off,
801 u_scale, u_off, v_scale, v_off);
818 #undef vpgl_RATIONAL_CAMERA_INSTANTIATE 819 #define vpgl_RATIONAL_CAMERA_INSTANTIATE(T) \ 820 template class vpgl_scale_offset<T >; \ 821 template class vpgl_rational_camera<T >; \ 822 template std::ostream& operator<<(std::ostream&, const vpgl_rational_camera<T >&); \ 823 template std::istream& operator>>(std::istream&, vpgl_rational_camera<T >&); \ 824 template vpgl_rational_camera<T > * read_rational_camera(std::string); \ 825 template vpgl_rational_camera<T > * read_rational_camera(std::istream&); \ 826 template vpgl_rational_camera<T > * read_rational_camera_from_txt(std::string); 829 #endif // vpgl_rational_camera_hxx_
A camera model based on ratios of cubic polynomials.
vpgl_rational_camera< T > * read_rational_camera(std::string cam_path)
Creates a rational camera from a file.
virtual bool save(std::string cam_path)
std::istream & operator >>(std::istream &s, vpgl_rational_camera< T > &c)
Read from stream.
void set_scale_offsets(std::vector< vpgl_scale_offset< T > > const &scale_offsets)
set coordinate scale and offsets.
vnl_vector_fixed< T, 20 > power_vector(const T x, const T y, const T z) const
Create a vector with the standard order of monomial terms.
vpgl_rational_camera()
default constructor.
std::vector< std::vector< T > > coefficients() const
get the rational polynomial coefficients in a vcl array.
std::ostream & operator<<(std::ostream &s, const vpgl_local_rational_camera< T > &p)
Write to stream.
virtual vpgl_rational_camera< T > * clone(void) const
Clone ‘this’: creation of a new object and initialization.
virtual void print(std::ostream &s=std::cout) const
print the camera parameters.
void set_coefficients(std::vector< std::vector< T > > const &rational_coeffs)
set rational polynomial coefficients.
void put(unsigned int i, T const &v)
vpgl_rational_camera< T > * read_rational_camera_from_txt(std::string cam_path)
Creates a rational camera from a txt file.
void project(const T x, const T y, const T z, T &u, T &v) const override
The generic camera interface. u represents image column, v image row.