26 for(r=0; r<rl->
nr; r++) {
34 if(rl->_allocNr>0) free(rl->
roi);
96 while(rois->
roi!=roi) {
102 if(rois->
roi->
x) free(rois->
roi->
x);
103 if(rois->
roi->
y) free(rois->
roi->
y);
125 if(verbose>0) printf(
"roi_read(%s, rl)\n", fname);
126 if(fname==NULL || rl==NULL)
return(1);
137 printf(
"%d: %s\n", 1+i, lines.
tok[i]);
140 if(roilist)
while(roilist->
next) roilist=roilist->
next;
147 newroi=malloc(
sizeof(
ROI));
148 memset(newroi, 0,
sizeof(
ROI));
152 for(; li<lines.
token_nr; li++)
if(lines.
tok[li][0]==
'*')
break;
156 int c=sscanf(lines.
tok[li],
"*%s %f %f %d %d %d %d %d %d %d %d %d ",
159 &newroi->
pos_x, &newroi->
pos_y, &newroi->
w, &newroi->
h, &newroi->
t,
167 char buf[256]=
"", buf2[256];
170 if(strlen(buf)>0) strcat(buf,
" ");
176 free(newroi->
x); free(newroi->
y); free(newroi);
179 char *cptr=strstr(buf,
"///");
if(cptr!=NULL) {*cptr=(char)0; cptr+=3;}
181 if(c==0) sprintf(newroi->
roiname,
"ROI%d", 1+n);
184 c=sscanf(cptr,
"%*d %d \n", &newroi->
point_nr);
186 strcpy(
roierrmsg,
"invalid roi point number");
187 free(newroi->
x); free(newroi->
y); free(newroi);
195 strcpy(
roierrmsg,
"cannot read ROI border definition");
196 free(newroi->
x); free(newroi->
y); free(newroi);
199 newroi->
x=malloc(newroi->
point_nr*
sizeof(
int));
200 newroi->
y=malloc(newroi->
point_nr*
sizeof(
int));
206 newroi->
x[i]=atoi(xs);
207 newroi->
y[i]=atoi(ys);
209 if(i < newroi->point_nr) {
210 strcpy(
roierrmsg,
"cannot read ROI border definition");
211 free(newroi->
x); free(newroi->
y); free(newroi);
216 newroientry=malloc(
sizeof(
RoiList));
217 newroientry->
roi=newroi;
218 newroientry->
prev=roilist;
219 newroientry->
next=NULL;
221 roilist->
next=newroientry;
249 if((roi->
x=malloc(roi->
point_nr*
sizeof(
int)))==NULL)
251 if((roi->
y=malloc(roi->
point_nr*
sizeof(
int)))==NULL) {
252 free(roi->
x);
return(-1);}
253 roi->
x[0]=0; roi->
y[0]=0;
254 roi->
x[1]=roi->
w; roi->
y[1]=0;
255 roi->
x[2]=roi->
w; roi->
y[2]=roi->
h;
256 roi->
x[3]=0; roi->
y[3]=roi->
h;
269 if((roi->
x=malloc(roi->
point_nr*
sizeof(
int)))==NULL)
271 if((roi->
y=malloc(roi->
point_nr*
sizeof(
int)))==NULL) {
272 free((
char*)roi->
x);
return(-1);}
273 roi->
x[0]=0; roi->
y[0]=0;
274 roi->
x[1]=roi->
w; roi->
y[1]=0;
275 roi->
x[2]=roi->
w; roi->
y[2]=roi->
h;
276 roi->
x[3]=0; roi->
y[3]=roi->
h;
277 roi->
x[4]=0; roi->
y[4]=0;
296 roi->
x=malloc(
sizeof(
int)*roi->
point_nr);
297 roi->
y=malloc(
sizeof(
int)*roi->
point_nr);
298 for(points=0;points<roi->
point_nr;points++) {
299 float rad=(M_PI/180.0)*(360.0*(points/(
float)roi->
point_nr));
300 roi->
x[points]=sin(rad)*r;
301 roi->
y[points]=cos(rad)*r-r;
319 roi->
x=malloc(
sizeof(
int)*roi->
point_nr);
320 roi->
y=malloc(
sizeof(
int)*roi->
point_nr);
321 for(points=0;points<roi->
point_nr;points++) {
322 float rad=(M_PI/180.0)*(360.0*(points/(
float)roi->
point_nr));
323 roi->
x[points]=sin(rad)*(roi->
w/2);
324 roi->
y[points]=cos(rad)*(roi->
h/2)-roi->
h/2;
339 printf(
"imgfile: %s\n", roi->
imgfile);
340 printf(
"zoom: %f\n recon_zoom: %f\n", roi->
zoom, roi->
recon_zoom);
342 printf(
"matnum: %d ; plane: %d frame: %d\n",
345 printf(
"type: %d\n status: %d\n", roi->
type, roi->
status);
346 printf(
"pos_x=%d pos_y=%d w=%d h=%d t=%d\n",
348 printf(
"roi=%d _%s_\n", roi->
roi, roi->
roiname);
349 printf(
"points=%d\n", roi->
point_nr);
351 for(i=0; i<roi->
point_nr; i++) printf(
"(%d,%d) ", roi->
x[i], roi->
y[i]);
371static void fill_traceroi(
389 PolygonEdge *edges=malloc(
sizeof(PolygonEdge)*point_nr);
391 for(
int p=0; p<point_nr; p++) {
394 if(p==point_nr-1) n=0;
else n=p+1;
395 if(roiy[p]>roiy[n]) {
396 edges[edge].minY=roiy[n]+pos_y;
397 edges[edge].x=roix[n]+pos_x;
398 edges[edge].maxY=roiy[p]+pos_y;
400 }
else if(roiy[p]<roiy[n]) {
401 edges[edge].minY=roiy[p]+pos_y;
402 edges[edge].x=roix[p]+pos_x;
403 edges[edge].maxY=roiy[n]+pos_y;
407 edges[edge].m=(maxX-edges[edge].x)/(edges[edge].maxY-edges[edge].minY);
412 int *px=malloc(
sizeof(
int)*point_nr);
413 for(
int y=0; y<dimy; y++) {
416 for(
int p=0; p<edge; p++) {
421 if(px[pc]<0) px[pc]=0;
426 for(
int x=0; x<dimx; x++) {
429 for(
int p=0; p<pc; p++) {
462 if(roi==NULL || dimx<2 || dimy<2 || m==NULL) {
463 strcpy(
roierrmsg,
"invalid arguments for roi_onoff()");
467 float pos_x=roi->
pos_x;
468 float pos_y=roi->
pos_y;
469 for(
int x=0; x<dimx; x++)
for(
int y=0; y<dimy; y++) m[x][y]=0;
474 fill_traceroi(m, dimx, dimy, pos_x, pos_y, roi->
x, roi->
y, roi->
point_nr);
477 for(
int x=pos_x; x<pos_x+roi->
w; x++)
478 for(
int y=pos_y; y<pos_y+roi->
h; y++)
485 for(
int y=0; y<r; y++) {
494 if(y1>=0 && y1<dimy) m[x1][y1]=1;
495 if(y2>=0 && y2<dimy) m[x1][y2]=1;
505 for(
int y=0; y<b; y++) {
508 x1=sqrt(1-(y*y)/(
float)(b*b))*a;
514 if(y1>=0 && y1<dimy) m[x1][y1]=1;
515 if(y2>=0 && y2<dimy) m[x1][y2]=1;
540 if(!fname[0] || rl==NULL || rl->
nr<1) {
541 strcpy(
roierrmsg,
"invalid arguments for roiSave()");
546 if((fp=fopen(fname,
"w"))==NULL) {
571 if(fprintf(fp,
"*%s %f %f %d %d %d %d %d %d %d %d %d %s///%d %d\n",
579 fclose(fp);
return 1;
585 fprintf(fp,
"%d %d ", roi->
x[j], roi->
y[j]);
624 t=x=n;
while(t>>=2) x>>=1; x++;
627 if(x<=q) {x2=x+2;
if(q<x2 || (q==x2 && r==0))
break;}
void mat_numdoc(int matnum, Matval *matval)
int roi_mplane(int matnum)
void roi_empty(ROI_list *rl)
int roi_append(FILE *fp, ROI *roi)
int roi_mframe(int matnum)
void roi_delete(ROI_list *rl, ROI *roi)
int roi_compute_rect(ROI *roi)
int roi_save(const char *fname, ROI_list *rl)
void roi_init(ROI_list *rl)
void roi_delete_n(ROI_list *rl, int ind)
int roi_read(const char *fname, ROI_list *rl)
int roi_compute_circle(ROI *roi)
int roi_compute_ellipse(ROI *roi)
int roiComputeRect(ROI *roi)
int roi_append_n(FILE *fp, ROI_list *rl, int ind)
int roi_onoff(ROI *roi, int dimx, int dimy, char **m)
void str_token_list_empty(STR_TOKEN_LIST *lst)
int textfileReadLines(const char *filename, STR_TOKEN_LIST *lst)
void strReplaceChar(char *str, char c1, char c2)
void str_token_list_init(STR_TOKEN_LIST *lst)
int strTokenNCpy(const char *str1, const char *str2, int i, char *str3, int count)
int strncpyCleanSpaces(char *s1, const char *s2, int maxlen)
int strTokenNr(const char *str1, const char *str2)
Header file for libtpcroi.
char imgfile[FILENAME_MAX]