vocabtree  0.0.1
MatchesPage Class Reference

MatchesPage class keeps track of query images and their matches, and outputs an html page containing these matches for visualization purposes. More...

#include <matches_page.hpp>

Public Member Functions

 MatchesPage (uint32_t max_matches_per_page=16, uint32_t max_images_per_match=16)
 Ctor, max_matches_per_page specified the max number of rows per page, if this is set too high, the web browser might have problems loading the page. More...
 
 ~MatchesPage ()
 
void add_match (uint32_t query_id, std::vector< uint64_t > &match_ids, const Dataset &dataset, std::shared_ptr< std::vector< int > > validated=nullptr)
 Adds a match to the html_strings variable which will be written as html on write(). More...
 
void write (const std::string &folder) const
 Writes out all the html match mages to the input specified folder. More...
 

Protected Member Functions

std::string stylesheet () const
 
std::string header () const
 Returns a string containing css stylesheet. More...
 
std::string footer () const
 Returns a string containing the html header. More...
 
std::string navbar (uint32_t cur_page, uint32_t max_pages) const
 Returns a string containing the html footer. More...
 
std::string pagename (uint32_t cur_page) const
 Returns a string containing the navbar needed for pagination. More...
 

Protected Attributes

std::vector< std::string > html_strings
 Returns a string containing the pagename (ex. matches_00001.html) More...
 
uint32_t max_matches_per_page_
 Holds the html strings for each match passed into add_match. More...
 
uint32_t max_images_per_match_
 

Detailed Description

MatchesPage class keeps track of query images and their matches, and outputs an html page containing these matches for visualization purposes.

Definition at line 8 of file matches_page.hpp.

Constructor & Destructor Documentation

MatchesPage::MatchesPage ( uint32_t  max_matches_per_page = 16,
uint32_t  max_images_per_match = 16 
)

Ctor, max_matches_per_page specified the max number of rows per page, if this is set too high, the web browser might have problems loading the page.

max_images_per_match specifies the max number of images in each row. If this is set too high, the web browser might have problems loading the page.

Definition at line 10 of file matches_page.cxx.

References max_images_per_match_, and max_matches_per_page_.

10  {
11  max_matches_per_page_ = max_matches_per_page;
12  max_images_per_match_ = max_images_per_match;
13 }
MatchesPage::~MatchesPage ( )

Definition at line 15 of file matches_page.cxx.

15  {
16 
17 }

Member Function Documentation

void MatchesPage::add_match ( uint32_t  query_id,
std::vector< uint64_t > &  match_ids,
const Dataset dataset,
std::shared_ptr< std::vector< int > >  validated = nullptr 
)

Adds a match to the html_strings variable which will be written as html on write().

The query_id is the id of the image query. match_ids are the ids of the matches. Finally, dataset is used to figure out the image paths. If validated vector is provided, the web page will highlight validated matches, values should be zero if unvalidated,

0 if validated, and < 0 if failed validation. The validation vector can be smaller

than the size of match_ids, in which case it is assumed to correspond to beginning of match_ids.

Definition at line 19 of file matches_page.cxx.

References html_strings, Dataset::image(), Dataset::location(), and max_images_per_match_.

Referenced by bench_oxford(), benchmark_dataset(), and main().

20  {
21 
22  std::stringstream html_string;
23  html_string << "<table><tr>";
24  html_string << "<td><img src='" << dataset.location(dataset.image(query_id)->location()) << "' /></td><td> </td>";
25  for(size_t i=0; i< MIN(match_ids.size(), max_images_per_match_); i++) {
26  std::shared_ptr<Image> image = dataset.image(match_ids[i]);
27  const std::string &impath = dataset.location(image->location());
28  if(validated == nullptr || i >= validated->size()) {
29  html_string << "<td><img src='" << impath << "' /></td>";
30  } else {
31  std::stringstream borderstr;
32  borderstr << "border: 1px solid " << ((*validated)[i] > 0 ? "green" : ((*validated)[i] == 0 ? "black" : "red"));
33  html_string << "<td><img src='" << impath << "' style='" << borderstr.str() << "' /></td>";
34  }
35  }
36  html_string << "</tr></table>";
37  html_strings.push_back(html_string.str());
38 }
std::string MatchesPage::footer ( ) const
protected

