13 int dataset_view::local_filename_x_()
const {
23 int dataset_view::local_filename_y_()
const {
33 std::string dataset_view::format_name(
const std::string& tpl)
const {
34 if(dataset_.
is_2d())
return fmt::format(tpl, fmt::arg(
"x", x_), fmt::arg(
"y", y_));
35 else return fmt::format(tpl, fmt::arg(
"x", x_));
38 std::string dataset_view::format_filename(
const std::string& tpl)
const {
40 if(dataset_.
is_2d()) relpath = fmt::format(tpl, fmt::arg(
"x", local_filename_x_()), fmt::arg(
"y", local_filename_y_()));
41 else relpath = fmt::format(tpl, fmt::arg(
"x", local_filename_x_()));
46 dataset_(datas), x_(x), y_(y), group_(grp) { }
50 if(group_.empty())
return dataset_.
parameters();
56 if(! tpl.empty())
return format_filename(tpl);
61 return format_name(dataset_.
parameters()[
"camera_name_format"]);
83 else throw std::runtime_error(
"no group '" + grp +
"' in dataset");
89 dataset_(datas), group_(grp) { }
92 if(group_.empty())
return dataset_.
parameters();
121 std::size_t last_sep_pos = parameters_filename.find_last_of(
'/');
122 if(last_sep_pos == std::string::npos) dirname_ =
"./";
123 else dirname_ = parameters_filename.substr(0, last_sep_pos + 1);
125 std::ifstream stream(parameters_filename);
126 stream >> parameters_;
128 for(
int v : parameters_[
"x_index_range"]) x_index_range_.push_back(v);
129 if(parameters_.count(
"y_index_range") == 1)
130 for(
int v : parameters_[
"y_index_range"]) y_index_range_.push_back(v);
134 return (y_index_range_.size() == 0);
138 return (y_index_range_.size() > 0);
142 if(relpath.front() ==
'/')
return relpath;
143 #ifdef LICORNEA_OS_WINDOWS 144 if((relpath.size() > 2) && (relpath[1] ==
':'))
return relpath;
150 return filepath(parameters_[
"cameras_filename"]);
154 return parameters_[
"width"];
158 return parameters_[
"height"];
162 return cv::Size(image_width(), image_height());
166 return x_index_range_[0];
170 return x_index_range_[1];
174 if(x_index_range_.size() == 3)
return x_index_range_[2];
179 return (x >= x_min()) && (x <= x_max()) && (((x - x_min()) % x_step()) == 0);
183 return (x_max() - x_min() + x_step()) / x_step();
187 return x_min() + (((x_max() - x_min()) / (2 * x_step())) * x_step());
191 std::vector<int> indices;
192 for(
int x = x_min(); x <= x_max(); x += x_step()) indices.push_back(x);
197 if(is_2d())
return y_index_range_[0];
202 if(is_2d())
return y_index_range_[1];
207 if(is_2d() && (y_index_range_.size() == 3))
return y_index_range_[2];
212 return (y >= y_min()) && (y <= y_max()) && (((y - y_min()) % y_step()) == 0);
216 std::vector<int> indices;
217 for(
int y = y_min(); y <= y_max(); y += y_step()) indices.push_back(y);
222 if(is_2d())
return (y_max() - y_min() + y_step()) / y_step();
227 if(is_2d())
return y_min() + (((y_max() - y_min()) / (2 * y_step())) * y_step());
232 return x_valid(idx.
x) && y_valid(idx.
y);
236 std::vector<view_index> list;
237 for(
int x = x_min(); x <= x_max(); x += x_step())
238 for(
int y = y_min(); y <= y_max(); y += y_step())
239 list.emplace_back(x, y);
244 if(is_2d())
throw std::runtime_error(
"must specify y view index, for 2d dataset");
245 if(! x_valid(x))
throw std::runtime_error(
"x view index out of range");
250 if(! x_valid(x))
throw std::runtime_error(
"x view index out of range");
251 if(! y_valid(y))
throw std::runtime_error(
"y view index out of range");
257 if(! idx.
is_2d())
throw std::runtime_error(
"must specify 2d view index");
258 return view(idx.
x, idx.
y);
260 if(idx.
is_2d() && idx.
y != 0)
throw std::runtime_error(
"must specify 1d view index");
268 else throw std::runtime_error(
"no group '" + grp +
"' in dataset");
283 auto j_idx = explode_from_string<int>(
',', key);
285 if(j_idx.size() == 2) idx.
y = j_idx[1];
291 if(idx.
is_2d()) stream <<
'(' << idx.
x <<
", " << idx.
y <<
')';
292 else stream <<
'(' << idx.
x <<
')';
298 std::cout <<
"loading dataset parameters" << std::endl;
dataset_group(const dataset &, const std::string &grp)
std::string filename_append(const std::string &a, const std::string &b)
bool has(const json &j, const std::string &key)
cv::Size image_size_with_border() const
std::string mask_filename() const
std::string image_filename() const
std::string encode_view_index(view_index idx)
std::string in_filename_arg()
border image_border() const
const json & parameters() const
std::string cameras_filename() const
std::vector< int > y_indices() const
dataset_view view(int x) const
bool x_valid(int x) const
border decode_border(const json &j_bord)
dataset_view group_view(const std::string &name) const
std::ostream & operator<<(std::ostream &, const view_index &)
dataset_view view(int x) const
bool valid(view_index) const
std::string depth_filename() const
dataset(const std::string ¶meters_filename)
bool y_valid(int y) const
std::vector< int > x_indices() const
std::string local_filename(const std::string &name, const std::string &def="") const
const json & parameters() const
std::string group() const
std::string camera_name() const
cv::Size add_border(const border &bord, const cv::Size &sz)
const json & local_parameters() const
std::string to_string(const T &)
view_index decode_view_index(const std::string &key)
cv::Size image_size() const
T get_or(const json &j, const std::string &key, const T &default_value)
std::string filepath(const std::string &relpath) const
dataset_view(const dataset &, int x, int y, const std::string &grp="")
dataset_group group(const std::string &grp) const
std::vector< view_index > indices() const