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 #ifndef MOVEIT_OCCUPANCY_MAP_MONITOR_OCCUPANCY_MAP_
38 #define MOVEIT_OCCUPANCY_MAP_MONITOR_OCCUPANCY_MAP_
39 
40 #include <octomap/octomap.h>
41 #include <boost/thread/locks.hpp>
42 #include <boost/thread/shared_mutex.hpp>
43 #include <boost/function.hpp>
44 #include <memory>
45 
47 {
49 
51 {
52 public:
53  OccMapTree(double resolution) : octomap::OcTree(resolution)
54  {
55  }
56 
57  OccMapTree(const std::string& filename) : octomap::OcTree(filename)
58  {
59  }
60 
63  void lockRead()
64  {
65  tree_mutex_.lock_shared();
66  }
67 
69  void unlockRead()
70  {
71  tree_mutex_.unlock_shared();
72  }
73 
76  void lockWrite()
77  {
78  tree_mutex_.lock();
79  }
80 
82  void unlockWrite()
83  {
84  tree_mutex_.unlock();
85  }
86 
87  typedef boost::shared_lock<boost::shared_mutex> ReadLock;
88  typedef boost::unique_lock<boost::shared_mutex> WriteLock;
89 
90  ReadLock reading()
91  {
92  return ReadLock(tree_mutex_);
93  }
94 
95  WriteLock writing()
96  {
97  return WriteLock(tree_mutex_);
98  }
99 
101  {
102  if (update_callback_)
104  }
105 
107  void setUpdateCallback(const boost::function<void()>& update_callback)
108  {
109  update_callback_ = update_callback;
110  }
111 
112 private:
113  boost::shared_mutex tree_mutex_;
114  boost::function<void()> update_callback_;
115 };
116 
117 typedef std::shared_ptr<OccMapTree> OccMapTreePtr;
118 typedef std::shared_ptr<const OccMapTree> OccMapTreeConstPtr;
119 } // namespace occupancy_map_monitor
120 
121 #endif
std::shared_ptr< OccMapTree > OccMapTreePtr
boost::shared_lock< boost::shared_mutex > ReadLock
Definition: occupancy_map.h:87
octomap::OcTreeNode OccMapNode
Definition: occupancy_map.h:48
std::shared_ptr< const OccMapTree > OccMapTreeConstPtr
OccMapTree(const std::string &filename)
Definition: occupancy_map.h:57
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: occupancy_map.h:88
OcTree(double resolution)
void setUpdateCallback(const boost::function< void()> &update_callback)
Set the callback to trigger when updates are received.
void lockWrite()
lock the underlying octree. it will not be read or written by the monitor until unlockTree() is calle...
Definition: occupancy_map.h:76
void lockRead()
lock the underlying octree. it will not be read or written by the monitor until unlockTree() is calle...
Definition: occupancy_map.h:63
void unlockRead()
unlock the underlying octree.
Definition: occupancy_map.h:69
boost::function< void()> update_callback_
void unlockWrite()
unlock the underlying octree.
Definition: occupancy_map.h:82


occupancy_map_monitor
Author(s): Ioan Sucan , Jon Binney , Suat Gedikli
autogenerated on Thu Jan 14 2021 03:59:05