AliceVision
Photogrammetric Computer Vision Framework
Pixel.hpp
1 // This file is part of the AliceVision project.
2 // Copyright (c) 2017 AliceVision contributors.
3 // This Source Code Form is subject to the terms of the Mozilla Public License,
4 // v. 2.0. If a copy of the MPL was not distributed with this file,
5 // You can obtain one at https://mozilla.org/MPL/2.0/.
6 
7 #pragma once
8 
9 #include <aliceVision/mvsData/Point2d.hpp>
10 
11 namespace aliceVision {
12 
13 struct Pixel
14 {
15  union
16  {
17  struct
18  {
19  int x, y;
20  };
21  int m[2];
22  };
23 
24  Pixel()
25  {
26  x = 0;
27  y = 0;
28  }
29 
30  explicit Pixel(const Point2d& p)
31  {
32  x = (int)floor(p.x + 0.5);
33  y = (int)floor(p.y + 0.5);
34  }
35 
36  Pixel(const int _x, const int _y)
37  {
38  x = _x;
39  y = _y;
40  }
41 
42  inline int& operator[](const int index) { return m[index]; }
43 
44  inline Pixel& operator=(const Pixel& param)
45  {
46  x = param.x;
47  y = param.y;
48  return *this;
49  }
50 
51  inline bool operator==(const Pixel& param) { return ((x == param.x) && (y == param.y)); }
52 
53  inline Pixel operator-(const Pixel& _p) { return Pixel(x - _p.x, y - _p.y); }
54 
55  inline Pixel operator+(const Pixel& _p) { return Pixel(x + _p.x, y + _p.y); }
56 
57  inline Pixel operator*(const int& d) { return Pixel(x * d, y * d); }
58 
59  inline Pixel operator/(int d)
60  {
61  if (d == 0)
62  {
63  return Pixel(0, 0);
64  }
65  else
66  {
67  Pixel p;
68  p.x = (int)floor((float)x / (float)d + 0.5);
69  p.y = (int)floor((float)y / (float)d + 0.5);
70  return p;
71  };
72  }
73 
74  inline double size() { return sqrt((double)(x * x + y * y)); }
75  inline int size2() { return x * x + y * y; }
76 
77  friend int dot(const Pixel& p1, const Pixel& p2) { return p1.x * p2.x + p1.y * p2.y; }
78 };
79 
80 } // namespace aliceVision
aliceVision::feature::Pixel
Definition: descriptorLIOP.cpp:20
aliceVision
Definition: checkerDetector.cpp:32
aliceVision::Point2d
Definition: Point2d.hpp:14