/*--------------------------------------------------------------------------- File name : lwjit_bb.c Author : N. Devillard Created on : July 2000 Description : blackboard structure creator/destructor for lwjit *--------------------------------------------------------------------------*/ /* $Id: lwjit_bb.c,v 1.4 2001/03/14 15:21:40 ndevilla Exp $ $Author: ndevilla $ $Date: 2001/03/14 15:21:40 $ $Revision: 1.4 $ */ /*--------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include #include #include #include #include "eclipse.h" #include "lwjit_bb.h" /*--------------------------------------------------------------------------- Function ANSI prototypes ---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ /** @name lwjit_bb_create() @memo allocate and initialize with zeros a blackboard struct @return newly allocated blackboard structure @doc Create a new blackboard for lwjitter. Deallocation MUST be performed by lwjit_bb_destroy() */ /*---------------------------------------------------------------------------*/ lwjit_bb * lwjit_bb_create(void) { lwjit_bb * bb ; bb = calloc(1, sizeof(lwjit_bb)); return bb ; } /*---------------------------------------------------------------------------*/ /** @name lwjit_bb_destroy() @memo Deallocate a blackboard structure @param destroyed Pointer to blackboard structure to destroy. @return void @doc Deallocate all data associated to a lwjitter blackboard. Blackboard structure assumed allocated previously by lwjit_bb_create() */ /*---------------------------------------------------------------------------*/ void lwjit_bb_destroy(lwjit_bb * bb) { int i ; if (bb==NULL) { return; } if (bb->chop_a!=NULL) { for (i=0 ; inchop ; i++) { if (bb->chop_a[i]!=NULL) { free(bb->chop_a[i]); } } free(bb->chop_a); } if (bb->chop_b!=NULL) { for (i=0 ; inchop ; i++) { if (bb->chop_b[i]!=NULL) { free(bb->chop_b[i]); } } free(bb->chop_b); } if (bb->xcorrobj_x!=NULL) free(bb->xcorrobj_x) ; if (bb->xcorrobj_y!=NULL) free(bb->xcorrobj_y) ; if (bb->xcorr_x!=NULL) free(bb->xcorr_x) ; if (bb->xcorr_y!=NULL) free(bb->xcorr_y) ; if (bb->xcorr_errx!=NULL) free(bb->xcorr_errx) ; if (bb->xcorr_erry!=NULL) free(bb->xcorr_erry) ; if (bb->xcorr_dist!=NULL) free(bb->xcorr_dist) ; free(bb); } /*---------------------------------------------------------------------------*/ /** @name lwjit_bb_dump() @memo Dump contents of the blackboard structure to a file. @param bb Pointer to allocated blackboard structure. @param filename Output filename (NULL for stderr). @return void @doc Dump the contents of the blackboard to a file. If the given filename is NULL, contents are dumped to stderr instead. */ /*---------------------------------------------------------------------------*/ #define IBOOL(i) ((i)? "yes" : "no") void lwjit_bb_dump(lwjit_bb * bb , char * filename) { FILE * dm ; int i ; if (bb==NULL) return ; if (filename==NULL) { dm = stderr ; } else { /* Open the file for dumping */ dm = fopen(filename, "w") ; if (dm==NULL) { e_error("cannot create file [%s]: ", filename); e_error("dumping config to stderr"); dm = stderr ; } } fprintf(dm, "#\n"); fprintf(dm, "# jitter_config from pid [%ld]\n", (long)getpid()); fprintf(dm, "#\n"); fprintf(dm, "\n"); fprintf(dm, "[AlgorithmStatus]\n"); fprintf(dm, "Classification= %s ;\n", lwjit_algo(bb->status_classification)); fprintf(dm, "Cosmetics = %s ;\n", lwjit_algo(bb->status_cosmetics)); fprintf(dm, "Subtraction = %s ;\n", lwjit_algo(bb->status_subtraction)); fprintf(dm, "ObjectAcq = %s ;\n", lwjit_algo(bb->status_objacq)); fprintf(dm, "OffsetAcq = %s ;\n", lwjit_algo(bb->status_offacq)); fprintf(dm, "Register = %s ;\n", lwjit_algo(bb->status_register)); fprintf(dm, "Average3D = %s ;\n", lwjit_algo(bb->status_3davg)); fprintf(dm, "PostProc = %s ;\n", lwjit_algo(bb->status_postproc)); fprintf(dm, "Save = %s ;\n", lwjit_algo(bb->status_save)); fprintf(dm, "\n"); fprintf(dm, "[Frames]\n"); fprintf(dm, "FileList = %s ;\n", bb->frames_filelist); fprintf(dm, "\n"); fprintf(dm, "[FlatField]\n"); fprintf(dm, "Division = %s ;\n", IBOOL(bb->flatfield_division)); fprintf(dm, "Filename = %s ;\n", bb->flatfield_filename); fprintf(dm, "[BadPixels]\n"); fprintf(dm, "Replacement = %s ;\n", IBOOL(bb->badpixels_replacement)); fprintf(dm, "Filename = %s ;\n", bb->badpixels_filename); fprintf(dm, "\n"); fprintf(dm, "[ShiftAndAdd]\n"); fprintf(dm, "ApplyShiftAndAdd = %s ;\n", IBOOL(bb->saa_apply)); fprintf(dm, "\n"); if (bb->saa_apply) { fprintf(dm, "[ObjectAcquisition]\n"); if (bb->objacq_source == OBJACQ_AUTO) fprintf(dm, "Source = auto ;\n"); if (bb->objacq_source == OBJACQ_FILE) { fprintf(dm, "Source = file ;\n"); fprintf(dm, "[UserObjects]\n"); fprintf(dm, "Filename = %s ;\n", bb->objacq_filename); } fprintf(dm, "\n"); fprintf(dm, "[DetPeak]\n"); fprintf(dm, "\n"); fprintf(dm, "Threshold = %g ;\n", bb->detpeak_threshold); fprintf(dm, "MinDetectPoints = %d ;\n", bb->detpeak_mindetpoints); fprintf(dm, "MaxDetectPoints = %d ;\n", bb->detpeak_maxdetpoints); fprintf(dm, "OutputObjects = %s ;\n", IBOOL(bb->detpeak_outputobjs)); fprintf(dm, "\n"); fprintf(dm, "[Offsets]\n"); fprintf(dm, "OffsetFileOutput = %s ;\n", IBOOL(bb->off_fileoutput)); if (bb->off_input == OFFSIN_HEADER) { fprintf(dm, "Input = header ;\n"); fprintf(dm, "\n"); fprintf(dm, "[HeaderOffsets]\n"); fprintf(dm, "XOffsetKeyword = %s ;\n", bb->off_hdr_xkey); fprintf(dm, "YOffsetKeyword = %s ;\n", bb->off_hdr_ykey); fprintf(dm, "Refine = %s ;\n",IBOOL(bb->off_hdr_refine)); fprintf(dm, "SearchSizeX = %d ;\n", bb->off_hdr_sx); fprintf(dm, "SearchSizeY = %d ;\n", bb->off_hdr_sy); fprintf(dm, "MeasureSizeX = %d ;\n", bb->off_hdr_hx); fprintf(dm, "MeasureSizeY = %d ;\n", bb->off_hdr_hy); fprintf(dm, "\n"); } if (bb->off_input == OFFSIN_FILE) { fprintf(dm, "Input = file ;\n"); fprintf(dm, "\n"); fprintf(dm, "[FileOffsets]\n"); fprintf(dm, "InputFileName = %s ;\n", bb->off_file_name); fprintf(dm, "Refine = %s ;\n",IBOOL(bb->off_file_refine)); fprintf(dm, "SearchSizeX = %d ;\n", bb->off_file_sx); fprintf(dm, "SearchSizeY = %d ;\n", bb->off_file_sy); fprintf(dm, "MeasureSizeX = %d ;\n", bb->off_file_hx); fprintf(dm, "MeasureSizeY = %d ;\n", bb->off_file_hy); fprintf(dm, "\n"); } if (bb->off_input == OFFSIN_AUTO) fprintf(dm, "Input = auto ;\n"); fprintf(dm, "[AutomaticOffsets]\n"); fprintf(dm, "SearchSizeX = %d ;\n", bb->off_auto_sx); fprintf(dm, "SearchSizeY = %d ;\n", bb->off_auto_sy); fprintf(dm, "MeasureSizeX = %d ;\n", bb->off_auto_hx); fprintf(dm, "MeasureSizeY = %d ;\n", bb->off_auto_hy); fprintf(dm, "\n"); if (bb->xcorr_nobj > 0) { fprintf(dm, "[XCorrObjects]\n"); fprintf(dm, "Computed = yes ;\n"); fprintf(dm, "NObjects = %d ;\n", bb->xcorr_nobj); fprintf(dm, "\n"); for (i=0 ; ixcorr_nobj ; i++) { fprintf(dm, "XCorrObj:%03d = %d, %d ;\n", i+1, bb->xcorrobj_x[i], bb->xcorrobj_y[i]); } fprintf(dm, "\n"); } else { fprintf(dm, "[XcorrObjects]\n"); fprintf(dm, "Computed = no ;\n"); } if (bb->xcorr_x!=NULL) { fprintf(dm, "[AppliedOffsets]\n"); fprintf(dm, "Computed = yes ;\n"); /* fprintf(dm, "NOffsets = %d ;\n", bb->nobj);*/ fprintf(dm, "NOffsets = %d ;\n", bb->nnod); fprintf(dm, "\n"); /* for (i=0 ; inobj ; i++) { */ for (i=0 ; innod ; i++) { fprintf(dm, "Offset:%03d = %5.2f %5.2f %5.2f %5.2f %g\n", i+1, bb->xcorr_x[i], bb->xcorr_errx[i], bb->xcorr_y[i], bb->xcorr_erry[i], bb->xcorr_dist[i]) ; } fprintf(dm, "\n"); } else { fprintf(dm, "[AppliedOffsets]\n"); fprintf(dm, "Computed = no ;\n"); fprintf(dm, "\n"); } fprintf(dm, "[Registration]\n"); fprintf(dm, "SubPixelShifts = %s ;\n", IBOOL(bb->reg_subpix)); fprintf(dm, "InterpKernel = %s ;\n", bb->reg_kernel); fprintf(dm, "\n"); fprintf(dm, "[FrameAverage]\n"); fprintf(dm, "AverageOutput = %s ;\n", IBOOL(bb->avg3d_active)); if (bb->avg3d_type == AVG3D_LINEAR) fprintf(dm, "AverageType = linear ;\n"); if (bb->avg3d_type == AVG3D_MEDIAN) fprintf(dm, "AverageType = median ;\n"); if (bb->avg3d_type == AVG3D_FILTERED) fprintf(dm, "AverageType = filtered ;\n"); fprintf(dm, "FilteredLow = %g ;\n", bb->avg3d_filt_lo); fprintf(dm, "FilteredHigh = %g ;\n", bb->avg3d_filt_hi); fprintf(dm, "\n"); } fprintf(dm, "[PostProcessing]\n"); fprintf(dm, "Activate = %s ;\n", IBOOL(bb->postproc_active)); fprintf(dm, "StartViewer = %s ;\n", IBOOL(bb->postproc_startviewer)); fprintf(dm, "StartCommand = %s ;\n", bb->postproc_viewer); fprintf(dm, "ProduceStatusReport = %s ;\n", IBOOL(bb->postproc_statusreport)); fprintf(dm, "\n"); fprintf(dm, "[Output]\n"); fprintf(dm, "BaseName = %s ;\n", bb->output_basename); fprintf(dm, "\n"); fprintf(dm, "# end of file\n"); if (dm!=stderr) fclose(dm); return ; } /*---------------------------------------------------------------------------*/ /** @name lwjit_algo() @memo Convert a status into a message. @param s Status integer @return character string @doc Convert an integer coding the algorithm status into a character string. */ /*---------------------------------------------------------------------------*/ char * lwjit_algo(int s) { static char status[15] ; switch (s) { case ALGO_NOTREACHED: strcpy(status, "not reached"); break ; case ALGO_OK: strcpy(status, "Ok"); break ; case ALGO_SKIPPED: strcpy(status, "skipped"); break ; case ALGO_FAILED: strcpy(status, "failed"); break ; default: strcpy(status, "unknown"); break ; } return status ; }