29 #include <visualization_msgs/Marker.h> 33 #include <asr_msgs/AsrObject.h> 35 #include <asr_ism_visualizations/ObjectModelVisualizerRVIZ.hpp> 38 #include <ISM/utility/TableHelper.hpp> 39 #include <ISM/common_type/ObjectSet.hpp> 40 #include <ISM/common_type/RecordedPattern.hpp> 41 #include <ISM/utility/Util.hpp> 61 std::string objectTopic;
62 std::string dbfilename;
63 std::string visualizationTopic;
70 mTableHelper = ISM::TableHelperPtr (
new ISM::TableHelper (dbfilename));
73 ISM::printRed(
"The database \"" + dbfilename +
"\" doesn't contain any recordings!\n");
89 else if (usedPattern > numberOfPatterns)
91 usedPattern = numberOfPatterns;
92 ROS_INFO_STREAM(
"usedPattern is greater than " << (numberOfPatterns) <<
", setting it to " << numberOfPatterns <<
" now.");
94 int numberOfSets =
mObjectSets[usedPattern-1].size();
95 if (numberOfSets <= 0)
102 if (firstUsedSet < 1)
105 ROS_INFO_STREAM(
"firstUsedSet is smaller than 1, setting it to 1 now.");
107 else if (firstUsedSet > numberOfSets)
109 firstUsedSet = numberOfSets ;
110 ROS_INFO_STREAM(
"firstUsedSet is greater than numberOfSets(" << (numberOfSets) <<
"), setting it to " << firstUsedSet <<
" now.");
117 ROS_INFO_STREAM(
"lastUsedSet is smaller than 1, setting it to 1 now.");
119 else if (lastUsedSet > numberOfSets)
121 lastUsedSet = numberOfSets;
122 ROS_INFO_STREAM(
"lastUsedSet is greater than numberOfSets(" << numberOfSets <<
"), setting it to " << lastUsedSet <<
" now.");
125 if (firstUsedSet > lastUsedSet)
131 std::cout << std::endl;
133 ROS_INFO_STREAM(
"and sets from " << (firstUsedSet) <<
" to " << lastUsedSet <<
" (including last)");
146 std::cout << std::endl;
151 std::string& pVisualizationTopic)
155 pObjectTopic =
"/objects";
167 throw std::runtime_error(
"dbfilename not set");
183 if (!
mNh.
getParam(
"visualization_topic", pVisualizationTopic))
185 pVisualizationTopic =
"visualization_marker";
234 std::cout << std::endl;
236 std::vector<std::string> patternNames = mTableHelper->getRecordedPatternNames();
237 ROS_INFO_STREAM(
"There are/is " << patternNames.size() <<
" pattern(s)");
238 std::vector<ISM::RecordedPatternPtr> recordedPatterns (patternNames.size());
239 std::vector<std::vector<ISM::ObjectSetPtr>> recordedSets (recordedPatterns.size());
240 for (
unsigned int i = 0; i < patternNames.size(); ++i)
243 recordedPatterns[i] = mTableHelper->getRecordedPattern(patternNames[i]);
245 for (
unsigned int pattern = 0; pattern < recordedPatterns.size(); ++pattern)
247 recordedSets[pattern] = std::vector<ISM::ObjectSetPtr> (recordedPatterns[pattern]->objectSets.size());
248 ROS_INFO_STREAM(
"Pattern " << pattern + 1 <<
" consists of " << recordedPatterns[pattern]->objectSets.size()
250 for (
unsigned int set = 0;
set < recordedPatterns[pattern]->objectSets.size(); ++
set)
252 recordedSets[pattern][
set] = recordedPatterns[pattern]->objectSets[
set];
253 ROS_INFO_STREAM(
"Set " <<
set + 1 <<
" of pattern " << pattern + 1 <<
" extracted");
261 asr_msgs::AsrObjectPtr msg;
262 msg.reset(
new asr_msgs::AsrObject());
268 msg->providedBy =
"fake_data_publisher";
269 geometry_msgs::Pose fake_pose;
270 fake_pose.position.x =
object->pose->point->eigen.x();
271 fake_pose.position.y =
object->pose->point->eigen.y();
272 fake_pose.position.z =
object->pose->point->eigen.z();
274 fake_pose.orientation.w =
object->pose->quat->eigen.w();
275 fake_pose.orientation.x =
object->pose->quat->eigen.x();
276 fake_pose.orientation.y =
object->pose->quat->eigen.y();
277 fake_pose.orientation.z =
object->pose->quat->eigen.z();
279 geometry_msgs::PoseWithCovariance fake_pose_with_c;
280 fake_pose_with_c.pose = fake_pose;
281 msg->sampledPoses.push_back(fake_pose_with_c);
282 msg->type =
object->type;
283 msg->typeConfidence =
object->confidence;
284 msg->sizeConfidence =
object->confidence;
285 msg->identifier =
object->observedId;
286 msg->meshResourcePath =
object->ressourcePath.string();
313 asr_msgs::AsrObjectPtr object;
315 unsigned int patterns = mObjectSets.size();
316 unsigned int patternSize = mObjectSets[
patternIter].size();
317 ROS_INFO_STREAM(
"Publishing set " << setIter + 1 <<
" / " << patternSize <<
" of pattern " 318 << patternIter + 1 <<
" / " << patterns);
320 for (
unsigned int objectIter = 0; objectIter < setSize; ++objectIter)
322 ROS_INFO_STREAM(
"Publishing object " << objectIter + 1 <<
" / " << setSize <<
" of set " 324 std::cout<<
"info\n"<<std::endl;
325 object =
objectToMessage(mObjectSets[patternIter][setIter]->objects[objectIter]);
329 mObjectModelVisualizer->drawObjectModels(mObjectSets[patternIter][setIter]->objects);
334 if (setIter >= patternSize)
339 if (patternIter >= patterns)
350 if (setIter > (
unsigned int) lastUsedSet)
362 int main(
int argc,
char **argv)
366 ros::init(argc, argv,
"fake_data_publisher");
std::vector< std::vector< ISM::ObjectSetPtr > > mObjectSets
VIZ::ObjectModelVisualizerRVIZ * mObjectModelVisualizer
void timerCallback(const ros::TimerEvent &timerEvent)
void publish(const boost::shared_ptr< M > &message) const
std::map< RecordKey, const asr_msgs::AsrObject > RecordMapType
std::vector< std::vector< ISM::ObjectSetPtr > > getDbEntries()
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
RecordMapType mObjectRecord
ros::Publisher mVisualizationPub
ROSCPP_DECL void spin(Spinner &spinner)
void getNodeParameters(std::string &pObjectTopic, std::string &pDbfilename, std::string &pVisualizationTopic)
asr_msgs::AsrObjectPtr objectToMessage(ISM::ObjectPtr object)
IH::ObjectConverter * mConverter
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
ISM::TableHelperPtr mTableHelper
std::pair< std::string, std::string > RecordKey
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
bool hasParam(const std::string &key) const
virtual ~Fake_data_publisher()
ISM::Recognizer * mRecognizer
int main(int argc, char **argv)