Skip to content

Commit

Permalink
Use CBOR compression for PointCloud2 (#239)
Browse files Browse the repository at this point in the history
* Use CBOR encoding for PointCloud2

* Don't reassign PointCloud2 buffer

Reassigning the buffer breaks underlying parts.

* Selectable compression in PointCloud2
  • Loading branch information
mvollrath authored and jihoonl committed Dec 5, 2018
1 parent 60aa319 commit e3fb0ad
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/sensors/PointCloud2.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ for(var i=0;i<64;i++){decode64.e[decode64.S.charAt(i)]=i;}
* * ros - the ROSLIB.Ros connection handle
* * topic - the marker topic to listen to (default: '/points')
* * tfClient - the TF client handle to use
* * compression (optional) - message compression (default: 'cbor')
* * rootObject (optional) - the root object to add this marker to use for the points.
* * max_pts (optional) - number of points to draw (default: 10000)
* * pointRatio (optional) - point subsampling ratio (default: 1, no subsampling)
Expand All @@ -60,6 +61,7 @@ ROS3D.PointCloud2 = function(options) {
options = options || {};
this.ros = options.ros;
this.topicName = options.topic || '/points';
this.compression = options.compression || 'cbor';
this.points = new ROS3D.Points(options);
this.rosTopic = undefined;
this.subscribe();
Expand All @@ -80,7 +82,8 @@ ROS3D.PointCloud2.prototype.subscribe = function(){
this.rosTopic = new ROSLIB.Topic({
ros : this.ros,
name : this.topicName,
messageType : 'sensor_msgs/PointCloud2'
messageType : 'sensor_msgs/PointCloud2',
compression: this.compression
});
this.rosTopic.subscribe(this.processMessage.bind(this));
};
Expand All @@ -93,7 +96,7 @@ ROS3D.PointCloud2.prototype.processMessage = function(msg){
var n, pointRatio = this.points.pointRatio;

if (msg.data.buffer) {
this.points.buffer = msg.data.buffer;
this.points.buffer.set(msg.data);
n = msg.height*msg.width / pointRatio;
} else {
n = decode64(msg.data, this.points.buffer, msg.point_step, pointRatio);
Expand Down

0 comments on commit e3fb0ad

Please sign in to comment.