ccstruct/points.h

Go to the documentation of this file.
00001 
00020 #ifndef           POINTS_H
00021 #define           POINTS_H
00022 
00023 #include          <stdio.h>
00024 #include          <math.h>
00025 #include          "elst.h"
00026 //#include                                      "ipeerr.h"
00027 
00028 class FCOORD;
00029 
00034 class DLLSYM ICOORD
00035 {
00036   friend class FCOORD;
00037 
00038   public:
00039     ICOORD() {  //empty constructor
00040       xcoord = ycoord = 0;       //default zero
00041     }
00042     ICOORD(              //constructor
00043            INT16 xin,    //x value
00044            INT16 yin) {  //y value
00045       xcoord = xin;
00046       ycoord = yin;
00047     }
00048     ~ICOORD () {                 //destructor
00049     }
00050 
00051                                  //access function
00052     NEWDELETE2 (ICOORD) INT16 x () const
00053     {
00054       return xcoord;
00055     }
00056     INT16 y() const {  //access_function
00057       return ycoord;
00058     }
00059 
00060     void set_x(  //rewrite function
00061                INT16 xin) {
00062       xcoord = xin;              //write new value
00063     }
00064     void set_y(              //rewrite function
00065                INT16 yin) {  //value to set
00066       ycoord = yin;
00067     }
00068 
00069     float sqlength() const {  //find sq length
00070       return (float) (xcoord * xcoord + ycoord * ycoord);
00071     }
00072 
00073     float length() const {  //find length
00074       return (float) sqrt (sqlength ());
00075     }
00076 
00077     float pt_to_pt_sqdist(  //sq dist between pts
00078                           const ICOORD &pt) const {
00079       ICOORD gap;
00080 
00081       gap.xcoord = xcoord - pt.xcoord;
00082       gap.ycoord = ycoord - pt.ycoord;
00083       return gap.sqlength ();
00084     }
00085 
00086     float pt_to_pt_dist(  //Distance between pts
00087                         const ICOORD &pt) const {
00088       return (float) sqrt (pt_to_pt_sqdist (pt));
00089     }
00090 
00091     float angle() const {  //find angle
00092       return (float) atan2 ((double) ycoord, (double) xcoord);
00093     }
00094 
00095     BOOL8 operator== (           //test equality
00096     const ICOORD & other) {
00097       return xcoord == other.xcoord && ycoord == other.ycoord;
00098     }
00099     BOOL8 operator!= (           //test inequality
00100     const ICOORD & other) {
00101       return xcoord != other.xcoord || ycoord != other.ycoord;
00102     }
00103     friend ICOORD operator! (    //rotate 90 deg anti
00104       const ICOORD &);
00105     friend ICOORD operator- (    //unary minus
00106       const ICOORD &);
00107     friend ICOORD operator+ (    //add
00108       const ICOORD &, const ICOORD &);
00109     friend ICOORD & operator+= ( //add
00110       ICOORD &, const ICOORD &);
00111     friend ICOORD operator- (    //subtract
00112       const ICOORD &, const ICOORD &);
00113     friend ICOORD & operator-= ( //subtract
00114       ICOORD &, const ICOORD &);
00115     friend INT32 operator% (     //scalar product
00116       const ICOORD &, const ICOORD &);
00117     friend INT32 operator *(  //cross product
00118                             const ICOORD &,
00119                             const ICOORD &);
00120     friend ICOORD operator *(  //multiply
00121                              const ICOORD &,
00122                              INT16);
00123     friend ICOORD operator *(  //multiply
00124                              INT16,
00125                              const ICOORD &);
00126     friend ICOORD & operator*= ( //multiply
00127       ICOORD &, INT16);
00128     friend ICOORD operator/ (    //divide
00129       const ICOORD &, INT16);
00130                                  //divide
00131     friend ICOORD & operator/= (ICOORD &, INT16);
00132     void rotate(                    //rotate
00133                 const FCOORD& vec);  //by vector
00134 
00135     void serialise_asc(  //serialise to ascii
00136                        FILE *f);
00137     void de_serialise_asc(  //serialise from ascii
00138                           FILE *f);
00139 
00140   protected:
00142     INT16 xcoord;
00144     INT16 ycoord;
00145 };
00146 
00151 class DLLSYM ICOORDELT:public ELIST_LINK, public ICOORD
00152 {
00153   public:
00154     ICOORDELT() {  //empty constructor
00155     }
00156     ICOORDELT (                  //constructor
00157                                  //from ICOORD
00158     ICOORD icoord):ICOORD (icoord) {
00159     }
00160     ICOORDELT(              //constructor
00161               INT16 xin,    //x value
00162               INT16 yin) {  //y value
00163       xcoord = xin;
00164       ycoord = yin;
00165     }
00166 
00172     void prep_serialise() const {  //set ptrs to counts
00173     }
00174 
00175     void dump(  //write external bits
00176               FILE *) const {
00177     }
00178 
00179     void de_dump(  //read external bits
00180                  FILE *) {
00181     }
00182 
00183                                  //serialise to ascii
00184     make_serialise (ICOORDELT) void serialise_asc (
00185       FILE * f);
00186     void de_serialise_asc(  //serialise from ascii
00187                           FILE *f);
00188 
00189 };
00190 
00191 ELISTIZEH_S (ICOORDELT)
00192 
00197 class DLLSYM FCOORD
00198 {
00199   public:
00200     FCOORD() { 
00201     }                            //empty constructor
00202     FCOORD(               //constructor
00203            float xvalue,  //coords to set
00204            float yvalue) {
00205       xcoord = xvalue;           //set coords
00206       ycoord = yvalue;
00207     }
00208     FCOORD(                  //make from ICOORD
00209            ICOORD icoord) {  //coords to set
00210       xcoord = icoord.xcoord;
00211       ycoord = icoord.ycoord;
00212     }
00213 
00214     float x() const {  //get coords
00215       return xcoord;
00216     }
00217     float y() const { 
00218       return ycoord;
00219     }
00220     void set_x(  //rewrite function
00221                float xin) {
00222       xcoord = xin;              //write new value
00223     }
00224     void set_y(              //rewrite function
00225                float yin) {  //value to set
00226       ycoord = yin;
00227     }
00228 
00229     float sqlength() const {  //find sq length
00230       return xcoord * xcoord + ycoord * ycoord;
00231     }
00232 
00233     float length() const {  //find length
00234       return (float) sqrt (sqlength ());
00235     }
00236 
00237     float pt_to_pt_sqdist(  //sq dist between pts
00238                           const FCOORD &pt) const {
00239       FCOORD gap;
00240 
00241       gap.xcoord = xcoord - pt.xcoord;
00242       gap.ycoord = ycoord - pt.ycoord;
00243       return gap.sqlength ();
00244     }
00245 
00246     float pt_to_pt_dist(  //Distance between pts
00247                         const FCOORD &pt) const {
00248       return (float) sqrt (pt_to_pt_sqdist (pt));
00249     }
00250 
00251     float angle() const {  //find angle
00252       return (float) atan2 (ycoord, xcoord);
00253     }
00254 
00255     bool normalise();  //Convert to unit vec
00256 
00257     BOOL8 operator== (           //test equality
00258     const FCOORD & other) {
00259       return xcoord == other.xcoord && ycoord == other.ycoord;
00260     }
00261     BOOL8 operator!= (           //test inequality
00262     const FCOORD & other) {
00263       return xcoord != other.xcoord || ycoord != other.ycoord;
00264     }
00265                                  //rotate 90 deg anti
00266     friend FCOORD operator! (const FCOORD &);
00267                                  //unary minus
00268     friend FCOORD operator- (const FCOORD &);
00269                                  //add
00270     friend FCOORD operator+ (const FCOORD &, const FCOORD &);
00271                                  //add
00272     friend FCOORD & operator+= (FCOORD &, const FCOORD &);
00273                                  //subtract
00274     friend FCOORD operator- (const FCOORD &, const FCOORD &);
00275                                  //subtract
00276     friend FCOORD & operator-= (FCOORD &, const FCOORD &);
00277                                  //scalar product
00278     friend float operator% (const FCOORD &, const FCOORD &);
00279                                  //cross product
00280     friend float operator *(const FCOORD &, const FCOORD &); 
00281     friend FCOORD operator *(const FCOORD &, float); 
00282     //multiply
00283     friend FCOORD operator *(float, const FCOORD &); 
00284     //multiply
00285                                  //multiply
00286     friend FCOORD & operator*= (FCOORD &, float);
00287     friend FCOORD operator/ (const FCOORD &, float);
00288     //divide
00289     void rotate(                    //rotate
00290                 const FCOORD vec);  //by vector
00291                                  //divide
00292     friend FCOORD & operator/= (FCOORD &, float);
00293 
00294   private:
00296     float xcoord;
00298     float ycoord;
00299 };
00300 
00301 #include          "ipoints.h"    /*do inline funcs */
00302 #endif

Generated on Wed Feb 28 19:49:08 2007 for Tesseract by  doxygen 1.5.1