00001
00024 #ifndef _BASICALGORITHMS_CALCULATEOPTIMALROI_H
00025 #define _BASICALGORITHMS_CALCULATEOPTIMALROI_H
00026
00027 #include <hugin_shared.h>
00028 #include <panotools/PanoToolsInterface.h>
00029 #include <algorithms/PanoramaAlgorithm.h>
00030 #include <panodata/PanoramaData.h>
00031
00032 #include <boost/dynamic_bitset.hpp>
00033
00034 namespace HuginBase {
00035
00036 class IMPEX CalculateOptimalROI : public PanoramaAlgorithm
00037 {
00038 public:
00040 CalculateOptimalROI(PanoramaData& panorama, bool intersect = false)
00041 : PanoramaAlgorithm(panorama), intersection(intersect)
00042 {
00043
00044 o_optimalROI = vigra::Rect2D(0,0,0,0);
00045 o_optimalSize = vigra::Size2D(0,0);
00046 }
00047
00048 CalculateOptimalROI(PanoramaData& panorama, std::vector<UIntSet> hdr_stacks)
00049 : PanoramaAlgorithm(panorama), intersection(true), stacks(hdr_stacks)
00050 {
00051
00052 o_optimalROI = vigra::Rect2D(0,0,0,0);
00053 o_optimalSize = vigra::Size2D(0,0);
00054 }
00055
00057 virtual ~CalculateOptimalROI()
00058 {}
00059
00060 public:
00062 virtual bool modifiesPanoramaData() const
00063 { return false; }
00064
00066 virtual bool runAlgorithm()
00067 {
00068 printf("Run called\n");
00069 calcOptimalROI(o_panorama);
00070 return true;
00071 }
00072
00073 public:
00075 bool calcOptimalROI(PanoramaData& panorama);
00076
00078 virtual vigra::Rect2D getResultOptimalROI()
00079 {
00080
00081
00082
00083 return o_optimalROI;
00084 }
00085
00087 virtual vigra::Size2D getResultOptimalSize()
00088 {
00089
00090
00091 return o_optimalSize;
00092 }
00093
00095 void setStacks(std::vector<UIntSet> hdr_stacks);
00096
00097 private:
00098 vigra::Rect2D o_optimalROI;
00099 vigra::Size2D o_optimalSize;
00100
00101 bool intersection;
00102
00103 std::vector<UIntSet> stacks;
00104
00105 UIntSet activeImages;
00106 std::map<unsigned int,PTools::Transform*> transfMap;
00107
00108 boost::dynamic_bitset<> testedPixels;
00109 boost::dynamic_bitset<> pixels;
00110
00111 bool imgPixel(int i, int j);
00112 bool stackPixel(int i, int j, UIntSet &stack);
00113
00114
00115 struct nonrec
00116 {
00117 int left,right,top,bottom;
00118 struct nonrec *next;
00119 };
00120
00121 void makecheck(int left,int top,int right,int bottom);
00122 int autocrop();
00123 void nonreccheck(int left,int top,int right,int bottom,int acc,int searchStrategy);
00124
00125 int count;
00126 struct nonrec *head;
00127 struct nonrec *tail;
00128 struct nonrec best;
00129
00130 long maxvalue;
00131 };
00132
00133 }
00134 #endif