contrib/gel/pop/pop_projective.cxx

Go to the documentation of this file.
00001 // This is gel/pop/pop_projective.cxx
00002 #include "pop_projective.h"
00003 //:
00004 // \file
00005 #include<pop/pop_point_2d.h>
00006 #include<pop/pop_point_3d.h>
00007 #include <vcl_cassert.h>
00008 
00009 
00010 //: constructor
00011 // the parameters for this transform are
00012 // the Euler angle r1 r2 r2 and the translation t1 t2 t3
00013 
00014 pop_projective::pop_projective(vcl_vector<pop_parameter*> params,
00015                                pop_vertex *cs1, pop_vertex *cs2) :
00016   pop_transform(params,cs1,cs2)
00017 {
00018   this->update();
00019 }
00020 
00021 //: destructor
00022 pop_projective::~pop_projective()
00023 {
00024 }
00025 
00026 //: transform a geometric object
00027 pop_geometric_object* pop_projective::transform(pop_geometric_object *obj)
00028 {
00029   // try to transform a 3d point to a 2d point
00030   pop_point_3d *p1 = obj->cast_to_pop_point_3d();
00031 
00032   if (p1)
00033   {
00034     // make sure that p1 comes from the right coordinate
00035     // system
00036     assert(p1->coordinate_system_ == cs1_);
00037 
00038     // transform this point
00039     vnl_vector<double> v1(3);
00040     v1(0) = p1->x();
00041     v1(1) = p1->y();
00042     v1(2) = p1->z();
00043 
00044     vnl_vector<double> v2 = trans_ * v1;
00045 
00046     // normalize
00047     if (v2(2)) {
00048       v2 = v2/v2(2);
00049     }
00050 
00051     // make a new pop_point_2d
00052     pop_point_2d *p2 = new pop_point_2d(cs2_,v2(0),v2(1));
00053 
00054     return p2;
00055   }
00056 
00057   return 0;
00058 }
00059 
00060 //: update the transform based on the parameters
00061 void pop_projective::update()
00062 {
00063   // update the projective matrix
00064   // |a s u0|
00065   // |0 b v0|
00066   // |0 0 1 |
00067 
00068   trans_.fill(0.0);
00069   trans_(0,0) = params_[0]->value_; // the a value
00070   trans_(1,1) = params_[1]->value_; // the b value
00071   trans_(0,1) = params_[2]->value_; // the shear s
00072   trans_(0,2) = params_[3]->value_; // the u offset
00073   trans_(1,2) = params_[4]->value_; // the v offset
00074   trans_(2,2) = 1.0;
00075 }
00076 

Generated on Sun Sep 7 05:15:06 2008 for contrib/gel/pop by  doxygen 1.5.1