nav_grid.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018, Locus Robotics
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 the copyright holder 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 HOLDER 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 #ifndef NAV_GRID_NAV_GRID_H
36 #define NAV_GRID_NAV_GRID_H
37 
38 #include <nav_grid/nav_grid_info.h>
39 #include <nav_grid/index.h>
40 #include <string>
41 
42 namespace nav_grid
43 {
76 template <typename T> class NavGrid
77 {
78 public:
79  explicit NavGrid(const T default_value = T{}) : default_value_(default_value) {}
80 
84  virtual void reset() = 0;
85 
92  virtual T getValue(const unsigned int x, const unsigned int y) const = 0;
93 
100  virtual void setValue(const unsigned int x, const unsigned int y, const T& value) = 0;
101 
103  // Note: You may not be able to use these unless your deriving class declares using NavGrid<T>::operator() or
104  // using NavGrid<T>::getValue
106  T getValue(const Index& index) { return getValue(index.x, index.y); }
107  T operator() (const unsigned int x, const unsigned int y) const { return getValue(x, y); }
108  T operator() (const Index& index) const { return getValue(index.x, index.y); }
109  void setValue(const Index& index, const T& value) { setValue(index.x, index.y, value); }
110 
117  virtual void setInfo(const NavGridInfo& new_info) = 0;
118 
127  virtual void updateInfo(const NavGridInfo& new_info) { setInfo(new_info); }
128 
129  inline NavGridInfo getInfo() const { return info_; }
130 
135  void setDefaultValue(const T new_value)
136  {
137  default_value_ = new_value;
138  }
139 
140  /*****************************************************************************************************
141  * NavGridInfo accessor methods
142  *****************************************************************************************************/
143  inline unsigned int getWidth() const { return info_.width; }
144  inline unsigned int getHeight() const { return info_.height; }
145  inline double getResolution() const { return info_.resolution; }
146  inline std::string getFrameId() const { return info_.frame_id; }
147  inline double getOriginX() const { return info_.origin_x; }
148  inline double getOriginY() const { return info_.origin_y; }
149 
150 protected:
153 };
154 
155 } // namespace nav_grid
156 
157 #endif // NAV_GRID_NAV_GRID_H
NavGridInfo getInfo() const
Definition: nav_grid.h:129
virtual void setValue(const unsigned int x, const unsigned int y, const T &value)=0
set the value of the grid at (x,y)
double getResolution() const
Definition: nav_grid.h:145
virtual void reset()=0
Reset the contents of the grid.
NavGridInfo info_
Definition: nav_grid.h:151
virtual T getValue(const unsigned int x, const unsigned int y) const =0
get the value of the grid at (x,y)
NavGrid(const T default_value=T{})
Definition: nav_grid.h:79
double getOriginY() const
Definition: nav_grid.h:148
double origin_x
The origin defines the coordinates of minimum corner of cell (0,0) in the grid.
Definition: nav_grid_info.h:57
void setDefaultValue(const T new_value)
Set the default value.
Definition: nav_grid.h:135
virtual void updateInfo(const NavGridInfo &new_info)
Change the info while attempting to keep the values associated with the world coordinates.
Definition: nav_grid.h:127
unsigned int getWidth() const
Definition: nav_grid.h:143
NumericType x
Definition: index.h:49
T getValue(const Index &index)
Definition: nav_grid.h:106
unsigned int getHeight() const
Definition: nav_grid.h:144
NumericType y
Definition: index.h:49
void setValue(const Index &index, const T &value)
Definition: nav_grid.h:109
std::string getFrameId() const
Definition: nav_grid.h:146
virtual void setInfo(const NavGridInfo &new_info)=0
Change the info while attempting to keep the values associated with the grid coordinates.
double getOriginX() const
Definition: nav_grid.h:147
A simple pair of x/y coordinates.
Definition: index.h:47
T operator()(const unsigned int x, const unsigned int y) const
Definition: nav_grid.h:107


nav_grid
Author(s):
autogenerated on Mon Feb 28 2022 23:32:36