Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

MakeSubRects.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Geometry_MakeSubRects_h
00002 #define Impala_Core_Geometry_MakeSubRects_h
00003 
00004 #include "Core/Geometry/RectangleSet.h"
00005 
00006 namespace Impala
00007 {
00008 namespace Core
00009 {
00010 namespace Geometry
00011 {
00012 
00019 template <class BackInsertIterator>
00020 inline void
00021 MakeSubRects(BackInsertIterator bi, int imWidth, int imHeight,
00022              int borderWidth, int nrRegionsX, int nrRegionsY, double overlap=0.5)
00023 {
00024 
00025     if(overlap < 0 || overlap >= 1)
00026     {
00027         std::cout << "MakeSubRects: overlap not between [0,1), overlap: "
00028                     << overlap << std::endl;
00029         exit(1);
00030     }
00031 
00032 //    std::cout << "imWidth: " << imWidth << std::endl;
00033 //    std::cout << "imHeight: " << imHeight << std::endl;
00034 
00035     imWidth -= 2*borderWidth;
00036     imHeight -= 2*borderWidth;
00037 
00038     int regionWidth =  imWidth/nrRegionsX;
00039     int regionHeight = imHeight/nrRegionsY;
00040 
00041 //    std::cout << "regionWidth: " << regionWidth << std::endl;
00042 //    std::cout << "regionHeight: " << regionHeight << std::endl;
00043 
00044     int regionXoffset = regionWidth/2;
00045     int regionYoffset = regionHeight/2;
00046 
00047     int incrementX = regionWidth*(1.0-overlap);
00048     int incrementY = regionHeight*(1.0-overlap);
00049 
00050 //    std::cout << "incrementX: " << incrementX << std::endl;
00051 //    std::cout << "incrementY: " << incrementY << std::endl;
00052 
00053 
00054     int maxRegionsX = ((imWidth-regionWidth) / incrementX ) +1;
00055     int maxRegionsY = ((imHeight-regionHeight) / incrementY ) +1;
00056 
00057 //    std::cout << "maxRegionsX: " << maxRegionsX << std::endl;
00058 //    std::cout << "maxRegionsY: " << maxRegionsY << std::endl;
00059 
00060     int nrRects = 0;
00061     int toProduce = maxRegionsX * maxRegionsY;
00062 
00063 
00064     int nrY = 1;
00065     for (int y=borderWidth+regionYoffset ;
00066          y<=imHeight-regionYoffset+borderWidth ; y+=incrementY)
00067     {
00068         if (nrY++ > maxRegionsY)
00069             continue;
00070         int nrX = 1;
00071         for(int x=borderWidth+regionXoffset ;
00072             x<=imWidth-regionXoffset+borderWidth ; x+=incrementX)
00073         {
00074             if (nrX++ > maxRegionsX)
00075                 continue;
00076             Rectangle rect(x-regionXoffset, y-regionYoffset,
00077                            x+regionXoffset-1, y+regionYoffset-1);
00078 //            std::cout << "new-rect: " << rect << std::endl;
00079             *bi++ = rect;
00080             nrRects++;
00081         }
00082     }
00083 
00084     if (nrRects != toProduce)
00085         std::cout << "MakeSubRects: produced incorrect number: "
00086                   << nrRects << " instead of " << toProduce << std::endl;
00087 }
00088 
00089 
00090 
00091 } // namespace Geometry
00092 } // namespace Core
00093 } // namespace Impala
00094 
00095 #endif

Generated on Fri Mar 19 09:31:09 2010 for ImpalaSrc by  doxygen 1.5.1