algebraic lens distortion

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Defines
point2d.h
Go to the documentation of this file.

    00001 #ifndef AMI_DLL_H
    00002 #define AMI_DLL_H
    00003 #endif
    00004
    00010 #ifndef POINT2D_H
    00011 #define POINT2D_H
    00012 #include <iostream>
    00013 #include <math.h>
    00014 #include <vector>
    00015
    00016 using namespace std;
    00017
    00018 namespace ami
    00019 {
    00020
    00026 template < class  T >
    00027 class AMI_DLL_H point2d {
    00028
    00029 public :
    00030     T x ;
    00031     T y ;
    00032     point2d():x( (T) 0), y( (T) 0) {};
    00033     ~point2d() {};
    00034     point2d(const T xx , const T yy) {
    00035         x=xx;
    00036         y=yy;
    00037     }
    00038     point2d(const T scalar) {
    00039         x=y=scalar;
    00040     }
    00041     point2d & operator=(const point2d &p) {
    00042         x=p.x;
    00043         y=p.y;
    00044         return *this;
    00045     }
    00046     point2d & operator=(const T scalar) {
    00047         x=scalar;
    00048         y=scalar;
    00049         return *this;
    00050     }
    00051     point2d (const point2d<T> &p) {
    00052         x=p.x;
    00053         y=p.y;
    00054     }
    00055     point2d operator+(const point2d &p)const {
    00056         return point2d(x+p.x,y+p.y);
    00057     }
    00058     point2d operator-(const point2d &p)const {
    00059         return point2d(x-p.x,y-p.y);
    00060     }
    00061     point2d operator*(const T &a)const {
    00062         return point2d(a*x,a*y);
    00063     }
    00064     double operator*(const point2d &p)const {
    00065         return ( (double) x*p.x+y*p.y);
    00066     }
    00067     inline T norm() {
    00068         T paso=x*x+y*y;
    00069         return(paso>0.?sqrtf((float) paso):0.);
    00070     }
    00071     inline T norm2() {
    00072         return(x*x+y*y);
    00073     }
    00074     void print() {
    00075         std::cout << "point2d : (" << x << "," << y << ")" << std::endl;
    00076     }
    00077     int find_nearest_point(std::vector< point2d <T> > primitive);
    00078     void find_nearest_point(std::vector< point2d <T> > primitive,int &id, T &distance);
    00079     bool operator!=(const T scalar) const {
    00080         return(x!=scalar && y!=scalar);
    00081     }
    00082 };
    00083
    00085
    00091 template <class  T>
    00092 int point2d<T>::find_nearest_point(std::vector< point2d <T> > primitive)
    00093 {
    00094     //FIND THE NEAREST POINT TO THE ACTUAL POINT
    00095     T min_dist,dist;
    00096     int min=-1;
    00097     min_dist=99999;
    00098     point2d<T> point_p;
    00099     for(unsigned int i=0; i<primitive.size(); i++)
    00100     {
    00101         point_p.x=primitive[i].x;
    00102         point_p.y=primitive[i].y;
    00103         dist = ((*this)-point_p).norm2(); //DISTANCE
    00104         if(dist < min_dist)
    00105         {
    00106             min_dist=dist;
    00107             min=i;
    00108         }
    00109     }
    00110     return min;
    00111 }
    00112
    00113
    00120 template <class  T>
    00121 void point2d<T>::find_nearest_point(std::vector< point2d <T> > primitive,int &id, T &distance)
    00122 {
    00123     //FIND THE NEAREST POINT TO THE ACTUAL POINT
    00124     T dist;
    00125     id=-1;
    00126     distance=99999;
    00127     point2d<T> point_p;
    00128     for(unsigned int i=0; i<primitive.size(); i++)
    00129     {
    00130         point_p.x=primitive[i].x;
    00131         point_p.y=primitive[i].y;
    00132         dist = ((*this)-point_p).norm2(); //DISTANCE
    00133         if(dist < distance)
    00134         {
    00135             distance=dist;
    00136             id=i;
    00137         }
    00138     }
    00139 }
    00140
    00141 }
    00142 #endif