NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
Pixel.hpp
Go to the documentation of this file.
1
28
29#pragma once
30
31#include <iostream>
32#include <string>
33
35#include "NumCpp/Core/Types.hpp"
38
39namespace nc::imageProcessing
40{
41 //================================================================================
42 // Class Description:
44 template<typename dtype>
45 class Pixel
46 {
47 private:
48 STATIC_ASSERT_ARITHMETIC(dtype);
49
50 public:
51 //==================================Attributes================================
52 mutable int32 clusterId{ -1 };
53 uint32 row{ 0 };
54 uint32 col{ 0 };
55 dtype intensity{ 0 };
56
57 //=============================================================================
58 // Description:
61 constexpr Pixel() = default;
62
63 //=============================================================================
64 // Description:
71 constexpr Pixel(uint32 inRow, uint32 inCol, dtype inIntensity) noexcept :
72 row(inRow),
73 col(inCol),
74 intensity(inIntensity)
75 {
76 }
77
78 //=============================================================================
79 // Description:
86 constexpr bool operator==(const Pixel<dtype>& rhs) const noexcept
87 {
88 return utils::essentiallyEqual(row, rhs.row) && utils::essentiallyEqual(col, rhs.col) &&
89 utils::essentiallyEqual(intensity, rhs.intensity);
90 }
91
92 //=============================================================================
93 // Description:
100 constexpr bool operator!=(const Pixel<dtype>& rhs) const noexcept
101 {
102 return !(*this == rhs);
103 }
104
105 //=============================================================================
106 // Description:
116 bool operator<(const Pixel<dtype>& rhs) const noexcept
117 {
118 if (row < rhs.row)
119 {
120 return true;
121 }
122 if (row == rhs.row)
123 {
124 return static_cast<bool>(col < rhs.col);
125 }
126
127 return false;
128 }
129
130 //=============================================================================
131 // Description:
136 [[nodiscard]] std::string str() const
137 {
138 std::string out = "row = " + utils::num2str(row) + " col = " + utils::num2str(col);
139 out += " intensity = " + utils::num2str(intensity) + '\n';
140 return out;
141 }
142
143 //============================================================================
147 void print() const
148 {
149 std::cout << *this;
150 }
151
152 //=============================================================================
153 // Description:
160 friend std::ostream& operator<<(std::ostream& inStream, const Pixel<dtype>& inPixel)
161 {
162 inStream << inPixel.str();
163 return inStream;
164 }
165 };
166} // namespace nc::imageProcessing
Holds the information for a single pixel.
Definition: Pixel.hpp:46
constexpr bool operator==(const Pixel< dtype > &rhs) const noexcept
Definition: Pixel.hpp:86
constexpr Pixel()=default
dtype intensity
Definition: Pixel.hpp:55
friend std::ostream & operator<<(std::ostream &inStream, const Pixel< dtype > &inPixel)
Definition: Pixel.hpp:160
void print() const
Definition: Pixel.hpp:147
constexpr bool operator!=(const Pixel< dtype > &rhs) const noexcept
Definition: Pixel.hpp:100
constexpr Pixel(uint32 inRow, uint32 inCol, dtype inIntensity) noexcept
Definition: Pixel.hpp:71
bool operator<(const Pixel< dtype > &rhs) const noexcept
Definition: Pixel.hpp:116
uint32 col
Definition: Pixel.hpp:54
uint32 row
Definition: Pixel.hpp:53
int32 clusterId
Definition: Pixel.hpp:52
std::string str() const
Definition: Pixel.hpp:136
Definition: applyThreshold.hpp:34
std::string num2str(dtype inNumber)
Definition: num2str.hpp:44
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:49
std::int32_t int32
Definition: Types.hpp:36
std::uint32_t uint32
Definition: Types.hpp:40