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