Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ImageRegionData.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLCV/src/ICLCV/ImageRegionData.h                      **
00010 ** Module : ICLCV                                                  **
00011 ** Authors: Christof Elbrechter, Erik Weitnauer                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.GPL  **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLCore/Img.h>
00034 #include <ICLUtils/Any.h>
00035 #include <ICLCV/ImageRegionPart.h>
00036 #include <ICLCV/ImageRegion.h>
00037 #include <ICLUtils/StackTimer.h>
00038 #include <ICLCV/RegionPCAInfo.h>
00039 #include <ICLCV/CornerDetectorCSS.h>
00040 
00041 #include <set>
00042 
00043 namespace icl{
00044   namespace cv{
00045   
00047 
00049     struct ImageRegionData{
00050     private:
00051       typedef ImageRegionData IRD;
00052     public:
00053       friend class RegionDetector; 
00054       friend struct ImageRegion;     
00055       friend bool region_search_border(std::set<IRD*>&,IRD*); 
00056       friend void collect_subregions_recursive(std::set<IRD*>&,IRD*);
00057       friend bool is_region_contained(IRD*,IRD*);
00058       friend bool region_search_outer_bb(const utils::Rect&,std::set<IRD*>&,IRD*);
00059     
00060     private:
00062       int  value; 
00063       
00065       int id;
00066   
00068       mutable int size;
00069   
00071       const core::ImgBase *image;
00072   
00074       std::vector<LineSegment> segments;
00075       
00077       utils::Any meta;
00078   
00080       struct RegionGraphInfo{
00082         RegionGraphInfo():isBorder(false),parent(0){}
00083   
00085         bool isBorder;
00086         
00087         // region graph information
00088         std::set<ImageRegionData*> neighbours;
00089   
00090         // child regions
00091         std::vector<ImageRegionData*> children;
00092   
00094         ImageRegionData *parent;              
00095       } *graph; 
00096   
00097       // structure for representing simple region information
00098       struct SimpleInformation{
00099         inline SimpleInformation():
00100           boundingBox(0),cog(0),pcainfo(0),
00101           boundaryLength(0),boundary(0),
00102           thinned_boundary(0),pixels(0){}
00103         inline ~SimpleInformation(){
00104           if(boundingBox) delete boundingBox;
00105           if(cog) delete cog;
00106           if(pcainfo) delete pcainfo;
00107           if(boundary) delete boundary;
00108           if(thinned_boundary) delete thinned_boundary;
00109           if(pixels) delete pixels;
00110         }
00111         utils::Rect *boundingBox;      
00112         utils::Point32f *cog;          
00113         RegionPCAInfo *pcainfo; 
00114         int boundaryLength;     
00115   
00116         std::vector<utils::Point> *boundary;         
00117         std::vector<utils::Point> *thinned_boundary; 
00118         std::vector<utils::Point> *pixels;           
00119   
00120       } *simple; 
00121   
00122       struct CSSParams{
00123         float angle_thresh;
00124         float rc_coeff;
00125         float sigma;
00126         float curvature_cutoff;
00127         float straight_line_thresh;
00128         std::vector<utils::Point32f> resultBuffer;
00129   
00130         bool isOk(CornerDetectorCSS *css) const{
00131           return css->getAngleThreshold() == angle_thresh &&
00132           css->getRCCoeff() == rc_coeff &&
00133           css->getSigma() == sigma &&
00134           css->getCurvatureCutoff() == curvature_cutoff &&
00135           css->getStraightLineThreshold() == straight_line_thresh;
00136         }
00137   
00138         void setFrom(CornerDetectorCSS *css){
00139           angle_thresh = css->getAngleThreshold();
00140           rc_coeff = css->getRCCoeff();
00141           sigma = css->getSigma();
00142           curvature_cutoff = css->getCurvatureCutoff();
00143           straight_line_thresh = css->getStraightLineThreshold();
00144         }
00145       };
00146   
00148       struct ComplexInformation{
00149         inline ComplexInformation():
00150           directSubRegions(0),allSubRegions(0),parent(0),
00151           parentTree(0),publicNeighbours(0),cssParams(0){}
00152         inline ~ComplexInformation(){
00153           if(directSubRegions) delete directSubRegions;
00154           if(allSubRegions) delete allSubRegions;
00155           if(parent) delete parent;
00156           if(parentTree) delete parentTree;
00157           if(publicNeighbours) delete publicNeighbours;
00158           if(cssParams) delete cssParams;
00159         }
00160         std::vector<ImageRegion> *directSubRegions;         
00161         std::vector<ImageRegion> *allSubRegions;            
00162         ImageRegion *parent;                                
00163         std::vector<ImageRegion> *parentTree;               
00164         std::vector<ImageRegion> *publicNeighbours;         
00165         CSSParams *cssParams;
00166       } *complex; 
00167   
00168       
00169       CornerDetectorCSS *css; 
00170   
00172       static ImageRegionData *createInstance(CornerDetectorCSS *css, ImageRegionPart *topRegionPart, int id, bool createGraphInfo, const core::ImgBase *image);
00173   
00175       inline ImageRegionData(CornerDetectorCSS *css, int value, int id, unsigned int segmentSize, bool createGraph,const core::ImgBase *image):
00176         value(value),id(id),size(0),image(image),segments(segmentSize),graph(createGraph ? new RegionGraphInfo : 0),
00177       simple(0),complex(0),css(css){}
00178       
00180       inline ~ImageRegionData(){
00181         if(graph) delete graph;
00182         if(simple) delete simple;
00183         if(complex) delete complex;
00184       }
00185       
00186       // utility function (only if linkTable is not given)
00187       inline void link(ImageRegionData *a){
00188         if(this != a){
00189           if(a->graph->neighbours.size() < graph->neighbours.size()){
00190             if(a->graph->neighbours.insert(this).second){
00191               graph->neighbours.insert(a);
00192             }
00193           }else{
00194             if(graph->neighbours.insert(a).second){
00195               a->graph->neighbours.insert(this);
00196             }
00197           }
00198         }
00199       }
00200       
00202       inline void addChild(ImageRegionData *a){
00203         graph->children.push_back(a);
00204         a->graph->parent = this;
00205       }
00206       
00208       void showTree(int indent=0) const;
00209   
00211       void showWithNeighbours() const;
00212       
00214       inline ComplexInformation *ensureComplex(){
00215         if(!complex) complex = new ComplexInformation;
00216         return complex;
00217       }
00218       
00220       inline SimpleInformation *ensureSimple(){
00221         if(!simple) simple = new SimpleInformation;
00222         return simple;
00223       }
00224     };
00225     
00226   } // namespace cv
00227 }
00228 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines