gwnavgeneration/raster/singlestageraster.h Source File

singlestageraster.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_SingleStageRaster_H
10 #define GwNavGen_SingleStageRaster_H
11 
12 
17 
18 namespace Kaim
19 {
20 
21 /*
22 Contains the memory that receives the rasterization of one triangle.
23 Given a clippingPixelBox, from a trianglePixelBox, make {rasterPixelBox, rasterPixelsMemory} available.
24 Has the ability to restore its initial state after a given geometry rasterization.
25 
26 +-----------------------+
27 |clippingPixelBox |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | +-----------------+---------+
34 | | | |
35 | |rasterPixelBox | |
36 | | | |
37 +-----+-----------------+ |
38  | |
39  | trianglePixelBox|
40  +---------------------------+
41 */
42 class SingleStageRaster
43 {
44  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
45 
46 public:
47  SingleStageRaster(MemoryHeap* heap);
48 
49  KyResult Init(const PixelBox& clippingPixelBox);
50 
51  bool SetupRasterPixelBox(const PixelBox& geometryPixelBox);
52 
53  void ClearPixels();
54 
55  void PushPixelValue(const PixelPos& pixelPos, KyFloat32 value);
56  void FlagPixel(const PixelPos& pixelPos);
57 
58  const SingleStagePixel& GetPixel(const PixelPos& pixelPos) const;
59  const SingleStagePixel& GetPixelFromLocalPos(const PixelPos& localPixelPos) const;
60 
61  const PixelBox& GetRasterPixelBox() const;
62 
63  PixelCoord GetFirstLine() const;
64  PixelCoord GetLastLine() const;
65  PixelCoord GetNoLineIdx() const;
66 
67  PixelCoord GetFirstPixelOnLine(PixelCoord py) const;
68  PixelCoord GetLastPixelOnLine(PixelCoord py) const;
69  PixelCoord GetNoPixelIdx() const;
70 
71  // unit test usage
72  bool IsPixelFlaggedFromLocalPos(const PixelPos& localPixelPos) const;
73 
74  void SetNavTagIdx(KyUInt32 navTagIdx);
75  KyUInt32 GetNavTagIdx() const;
76 
77  void SetOwnerIdx(KyUInt32 ownerIdx);
78  KyUInt32 GetOwnerIdx() const;
79 
80 public:
81  PixelBox m_clippingPixelBox;
82  PixelBox m_rasterPixelBox;
83  KyArrayTLS<SingleStagePixel> m_pixels; // row major
84  BitArray2d_1024 m_bitArray2d;
85  KyUInt32 m_navTagIdx;
86  KyUInt32 m_ownerIndex;
87  MemoryHeap* m_heap;
88 };
89 
90 
91 KY_INLINE SingleStageRaster::SingleStageRaster(MemoryHeap* heap) : m_bitArray2d(heap), m_navTagIdx(KyUInt32MAXVAL), m_heap(heap) {}
92 
93 KY_INLINE void SingleStageRaster::PushPixelValue(const PixelPos& pixelPos, KyFloat32 value)
94 {
95  KY_DEBUG_ASSERTN(m_rasterPixelBox.IsInside(pixelPos),("Pixel is outside rasterPixelBox"));
96 
97  PixelPos localPixelPos = pixelPos - m_rasterPixelBox.Min();
98  KyInt32 pixelIdx = m_rasterPixelBox.GetRowMajorIndexFromLocalPos(localPixelPos);
99  m_pixels[pixelIdx].AddValue(value);
100  m_bitArray2d.SetPixel(localPixelPos.x, localPixelPos.y);
101 }
102 
103 KY_INLINE void SingleStageRaster::FlagPixel(const PixelPos& pixelPos)
104 {
105  KY_DEBUG_ASSERTN(m_rasterPixelBox.IsInside(pixelPos),("Pixel is outside rasterPixelBox"));
106 
107  PixelPos localPixelPos = pixelPos - m_rasterPixelBox.Min();
108  m_bitArray2d.SetPixel(localPixelPos.x, localPixelPos.y);
109 }
110 
111 KY_INLINE const SingleStagePixel& SingleStageRaster::GetPixel(const PixelPos& pixelPos) const
112 {
113  return m_pixels[m_rasterPixelBox.GetRowMajorIndex(pixelPos)];
114 }
115 
116 KY_INLINE const SingleStagePixel& SingleStageRaster::GetPixelFromLocalPos(const PixelPos& localPixelPos) const
117 {
118  return m_pixels[m_rasterPixelBox.GetRowMajorIndexFromLocalPos(localPixelPos)];
119 }
120 
121 KY_INLINE const PixelBox& SingleStageRaster::GetRasterPixelBox() const { return m_rasterPixelBox; }
122 KY_INLINE PixelCoord SingleStageRaster::GetFirstLine() const { return m_bitArray2d.GetFirstY() + m_rasterPixelBox.Min().y; }
123 KY_INLINE PixelCoord SingleStageRaster::GetLastLine() const { return m_bitArray2d.GetLastY() + m_rasterPixelBox.Min().y; }
124 KY_INLINE PixelCoord SingleStageRaster::GetNoLineIdx() const { return m_rasterPixelBox.Min().y - 1; }
125 KY_INLINE PixelCoord SingleStageRaster::GetNoPixelIdx() const { return m_rasterPixelBox.Min().x - 1; }
126 KY_INLINE PixelCoord SingleStageRaster::GetFirstPixelOnLine(PixelCoord py) const { return m_bitArray2d.GetFirstX(py - m_rasterPixelBox.Min().y) + m_rasterPixelBox.Min().x; }
127 KY_INLINE PixelCoord SingleStageRaster::GetLastPixelOnLine(PixelCoord py) const { return m_bitArray2d.GetLastX( py - m_rasterPixelBox.Min().y) + m_rasterPixelBox.Min().x; }
128 
129 // unit test usage
130 KY_INLINE bool SingleStageRaster::IsPixelFlaggedFromLocalPos(const PixelPos& localPixelPos) const
131 {
132  return m_bitArray2d.GetPixel(localPixelPos.x, localPixelPos.y);
133 }
134 
135 KY_INLINE void SingleStageRaster::SetNavTagIdx(KyUInt32 navTagIdx) { m_navTagIdx = navTagIdx; }
136 KY_INLINE KyUInt32 SingleStageRaster::GetNavTagIdx() const { return m_navTagIdx; }
137 
138 KY_INLINE void SingleStageRaster::SetOwnerIdx(KyUInt32 ownerIdx) { m_ownerIndex = ownerIdx; }
139 KY_INLINE KyUInt32 SingleStageRaster::GetOwnerIdx() const { return m_ownerIndex; }
140 
141 }
142 
143 
144 #endif
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
#define KyUInt32MAXVAL
The maximum value that can be stored in the KyUInt32 variable type.
Definition: types.h:226
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43