gwnavruntime/navmesh/pixelandcellgrid.h Source File

pixelandcellgrid.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
9 
13 
14 
15 namespace Kaim
16 {
17 
18 /*
19  /\ [---------------[ cellSize = 16
20  % [-------[ pixelSize = 8
21  %
22  %
23 ################################%################################################################
24 # | # | % | # | # | # | #
25 # | # | % pixel | pixel # pixel | pixel # | # | #
26 # | # | % 0,3 | 1,3 # 2,3 | 3,3 # | # | #
27 #-------+-------#-------+-------%---cell(1,0)---#---cell(1,1)---#---cell(2,1)---#---cell(3,1)---#
28 # | # | % | # | # | # | #
29 # | # | % pixel | pixel # pixel | pixel # | # | #
30 # | # | % 0,2 | 1,2 # 2,2 | 3,2 # | # | #
31 ################################%################################################################
32 # | # | % | # | # | # | #
33 # | # | % pixel | pixel # pixel | pixel # | # | #
34 # | # | % 0,1 | 1,1 # 2,1 | 3,1 # | # | #
35 #-------+-------#-------+-------%---cell(0,0)---#---cell(1,0)---#---cell(2,0)---#---cell(3,0)---#
36 # | # | % | # | # | # | #
37 # | # | pixel % pixel | pixel # pixel | pixel # | # | #
38 # | # | -1,0 % 0,0 | 1,0 # 2,0 | 3,0 # | # | #
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%> X
40 # | # | % | # | # | # | #
41 # | # | pixel % pixel | # | # | # | #
42 # | # | -1,-1 % 0,-1 | # | # | # | #
43 #-------+-------#--cell(-1,-1)--%--cell(0,-1)---#-------+-------#-------+-------#-------+-------#
44 # | # | % | # | # | # | #
45 # | # | % | # | # | # | #
46 # | # | % | # | # | # | #
47 ################################%################################################################
48 # | # | % | # | # | # | #
49 # | # | % | # | # | # | #
50 # | # | % | # | # | # | #
51 #-------+-------#-------+-------%-------+-------#-------+-------#-------+-------#-------+-------#
52 # | # | % | # | # | # | #
53 # | # | % | # | # | # | #
54 # | # | % | # | # | # | #
55 ################################%################################################################
56 
57 
58 ---------------------------- ZOOMING ON (0,0) ----------------------------
59  Y/\
60  %
61  X=-8 X=0 X=8 X=16
62  | % | |
63  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
64  + + + + | + + pixel + + % + + pixel + + | + + pixel + + | + +
65  + + + + | + +(-1,1) + + % + + (0,1) + + | + + (1,1) + + | + +
66  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
67  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
68 ---------+---------------+---------------+---------------+-------Y=8
69  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
70  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
71  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
72  + + + + | + + pixel + + % + + pixel + + | + + pixel + + | + +
73  + + + + | + +(-1,0) + + % + + (0,0) + + | + + (1,0) + + | + +
74  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
75  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
76 %%%%%%%%%+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%+%%%%%%%Y=0%%%> X
77  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
78  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
79  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
80  + + + + | + + pixel + + % + + pixel + + | + + pixel + + | + +
81  + + + + | + +(-1,-1)+ + % + + (0,-1)+ + | + + (1,-1)+ + | + +
82  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
83  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
84 ---------+---------------+---------------+---------------+-------Y=-8
85  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
86  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
87  + + + + | + + + + + + + % + + + + + + + | + + + + + + + | + +
88 */
89 class PixelAndCellGrid
90 {
91  typedef GridUtils Utils; // alias for readability
92 
93 public:
94  PixelAndCellGrid()
95  {
96  m_pixelSize = 0;
97  m_cellSize = 0;
98  m_nbPixelsOnCellSide = 0;
99  m_pixelEnlargement = 0;
100  m_coordEnlargement = 0;
101  }
102 
106  // the cellSize in Meters is typically not used in the generation because the generation works in integer coordinates
107  void Init(KyUInt32 cellSizeInPixel, KyUInt32 pixelEnlargement)
108  {
109  m_nbPixelsOnCellSide = cellSizeInPixel;
110 
111  m_pixelSize = IntCoordSystem::IntPixelSize(); // in integer coord
112  m_cellSize = m_pixelSize * m_nbPixelsOnCellSide; // in integer coord
113 
114  m_pixelEnlargement = pixelEnlargement;
115  m_coordEnlargement = m_pixelEnlargement * m_pixelSize; // in integer coord
116  }
117 
118 public:
119  // -------------------- Coord PixelCoord CoordPos PixelPos --------------------
120  // Coord -> PixelCoord
121  PixelCoord LowPixelCoord (Coord coord) const { return Utils::LowSquare (m_pixelSize, coord); }
122  PixelCoord HighPixelCoord(Coord coord) const { return Utils::HighSquare(m_pixelSize, coord); }
123 
124  // PixelCoord -> Coord
125  Coord MinCoordOfPixel(PixelCoord pixelCoord) const { return Utils::MinCoord(m_pixelSize, pixelCoord); }
126  Coord MaxCoordOfPixel(PixelCoord pixelCoord) const { return Utils::MaxCoord(m_pixelSize, pixelCoord); }
127 
128  // CoordPos -> PixelPos
129  void LowPixelPos (const CoordPos& coordPos, PixelPos& pixelPos) const { return Utils::LowSquare (m_pixelSize, coordPos, pixelPos); }
130  void HighPixelPos(const CoordPos& coordPos, PixelPos& pixelPos) const { return Utils::HighSquare(m_pixelSize, coordPos, pixelPos); }
131 
132  // PixelPos -> CoordPos
133  void MinCoordPosOfPixel(const PixelPos& pixelPos, CoordPos& coordPos) const { Utils::MinCoordPos(m_pixelSize, pixelPos, coordPos); }
134  void MaxCoordPosOfPixel(const PixelPos& pixelPos, CoordPos& coordPos) const { Utils::MaxCoordPos(m_pixelSize, pixelPos, coordPos); }
135 
136 
137  // ------------------------- PixelPos CellPos -------------------------
138  // PixelPos -> CellPos
139  void PixelPos_To_CellPos(const PixelPos& pixelPos, CellPos& cellPos) const { Utils::BigSquarePos(m_nbPixelsOnCellSide, pixelPos, cellPos); }
140 
141  // ---------------- CoordBox <-> { PixelBox, CellBox } ----------------
142  // PixelBox <-> CoordBox
143  void CoordBox_To_PixelBox(const CoordBox& coordBox, PixelBox& pixelBox) const { Utils::SquareBox(m_pixelSize, coordBox, pixelBox); }
144  void PixelBox_To_CoordBox(const PixelBox& pixelBox, CoordBox& coordBox) const { Utils::GetCoordBox(m_pixelSize, pixelBox, coordBox); }
145 
146  // CellBox <-> CoordBox
147  void CoordBox_To_CellBox(const CoordBox& coordBox, CellBox& cellBox) const { Utils::SquareBox(m_cellSize, coordBox, cellBox); }
148  void CellBox_To_CoordBox(const CellBox& cellBox, CoordBox& coordBox) const { Utils::GetCoordBox(m_cellSize, cellBox, coordBox); }
149 
150  // --------------------- PixelBox <-> CellBox ---------------------
151  // PixelBox <-> CellBox
152  void PixelBox_To_CellBox(const PixelBox& pixelBox, CellBox& cellBox) const { Utils::BigSquareBox(m_nbPixelsOnCellSide, pixelBox, cellBox); }
153  void CellBox_To_PixelBox(const CellBox& cellBox, PixelBox& pixelBox) const { Utils::SmallSquareBox(m_nbPixelsOnCellSide, cellBox, pixelBox); }
154 
155 public:
156  Coord m_pixelSize; // pixel size in integer coordinates
157  Coord m_cellSize; // cell size in integer coordinates
158  PixelCoord m_nbPixelsOnCellSide; // cell size in number of pixels
159 
160  Coord m_coordEnlargement; // Cell enlargement in integer coordinates
161  PixelCoord m_pixelEnlargement; // Cell enlargement in number of pixels, should be renamed to m_nbPixelsInEnlargement or m_enlargementInPixel
162 };
163 
164 inline void SwapEndianness(Endianness::Target e, PixelAndCellGrid& self)
165 {
166  SwapEndianness(e, self.m_pixelSize);
167  SwapEndianness(e, self.m_cellSize);
168  SwapEndianness(e, self.m_nbPixelsOnCellSide);
169  SwapEndianness(e, self.m_coordEnlargement);
170  SwapEndianness(e, self.m_pixelEnlargement);
171 }
172 
173 
174 }
175 
176 
177 
Box2i CellBox
A type that represents a bounding box around cells in a 2D grid.
Definition: navmeshtypes.h:31
Vec2i CellPos
A type that represents the position of a cell within a 2D grid.
Definition: navmeshtypes.h:30
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Box2i CoordBox
A type that represents a bounding box in the integer 2D grid.
Definition: navmeshtypes.h:21
Vec2i CoordPos
A type that represents the position of a point within the 2D integer grid.
Definition: navmeshtypes.h:20
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17