Domain.cpp
Go to the documentation of this file.
1 
19 #include "Domain.h"
20 #include <boost/lexical_cast.hpp>
21 #include <boost/algorithm/string.hpp>
22 #include <fstream>
23 #include <chrono>
24 #include <ctime>
25 
26 
28 {
30 }
31 
33 {
34 }
35 
37 {
38  //Calculate intermediate object ranking for each object in each scene
39  for (std::vector<SceneSharedPointer>::iterator sceneIterator = SceneList.begin(); sceneIterator != SceneList.end(); ++sceneIterator)
40  {
41  (*sceneIterator)->getObjectFromDb();
42  (*sceneIterator)->calcAveragePositionForEachObject();
43  (*sceneIterator)->calcPresenceInSceneForEachObject();
44  (*sceneIterator)->getObjectAverageDistance();
45  (*sceneIterator)->normalize();
46  (*sceneIterator)->rank();
47  (*sceneIterator)->displayStats();
48  }
49  std::list<evalulatorTupleSharedPtr> evaluatorTupleList;
50  std::list<std::string> sceneList;
51  ROS_DEBUG_STREAM("Domain::calcIntermediateObjectsForDomain begin scene fusion");
52  //Creation of an evaluator tuple for all object in all scenes. (1 evaluator tuple per object per scene)
53  for (std::vector<SceneSharedPointer>::iterator sceneIterator = SceneList.begin(); sceneIterator != SceneList.end(); ++sceneIterator)
54  {
55  std::string sceneName = (*sceneIterator)->getSceneName();
56  sceneList.push_back(sceneName);
57  std::unordered_map<std::string,ObjectSharedPointer> bufferObjectMap = (*sceneIterator)->getObjectMap();
58  for (std::unordered_map<std::string,ObjectSharedPointer>::iterator objectMapIterator=bufferObjectMap.begin(); objectMapIterator!=bufferObjectMap.end(); ++objectMapIterator)
59  {
60  evaluatorTupleList.push_back(evalulatorTupleSharedPtr(new evalulatorTuple(objectMapIterator->second->getRankValue(),sceneName,objectMapIterator->first,
61  objectMapIterator->second->getObjectName(),objectMapIterator->second->getObservedId())));
62  }
63  }
64  ROS_DEBUG_STREAM("Domain::calcIntermediateObjectsForDomain scene fusion completed");
65  ROS_DEBUG_STREAM("Domain::calcIntermediateObjectsForDomain begin from evaluation");
66  Evaluator evaluator = Evaluator(evaluatorTupleList,sceneList,GainValueThreshold,NBVPath,Scene_path);
68  ROS_DEBUG_STREAM("Domain::calcIntermediateObjectsForDomain end from evaluation");
69 }
70 
72 {
73  LocalHandle.getParam(LocalHandle.getNamespace() + "/asr_intermediate_object_generator/RankingMethod",RankingMethod);
74  LocalHandle.getParam(LocalHandle.getNamespace() + "/asr_intermediate_object_generator/Alpha",Alpha);
75  LocalHandle.getParam(LocalHandle.getNamespace() + "/asr_intermediate_object_generator/Beta",Beta);
76  LocalHandle.getParam(LocalHandle.getNamespace() + "/asr_intermediate_object_generator/Gamma",Gamma);
77  LocalHandle.getParam(LocalHandle.getNamespace() + "/asr_intermediate_object_generator/GainValueThreshold",GainValueThreshold);
78  LocalHandle.getParam(LocalHandle.getNamespace() + "/asr_intermediate_object_generator/DomainName",DomainName);
79  LocalHandle.getParam(LocalHandle.getNamespace() + "/asr_intermediate_object_generator/AutomatPath", AutomatPath);
80  LocalHandle.getParam(LocalHandle.getNamespace() + "/asr_intermediate_object_generator/LogPath", LogPath);
81  LocalHandle.getParam(LocalHandle.getNamespace() + "/asr_intermediate_object_generator/NBVPath", NBVPath);
82 
83  LocalHandle.getParam(LocalHandle.getNamespace() + "/asr_intermediate_object_generator/dbfilename", Scene_path);
84 
85 
86  std::vector<std::string> pathSplit;
87  boost::split(pathSplit, Scene_path, boost::is_any_of("/"));
88  std::string dbName = pathSplit[pathSplit.size()-1];
89 
90  const std::string placeholder = "XXX";
91  std::string::size_type pos;
92  if ((pos = AutomatPath.find(placeholder)) != std::string::npos) {
93  AutomatPath.replace(pos, placeholder.length(), dbName);
94  }
95 
96  if ((pos = NBVPath.find(placeholder)) != std::string::npos) {
97  NBVPath.replace(pos, placeholder.length(), dbName);
98  }
99 
100 
101  ROS_DEBUG_STREAM("Domain::getDomainFromParams BEGIN");
102  ROS_DEBUG_STREAM("Domain::getDomainFromParams RankingMethod : " << RankingMethod);
103  ROS_DEBUG_STREAM("Domain::getDomainFromParams Alpha : " << Alpha);
104  ROS_DEBUG_STREAM("Domain::getDomainFromParams Beta : " << Beta);
105  ROS_DEBUG_STREAM("Domain::getDomainFromParams Gamma : " << Gamma);
106  ROS_DEBUG_STREAM("Domain::getDomainFromParams GainValueThreshold : " << GainValueThreshold);
107  ROS_DEBUG_STREAM("Domain::getDomainFromParams AutomatPath : " << AutomatPath);
108  ROS_DEBUG_STREAM("Domain::getDomainFromParams LogPath : " << LogPath);
109  ROS_DEBUG_STREAM("Domain::getDomainFromParams NBVPath : " << NBVPath);
110 
111 
112  ISM::TableHelper tabelHelper(Scene_path);
113  std::vector<std::string> Scene_patterns = tabelHelper.getRecordedPatternNames();
114  for(const std::string &name : Scene_patterns)
115  {
117  ROS_DEBUG_STREAM("Domain::getDomainFromParams Adding scene : " << name);
118  ROS_DEBUG_STREAM("Domain::getDomainFromParams with path : " << Scene_path);
119  }
120  ROS_DEBUG_STREAM("Domain::getDomainFromParams END");
121 }
122 
124 {
125  //Publish logs in the log file folder.
126  std::chrono::time_point<std::chrono::system_clock> start;
127  start = std::chrono::system_clock::now();
128  std::time_t start_time = std::chrono::system_clock::to_time_t(start);
129  std::string filePath = this->LogPath + this->DomainName + ".log";
130  std::ofstream file(filePath, std::ios::out | std::ios::app);
131  if(file)
132  {
133  file << std::endl <<this->DomainName << " Log file" << std::endl;
134  file << "Timestamp for the Log " << std::ctime(&start_time) << std::endl;
135  file << std::endl << "Intermediate Objects for The Domain " << std::endl;
136  for (const objectTupleSharedPtr &tuple : IntermediateOjects)
137  {
138  file << std::get<1>(*tuple) << " : " << std::get<0>(*tuple) << std::endl;
139  }
140  file.close();
141  }
142  for (std::vector<SceneSharedPointer>::iterator sceneIterator = SceneList.begin(); sceneIterator != SceneList.end(); ++sceneIterator)
143  {
144  (*sceneIterator)->publishLogs(filePath);
145  }
146 }
147 
149 {
150  //Publish the XML data containing intermediate object for the direct search.
151  std::string output = "<InterObj>";
152  for (const objectTupleSharedPtr &tuple : IntermediateOjects)
153  {
154  output += "<obj type=\"" + std::get<2>(*tuple) + "\" identifier=\""+ std::get<3>(*tuple) + "\"/>";
155  }
156  output += "</InterObj>";
157  std::ofstream file(AutomatPath, std::ios::out | std::ios::trunc);
158  if(file)
159  {
160  file << output;
161  file.close();
162  }
163 }
ROSCPP_DECL void start()
std::shared_ptr< objectTuple > objectTupleSharedPtr
Definition: Evaluator.h:35
std::vector< SceneSharedPointer > SceneList
Definition: Domain.h:30
std::string Scene_path
Definition: Domain.h:39
Domain()
Definition: Domain.cpp:27
std::list< objectTupleSharedPtr > getIntermediateObjects()
Definition: Evaluator.cpp:127
void getDomainFromParams()
Definition: Domain.cpp:71
std::string AutomatPath
Definition: Domain.h:38
void publishLogs()
Definition: Domain.cpp:123
virtual ~Domain()
Definition: Domain.cpp:32
std::list< objectTupleSharedPtr > IntermediateOjects
Definition: Domain.h:40
void calcIntermediateObjectsForDomain()
Definition: Domain.cpp:36
double Gamma
Definition: Domain.h:35
double GainValueThreshold
Definition: Domain.h:31
const std::string & getNamespace() const
void publishIntermediateObjectToAutomat()
Definition: Domain.cpp:148
std::string NBVPath
Definition: Domain.h:37
#define ROS_DEBUG_STREAM(args)
double Alpha
Definition: Domain.h:33
std::string DomainName
Definition: Domain.h:29
std::string LogPath
Definition: Domain.h:36
Definition: Scene.h:33
bool getParam(const std::string &key, std::string &s) const
double Beta
Definition: Domain.h:34
std::tuple< double, std::string, std::string, std::string, std::string > evalulatorTuple
Definition: Evaluator.h:31
int RankingMethod
Definition: Domain.h:32
std::shared_ptr< Scene > SceneSharedPointer
Definition: Domain.h:25
ros::NodeHandle LocalHandle
Definition: Domain.h:41
std::shared_ptr< evalulatorTuple > evalulatorTupleSharedPtr
Definition: Evaluator.h:32


asr_intermediate_object_generator
Author(s): Borella Jocelyn, Mei├čner Pascal
autogenerated on Thu Nov 21 2019 03:53:41