Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

strk_art_info_model.cxx

Go to the documentation of this file.
00001 // This is brl/bseg/strk/strk_art_info_model.cxx
00002 #include "strk_art_info_model.h"
00003 //:
00004 // \file
00005 // See strk_art_info_model.h
00006 //
00007 //-----------------------------------------------------------------------------
00008 #include <strk/strk_tracking_face_2d.h>
00009 #include <btol/btol_face_algs.h>
00010 #include <vsol/vsol_point_2d.h>
00011 #include <vcl_cmath.h> // for sqrt()
00012 
00013 //------------------------------------------------------------------------
00014 // Constructor
00015 //
00016 strk_art_info_model::strk_art_info_model()
00017 {
00018 }
00019 
00020 //------------------------------------------------------------------------
00021 // Accessors
00022 //
00023 strk_tracking_face_2d_sptr strk_art_info_model::face(int i) const { return faces_[i]; }
00024 strk_tracking_face_2d_sptr strk_art_info_model::stem() const { return faces_[STEM]; }
00025 strk_tracking_face_2d_sptr strk_art_info_model::left_tip() const { return faces_[LONG_TIP]; }
00026 strk_tracking_face_2d_sptr strk_art_info_model::right_tip() const { return faces_[SHORT_TIP]; }
00027 vsol_point_2d_sptr strk_art_info_model::stem_pivot() const { return stem_pivot_; }
00028 
00029 double strk_art_info_model::arm_radius(strk_tracking_face_2d_sptr const& face)
00030 {
00031   if (!face)
00032     return 0;
00033   double fx0 = 0, fy0 = 0;
00034   face->centroid(fx0, fy0);
00035   double px0 = stem_pivot_->x(), py0 = stem_pivot_->y();
00036   return vcl_sqrt((fx0-px0)*(fx0-px0)+ (fy0-py0)*(fy0-py0));
00037 }
00038 
00039 strk_art_info_model::
00040 strk_art_info_model(vcl_vector<vtol_face_2d_sptr> const& faces,
00041                     vsol_point_2d_sptr const stem_pivot,
00042                     vil1_memory_image_of<float> & image)
00043 {
00044   vil1_memory_image_of<float> null;
00045   for (vcl_vector<vtol_face_2d_sptr>::const_iterator fit = faces.begin();
00046        fit != faces.end(); fit++)
00047     faces_.push_back(new strk_tracking_face_2d(*fit, image, null, null,null, null,0,1,0,0,0));
00048   stem_pivot_ = stem_pivot;
00049   //compute the arm radii
00050   long_arm_radius_ = arm_radius(faces_[LONG_TIP]);
00051   short_arm_radius_ = arm_radius(faces_[SHORT_TIP]);
00052 }
00053 
00054 strk_art_info_model::
00055 strk_art_info_model(vcl_vector<vtol_face_2d_sptr> const& faces,
00056                     vsol_point_2d_sptr const stem_pivot,
00057                     vil1_memory_image_of<float> & image,
00058                     vil1_memory_image_of<float>& Ix,
00059                     vil1_memory_image_of<float>& Iy)
00060 {
00061   vil1_memory_image_of<float> null;
00062   for (vcl_vector<vtol_face_2d_sptr>::const_iterator fit = faces.begin();
00063        fit != faces.end(); fit++)
00064     faces_.push_back(new strk_tracking_face_2d(*fit, image, Ix, Iy, null, null,0,1,0,0,0));
00065   stem_pivot_ = stem_pivot;
00066   //compute the arm radii
00067   long_arm_radius_ = arm_radius(faces_[LONG_TIP]);
00068   short_arm_radius_ = arm_radius(faces_[SHORT_TIP]);
00069 }
00070 
00071 strk_art_info_model::strk_art_info_model(strk_art_info_model_sptr const& im)
00072 {
00073   if (!im)
00074     return;
00075   for (unsigned int i = 0; i<im->n_faces(); i++)
00076     faces_.push_back(new strk_tracking_face_2d(im->face(i)));
00077   stem_pivot_ = im->stem_pivot_;
00078   long_arm_radius_ = im->long_arm_radius_;
00079   short_arm_radius_ = im->short_arm_radius_;
00080 }
00081 
00082 strk_art_info_model::strk_art_info_model(strk_art_info_model const& im)
00083   : vbl_ref_count(), long_arm_radius_(im.long_arm_radius_),
00084     short_arm_radius_(im.short_arm_radius_), stem_pivot_(im.stem_pivot_)
00085 {
00086   for (unsigned int i = 0; i<im.n_faces(); i++)
00087     faces_.push_back(new strk_tracking_face_2d(im.face(i)));
00088 }
00089 
00090 strk_art_info_model::~strk_art_info_model()
00091 {
00092 }
00093 
00094 bool strk_art_info_model::
00095 pivot_tip_face(strk_tracking_face_2d_sptr const& face,
00096                const double angle, const double radius)
00097 {
00098   if (!face||!radius)
00099     return false;
00100   if (!angle)
00101     return true;
00102   double fx0 = 0, fy0 = 0;
00103   face->centroid(fx0, fy0);
00104   double px0 = stem_pivot_->x(), py0 = stem_pivot_->y();
00105 
00106   //get the current orientation of the arm
00107   double c = (fx0-px0)/radius, s = (fy0-py0)/radius;
00108   double theta = vcl_atan2(s, c);
00109   theta += angle;
00110   double new_fx0 = radius*vcl_cos(theta)+px0, new_fy0 = radius*vcl_sin(theta)+py0;
00111   double tx = new_fx0-fx0, ty = new_fy0-fy0;
00112   face->transform(tx, ty, 0, 1.0);
00113   return true;
00114 }
00115 
00116 //:transform the articulated model
00117 bool strk_art_info_model::transform(const double stem_tx,
00118                                     const double stem_ty,
00119                                     const double stem_angle,
00120                                     const double long_arm_pivot_angle,
00121                                     const double short_arm_pivot_angle,
00122                                     const double long_tip_angle,
00123                                     const double short_tip_angle)
00124 {
00125 #ifdef DEBUG
00126   vcl_cout << " long_radius btrans "<< arm_radius(faces_[LONG_TIP])
00127            << " short_radius btrans"<< arm_radius(faces_[SHORT_TIP]) << '\n';
00128 #endif
00129 
00130   // move the pivot
00131   if (!stem_pivot_)
00132     return false;
00133 #if 0
00134   stem_pivot_->set_x(stem_pivot_->x()+stem_tx);
00135   stem_pivot_->set_y(stem_pivot_->y()+stem_ty);
00136 #endif
00137 
00138   //transform all the faces since the stem transform is considered global
00139   //for now we assume that the stem_pivot is the same as the centroid
00140   //of the stem face (It is being constructed that way at present, although
00141   //the option remains to have the pivot independently defined).
00142  for (vcl_vector<strk_tracking_face_2d_sptr>::iterator fit = faces_.begin();
00143       fit != faces_.end(); fit++)
00144     if (!(*fit))
00145       return false;
00146     else
00147       (*fit)->transform(stem_tx, stem_ty, stem_angle, 1.0);
00148 
00149   stem_pivot_ = btol_face_algs::centroid(faces_[STEM]->face()->cast_to_face_2d());
00150 #ifdef DEBUG
00151   vcl_cout << "Stem Pivot (" << stem_pivot_->x() << ' ' << stem_pivot_->y() << ")\n";
00152 #endif
00153 
00154  //pivot the tips by the same stem angle
00155   if (!this->pivot_tip_face(faces_[LONG_TIP],stem_angle,
00156                             long_arm_radius_))
00157     return false;
00158 
00159   if (!this->pivot_tip_face(faces_[SHORT_TIP], stem_angle,
00160                             short_arm_radius_))
00161     return false;
00162 #ifdef DEBUG
00163   vcl_cout << " long_radius_atrans "<< arm_radius(faces_[LONG_TIP])
00164            << " short_radius_atrans "<< arm_radius(faces_[SHORT_TIP]) << '\n';
00165 #endif
00166 
00167   //transform the arms around the pivot
00168   //this just translates the tip faces since we assume their orientation
00169   //only changes by pivoting around their centroid
00170   if (!this->pivot_tip_face(faces_[LONG_TIP],long_arm_pivot_angle, long_arm_radius_))
00171     return false;
00172 
00173   if (!this->pivot_tip_face(faces_[SHORT_TIP], short_arm_pivot_angle,
00174       short_arm_radius_))
00175     return false;
00176 
00177   //rotate the tip faces around their centroids
00178   faces_[LONG_TIP]->transform(0.0, 0.0, long_tip_angle, 1.0);
00179   faces_[SHORT_TIP]->transform(0.0, 0.0, short_tip_angle, 1.0);
00180 
00181   return true;
00182 }
00183 
00184 vcl_vector<vtol_face_2d_sptr> strk_art_info_model::vtol_faces() const
00185 {
00186   vcl_vector<vtol_face_2d_sptr> vtol_faces;
00187   for (vcl_vector<strk_tracking_face_2d_sptr>::const_iterator fit = faces_.begin();
00188        fit != faces_.end(); fit++)
00189   {
00190     vtol_face_2d_sptr f = (*fit)->face()->cast_to_face_2d();
00191     vtol_faces.push_back(f);
00192   }
00193   return vtol_faces;
00194 }
00195 
00196 bool strk_art_info_model::
00197 compute_mutual_information(vil1_memory_image_of<float> const& image)
00198 {
00199   if (!image)
00200     return false;
00201   vil1_memory_image_of<float> null;//dummy args (replace with deflts)
00202   double model_info = 0.0;
00203   for (vcl_vector<strk_tracking_face_2d_sptr>::const_iterator fit =  faces_.begin();
00204        fit != faces_.end(); fit++)
00205   {
00206     if (!(*fit)->compute_mutual_information(image, null, null, null, null))
00207       continue;
00208     model_info += (*fit)->total_info();
00209   }
00210   total_model_info_ = model_info;
00211   return true;
00212 }
00213 
00214 bool strk_art_info_model::
00215 compute_mutual_information(vil1_memory_image_of<float> const& image,
00216                            vil1_memory_image_of<float> const& Ix,
00217                            vil1_memory_image_of<float> const& Iy)
00218 {
00219   if (!image||!Ix||!Iy)
00220     return false;
00221   vil1_memory_image_of<float> null;
00222   double model_info = 0.0;
00223   for (vcl_vector<strk_tracking_face_2d_sptr>::const_iterator fit =  faces_.begin();
00224        fit != faces_.end(); fit++)
00225   {
00226     if (!(*fit)->compute_mutual_information(image, Ix, Iy, null, null))
00227       continue;
00228     model_info += (*fit)->total_info();
00229   }
00230   total_model_info_ = model_info;
00231   return true;
00232 }

Generated on Thu Jan 10 14:53:19 2008 for contrib/brl/bseg/strk by  doxygen 1.4.4