32 LocalizationQuery::LocalizationQuery(
const std::string& queryName,
const std::string& objectClassName,
int cycleTimeMS,
int priority)
34 this->queryName = queryName;
35 this->className = objectClassName;
36 this->cycleTimeMS = cycleTimeMS;
37 this->priority = priority;
40 std::vector<LocalizationJobPtr> LocalizationQuery::createJobs(
const ObjectClassMemorySegmentBasePtr& objectClassSegment)
42 std::scoped_lock lock(jobsMutex);
44 std::vector<LocalizationJobPtr> jobs;
46 ObjectClassList objectClasses = objectClassSegment->getClassWithSubclasses(className);
49 std::multimap<std::string, std::string> recognitionMethodMap;
50 std::set<std::string> recognitionMethods;
52 for (ObjectClassList::iterator iter = objectClasses.begin() ; iter != objectClasses.end() ; iter++)
56 if (getLocalizableObjectClass(objectClass))
59 std::string recognitionMethod = recognitionWrapper->getRecognitionMethod();
61 recognitionMethodMap.insert(std::make_pair(recognitionMethod, objectClass->getName()));
62 recognitionMethods.insert(recognitionMethod);
67 for (std::set<std::string>::iterator iter = recognitionMethods.begin() ; iter != recognitionMethods.end() ; iter++)
69 std::string recognitionMethod = *iter;
71 std::pair<std::multimap<std::string, std::string>::iterator, std::multimap<std::string, std::string>::iterator> classesForMethod;
72 classesForMethod = recognitionMethodMap.equal_range(recognitionMethod);
74 std::vector<std::string> objectClassNames;
76 for (std::multimap<std::string, std::string>::iterator iter = classesForMethod.first; iter != classesForMethod.second ; iter++)
78 objectClassNames.push_back(iter->second);
86 job =
new LocalizationStrategyOnce();
90 job =
new LocalizationStrategyRepeated(cycleTimeMS);
93 job->init(
this, recognitionMethod, objectClassNames);
95 jobsFinished[recognitionMethod] =
false;
106 std::scoped_lock lock(jobsMutex);
108 if (jobsFinished.size() == 0)
113 bool finished =
true;
115 for (std::map<std::string, bool>::iterator iter = jobsFinished.begin() ; iter != jobsFinished.end() ; iter++)
117 finished &= iter->second;
123 void LocalizationQuery::setJobFinished(std::string recognitionMethod)
125 std::scoped_lock lock(jobsMutex);
126 jobsFinished[recognitionMethod] =
true;
130 ObjectClassPtr LocalizationQuery::getLocalizableObjectClass(
const EntityBasePtr& entity)
138 std::string recognitionMethod = objectRecognitionWrapper->getRecognitionMethod();
141 if ((recognitionMethod !=
"") && (recognitionMethod !=
"<none>"))
147 if (objectClass->getName() !=
"all")
149 ARMARX_WARNING_S <<
"Recognition method for object " << objectClass->getName() <<
" is undefined";
157 ARMARX_WARNING_S <<
"Entity " << entity->getName() <<
" could not be casted to an ObjectClassPtr";