Skip to content

Commit 3982364

Browse files
Fixed crash caused by sampling outside image domain during image map
1 parent 569643e commit 3982364

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

FEBioStudio/ImageMapTool.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,19 @@ void CImageMapTool::OnCreate()
427427
int voxelIndexY = locPos.y/spacing.y;
428428
int voxelIndexZ = locPos.z/spacing.z;
429429

430+
// Ensure we're in the bounds of the image before we sample
431+
if(voxelIndexX < 0) voxelIndexX = 0;
432+
else if(voxelIndexX >= imageModel->Get3DImage()->Width())
433+
voxelIndexX = imageModel->Get3DImage()->Width() - 1;
434+
435+
if(voxelIndexY < 0) voxelIndexY = 0;
436+
else if(voxelIndexY >= imageModel->Get3DImage()->Height())
437+
voxelIndexY = imageModel->Get3DImage()->Height() - 1;
438+
439+
if(voxelIndexZ < 0) voxelIndexZ = 0;
440+
else if(voxelIndexZ >= imageModel->Get3DImage()->Depth())
441+
voxelIndexZ = imageModel->Get3DImage()->Depth() - 1;
442+
430443
double discreteVal = imageModel->Get3DImage()->Value(voxelIndexX, voxelIndexY, voxelIndexZ);
431444
if(discreteVal >= threshold)
432445
{

0 commit comments

Comments
 (0)