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

HxBlob2d.h

00001 /*
00002  *  Copyright (c) 1998, University of Amsterdam, The Netherlands.
00003  *  All rights reserved.
00004  *
00005  *
00006  *  Author(s):
00007  *  Leon Todoran (todoran@wins.uva.nl)
00008  *  Dennis Koelma (koelma@wins.uva.nl)
00009  */
00010 
00011 #ifndef HxBlob2d_h
00012 #define HxBlob2d_h
00013 
00014 #include <list>
00015 #include <map>
00016 #include "HxImageRep.h"
00017 #include "HxFreemanChain2d.h"
00018 #include "HxNameTable.h"
00019 #include "HxBlob2dFeatureTem.h"
00020 
00021 
00027 class HxBlob2d
00028 {
00029 public:
00031                             HxBlob2d();
00032 
00040                             HxBlob2d(int label, int xmin, int ymin,
00041                                      int width, int height);
00042 
00044                             ~HxBlob2d();
00045 
00047     int                     ident() const;
00048     /* deprecated
00049     HxImageRep              getInputImage() const;
00050     HxImageRep              getLabeledImage() const;
00051     */
00055     int                     getLabel() const;
00056 
00058     HxPoint                 startMaer() const;
00059 
00061     HxSizes                 sizeMaer() const;
00062 
00063     /* deprecated
00064     HxFreemanChain2d        getContour() const;
00065 
00066                             // these are to simplify the SA interface
00067     int                     getContourX() const;
00068     int                     getContourY() const;
00069     int                     getContourLength() const;
00070     void                    getContourCodes(int* codes) const;
00071     void                    getRgbPixels(int* pixels) const;
00072     */
00073 
00075     template<class T> void
00076     addFeature(HxString name, const T& val)
00077     {
00078         HxNameTable::sizeType id = _featNameTable.getId(name);
00079         addFeature(id, val);
00080     }
00081 
00083     template<class T> void
00084     addFeature(HxNameTable::sizeType id, const T& val)
00085     {
00086         HxBlob2dFeature* feat = new HxBlob2dFeatureTem<T>(val);
00087         _features[id] = feat;
00088     }
00089 
00091     template<class T> bool  
00092     getFeature(HxString name, T& val) const
00093     {
00094         HxNameTable::sizeType id = _featNameTable.getId(name);
00095         return getFeature(id, val);
00096     }
00097 
00099     template<class T> bool  
00100     getFeature(HxNameTable::sizeType id, T& val) const
00101     {
00102         FeatureMap::const_iterator it = _features.find(id);
00103         if (it == _features.end())
00104             return false;
00105         HxBlob2dFeature* base = (*it).second;
00106         HxBlob2dFeatureTem<T>* featPtr = 
00107             dynamic_cast<HxBlob2dFeatureTem<T>* > (base);
00108         if (featPtr == 0)
00109             return false; // was other type
00110         val = featPtr->getValue();
00111         return true;
00112     }
00113 
00115     int                     getFeatureInt(HxString name) const;
00116 
00118     HxValue                 getFeatureValue(HxString name) const;
00119 
00121     STD_OSTREAM&            put(STD_OSTREAM& os) const;
00122 
00124     static 
00125     std::vector<HxString>   getFeatureNames();
00126 
00127 private:
00128     //HxImageRep              _inputImage; // could be color, gray-level, etc.
00129     //HxImageRep              _labImage; // for access to connected component,
00130                                        // (should we use a mask?)
00131     int                     _ident;    // unique identifier
00132     int                     _label;    // identification label of the component
00133     int                     _xmin;
00134     int                     _ymin;
00135     int                     _width;
00136     int                     _height;
00137     //HxFreemanChain2d        _chain;
00138 
00139     typedef std::map<HxNameTable::sizeType, HxBlob2dFeature*> FeatureMap;
00140     FeatureMap              _features;
00141 
00142     static int              _nr;
00143     static HxNameTable      _featNameTable;
00144 };
00145 
00146 inline STD_OSTREAM&
00147 operator<<(STD_OSTREAM& os, const HxBlob2d& blob)
00148 {
00149     return blob.put(os);
00150 }
00151 
00152 inline HxString
00153 makeString(const HxBlob2d& b)
00154 {
00155     return HxString("HxBlob2d") + makeString(b.ident());
00156 }
00157 
00161 struct HxBlob2dPtrLess
00162 {
00163     bool 
00164     operator() (HxBlob2d* b1, HxBlob2d* b2) const 
00165     {
00166         return b1->getLabel() < b2->getLabel();
00167     }
00168 };
00169 
00170 #endif

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