moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
occupancy_map.h
Go to the documentation of this file.
1/*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2012, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34
35/* Author: Ioan Sucan, Jon Binney */
36
37#pragma once
38
39#include <octomap/octomap.h>
40
41#include <memory>
42#include <string>
43#include <shared_mutex>
44#include <mutex>
45#include <functional>
46
47namespace collision_detection
48{
49typedef octomap::OcTreeNode OccMapNode;
50
51class OccMapTree : public octomap::OcTree
52{
53public:
54 OccMapTree(double resolution) : octomap::OcTree(resolution)
55 {
56 }
57
58 OccMapTree(const std::string& filename) : octomap::OcTree(filename)
59 {
60 }
61
64 void lockRead()
65 {
66 tree_mutex_.lock_shared();
67 }
68
71 {
72 tree_mutex_.unlock_shared();
73 }
74
77 void lockWrite()
78 {
79 tree_mutex_.lock();
80 }
81
84 {
85 tree_mutex_.unlock();
86 }
87
88 using ReadLock = std::shared_lock<std::shared_mutex>;
89 using WriteLock = std::unique_lock<std::shared_mutex>;
90
92 {
93 return ReadLock(tree_mutex_);
94 }
95
97 {
98 return WriteLock(tree_mutex_);
99 }
100
102 {
103 if (update_callback_)
104 update_callback_();
105 }
106
108 void setUpdateCallback(const std::function<void()>& update_callback)
109 {
110 update_callback_ = update_callback;
111 }
112
113private:
114 std::shared_mutex tree_mutex_;
115 std::function<void()> update_callback_;
116};
117
118using OccMapTreePtr = std::shared_ptr<OccMapTree>;
119using OccMapTreeConstPtr = std::shared_ptr<const OccMapTree>;
120} // namespace collision_detection
void unlockWrite()
unlock the underlying octree.
std::shared_lock< std::shared_mutex > ReadLock
void setUpdateCallback(const std::function< void()> &update_callback)
Set the callback to trigger when updates are received.
void unlockRead()
unlock the underlying octree.
OccMapTree(const std::string &filename)
void lockRead()
lock the underlying octree. it will not be read or written by the monitor until unlockTree() is calle...
std::unique_lock< std::shared_mutex > WriteLock
void lockWrite()
lock the underlying octree. it will not be read or written by the monitor until unlockTree() is calle...
std::shared_ptr< const OccMapTree > OccMapTreeConstPtr
std::shared_ptr< OccMapTree > OccMapTreePtr
octomap::OcTreeNode OccMapNode