Robotics StackExchange | Archived questions

How to remove the existing point cloud from viewer created using ros3djs

I have multiple sub-clouds created after processing the parent cloud. The sub-clouds are being sent over the topics to be displayed on the 3D viewer in a browser using ros3djs, roslibjs. Since, the number of sub-clouds keeps varying i'll have to remove few clouds after unsubscription of topics.There is no function/option to remove an existing cloud from the viewer after unsubscription. Does anyone know how to do it?

I've tried the option of clearing all the objects in the viewer using "viewer.scene.children = [];" but it also removes other things like the co-ordinate frame, markers which i would like to retain.

Asked by sharath on 2018-09-26 00:42:47 UTC

Comments

Answers

Clearing an existing point cloud from the viewer can be done by first removing the children of points scene associated with the point cloud and then removing points scene from the 3D viewer.

var viewer = new ROS3D.Viewer({ 
  divID : 'webViewer',
  width : 800,
  height : 600,
  antialias : true,
});
tfClient = new ROSLIB.TFClient({
  ros : ros,
  angularThres : 0.01,
  transThres : 0.01,
  rate : 10.0,
  fixedFrame : '/camera_link'
});
var cloudClient = new ROS3D.PointCloud2({
  ros: ros,
  tfClient: tfClient,
  rootObject: viewer.scene,
  topic: '/point_cloud_topic',
});
function removeCloud(){
  for(var j=cloudClient.points.sn.children.length; j>0; j--){
    cloudClient.points.sn.remove(cloudClient.points.sn.children[j-1]);
  viewer.scene.remove(cloudClient.points.sn);
  }
}

Asked by sharath on 2019-02-11 04:08:17 UTC

Comments