Reputation: 9453
I am having a problem figuring out how to create a heatmap overlay having:
- set of points and their correspondig repetition counter
- maximum repetition counter for a single point
- minimum repetition counter for a single point
If you have any code examples I would appreciate.
Edit
I need to end up with an UIImage that shows a map in lets say rainbow colors (red - hottest -> blue coldest)
The idea that I have is to:
-create grayscale image
-draw small gray scale gradients at each point with some alpha (overlaying the same point will increase its visual density)
-create a copy of grayscale image and call it heatmapImage
-for every pixel in the heatmapImage check the pixel grayscale and replacy it with appropriate pixel color from a heat gradient array.
But don't know how to put it into a code.
Upvotes: 2
Views: 1864
Reputation: 6856
To go along with @Goz's answer, you could create an array of objects called HTPoint
that assist in creating the grid.
@interface HTPoint NSObject {
int _density;
}
enum Range {
MaxAccumulator = 100,
MinAccumulator = -100
}
@property (int) x
@property (int) y
@property (int) density
-(id)initWithPoint:(CGPoint)pt andDensity:(int)d;
@end
Use it like you would a CGPoint for the Image. Override the density setter/getter.
@implementation HTPoint
- (int) density { return _density; }
- (void) setDensity: (int) density
{
if (density < MaxAccumulator && density > MinAccumulator)
_density = density;
}
// Do the same for decr
- (void) incr
{
if (_density > MaxAccumulator && _density < MinAccumulator) return; // or throw an exception
_density ++;
}
@end
That should help you keep track of the grid itself. Use @Goz' answer for displaying it, but instead of adding '1', just add the density of the HTPoint.
Upvotes: 1
Reputation: 62333
Well its relatively easy.
Divide up the area into a fixed grid (For example 64x64).
Now scan through every point and check which grid box it falls. Then add 1 to that grid box's counter. You now have a density map. Convert and render however you please.
Upvotes: 1