Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TFrame.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/math_fwd.h"
4#include "Frame/frame_fwd.h"
9#include "Utility/TSpan.h"
10
11#include <Common/primitive_type.h>
12
13#include <vector>
14#include <cstddef>
15
16namespace ph
17{
18
19template<typename T, std::size_t N>
20class TFrame final
21{
22public:
23 using ElementType = T;
24
25 template<typename U>
27
29
30 template<typename U = T>
32
33public:
36 TFrame();
37
40 TFrame(uint32 wPx, uint32 hPx);
41
42 TFrame(const TFrame& other);
43 TFrame(TFrame&& other) noexcept;
44 inline ~TFrame() = default;
45
46 void fill(T value);
47 void fill(T value, const math::TAABB2D<uint32>& region);
48 void flipHorizontally();
49 void flipVertically();
50 void setSize(uint32 wPx, uint32 hPx);
51 void setSize(const math::TVector2<uint32>& sizePx);
52
53 // TODO: user specified clamping range?
54 // TODO: specify size instead of radius for finer control
55 void sample(
56 TFrame& sampled,
58 uint32 kernelRadiusPx) const;
59
63 template<typename PerPixelOperation>
64 void forEachPixel(PerPixelOperation op);
65
66 template<typename PerPixelOperation>
67 void forEachPixel(PerPixelOperation op) const;
69
75 template<typename PerPixelOperation>
76 void forEachPixel(const math::TAABB2D<uint32>& region, PerPixelOperation op);
77
78 template<typename PerPixelOperation>
79 void forEachPixel(const math::TAABB2D<uint32>& region, PerPixelOperation op) const;
81
82 // TODO: sampling texture
83
84 void setPixel(const math::TVector2<uint32>& coordPx, const PixelType& pixel);
85 void setPixel(uint32 x, uint32 y, const PixelType& pixel);
86
87 PixelType getPixel(const math::TVector2<uint32>& coordPx) const;
88 void getPixel(uint32 x, uint32 y, PixelType* out_pixel) const;
89
97
102 void copyPixelData(const math::TAABB2D<uint32>& region, TSpan<T> out_data) const;
103
105
106 TFrame& operator = (const TFrame& rhs);
107 TFrame& operator = (TFrame&& rhs) noexcept;
108
109 uint32 widthPx() const;
110 uint32 heightPx() const;
111 bool isEmpty() const;
112
113 constexpr std::size_t numPixelComponents() const noexcept;
114
115private:
116 uint32 m_widthPx;
117 uint32 m_heightPx;
118
119 std::vector<T> m_pixelData;
120
121 std::size_t calcPixelDataBaseIndex(uint32 x, uint32 y) const;
122};
123
124}// end namespace ph
125
126#include "Frame/TFrame.ipp"
Definition TFrame.h:21
uint32 heightPx() const
Definition TFrame.ipp:440
~TFrame()=default
TSpan< T > getPixelData()
Get pixel data for the full frame.
Definition TFrame.ipp:398
void forEachPixel(PerPixelOperation op)
Iterate over all pixels in the frame in row-major order.
Definition TFrame.ipp:252
TFrame()
Constructs an empty frame.
Definition TFrame.ipp:70
T ElementType
Definition TFrame.h:23
void copyPixelData(const math::TAABB2D< uint32 > &region, TSpan< T > out_data) const
Copy a region of pixel data into a buffer.
Definition TFrame.ipp:410
static TPixelType< U > makeMonochromaticPixel(U value)
void sample(TFrame &sampled, const math::TMathFunction2D< float64 > &kernel, uint32 kernelRadiusPx) const
Definition TFrame.ipp:120
void fill(T value)
Definition TFrame.ipp:96
void setPixel(const math::TVector2< uint32 > &coordPx, const PixelType &pixel)
Definition TFrame.ipp:370
constexpr std::size_t numPixelComponents() const noexcept
Definition TFrame.ipp:392
void flipVertically()
Definition TFrame.ipp:219
uint32 widthPx() const
Definition TFrame.ipp:434
void flipHorizontally()
Definition TFrame.ipp:199
math::TVector2< uint32 > getSizePx() const
Definition TFrame.ipp:428
TFrame & operator=(const TFrame &rhs)
Definition TFrame.ipp:463
void setSize(uint32 wPx, uint32 hPx)
Definition TFrame.ipp:237
bool isEmpty() const
Definition TFrame.ipp:446
PixelType getPixel(const math::TVector2< uint32 > &coordPx) const
Definition TFrame.ipp:343
A 2-D Axis-Aligned Bounding Box (AABB).
Definition TAABB2D.h:26
Definition TArithmeticArray.h:13
Definition TMathFunction2D.h:8
Represents a 2-D vector.
Definition TVector2.h:19
The root for all renderer implementations.
Definition EEngineProject.h:6
std::span< const T, EXTENT > TSpanView
Same as TSpan, except that the objects are const-qualified. Note that for pointer types,...
Definition TSpan.h:19
std::span< T, EXTENT > TSpan
A contiguous sequence of objects of type T. Effectively the same as std::span.
Definition TSpan.h:12
Definition TAABB2D.h:96