20 #include <boost/filesystem.hpp> 25 #include <asr_ism_visualizations/ObjectModelVisualizerRVIZ.hpp> 26 #include <asr_ism_visualizations/model_visualizer_rviz.hpp> 29 #include <ISM/common_type/Tracks.hpp> 30 #include <ISM/utility/GeometryHelper.hpp> 31 #include <ISM/utility/TableHelper.hpp> 32 #include <ISM/utility/Util.hpp> 40 std::string db_filename;
41 std::string base_frame;
42 std::string visualization_topic;
45 table_helper_ = ISM::TableHelperPtr(
new ISM::TableHelper(db_filename));
48 ISM::printRed(
"The database \"" + db_filename +
"\" doesn't contain any recordings!\n");
53 ISM::printRed(
"The database \"" + db_filename +
"\" doesn't contain a model!\n");
65 ISM::printGreen(
"Generate and publish models for " +
scene_name_ +
"!\n");
66 ISM::printGreen(
"\t(sub)pattern:\n");
70 ISM::printBlue(
"\t\t" + track_index_to_votes.first +
"\n");
71 model_visualizer_->addVisualization(track_index_to_votes.first,
tracks_,
ism_object_tracks_, track_index_to_votes.second);
79 void getNodeParameters(std::string& db_filename, std::string& base_frame, std::string& visualization_topic)
93 if (!
nh_.
getParam(
"visualization_topic", visualization_topic))
95 visualization_topic =
"";
110 if (recorded_pattern ==
nullptr)
112 ISM::printRed(
"No recorded pattern in the database, with the name: " +
scene_name_ +
"\n");
116 std::vector<ISM::ObjectSetPtr> recorded_object_sets = recorded_pattern->objectSets;
117 if (recorded_object_sets.empty())
119 ISM::printRed(
"No tracks in the database for the pattern with the name: " +
scene_name_ +
"\n");
123 tracks_ = ISM::TracksPtr(
new ISM::Tracks(recorded_object_sets));
129 std::vector<std::string> pattern_names =
table_helper_->getModelPatternNames();
130 ISM::PatternToObjectToVoteMap pattern_to_object_to_votes;
131 bool pattern_exist =
false;
134 for (std::string pattern_name : pattern_names)
138 std::set<std::pair<std::string, std::string> > objects;
139 objects =
table_helper_->getObjectTypesAndIdsBelongingToPattern(pattern_name);
140 pattern_to_object_to_votes[pattern_name] =
table_helper_->getVoteSpecifiersForPatternAndObjects(pattern_name, objects);
142 pattern_exist = pattern_exist || !pattern_to_object_to_votes[pattern_name].empty();
147 ISM::printRed(
"No pattern in the database, with the name: " +
scene_name_ +
"\n");
152 for (std::pair<const std::string, ISM::ObjectToVoteMap>& object_to_votes : pattern_to_object_to_votes)
154 for (std::pair<
const std::string, std::map<std::string, std::vector<ISM::VoteSpecifierPtr>>>& obj_id_to_votes : object_to_votes.second)
156 for (std::pair<
const std::string, std::vector<ISM::VoteSpecifierPtr>>& votes : obj_id_to_votes.second)
158 for(ISM::VoteSpecifierPtr vote : votes.second)
170 ISM::TracksPtr overall_tracks = ISM::TracksPtr(
new ISM::Tracks(
tracks_->tracks));
176 ISM::TrackPtr reference_track = ISM::TrackPtr(
new ISM::Track(track_index_to_votes.first));
179 for (
size_t i = 0; i < track_index_to_votes.second.size(); i++)
182 while(reference_track->objects.size() < i)
184 reference_track->objects.push_back(ISM::ObjectPtr());
188 for (ISM::VoteSpecifierPtr vote : track_index_to_votes.second[i])
190 if (ISM::GeometryHelper::isSelfVote(vote))
192 ISM::ObjectPtr ism_object;
193 ISM::TrackPtr track = overall_tracks->getTrackByTypeAndId(vote->objectType, vote->observedId);
194 if (track !=
nullptr)
196 ism_object = ISM::ObjectPtr(
new ISM::Object(*(track->objects[i])));
198 if (ism_object !=
nullptr)
200 ism_object->type = track_index_to_votes.first;
201 ism_object->observedId =
"";
205 reference_track->objects.push_back(ism_object);
212 while(reference_track->objects.size() < overall_tracks->tracks[0]->objects.size())
214 reference_track->objects.push_back(ISM::ObjectPtr());
218 overall_tracks->tracks.push_back(reference_track);
229 ISM::printGreen(
"Publish model marker!\n");
252 int main (
int argc,
char **argv)
void getNodeParameters(std::string &db_filename, std::string &base_frame, std::string &visualization_topic)
void refreshVisualization(const ros::TimerEvent &e)
VIZ::ModelVisualizerRVIZ * model_visualizer_
void initISMObjectTrack()
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
unsigned int number_of_subscriber_
ros::Publisher visualization_publisher_
ISM::TracksPtr ism_object_tracks_
uint32_t getNumSubscribers() const
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
std::map< std::string, std::map< int, std::vector< ISM::VoteSpecifierPtr > > > pattern_to_track_index_to_votes_
ISM::TableHelperPtr table_helper_
int main(int argc, char **argv)