NumCpp  2.1.0
A C++ implementation of the Python Numpy library
Pixel.hpp
Go to the documentation of this file.
1 
30 #pragma once
31 
33 #include "NumCpp/Core/Types.hpp"
34 #include "NumCpp/Utils/num2str.hpp"
35 
36 #include <iostream>
37 #include <string>
38 
39 namespace nc
40 {
41  namespace imageProcessing
42  {
43  //================================================================================
44  // Class Description:
46  template<typename dtype>
47  class Pixel
48  {
49  private:
50  STATIC_ASSERT_ARITHMETIC(dtype);
51 
52  public:
53  //==================================Attributes================================
54  mutable int32 clusterId{ -1 };
55  uint32 row{ 0 };
56  uint32 col{ 0 };
57  dtype intensity{ 0 };
58 
59  //=============================================================================
60  // Description:
63  constexpr Pixel() = default;
64 
65  //=============================================================================
66  // Description:
73  constexpr Pixel(uint32 inRow, uint32 inCol, dtype inIntensity) noexcept :
74  row(inRow),
75  col(inCol),
76  intensity(inIntensity)
77  {}
78 
79  //=============================================================================
80  // Description:
89  constexpr bool operator==(const Pixel<dtype>& rhs) const noexcept
90  {
91  return row == rhs.row && col == rhs.col && intensity == rhs.intensity;
92  }
93 
94  //=============================================================================
95  // Description:
104  constexpr bool operator!=(const Pixel<dtype>& rhs) const noexcept
105  {
106  return !(*this == rhs);
107  }
108 
109  //=============================================================================
110  // Description:
122  bool operator<(const Pixel<dtype>& rhs) const noexcept
123  {
124  if (row < rhs.row)
125  {
126  return true;
127  }
128  if (row == rhs.row)
129  {
130  return static_cast<bool>(col < rhs.col);
131  }
132 
133  return false;
134  }
135 
136  //=============================================================================
137  // Description:
143  std::string str() const
144  {
145  std::string out = "row = " + utils::num2str(row) + " col = " + utils::num2str(col);
146  out += " intensity = " + utils::num2str(intensity) + "\n";
147  return out;
148  }
149 
150  //============================================================================
154  void print() const
155  {
156  std::cout << *this;
157  }
158 
159  //=============================================================================
160  // Description:
168  friend std::ostream& operator<<(std::ostream& inStream, const Pixel<dtype>& inPixel)
169  {
170  inStream << inPixel.str();
171  return inStream;
172  }
173  };
174  } // namespace imageProcessing
175 } // namespace nc
StaticAsserts.hpp
nc::int32
std::int32_t int32
Definition: Types.hpp:37
nc::imageProcessing::Pixel::str
std::string str() const
Definition: Pixel.hpp:143
nc::utils::num2str
std::string num2str(dtype inNumber)
Definition: num2str.hpp:47
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
nc::imageProcessing::Pixel::operator<
bool operator<(const Pixel< dtype > &rhs) const noexcept
Definition: Pixel.hpp:122
num2str.hpp
nc::imageProcessing::Pixel::print
void print() const
Definition: Pixel.hpp:154
nc
Definition: Coordinate.hpp:45
nc::imageProcessing::Pixel::Pixel
constexpr Pixel()=default
nc::imageProcessing::Pixel::operator==
constexpr bool operator==(const Pixel< dtype > &rhs) const noexcept
Definition: Pixel.hpp:89
nc::imageProcessing::Pixel::intensity
dtype intensity
Definition: Pixel.hpp:57
nc::imageProcessing::Pixel::operator!=
constexpr bool operator!=(const Pixel< dtype > &rhs) const noexcept
Definition: Pixel.hpp:104
nc::imageProcessing::Pixel::operator<<
friend std::ostream & operator<<(std::ostream &inStream, const Pixel< dtype > &inPixel)
Definition: Pixel.hpp:168
nc::imageProcessing::Pixel::Pixel
constexpr Pixel(uint32 inRow, uint32 inCol, dtype inIntensity) noexcept
Definition: Pixel.hpp:73
nc::imageProcessing::Pixel::col
uint32 col
Definition: Pixel.hpp:56
Types.hpp
nc::imageProcessing::Pixel::clusterId
int32 clusterId
Definition: Pixel.hpp:54
nc::imageProcessing::Pixel::row
uint32 row
Definition: Pixel.hpp:55
nc::imageProcessing::Pixel
Holds the information for a single pixel.
Definition: Pixel.hpp:47