LocalizationJobContainer.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package MemoryX::Core
17* @author Kai Welke <welke@kit.edu>
18* @copyright 2012 Kai Welke
19* @license http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#pragma once
24
25#include <string>
26
27#include <Eigen/Eigen>
28
29#include <Ice/Ice.h>
30
31#include <RobotAPI/interface/core/RobotState.h>
33
35
36namespace memoryx
37{
40
41 /**
42 * @brief The LocalizationJobContainer class is used by ObjectLocalizationMemoryUpdater to create and execute segmentation specific groups of localization jobs.
43 */
44 class LocalizationJobContainer : public Ice::LocalObject
45 {
46 public:
47 LocalizationJobContainer(const std::string& recognitionMethod) :
48 recognitionMethod(recognitionMethod)
49 {
50 robotPose = new armarx::Pose(Eigen::Matrix4f::Identity());
51 }
52
54 {
55 try
56 {
57 if (this->robotStatePrx)
58 {
59 this->robotStatePrx->unref();
60 }
61 }
62 catch (...)
63 {
64 }
65 }
66
67 void
69 {
70 jobs.push_back(job);
71
72 std::vector<std::string> jobClassNames = job->getClassNamesToBeLocalized();
73
74 for (std::vector<std::string>::iterator iterNames = jobClassNames.begin();
75 iterNames != jobClassNames.end();
76 iterNames++)
77 {
78 classNamesUnique.insert(*iterNames);
79 }
80 }
81
82 /**
83 * @brief startJobs calls the LocalizationJob::start() method on all jobs added via LocalizationJobContainer::addJob().
84 */
85 void
87 {
88 for (LocalizationJobList::iterator iter = jobs.begin(); iter != jobs.end(); iter++)
89 {
90 (*iter)->start();
91 }
92 }
93
94 /**
95 * @brief finishJobs sets the finished property of all localization jobs to true
96 *
97 * This results in LocalizationQuery::getFinished() to return true, indicating that all localization jobs have finished running.
98 * Calls LocalizationJob::setFinished() on each job added via LocalizationJobContainer::addJob().
99 */
100 void
102 {
103 for (LocalizationJobList::iterator iter = jobs.begin(); iter != jobs.end(); iter++)
104 {
105 (*iter)->setFinished();
106 }
107 }
108
109 std::vector<std::string>
111 {
112 std::vector<std::string> classNames;
113 std::copy(
114 classNamesUnique.begin(), classNamesUnique.end(), std::back_inserter(classNames));
115
116 return classNames;
117 }
118
119 std::vector<LocalizationQueryPtr>
121 {
122 std::vector<LocalizationQueryPtr> queries;
123
124 for (LocalizationJobList::iterator iter = jobs.begin(); iter != jobs.end(); iter++)
125 {
126 queries.push_back((*iter)->getQuery());
127 }
128
129 return queries;
130 }
131
132 std::string
134 {
135 return recognitionMethod;
136 }
137
138 void
140 {
141 if (this->robotStatePrx)
142 {
143 this->robotStatePrx->unref();
144 }
145
146 this->robotStatePrx = robotStatePrx;
147
148 if (this->robotStatePrx)
149 {
150 this->robotStatePrx->ref();
151 }
152 }
153
156 {
157 return robotStatePrx;
158 }
159
160 void
162 {
163 this->robotPose = robotPose;
164 }
165
168 {
169 return robotPose;
170 }
171
172
173 private:
175 std::set<std::string> classNamesUnique;
176 std::string recognitionMethod;
178 armarx::PosePtr robotPose;
179 };
180
182} // namespace memoryx
The Pose class.
Definition Pose.h:243
void addJob(const LocalizationJobPtr &job)
void setRobotPose(const armarx::PosePtr &robotPose)
void setRobotState(const armarx::SharedRobotInterfacePrx &robotStatePrx)
std::vector< std::string > getClassNamesUnique()
std::vector< LocalizationQueryPtr > getQueries()
void startJobs()
startJobs calls the LocalizationJob::start() method on all jobs added via LocalizationJobContainer::a...
armarx::SharedRobotInterfacePrx getRobotState()
LocalizationJobContainer(const std::string &recognitionMethod)
void finishJobs()
finishJobs sets the finished property of all localization jobs to true
The LocalizationQuery class is used to create LocalizationJob instances and provide an interface to q...
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
::IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface > SharedRobotInterfacePrx
Definition FramedPose.h:59
VirtualRobot headers.
IceUtil::Handle< LocalizationJobContainer > LocalizationJobContainerPtr
IceInternal::Handle< LocalizationQuery > LocalizationQueryPtr
std::vector< LocalizationJobPtr > LocalizationJobList
IceUtil::Handle< LocalizationJob > LocalizationJobPtr