let height = Int(arView.frame.height)
let width = Int(arView.frame.width)
UIGraphicsBeginImageContextWithOptions(CGSize(width: width, height: height), true, 0)
while y < height {
var x = 0
while x < width {
let location = CGPoint(x: x, y: y)
let results = arView.hitTest(location, types: [.featurePoint, .existingPlane, .estimatedVerticalPlane, .estimatedHorizontalPlane, .existingPlaneUsingGeometry, .existingPlaneUsingExtent])
let alpha = results.isEmpty ? 1.0 : (1.0 / CGFloat(results.count))
for result in results {
let value = 1.0 / (result.distance + 1.0)
switch result.type {
case .featurePoint:
UIColor(red: value, green: 0, blue: 0, alpha: alpha).setFill()
case .existingPlane:
UIColor(red: 0, green: 1, blue: 0, alpha: alpha).setFill()
case .estimatedVerticalPlane:
UIColor(red: 0, green: 0, blue: value, alpha: alpha).setFill()
case .estimatedHorizontalPlane:
UIColor(red: 0, green: 0, blue: value, alpha: alpha).setFill()
case .existingPlaneUsingGeometry:
UIColor(red: value, green: value, blue: value, alpha: alpha).setFill()
case .existingPlaneUsingExtent:
UIColor(red: value, green: value, blue: value, alpha: alpha).setFill()
default:
UIColor.black.setFill()
}
UIRectFill(CGRect(x: x, y: y, width: 1, height: 1))
}
x += 1
}
y += 1
}
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
imgView.image = image