Horus Doc || C++ Reference || Class Overview   Pixels   Images   Detector   Geometry   Registry || Doxygen's quick Index  

HxIndxArray.h

00001 /*
00002  *  Copyright (c) 2000, University of Amsterdam, The Netherlands.
00003  *  All rights reserved.
00004  *
00005  *  Author(s):
00006  *  Jan-Mark Geusebroek (mark@wins.uva.nl)
00007  *
00008  */
00009 
00010 /*
00011  *  JV, 06Mar03: added at+getKey function for random access to data
00012  */
00013 
00014 #ifndef HxIndxArray_H
00015 #define HxIndxArray_H
00016 
00017 #include <stdio.h>
00018 #include <list>
00019 #include "HxMatrix.h"
00020 
00021 
00022 template<class ArrayT, class HeaderT>
00023 class indexedArray {
00024 public:
00025     indexedArray();
00026     ~indexedArray();
00027 
00028     void open(HxString indexFile, int norm = 0);
00029     void close();
00030     void append(HxString indexFile);
00031     void create(HxString indexFile);
00032     void setHeader(HeaderT& header)
00033         {_header = header;}
00034         // should be called after create, before the first add
00035 
00036     HeaderT     header() const {return _header;}
00037 
00038     int         size() const {return _key.size();}
00039 
00040     virtual int arraySize(const HeaderT& header) const = 0;
00041     virtual double compare(ArrayT *e1, ArrayT *e2,
00042         const HeaderT& header) const = 0;
00043 
00044     void        add(HxString& key, ArrayT *data);
00045 
00046     ArrayT*     getData(HxString key) const;
00047 
00048     void        random(int n);
00049     void        search(ArrayT *target, int n, int refine = 0);
00050     void        retrieve(HxString key, int n, int refine = 0);
00051     HxString    nearest(int n) const;
00052     double      score(int n) const;
00053     ArrayT*     nearestData(int n) const;
00054 
00055     HxMatrix    similarity() const;
00056     STD_OSTREAM& put(STD_OSTREAM& os) const;
00057 
00058     void        import(STD_ISTREAM& is);
00059 
00060         /* Returns the data for the ndx-th element. */
00061     ArrayT*     at(int ndx) const;
00062     
00063         /* Returns the key of the ndx-th element. */
00064     HxString    getKey(int ndx) const;
00065 
00066     friend STD_OSTREAM& operator<<(STD_OSTREAM& os,
00067             const indexedArray<ArrayT, HeaderT>& l)
00068                 {return l.put(os);}
00069 
00070 
00071 private:
00072     HeaderT     _header;
00073     HxString     _fileName;
00074 
00075     FILE        *_fp;
00076     char        *_mem;
00077 
00078     int         _arraySize;
00079 
00080     std::list<ArrayT*>   _arrays;
00081     std::list<char*>        _key;
00082 
00083     double      *_nearval;
00084     char        **_nearkey;
00085     ArrayT      **_neardata;
00086 
00087     int         _normalize;
00088     ArrayT      *_minVal;
00089     ArrayT      *_normVal;
00090 };
00091 
00092 class indexedFloatArray : public indexedArray<float, int>  {
00093     int         arraySize(const int& header) const
00094                     {return header;}
00095     double      compare(float *e1, float *e2, const int& size) const
00096                     {
00097                         double norm2 = 0.0;
00098                         double v;
00099 
00100                         for (int i = size; i > 0; i--) {
00101                             v = *e1++ - *e2++;
00102                             norm2 += v*v;
00103                         }
00104 
00105                         return sqrt(norm2);
00106                     }
00107 };
00108 
00109 #ifdef INC_TEMPLATE_SRC
00110 #include "HxIndxArray.c"
00111 #endif
00112 
00113 #endif

Generated on Tue Feb 3 14:18:38 2004 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001