DLConnectedComponents.h

Go to the documentation of this file.
00001 #ifndef _DLCONNECTEDCOMPONENTS_H_
00002 #define _DLCONNECTEDCOMPONENTS_H_
00003 
00004 #include "DLImage.h"
00005 #include "DLComponent.h"
00006 #include "DLConst.h"
00007 #include "DLTypes.h"
00008 //#include "DLCompIterator.h"
00009 
00010 #include <vector>
00011 using namespace std;
00012 
00051 class DLConnectedComponents
00052 {
00053    public:
00054 
00058    DLConnectedComponents();
00059 
00063    DLConnectedComponents(const DLConnectedComponents & orig);
00064 
00069    const DLConnectedComponents & operator=(const DLConnectedComponents & right);
00070 
00071 
00075    virtual ~DLConnectedComponents();
00076 
00084    void dlCreateConnectedComponents(const DLImage &img);
00085 
00096    vector <DLComponent> dlGetConnectedComponents()  const;
00097 
00101    void dlCalculateMoments();
00102    
00117    vector <DLComponent> dlGetFilteredCCs()  const;
00118 
00119 
00126    void dlResetCCFilter();
00127 
00129 
00130 
00139    int dlFilterCCHeightBetween(int minHeight, int maxHeight);
00140 
00149    int dlFilterCCWidthBetween(int minWidth, int maxWidth);
00150 
00161    int dlFilterCCRemoveTopBottom(int toprow, int bottomrow);
00162 
00173    int dlFilterCCRemoveLeftRight(int leftcol, int rightcol);
00174 
00185    int dlFilterCCDensityGreater(float density);
00186 
00197    int dlFilterCCDensityLess(float density);
00198 
00211    int dlFilterCCDensityBetween(float mindensity, float maxdensity);
00212 
00222    int dlFilterCCBoxLess(float width, float height);
00223 
00233    int dlFilterCCBoxGreater(float width, float height);
00234 
00244    int dlFilterCCMassGreater(float mass);
00245 
00255    int dlFilterCCMassLess(float mass);
00256 
00266    int dlFilterCCMassBetween(float minmass, float maxmass); 
00267 
00269 
00274    DLImage dlRenderCCs();
00275 
00284    DLImage dlRenderFilteredCCs();
00285 
00291    DLImage dlRenderColorCCs();
00292 
00297    DLConnectedComponents dlCopyCCs();
00298 
00305    void setCalConvexHulls(bool calculateConvexHulls);
00306 
00311    bool getCalConvexHalls()  const;
00312 
00317    void setCalMoments(bool calculateMoments);
00318 
00323    bool getCalMoments()  const;
00324 
00331    int dlGetNumCCs() const;
00332 
00344    const vector<int> dlGetConnectedCCMap();
00345 
00354    void dlSetFilteredCCColor(DLColor color);
00355 
00367    template<typename COMP, typename CVEC, typename CVECITER, typename IVEC, typename IVECITER>
00368       class fiterator_base : public std::iterator<std::bidirectional_iterator_tag,
00369       CVEC> {
00370          public:
00378       fiterator_base() {
00379          ; // should add code to set iterator to known "fail" state
00380       }
00381 
00389       fiterator_base(CVEC * vc, IVEC * idxs, bool b)
00390          : myvector_p(vc), filteredIdxs_p(idxs) {
00391 
00392          if (b) {
00393             // for begin()
00394             // set internal DLComponent iterator to beginning of the vector of
00395             // DLComponents; then advance it to point to the first filtered component
00396             filtIdx_iter = filteredIdxs_p->begin();
00397             myiter = myvector_p->begin();
00398             advance(myiter, *filtIdx_iter);
00399          } else {
00400             // for end()
00401 
00402             // set internal DLComponent iterator to its end (so we can check against it)
00403             filtIdx_iter = filteredIdxs_p->end();
00404             myiter = myvector_p->end();
00405          }
00406 
00407       }
00408 
00414       COMP & operator* () const {
00415          return (*myiter);
00416       }
00417 
00423       COMP * operator-> () const{
00424          return &(*myiter);
00425       }
00426 
00430       bool operator!= (const fiterator_base & right) const{
00431          return myiter != right.myiter;
00432       }
00433 
00437       bool operator== (const fiterator_base & right) {
00438          return myiter == right.myiter;
00439       }
00440 
00445       const fiterator_base operator++() {
00446          int oldpos = *filtIdx_iter; // save current position
00447          ++filtIdx_iter;             // advance filtered index iterator
00448 
00449          if (filtIdx_iter == filteredIdxs_p->end()) {
00450             // if we've reached the last of the filtered components, return "end"
00451             myiter = myvector_p->end();
00452          } else {
00453             // advance the internal DLComponent iterator to the next filtered component
00454             advance(myiter, *filtIdx_iter - oldpos );
00455          }
00456          return *this;
00457       }
00458 
00459          protected:
00460 
00462       CVEC * myvector_p; 
00464       CVECITER myiter; 
00466       IVEC * filteredIdxs_p; 
00468       IVECITER filtIdx_iter; 
00469 
00470    }; // class DLConnectedComponents::fiterator
00471 
00472 
00473    
00476    typedef std::vector<DLComponent>::iterator iterator;
00477 
00482    typedef std::vector<DLComponent>::const_iterator const_iterator;
00483 
00486    typedef fiterator_base<const DLComponent, 
00487       const std::vector<DLComponent>, std::vector<DLComponent>::const_iterator,
00488       const std::vector<int>, std::vector<int>::const_iterator> const_fiterator;
00489 
00492    typedef fiterator_base<DLComponent,
00493       std::vector<DLComponent>, std::vector<DLComponent>::iterator,
00494       std::vector<int>, std::vector<int>::iterator> fiterator;
00498    iterator begin() { return cComponents.begin(); }
00499 
00504    const_iterator begin() const {return cComponents.begin();}
00505 
00510    const_iterator end() const { return cComponents.end(); }
00511 
00516    iterator end() { return cComponents.end(); } 
00517 
00523    fiterator fbegin() { return fiterator(&cComponents,&filtCompIndices,true); }
00524 
00530    fiterator fend() { return fiterator(&cComponents,&filtCompIndices,false); }
00531 
00532 
00538    const_fiterator fbegin() const { return const_fiterator(&cComponents,&filtCompIndices,true); }
00539 
00545    const_fiterator fend() const { return const_fiterator(&cComponents,&filtCompIndices,false); }
00546 
00547    private:
00549    bool calConvexHulls;
00550 
00552    bool calMoments;
00553 
00555    vector <DLComponent> cComponents;
00556 
00558    vector<int> ccMapVector;
00559 
00561    vector <int> filtCompIndices;
00562 
00564    int imageHeight;
00565 
00567    int imageWidth;
00568 
00572    int needToReCalculateCCMap;
00573 
00574 
00575 
00576 };//end class
00577 
00578 #endif //_DLCONNECTEDCOMPONENTS_H_

DOCLIB is being developed under contract by a collaboration between:
The Laboratory for Language and Media Processing
Unviersity of Maryland, College Park
and
Booz | Allen | Hamilton

All Rights Reserved, 2003-2007