contrib/gel/pop/pop_homography_2d.cxx

Go to the documentation of this file.
00001 // This is gel/pop/pop_homography_2d.cxx
00002 #include "pop_homography_2d.h"
00003 //:
00004 // \file
00005 
00006 #include <pop/pop_point_2d.h>
00007 #include <vgl/vgl_homg_point_2d.h>
00008 #include <vcl_cassert.h>
00009 
00010 //: constructor
00011 // The parameters for this transform are
00012 // the Euler angle r1 r2 r2 and the translation t1 t2 t3
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 //: destructor
00021 pop_homography_2d::~pop_homography_2d()
00022 {
00023 }
00024 
00025 //: transform a geometric object
00026 pop_geometric_object* pop_homography_2d::transform(pop_geometric_object *obj)
00027 {
00028   // try to transform a 2d point to a 2d point
00029   pop_point_2d *p1 = obj->cast_to_pop_point_2d();
00030 
00031   if (p1)
00032   {
00033     // make sure that p1 comes from the right coordinate
00034     // system
00035     assert(p1->coordinate_system_ == cs1_);
00036 
00037     // transform this point
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     // make a new pop_point_3d
00052     pop_point_2d *p2 = new pop_point_2d(cs2_,x,y);
00053 
00054     return p2;
00055   }
00056 
00057   return 0;
00058 }
00059 
00060 //: update the transform based on the parameters
00061 void pop_homography_2d::update()
00062 {
00063   // update the rotation
00064   // make a 3 by 3 matrix
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 

Generated on Tue Oct 7 05:14:37 2008 for contrib/gel/pop by  doxygen 1.5.1