contrib/gel/pop/pop_rigid_3d.cxx

Go to the documentation of this file.
00001 // This is gel/pop/pop_rigid_3d.cxx
00002 #include "pop_rigid_3d.h"
00003 //:
00004 // \file
00005 
00006 #include <vgl/vgl_homg_point_3d.h>
00007 #include <pop/pop_point_3d.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 
00014 
00015 pop_rigid_3d::pop_rigid_3d(vcl_vector<pop_parameter*> params,
00016                            pop_vertex *cs1, pop_vertex *cs2) :
00017   pop_transform(params,cs1,cs2)
00018 {
00019   this->update();
00020 }
00021 
00022 //: destructor
00023 pop_rigid_3d::~pop_rigid_3d()
00024 {
00025 }
00026 
00027 //: transform a geometric object
00028 pop_geometric_object* pop_rigid_3d::transform(pop_geometric_object *obj)
00029 {
00030   // try to transform a 3d point to a 3d point
00031   pop_point_3d *p1 = obj->cast_to_pop_point_3d();
00032 
00033   if (p1)
00034   {
00035     // make sure that p1 comes from the right coordinate
00036     // system
00037     assert(p1->coordinate_system_ == cs1_);
00038 
00039     // transform this point
00040     vgl_homg_point_3d<double> hp1(p1->x(),p1->y(),p1->z(),1.0);
00041 
00042     vgl_homg_point_3d<double> hp2 = trans_ * hp1;
00043     double w = hp2.w();
00044 
00045     double x = hp2.x();
00046     double y = hp2.y();
00047     double z = hp2.z();
00048 
00049     if (w) {
00050       x=x/w;
00051       y=y/w;
00052       z=z/w;
00053     }
00054 
00055     // make a new pop_point_3d
00056     pop_point_3d *p2 = new pop_point_3d(cs2_,x,y,z);
00057 
00058     return p2;
00059   }
00060 
00061   return 0;
00062 }
00063 
00064 //: update the transform based on the parameters
00065 void pop_rigid_3d::update()
00066 {
00067   // update the rotation
00068   trans_.set_identity();
00069 
00070   trans_.set_rotation_euler(params_[0]->value_,
00071                             params_[1]->value_,
00072                             params_[2]->value_);
00073 
00074   trans_.set_translation(params_[3]->value_,
00075                          params_[4]->value_,
00076                          params_[5]->value_);
00077 }
00078 

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