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 #include <boost/thread/locks.hpp>
41 #include <boost/thread/shared_mutex.hpp>
42 #include <boost/function.hpp>
43 #include <memory>
44 
45 namespace collision_detection
46 {
48 
49 class OccMapTree : public octomap::OcTree
50 {
51 public:
53  {
54  }
55 
56  OccMapTree(const std::string& filename) : octomap::OcTree(filename)
57  {
58  }
59 
62  void lockRead()
63  {
64  tree_mutex_.lock_shared();
65  }
66 
68  void unlockRead()
69  {
70  tree_mutex_.unlock_shared();
71  }
72 
75  void lockWrite()
76  {
77  tree_mutex_.lock();
78  }
79 
81  void unlockWrite()
82  {
83  tree_mutex_.unlock();
84  }
85 
86  using ReadLock = boost::shared_lock<boost::shared_mutex>;
87  using WriteLock = boost::unique_lock<boost::shared_mutex>;
88 
90  {
91  return ReadLock(tree_mutex_);
92  }
93 
95  {
96  return WriteLock(tree_mutex_);
97  }
98 
100  {
101  if (update_callback_)
103  }
104 
106  void setUpdateCallback(const boost::function<void()>& update_callback)
107  {
108  update_callback_ = update_callback;
109  }
110 
111 private:
112  boost::shared_mutex tree_mutex_;
113  boost::function<void()> update_callback_;
114 };
115 
116 using OccMapTreePtr = std::shared_ptr<OccMapTree>;
117 using OccMapTreeConstPtr = std::shared_ptr<const OccMapTree>;
118 } // namespace collision_detection
collision_detection::OccMapTree::update_callback_
boost::function< void()> update_callback_
Definition: occupancy_map.h:145
collision_detection::OccMapTreeConstPtr
std::shared_ptr< const OccMapTree > OccMapTreeConstPtr
Definition: occupancy_map.h:149
collision_detection::OccMapTree::WriteLock
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: occupancy_map.h:119
collision_detection::OccMapNode
octomap::OcTreeNode OccMapNode
Definition: occupancy_map.h:79
collision_detection::OccMapTree::OccMapTree
OccMapTree(double resolution)
Definition: occupancy_map.h:84
octomap::OcTree::OcTree
OcTree(double resolution)
collision_detection::OccMapTree::unlockWrite
void unlockWrite()
unlock the underlying octree.
Definition: occupancy_map.h:113
collision_detection::OccMapTree::tree_mutex_
boost::shared_mutex tree_mutex_
Definition: occupancy_map.h:144
octomap::OcTree
collision_detection::OccMapTree::lockWrite
void lockWrite()
lock the underlying octree. it will not be read or written by the monitor until unlockTree() is calle...
Definition: occupancy_map.h:107
octomap::OcTreeNode
collision_detection::OccMapTree::unlockRead
void unlockRead()
unlock the underlying octree.
Definition: occupancy_map.h:100
collision_detection::OccMapTree::reading
ReadLock reading()
Definition: occupancy_map.h:121
collision_detection::OccMapTree::ReadLock
boost::shared_lock< boost::shared_mutex > ReadLock
Definition: occupancy_map.h:118
collision_detection::OccMapTree::lockRead
void lockRead()
lock the underlying octree. it will not be read or written by the monitor until unlockTree() is calle...
Definition: occupancy_map.h:94
collision_detection::OccMapTree::setUpdateCallback
void setUpdateCallback(const boost::function< void()> &update_callback)
Set the callback to trigger when updates are received.
Definition: occupancy_map.h:138
octomap.h
octomap
collision_detection::OccMapTree::triggerUpdateCallback
void triggerUpdateCallback()
Definition: occupancy_map.h:131
OcTreeBaseImpl< OcTreeNode, AbstractOccupancyOcTree >::resolution
double resolution
collision_detection::OccMapTreePtr
std::shared_ptr< OccMapTree > OccMapTreePtr
Definition: occupancy_map.h:148
collision_detection::OccMapTree::writing
WriteLock writing()
Definition: occupancy_map.h:126
collision_detection
Definition: collision_detector_allocator_allvalid.h:42


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Sun Nov 21 2021 03:25:56