contrib/brl/bbas/bugl/bugl_random_transform_set_2d.txx

Go to the documentation of this file.
00001 #ifndef bugl_random_transform_set_2d_txx_
00002 #define bugl_random_transform_set_2d_txx_
00003 
00004 #include "bugl_random_transform_set_2d.h"
00005 
00006 #include <vcl_cstdlib.h> // for rand()
00007 
00008 template<class T>
00009 void bugl_random_transform_set_2d<T>::
00010 equiform_uniform(const unsigned n_trans,
00011                  vcl_vector<vgl_h_matrix_2d<T> >& transform_set,
00012                  const T dx, const T dy,
00013                  const T dtheta, const T ds)
00014 {
00015   //convert to double
00016   double dx_d = dx, dy_d = dy, dtheta_d = dtheta, ds_d = ds;
00017   transform_set.resize(n_trans);
00018   for (unsigned i = 0; i<n_trans; ++i)
00019   {
00020     //generate random samples of uniform distribution
00021     T rnd_dx = (T)((2.0*dx_d)*(vcl_rand()/(RAND_MAX+1.0)) - dx_d);
00022     T rnd_dy = (T)((2.0*dy_d)*(vcl_rand()/(RAND_MAX+1.0)) - dy_d);
00023     T rnd_dtheta =
00024       (T)((2.0*dtheta_d)*(vcl_rand()/(RAND_MAX+1.0)) - dtheta_d);
00025     T rnd_ds = (T)((2.0*ds_d)*(vcl_rand()/(RAND_MAX+1.0)) - ds_d);
00026     rnd_ds += 1.0;
00027     transform_set[i].set_identity();
00028     transform_set[i].set_rotation(rnd_dtheta);
00029     transform_set[i].set_scale(rnd_ds);
00030     transform_set[i].set_translation(rnd_dx, rnd_dy);
00031   }
00032 }
00033 
00034 template<class T>
00035 void bugl_random_transform_set_2d<T>::
00036 zero_skew_affine_uniform(const unsigned n_trans,
00037                          vcl_vector<vgl_h_matrix_2d<T> >& transform_set,
00038                          const T dx, const T dy,
00039                          const T dtheta, const T ds,
00040                          const T daspect)
00041 {
00042   //convert to double
00043   double dx_d = dx, dy_d = dy, dtheta_d = dtheta, ds_d = ds, da_d = daspect;
00044   transform_set.resize(n_trans);
00045   for (unsigned i = 0; i<n_trans; ++i)
00046   {
00047     //generate random samples of uniform distribution
00048     T rnd_dx = (T)((2.0*dx_d)*(vcl_rand()/(RAND_MAX+1.0)) - dx_d);
00049     T rnd_dy = (T)((2.0*dy_d)*(vcl_rand()/(RAND_MAX+1.0)) - dy_d);
00050     T rnd_dtheta =
00051       (T)((2.0*dtheta_d)*(vcl_rand()/(RAND_MAX+1.0)) - dtheta_d);
00052     T rnd_ds = (T)((2.0*ds_d)*(vcl_rand()/(RAND_MAX+1.0)) - ds_d);
00053     rnd_ds += 1.0;
00054     T rnd_da = (T)((2.0*da_d)*(vcl_rand()/(RAND_MAX+1.0)) - da_d);
00055     rnd_da += 1.0;
00056     transform_set[i].set_identity();
00057     transform_set[i].set_rotation(rnd_dtheta);
00058     transform_set[i].set_scale(rnd_ds);
00059     transform_set[i].set_aspect_ratio(rnd_da);
00060     transform_set[i].set_translation(rnd_dx, rnd_dy);
00061   }
00062 }
00063 
00064 template<class T>
00065 void bugl_random_transform_set_2d<T>::
00066 zero_skew_affine_uniform_interval(const unsigned n_trans,
00067                                   vcl_vector<vgl_h_matrix_2d<T> >& trans_set,
00068                                   const T xmin, const T xmax,
00069                                   const T ymin, const T ymax,
00070                                   const T theta_min, const T theta_max,
00071                                   const T scale_min, const T scale_max,
00072                                   const T aspect_min, const T aspect_max)
00073 {
00074   //convert to double
00075   double xmin_d = xmin, xmax_d = xmax, ymin_d = ymin, ymax_d = ymax;
00076   double theta_min_d = theta_min, theta_max_d = theta_max;
00077   double scale_min_d = scale_min, scale_max_d = scale_max;
00078   double aspect_min_d = aspect_min, aspect_max_d = aspect_max;
00079 
00080   trans_set.resize(n_trans);
00081   for (unsigned i = 0; i<n_trans; ++i)
00082   {
00083     //generate random samples of uniform distribution
00084     T rnd_x = (T)((xmax_d-xmin_d)*(vcl_rand()/(RAND_MAX+1.0)) + xmin_d );
00085     T rnd_y = (T)((ymax_d-ymin_d)*(vcl_rand()/(RAND_MAX+1.0)) + ymin_d );
00086     T rnd_theta = (T)((theta_max_d-theta_min_d) *
00087                       (vcl_rand()/(RAND_MAX+1.0)) + theta_min_d );
00088     T rnd_scale = (T)((scale_max_d-scale_min_d) *
00089                       (vcl_rand()/(RAND_MAX+1.0)) + scale_min_d );
00090     T rnd_aspect = (T)((aspect_max_d-aspect_min_d) *
00091                        (vcl_rand()/(RAND_MAX+1.0)) + aspect_min_d );
00092 
00093     trans_set[i].set_identity();
00094     trans_set[i].set_rotation(rnd_theta);
00095     trans_set[i].set_scale(rnd_scale);
00096     trans_set[i].set_aspect_ratio(rnd_aspect);
00097     trans_set[i].set_translation(rnd_x, rnd_y);
00098   }
00099 }
00100 
00101 //----------------------------------------------------------------------------
00102 #undef BUGL_RANDOM_TRANSFORM_SET_2D_INSTANTIATE
00103 #define BUGL_RANDOM_TRANSFORM_SET_2D_INSTANTIATE(T) \
00104 template class bugl_random_transform_set_2d<T >
00105 
00106 #endif // bugl_random_transform_set_2d_txx_

Generated on Sun Sep 7 05:20:42 2008 for contrib/brl/bbas/bugl by  doxygen 1.5.1