00001
00002 #include "pop_rigid_3d.h"
00003
00004
00005
00006 #include <vgl/vgl_homg_point_3d.h>
00007 #include <pop/pop_point_3d.h>
00008 #include <vcl_cassert.h>
00009
00010
00011
00012
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
00023 pop_rigid_3d::~pop_rigid_3d()
00024 {
00025 }
00026
00027
00028 pop_geometric_object* pop_rigid_3d::transform(pop_geometric_object *obj)
00029 {
00030
00031 pop_point_3d *p1 = obj->cast_to_pop_point_3d();
00032
00033 if (p1)
00034 {
00035
00036
00037 assert(p1->coordinate_system_ == cs1_);
00038
00039
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
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
00065 void pop_rigid_3d::update()
00066 {
00067
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