NumCpp  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  else if (row == rhs.row)
129  {
130  if (col < rhs.col)
131  {
132  return true;
133  }
134  else
135  {
136  return false;
137  }
138  }
139  else
140  {
141  return false;
142  }
143  }
144 
145  //=============================================================================
146  // Description:
152  std::string str() const
153  {
154  std::string out = "row = " + utils::num2str(row) + " col = " + utils::num2str(col);
155  out += " intensity = " + utils::num2str(intensity) + "\n";
156  return out;
157  }
158 
159  //============================================================================
163  void print() const
164  {
165  std::cout << *this;
166  }
167 
168  //=============================================================================
169  // Description:
177  friend std::ostream& operator<<(std::ostream& inStream, const Pixel<dtype>& inPixel)
178  {
179  inStream << inPixel.str();
180  return inStream;
181  }
182  };
183  }
184 }
StaticAsserts.hpp
nc::int32
std::int32_t int32
Definition: Types.hpp:37
nc::imageProcessing::Pixel::str
std::string str() const
Definition: Pixel.hpp:152
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:163
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:177
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