43 const int ConsistencyGraph::kNoConsistentImageIds = -1;
48 const std::vector<int>&
data)
54 return (data_.size() + map_.size()) *
sizeof(int);
59 const int** image_idxs)
const {
60 const int index = map_(row, col);
61 if (index == kNoConsistentImageIds) {
63 *image_idxs =
nullptr;
65 *num_images = data_.at(index);
66 *image_idxs = &data_.at(index + 1);
71 std::fstream text_file(
path, std::ios::in | std::ios::binary);
72 CHECK(text_file.is_open()) <<
path;
79 text_file >>
width >> unused_char >>
height >> unused_char >> depth >>
81 const std::streampos pos = text_file.tellg();
88 std::fstream binary_file(
path, std::ios::in | std::ios::binary);
89 CHECK(binary_file.is_open()) <<
path;
91 binary_file.seekg(0, std::ios::end);
92 const size_t num_bytes = binary_file.tellg() - pos;
94 data_.resize(num_bytes /
sizeof(
int));
96 binary_file.seekg(pos);
97 ReadBinaryLittleEndian<int>(&binary_file, &data_);
104 std::fstream text_file(
path, std::ios::out);
105 CHECK(text_file.is_open()) <<
path;
106 text_file << map_.cols() <<
"&" << map_.rows() <<
"&" << 1 <<
"&";
109 std::fstream binary_file(
path,
110 std::ios::out | std::ios::binary | std::ios::app);
111 CHECK(binary_file.is_open()) <<
path;
112 WriteBinaryLittleEndian<int>(&binary_file, data_);
116 void ConsistencyGraph::InitializeMap(
const size_t width,
const size_t height) {
118 map_.setConstant(kNoConsistentImageIds);
119 for (
size_t i = 0; i < data_.size();) {
120 const int num_images = data_.at(i + 2);
121 if (num_images > 0) {
122 const int col = data_.at(i);
123 const int row = data_.at(i + 1);
124 map_(row, col) = i + 2;
size_t GetNumBytes() const
void GetImageIdxs(const int row, const int col, int *num_images, const int **image_idxs) const
void Read(const std::string &path)
void Write(const std::string &path) const
static const std::string path