NumCpp  2.9.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 
31 #include <iostream>
32 #include <string>
33 
35 #include "NumCpp/Core/Types.hpp"
36 #include "NumCpp/Utils/num2str.hpp"
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  //=============================================================================
80  // Description:
87  constexpr bool operator==(const Pixel<dtype>& rhs) const noexcept
88  {
89  return row == rhs.row && col == rhs.col && 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  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 imageProcessing
167 } // 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:87
constexpr Pixel()=default
friend std::ostream & operator<<(std::ostream &inStream, const Pixel< dtype > &inPixel)
Definition: Pixel.hpp:160
dtype intensity
Definition: Pixel.hpp:56
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:72
bool operator<(const Pixel< dtype > &rhs) const noexcept
Definition: Pixel.hpp:116
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:136
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