10 #include <gsl/gsl_math.h>
15 #ifndef __ALE_TOUCHSENSOR_H__
16 #define __ALE_TOUCHSENSOR_H__
18 #define MAX_TAXELS 192
36 void setColor(
unsigned char r,
unsigned char g,
unsigned char b)
48 void resize(
int width,
int height,
int margin)
50 if (3*margin>=width || 3*margin>=height) margin=0;
52 double scaleX=double(width -2*margin)/(
dXmax-
dXmin);
53 double scaleY=double(height-2*margin)/(
dYmax-
dYmin);
54 double scale=scaleX<scaleY?scaleX:scaleY;
68 x[i]=w2+int(scale*(
dX[i]-dXmid));
69 y[i]=h2+int(scale*(
dY[i]-dYmid));
72 for (
int i=0; i<
nVerts; ++i)
74 xv[i]=w2+int(scale*(
dXv[i]-dXmid));
75 yv[i]=h2+int(scale*(
dYv[i]-dYmid));
78 double sigma=0.5*5.55*scale;
79 int maxRange=int(2.5*sigma);
88 double k=-0.5/(sigma*sigma);
89 for (
int x=0;
x<maxRange; ++
x)
95 xMin=w2+int(scale*(
dXc-dXmid-15.0))-maxRange;
96 xMax=w2+int(scale*(
dXc-dXmid+15.0))+maxRange;
97 yMin=h2+int(scale*(
dYc-dYmid-15.0))-maxRange;
98 yMax=h2+int(scale*(
dYc-dYmid+15.0))+maxRange;
145 printf(
"WARN: unkwnown layout number.\n");
162 for (dy=dya; dy<=dyb; ++dy)
166 for (dx=dxa; dx<=dxb; ++dx)
168 if (dx*dx+dy*dy<=maxRange2)
170 image[(dx+Y1)*3]=act<255?act:255;
177 void eval(
unsigned char *image)
196 printf(
"WARN: unkwnown layout number.\n");
211 for (dy=dya; dy<=dyb; ++dy)
216 for (dx=dxa; dx<=dxb; ++dx)
220 if (image[index]<
R_MAX || image[index+1]<
G_MAX || image[index+2]<
B_MAX)
224 int actR=image[index ]+(act*
R_MAX)/255;
225 int actG=image[index+1]+(act*
G_MAX)/255;
226 int actB=image[index+2]+(act*
B_MAX)/255;
239 for (
int i=0; i<7; ++i)
246 for (
int i=1; i<=5; ++i)
275 virtual void draw(
unsigned char *image)
277 for (
int i=0; i<
nVerts; ++i)
291 static const unsigned char R1=0x80,G1=0x50,B1=0x00;
292 static const unsigned char R2=3*R1/4,G2=3*G1/4,B2=3*B1/4;
293 static const unsigned char R4=3*R2/4,G4=3*G2/4,B4=3*B2/4;
299 if (image[bytePos-3]<R4) image[bytePos-3]=R4;
300 if (image[bytePos-2]<G4) image[bytePos-2]=G4;
303 if (image[bytePos ]<R2) image[bytePos ]=R2;
304 if (image[bytePos+1]<G2) image[bytePos+1]=G2;
307 if (image[bytePos+3]<R4) image[bytePos+3]=R4;
308 if (image[bytePos+4]<G4) image[bytePos+4]=G4;
313 if (image[bytePos-3]<R2) image[bytePos-3]=R2;
314 if (image[bytePos-2]<G2) image[bytePos-2]=G2;
317 if (image[bytePos ]<R1) image[bytePos ]=R1;
318 if (image[bytePos+1]<G1) image[bytePos+1]=G1;
321 if (image[bytePos+3]<R2) image[bytePos+3]=R2;
322 if (image[bytePos+4]<G2) image[bytePos+4]=G2;
327 if (image[bytePos-3]<R4) image[bytePos-3]=R4;
328 if (image[bytePos-2]<G4) image[bytePos-2]=G4;
331 if (image[bytePos ]<R2) image[bytePos ]=R2;
332 if (image[bytePos+1]<G2) image[bytePos+1]=G2;
335 if (image[bytePos+3]<R4) image[bytePos+3]=R4;
336 if (image[bytePos+4]<G4) image[bytePos+4]=G4;
340 void drawLine(
unsigned char *image,
int x0,
int y0,
int x1,
int y1)
342 if (
x1==x0 && y1==y0)
return;
343 double Vx=double(
x1-x0);
344 double Vy=double(y1-y0);
345 double dt=1.0/sqrt(Vx*Vx+Vy*Vy);
347 for (
double t=0.0; t<=1.0; t+=dt)
349 dither(x0+
int(t*Vx),y0+
int(t*Vy),image);
353 void drawCircle(
unsigned char *image,
int cx,
int cy,
double radius)
355 double dt=1.0/(2*
M_PI*radius);
361 for (
double t=0.0; t<=M_PI_4; t+=dt)
369 dither(cx+dx,cy+dy,image);
370 dither(cx+dx,cy-dy,image);
371 dither(cx-dx,cy-dy,image);
372 dither(cx-dx,cy+dy,image);
374 dither(cx+dy,cy+dx,image);
375 dither(cx+dy,cy-dx,image);
376 dither(cx-dy,cy-dx,image);
377 dither(cx-dy,cy+dx,image);
bool connected[MAX_TAXELS]
double activation[MAX_TAXELS]
double remapped_activation[MAX_TAXELS]
void setActivationFromPortData(double val, int id)
void eval(unsigned char *image)
void resize(int width, int height, int margin)
void setCalibrationFlag(bool use_calibrated_skin)
static double * Exponential
void setActivationFirst7(unsigned char *data)
void drawLine(unsigned char *image, int x0, int y0, int x1, int y1)
void setActivationLast5(unsigned char *data)
virtual void draw(unsigned char *image)
void dither(int x, int y, unsigned char *image)
void drawCircle(unsigned char *image, int cx, int cy, double radius)
void setColor(unsigned char r, unsigned char g, unsigned char b)
void eval_light(unsigned char *image)