Hi,

here is a patch that implements the feature requested in hugin bug 679981 - 
autocrop based on image stacks.
The algorithm already works, but the integration is not yet finished. I want 
to ask you for opinion on these issues:

- Currently it is not configurable. Should I add it as another crop button
or as an option under preferences?

- getHDRStacks is in PanoramaMakefilelibExport.cpp, which make it hard to use
from Panorama.h. There is already a comment that it should be moved somewhere 
else. What is the best place for it?

Regards,

Vladimir

-- 
You received this message because you are subscribed to the Google Groups 
"Hugin and other free panoramic software" group.
A list of frequently asked questions is available at: 
http://wiki.panotools.org/Hugin_FAQ
To post to this group, send email to hugin-ptx@googlegroups.com
To unsubscribe from this group, send email to 
hugin-ptx+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/hugin-ptx
diff -r 517766989028 -r 39d1b80e91cd src/hugin1/PT/Panorama.h
--- a/src/hugin1/PT/Panorama.h	Wed Nov 23 22:30:37 2011 +0100
+++ b/src/hugin1/PT/Panorama.h	Wed Nov 23 22:31:51 2011 +0100
@@ -37,6 +37,8 @@
 #include <algorithms/basic/CalculateMeanExposure.h>
 #include <algorithms/basic/CalculateOptimalROI.h>
 
+// for getHDRStacks
+#include <algorithms/panorama_makefile/PanoramaMakefilelibExport.h>
 
 #include <typeinfo>
 #include "PT/PanoImage.h"
@@ -101,7 +103,7 @@
     void calcOptimalROI(vigra::Rect2D & roi,vigra::Size2D & size)
     {
         printf("calcOptimalROI Called\n");
-        HuginBase::CalculateOptimalROI cropPano(*this);
+        HuginBase::CalculateOptimalROI cropPano(*this, getHDRStacks(*this, getActiveImages()));
         
         cropPano.run();
         
diff -r 517766989028 -r 39d1b80e91cd src/hugin_base/algorithms/basic/CalculateOptimalROI.cpp
--- a/src/hugin_base/algorithms/basic/CalculateOptimalROI.cpp	Wed Nov 23 22:30:37 2011 +0100
+++ b/src/hugin_base/algorithms/basic/CalculateOptimalROI.cpp	Wed Nov 23 22:31:51 2011 +0100
@@ -92,31 +92,57 @@
 }
 
 //now you can do dynamic programming, look thinks up on fly
+bool CalculateOptimalROI::stackPixel(int i, int j, UIntSet &stack)
+{
+    bool inside = intersection; // start with true for intersection mode and with false for union mode
+    //check that pixel at each place
+    for(UIntSet::const_iterator it=stack.begin();it!=stack.end();it++)
+    {
+        double xd,yd;
+        if(transfMap[*it]->transformImgCoord(xd,yd,(double)i,(double)j))
+        {
+            if(o_panorama.getImage(*it).isInside(vigra::Point2D(xd,yd)))
+            {
+                if (!intersection) {
+                    //if found in a single image, short cut out
+                    inside=true;
+                    break;
+                }
+            }
+            else {
+                if (intersection) {
+                    //outside of at least one image - return false
+                    inside=false;
+                    break;
+                }
+            }
+        }
+    }
+
+    return inside;
+}
+
 bool CalculateOptimalROI::imgPixel(int i, int j)
 {
     if(testedPixels[j*o_optimalSize.x+i]==0)
     {
-        bool inside = intersection; // start with true for intersection mode and with false for union mode
-        //check that pixel at each place
-        for(UIntSet::const_iterator it=activeImages.begin();it!=activeImages.end();it++)
+        bool inside;
+        
+        if (stacks.empty())
         {
-            double xd,yd;
-            if(transfMap[*it]->transformImgCoord(xd,yd,(double)i,(double)j))
+            // no stacks - test all images on union or intersections
+            inside = stackPixel(i, j, activeImages);
+        }
+        else
+        {
+            inside = false;
+            // pixel must be inside of at least one stack
+            for (unsigned s=0; s < stacks.size(); s++)
             {
-                if(o_panorama.getImage(*it).isInside(vigra::Point2D(xd,yd)))
+                if (stackPixel(i, j, stacks[s]))
                 {
-                    if (!intersection) {
-                        //if found in a single image, short cut out
-                        inside=true;
-                        break;
-                    }
-                }
-                else {
-                    if (intersection) {
-                        //outside of at least one image - return false
-                        inside=false;
-                        break;
-                    }
+                    inside = true;
+                    break;
                 }
             }
         }
diff -r 517766989028 -r 39d1b80e91cd src/hugin_base/algorithms/basic/CalculateOptimalROI.h
--- a/src/hugin_base/algorithms/basic/CalculateOptimalROI.h	Wed Nov 23 22:30:37 2011 +0100
+++ b/src/hugin_base/algorithms/basic/CalculateOptimalROI.h	Wed Nov 23 22:31:51 2011 +0100
@@ -44,6 +44,14 @@
             o_optimalROI = vigra::Rect2D(0,0,0,0);
             o_optimalSize = vigra::Size2D(0,0);
         }
+
+        CalculateOptimalROI(PanoramaData& panorama, std::vector<UIntSet> hdr_stacks)
+         : PanoramaAlgorithm(panorama), intersection(true), stacks(hdr_stacks)
+        {
+            //set to zero for error condition
+            o_optimalROI = vigra::Rect2D(0,0,0,0);
+            o_optimalSize = vigra::Size2D(0,0);
+        }
         
         ///
         virtual ~CalculateOptimalROI()
@@ -90,6 +98,8 @@
         
         bool intersection;
         
+        std::vector<UIntSet> stacks;
+        
         UIntSet activeImages;
         std::map<unsigned int,PTools::Transform*> transfMap;
         //map for storing already tested pixels
@@ -97,6 +107,7 @@
         boost::dynamic_bitset<> pixels;
         
         bool imgPixel(int i, int j);
+        bool stackPixel(int i, int j, UIntSet &stack);
         
         //local stuff, convert over later
         struct nonrec

Reply via email to