2
* Copyright Staffan Gimåker 2008-2010.
6
* This file is part of peekabot.
8
* peekabot is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 3 of the License, or
11
* (at your option) any later version.
13
* peekabot is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#ifndef PEEKABOT_RENDERER_PRIMITIVES_OCCUPANCY_GRID_2D_HH_INCLUDED
24
#define PEEKABOT_RENDERER_PRIMITIVES_OCCUPANCY_GRID_2D_HH_INCLUDED
32
#include "../../Types.hh"
33
#include "../CullableEntity.hh"
44
class OccupancyGrid3D : public CullableEntity
47
OccupancyGrid3D(float cell_size, size_t max_cache_size);
49
~OccupancyGrid3D() throw();
51
void set_belief(const Eigen::Vector3f &x, float belief)
52
throw(std::domain_error);
54
float get_belief(const Eigen::Vector3f &x)
55
throw(std::runtime_error);
57
void clear_cell(const Eigen::Vector3f &x) throw();
61
virtual void get_renderables(PrepareRenderContext &context) const;
68
Batch(PrepareRenderContext &context, size_t batch_size);
73
double x_c, double y_c, double z_c,
75
double r, double g, double b);
79
Eigen::Vector3f * &vp,
80
const Eigen::Vector3f *vertices,
81
int i0, int i1, int i2, int i3)
83
*(vp++) = vertices[i0];
84
*(vp++) = vertices[i1];
85
*(vp++) = vertices[i2];
87
*(vp++) = vertices[i2];
88
*(vp++) = vertices[i3];
89
*(vp++) = vertices[i0];
94
void allocate_buffers();
97
PrepareRenderContext &m_context;
98
const size_t m_batch_size;
100
float *m_vertices, *m_colors, *m_normals;
110
inline bool is_leaf() const throw()
112
return m_children == 0;
116
const Eigen::Vector3f &x,
117
const Eigen::Vector3f ¢er,
118
float node_size) throw();
121
const Eigen::Vector3f &x,
123
const float cell_size,
124
const Eigen::Vector3f ¢er,
125
float node_size) throw(std::domain_error);
127
inline Node *get_parent() throw()
132
inline const Node *get_parent() const throw()
138
* \brief Get a child octants's position relative to its
141
* \pre \f$ 0 \leq i < 4 \f$
143
* \param i The octant for which to get the offset
144
* from its parent node.
145
* \return A vector describing the offset of node i from its parent.
147
* \sa \c m_children (for octant indexing).
149
inline Eigen::Vector3f octant_offset(
150
int i, float node_size) const throw()
152
return Eigen::Vector3f(
153
node_size/4*(2*(i&1)-1),
154
node_size/4*((i&2)-1),
155
node_size/4*(((i&4)>>1)-1) );
159
* \brief Check if a coordinate is enclosed in the
162
* \return \c true if the node encloses the given coordinate,
163
* \c false otherwise.
166
const Eigen::Vector3f &x,
167
const Eigen::Vector3f ¢er,
168
float node_size) const throw();
171
* \brief Check if a coordinate is enclosed the node's
172
* <em>i</em>:th quadrant.
174
* \pre The coordinate is enclosed in the node, i.e.
175
* <tt>encloses(x) == true</tt>.
177
* \param i The quadrant to check against, in the range 0
179
* \return \c true if the coordinate is enclosed by the
180
* node's <em>i</em>:th quadrant, \c false
183
* \remarks Note that this doesn't check if the coordinare
184
* is enclosed by a child node, or even demands that any
185
* child nodes exist. \sa encloses(float, float),
186
* m_children (for quadrant indexing).
188
inline bool enclosed_in_octant(
189
const Eigen::Vector3f &x, int i,
190
const Eigen::Vector3f ¢er) const throw()
192
return ( ( i&1 ? x(0) >= center(0) : x(0) < center(0) ) &&
193
( i&2 ? x(1) >= center(1) : x(1) < center(1) ) &&
194
( i&4 ? x(2) >= center(2) : x(2) < center(2) ) );
199
const Eigen::Vector3f ¢er,
201
const int order[]) throw();
205
const Camera &camera,
206
const Eigen::Vector3f ¢er,
208
const Frustum &frustum,
210
int plane_mask) throw();
214
* \brief Optimize the storage by merging neighbouring nodes
217
* \pre \a node is a leaf node.
219
static void optimize(Node *node);
225
* \brief Pointers to the child nodes of the node.
227
* \invariant m_children == 0 \f$\Leftrightarrow\f$ the
236
Node *grow_to_accomodate(const Eigen::Vector3f &x) throw();
238
void calculate_bvs() throw();
244
* \brief The root node of the quad-tree.
245
* \invariant Always non-null (except in the constructor).
246
* \remarks May change over time (if the tree is enlarged).
252
float m_root_cell_size;
254
Eigen::Vector3f m_root_cell_center;
256
size_t m_max_cache_size;
262
#endif // PEEKABOT_RENDERER_PRIMITIVES_OCCUPANCY_GRID_2D_HH_INCLUDED