Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r36647]: trunk / contrib / brl / bbas / volm / volm_spherical_index_query_matcher.cxx Maximize Restore History

Download this file

volm_spherical_index_query_matcher.cxx    65 lines (60 with data), 3.2 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
#include <volm/volm_spherical_index_query_matcher.h>
#include <vsph/vsph_sph_box_2d.h>
volm_spherical_index_query_matcher::volm_spherical_index_query_matcher(volm_spherical_region_index & index,
volm_spherical_region_query & query,
volm_camera_space_sptr & cam_space)
: index_(index),query_(query), cam_space_(cam_space)
{
}
bool volm_spherical_index_query_matcher::match()
{
volm_spherical_regions_layer index_layer = index_.index_regions();
vcl_vector<volm_spherical_region> i_regions = index_layer.regions();
for ( camera_space_iterator iter = cam_space_->begin(); iter != cam_space_->end(); iter++)
{
cam_angles camera = iter->camera_angles();
unsigned roll_index;
unsigned fov_index;
unsigned head_index;
unsigned tilt_index;
iter->cam_indices(roll_index,fov_index,head_index,tilt_index);
double score = 0.0;
volm_spherical_regions_layer q_regions =query_.query_regions(roll_index);
for (unsigned i = 0; i< q_regions.size(); i++)
{
// transform query_region box
volm_spherical_region query_region = q_regions.regions()[i];
unsigned char qval = 0;
if (!query_region.attribute_value(spherical_region_attributes::ORIENTATION,qval))
continue;
vsph_sph_box_2d qbox = query_region.bbox_ref();
// convert google coordinate axis( z is down and x is north) to spherical coordinate system ( z is up and x is east)
vsph_sph_box_2d qbox_xfomred = qbox.transform(camera.tilt_-cam_space_->tilt_mid(),
camera.heading_-cam_space_->head_mid(),
(camera.top_fov_)/cam_space_->top_fov(0),
180-camera.tilt_,90-camera.heading_,false);
// match it with index bboxes;
vcl_vector<unsigned int> attribute_poly_ids
= index_layer.attributed_regions(spherical_region_attributes::ORIENTATION);
for (unsigned j = 0; j< attribute_poly_ids.size(); j++)
{
volm_spherical_region index_region = i_regions[attribute_poly_ids[j]];
unsigned char ival = 0;
if (!index_region.attribute_value(spherical_region_attributes::ORIENTATION,ival))
continue;
// just considering horizontal and vertical
if (qval >=1 && ival>=2 && qval <= 3 && ival<=9 )
{
vcl_vector<vsph_sph_box_2d> intersection_box ;
if (intersection(qbox_xfomred,index_region.bbox_ref(),intersection_box))
{
for (unsigned k = 0 ; k < intersection_box.size();k++)
score+=intersection_box[k].area()/(qbox_xfomred.area());
}
}
}
}
scores_.push_back(score);
}
return true;
}