00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #pragma once
00023 #include "Node.h"
00024 #include "Point.h"
00025 #include "global.h"
00026 #include <stdlib.h>
00027 #include <iostream>
00028 using namespace std;
00029 namespace Recognition{
00033 class PointList{
00034 private:
00035 Node *head;
00036 Node *curr;
00037 int Size;
00038 public:
00040 Node* gHead(){return head;}
00042 void removeDoubles();
00043
00044 PointList(void);
00045 ~PointList(void);
00047 void add(float imgx,float imgy,int gridx=-1, int gridy=-1){
00048 Node *temp=new Node(imgx,imgy,gridx,gridy,NULL,head);
00049 head=temp;
00050 Size++;
00051 }
00053 void del(){
00054 if(curr==NULL)
00055 return;
00056 if(curr==head)
00057 head=head->next;
00058 Node *next=curr->next;
00059 Node *prev=curr->prev;
00060 if(prev!=NULL)
00061 prev->next=next;
00062 if(next!=NULL)
00063 next->prev=prev;
00064 delete curr;
00065 curr=next;
00066 Size--;
00067 }
00069 void del(Node *target){
00070 if(target==head){
00071 head=head->next;
00072 }
00073 if(target->next!=NULL)
00074 target->next->prev=target->prev;
00075 if(target->prev!=NULL)
00076 target->prev->next=target->next;
00077 if(curr==target)
00078 curr=target->next;
00079 delete target;
00080 Size--;
00081 }
00082
00085 Point* next(){
00086
00087 curr=curr->next;
00088 if(curr==NULL)
00089 return NULL;
00090 return &(curr->data);
00091 }
00093 Point* current(){
00094 if(curr==NULL)
00095 return NULL;
00096 return &(curr->data);
00097 }
00099 void reset(){
00100 curr=head;
00101 }
00103 int size(){return Size;}
00104
00106 Node* closest(Point &p,double limit){
00107 Node* temp=head;
00108 Node* best=head;
00109 double bestD=dist(head->data,p);
00110 double dt;
00111 temp=head->next;
00112
00113 while(temp!=NULL){
00114 dt=dist(temp->data,p);
00115 if(dt<bestD){
00116 bestD=dt;
00117 best=temp;
00118 }
00119 temp=temp->next;
00120 }
00121 if(bestD<=limit)
00122 return best;
00123 return NULL;
00124 }
00125 PointList & operator=(PointList &that){
00126 if(this==&that)
00127 return *this;
00128
00129 Node *cur=head;
00130 Node *prev;
00131 while(cur!=NULL){
00132 prev=cur;
00133 cur=cur->next;
00134 delete prev;
00135 }
00136
00137 head=that.head;
00138 curr=head;
00139 Size=that.Size;
00140 that.head=NULL;
00141 that.curr=NULL;
00142 that.Size=0;
00143 return *this;
00144
00145 }
00146 void print(){
00147 Node *cur=head;
00148 while(cur!=NULL){
00149 cur->data.print();
00150 cur=cur->next;
00151 }
00152 }
00153
00154 };}