\doxysection{Uniform\+Grid25.\+hpp}
\hypertarget{UniformGrid25_8hpp_source}{}\label{UniformGrid25_8hpp_source}\index{/home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/UniformGrid25.hpp@{/home/chr/devel/PhD/Environment/pub/PCBEnv/pcbenv/cxx/UniformGrid25.hpp}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#ifndef\ GYM\_PCB\_UNIFORMGRID25\_H}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#define\ GYM\_PCB\_UNIFORMGRID25\_H}}
\DoxyCodeLine{00003\ }
\DoxyCodeLine{00004\ \textcolor{preprocessor}{\#include\ "{}Geometry.hpp"{}}}
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ "{}Math/IPoint3.hpp"{}}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ "{}UserSettings.hpp"{}}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ \textcolor{keyword}{class\ }UniformGrid25}
\DoxyCodeLine{00009\ \{}
\DoxyCodeLine{00010\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00011\ \ \ \ \ \textcolor{keyword}{const}\ Real\ EdgeLen,\ EdgeLen05,\ EdgeLenRcp;\ \textcolor{comment}{//\ Compiler\ should\ realize\ that\ these\ are\ 1/0.5\ in\ NavGrid!}}
\DoxyCodeLine{00012\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00013\ \ \ \ \ UniformGrid25(Real\ edgeLen)\ :\ EdgeLen(edgeLen),\ EdgeLen05(edgeLen\ *\ 0.5),\ EdgeLenRcp(1.0\ /\ EdgeLen)\ \{\ \}}
\DoxyCodeLine{00014\ }
\DoxyCodeLine{00015\ \ \ \ \ \mbox{\hyperlink{classIVector__3}{IVector\_3}}\ getSize()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classIVector__3}{IVector\_3}}(mSize[0],\ mSize[1],\ mSize[2]);\ \}}
\DoxyCodeLine{00016\ \ \ \ \ uint\ getSize(uint\ d)\textcolor{keyword}{\ const\ }\{\ assert(d\ <\ 3);\ \textcolor{keywordflow}{return}\ mSize[d];\ \}}
\DoxyCodeLine{00017\ \ \ \ \ \textcolor{keyword}{const}\ Bbox\_2\&\ getBbox()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ mBbox;\ \}}
\DoxyCodeLine{00018\ }
\DoxyCodeLine{00019\ \ \ \ \ Real\ XCoord(\textcolor{keywordtype}{int}\ x)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ x\ *\ EdgeLen\ +\ mBbox.xmin();\ \}}
\DoxyCodeLine{00020\ \ \ \ \ Real\ YCoord(\textcolor{keywordtype}{int}\ y)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ y\ *\ EdgeLen\ +\ mBbox.ymin();\ \}}
\DoxyCodeLine{00021\ \ \ \ \ Point\_2\ Coords(\textcolor{keyword}{const}\ \mbox{\hyperlink{classIPoint__2}{IPoint\_2}}\ \&v)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ Coords(v.x,\ v.y);\ \}}
\DoxyCodeLine{00022\ \ \ \ \ Point\_2\ Coords(\textcolor{keywordtype}{int}\ x,\ \textcolor{keywordtype}{int}\ y)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ Point\_2(XCoord(x),\ YCoord(y));\ \}}
\DoxyCodeLine{00023\ \ \ \ \ \mbox{\hyperlink{classPoint__25}{Point\_25}}\ Coords(\textcolor{keyword}{const}\ \mbox{\hyperlink{classIPoint__3}{IPoint\_3}}\ \&v)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ Coords(v.x,\ v.y,\ v.z);\ \}}
\DoxyCodeLine{00024\ \ \ \ \ \mbox{\hyperlink{classPoint__25}{Point\_25}}\ Coords(\textcolor{keywordtype}{int}\ x,\ \textcolor{keywordtype}{int}\ y,\ uint\ z)\textcolor{keyword}{\ const\ }\{\ assert(z\ <\ mSize[2]);\ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classPoint__25}{Point\_25}}(XCoord(x),\ YCoord(y),\ z);\ \}}
\DoxyCodeLine{00025\ }
\DoxyCodeLine{00026\ \ \ \ \ Vector\_2\ MidPointOffset()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ Vector\_2(EdgeLen05,\ EdgeLen05);\ \}}
\DoxyCodeLine{00027\ \ \ \ \ Real\ MidPointX(\textcolor{keywordtype}{int}\ x)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ XCoord(x)\ +\ MidPointOffset().x();\ \}}
\DoxyCodeLine{00028\ \ \ \ \ Real\ MidPointY(\textcolor{keywordtype}{int}\ y)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ YCoord(y)\ +\ MidPointOffset().y();\ \}}
\DoxyCodeLine{00029\ \ \ \ \ Point\_2\ MidPoint(\textcolor{keyword}{const}\ \mbox{\hyperlink{classIPoint__2}{IPoint\_2}}\ \&v)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ MidPoint(v.x,\ v.y);\ \}}
\DoxyCodeLine{00030\ \ \ \ \ Point\_2\ MidPoint(\textcolor{keywordtype}{int}\ x,\ \textcolor{keywordtype}{int}\ y)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ Coords(x,y)\ +\ MidPointOffset();\ \}}
\DoxyCodeLine{00031\ \ \ \ \ \mbox{\hyperlink{classPoint__25}{Point\_25}}\ MidPoint(\textcolor{keyword}{const}\ \mbox{\hyperlink{classIPoint__3}{IPoint\_3}}\ \&v)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ Coords(v)\ +\ MidPointOffset();\ \}}
\DoxyCodeLine{00032\ }
\DoxyCodeLine{00033\ \ \ \ \ \mbox{\hyperlink{classIVector__2}{IVector\_2}}\ HIndices(\textcolor{keyword}{const}\ Point\_2\ \&v)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classIVector__2}{IVector\_2}}(XIndex(v.x()),\ YIndex(v.y()));\ \}}
\DoxyCodeLine{00034\ \ \ \ \ \textcolor{keywordtype}{int}\ \ XIndex(Real\ x,\ Real\ ex\ =\ 0.0)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00035\ \ \ \ \ \textcolor{keywordtype}{int}\ \ YIndex(Real\ y,\ Real\ ey\ =\ 0.0)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00036\ \ \ \ \ uint\ XIndexBounded(Real\ x,\ Real\ ex\ =\ 0.0)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00037\ \ \ \ \ uint\ YIndexBounded(Real\ y,\ Real\ ey\ =\ 0.0)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00038\ \ \ \ \ uint\ LinearIndex(uint\ z,\ uint\ y,\ uint\ x)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ z\ *\ mStrideZ\ +\ y\ *\ mStrideY\ +\ x;\ \}}
\DoxyCodeLine{00039\ \ \ \ \ uint\ LinearIndex(\textcolor{keyword}{const}\ \mbox{\hyperlink{classPoint__25}{Point\_25}}\ \&v)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ LinearIndex(XIndexBounded(v.x()),\ YIndexBounded(v.y()),\ 0);\ \}}
\DoxyCodeLine{00040\ \ \ \ \ \mbox{\hyperlink{structIBox__3}{IBox\_3}}\ getBox(\textcolor{keyword}{const}\ Bbox\_2\&,\ uint\ z0\ =\ 0,\ uint\ z1\ =\ std::numeric\_limits<uint>::max())\ \textcolor{keyword}{const};}
\DoxyCodeLine{00041\ }
\DoxyCodeLine{00042\ \ \ \ \ Real\ XfIndex(Real\ x,\ Real\ ex\ =\ 0.0)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00043\ \ \ \ \ Real\ YfIndex(Real\ y,\ Real\ ey\ =\ 0.0)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00044\ }
\DoxyCodeLine{00045\ \ \ \ \ uint\ getNumPoints2D()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ mSize[0]\ *\ mSize[1];\ \}}
\DoxyCodeLine{00046\ \ \ \ \ uint\ getNumPoints3D()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ mNumPoints3D;\ \}}
\DoxyCodeLine{00047\ }
\DoxyCodeLine{00048\ \ \ \ \ \textcolor{keywordtype}{bool}\ inside(\textcolor{keyword}{const}\ \mbox{\hyperlink{classIPoint__3}{IPoint\_3}}\ \&v)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ inside(v.x,\ v.y,\ v.z);\ \}}
\DoxyCodeLine{00049\ \ \ \ \ \textcolor{keywordtype}{bool}\ inside(uint\ x,\ uint\ y,\ uint\ z)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00050\ }
\DoxyCodeLine{00051\ \ \ \ \ \mbox{\hyperlink{classPoint__25}{Point\_25}}\ snapToMidPoint(\textcolor{keyword}{const}\ \mbox{\hyperlink{classPoint__25}{Point\_25}}\&)\ \textcolor{keyword}{const};}
\DoxyCodeLine{00052\ }
\DoxyCodeLine{00053\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00054\ \ \ \ \ Bbox\_2\ mBbox;}
\DoxyCodeLine{00055\ \ \ \ \ uint\ mSize[3];}
\DoxyCodeLine{00056\ \ \ \ \ uint\ mStrideZ;}
\DoxyCodeLine{00057\ \ \ \ \ uint\ mStrideY;}
\DoxyCodeLine{00058\ \ \ \ \ uint\ mNumPoints3D;}
\DoxyCodeLine{00059\ }
\DoxyCodeLine{00060\ \ \ \ \ \textcolor{keywordtype}{void}\ calcNumPoints3D();}
\DoxyCodeLine{00061\ \};}
\DoxyCodeLine{00062\ }
\DoxyCodeLine{00063\ \textcolor{keyword}{inline}\ Real\ UniformGrid25::XfIndex(Real\ x,\ Real\ ex)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00064\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00065\ \ \ \ \ \textcolor{keywordflow}{return}\ (x\ +\ ex\ -\/\ mBbox.xmin())\ *\ EdgeLenRcp;}
\DoxyCodeLine{00066\ \}}
\DoxyCodeLine{00067\ \textcolor{keyword}{inline}\ Real\ UniformGrid25::YfIndex(Real\ y,\ Real\ ey)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00068\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00069\ \ \ \ \ \textcolor{keywordflow}{return}\ (y\ +\ ey\ -\/\ mBbox.ymin())\ *\ EdgeLenRcp;}
\DoxyCodeLine{00070\ \}}
\DoxyCodeLine{00071\ }
\DoxyCodeLine{00072\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{int}\ UniformGrid25::XIndex(Real\ x,\ Real\ ex)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00073\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00074\ \ \ \ \ \textcolor{keywordflow}{return}\ int(XfIndex(x,\ ex));}
\DoxyCodeLine{00075\ \}}
\DoxyCodeLine{00076\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{int}\ UniformGrid25::YIndex(Real\ y,\ Real\ ey)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00077\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00078\ \ \ \ \ \textcolor{keywordflow}{return}\ int(YfIndex(y,\ ey));}
\DoxyCodeLine{00079\ \}}
\DoxyCodeLine{00080\ \textcolor{keyword}{inline}\ uint\ UniformGrid25::XIndexBounded(Real\ x,\ Real\ ex)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00081\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00082\ \ \ \ \ \textcolor{keywordflow}{return}\ std::max(0,\ std::min(XIndex(x,\ ex),\ \textcolor{keywordtype}{int}(mSize[0]\ -\/\ 1)));}
\DoxyCodeLine{00083\ \}}
\DoxyCodeLine{00084\ \textcolor{keyword}{inline}\ uint\ UniformGrid25::YIndexBounded(Real\ y,\ Real\ ey)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00085\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00086\ \ \ \ \ \textcolor{keywordflow}{return}\ std::max(0,\ std::min(YIndex(y,\ ey),\ \textcolor{keywordtype}{int}(mSize[1]\ -\/\ 1)));}
\DoxyCodeLine{00087\ \}}
\DoxyCodeLine{00088\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{bool}\ UniformGrid25::inside(uint\ x,\ uint\ y,\ uint\ z)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00089\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00090\ \ \ \ \ \textcolor{keywordflow}{return}\ (x\ <\ mSize[0])\ \&\&\ (y\ <\ mSize[1])\ \&\&\ (z\ <\ mSize[2]);}
\DoxyCodeLine{00091\ \}}
\DoxyCodeLine{00092\ }
\DoxyCodeLine{00093\ \textcolor{keyword}{inline}\ \mbox{\hyperlink{classPoint__25}{Point\_25}}\ UniformGrid25::snapToMidPoint(\textcolor{keyword}{const}\ \mbox{\hyperlink{classPoint__25}{Point\_25}}\ \&v)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00094\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00095\ \ \ \ \ \textcolor{keywordflow}{return}\ Point\_25(std::floor(v.x()\ -\/\ mBbox.xmin())\ +\ EdgeLen05\ +\ mBbox.xmin(),}
\DoxyCodeLine{00096\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::floor(v.y()\ -\/\ mBbox.ymin())\ +\ EdgeLen05\ +\ mBbox.ymin(),}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ v.z());}
\DoxyCodeLine{00098\ \}}
\DoxyCodeLine{00099\ }
\DoxyCodeLine{00100\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ UniformGrid25::calcNumPoints3D()}
\DoxyCodeLine{00101\ \{}
\DoxyCodeLine{00102\ \ \ \ \ uint64\_t\ N\ =\ (uint64\_t(mSize[0])\ *\ mSize[1])\ *\ mSize[2];}
\DoxyCodeLine{00103\ \ \ \ \ \textcolor{keywordflow}{if}\ (N\ >\ UserSettings::get().MaxGridCells\ ||\ N\ >\ std::numeric\_limits<uint>::max())}
\DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ std::runtime\_error(\textcolor{stringliteral}{"{}grid\ is\ too\ large,\ reduce\ the\ resolution"{}});}
\DoxyCodeLine{00105\ \ \ \ \ mNumPoints3D\ =\ N;}
\DoxyCodeLine{00106\ \}}
\DoxyCodeLine{00107\ }
\DoxyCodeLine{00108\ \textcolor{keyword}{inline}\ \mbox{\hyperlink{structIBox__3}{IBox\_3}}\ UniformGrid25::getBox(\textcolor{keyword}{const}\ Bbox\_2\ \&bbox,\ uint\ z0,\ uint\ z1)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00109\ \textcolor{keyword}{}\{}
\DoxyCodeLine{00110\ \ \ \ \ \textcolor{keywordflow}{return}\ IBox\_3(IPoint\_3(XIndexBounded(bbox.xmin()),\ YIndexBounded(bbox.ymin()),\ std::min(z0,\ mSize[2]\ -\/\ 1)),}
\DoxyCodeLine{00111\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ IPoint\_3(XIndexBounded(bbox.xmax()),\ YIndexBounded(bbox.ymax()),\ std::min(z1,\ mSize[2]\ -\/\ 1)));}
\DoxyCodeLine{00112\ \}}
\DoxyCodeLine{00113\ }
\DoxyCodeLine{00114\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ GYM\_PCB\_UNIFORMGRID25\_H}}

\end{DoxyCode}
