| 60 | |
| 61 | template <class T> |
| 62 | void TestRandomPixelAccess(const mitk::PixelType /*ptype*/, |
| 63 | mitk::Image::Pointer image, |
| 64 | mitk::Point3D &point, |
| 65 | mitk::ScalarType &value) |
| 66 | { |
| 67 | // generate a random point in world coordinates |
| 68 | mitk::Point3D xMax, yMax, zMax, xMaxIndex, yMaxIndex, zMaxIndex; |
| 69 | xMaxIndex.Fill(0.0f); |
| 70 | yMaxIndex.Fill(0.0f); |
| 71 | zMaxIndex.Fill(0.0f); |
| 72 | xMaxIndex[0] = image->GetLargestPossibleRegion().GetSize()[0]; |
| 73 | yMaxIndex[1] = image->GetLargestPossibleRegion().GetSize()[1]; |
| 74 | zMaxIndex[2] = image->GetLargestPossibleRegion().GetSize()[2]; |
| 75 | image->GetGeometry()->IndexToWorld(xMaxIndex, xMax); |
| 76 | image->GetGeometry()->IndexToWorld(yMaxIndex, yMax); |
| 77 | image->GetGeometry()->IndexToWorld(zMaxIndex, zMax); |
| 78 | MITK_INFO << "Origin " << image->GetGeometry()->GetOrigin()[0] << " " << image->GetGeometry()->GetOrigin()[1] << " " |
| 79 | << image->GetGeometry()->GetOrigin()[2] << ""; |
| 80 | MITK_INFO << "MaxExtend " << xMax[0] << " " << yMax[1] << " " << zMax[2] << ""; |
| 81 | |
| 82 | itk::Statistics::MersenneTwisterRandomVariateGenerator::Pointer randomGenerator = |
| 83 | itk::Statistics::MersenneTwisterRandomVariateGenerator::New(); |
| 84 | randomGenerator->Initialize(std::rand()); // initialize with random value, to get sensible random points for the image |
| 85 | point[0] = randomGenerator->GetUniformVariate(image->GetGeometry()->GetOrigin()[0], xMax[0]); |
| 86 | point[1] = randomGenerator->GetUniformVariate(image->GetGeometry()->GetOrigin()[1], yMax[1]); |
| 87 | point[2] = randomGenerator->GetUniformVariate(image->GetGeometry()->GetOrigin()[2], zMax[2]); |
| 88 | MITK_INFO << "RandomPoint " << point[0] << " " << point[1] << " " << point[2] << ""; |
| 89 | |
| 90 | // test values and max/min |
| 91 | mitk::ScalarType imageMin = image->GetStatistics()->GetScalarValueMin(); |
| 92 | mitk::ScalarType imageMax = image->GetStatistics()->GetScalarValueMax(); |
| 93 | |
| 94 | // test accessing PixelValue with coordinate leading to a negative index |
| 95 | const mitk::Point3D geom_origin = image->GetGeometry()->GetOrigin(); |
| 96 | const mitk::Point3D geom_center = image->GetGeometry()->GetCenter(); |
| 97 | |
| 98 | // shift position from origin outside of the image ( in the opposite direction to [center-origin] vector which points |
| 99 | // in the inside) |
| 100 | mitk::Point3D position = geom_origin + (geom_origin - geom_center); |
| 101 | |
| 102 | MITK_INFO << "Testing access outside of the image"; |
| 103 | unsigned int dim = image->GetDimension(); |
| 104 | if (dim == 3 || dim == 4) |
| 105 | { |
| 106 | mitk::ImagePixelReadAccessor<T, 3> imAccess3(image, image->GetVolumeData(0)); |
| 107 | |
| 108 | // Comparison ?>=0 not needed since all position[i] and timestep are unsigned int |
| 109 | // (position[0]>=0 && position[1] >=0 && position[2]>=0 && timestep>=0) |
| 110 | // bug-11978 : we still need to catch index with negative values |
| 111 | if (point[0] < 0 || point[1] < 0 || point[2] < 0) |
| 112 | { |
| 113 | MITK_WARN << "Given position (" << point << ") is out of image range, returning 0."; |
| 114 | } |
| 115 | else |
| 116 | { |
| 117 | value = static_cast<mitk::ScalarType>(imAccess3.GetPixelByWorldCoordinates(point)); |
| 118 | MITK_TEST_CONDITION((value >= imageMin && value <= imageMax), "Value returned is between max/min"); |
| 119 | } |
nothing calls this directly
no test coverage detected