Heat map optimisation
in
Programming Questions
•
1 year ago
Hi guys,
I wrote the below heat mapping function. It works reasonably well but sometimes gives me an out of memory error. I wonder is anyone has any suggestions for optimisation. I'm also controlling the fall off of the points a bit brutally with a multiplier (called fallOff). I wonder if this should also be some kind of logarithmic function? Cheers folks, hopefully this thread will expand a bit and we can get good solid simple solution!
cheers
Tom
PImage makeHeatMap(PVector [] dataPoints, float fallOff) {
PImage timg=createImage(width, height, RGB);
timg.loadPixels();
loadPixels();
dataPoints[0].x=mouseX;
dataPoints[0].y=mouseY;
//maxpossible distance between any 2 pixels is the diagonal distance across the screen
float maxDist = sqrt((width*width)+(height*height));
float heats[] =new float[pixels.length];
int x=0;
int y=0;
for (int i=0;i<pixels.length;i++) {
//get average distance to all points
float averageDistance=0.0f;
for (int j=0;j< dataPoints.length;j++) {
float thisDist=dist(x, y, dataPoints[j].x, dataPoints[j].y) ;
//multiply the distance by the scaler
averageDistance+=thisDist*dataPoints[j].z;
//float _hue =(1.0f/7.0f)* map(sqrt(thisDist), 0, sqrt(maxDist), 0, 255);
}
averageDistance/=dataPoints.length;
float _hue = map (sqrt(averageDistance), 0, sqrt(maxDist)*fallOff, 0, 255);
timg.pixels[i]= color(_hue, 255, 255);
x++;
if (x>=width) {
x=0;
y++;
}
}
timg.updatePixels();
return timg;
}
1