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/shared_mutex.hpp>
42 #include <boost/function.hpp>
43 #include <memory>
44 
45 namespace occupancy_map_monitor
46 {
48 
50 {
51 public:
52  OccMapTree(double resolution) : octomap::OcTree(resolution)
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  typedef boost::shared_lock<boost::shared_mutex> ReadLock;
87  typedef boost::unique_lock<boost::shared_mutex> WriteLock;
88 
89  ReadLock reading()
90  {
91  return ReadLock(tree_mutex_);
92  }
93 
94  WriteLock writing()
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 typedef std::shared_ptr<OccMapTree> OccMapTreePtr;
117 typedef std::shared_ptr<const OccMapTree> OccMapTreeConstPtr;
118 }
119 
120 #endif
std::shared_ptr< OccMapTree > OccMapTreePtr
boost::shared_lock< boost::shared_mutex > ReadLock
Definition: occupancy_map.h:86
octomap::OcTreeNode OccMapNode
Definition: occupancy_map.h:47
std::shared_ptr< const OccMapTree > OccMapTreeConstPtr
OccMapTree(const std::string &filename)
Definition: occupancy_map.h:56
boost::unique_lock< boost::shared_mutex > WriteLock
Definition: occupancy_map.h:87
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:75
void lockRead()
lock the underlying octree. it will not be read or written by the monitor until unlockTree() is calle...
Definition: occupancy_map.h:62
void unlockRead()
unlock the underlying octree.
Definition: occupancy_map.h:68
boost::function< void()> update_callback_
void unlockWrite()
unlock the underlying octree.
Definition: occupancy_map.h:81


perception
Author(s): Ioan Sucan , Jon Binney , Suat Gedikli
autogenerated on Wed Jul 18 2018 02:48:55