Skip to content

Commit

Permalink
Merge pull request #2 from byte-physics/bugfix/fix-pixelsize-vs-datasize
Browse files Browse the repository at this point in the history
Bugfix/fix pixelsize vs datasize
  • Loading branch information
t-b authored Jun 17, 2021
2 parents 4e82e25 + f9b580c commit c4c2434
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 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
4 changes: 2 additions & 2 deletions VC8/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
version string of the XOP
returned by the GetMtrxFileReaderVersion operation and also used for the resource file
*/
#define MatrixFileReader_XOP_VERSION 0, 2, 6, 0
#define MatrixFileReader_XOP_VERSION 0, 2, 7, 0

// must be convertible to a double
#define MatrixFileReader_XOP_VERSION_STR "0.260\0"
#define MatrixFileReader_XOP_VERSION_STR "0.270\0"
4 changes: 2 additions & 2 deletions create-public-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

lastVersion=0.25.2
newVersion=0.26
lastVersion=0.26
newVersion=0.27

filesToWatch="VC8 *.txt regression_tests *.pxp *.ihf"

Expand Down
Binary file modified matrixfilereader Help.ihf
Binary file not shown.
Binary file added public-releases/matrixFileReaderXOP-v0.27.zip
Binary file not shown.
24 changes: 23 additions & 1 deletion regression_tests/Test_GetBrickletData.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,33 @@ static Function valid_pixelsizes()
CHECK(ItemsInList(S_waveNames) == 4) // we have four trace directions
variable j
for(j = 0; j < ItemsInList(S_waveNames); j+=1)
CHECK_WAVE($StringFromList(j, S_waveNames), NUMERIC_WAVE, minorType = DOUBLE_WAVE)
WAVE wv = $StringFromList(j, S_waveNames)
CHECK_WAVE(wv, NUMERIC_WAVE, minorType = DOUBLE_WAVE)
CHECK_EQUAL_VAR(NumberByKey("pixelSize", note(wv), "=", "\r"), i)
endfor
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 c4c2434

Please sign in to comment.