Commit c3a51635 authored by Samuel Debionne's avatar Samuel Debionne

Fix computation of max_roi_size when mixing hw and sw binning

parent a0efb479
Pipeline #32442 passed with stages
in 44 minutes and 29 seconds
......@@ -364,7 +364,8 @@ class LIMACORE_API Bin
Bin& operator /=(const Point& p)
{ m_xy = checkValid(m_xy / p); return *this; }
void swap()
void swapDimensions()
{ m_xy.swap(); }
private:
static bool isValidCoord(int i);
......
......@@ -178,7 +178,8 @@ using namespace lima;
Bin& operator *=(const Point& p);
Bin& operator /=(const Point& p);
void swap();
void swapDimensions();
SIP_PYOBJECT __repr__() const;
%MethodCode
......
......@@ -28,9 +28,10 @@ using namespace lima;
static const Bin Bin_1x1(1, 1);
Size SwapDimIfRotated(RotationMode rotation, const Size& size)
template <typename T>
T SwapDimIfRotated(RotationMode rotation, const T& size)
{
Size res = size;
T res = size;
if(rotation == Rotation_90 || rotation == Rotation_270)
res.swapDimensions();
return res;
......@@ -77,7 +78,7 @@ void CtSwBinRoiFlip::setMaxSize(Size& size)
m_max_size= size;
// Comppute the full ROI according to the current rotation and binning
Roi max_roi(Point(0,0), SwapDimIfRotated(m_rotation, m_max_size) / m_bin);
Roi max_roi(Point(0,0), Size(SwapDimIfRotated(m_rotation, m_max_size) / m_bin));
DEB_PARAM() << DEB_VAR1(max_roi);
if (!m_roi.isEmpty()) {
......@@ -110,7 +111,7 @@ void CtSwBinRoiFlip::setRoi(const Roi& roi)
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(roi);
Roi max_roi(Point(0,0), SwapDimIfRotated(m_rotation, m_max_size) / m_bin);
Roi max_roi(Point(0,0), Size(SwapDimIfRotated(m_rotation, m_max_size) / m_bin));
DEB_TRACE() << DEB_VAR1(max_roi);
if (roi.isEmpty())
......@@ -872,9 +873,15 @@ void CtImage::setFlip(Flip &flip)
RotationMode currentRotation;
getRotation(currentRotation);
const Size& max_roi_size = m_hw->getMaxRoiSize();
Size hw_max_roi_size = m_hw->getMaxRoiSize();
Size max_roi_size = SwapDimIfRotated(currentRotation, Size(hw_max_roi_size / m_sw->getBin()));
DEB_TRACE() << DEB_VAR3(currentRoi, max_roi_size, hw_max_roi_size);
currentRoi = currentRoi.getUnrotated(currentRotation,max_roi_size);
DEB_TRACE() << "Unrotated " << DEB_VAR1(currentRoi);
currentRoi = currentRoi.getFlipped(currentFlip,max_roi_size);
DEB_TRACE() << "Unflipped " << DEB_VAR1(currentRoi);
if(!flip.x && ! flip.y)
_resetFlip();
......@@ -912,8 +919,12 @@ void CtImage::setRotation(RotationMode rotation)
Bin currentBin;
getBin(currentBin);
const Size& max_roi_size = m_hw->getMaxRoiSize();
Size hw_max_roi_size = m_hw->getMaxRoiSize();
Size max_roi_size = SwapDimIfRotated(currentRotation, Size(hw_max_roi_size / m_sw->getBin()));
DEB_TRACE() << DEB_VAR3(currentRoi, max_roi_size, hw_max_roi_size);
currentRoi = currentRoi.getUnrotated(currentRotation,max_roi_size);
DEB_TRACE() << "Unrotated " << DEB_VAR1(currentRoi);
m_sw->setRotation(rotation);
......
......@@ -27,12 +27,12 @@ rots = [Core.Rotation_0, Core.Rotation_90, Core.Rotation_180, Core.Rotation_270]
binnings = [Core.Bin(1,1), Core.Bin(1,2), Core.Bin(2,1), Core.Bin(2,2)]
flips = [Core.Flip(False, False), Core.Flip(False, True), Core.Flip(True, False), Core.Flip(True, True)]
# Python function to print permutations of a given list
# Python function to print permutations of a given list (from SO)
def permutation(lst):
if len(lst) == 0:
return []
if len(lst) == 1:
if len(lst) == 1:
return [lst]
l = []
......@@ -47,20 +47,28 @@ def permutation(lst):
permutations = permutation(['b', 'f', 'r'])
# For every permuation of every Bin Rot Flip parameters
# For every permutation of every Bin Rot Flip parameters applied in any order
for rot in rots:
for bin in binnings:
for flip in flips:
for perm in permutations:
try:
for op in perm:
if op[0] == 'f':
if op == 'f':
img.setFlip(flip)
elif op == 'b':
img.setBin(bin)
elif op == 'r':
img.setRotation(rot)
#print(perm, flip, rot, bin, img.getRoi(), " - OK")
except Exception:
print(perm, flip, rot, bin, img.getRoi(), " - FAILED")
img.resetBin()
img.resetFlip()
img.resetRotation()
assert img.getRoi() == roi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment