ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
Pixel.h
Go to the documentation of this file.
1/**
2 * @file Pixel.h
3 * @brief Declares the Pixel class for managing pixel data and relationships in a 2D grid.
4 *
5 * This file defines the Pixel class, which represents a single pixel with positional data,
6 * color, and connections to neighboring pixels in a grid.
7 *
8 * @author Coela Can't
9 * @date 22/12/2024
10 */
11
12#pragma once
13
14#include "../../Utils/RGBColor.h" // Include for color representation.
15#include "../../Utils/Math/Vector2D.h" // Include for 2D positional data.
16
17/**
18 * @class Pixel
19 * @brief Represents a pixel in a 2D grid with positional, color, and neighbor information.
20 *
21 * The Pixel class stores data for a single pixel, including its position, color, and connections
22 * to neighboring pixels (up, down, left, right). It provides methods for managing these relationships
23 * and accessing pixel properties.
24 */
25class Pixel {
26private:
27 const Vector2D* position; ///< Pointer to the pixel's position in 2D space.
28 bool sorted = false; ///< Indicates whether the pixel has been processed in sorting algorithms.
29 bool upExists = false; ///< Indicates if a pixel exists above this pixel.
30 bool downExists = false; ///< Indicates if a pixel exists below this pixel.
31 bool leftExists = false; ///< Indicates if a pixel exists to the left of this pixel.
32 bool rightExists = false; ///< Indicates if a pixel exists to the right of this pixel.
33
34 Pixel* up = nullptr; ///< Pointer to the pixel above this pixel.
35 Pixel* down = nullptr; ///< Pointer to the pixel below this pixel.
36 Pixel* left = nullptr; ///< Pointer to the pixel to the left of this pixel.
37 Pixel* right = nullptr; ///< Pointer to the pixel to the right of this pixel.
38
39public:
40 RGBColor* Color; ///< Pointer to the RGB color of the pixel.
41
42 /**
43 * @brief Default constructor.
44 *
45 * Constructs a Pixel object with default settings.
46 */
47 Pixel();
48
49 /**
50 * @brief Constructs a Pixel object with a specified position.
51 *
52 * @param position Pointer to the pixel's position in 2D space.
53 */
54 Pixel(const Vector2D* position);
55
56 /**
57 * @brief Retrieves the pixel's position.
58 *
59 * @return A copy of the pixel's position as a Vector2D object.
60 */
61 const Vector2D GetPosition();
62
63 /**
64 * @brief Sets the pixel above this pixel.
65 *
66 * @param pixel Pointer to the pixel above this pixel.
67 */
68 void SetUpPixel(Pixel* pixel);
69
70 /**
71 * @brief Sets the pixel below this pixel.
72 *
73 * @param pixel Pointer to the pixel below this pixel.
74 */
75 void SetDownPixel(Pixel* pixel);
76
77 /**
78 * @brief Sets the pixel to the left of this pixel.
79 *
80 * @param pixel Pointer to the pixel to the left of this pixel.
81 */
82 void SetLeftPixel(Pixel* pixel);
83
84 /**
85 * @brief Sets the pixel to the right of this pixel.
86 *
87 * @param pixel Pointer to the pixel to the right of this pixel.
88 */
89 void SetRightPixel(Pixel* pixel);
90
91 /**
92 * @brief Checks if a pixel exists above this pixel.
93 *
94 * @return True if a pixel exists above, otherwise false.
95 */
96 bool HasUpPixel();
97
98 /**
99 * @brief Checks if a pixel exists below this pixel.
100 *
101 * @return True if a pixel exists below, otherwise false.
102 */
103 bool HasDownPixel();
104
105 /**
106 * @brief Checks if a pixel exists to the left of this pixel.
107 *
108 * @return True if a pixel exists to the left, otherwise false.
109 */
110 bool HasLeftPixel();
111
112 /**
113 * @brief Checks if a pixel exists to the right of this pixel.
114 *
115 * @return True if a pixel exists to the right, otherwise false.
116 */
117 bool HasRightPixel();
118
119 /**
120 * @brief Retrieves the pixel above this pixel.
121 *
122 * @return Pointer to the pixel above, or nullptr if none exists.
123 */
124 Pixel* GetUpPixel();
125
126 /**
127 * @brief Retrieves the pixel below this pixel.
128 *
129 * @return Pointer to the pixel below, or nullptr if none exists.
130 */
132
133 /**
134 * @brief Retrieves the pixel to the left of this pixel.
135 *
136 * @return Pointer to the pixel to the left, or nullptr if none exists.
137 */
139
140 /**
141 * @brief Retrieves the pixel to the right of this pixel.
142 *
143 * @return Pointer to the pixel to the right, or nullptr if none exists.
144 */
146};
Represents a pixel in a 2D grid with positional, color, and neighbor information.
Definition Pixel.h:25
void SetRightPixel(Pixel *pixel)
Sets the pixel to the right of this pixel.
Definition Pixel.cpp:30
bool HasRightPixel()
Checks if a pixel exists to the right of this pixel.
Definition Pixel.cpp:47
bool upExists
Indicates if a pixel exists above this pixel.
Definition Pixel.h:29
Pixel * GetLeftPixel()
Retrieves the pixel to the left of this pixel.
Definition Pixel.cpp:59
bool HasLeftPixel()
Checks if a pixel exists to the left of this pixel.
Definition Pixel.cpp:43
RGBColor * Color
Pointer to the RGB color of the pixel.
Definition Pixel.h:40
Pixel()
Default constructor.
Definition Pixel.cpp:3
Pixel * up
Pointer to the pixel above this pixel.
Definition Pixel.h:34
Pixel * left
Pointer to the pixel to the left of this pixel.
Definition Pixel.h:36
Pixel * down
Pointer to the pixel below this pixel.
Definition Pixel.h:35
bool rightExists
Indicates if a pixel exists to the right of this pixel.
Definition Pixel.h:32
void SetDownPixel(Pixel *pixel)
Sets the pixel below this pixel.
Definition Pixel.cpp:20
void SetUpPixel(Pixel *pixel)
Sets the pixel above this pixel.
Definition Pixel.cpp:15
bool downExists
Indicates if a pixel exists below this pixel.
Definition Pixel.h:30
Pixel * right
Pointer to the pixel to the right of this pixel.
Definition Pixel.h:37
const Vector2D GetPosition()
Retrieves the pixel's position.
Definition Pixel.cpp:11
bool HasUpPixel()
Checks if a pixel exists above this pixel.
Definition Pixel.cpp:35
const Vector2D * position
Pointer to the pixel's position in 2D space.
Definition Pixel.h:27
bool leftExists
Indicates if a pixel exists to the left of this pixel.
Definition Pixel.h:31
bool HasDownPixel()
Checks if a pixel exists below this pixel.
Definition Pixel.cpp:39
Pixel * GetRightPixel()
Retrieves the pixel to the right of this pixel.
Definition Pixel.cpp:63
Pixel * GetUpPixel()
Retrieves the pixel above this pixel.
Definition Pixel.cpp:51
Pixel * GetDownPixel()
Retrieves the pixel below this pixel.
Definition Pixel.cpp:55
bool sorted
Indicates whether the pixel has been processed in sorting algorithms.
Definition Pixel.h:28
void SetLeftPixel(Pixel *pixel)
Sets the pixel to the left of this pixel.
Definition Pixel.cpp:25
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