#include "medcon.h" #include "dicom.h" #include #undef VERSION /* prevent any conflict */ #define VERSION "mdc_create_mtf v0.1" ELEMENT *e; DICTIONARY *d; char string[MDC_MAXSTR]; char subj_name[MDC_MAXSTR]; int session_nr,study_nr,matched; #define TAGMATCH(a,b) if(e->group==a&&e->element==b) {matched=1;count++;} int main(int argc, char *argv[]) { FILEINFO fi; FILE *raw; int err=MDC_OK; /* some variables*/ int count=0; double RadX,RadY,PosX,PosY,PosZ; double Thickness=0.,Spacing=0.; double NormX,NormY,NormZ,Step; double RowX,RowY,RowZ; double ColX,ColY,ColZ; /* check arguments */ if(argc!=3){ printf("Usage %s \n",argv[0]); exit(1); } /* disable float exceptions */ MdcIgnoreSIGFPE(); /* do the stuff for each input file */ if ((err = MdcOpenFile(&fi, argv[1])) != MDC_OK) return(err); dicom_init(fi.ifp); if (dicom_open(fi.ipath)) return(1); for (;;) { e=dicom_element(); if (!e) break; /*mit e->vr=UN kann mann immer nach e->value.LT sehen mit dicom_query sind zugriffe sicherer aber komplexer und langsamer siehe mdc_dicom_dumpinfo und mdc_dicom_printinfo in m-dicm.c von xmedcon*/ //d=dicom_query(e); //if (e->vr==UN && d->vr!=ox) { /* replace, except for special tags */ //e->vr=d->vr;} e->vr=DS; if (dicom_load(e->vr)) return(1); matched=0;TAGMATCH(0x0021,0x1120) if(matched==1) { sscanf(e->value.AE[0],"%lf ",&RadX); sscanf(e->value.AE[1],"%lf ",&RadY); } matched=0;TAGMATCH(0x0021,0x1160); if(matched==1) { sscanf(e->value.AE[0],"%le ",&PosX); sscanf(e->value.AE[1],"%le ",&PosY); sscanf(e->value.AE[2],"%le ",&PosZ); } matched=0;TAGMATCH(0x0021,0x1161); if(matched==1) { sscanf(e->value.AE[0],"%lf ",&NormX); sscanf(e->value.AE[1],"%lf ",&NormY); sscanf(e->value.AE[2],"%lf ",&NormZ); } matched=0;TAGMATCH(0x0021,0x116a); if(matched==1) { sscanf(e->value.AE[0],"%lf ",&RowX); sscanf(e->value.AE[1],"%lf ",&RowY); sscanf(e->value.AE[2],"%lf ",&RowZ); } matched=0;TAGMATCH(0x0021,0x116b); if(matched==1) { sscanf(e->value.AE[0],"%lf ",&ColX); sscanf(e->value.AE[1],"%lf ",&ColY); sscanf(e->value.AE[2],"%lf ",&ColZ); } matched=0;TAGMATCH(0x0018,0x0050); if(matched==1) sscanf(e->value.AE[0],"%lf ",&Thickness); matched=0;TAGMATCH(0x0018,0x0088); if(matched==1) sscanf(e->value.AE[0],"%lf ",&Spacing); MdcFree(e->value.UN); if(count==7) break; } MdcCleanUpFI(&fi); Step=(Spacing+Thickness)/1000.; printf("Automatic generated MTF (Auto reversed Col/Norm)\n"); printf("%13.10f %13.10f\n",RadX/2000,RadY/2000); printf("%13.10f %13.10f %13.10f\n",PosX/1000,PosY/1000,PosZ/1000); printf("%13.10f %13.10f %13.10f\n",RowX,-ColX,-NormX); printf("%13.10f %13.10f %13.10f\n",RowY,-ColY,-NormY); printf("%13.10f %13.10f %13.10f\n",RowZ,-ColZ,-NormZ); printf("%13.10f %13.10f %13.10f\n",NormX*Step,NormY*Step,NormZ*Step); if((raw=fopen(argv[2],"w"))==NULL){printf("Can't open %s\n for output",argv[3]);exit(1);} fprintf(raw,"Automatic generated MTF (Auto reversed Col/Norm)\n"); fprintf(raw,"%13.10f %13.10f\n",RadX/2000,RadY/2000); fprintf(raw,"%13.10f %13.10f %13.10f\n",PosX/1000,PosY/1000,PosZ/1000); fprintf(raw,"%13.10f %13.10f %13.10f\n",RowX,-ColX,-NormX); fprintf(raw,"%13.10f %13.10f %13.10f\n",RowY,-ColY,-NormY); fprintf(raw,"%13.10f %13.10f %13.10f\n",RowZ,-ColZ,-NormZ); fprintf(raw,"%13.10f %13.10f %13.10f\n",NormX*Step,NormY*Step,NormZ*Step); fclose(raw); return(0); }