26 #include <mongo/client/dbclient.h> 28 #include <rviz_intel/TriangleMesh.h> 29 #include <mongodb_store/util.h> 32 using namespace mongo;
45 static pthread_mutex_t
qsize_mutex = PTHREAD_MUTEX_INITIALIZER;
49 BSONObjBuilder document;
51 Date_t stamp = msg->header.stamp.sec * 1000.0 + msg->header.stamp.nsec / 1000000.0;
52 document.append(
"header", BSON(
"seq" << msg->header.seq
54 <<
"frame_id" << msg->header.frame_id));
56 BSONArrayBuilder pointsb(document.subarrayStart(
"points"));
57 std::vector<geometry_msgs::Point32>::const_iterator p;
58 for (p = msg->points.begin(); p != msg->points.end(); ++p) {
59 pointsb.append(BSON(
"x" << p->x
65 BSONArrayBuilder normalsb(document.subarrayStart(
"normals"));
66 for (p = msg->normals.begin(); p != msg->normals.end(); ++p) {
67 normalsb.append(BSON(
"x" << p->x
73 BSONArrayBuilder colorsb(document.subarrayStart(
"colors"));
74 std::vector<uint32_t>::const_iterator u;
75 for (u = msg->colors.begin(); u != msg->colors.end(); ++u) {
80 BSONArrayBuilder color_indsb(document.subarrayStart(
"color_inds"));
81 for (u = msg->color_inds.begin(); u != msg->color_inds.end(); ++u) {
82 color_indsb.append(*u);
84 color_indsb.doneFast();
86 BSONArrayBuilder trianglesb(document.subarrayStart(
"triangles"));
87 std::vector<rviz_intel::Triangle>::const_iterator t;
88 for (t = msg->triangles.begin(); t != msg->triangles.end(); ++t) {
89 trianglesb.append(BSON(
"i" << t->i
93 trianglesb.doneFast();
94 document.append(
"sending_node", msg->sending_node);
96 mongodb_store::add_meta_for_msg<rviz_intel::TriangleMesh>(msg, document);
111 unsigned int l_in_counter, l_out_counter, l_drop_counter, l_qsize;
129 printf(
"%u:%u:%u:%u\n", l_in_counter, l_out_counter, l_drop_counter, l_qsize);
137 std::string
topic =
"", mongodb =
"localhost", nodename =
"";
143 while ((c = getopt(argc, argv,
"t:m:n:c:")) != -1) {
144 if ((c ==
'?') || (c ==
':')) {
145 printf(
"Usage: %s -t topic -m mongodb -n nodename -c collection\n", argv[0]);
147 }
else if (c ==
't') {
149 }
else if (c ==
'm') {
151 }
else if (c ==
'n') {
153 }
else if (c ==
'c') {
159 printf(
"No topic given.\n");
161 }
else if (nodename ==
"") {
162 printf(
"No node name given.\n");
172 ROS_ERROR(
"Failed to connect to MongoDB: %s", errmsg.c_str());
static pthread_mutex_t out_counter_mutex
unsigned int drop_counter
static pthread_mutex_t qsize_mutex
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
DBClientConnection * mongodb_conn
ROSCPP_DECL void spin(Spinner &spinner)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
int main(int argc, char **argv)
void msg_callback(const rviz_intel::TriangleMesh::ConstPtr &msg)
static pthread_mutex_t drop_counter_mutex
static pthread_mutex_t in_counter_mutex
void print_count(const ros::TimerEvent &te)