licornea_tools
straight_depths.cc
Go to the documentation of this file.
1 #include "straight_depths.h"
2 
3 namespace tlz {
4 
6  json j_depths = json::object();
7  for(const auto& kv : depths) {
8  const std::string& feature_name = kv.first;
9  const straight_depth& depth = kv.second;
10  json j_depth = json::object();
11  if(std::isnan(depth.depth)) continue;
12  j_depth["depth"] = depth.depth;
13  j_depth["confidence"] = depth.confidence;
14  j_depths[feature_name] = j_depth;
15  }
16  return j_depths;
17 }
18 
19 
21  straight_depths depths;
22  for(auto it = j_depths.begin(); it != j_depths.end(); ++it) {
23  const std::string& feature_name = it.key();
24  const json& j_depth = it.value();
25  if(j_depth.is_number())
26  depths[feature_name] = straight_depth(real(j_depth));
27  else
28  depths[feature_name] = straight_depth(j_depth["depth"], get_or(j_depth, "confidence", 1.0));
29  }
30  return depths;
31 }
32 
33 
36 }
37 
38 
39 }
json encode_straight_depths(const straight_depths &depths)
straight_depths decode_straight_depths(const json &j_depths)
json json_arg()
Definition: json.h:34
std::map< std::string, straight_depth > straight_depths
double real
Definition: common.h:16
straight_depths straight_depths_arg()
nlohmann::json json
Definition: json.h:11
T get_or(const json &j, const std::string &key, const T &default_value)
Definition: json.h:28