Returns a string containing the html header.

Definition at line 113 of file matches_page.cxx.

Referenced by write().

113  {
114  std::string footer_str = R"( </body> </html> )";
115  return footer_str;
116 }
117 
std::string MatchesPage::header ( ) const
protected

Returns a string containing css stylesheet.

Definition at line 102 of file matches_page.cxx.

Referenced by write().

102  {
103  std::string header_str = R"( <html> <head> <link rel='stylesheet' type='text/css' href=')" + s_stylesheet_name + R"(' /> </head> <body> )";
104  return header_str;
105 }
106 
std::string MatchesPage::navbar ( uint32_t  cur_page,
uint32_t  max_pages 
) const
protected

Returns a string containing the html footer.

Definition at line 121 of file matches_page.cxx.

Referenced by write().

121  {
122  std::stringstream navbar_str;
123  navbar_str << "<table><tr>";
124  for(uint32_t i=0; i<max_pages; i++) {
125  navbar_str << "<td><a href='" << pagename(i) << "'>" << i << "</a></td>";
126  }
127  navbar_str << "</tr></table>";
128  return navbar_str.str();
129 }
std::string MatchesPage::pagename ( uint32_t  cur_page) const
protected

Returns a string containing the navbar needed for pagination.

Definition at line 64 of file matches_page.cxx.

Referenced by write().

64  {
65  std::stringstream current_page_name;
66  current_page_name << "matches_" << std::setw(5) << std::setfill('0') << cur_page << ".html";
67  return current_page_name.str();
68 }
std::string MatchesPage::stylesheet ( ) const
protected

Definition at line 70 of file matches_page.cxx.

Referenced by write().

70  {
71  std::string stylesheet_str = R"( body { margin: 0px; color : #fcfcfc; background: #111; font-size: 14px; font-family: sans-serif; } table { margin: 5px; border: 2px solid #fcfcfc; border-spacing: 0; border-collapse: collapse; } a { color: #fff; text-decoration: none; font-weight: bold; } img { height: 120px; } )";
72  return stylesheet_str;
73 }
74 
void MatchesPage::write ( const std::string &  folder) const

Writes out all the html match mages to the input specified folder.

The first page will look something like folder/matches_00000.html.

Definition at line 40 of file matches_page.cxx.

References filesystem::create_file_directory(), filesystem::file_exists(), footer(), header(), html_strings, max_images_per_match_, max_matches_per_page_, navbar(), pagename(), s_stylesheet_name, stylesheet(), and filesystem::write_text().

Referenced by bench_oxford(), benchmark_dataset(), and main().

40  {
41  if(!filesystem::file_exists(folder)) {
42  filesystem::create_file_directory(folder + "/index.html");
43  }
44 
45  // style sheet
46  const std::string stylesheet_string = this->stylesheet();
47  filesystem::write_text(folder + "/" + s_stylesheet_name, stylesheet_string);
48 
49  for(size_t i=0; i<html_strings.size(); i+=max_matches_per_page_) {
50  uint32_t cur_page = i / max_images_per_match_;
51  std::stringstream current_page_str;
52  current_page_str << header();
53  current_page_str << navbar(cur_page, html_strings.size() / max_matches_per_page_ + 1);
54 
55  for(size_t j=i; j<MIN(html_strings.size(), i+max_matches_per_page_); j++) {
56  current_page_str << html_strings[j];
57  }
58  current_page_str << footer();
59 
60  filesystem::write_text(folder + "/" + this->pagename(cur_page), current_page_str.str());
61  }
62 }

Field Documentation

std::vector<std::string> MatchesPage::html_strings
protected

Returns a string containing the pagename (ex. matches_00001.html)

Definition at line 39 of file matches_page.hpp.

Referenced by add_match(), and write().

uint32_t MatchesPage::max_images_per_match_
protected

Definition at line 41 of file matches_page.hpp.

Referenced by add_match(), MatchesPage(), and write().

uint32_t MatchesPage::max_matches_per_page_
protected

Holds the html strings for each match passed into add_match.

Definition at line 41 of file matches_page.hpp.

Referenced by MatchesPage(), and write().


The documentation for this class was generated from the following files: