📄 annotate.c
字号:
/*annotation line segment object code*/#include <stdio.h>#include "data.h"#include "map.h"#include "pick.h"#include "plane.h"#include "render.h"#include "draw.h"#include "annotate.h"Annotate _annotate;Annotate AnnotateCurrent () { return _annotate; }void AnnotateSetCurrent (Annotate annotate) { _annotate = annotate; }Annotate AnnotateInit () { Annotate annotate; NEW (Annotate,annotate,1); annotate->nseg = 0; if (GETPARSTRING ("annotate","s",annotate->filename[0])) { AnnotateRead (annotate,annotate->filename[0]); } return annotate; }int AnnotateCompare (AnnotateSeg A , AnnotateSeg B) { if (A->dir != B->dir) { return A->dir - B->dir; } else { return A->a[A->dir] - B->b[B->dir]; } }void AnnotateRead (Annotate annotate , char* filename) { int iline, iaxis, len, iseg, naxis, i, nseg, ntiny, nbad, nclip, dir; FILE *fd; char line[100]; float a[DATA_NAXIS], b[DATA_NAXIS]; AnnotateSeg seg, eseg; Message message; if ((fd=fopen(filename,"r")) == NULL) { sprintf (message, "cant open annotate=%s", filename); UIMessage (message); return; } strcpy (annotate->filename[annotate->nfile],filename); annotate->vis[annotate->nfile] = 1; nseg = 0; ntiny = 0; nbad = 0; nclip = 0; for (seg=annotate->seg, eseg=seg+ANNO_NSEG, iline=1; seg<eseg; iline++) { if (fgets(line,sizeof(line),fd) == NULL) break; sscanf (line,"%d %f %f %f %f %f %f",&dir,a+1,a+2,a+3,b+1,b+2,b+3); seg->dir = dir; seg->id = annotate->nfile; seg->line = iline; if (seg->dir < 1 || seg->dir > 3) { fprintf (stderr,"%s: line=%d dir < 1 or dir > 3\n",filename,iline); nbad++; goto next; } if (a[seg->dir] != b[seg->dir]) { fprintf (stderr,"%s: line=%d is not coplanar\n",filename,iline); nbad++; goto next; } for (iaxis=1, len=0; iaxis<4; iaxis++) { seg->a[iaxis] = AxisIndex(DataAxis(DataCurrent(),iaxis),a[iaxis]); if (seg->a[iaxis] == NO_INDEX) { fprintf (stderr,"%s: line=%d point=%g is out of bounds\n",filename,iline,a[iaxis]); nclip++; goto next; } seg->b[iaxis] = AxisIndex(DataAxis(DataCurrent(),iaxis),b[iaxis]); if (seg->b[iaxis] == NO_INDEX) { fprintf (stderr,"%s: line=%d point=%g is out of bounds\n",filename,iline,b[iaxis]); nclip++; goto next; } len += (seg->b[iaxis] - seg->a[iaxis]) * (seg->b[iaxis] - seg->a[iaxis]); } if (len == 0) { fprintf (stderr,"%s: line=%d is zero len\n",filename,iline); ntiny++; goto next; } seg++; nseg++;next: continue; } fclose (fd); sprintf (message,"%s: nline=%d ntiny=%d nclip=%d nbad=%d\n",filename,nseg,ntiny,nclip,ntiny); UIMessage (message); if (nseg == 0) return; annotate->nseg += nseg; annotate->nfile++; qsort (annotate->seg,annotate->nseg,sizeof(annotate->seg[0]),AnnotateCompare); iseg = 0; for (iaxis=1; iaxis<4; iaxis++) { naxis = AxisSize(DataAxis(DataCurrent(),iaxis)); FREE(annotate->seg0[iaxis]); FREE(annotate->segn[iaxis]); NEW(int*,annotate->seg0[iaxis],naxis); NEW(int*,annotate->segn[iaxis],naxis);/* printf ("naxis=%d\n",naxis);*/ for (i=0; i<naxis && iseg<annotate->nseg && annotate->seg[iseg].dir == iaxis; i++) { while (annotate->seg[iseg].a[iaxis] == i && iseg<annotate->nseg && annotate->seg[iseg].dir == iaxis) { if (!annotate->segn[iaxis][i]) { annotate->seg0[iaxis][i] = iseg; } annotate->segn[iaxis][i]++; iseg++; }/* if (annotate->segn[iaxis][i]) { }*/ } } AnnotateDraw (annotate,DRAW);/* printf ("iseg=%d nseg=%d i=%d\n",iseg,annotate->nseg,i); for (iseg=0; iseg<annotate->nseg; iseg++) { printf ("dir=%d line=%-2d a=(%3d,%3d,%3d) b=(%3d,%3d,%3d)\n",annotate->seg[iseg].dir,annotate->seg[iseg].line,annotate->seg[iseg].a[1],annotate->seg[iseg].a[2],annotate->seg[iseg].a[3],annotate->seg[iseg].b[1],annotate->seg[iseg].b[2],annotate->seg[iseg].b[3]); }*/ }void AnnotateDraw (Annotate annotate , int draw) { int iseg, nseg, dir, frame, x, y, x1, y1, x2, y2, hskew=0, vskew=0; Plane plane, eplane; if (!annotate || !annotate->nseg) return; for (plane=PlaneList(), eplane=plane+NPLANE; plane < eplane && PlaneIsSet(plane); plane++) { dir = PlaneDir(plane); frame = PlaneFrame(plane); hskew = 0; vskew = 0; if (PlaneType(plane) == RENDER_HORZ) hskew = PlaneSkew(plane); else vskew = PlaneSkew(plane); for (iseg=annotate->seg0[dir][frame], nseg=iseg+annotate->segn[dir][frame]; iseg<nseg; iseg++) { if (!annotate->vis[annotate->seg[iseg].id]) continue; x = MapInverse(PlaneHmap(plane), annotate->seg[iseg].a[AxisDir(MapAxis(PlaneHmap(plane)))]); if (PlaneType(plane) == RENDER_VERT) { x = MapSize(PlaneHmap(plane)) - x; } y = MapInverse(PlaneVmap(plane), annotate->seg[iseg].a[AxisDir(MapAxis(PlaneVmap(plane)))]); if (x != NO_INDEX && y != NO_INDEX) { x1 = x + PlaneH0(plane) + hskew * (MapSize(PlaneVmap(plane)) - y); y1 = y + PlaneV0(plane) + vskew * (PlaneNH(plane) - x); } else continue; x = MapInverse(PlaneHmap(plane), annotate->seg[iseg].b[AxisDir(MapAxis(PlaneHmap(plane)))]); if (PlaneType(plane) == RENDER_VERT) { x = MapSize(PlaneHmap(plane)) - x; } y = MapInverse(PlaneVmap(plane), annotate->seg[iseg].b[AxisDir(MapAxis(PlaneVmap(plane)))]); if (x != NO_INDEX && y != NO_INDEX) { x2 = x + PlaneH0(plane) + hskew * (MapSize(PlaneVmap(plane)) - y); y2 = y + PlaneV0(plane) + vskew * (PlaneNH(plane) - x); } else continue; DrawLine (DrawCurrent(),x1,y1,x2,y2,draw); } } }char* AnnotateFilename (Annotate annotate) { if (!annotate) return 0; return annotate->filename[0]; }void AnnotateInfo (Annotate annotate) { Message message; sprintf (message,"ANNOTATE INFO:\n\file=%s nseg=%d", annotate->filename[0], annotate->nseg); UIMessageBox (message); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -