gwnavruntime/navmesh/pixelandcellgrid.h Source File

pixelandcellgrid.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 // primary contact: GUAL - secondary contact: NOBODY
9 #ifndef GwNavGen_PixelAndCellGrid_H
10 #define GwNavGen_PixelAndCellGrid_H
11 
15 
16 
17 namespace Kaim
18 {
19 
20 /*
21  /\ [---------------[ cellSize = 16
22  % [-------[ pixelSize = 8
23  %
24  %
25 ################################%################################################################
26 # | # | % | # | # | # | #
27 # | # | % pixel | pixel # pixel | pixel # | # | #
28 # | # | % 0,3 | 1,3 # 2,3 | 3,3 # | # | #
29 #-------+-------#-------+-------%---cell(1,0)---#---cell(1,1)---#---cell(2,1)---#---cell(3,1)---#
30 # | # | % | # | # | # | #
31 # | # | % pixel | pixel # pixel | pixel # | # | #
32 # | # | % 0,2 | 1,2 # 2,2 | 3,2 # | # | #
33 ################################%################################################################
34 # | # | % | # | # | # | #
35 # | # | % pixel | pixel # pixel | pixel # | # | #
36 # | # | % 0,1 | 1,1 # 2,1 | 3,1 # | # | #
37 #-------+-------#-------+-------%---cell(0,0)---#---cell(1,0)---#---cell(2,0)---#---cell(3,0)---#
38 # | # | % | # | # | # | #
39 # | # | pixel % pixel | pixel # pixel | pixel # | # | #
40 # | # | -1,0 % 0,0 | 1,0 # 2,0 | 3,0 # | # | #
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%> X
42 # | # | % | # | # | # | #
43 # | # | pixel % pixel | # | # | # | #
44 # | # | -1,-1 % 0,-1 | # | # | # | #
45 #-------+-------#--cell(-1,-1)--%--cell(0,-1)---#-------+-------#-------+-------#-------+-------#
46 # | # | % | # | # | # | #
47 # | # | % | # | # | # | #
48 # | # | % | # | # | # | #
49 ################################%################################################################
50 # | # | % | # | # | # | #
51 # | # | % | # | # | # | #
52 # | # | % | # | # | # | #
53 #-------+-------#-------+-------%-------+-------#-------+-------#-------+-------#-------+-------#
54 # | # | % | # | # | # | #
55 # | # | % | # | # | # | #
56 # | # | % | # | # | # | #
57 ################################%################################################################
58 
59 
60 ---------------------------- ZOOMING ON (0,0) ----------------------------
61  Y/\
62  %
63  X=-8 X=0 X=8 X=16
64  | % | |
65  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
66  + + + + | + + pixel + + % + + pixel + + | + + pixel + + | + +
67  + + + + | + +(-1,1) + + % + + (0,1) + + | + + (1,1) + + | + +
68  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
69  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
70 ---------+---------------+---------------+---------------+-------Y=8
71  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
72  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
73  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
74  + + + + | + + pixel + + % + + pixel + + | + + pixel + + | + +
75  + + + + | + +(-1,0) + + % + + (0,0) + + | + + (1,0) + + | + +
76  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
77  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
78 %%%%%%%%%+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%+%%%%%%%Y=0%%%> X
79  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
80  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
81  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
82  + + + + | + + pixel + + % + + pixel + + | + + pixel + + | + +
83  + + + + | + +(-1,-1)+ + % + + (0,-1)+ + | + + (1,-1)+ + | + +
84  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
85  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
86 ---------+---------------+---------------+---------------+-------Y=-8
87  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
88  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
89  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
90 */
91 class PixelAndCellGrid
92 {
93  typedef GridUtils Utils; // alias for readability
94 
95 public:
96  PixelAndCellGrid()
97  {
98  m_pixelSize = 0;
99  m_cellSize = 0;
100  m_nbPixelsOnCellSide = 0;
101  m_pixelEnlargement = 0;
102  m_coordEnlargement = 0;
103  }
104 
108  // the cellSize in Meters is typically not used in the generation because the generation works in integer coordinates
109  void Init(KyUInt32 cellSizeInPixel, KyUInt32 entityRadiusInPixel)
110  {
111  m_nbPixelsOnCellSide = cellSizeInPixel;
112 
113  m_pixelSize = IntCoordSystem::IntPixelSize(); // in integer coord
114  m_cellSize = m_pixelSize * m_nbPixelsOnCellSide; // in integer coord
115 
116  m_pixelEnlargement = entityRadiusInPixel + 3; // for hard to grasp reasons, +3 is necessary, don't change even if it seems overkill
117  m_coordEnlargement = m_pixelEnlargement * m_pixelSize; // in integer coord
118  }
119 
120 public:
121  // -------------------- Coord PixelCoord CoordPos PixelPos --------------------
122  // Coord -> PixelCoord
123  PixelCoord LowPixelCoord (Coord coord) const { return Utils::LowSquare (m_pixelSize, coord); }
124  PixelCoord HighPixelCoord(Coord coord) const { return Utils::HighSquare(m_pixelSize, coord); }
125 
126  // PixelCoord -> Coord
127  Coord MinCoordOfPixel(PixelCoord pixelCoord) const { return Utils::MinCoord(m_pixelSize, pixelCoord); }
128  Coord MaxCoordOfPixel(PixelCoord pixelCoord) const { return Utils::MaxCoord(m_pixelSize, pixelCoord); }
129 
130  // CoordPos -> PixelPos
131  void LowPixelPos (const CoordPos& coordPos, PixelPos& pixelPos) const { return Utils::LowSquare (m_pixelSize, coordPos, pixelPos); }
132  void HighPixelPos(const CoordPos& coordPos, PixelPos& pixelPos) const { return Utils::HighSquare(m_pixelSize, coordPos, pixelPos); }
133 
134  // PixelPos -> CoordPos
135  void MinCoordPosOfPixel(const PixelPos& pixelPos, CoordPos& coordPos) const { Utils::MinCoordPos(m_pixelSize, pixelPos, coordPos); }
136  void MaxCoordPosOfPixel(const PixelPos& pixelPos, CoordPos& coordPos) const { Utils::MaxCoordPos(m_pixelSize, pixelPos, coordPos); }
137 
138 
139  // ------------------------- PixelPos CellPos -------------------------
140  // PixelPos -> CellPos
141  void PixelPos_To_CellPos(const PixelPos& pixelPos, CellPos& cellPos) const { Utils::BigSquarePos(m_nbPixelsOnCellSide, pixelPos, cellPos); }
142 
143  // ---------------- CoordBox <-> { PixelBox, CellBox } ----------------
144  // PixelBox <-> CoordBox
145  void CoordBox_To_PixelBox(const CoordBox& coordBox, PixelBox& pixelBox) const { Utils::SquareBox(m_pixelSize, coordBox, pixelBox); }
146  void PixelBox_To_CoordBox(const PixelBox& pixelBox, CoordBox& coordBox) const { Utils::GetCoordBox(m_pixelSize, pixelBox, coordBox); }
147 
148  // CellBox <-> CoordBox
149  void CoordBox_To_CellBox(const CoordBox& coordBox, CellBox& cellBox) const { Utils::SquareBox(m_cellSize, coordBox, cellBox); }
150  void CellBox_To_CoordBox(const CellBox& cellBox, CoordBox& coordBox) const { Utils::GetCoordBox(m_cellSize, cellBox, coordBox); }
151 
152  // --------------------- PixelBox <-> CellBox ---------------------
153  // PixelBox <-> CellBox
154  void PixelBox_To_CellBox(const PixelBox& pixelBox, CellBox& cellBox) const { Utils::BigSquareBox(m_nbPixelsOnCellSide, pixelBox, cellBox); }
155  void CellBox_To_PixelBox(const CellBox& cellBox, PixelBox& pixelBox) const { Utils::SmallSquareBox(m_nbPixelsOnCellSide, cellBox, pixelBox); }
156 
157 public:
158  Coord m_pixelSize; // pixel size in integer coordinates
159  Coord m_cellSize; // cell size in integer coordinates
160  PixelCoord m_nbPixelsOnCellSide; // cell size in number of pixels
161 
162  Coord m_coordEnlargement; // Cell enlargement in integer coordinates
163  PixelCoord m_pixelEnlargement; // Cell enlargement in number of pixels, should be renamed to m_nbPixelsInEnlargement or m_enlargementInPixel
164 };
165 
166 inline void SwapEndianness(Endianness::Target e, PixelAndCellGrid& self)
167 {
168  SwapEndianness(e, self.m_pixelSize);
169  SwapEndianness(e, self.m_cellSize);
170  SwapEndianness(e, self.m_nbPixelsOnCellSide);
171  SwapEndianness(e, self.m_coordEnlargement);
172  SwapEndianness(e, self.m_pixelEnlargement);
173 }
174 
175 
176 }
177 
178 
179 #endif
180 
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:34
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:33
Box2i CoordBox
A type that represents a bounding box in the integer 2D grid.
Definition: navmeshtypes.h:24
Vec2i CoordPos
A type that represents the position of a point within the 2D integer grid.
Definition: navmeshtypes.h:23
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
Definition: gamekitcrowddispersion.h:20
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36