Skip to content

Commit

Permalink
MFR_GetBrickletData: Fix resampling/pixelation errors
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
t-b committed Jun 17, 2021
1 parent 4ee2d5f commit 4082988
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
38 changes: 18 additions & 20 deletions VC8/brickletconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -180,6 +187,7 @@ int HandleResamplingIfRequested(DataFolderHandle waveFolderHandle, Wave &wave, i
}

wave.setWaveHandle(FetchWaveFromDataFolder(waveFolderHandle, wave.getWaveName()));
wave.SetPixelSize(static_cast<int>(pixelSize));

return 0;
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
20 changes: 20 additions & 0 deletions regression_tests/Test_GetBrickletData.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4082988

Please sign in to comment.