From 4082988a510aae5395e9a23ecae854ee320897e1 Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Thu, 17 Jun 2021 12:49:07 +0200 Subject: [PATCH] MFR_GetBrickletData: Fix resampling/pixelation errors When loading bricklets which have too few points for the resampling or pixelation, we currently bug out or skip the bricklet depending wether it is 1D or 2D. While this can be manually worked around, this currently breaks the MFR GUI as there is no fallback for failed resampling/pixelation. We now check that we have enough points before trying the pixelation. And we also only set the resampled dimension scales when resampling worked, and also use the original wave when resampling failed. Reported-By: Nils Krane --- VC8/brickletconverter.cpp | 38 +++++++++++------------ regression_tests/Test_GetBrickletData.ipf | 20 ++++++++++++ 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/VC8/brickletconverter.cpp b/VC8/brickletconverter.cpp index 403c17d..e093b65 100644 --- a/VC8/brickletconverter.cpp +++ b/VC8/brickletconverter.cpp @@ -111,16 +111,13 @@ int createEmptyWaves(WaveVec &waves, DataFolderHandle waveFolderHandle, CountInt return 0; } -int HandleResamplingIfRequested(DataFolderHandle waveFolderHandle, Wave &wave, int dimension, bool resampleData, - int pixelSize) +int HandleResamplingIfRequested(DataFolderHandle waveFolderHandle, Wave &wave, CountInt dimensionSizes[MAX_DIMENSIONS + 1], int dimension, bool resampleData, CountInt pixelSize) { if(!resampleData) { return 0; } - wave.SetPixelSize(pixelSize); - DEBUGPRINT("Resampling wave %s with pixelSize=%d", wave.getWaveName(), pixelSize); char dataFolderPath[MAXCMDLEN + 1]; @@ -135,6 +132,11 @@ int HandleResamplingIfRequested(DataFolderHandle waveFolderHandle, Wave &wave, i char cmd[MAXCMDLEN + ARRAY_SIZE]; if(dimension == 1) { + if((pixelSize * 15) >= dimensionSizes[ROWS]) + { + return LA_TOO_FEW_PNTS; + } + // Command: "Resample/DOWN= [...] wave" sprintf(cmd, "Resample/DOWN={%d} %s", pixelSize, dataFolderPath); CatPossiblyQuotedName(cmd, wave.getWaveName()); @@ -149,6 +151,11 @@ int HandleResamplingIfRequested(DataFolderHandle waveFolderHandle, Wave &wave, i } else if(dimension == 2) { + if ((pixelSize >= dimensionSizes[ROWS]) || (pixelSize >= dimensionSizes[COLUMNS])) + { + return LA_TOO_FEW_PNTS; + } + // Command: "ImageInterpolate [...] Pixelate" sprintf(cmd, "ImageInterpolate/PXSZ={%d,%d}/DEST=%sM_PixelatedImage Pixelate %s", pixelSize, pixelSize, dataFolderPath, dataFolderPath); @@ -180,6 +187,7 @@ int HandleResamplingIfRequested(DataFolderHandle waveFolderHandle, Wave &wave, i } wave.setWaveHandle(FetchWaveFromDataFolder(waveFolderHandle, wave.getWaveName())); + wave.SetPixelSize(static_cast(pixelSize)); return 0; } @@ -282,17 +290,12 @@ int createWaves1D(DataFolderHandle baseFolderHandle, DataFolderHandle waveFolder continue; } - ret = HandleResamplingIfRequested(waveFolderHandle, *it, 1, resampleData, pixelSize); - - if(ret != 0) - { - return ret; - } + ret = HandleResamplingIfRequested(waveFolderHandle, *it, dimensionSizes, 1, resampleData, pixelSize); double xAxisDelta; - // also the wave scaling changes if we have resampled the data - if(resampleData) + // also the wave scaling changes if we have resampled the data successfully + if(resampleData && ret == 0) { CountInt interpolatedDimSizes[MAX_DIMENSIONS + 1]; MemClear(interpolatedDimSizes, sizeof(interpolatedDimSizes)); @@ -582,17 +585,12 @@ int createWaves2D(DataFolderHandle baseFolderHandle, DataFolderHandle waveFolder continue; } - ret = HandleResamplingIfRequested(waveFolderHandle, *it, 2, resampleData, pixelSize); - - if(ret != 0) - { - continue; - } + ret = HandleResamplingIfRequested(waveFolderHandle, *it, dimensionSizes, 2, resampleData, pixelSize); double xAxisDelta, yAxisDelta; - // also the wave scaling changes if we have resampled the data - if(resampleData) + // also the wave scaling changes if we have resampled the data successfully + if(resampleData && ret == 0) { CountInt interpolatedDimSizes[MAX_DIMENSIONS + 1]; MemClear(interpolatedDimSizes, sizeof(interpolatedDimSizes)); diff --git a/regression_tests/Test_GetBrickletData.ipf b/regression_tests/Test_GetBrickletData.ipf index cfa26f4..8d95ec2 100644 --- a/regression_tests/Test_GetBrickletData.ipf +++ b/regression_tests/Test_GetBrickletData.ipf @@ -233,6 +233,26 @@ static Function valid_pixelsizes() endfor End +static Function pixelsize_too_large_and_ignored() + Struct errorCode err + initStruct(err) + + MFR_OpenResultFile/K folder + file + CHECK_EQUAL_VAR(err.SUCCESS, V_flag) + + variable/G V_MatrixFileReaderOverwrite = 1 + + MFR_GetBrickletData/S=(10)/R=(39) + CHECK_EQUAL_VAR(err.SUCCESS, V_flag) + CHECK(ItemsInList(S_waveNames) == 4) // we have four trace directions + variable j + for(j = 0; j < ItemsInList(S_waveNames); j+=1) + WAVE wv = $StringFromList(j, S_waveNames) + CHECK_WAVE(wv, NUMERIC_WAVE, minorType = DOUBLE_WAVE) + CHECK_EQUAL_VAR(NumberByKey("pixelSize", note(wv), "=", "\r"), 1) + endfor +End + static Function valid_ps_with_liberal_names() Struct errorCode err initStruct(err)