snark
focus.h
1 // This file is part of snark, a generic and flexible library
2 // for robotics research.
3 //
4 // Copyright (C) 2011 The University of Sydney
5 //
6 // snark is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // snark is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 // for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with snark. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef SNARK_SENSORS_VELODYNE_THIN_FOCUS
20 #define SNARK_SENSORS_VELODYNE_THIN_FOCUS
21 
22 #include <map>
23 #include <boost/shared_ptr.hpp>
24 #include "./region.h"
25 
26 namespace snark { namespace velodyne { namespace thin {
27 
29 class focus
30 {
31  public:
32  focus( double rate = 1.0, double ratio = 1.0 );
33  template < typename Random >
34  bool has( double range, double bearing, double elevation, Random& random ) const;
35  double rate_in_focus() const;
36  double rate_out_of_focus() const;
37  double coverage() const;
38  void insert( std::size_t id, region* r );
39  void erase( std::size_t id );
40 
41  private:
42  typedef std::map< std::size_t, boost::shared_ptr< region > > Map;
43  double m_rate;
44  double m_ratio;
45  Map m_regions;
46  double m_rate_in_focus;
47  double m_rate_out_of_focus;
48  void update();
49 };
50 
51 template < typename Random >
52 bool focus::has( double range, double bearing, double elevation, Random& random ) const
53 {
54  double r = random();
55  for( typename Map::const_iterator it = m_regions.begin(); it != m_regions.end(); ++it )
56  {
57  if( it->second->has( range, bearing, elevation ) ) { return r < m_rate_in_focus; }
58  }
59  return r < m_rate_out_of_focus;
60 }
61 
62 } } } // namespace snark { namespace velodyne { namespace thin {
63 
64 #endif // #ifndev SNARK_SENSORS_VELODYNE_THIN_FOCUS
65