28 #ifndef CPose2DGridTemplate_H
29 #define CPose2DGridTemplate_H
37 using namespace mrpt::math;
38 using namespace mrpt::utils;
49 double m_xMin, m_xMax,
52 m_resolutionXY,m_resolutionPhi;
56 size_t m_sizeX,
m_sizeY,m_sizePhi, m_sizeXY;
69 size_t x2idx(
double x)
const
71 int idx =
round( (x-m_xMin) / m_resolutionXY );
72 ASSERT_(idx>=0 && idx< static_cast<int>(m_sizeX));
78 size_t y2idx(
double y)
const
80 int idx =
round( (y-m_yMin) / m_resolutionXY );
81 ASSERT_(idx>=0 && idx< static_cast<int>(m_sizeY));
87 size_t phi2idx(
double phi)
const
89 int idx =
round( (phi-m_phiMin) / m_resolutionPhi );
90 ASSERT_(idx>=0 && idx< static_cast<int>(m_sizePhi) );
96 double idx2x(
size_t x)
const
99 return m_xMin + x * m_resolutionXY;
104 double idx2y(
size_t y)
const
107 return m_yMin + y * m_resolutionXY;
112 double idx2phi(
size_t phi)
const
115 return m_phiMin + phi * m_resolutionPhi;
125 double resolutionXY = 0.5f,
126 double resolutionPhi =
DEG2RAD(180),
127 double phiMin = -
M_PIf,
128 double phiMax =
M_PIf
132 m_phiMin(), m_phiMax(),
133 m_resolutionXY(),m_resolutionPhi(),
134 m_sizeX(),m_sizeY(),m_sizePhi(), m_sizeXY(),
135 m_idxLeftX(), m_idxLeftY(), m_idxLeftPhi(),
138 setSize(xMin,xMax,yMin,yMax,resolutionXY,resolutionPhi,phiMin,phiMax);
152 double resolutionPhi,
153 double phiMin = -
M_PIf,
154 double phiMax =
M_PIf
165 m_xMin = xMin; m_xMax = xMax;
166 m_yMin = yMin; m_yMax = yMax;
167 m_phiMin = phiMin; m_phiMax = phiMax;
168 m_resolutionXY = resolutionXY;
169 m_resolutionPhi = resolutionPhi;
172 m_idxLeftX =
round( xMin/resolutionXY ) ;
173 m_idxLeftY =
round( yMin/resolutionXY ) ;
174 m_idxLeftPhi =
round( phiMin/resolutionPhi ) ;
177 m_sizeX =
round( xMax/resolutionXY ) - m_idxLeftX + 1;
178 m_sizeY =
round( yMax/resolutionXY ) - m_idxLeftY + 1;
179 m_sizePhi =
round( phiMax/resolutionPhi ) - m_idxLeftPhi + 1;
180 m_sizeXY = m_sizeX * m_sizeY;
184 m_data.resize( m_sizeX * m_sizeY * m_sizePhi );
189 const T* getByPos(
double x,
double y,
double phi )
const
191 return getByIndex( x2idx(x),y2idx(y),phi2idx(phi) );
196 T* getByPos(
double x,
double y,
double phi )
198 return getByIndex( x2idx(x),y2idx(y),phi2idx(phi) );
203 const T* getByIndex(
size_t x,
size_t y,
size_t phi )
const
207 ASSERT_(phi>=0 && phi<m_sizePhi);
208 return &m_data[ phi*m_sizeXY + y*m_sizeX + x ];
213 T* getByIndex(
size_t x,
size_t y,
size_t phi )
217 ASSERT_(phi>=0 && phi<m_sizePhi);
218 return &m_data[ phi*m_sizeXY + y*m_sizeX + x ];
226 outMat.
setSize( m_sizeY, m_sizeX );
227 size_t phiIdx = phi2idx(phi);
229 for (
size_t y=0;y<m_sizeY;y++)
230 for (
size_t x=0;x<m_sizeX;x++)
231 outMat(y,x)=m_data[ phiIdx*m_sizeXY + y*m_sizeX + x ];