15 template <
class Cell,
class Storage, const
bool isClass=true>
18 Map(
int mapSizeX,
int mapSizeY,
double delta);
19 Map(
const Point& center,
double worldSizeX,
double worldSizeY,
double delta);
20 Map(
const Point& center,
double xmin,
double ymin,
double xmax,
double ymax,
double delta);
24 void resize(
double xmin,
double ymin,
double xmax,
double ymax);
25 void grow(
double xmin,
double ymin,
double xmax,
double ymax);
41 inline void getSize(
double & xmin,
double& ymin,
double& xmax,
double& ymax)
const {
43 xmin=min.
x, ymin=min.
y, xmax=
max.x, ymax=
max.y;
46 inline Cell&
cell(
int x,
int y) {
51 inline const Cell&
cell(
int x,
int y)
const {
56 inline Cell&
cell(
double x,
double y) {
61 inline const Cell&
cell(
double x,
double y)
const {
72 inline bool isInside(
double x,
double y)
const {
79 inline const Cell&
cell(
const Point& p)
const;
97 template <
class Cell,
class Storage, const
bool isClass>
100 template <
class Cell,
class Storage, const
bool isClass>
103 m_worldSizeX=mapSizeX *
delta;
104 m_worldSizeY=mapSizeY *
delta;
106 m_center=
Point(0.5*m_worldSizeX, 0.5*m_worldSizeY);
107 m_sizeX2=m_mapSizeX>>1;
108 m_sizeY2=m_mapSizeY>>1;
111 template <
class Cell,
class Storage, const
bool isClass>
113 m_storage((int)ceil(worldSizeX/delta), (int)ceil(worldSizeY/delta)){
115 m_worldSizeX=worldSizeX;
116 m_worldSizeY=worldSizeY;
118 m_mapSizeX=m_storage.getXSize()<<m_storage.getPatchSize();
119 m_mapSizeY=m_storage.getYSize()<<m_storage.getPatchSize();
120 m_sizeX2=m_mapSizeX>>1;
121 m_sizeY2=m_mapSizeY>>1;
124 template <
class Cell,
class Storage, const
bool isClass>
126 m_storage((int)ceil((xmax-xmin)/delta), (int)ceil((ymax-ymin)/delta)){
128 m_worldSizeX=xmax-xmin;
129 m_worldSizeY=ymax-ymin;
131 m_mapSizeX=m_storage.getXSize()<<m_storage.getPatchSize();
132 m_mapSizeY=m_storage.getYSize()<<m_storage.getPatchSize();
133 m_sizeX2=(int)round((m_center.x-xmin)/m_delta);
134 m_sizeY2=(int)round((m_center.y-ymin)/m_delta);
137 template <
class Cell,
class Storage, const
bool isClass>
139 IntPoint imin=world2map(xmin, ymin);
140 IntPoint imax=world2map(xmax, ymax);
141 int pxmin, pymin, pxmax, pymax;
142 pxmin=(int)floor((
float)imin.
x/(1<<m_storage.getPatchMagnitude()));
143 pxmax=(int)ceil((
float)imax.
x/(1<<m_storage.getPatchMagnitude()));
144 pymin=(int)floor((
float)imin.
y/(1<<m_storage.getPatchMagnitude()));
145 pymax=(int)ceil((
float)imax.
y/(1<<m_storage.getPatchMagnitude()));
146 m_storage.resize(pxmin, pymin, pxmax, pymax);
147 m_mapSizeX=m_storage.getXSize()<<m_storage.getPatchSize();
148 m_mapSizeY=m_storage.getYSize()<<m_storage.getPatchSize();
149 m_worldSizeX=xmax-xmin;
150 m_worldSizeY=ymax-ymin;
151 m_sizeX2-=pxmin*(1<<m_storage.getPatchMagnitude());
152 m_sizeY2-=pymin*(1<<m_storage.getPatchMagnitude());
155 template <
class Cell,
class Storage, const
bool isClass>
157 IntPoint imin=world2map(xmin, ymin);
158 IntPoint imax=world2map(xmax, ymax);
159 if (isInside(imin) && isInside(imax))
162 imax=
max(imax,
IntPoint(m_mapSizeX-1,m_mapSizeY-1));
163 int pxmin, pymin, pxmax, pymax;
164 pxmin=(int)floor((
float)imin.
x/(1<<m_storage.getPatchMagnitude()));
165 pxmax=(int)ceil((
float)imax.
x/(1<<m_storage.getPatchMagnitude()));
166 pymin=(int)floor((
float)imin.
y/(1<<m_storage.getPatchMagnitude()));
167 pymax=(int)ceil((
float)imax.
y/(1<<m_storage.getPatchMagnitude()));
168 m_storage.resize(pxmin, pymin, pxmax, pymax);
169 m_mapSizeX=m_storage.getXSize()<<m_storage.getPatchSize();
170 m_mapSizeY=m_storage.getYSize()<<m_storage.getPatchSize();
171 m_worldSizeX=xmax-xmin;
172 m_worldSizeY=ymax-ymin;
173 m_sizeX2-=pxmin*(1<<m_storage.getPatchMagnitude());
174 m_sizeY2-=pymin*(1<<m_storage.getPatchMagnitude());
178 template <
class Cell,
class Storage, const
bool isClass>
180 return IntPoint( (
int)round((p.
x-m_center.x)/m_delta)+m_sizeX2, (
int)round((p.
y-m_center.y)/m_delta)+m_sizeY2);
183 template <
class Cell,
class Storage, const
bool isClass>
185 return Point( (p.
x-m_sizeX2)*m_delta,
186 (p.
y-m_sizeY2)*m_delta)+m_center;
190 template <
class Cell,
class Storage, const
bool isClass>
198 return m_storage.cell(p);
202 template <
class Cell,
class Storage, const
bool isClass>
211 return m_storage.cell(ip);
214 template <
class Cell,
class Storage, const
bool isClass>
219 return m_storage.
cell(p);
223 template <
class Cell,
class Storage, const
bool isClass>
229 return m_storage.cell(ip);
235 template <
class Cell,
class Storage, const
bool isClass>
237 DoubleArray2D* darr=
new DoubleArray2D(getMapSizeX()-1, getMapSizeY()-1);
238 for(
int x=0; x<getMapSizeX()-1; x++)
239 for(
int y=0; y<getMapSizeY()-1; y++){
241 darr->
cell(p)=cell(p);
247 template <
class Cell,
class Storage, const
bool isClass>
251 Point pmax=map2world(getMapSizeX()-1,getMapSizeY()-1);
252 Point center=(pmax+pmin)*0.5;
254 for(
int x=0; x<getMapSizeX()-1; x++)
255 for(
int y=0; y<getMapSizeY()-1; y++){
257 plainMap->
cell(p)=cell(p);
const char *const *argv double delta
Point map2world(const IntPoint &p) const
Cell & cell(double x, double y)
point< T > min(const point< T > &p1, const point< T > &p2)
Cell & cell(int x, int y)
bool isInside(const Point &p) const
bool isInside(const IntPoint &p) const
Map(int mapSizeX, int mapSizeY, double delta)
Point map2world(int x, int y) const
static const Cell m_unknown
point< T > max(const point< T > &p1, const point< T > &p2)
double getWorldSizeX() const
void getSize(double &xmin, double &ymin, double &xmax, double &ymax) const
Map< double, DoubleArray2D, false > * toDoubleMap() const
bool isInside(double x, double y) const
double getResolution() const
const Cell & cell(double x, double y) const
double min(double a, double b)
const Cell & cell(int x, int y) const
DoubleArray2D * toDoubleArray() const
IntPoint world2map(double x, double y) const
void grow(double xmin, double ymin, double xmax, double ymax)
void resize(double xmin, double ymin, double xmax, double ymax)
double getMapResolution() const
Map< double, DoubleArray2D, false > DoubleMap
double max(double a, double b)
IntPoint world2map(const Point &p) const
const Cell & cell(int x, int y) const
const Storage & storage() const
Array2D< double > DoubleArray2D
double getWorldSizeY() const
bool isInside(int x, int y) const