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