-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warper: Add TIE_STRATEGY warp option #11649
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -989,7 +989,8 @@ GDALWarpKernel::GDALWarpKernel() | |
nDstXOff(0), nDstYOff(0), pfnTransformer(nullptr), | ||
pTransformerArg(nullptr), pfnProgress(GDALDummyProgress), | ||
pProgress(nullptr), dfProgressBase(0.0), dfProgressScale(1.0), | ||
padfDstNoDataReal(nullptr), psThreadData(nullptr) | ||
padfDstNoDataReal(nullptr), psThreadData(nullptr), | ||
eTieStrategy(GWKTS_First) | ||
{ | ||
} | ||
|
||
|
@@ -6870,6 +6871,9 @@ static void GWKAverageOrModeThread(void *pData) | |
// Only used with nAlgo = 6. | ||
float quant = 0.5; | ||
|
||
// Only used for GRA_Mode | ||
const GWKTieStrategy eTieStrategy = poWK->eTieStrategy; | ||
|
||
// To control array allocation only when data type is complex | ||
const bool bIsComplex = GDALDataTypeIsComplex(poWK->eWorkingDataType) != 0; | ||
|
||
|
@@ -7599,13 +7603,44 @@ static void GWKAverageOrModeThread(void *pData) | |
|
||
// Check array for existing entry. | ||
for (i = 0; i < iMaxInd; ++i) | ||
if (pafRealVals[i] == fVal && | ||
++panRealSums[i] > | ||
panRealSums[iMaxVal]) | ||
{ | ||
if (pafRealVals[i] == fVal) | ||
{ | ||
iMaxVal = i; | ||
bool bValIsMax = | ||
(++panRealSums[i] > | ||
panRealSums[iMaxVal]); | ||
|
||
if (!bValIsMax && | ||
panRealSums[i] == | ||
panRealSums[iMaxVal]) | ||
{ | ||
switch (eTieStrategy) | ||
{ | ||
case GWKTS_First: | ||
break; | ||
case GWKTS_Min: | ||
bValIsMax = | ||
fVal < | ||
pafRealVals | ||
[iMaxVal]; | ||
break; | ||
case GWKTS_Max: | ||
bValIsMax = | ||
fVal > | ||
pafRealVals | ||
[iMaxVal]; | ||
break; | ||
} | ||
} | ||
|
||
if (bValIsMax) | ||
{ | ||
iMaxVal = i; | ||
} | ||
|
||
break; | ||
} | ||
} | ||
|
||
// Add to arr if entry not already there. | ||
if (i == iMaxInd) | ||
|
@@ -7676,7 +7711,25 @@ static void GWKAverageOrModeThread(void *pData) | |
{ | ||
const int nVal = | ||
static_cast<int>(dfValueRealTmp); | ||
if (++panVals[nVal + nBinsOffset] > nMaxVal) | ||
|
||
bool bValIsMax = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this isn't due to your changes, but the current variable naming is terrible and makes it hard to follow the algorithm. Would you mind renaming:
I believe panRealSums could be removed, and just replaced by panCount shared between int and float implementations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the variable names caused me some confusion when working on this. I'll try to improve them in a separate commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I was surprised to see that "mode" resampling isn't accounting for pixel coverage fractions in the way that "sum" and "average" are. I'm planning to address this as I rename the variables. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes, that would definitely make sense for "mode" as well |
||
++panVals[nVal + nBinsOffset] > nMaxVal; | ||
if (!bValIsMax && | ||
panVals[nVal + nBinsOffset] == nMaxVal) | ||
{ | ||
switch (eTieStrategy) | ||
{ | ||
case GWKTS_First: | ||
break; | ||
case GWKTS_Min: | ||
bValIsMax = nVal < iMaxInd; | ||
break; | ||
case GWKTS_Max: | ||
bValIsMax = nVal > iMaxInd; | ||
break; | ||
} | ||
} | ||
if (bValIsMax) | ||
{ | ||
// Sum the density. | ||
// Is it the most common value so far? | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rouault probably not worth backporting, but this is doing extra work by not hitting
break
onpafRealVals[i] == fVal
regardless of whether++panRealSums[i] > panRealSums[iMaxVal]