Skip to content

Commit

Permalink
Small update (#507)
Browse files Browse the repository at this point in the history
* (MarkerClient) use key variable

* Unsubscribe with callback as arg

* Fix Octree circular dep

Move Octree Enums to OctreeBase
  • Loading branch information
MatthijsBurgh authored Mar 9, 2022
1 parent 6d869e4 commit 2476bcc
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/interactivemarkers/InteractiveMarkerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ROS3D.InteractiveMarkerClient.prototype.subscribe = function(topic) {
*/
ROS3D.InteractiveMarkerClient.prototype.unsubscribe = function() {
if (this.updateTopic) {
this.updateTopic.unsubscribe();
this.updateTopic.unsubscribe(this.processUpdate);
}
if (this.feedbackTopic) {
this.feedbackTopic.unadvertise();
Expand Down
15 changes: 8 additions & 7 deletions src/markers/MarkerArrayClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,33 @@ ROS3D.MarkerArrayClient.prototype.subscribe = function(){

ROS3D.MarkerArrayClient.prototype.processMessage = function(arrayMessage){
arrayMessage.markers.forEach(function(message) {
var key = message.ns + message.id;
if(message.action === 0) {
var updated = false;
if(message.ns + message.id in this.markers) { // "MODIFY"
updated = this.markers[message.ns + message.id].children[0].update(message);
if(key in this.markers) { // "MODIFY"
updated = this.markers[key].children[0].update(message);
if(!updated) { // "REMOVE"
this.removeMarker(message.ns + message.id);
this.removeMarker(key);
}
}
if(!updated) { // "ADD"
var newMarker = new ROS3D.Marker({
message : message,
path : this.path,
});
this.markers[message.ns + message.id] = new ROS3D.SceneNode({
this.markers[key] = new ROS3D.SceneNode({
frameID : message.header.frame_id,
tfClient : this.tfClient,
object : newMarker
});
this.rootObject.add(this.markers[message.ns + message.id]);
this.rootObject.add(this.markers[key]);
}
}
else if(message.action === 1) { // "DEPRECATED"
console.warn('Received marker message with deprecated action identifier "1"');
}
else if(message.action === 2) { // "DELETE"
this.removeMarker(message.ns + message.id);
this.removeMarker(key);
}
else if(message.action === 3) { // "DELETE ALL"
for (var m in this.markers){
Expand All @@ -93,7 +94,7 @@ ROS3D.MarkerArrayClient.prototype.processMessage = function(arrayMessage){

ROS3D.MarkerArrayClient.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down
13 changes: 7 additions & 6 deletions src/markers/MarkerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ROS3D.MarkerClient.prototype.__proto__ = EventEmitter2.prototype;

ROS3D.MarkerClient.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down Expand Up @@ -70,10 +70,11 @@ ROS3D.MarkerClient.prototype.subscribe = function(){

ROS3D.MarkerClient.prototype.processMessage = function(message){
// remove old marker from Three.Object3D children buffer
var oldNode = this.markers[message.ns + message.id];
this.updatedTime[message.ns + message.id] = new Date().getTime();
var key = message.ns + message.id;
var oldNode = this.markers[key];
this.updatedTime[key] = new Date().getTime();
if (oldNode) {
this.removeMarker(message.ns + message.id);
this.removeMarker(key);

} else if (this.lifetime) {
this.checkTime(message.ns + message.id);
Expand All @@ -85,12 +86,12 @@ ROS3D.MarkerClient.prototype.processMessage = function(message){
path : this.path,
});

this.markers[message.ns + message.id] = new ROS3D.SceneNode({
this.markers[key] = new ROS3D.SceneNode({
frameID : message.header.frame_id,
tfClient : this.tfClient,
object : newMarker
});
this.rootObject.add(this.markers[message.ns + message.id]);
this.rootObject.add(this.markers[key]);
}

this.emit('change');
Expand Down
28 changes: 0 additions & 28 deletions src/navigation/OcTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,6 @@
* @author Peter Sari - sari@photoneo.com
*/

/**
* Toggles voxel visibility
*
* * `occupied` - only voxels that are above or equal to the occupation threshold are shown
* * `free` - only voxels that are below the occupation threshold are shown
* * `all` - all allocated voxels are shown
*/
ROS3D.OcTreeVoxelRenderMode = {
OCCUPIED: 'occupied',
FREE: 'free',
ALL: 'all',
};

/**
* Coloring modes for each voxel
*
* * 'solid' - voxels will have a single solid color set by the tree globally
* * 'occupancy' - voxels are false colored by their occupancy value. Fall back for `solid` if not available.
* * 'color' - voxels will colorized by their
*/
ROS3D.OcTreeColorMode = {
SOLID: 'solid',
OCCUPANCY: 'occupancy',
COLOR: 'color'
};

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----

/**
* Specilaization of BaseOcTree
*
Expand Down
28 changes: 28 additions & 0 deletions src/navigation/OcTreeBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
* @author Peter Sari - sari@photoneo.com
*/

/**
* Toggles voxel visibility
*
* * `occupied` - only voxels that are above or equal to the occupation threshold are shown
* * `free` - only voxels that are below the occupation threshold are shown
* * `all` - all allocated voxels are shown
*/
ROS3D.OcTreeVoxelRenderMode = {
OCCUPIED: 'occupied',
FREE: 'free',
ALL: 'all',
};

/**
* Coloring modes for each voxel
*
* * 'solid' - voxels will have a single solid color set by the tree globally
* * 'occupancy' - voxels are false colored by their occupancy value. Fall back for `solid` if not available.
* * 'color' - voxels will colorized by their
*/
ROS3D.OcTreeColorMode = {
SOLID: 'solid',
OCCUPANCY: 'occupancy',
COLOR: 'color'
};

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----

/**
Quick and dirty helper class
to read ArrayBuffer in a streamed data-like fashion with mixed types in it
Expand Down
4 changes: 2 additions & 2 deletions src/navigation/OcTreeClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ROS3D.OcTreeClient.prototype.__proto__ = EventEmitter2.prototype;

ROS3D.OcTreeClient.prototype.unsubscribe = function () {
if (this.rosTopic) {
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down Expand Up @@ -90,7 +90,7 @@ ROS3D.OcTreeClient.prototype.processMessage = function (message) {
this._processMessagePrivate(message);

if (!this.continuous) {
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}

};
Expand Down
4 changes: 2 additions & 2 deletions src/navigation/OccupancyGridClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ROS3D.OccupancyGridClient.prototype.__proto__ = EventEmitter2.prototype;

ROS3D.OccupancyGridClient.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down Expand Up @@ -108,6 +108,6 @@ ROS3D.OccupancyGridClient.prototype.processMessage = function(message){

// check if we should unsubscribe
if (!this.continuous) {
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};
2 changes: 1 addition & 1 deletion src/navigation/Odometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ROS3D.Odometry.prototype.__proto__ = THREE.Object3D.prototype;

ROS3D.Odometry.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/navigation/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ROS3D.Path.prototype.__proto__ = THREE.Object3D.prototype;

ROS3D.Path.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/navigation/Point.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ROS3D.Point.prototype.__proto__ = THREE.Object3D.prototype;

ROS3D.Point.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/navigation/Polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ROS3D.Polygon.prototype.__proto__ = THREE.Object3D.prototype;

ROS3D.Polygon.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/navigation/Pose.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ROS3D.Pose.prototype.__proto__ = THREE.Object3D.prototype;

ROS3D.Pose.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/navigation/PoseArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ROS3D.PoseArray.prototype.__proto__ = THREE.Object3D.prototype;

ROS3D.PoseArray.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/navigation/PoseWithCovariance.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ROS3D.PoseWithCovariance.prototype.__proto__ = THREE.Object3D.prototype;

ROS3D.PoseWithCovariance.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/sensors/LaserScan.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ROS3D.LaserScan.prototype.__proto__ = THREE.Object3D.prototype;

ROS3D.LaserScan.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/sensors/NavSatFix.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ROS3D.NavSatFix.prototype.__proto__ = THREE.Object3D.prototype;

ROS3D.NavSatFix.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/sensors/PointCloud2.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ROS3D.PointCloud2.prototype.__proto__ = THREE.Object3D.prototype;

ROS3D.PointCloud2.prototype.unsubscribe = function(){
if(this.rosTopic){
this.rosTopic.unsubscribe();
this.rosTopic.unsubscribe(this.processMessage);
}
};

Expand Down

0 comments on commit 2476bcc

Please sign in to comment.