gwnavgeneration/raster/singlestageraster.h Source File

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