ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
PixelGroup.h
Go to the documentation of this file.
1/**
2 * @file PixelGroup.h
3 * @brief Declares the PixelGroup template class for managing a collection of pixels.
4 *
5 * This file defines the PixelGroup class, which implements the IPixelGroup interface
6 * to manage a fixed number of pixels with spatial and color properties.
7 *
8 * @date 22/12/2024
9 * @author Coela Can't
10 */
11
12#pragma once
13
14#include "IPixelGroup.h" // Include for the base pixel group interface.
15
16/**
17 * @class PixelGroup
18 * @brief Manages a collection of pixels with positions, colors, and spatial relationships.
19 *
20 * The PixelGroup class provides methods for retrieving and manipulating pixel data,
21 * including spatial relationships and color properties. Supports both rectangular
22 * and arbitrary pixel arrangements.
23 *
24 * @tparam pixelCount The total number of pixels in the group.
25 */
26template<size_t pixelCount>
27class PixelGroup : public IPixelGroup {
28private:
29 const Vector2D* pixelPositions; ///< Array of pixel positions.
30 Direction direction; ///< Direction of pixel traversal.
31 BoundingBox2D bounds; ///< Bounding box for the pixel group.
32 RGBColor pixelColors[pixelCount]; ///< Array of pixel colors.
33 RGBColor pixelBuffer[pixelCount]; ///< Array of color buffers for temporary use.
34 uint16_t up[pixelCount]; ///< Indices of pixels above each pixel.
35 uint16_t down[pixelCount]; ///< Indices of pixels below each pixel.
36 uint16_t left[pixelCount]; ///< Indices of pixels to the left of each pixel.
37 uint16_t right[pixelCount]; ///< Indices of pixels to the right of each pixel.
38
39 bool isRectangular = false; ///< Indicates if the group forms a rectangular grid.
40 uint16_t rowCount; ///< Number of rows in the grid.
41 uint16_t colCount; ///< Number of columns in the grid.
42 Vector2D size; ///< Size of the grid.
43 Vector2D position; ///< Position of the grid.
44 Vector2D tempLocation; ///< Temporary location for calculations.
45
46public:
47 /**
48 * @brief Constructs a rectangular PixelGroup.
49 *
50 * @param size Size of the rectangular grid.
51 * @param position Position of the rectangular grid.
52 * @param rowCount Number of rows in the grid.
53 */
55
56 /**
57 * @brief Constructs a PixelGroup from arbitrary pixel locations.
58 *
59 * @param pixelLocations Array of pixel locations.
60 * @param direction Direction of pixel traversal (default: ZEROTOMAX).
61 */
62 PixelGroup(const Vector2D* pixelLocations, Direction direction = ZEROTOMAX);
63
64 /**
65 * @brief Destroys the PixelGroup object.
66 */
68
70 Vector2D GetSize() override;
71 Vector2D GetCoordinate(uint16_t count) override;
72 int GetPixelIndex(Vector2D location) override;
73 RGBColor* GetColor(uint16_t count) override;
74 RGBColor* GetColors() override;
76 uint16_t GetPixelCount() override;
77 bool Overlaps(BoundingBox2D* box) override;
78 bool ContainsVector2D(Vector2D v) override;
79 bool GetUpIndex(uint16_t count, uint16_t* upIndex) override;
80 bool GetDownIndex(uint16_t count, uint16_t* downIndex) override;
81 bool GetLeftIndex(uint16_t count, uint16_t* leftIndex) override;
82 bool GetRightIndex(uint16_t count, uint16_t* rightIndex) override;
83 bool GetAlternateXIndex(uint16_t count, uint16_t* index) override;
84 bool GetAlternateYIndex(uint16_t count, uint16_t* index) override;
85 bool GetOffsetXIndex(uint16_t count, uint16_t* index, int x1) override;
86 bool GetOffsetYIndex(uint16_t count, uint16_t* index, int y1) override;
87 bool GetOffsetXYIndex(uint16_t count, uint16_t* index, int x1, int y1) override;
88 bool GetRadialIndex(uint16_t count, uint16_t* index, int pixels, float angle) override;
89 void GridSort() override;
90};
91
92#include "PixelGroup.tpp" // Include the template implementation.
Declares the IPixelGroup interface for managing collections of pixels.
Represents a 2D axis-aligned bounding box.
Interface for managing and interacting with a collection of pixels.
Definition IPixelGroup.h:25
Direction
Specifies traversal directions for pixels.
Definition IPixelGroup.h:31
@ ZEROTOMAX
Traverse from minimum to maximum indices.
Definition IPixelGroup.h:32
Manages a collection of pixels with positions, colors, and spatial relationships.
Definition PixelGroup.h:27
bool GetRadialIndex(uint16_t count, uint16_t *index, int pixels, float angle) override
Retrieves a radial index for a given pixel based on distance and angle.
RGBColor * GetColors() override
Retrieves the array of colors for the pixel group.
void GridSort() override
Sorts the pixels in a grid structure.
bool GetOffsetXYIndex(uint16_t count, uint16_t *index, int x1, int y1) override
Retrieves an offset XY-axis index for a given pixel.
uint16_t down[pixelCount]
Indices of pixels below each pixel.
Definition PixelGroup.h:35
uint16_t colCount
Number of columns in the grid.
Definition PixelGroup.h:41
uint16_t GetPixelCount() override
Retrieves the total number of pixels in the group.
uint16_t right[pixelCount]
Indices of pixels to the right of each pixel.
Definition PixelGroup.h:37
Vector2D position
Position of the grid.
Definition PixelGroup.h:43
bool GetUpIndex(uint16_t count, uint16_t *upIndex) override
Retrieves the index of the pixel above a given pixel.
RGBColor * GetColor(uint16_t count) override
Retrieves the color of a specific pixel.
RGBColor pixelBuffer[pixelCount]
Array of color buffers for temporary use.
Definition PixelGroup.h:33
PixelGroup(Vector2D size, Vector2D position, uint16_t rowCount)
Constructs a rectangular PixelGroup.
Direction direction
Direction of pixel traversal.
Definition PixelGroup.h:30
bool GetAlternateXIndex(uint16_t count, uint16_t *index) override
Retrieves an alternate X-axis index for a given pixel.
int GetPixelIndex(Vector2D location) override
Retrieves the index of a pixel at a specific location.
bool Overlaps(BoundingBox2D *box) override
Checks if the pixel group overlaps with a bounding box.
RGBColor pixelColors[pixelCount]
Array of pixel colors.
Definition PixelGroup.h:32
bool GetLeftIndex(uint16_t count, uint16_t *leftIndex) override
Retrieves the index of the pixel to the left of a given pixel.
Vector2D GetCoordinate(uint16_t count) override
Retrieves the coordinate of a specific pixel.
uint16_t rowCount
Number of rows in the grid.
Definition PixelGroup.h:40
bool GetDownIndex(uint16_t count, uint16_t *downIndex) override
Retrieves the index of the pixel below a given pixel.
const Vector2D * pixelPositions
Array of pixel positions.
Definition PixelGroup.h:29
bool ContainsVector2D(Vector2D v) override
Checks if the pixel group contains a specific vector.
Vector2D tempLocation
Temporary location for calculations.
Definition PixelGroup.h:44
bool GetOffsetXIndex(uint16_t count, uint16_t *index, int x1) override
Retrieves an offset X-axis index for a given pixel.
uint16_t left[pixelCount]
Indices of pixels to the left of each pixel.
Definition PixelGroup.h:36
bool GetRightIndex(uint16_t count, uint16_t *rightIndex) override
Retrieves the index of the pixel to the right of a given pixel.
PixelGroup(const Vector2D *pixelLocations, Direction direction=ZEROTOMAX)
Constructs a PixelGroup from arbitrary pixel locations.
bool GetOffsetYIndex(uint16_t count, uint16_t *index, int y1) override
Retrieves an offset Y-axis index for a given pixel.
Vector2D GetCenterCoordinate() override
Retrieves the center coordinate of the pixel group.
uint16_t up[pixelCount]
Indices of pixels above each pixel.
Definition PixelGroup.h:34
RGBColor * GetColorBuffer() override
Retrieves the color buffer for the pixel group.
~PixelGroup()
Destroys the PixelGroup object.
bool isRectangular
Indicates if the group forms a rectangular grid.
Definition PixelGroup.h:39
Vector2D GetSize() override
Retrieves the size of the pixel group.
BoundingBox2D bounds
Bounding box for the pixel group.
Definition PixelGroup.h:31
Vector2D size
Size of the grid.
Definition PixelGroup.h:42
bool GetAlternateYIndex(uint16_t count, uint16_t *index) override
Retrieves an alternate Y-axis index for a given pixel.
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27