NumCpp  2.6.2
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 
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:
88  constexpr bool operator==(const Pixel<dtype>& rhs) const noexcept
89  {
90  return row == rhs.row && col == rhs.col && intensity == rhs.intensity;
91  }
92 
93  //=============================================================================
94  // Description:
103  constexpr bool operator!=(const Pixel<dtype>& rhs) const noexcept
104  {
105  return !(*this == rhs);
106  }
107 
108  //=============================================================================
109  // Description:
121  bool operator<(const Pixel<dtype>& rhs) const noexcept
122  {
123  if (row < rhs.row)
124  {
125  return true;
126  }
127  if (row == rhs.row)
128  {
129  return static_cast<bool>(col < rhs.col);
130  }
131 
132  return false;
133  }
134 
135  //=============================================================================
136  // Description:
142  std::string str() const
143  {
144  std::string out = "row = " + utils::num2str(row) + " col = " + utils::num2str(col);
145  out += " intensity = " + utils::num2str(intensity) + '\n';
146  return out;
147  }
148 
149  //============================================================================
153  void print() const
154  {
155  std::cout << *this;
156  }
157 
158  //=============================================================================
159  // Description:
167  friend std::ostream& operator<<(std::ostream& inStream, const Pixel<dtype>& inPixel)
168  {
169  inStream << inPixel.str();
170  return inStream;
171  }
172  };
173  } // namespace imageProcessing
174 } // 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:88
constexpr Pixel()=default
friend std::ostream & operator<<(std::ostream &inStream, const Pixel< dtype > &inPixel)
Definition: Pixel.hpp:167
dtype intensity
Definition: Pixel.hpp:56
void print() const
Definition: Pixel.hpp:153
constexpr bool operator!=(const Pixel< dtype > &rhs) const noexcept
Definition: Pixel.hpp:103
constexpr Pixel(uint32 inRow, uint32 inCol, dtype inIntensity) noexcept
Definition: Pixel.hpp:72
bool operator<(const Pixel< dtype > &rhs) const noexcept
Definition: Pixel.hpp:121
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:142
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