contrib/brl/bseg/brip/brip_quadtree_utils.h
Go to the documentation of this file.
00001 #ifndef brip_quadtree_utils_h
00002 #define brip_quadtree_utils_h
00003 //-----------------------------------------------------------------
00004 //:
00005 // \file
00006 // \author  J.L. Mundy March 8, 2008
00007 // \brief brip_quadtree_utils - Various utilities using quadtrees
00008 //
00009 // \verbatim
00010 //  Modifications:
00011 //   None
00012 // \endverbatim
00013 //------------------------------------------------------------------
00014 #include <vcl_vector.h>
00015 #include <vcl_iostream.h>
00016 #include <vil/vil_image_view.h>
00017 #include <brip/brip_quadtree_node.h>
00018 #include <vbl/vbl_array_2d.h>
00019 
00020 template <class T>
00021 class brip_quadtree_utils
00022 {
00023  public:
00024   //: Given a leaf quadtree node, fill the corresponding image region with its value -- the base case
00025   static void fill_image_region(brip_quadtree_node_base_sptr node,
00026                                 vil_image_view<T>& img);
00027 
00028   //: Given a tree root, recursively fill the image values according to the tree nodes
00029   static void fill_image_from_node(brip_quadtree_node_base_sptr node,
00030                                    vil_image_view<T>& img);
00031 
00032   //: Construct an array of quadtree nodes from an image and a parent image
00033   //  The masks determine if a pixel is to be included in the tree
00034   //  Scale is the ratio of the child resolution to the parent resolution,
00035   //  e.g. scale = 2 indicates that the dimensions of the child are twice
00036   //  that of the parent.
00037   static void
00038     extract_nodes_from_image(vil_image_view<T> const & img,
00039                              vil_image_view<bool> const & mask,
00040                              vil_image_view<T> const& parent_img,
00041                              vil_image_view<bool> const& parent_mask,
00042                              unsigned scale,
00043                              vbl_array_2d<brip_quadtree_node_base_sptr>& nodes);
00044 
00045 //: given two layers of a pyramid of quadtree nodes, establish the parent-child links
00046 static void connect_children(vbl_array_2d<brip_quadtree_node_base_sptr>& nodes,
00047                              unsigned scale,
00048                              vbl_array_2d<brip_quadtree_node_base_sptr> const& prev);
00049 
00050 //: Construct the quadtree from an image pyramid, with masks defined for each pyramid layer
00051 static
00052 void quadtrees_from_pyramid(vcl_vector<vil_image_view<T> > levels,
00053                             vcl_vector<vil_image_view<bool> > masks,
00054                             vbl_array_2d<brip_quadtree_node_base_sptr>& roots);
00055 
00056 //: Recursively print all the levels of the quadtree below the node
00057  static void print_node( brip_quadtree_node_base_sptr const& node,
00058                          vcl_ostream& os = vcl_cout,
00059                          vcl_string indent = "");
00060 };
00061 
00062 
00063 #define BRIP_QUADTREE_UTILS_INSTANTIATE(T) extern "please include brip_quadtree_utils.txx first"
00064 
00065 
00066 #endif