[r36136]: trunk / contrib / brl / bseg / boxm2 / volm / tests / test_volm_wr3db_ind.cxx Maximize Restore History

Download this file

test_volm_wr3db_ind.cxx    127 lines (107 with data), 6.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <testlib/testlib_test.h>
#include <boxm2/volm/boxm2_volm_wr3db_index.h>
#include <boxm2/volm/boxm2_volm_wr3db_index_sptr.h>
#include <bbas/volm/volm_spherical_container.h>
#include <bbas/volm/volm_spherical_shell_container.h>
#include <bbas/volm/volm_spherical_shell_container_sptr.h>
#include <vnl/vnl_random.h>
static void test_volm_wr3db_index()
{
// create a much smaller index for testing purposes
float vmin = 2.0f; // min voxel resolution
float dmax = 3000.0f;
float solid_angle = 2.0f;
volm_spherical_container_sptr sph2 = new volm_spherical_container(solid_angle,vmin,dmax);
#if 0
boxm2_volm_wr3db_index_sptr ind = new boxm2_volm_wr3db_index(sph2);
vcl_cout << "number of voxels in container: " << sph2->get_voxels().size() << vcl_endl;
sph2->draw_template("./container.vrml",0.0);
fill the layer after vmin with some depth interval values:
unsigned int offset, end_offset; double depth;
sph2->first_res(sph2->min_voxel_res()*2, offset, end_offset, depth);
vcl_vector<unsigned char> values(end_offset-offset);
vnl_random rng;
for (unsigned i = 0; i+offset < end_offset; ++i)
values[i] = (unsigned char)rng.drand32(1.0,(double)(sph2->get_depth_offset_map().size()-1));
vcl_vector<char> vis_prob;
vis_prob.resize(sph2->get_voxels().size());
boxm2_volm_wr3db_index::inflate_index_vis_and_prob(values, sph2, vis_prob);
sph2->draw_template_vis_prob("./container2.vrml", 0.0, vis_prob);
#endif
volm_spherical_shell_container_sptr sph_shell = new volm_spherical_shell_container(1.0, 90.0, 30.0, 0.0, 0.0);
// test io
int layer_size = (int)sph_shell->get_container_size();
boxm2_volm_wr3db_index_sptr ind = new boxm2_volm_wr3db_index(layer_size, 1.0f);
vcl_vector<unsigned char> vals(layer_size, 0);
vals[0] = 'a'; vals[3] = 'c';
vul_file::delete_file_glob("./test_ind.bin");
TEST("initialize write", ind->initialize_write("./test_ind.bin"), true);
// now fill up the active cache twice! before the second fill the first batch needs to be written to disc
for (unsigned i = 0; i < ind->buffer_size(); i++)
ind->add_to_index(vals);
// the one below should trigger a write to disc
vals[0] = 'b'; vals[layer_size-1] = 'd';
TEST("add to index", ind->add_to_index(vals), true);
unsigned char *vals_buf = new unsigned char[layer_size];
vals_buf[0] = 'e'; vals_buf[layer_size-1] = 'f';
TEST("add to index", ind->add_to_index(vals_buf), true);
vcl_cout << "global id: " << ind->current_global_id() << " current active cache id: " << ind->current_id() << vcl_endl;
TEST("finalize write", ind->finalize(), true);
boxm2_volm_wr3db_index_sptr ind2 = ind;
// initialize_read() finalizes write operations in case there is any active write operation
TEST("initialize read", ind2->initialize_read("./test_ind.bin"), true);
TEST("global id", ind2->current_global_id(), 0);
vcl_vector<unsigned char> vals2(layer_size);
TEST("getting the first index", ind2->get_next(vals2), true);
TEST("test index 0", vals2[0] == 'a', true);
TEST("test index 0", vals2[3] == 'c', true);
for (unsigned i = 0; i < ind->buffer_size()-1; i++)
ind2->get_next(vals2);
ind2->get_next(vals2);
vcl_vector<unsigned char> vals_buf2(layer_size);
ind2->get_next(vals_buf2);
TEST("test index end", vals_buf2[0] == 'e', true);
TEST("test index end", vals_buf2[layer_size-1] == 'f', true);
TEST("finalize read", ind2->finalize(), true);
}
TESTMAIN(test_volm_wr3db_index);
#if 0
float vmin = 10.0f; // min voxel resolution
float dmax = 60000.0f;
float solid_angle = 4.0f;
volm_spherical_container_sptr sph = new volm_spherical_container(solid_angle,vmin,dmax);
vcl_vector<volm_voxel>& voxels = sph->get_voxels();
int data_size = 1; // 1 byte if only vis values will be indexed, otherwise its 2 bytes
double ind_size = voxels.size()*data_size/1048576.0; // in MBs
vcl_cout << "number of voxels in container: " << voxels.size() << " size of voxel array for " << data_size << " bytes: " << ind_size << " MB" << vcl_endl;
double inc = 10.0;
double num = (100000/inc)*(100000/inc);
vcl_cout << " for 100 km size WR (in each size) for every " << inc << "m there are: " << num << " location hypotheses\n"
<< " then the index size on file is: " << num*ind_size << " MBs = " << num*ind_size/1024 << " GBs = " << num*ind_size/1048576 << " TBs.\n";
unsigned int offset, end_offset; double d;
//sph->first_res(sph->min_voxel_res()*2, offset, end_offset, d);
sph->last_res(vmin, offset, end_offset, d);
vcl_cout << " last layer with vmin res is at depth: " << d << " and has offset: " << offset << " end_offset: " << end_offset << '\n'
<< "first voxel: " << sph->get_voxels()[offset].center_ << ' ' << sph->get_voxels()[offset].resolution_ << '\n'
<< "last voxel: " << sph->get_voxels()[end_offset-1].center_ << ' ' << sph->get_voxels()[end_offset-1].resolution_ << '\n'
<< "after last voxel: " << sph->get_voxels()[end_offset].center_ << ' ' << sph->get_voxels()[end_offset].resolution_ << vcl_endl;
unsigned int size = end_offset-offset;
vcl_cout << "size is: " << size << vcl_endl;
ind_size = size*sizeof(float)*2*num/1048576.0; // in MBs
vcl_cout << "if we index 2 floats for this layer each location index is of size: "<< size*sizeof(float)*2/1048576.0 << " MBs, for all locs, size is: "<< ind_size << " MB = " << ind_size/1024 << " GB\n"
<< "if we index 1 floats for this layer each location index is of size: "<< size*sizeof(float)/1048576.0 << " MBs, for all locs, size is: "<< ind_size/2 << " MB = " << ind_size/2048 << " GB\n"
<< "if we index 1 unsigned short for this layer, each location index is of size: "<< size*sizeof(unsigned short)/1048576.0 << " MBs, for all locs, size is: "<< size*num*sizeof(unsigned short)/1048576.0 << " MBs = " << size*num*sizeof(unsigned short)/1048576.0/1024 << " GBs\n";
#endif
#if 0
// use hypotheses to generate index
boxm2_volm_wr3db_index_sptr ind = new boxm2_volm_wr3db_index(sph);
ind->index_locations(scene, h);
vcl_string out_name = out_file() + "_volm_index_" + tiles[i].get_string() + ".bin";
if (!ind->write_index(out_name))
vcl_cerr << "Problems writing index: " << out_name << vcl_endl;
for (unsigned i = 0; i < tiles.size(); i++) {
vcl_string name = out_file() + "_volm_index_" + tiles[i].get_string() + ".bin";
boxm2_volm_wr3db_index_sptr ind = new boxm2_volm_wr3db_index(sph);
ind->read_index(name);
}
#endif