Lens distortion correction division model 1p
 All Classes Files Functions Variables
point2d.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010-2013, AMI RESEARCH GROUP <lalvarez@dis.ulpgc.es>
3  License : CC Creative Commons "Attribution-NonCommercial-ShareAlike"
4  see http://creativecommons.org/licenses/by-nc-sa/3.0/es/deed.en
5  */
6 
7 
8 #ifndef AMI_DLL_H
9  #define AMI_DLL_H
10 #endif
11 
17 #ifndef POINT2D_H
18 #define POINT2D_H
19 #include <iostream>
20 #include <math.h>
21 #include <vector>
22 
23 using namespace std;
24 
25 namespace ami
26 {
27 
33 template < class T >
34 class AMI_DLL_H point2d {
35 
36  public :
37  T x ;
38  T y ;
39  point2d():x( (T) 0), y( (T) 0){};
40  ~point2d(){};
41  point2d(const T xx , const T yy){x=xx; y=yy;}
42  point2d(const T scalar){x=y=scalar;}
43  point2d & operator=(const point2d &p){ x=p.x; y=p.y; return *this;}
44  point2d & operator=(const T scalar){ x=scalar; y=scalar; return *this;}
45  point2d (const point2d<T> &p){x=p.x; y=p.y;}
46  point2d operator+(const point2d &p)const {return point2d(x+p.x,y+p.y);}
47  point2d operator-(const point2d &p)const {return point2d(x-p.x,y-p.y);}
48  point2d operator*(const T &a)const {return point2d(a*x,a*y);}
49  double operator*(const point2d &p)const {return ( (double) x*p.x+y*p.y);}
50  inline T norm(){T paso=x*x+y*y; return(paso>0.?sqrtf((float) paso):0.);}
51  inline T norm2(){ return(x*x+y*y);}
52  void print(){ std::cout << "point2d : (" << x << "," << y << ")" <<
53  std::endl;}
54  int find_nearest_point(std::vector< point2d <T> > primitive);
55  void find_nearest_point(std::vector< point2d <T> > primitive,int &id,
56  T &distance);
57  bool operator!=(const T scalar) const {return(x!=scalar && y!=scalar);}
58 };
59 
61 
70 template <class T>
71  int point2d<T>::find_nearest_point(std::vector< point2d <T> > primitive)
72  {
73  //FIND THE NEAREST POINT TO THE ACTUAL POINT
74  T min_dist,dist;
75  int min=-1;
76  min_dist=99999;
77  point2d<T> point_p;
78  for(unsigned int i=0;i<primitive.size();i++)
79  {
80  point_p.x=primitive[i].x;
81  point_p.y=primitive[i].y;
82  dist = ((*this)-point_p).norm2(); //DISTANCE
83  if(dist < min_dist)
84  {
85  min_dist=dist;
86  min=i;
87  }
88  }
89  return min;
90  }
91 
92 
102 template <class T>
103  void point2d<T>::find_nearest_point(std::vector< point2d <T> >primitive,
104  int &id, T &distance)
105  {
106  //FIND THE NEAREST POINT TO THE ACTUAL POINT
107  T dist;
108  id=-1;
109  distance=99999;
110  point2d<T> point_p;
111  for(unsigned int i=0;i<primitive.size();i++)
112  {
113  point_p.x=primitive[i].x;
114  point_p.y=primitive[i].y;
115  dist = ((*this)-point_p).norm2(); //DISTANCE
116  if(dist < distance)
117  {
118  distance=dist;
119  id=i;
120  }
121  }
122  }
123 
124 }
125 #endif
T x
Definition: point2d.h:37
class to store 2D points and basic methods
Definition: point2d.h:34
T y
Definition: point2d.h:38