contrib/brl/bbas/bvgl/bvgl_ray_pyramid.cxx
Go to the documentation of this file.
00001 //:
00002 // \file
00003 #include "bvgl_ray_pyramid.h"
00004 
00005 //construct pyramid from finest level
00006 bvgl_ray_pyramid::bvgl_ray_pyramid(vbl_array_2d<vgl_ray_3d<float> >& finest_level, unsigned numLevels)
00007 {
00008   if (finest_level.rows() != finest_level.cols()) {
00009     vcl_cerr << "bvgl_ray_pyramid input not square\n";
00010   }
00011 
00012   //side length
00013   vbl_array_2d<vgl_ray_3d<float> > level0(finest_level);
00014   pyramid_.push_back(level0);
00015 
00016   //create the levels
00017   for (unsigned int l=1; l<numLevels; ++l) {
00018     vbl_array_2d<vgl_ray_3d<float> > scaled = scale_down(pyramid_[l-1]);
00019     pyramid_.push_back(scaled);
00020   }
00021 }
00022 
00023 vbl_array_2d<vgl_ray_3d<float> > bvgl_ray_pyramid::scale_down(vbl_array_2d<vgl_ray_3d<float> >& toScale)
00024 {
00025   //initialize new half size ray image
00026   vcl_size_t side_len = toScale.rows()/2;
00027   vbl_array_2d<vgl_ray_3d<float> > scaled(side_len, side_len);
00028 
00029   //go through and average the vectors
00030   for (unsigned int i=0; i<side_len; ++i) {
00031     for (unsigned int j=0; j<side_len; ++j) {
00032       //get 2x2 patch
00033       vgl_vector_3d<float> dir(0.0, 0.0, 0.0);
00034       for (int prevI=0; prevI<2; ++prevI)
00035         for (int prevJ=0; prevJ<2; ++prevJ)
00036           dir = dir + toScale(2*i+prevI, 2*j+prevJ).direction();
00037       normalize(dir);
00038       scaled(i,j) = vgl_ray_3d<float>( toScale(2*i, 2*j).origin(), dir );
00039     }
00040   }
00041   return scaled;
00042 }
00043