[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3. Boxm2 IO Package

Chapter summary:
IO and cache for boxm2 data structures.

The boxm2_io sub library has been designed to simplify disk io when running boxm2 algorithms.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1 Disk IO

There are two methods of reading and writing blocks to disk, synchronous and asynchronous. Synchronously reading and writing will block and wait for the read to finish, while asynchronous reading and writing will return immediately, and allow for processing on other data.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1.1 Synchronous IO

The boxm2_sio_mgr provides synchronous reading and writing of boxm2_blocks and boxm2_data_bases, as well as boxm2_data<T>s. The following static methods are implemented:

 
  •  boxm2_block* load_block(vcl_string dir, boxm2_block_id block_id)
    
  •  boxm2_data_base* load_block_data_generic(vcl_string dir, boxm2_block_id id, vcl_string data_type);
    
  •  boxm2_data<T>* load_block_data<T>(vcl_string dir, boxm2_block_id block_id)
    

as well as their writing counterparts:

 
  •  void save_block(vcl_string dir, boxm2_block* block)
    
  •  void save_block_data_base(vcl_string dir, boxm2_block_id block_id, boxm2_data_base* data, vcl_string prefix)
    
  •  void save_block_data<T>(vcl_string dir, boxm2_block_id block_id, boxm2_data<T> * block_data )
    

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1.2 Asynchronous IO

The asynchronous manager handles asynchronous requests, which take the form of baio objects (located in src/contrib/brl/bbas/baio/). These baio objects are implemented in a system-dependent manner. Currently linux and windows baio objects have been implemented and tested. The mac os x baio implementation remains untested.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 Boxm2 Cache

The pure virtual boxm2_cache class provides the following interface:

 
  //: returns block pointer to block specified by ID
  virtual boxm2_block* get_block(boxm2_block_id id) = 0;

  //: returns data_base pointer
  virtual boxm2_data_base* get_data_base(boxm2_block_id, vcl_string type) = 0;

  //: returns data pointer to data specified by ID and data_type
  template <boxm2_data_type T>
  boxm2_data<T>* get_data(boxm2_block_id id);

Different realizations of this abstract class provide different methods of caching boxm2_blocks and boxm2_data_bases. Below is an example of the nearest neighbor cache that we have implemented.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2.1 Example: boxm2_nn_cache

The boxm2_nn_cache maintains two maps, one for boxm2_blocks, and a map of boxm2_data_bases. It also maintains an asynchronous io manager. When a call to get_block or get_data_base is made, the nearest neighbor cache loads any finished asynch requests, searches its cache for the appropriate block, updates its cache by sending out asynchronous requests for any missing neighbors, and then returns the block. The following is its get_block procedure:

 
boxm2_block* boxm2_nn_cache::get_block(boxm2_block_id id)
{
  //first thing to do is to load all async requests into the cache
  this->finish_async_blocks();

  //then look for the block you're requesting
  if ( cached_blocks_.find(id) != cached_blocks_.end() )
  {
    //vcl_cout<<"CACHE HIT!"<<vcl_endl;
    this->update_block_cache(cached_blocks_[id]);
    return cached_blocks_[id];
  

  //vcl_cout<<"Cache miss"<<vcl_endl;
  boxm2_block* loaded = boxm2_sio_mgr::load_block(scene_dir_, id);
  
  //if the block is null then initialize an empty one
  if(!loaded && scene_->block_exists(id)) {
    vcl_cout<<"boxm2_nn_cache::initializing empty block "<<id<<vcl_endl;
    boxm2_block_metadata data = scene_->get_block_metadata(id); 
    loaded = new boxm2_block(data);
  
  
  this->update_block_cache(loaded);
  return loaded;


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated on May, 1 2013 using texi2html 1.76.