19 #include <boost/filesystem.hpp> 20 #include <boost/algorithm/string.hpp> 21 #include <boost/lexical_cast.hpp> 23 #include <rapidxml.hpp> 24 #include <rapidxml_utils.hpp> 28 #include <asr_ism_visualizations/ObjectModelVisualizerRVIZ.hpp> 29 #include <asr_ism_visualizations/vote_visualizer_rviz.hpp> 30 #include <asr_ism_visualizations/VizHelperRVIZ.hpp> 33 #include <ISM/utility/GeometryHelper.hpp> 34 #include <ISM/utility/TableHelper.hpp> 35 #include <ISM/utility/Util.hpp> 44 std::string db_filename;
45 std::string base_frame;
46 std::string visualization_topic;
48 ISM::TableHelperPtr table_helper(
new ISM::TableHelper(db_filename));
49 if(!table_helper->modelDataExists())
51 ISM::printRed(
"The database \"" + db_filename +
"\" doesn't contain a model!\n");
67 ISM::printGreen(
"\n###############################################\n");
68 std::cout <<
scene_name_ <<
" contains following sub-ISMs and objects (NAME & ID):\n";
69 for (std::pair<
const std::string, std::map<std::string, std::map<std::string, std::vector<ISM::VoteSpecifierPtr>>>>& object_to_votes :
pattern_to_object_to_votes_)
71 std::cout <<
"\t" << object_to_votes.first <<
":\n";
72 for (std::pair<
const std::string, std::map<std::string, std::vector<ISM::VoteSpecifierPtr>>>& object_name : object_to_votes.second)
74 for (std::pair<
const std::string, std::vector<ISM::VoteSpecifierPtr>>& object_id : object_name.second)
76 std::cout <<
"\t\t" << object_name.first <<
" " << object_id.first << std::endl;
80 ISM::printGreen(
"###############################################\n");
90 ISM::printRed(
"Couldn't load object constellation from xml, because the parameter \"config_file_path\" is not specified!\n");
98 rapidxml::file<> xmlFile(xml_path.c_str());
99 rapidxml::xml_document<> doc;
100 doc.parse<0>(xmlFile.data());
102 rapidxml::xml_node<> *root_node = doc.first_node();
105 rapidxml::xml_node<> *child_node = root_node->first_node();
108 rapidxml::xml_attribute<> *type_attribute = child_node->first_attribute(
"type");
109 rapidxml::xml_attribute<> *id_attribute = child_node->first_attribute(
"id");
110 rapidxml::xml_attribute<> *mesh_attribute = child_node->first_attribute(
"mesh");
111 rapidxml::xml_attribute<> *angles_attribute = child_node->first_attribute(
"angles");
112 if (type_attribute && id_attribute && mesh_attribute && angles_attribute)
114 std::string type = type_attribute->value();
115 std::string mesh = mesh_attribute->value();
116 std::string
id = id_attribute->value();
117 std::string pose_string = child_node->value();
118 std::string
angles = angles_attribute->value();
119 ISM::PosePtr pose = ISM::PosePtr(
new ISM::Pose());
125 child_node = child_node->next_sibling();
128 }
catch(std::runtime_error err) {
130 }
catch (rapidxml::parse_error err) {
136 ISM::printRed(
"No objects loaded! Check path specified in the launch-file!\n");
141 ISM::printGreen(
"Objects loaded!\n");
163 std::string obj_name;
165 ISM::printYellow(
"\nNEW SELECTION:\n");
166 std::cout <<
"Enter object NAME: ";
167 std::getline (std::cin, obj_name);
168 std::cout <<
"Enter object ID: ";
169 std::getline (std::cin, obj_id);
174 ISM::printGreen(
"SELECTED ");
175 std::cout << obj_name <<
" with the ID " << obj_id << std::endl;
177 ISM::PosePtr origin(
new ISM::Pose(
new ISM::Point(0.0, 0.0, 0.0),
new ISM::Quaternion(1.0, 0.0, 0.0, 0.0)));
179 ISM::ObjectPtr obj(ISM::ObjectPtr(
new ISM::Object(obj_name, origin, obj_id, resource_path)));
188 ISM::printRed(
"NO SUCH OBJECT!\n");
192 refresh_rate.
sleep();
198 void getNodeParameters(std::string& db_filename, std::string& base_frame, std::string& visualization_topic)
206 if (!
nh_.
getParam(
"visualization_topic", visualization_topic))
208 visualization_topic =
"";
232 void init(ISM::TableHelperPtr table_helper)
234 std::vector<std::string> pattern_names = table_helper->getModelPatternNames();
236 bool pattern_exist =
false;
238 for (std::string pattern_name : pattern_names)
242 std::set<std::pair<std::string, std::string>> objects = table_helper->getObjectTypesAndIdsBelongingToPattern(pattern_name);
251 ISM::printRed(
"No pattern in the database, with the name: " +
scene_name_ +
"\n");
260 std::vector<std::string> strvec;
262 boost::algorithm::trim_if(pose_in, boost::algorithm::is_any_of(delim));
263 boost::algorithm::split(strvec, pose_in, boost::algorithm::is_any_of(delim), boost::algorithm::token_compress_on);
264 if (strvec.size() == 6 || strvec.size() == 7) {
266 pose_out->point->eigen.x() = boost::lexical_cast<
double>(strvec[0]);
267 pose_out->point->eigen.y() = boost::lexical_cast<
double>(strvec[1]);
268 pose_out->point->eigen.z() = boost::lexical_cast<
double>(strvec[2]);
270 if(angles ==
"quaternion" && strvec.size() == 7)
272 pose_out->quat->eigen.w() = boost::lexical_cast<
double>(strvec[3]);
273 pose_out->quat->eigen.x() = boost::lexical_cast<
double>(strvec[4]);
274 pose_out->quat->eigen.y() = boost::lexical_cast<
double>(strvec[5]);
275 pose_out->quat->eigen.z() = boost::lexical_cast<
double>(strvec[6]);
277 else if(angles ==
"euler" && strvec.size() == 6)
279 double euler0,euler1,euler2;
280 euler0 = boost::lexical_cast<
double>(strvec[3]);
281 euler1 = boost::lexical_cast<
double>(strvec[4]);
282 euler2 = boost::lexical_cast<
double>(strvec[5]);
284 Eigen::Matrix3d rotationMatrix;
285 rotationMatrix = Eigen::AngleAxisd(euler0 * (M_PI / 180), Eigen::Vector3d::UnitX())
286 * Eigen::AngleAxisd(euler1 * (M_PI / 180), Eigen::Vector3d::UnitY())
287 * Eigen::AngleAxisd(euler2 * (M_PI / 180), Eigen::Vector3d::UnitZ());
289 Eigen::Quaternion<double> result(rotationMatrix);
290 pose_out->quat->eigen.w() = result.w();
291 pose_out->quat->eigen.x() = result.x();
292 pose_out->quat->eigen.y() = result.y();
293 pose_out->quat->eigen.z() = result.z();
302 }
catch (boost::bad_lexical_cast err) {
312 ROS_DEBUG_STREAM(
"Add Object " << object->type <<
" with id " << object->observedId <<
". [addObjectAndVotes(..)]");
317 ISM::ObjectToVoteMap::iterator obj_name_it = pat_it->second.find(object->type);
318 if (obj_name_it != pat_it->second.end())
320 std::map<std::string, std::vector<ISM::VoteSpecifierPtr>>::iterator obj_id_it = obj_name_it->second.find(object->observedId);
321 if (obj_id_it != obj_name_it->second.end())
323 if(obj_id_it->second.size() > 0)
328 if(recursive && pat_it->first.find(
"sub") != std::string::npos && ISM::GeometryHelper::isSelfVote(obj_id_it->second[0]))
330 ROS_DEBUG_STREAM(
"Object " << object->type <<
" with id " << object->observedId <<
" is the reference object of sub-ism " << pat_it->first <<
". [addObjectAndVotes(..)]");
331 ISM::ObjectPtr obj(ISM::ObjectPtr(
new ISM::Object(pat_it->first, object->pose,
"")));
345 ROS_DEBUG_STREAM(
"No votes for Object " << object->type <<
" with id " << object->observedId <<
" in the model for " <<
scene_name_ <<
". [addObjectAndVotes(..)]");
354 ISM::ObjectToVoteMap::iterator obj_name_it = pat_it->second.find(obj_name);
355 if (obj_name_it != pat_it->second.end())
357 std::map<std::string, std::vector<ISM::VoteSpecifierPtr>>::iterator obj_id_it = obj_name_it->second.find(obj_id);
358 if (obj_id_it != obj_name_it->second.end())
375 ISM::printGreen(
"Publish vote marker!\n");
403 int main (
int argc,
char **argv)
413 std::string load_config_query;
414 ISM::printYellow(
"\nDo you want to use object constellation from an xml-file?\n");
415 std::cout <<
"[y]es or [n]o: ";
416 std::getline (std::cin, load_config_query);
417 if (load_config_query ==
"y")
424 else if (load_config_query ==
"n")
431 std::cout << load_config_query <<
" is not valid, try again!" << std::endl;
void loadObjectsFromXML()
void init(ISM::TableHelperPtr table_helper)
ISM::PatternToObjectToVoteMap pattern_to_object_to_votes_
VIZ::VoteVisualizerRVIZ * vote_visualizer_
void addObjectAndVotes(ISM::ObjectPtr object, bool recursive=false)
void refreshVisualization(const ros::TimerEvent &e)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool parsePoseString(std::string pose_in, ISM::PosePtr &pose_out, std::string delim, std::string angles)
unsigned int number_of_subscriber_
int main(int argc, char **argv)
std::map< std::string, boost::filesystem::path > type_to_resource_path_
ROSCPP_DECL void spin(Spinner &spinner)
std::map< ISM::ObjectPtr, std::vector< ISM::VoteSpecifierPtr > > object_to_votes_
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
VIZ::ObjectModelVisualizerRVIZ * object_model_visualizer_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_DEBUG_STREAM(args)
std::string config_file_path_
std::vector< ISM::ObjectPtr > objects_
bool objectExist(std::string &obj_name, std::string &obj_id)
uint32_t getNumSubscribers() const
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL void shutdown()
ROSCPP_DECL void spinOnce()
void getNodeParameters(std::string &db_filename, std::string &base_frame, std::string &visualization_topic)
ros::Publisher visualization_publisher_
void generateVisualization()