Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PointCloud2 buffers #244

Merged
merged 2 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/sensors/PointCloud2.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ ROS3D.PointCloud2 = function(options) {
this.ros = options.ros;
this.topicName = options.topic || '/points';
this.compression = options.compression || 'cbor';
this.max_pts = options.max_pts || 10000;
this.points = new ROS3D.Points(options);
this.rosTopic = undefined;
this.buffer = null;
this.subscribe();
};
ROS3D.PointCloud2.prototype.__proto__ = THREE.Object3D.prototype;
Expand Down Expand Up @@ -94,16 +96,20 @@ ROS3D.PointCloud2.prototype.processMessage = function(msg){
}

var n, pointRatio = this.points.pointRatio;
var bufSz = this.max_pts * msg.point_step;

if (msg.data.buffer) {
this.points.buffer.set(msg.data);
n = msg.height*msg.width / pointRatio;
this.buffer = msg.data.slice(0, Math.min(msg.data.byteLength, bufSz));
n = Math.min(msg.height*msg.width / pointRatio, this.points.positions.array.length / 3);
} else {
n = decode64(msg.data, this.points.buffer, msg.point_step, pointRatio);
if (!this.buffer || this.buffer.byteLength < bufSz) {
this.buffer = new Uint8Array(bufSz);
}
n = decode64(msg.data, this.buffer, msg.point_step, pointRatio);
pointRatio = 1;
}

var dv = new DataView(this.points.buffer.buffer);
var dv = new DataView(this.buffer.buffer);
var littleEndian = !msg.is_bigendian;
var x = this.points.fields.x.offset;
var y = this.points.fields.y.offset;
Expand Down
5 changes: 0 additions & 5 deletions src/sensors/Points.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,13 @@ ROS3D.Points = function(options) {
}

this.sn = null;
this.buffer = null;
};

ROS3D.Points.prototype.__proto__ = THREE.Object3D.prototype;

ROS3D.Points.prototype.setup = function(frame, point_step, fields)
{
if(this.sn===null){
// scratch space to decode base64 buffers
if(point_step) {
this.buffer = new Uint8Array( this.max_pts * point_step );
}
// turn fields to a map
fields = fields || [];
this.fields = {};
Expand Down