Sarafun Behavior Trees package  1
Behavior trees for the SARAFun project
 All Data Structures Namespaces Functions Variables Enumerations Enumerator
TreeFromKF.hpp
1 #ifndef __TREE_FROM_KF__
2 #define __TREE_FROM_KF__
3 
4 #include <ros/ros.h>
5 #include <ros/package.h>
6 #include <fstream>
7 #include <json/json.hpp>
8 #include <sarafun_msgs/KeyframeMsg.h>
9 
10 using json = nlohmann::json;
11 namespace tree_generator {
12 
14 
23 public:
24  SubTreeFromKF();
26 
33  bool loadLabel(std::string label);
34 
35  /*
36  Creates the subtree for the loaded label, adjusting the id's
37  based on the given indices. Updates the given indices.
38 
39  @param indices Vector of indices that define the number of actions and conditions
40  of a given label that have occurred.
41  @return A JSON node with the JSON description of the subtree defined by the
42  KD label
43  @throw logic_error
44  */
45  json createSubTree(std::vector<int> &indices);
46 
47 private:
48  ros::NodeHandle nh_;
49  json subtree_;
50  std::ifstream file_;
51  bool has_label_;
52  std::string current_id_;
53 
62  json modifyId(json node, std::vector<int> &indices);
63 };
64 
70 {
71 public:
72  TreeFromKF();
74 
81  json createTree(const std::vector<sarafun_msgs::KeyframeMsg> &keyframes_list);
82 
83 private:
84  std::vector<int> indices_; // to keep track of the id's
85 
86  json tree_;
88 
89  void addChildren(const json &tree, std::map<std::string, json> &children_map);
90 };
91 
97 void replaceWithUnderscore(std::string &label);
98 }
99 
100 #endif
void replaceWithUnderscore(std::string &label)
Definition: TreeFromKF.cpp:15
SubTreeFromKF subtree_parser_
Definition: TreeFromKF.hpp:87
bool loadLabel(std::string label)
Definition: TreeFromKF.cpp:26
json createSubTree(std::vector< int > &indices)
Definition: TreeFromKF.cpp:53
json createTree(const std::vector< sarafun_msgs::KeyframeMsg > &keyframes_list)
Definition: TreeFromKF.cpp:119
json modifyId(json node, std::vector< int > &indices)
Definition: TreeFromKF.cpp:77
std::vector< int > indices_
Definition: TreeFromKF.hpp:84
void addChildren(const json &tree, std::map< std::string, json > &children_map)
Definition: TreeFromKF.cpp:151