From 37980f66557e6c02f3bf8f5dcaeb122a50477fe0 Mon Sep 17 00:00:00 2001 From: Manuel Grizonnet <manuel.grizonnet@orfeo-toolbox.org> Date: Fri, 6 Feb 2015 10:38:06 +0100 Subject: [PATCH] COV: refactor and simplify loop to avoid corner cases --- ...ctorDataToLabelMapWithAttributesFilter.txx | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Code/OBIA/otbVectorDataToLabelMapWithAttributesFilter.txx b/Code/OBIA/otbVectorDataToLabelMapWithAttributesFilter.txx index 1b79e75a56..138ef6608f 100644 --- a/Code/OBIA/otbVectorDataToLabelMapWithAttributesFilter.txx +++ b/Code/OBIA/otbVectorDataToLabelMapWithAttributesFilter.txx @@ -336,7 +336,7 @@ VectorDataToLabelMapWithAttributesFilter<TVectorData, TLabelMap> typedef typename IndexType::IndexValueType IndexValueType; RSRegionType polygonExtRingBoundReg = correctPolygonExtRing->GetBoundingRegion(); - IndexType startIdx,endIdx,tmpIdx; + OriginType physCorners[4]; physCorners[0][0] = polygonExtRingBoundReg.GetOrigin(0); physCorners[0][1] = polygonExtRingBoundReg.GetOrigin(1); @@ -349,21 +349,19 @@ VectorDataToLabelMapWithAttributesFilter<TVectorData, TLabelMap> physCorners[2][0] += polygonExtRingBoundReg.GetSize(0); physCorners[3][0] += polygonExtRingBoundReg.GetSize(0); + IndexType startIdx,endIdx,tmpIdx; + + startIdx.Fill(itk::NumericTraits<IndexValueType>::max()); + endIdx.Fill(itk::NumericTraits<IndexValueType>::NonpositiveMin()); + for (unsigned int k=0; k<4; ++k) { this->GetOutput()->TransformPhysicalPointToIndex(physCorners[k],tmpIdx); - if (k == 0) - { - startIdx = tmpIdx; - endIdx = tmpIdx; - } - else - { - startIdx[0] = std::min(startIdx[0],tmpIdx[0]); - startIdx[1] = std::min(startIdx[1],tmpIdx[1]); - endIdx[0] = std::max(endIdx[0],tmpIdx[0]); - endIdx[1] = std::max(endIdx[1],tmpIdx[1]); - } + + startIdx[0] = std::min(startIdx[0],tmpIdx[0]); + startIdx[1] = std::min(startIdx[1],tmpIdx[1]); + endIdx[0] = std::max(endIdx[0],tmpIdx[0]); + endIdx[1] = std::max(endIdx[1],tmpIdx[1]); } // Check that the polygon intersects the largest possible region RegionType polyRegion; -- GitLab