00001
00002 #include "pop_homography_2d.h"
00003
00004
00005
00006 #include <pop/pop_point_2d.h>
00007 #include <vgl/vgl_homg_point_2d.h>
00008 #include <vcl_cassert.h>
00009
00010
00011
00012
00013 pop_homography_2d::pop_homography_2d(vcl_vector<pop_parameter*> params,
00014 pop_vertex *cs1, pop_vertex *cs2) :
00015 pop_transform(params,cs1,cs2)
00016 {
00017 this->update();
00018 }
00019
00020
00021 pop_homography_2d::~pop_homography_2d()
00022 {
00023 }
00024
00025
00026 pop_geometric_object* pop_homography_2d::transform(pop_geometric_object *obj)
00027 {
00028
00029 pop_point_2d *p1 = obj->cast_to_pop_point_2d();
00030
00031 if (p1)
00032 {
00033
00034
00035 assert(p1->coordinate_system_ == cs1_);
00036
00037
00038 vgl_homg_point_2d<double> hp1(p1->x(),p1->y(),1.0);
00039
00040 vgl_homg_point_2d<double> hp2 = trans_ * hp1;
00041 double w = hp2.w();
00042
00043 double x = hp2.x();
00044 double y = hp2.y();
00045
00046 if (w) {
00047 x=x/w;
00048 y=y/w;
00049 }
00050
00051
00052 pop_point_2d *p2 = new pop_point_2d(cs2_,x,y);
00053
00054 return p2;
00055 }
00056
00057 return 0;
00058 }
00059
00060
00061 void pop_homography_2d::update()
00062 {
00063
00064
00065 vnl_matrix_fixed<double,3,3> mat;
00066
00067 for (int r=0;r<3;r++)
00068 for (int c=0;c<3;c++)
00069 mat(r,c)=params_[r*3+c]->value_;
00070 trans_.set(mat);
00071 }
00072