Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #include <shared_workspace/Snapshotting.h>
  2.  
  3. Snapshotting::Snapshotting(ros::NodeHandle& nh, gpu_voxels::GpuVoxelsSharedPtr gvl, boost::shared_ptr<Config> config)
  4. : m_snapshot_service_server(nh.advertiseService("make_snapshot", &Snapshotting::triggerCB, this))
  5. , m_config(config)
  6. , m_gvl(gvl)
  7. {
  8. gvl->addMap(MT_BITVECTOR_VOXELLIST, "SnapshotVoxellist");
  9. m_snapshot_voxellist = boost::dynamic_pointer_cast<voxellist::BitVectorVoxelList, gpu_voxels::GpuVoxelsMap>(gvl->getMap("SnapshotVoxellist"));
  10. if (m_config->getDynRec()->visualize_maps)
  11. {
  12. m_gvl->visualizeMap("SnapshotVoxellist");
  13. }
  14.  
  15. m_make_snapshot_trigger = false;
  16. m_recording_voxels_for_snapshot = false;
  17. m_snapshot_iterations_counter = 0;
  18. m_iterations_for_snapshot = 20;
  19. }
  20.  
  21. Snapshotting::~Snapshotting()
  22. {
  23. }
  24.  
  25. bool Snapshotting::triggerCB(std_srvs::Trigger::Request& req, std_srvs::Trigger::Response& res)
  26. {
  27. m_make_snapshot_trigger = true;
  28. res.success = true;
  29. res.message = "Starting to make snapshot of the live_environment_voxellist.";
  30. return true;
  31. }
  32.  
  33. void Snapshotting::handle(boost::shared_ptr<gpu_voxels::voxellist::CountingVoxelList> env)
  34. {
  35. if (m_make_snapshot_trigger)
  36. {
  37. m_snapshot_voxellist->clearMap();
  38.  
  39. ROS_INFO_STREAM("Starting to take a snapshot of the live environment.");
  40.  
  41. m_snapshot_iterations_counter = 0;
  42. m_recording_voxels_for_snapshot = true;
  43.  
  44. m_make_snapshot_trigger = false;
  45. }
  46.  
  47. if (m_recording_voxels_for_snapshot)
  48. {
  49. const BitVoxelMeaning bvm = eBVM_OCCUPIED;
  50.  
  51. m_snapshot_voxellist->merge(env, Vector3f(), &bvm);
  52. m_snapshot_iterations_counter++;
  53.  
  54. if (m_snapshot_iterations_counter >= m_iterations_for_snapshot)
  55. {
  56. ROS_INFO_STREAM("Finished taking a snapshot of the live environment. Snapshot has " << m_snapshot_voxellist->getDimensions().x << " voxels");
  57. m_recording_voxels_for_snapshot = false;
  58. }
  59. }
  60.  
  61. if (!m_recording_voxels_for_snapshot)
  62. {
  63. if (m_config->getDynRec()->visualize_maps)
  64. {
  65. m_gvl->visualizeMap("SnapshotVoxellist");
  66. }
  67. env->subtractFromCountingVoxelList(m_snapshot_voxellist.get(), Vector3f());
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement