Skip to content

Commit

Permalink
Update occupancy grid rendering (#339)
Browse files Browse the repository at this point in the history
* Use raw probabilities values from the occupancy grid as part of the color scale instead of encoding them as only 3 discrete values:
0 will be rendered as black, 100 as full color.

Do not use linear filtering, instead use nearest filter so the texture appears as a grid.

* Do not duplicate SceneNode when multiple messages are delivered.
  • Loading branch information
J-Rojas authored Sep 18, 2020
1 parent 90ad89b commit a62a3a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
15 changes: 4 additions & 11 deletions src/navigation/OccupancyGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,8 @@ ROS3D.OccupancyGrid = function(options) {
var mapI = col + ((height - row - 1) * width);
// determine the value
var data = message.data[mapI];
var val;
if (data === 100) {
val = 0;
} else if (data === 0) {
val = 255;
} else {
val = 127;
}

var val = data * 255 / 100;

// determine the index into the image data array
var i = (col + (row * width)) * 3;
// r
Expand All @@ -53,8 +46,8 @@ ROS3D.OccupancyGrid = function(options) {

var texture = new THREE.DataTexture(imageData, width, height, THREE.RGBFormat);
texture.flipY = true;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
texture.needsUpdate = true;

var material = new THREE.MeshBasicMaterial({
Expand Down
23 changes: 14 additions & 9 deletions src/navigation/OccupancyGridClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ ROS3D.OccupancyGridClient.prototype.subscribe = function(){
queue_length : 1,
compression : this.compression
});
this.sceneNode = null;
this.rosTopic.subscribe(this.processMessage.bind(this));
};

Expand All @@ -72,7 +73,7 @@ ROS3D.OccupancyGridClient.prototype.processMessage = function(message){
// grid is of type ROS3D.SceneNode
this.currentGrid.unsubscribeTf();
}
this.rootObject.remove(this.currentGrid);
this.sceneNode.remove(this.currentGrid);
}

var newGrid = new ROS3D.OccupancyGrid({
Expand All @@ -84,18 +85,22 @@ ROS3D.OccupancyGridClient.prototype.processMessage = function(message){
// check if we care about the scene
if (this.tfClient) {
this.currentGrid = newGrid;
this.sceneNode = new ROS3D.SceneNode({
frameID : message.header.frame_id,
tfClient : this.tfClient,
object : newGrid,
pose : this.offsetPose
});
if (this.sceneNode === null) {
this.sceneNode = new ROS3D.SceneNode({
frameID : message.header.frame_id,
tfClient : this.tfClient,
object : newGrid,
pose : this.offsetPose
});
this.rootObject.add(this.sceneNode);
} else {
this.sceneNode.add(this.currentGrid);
}
} else {
this.sceneNode = this.currentGrid = newGrid;
this.rootObject.add(this.currentGrid);
}

this.rootObject.add(this.sceneNode);

this.emit('change');

// check if we should unsubscribe
Expand Down

0 comments on commit a62a3a3

Please sign in to comment.