From f650721f076832ce239b17407843cdfd02652d14 Mon Sep 17 00:00:00 2001 From: oguyon Date: Thu, 15 Aug 2024 04:52:18 -1000 Subject: [PATCH] multicrop --- .../milk-extra-src/linalgebra/GramSchmidt.c | 2 +- .../linalgebra/MVMextractModes.c | 2 - .../linalgebra/basis_rotate_match.c | 93 ++- src/COREMOD_arith/CMakeLists.txt | 2 + src/COREMOD_arith/COREMOD_arith.c | 3 +- src/COREMOD_arith/COREMOD_arith.h | 2 + src/COREMOD_arith/image_crop2D.c | 12 +- src/COREMOD_arith/image_multicrop2D.c | 574 ++++++++++++++++++ src/COREMOD_arith/image_multicrop2D.h | 6 + src/CommandLineInterface/CLIcore.h | 2 +- .../CLIcore/CLIcore_help.c | 243 ++++---- .../CLIcore/CLIcore_modules.c | 5 + .../CLIcore/CLIcore_utils.h | 4 +- 13 files changed, 790 insertions(+), 160 deletions(-) create mode 100644 src/COREMOD_arith/image_multicrop2D.c create mode 100644 src/COREMOD_arith/image_multicrop2D.h diff --git a/plugins/milk-extra-src/linalgebra/GramSchmidt.c b/plugins/milk-extra-src/linalgebra/GramSchmidt.c index 8e533ed3..daba418b 100644 --- a/plugins/milk-extra-src/linalgebra/GramSchmidt.c +++ b/plugins/milk-extra-src/linalgebra/GramSchmidt.c @@ -149,7 +149,7 @@ errno_t GramSchmidt( double sqrsum0 = 0.0; // square sum v1 - double sqrsum1= 0.0; + double sqrsum1 = 0.0; for( uint32_t ii=0; iiarray.SI64[ii]; } break; - - } } diff --git a/plugins/milk-extra-src/linalgebra/basis_rotate_match.c b/plugins/milk-extra-src/linalgebra/basis_rotate_match.c index 9d6612e4..1f2b1643 100644 --- a/plugins/milk-extra-src/linalgebra/basis_rotate_match.c +++ b/plugins/milk-extra-src/linalgebra/basis_rotate_match.c @@ -158,11 +158,7 @@ errno_t compute_basis_rotate_match( int incrcnt = 0; // incremented int proccnt = 0; // processed - int TriangMode = 0; // lower triang - if(optmode == 3) - { - TriangMode = 1; // upper triang - } + @@ -308,15 +304,18 @@ errno_t compute_basis_rotate_match( if(optmode == 2) { loopiter = 0; - loopiterMax = 1000; + loopiterMax = 100; double alphap = 1.0; double dangle = 1.0; + double danglegain = 0.8; + double danglemin = 0.001; - double danglemfact = 0.97; + double danglemfact = 0.7; - double posSideAmp = 10.0; + double negSideAmp = 0.0; + double posSideAmp = 1.0; // temp storate for vects to be swapped @@ -343,24 +342,38 @@ errno_t compute_basis_rotate_match( long cntneg = 0; long cntmid = 0; + + // measure quality metric (optall) + // double optall = 0.0; for( int iia = 0; iia < Adim; iia++ ) { + // x0 generally > 1 + // x0 tracks diagonal double x0 = AmodeBeff[iia] / Adim; + for( int iib = 0; iib < Bdim; iib++ ) { + // dx0 is distance to "diagonal" double x = 1.0*iib / Adim; double dx0 = x-x0; + + double dcoeff = pow(dx0*dx0, alphap); if( dx0 > 0.0 ) { dcoeff *= posSideAmp; } + else + { + dcoeff *= negSideAmp; + } optall += dcoeff * matAB[iia*Bdim + iib] * dcoeff * matAB[iia*Bdim + iib]; } } printf("iter %4d / %4d dangle = %f / %f val = %g\n", loopiter, loopiterMax, dangle, danglemin, optall); + for ( int n0 = 0; n0 < Adim; n0++) { for ( int n1 = n0+1; n1 < Adim; n1++ ) @@ -368,8 +381,9 @@ errno_t compute_basis_rotate_match( // testing rotation n0 n1, dangle // ref value - double optval0 = 0.0; // to be minimized - double optval1 = 0.0; // to be minimized + // sum of optval0 and optval1 to be minimized + double optval0 = 0.0; + double optval1 = 0.0; double optvalpos0 = 0.0; double optvalpos1 = 0.0; @@ -394,23 +408,43 @@ errno_t compute_basis_rotate_match( double dcoeff0 = pow(dx0*dx0, alphap); double dcoeff1 = pow(dx1*dx1, alphap); + double v0 = matAB[n0*Bdim + ii]; + double v1 = matAB[n1*Bdim + ii]; + + double wcoeff0 = 0.0; + double wcoeff1 = 0.0; + if( dx0 > 0.0 ) { dcoeff0 *= posSideAmp; + wcoeff0 += posSideAmp * fabs(v0); + } + else + { + dcoeff0 *= negSideAmp; + wcoeff0 += negSideAmp * fabs(v0); } + if( dx1 > 0.0 ) { dcoeff1 *= posSideAmp; + wcoeff1 += posSideAmp * fabs(v1); + } + else + { + dcoeff1 *= negSideAmp; + wcoeff1 += negSideAmp * fabs(v1); } + //wcoeff = pow(wcoeff, 4.0); + wcoeff0 = 1.0; + wcoeff1 = 1.0; - double v0 = matAB[n0*Bdim + ii]; - double v1 = matAB[n1*Bdim + ii]; // optimization metric without rotation - optval0 += dcoeff0 * v0*v0; - optval1 += dcoeff1 * v1*v1; + optval0 += wcoeff0 * dcoeff0 * v0*v0; + optval1 += wcoeff1 * dcoeff1 * v1*v1; // perform rotation, weite to n0array and n1array n0arraypos[ii] = v0 * cos(dangle) - v1 * sin(dangle); @@ -420,12 +454,12 @@ errno_t compute_basis_rotate_match( n1arrayneg[ii] = - v0 * sin(dangle) + v1 * cos(dangle); // optimization metric with positive rotation - optvalpos0 += dcoeff0 * n0arraypos[ii] * n0arraypos[ii]; - optvalpos1 += dcoeff1 * n1arraypos[ii] * n1arraypos[ii]; + optvalpos0 += wcoeff0 * dcoeff0 * n0arraypos[ii] * n0arraypos[ii]; + optvalpos1 += wcoeff1 * dcoeff1 * n1arraypos[ii] * n1arraypos[ii]; // optimization metric with negative rotation - optvalneg0 += dcoeff0 * n0arrayneg[ii] * n0arrayneg[ii]; - optvalneg1 += dcoeff1 * n1arrayneg[ii] * n1arrayneg[ii]; + optvalneg0 += wcoeff0 * dcoeff0 * n0arrayneg[ii] * n0arrayneg[ii]; + optvalneg1 += wcoeff1 * dcoeff1 * n1arrayneg[ii] * n1arrayneg[ii]; } double optval = optval0 + optval1; @@ -439,13 +473,13 @@ errno_t compute_basis_rotate_match( if(optvalneg < optval) { // rotate neg - optrotangle = -dangle; + optrotangle = -dangle * danglegain; cntneg++; } else if(optvalpos < optval) { // rotate pos - optrotangle = dangle; + optrotangle = dangle * danglegain; cntpos++; } else @@ -466,11 +500,11 @@ errno_t compute_basis_rotate_match( if( optrotangle > dangle ) { - optrotangle = dangle; + optrotangle = dangle * danglegain; } if( optrotangle < -dangle ) { - optrotangle = -dangle; + optrotangle = -dangle * danglegain; } //optrotangle = 0.0; @@ -506,8 +540,8 @@ errno_t compute_basis_rotate_match( } } - printf(" [%5ld %5ld %5ld] %g\n", cntneg, cntmid, cntpos, dangle); - if( cntmid > 100.0*(cntpos+cntneg) ) + printf(" [%5ld %5ld %5ld] %8.6f -> %8.6f\n", cntneg, cntmid, cntpos, 1.0*cntmid/(cntmid+cntpos+cntneg), dangle); + if( 1.0*cntmid/(cntmid+cntpos+cntneg) > 0.999 ) { dangle *= danglemfact; } @@ -517,6 +551,7 @@ errno_t compute_basis_rotate_match( // Measure, for each A mode, the effective index of B modes + // AmodeBeff[iia] has to be > iia // long * iarray = (long *) malloc(sizeof(long) * Adim); for( int iia = 0; iia < Adim; iia++ ) @@ -536,17 +571,23 @@ errno_t compute_basis_rotate_match( // sort by effective index quick_sort2l(AmodeBeff, iarray, Adim); - /* + { char fname[STRINGMAXLEN_FILENAME]; WRITE_FILENAME(fname, "./compfCM/Beff.%04d.dat", loopiter); FILE * fpBeff = fopen(fname, "w"); for( int iia = 0; iia < Adim; iia++ ) { + if(AmodeBeff[iia] < iia) + { + AmodeBeff[iia] = iia; + } fprintf(fpBeff, "%4d %16f %4ld\n", iia, AmodeBeff[iia], iarray[iia]); } fclose(fpBeff); - }*/ + } + + if ( loopiter == loopiterMax-1 ) diff --git a/src/COREMOD_arith/CMakeLists.txt b/src/COREMOD_arith/CMakeLists.txt index bc815cbf..94cfc63a 100644 --- a/src/COREMOD_arith/CMakeLists.txt +++ b/src/COREMOD_arith/CMakeLists.txt @@ -9,6 +9,7 @@ set(SOURCEFILES ${SRCNAME}.c image_crop.c image_crop2D.c + image_multicrop2D.c image_merge3D.c image_norm.c image_pixremap.c @@ -38,6 +39,7 @@ set(INCLUDEFILES ${SRCNAME}.h image_crop.h image_crop2D.h + image_multicrop2D.h image_cropmask.h image_merge3D.h image_norm.h diff --git a/src/COREMOD_arith/COREMOD_arith.c b/src/COREMOD_arith/COREMOD_arith.c index 8df53494..cf93c11b 100644 --- a/src/COREMOD_arith/COREMOD_arith.c +++ b/src/COREMOD_arith/COREMOD_arith.c @@ -52,7 +52,7 @@ #include "image_crop.h" //#include "image_cropmask.h" #include "image_crop2D.h" - +#include "image_multicrop2D.h" #include "image_dxdy.h" #include "image_norm.h" @@ -107,6 +107,7 @@ static errno_t init_module_CLI() //CLIADDCMD_COREMODE_arith__cropmask(); CLIADDCMD_COREMODE_arith__crop2D(); + CLIADDCMD_COREMODE_arith__multicrop2D(); CLIADDCMD_COREMOD_arith__imset_1Dpixrange(); CLIADDCMD_COREMOD_arith__imset_2Dpix(); diff --git a/src/COREMOD_arith/COREMOD_arith.h b/src/COREMOD_arith/COREMOD_arith.h index 2746281d..f628aadb 100644 --- a/src/COREMOD_arith/COREMOD_arith.h +++ b/src/COREMOD_arith/COREMOD_arith.h @@ -12,6 +12,8 @@ #include "COREMOD_arith/image_arith__im_f_f__im.h" #include "COREMOD_arith/image_arith__im_im__im.h" #include "COREMOD_arith/image_crop.h" +#include "COREMOD_arith/image_crop2D.h" +#include "COREMOD_arith/image_multicrop2D.h" #include "COREMOD_arith/image_dxdy.h" #include "COREMOD_arith/image_merge3D.h" #include "COREMOD_arith/image_stats.h" diff --git a/src/COREMOD_arith/image_crop2D.c b/src/COREMOD_arith/image_crop2D.c index 47ba3c30..500f1509 100644 --- a/src/COREMOD_arith/image_crop2D.c +++ b/src/COREMOD_arith/image_crop2D.c @@ -8,24 +8,24 @@ static char *cropinsname; -long fpi_cropinsname; +static long fpi_cropinsname; static char *outsname; -long fpi_outsname; +static long fpi_outsname; static uint32_t *cropxstart; -long fpi_cropxstart; +static long fpi_cropxstart; static uint32_t *cropxsize; -long fpi_cropxsize; +static long fpi_cropxsize; static uint32_t *cropystart; -long fpi_cropystart; +static long fpi_cropystart; static uint32_t *cropysize; -long fpi_cropysize; +static long fpi_cropysize; diff --git a/src/COREMOD_arith/image_multicrop2D.c b/src/COREMOD_arith/image_multicrop2D.c new file mode 100644 index 00000000..5142c329 --- /dev/null +++ b/src/COREMOD_arith/image_multicrop2D.c @@ -0,0 +1,574 @@ +/** + * @file image_multicrop2D.c + * @brief crop 2D function, multiple windows + * + */ + +#include "CommandLineInterface/CLIcore.h" + +static char *mcropinsname; +static long fpi_mcropinsname; + +static char *outsname; +static long fpi_outsname; + + +static uint32_t *outxsize; +static long fpi_outxsize; + +static uint32_t *outysize; +static long fpi_outysize; + + +/* +#define CROPWINDOWVARS(WINDEX) \ +static int64_t *w#WINDEXactive; \ +static long fpi_w#WINDEXactive; \ +static uint32_t *w#WINDEXcropxstart; \ +long fpi_w#WINDEXcropxstart; \ +static uint32_t *w#WINDEXcropxsize; \ +long fpi_w#WINDEXcropxsize; \ +static uint32_t *w#WINDEXcropystart; \ +long fpi_w#WINDEXcropystart; \ +static uint32_t *w#WINDEXcropysize; \ +long fpi_w#WINDEXcropysize; + +CROPWINDOWVARS(00) +*/ + + +// Window 00 + +#define MAXNB_CROPWINDOW 8 + +static int64_t *wactive[MAXNB_CROPWINDOW]; +static long fpi_wactive[MAXNB_CROPWINDOW]; + +// addmode = 0 if replacing pixels, 1 if adding +static int64_t *waddmode[MAXNB_CROPWINDOW]; +static long fpi_waddmode[MAXNB_CROPWINDOW]; + +static uint32_t *wcropxstart[MAXNB_CROPWINDOW]; +static long fpi_wcropxstart[MAXNB_CROPWINDOW]; + +static uint32_t *wcropxsize[MAXNB_CROPWINDOW]; +static long fpi_wcropxsize[MAXNB_CROPWINDOW]; + +static uint32_t *wcropystart[MAXNB_CROPWINDOW]; +static long fpi_wcropystart[MAXNB_CROPWINDOW]; + +static uint32_t *wcropysize[MAXNB_CROPWINDOW]; +static long fpi_wcropysize[MAXNB_CROPWINDOW]; + + + + +#define STR_EXPAND(tok) #tok +#define STR(tok) STR_EXPAND(tok) + + +#define CROPWINDOWONOFF(wn) \ + { \ + CLIARG_ONOFF,\ + ".w"#wn".active",\ + "crop window active flag", \ + "0",\ + CLIARG_HIDDEN_DEFAULT,\ + (void **) &wactive[wn],\ + &fpi_wactive[wn]\ + } + +#define CROPWINDOWADDMODE(wn) \ + { \ + CLIARG_ONOFF,\ + ".w"#wn".addmode",\ + "1 if adding, 0 if replacing", \ + "0",\ + CLIARG_HIDDEN_DEFAULT,\ + (void **) &waddmode[wn],\ + &fpi_waddmode[wn]\ + } + +#define CROPWINDOWXSTART(wn) \ + {\ + CLIARG_UINT32,\ + ".w"#wn".cropxstart",\ + "crop x coord start",\ + "30",\ + CLIARG_HIDDEN_DEFAULT,\ + (void **) &wcropxstart[wn],\ + &fpi_wcropxstart[wn]\ + } + +#define CROPWINDOWXSIZE(wn) \ + {\ + CLIARG_UINT32,\ + ".w"#wn".cropxsize",\ + "crop x coord size",\ + "30",\ + CLIARG_HIDDEN_DEFAULT,\ + (void **) &wcropxsize[wn],\ + &fpi_wcropxsize[wn]\ + } + +#define CROPWINDOWYSTART(wn) \ + {\ + CLIARG_UINT32,\ + ".w"#wn".cropystart",\ + "crop y coord start",\ + "30",\ + CLIARG_HIDDEN_DEFAULT,\ + (void **) &wcropystart[wn],\ + &fpi_wcropystart[wn]\ + } + +#define CROPWINDOWYSIZE(wn) \ + {\ + CLIARG_UINT32,\ + ".w"#wn".cropysize",\ + "crop y coord size",\ + "30",\ + CLIARG_HIDDEN_DEFAULT,\ + (void **) &wcropysize[wn],\ + &fpi_wcropysize[wn]\ + } + + + + + + +static CLICMDARGDEF farg[] = +{ + { + CLIARG_IMG, + ".insname", + "input stream name", + "inim", + CLIARG_VISIBLE_DEFAULT, + (void **) &mcropinsname, + &fpi_mcropinsname + }, + { + CLIARG_STR, + ".outsname", + "output stream name", + "outim", + CLIARG_VISIBLE_DEFAULT, + (void **) &outsname, + &fpi_outsname + }, + { + CLIARG_UINT32, + ".outxsize", + "output x size", + "200", + CLIARG_VISIBLE_DEFAULT, + (void **) &outxsize, + &fpi_outxsize + }, + { + CLIARG_UINT32, + ".outysize", + "output y size", + "200", + CLIARG_VISIBLE_DEFAULT, + (void **) &outysize, + &fpi_outysize + }, + CROPWINDOWONOFF(00), + CROPWINDOWADDMODE(00), + CROPWINDOWXSTART(00), + CROPWINDOWXSIZE(00), + CROPWINDOWYSTART(00), + CROPWINDOWYSIZE(00), + + CROPWINDOWONOFF(01), + CROPWINDOWADDMODE(01), + CROPWINDOWXSTART(01), + CROPWINDOWXSIZE(01), + CROPWINDOWYSTART(01), + CROPWINDOWYSIZE(01), + + CROPWINDOWONOFF(02), + CROPWINDOWADDMODE(02), + CROPWINDOWXSTART(02), + CROPWINDOWXSIZE(02), + CROPWINDOWYSTART(02), + CROPWINDOWYSIZE(02), + + CROPWINDOWONOFF(03), + CROPWINDOWADDMODE(03), + CROPWINDOWXSTART(03), + CROPWINDOWXSIZE(03), + CROPWINDOWYSTART(03), + CROPWINDOWYSIZE(03), + + CROPWINDOWONOFF(04), + CROPWINDOWADDMODE(04), + CROPWINDOWXSTART(04), + CROPWINDOWXSIZE(04), + CROPWINDOWYSTART(04), + CROPWINDOWYSIZE(04), + + CROPWINDOWONOFF(05), + CROPWINDOWADDMODE(05), + CROPWINDOWXSTART(05), + CROPWINDOWXSIZE(05), + CROPWINDOWYSTART(05), + CROPWINDOWYSIZE(05), + + CROPWINDOWONOFF(06), + CROPWINDOWADDMODE(06), + CROPWINDOWXSTART(06), + CROPWINDOWXSIZE(06), + CROPWINDOWYSTART(06), + CROPWINDOWYSIZE(06), + + CROPWINDOWONOFF(07), + CROPWINDOWADDMODE(07), + CROPWINDOWXSTART(07), + CROPWINDOWXSIZE(07), + CROPWINDOWYSTART(07), + CROPWINDOWYSIZE(07) +}; + + + +// Optional custom configuration setup. +// Runs once at conf startup +// +static errno_t customCONFsetup() +{ + if(data.fpsptr != NULL) + { + data.fpsptr->parray[fpi_mcropinsname].fpflag |= + FPFLAG_STREAM_RUN_REQUIRED | FPFLAG_CHECKSTREAM; + } + + return RETURN_SUCCESS; +} + +// Optional custom configuration checks. +// Runs at every configuration check loop iteration +// +static errno_t customCONFcheck() +{ + + if(data.fpsptr != NULL) + { + } + + return RETURN_SUCCESS; +} + +static CLICMDDATA CLIcmddata = +{ + "multicrop2D", "crop 2D image, multiple crops", CLICMD_FIELDS_DEFAULTS +}; + +// detailed help +static errno_t help_function() +{ + return RETURN_SUCCESS; +} + + + + + + + +static errno_t compute_function() +{ + DEBUG_TRACE_FSTART(); + + // CONNECT TO INPUT STREAM + IMGID imgin = mkIMGID_from_name(mcropinsname); + resolveIMGID(&imgin, ERRMODE_ABORT); + + // CONNNECT TO OR CREATE OUTPUT STREAM + IMGID imgout = stream_connect_create_2D(outsname, *outxsize, *outysize, imgin.md->datatype); + + + INSERT_STD_PROCINFO_COMPUTEFUNC_INIT; + + + + INSERT_STD_PROCINFO_COMPUTEFUNC_LOOPSTART + { + + // zero output array + switch (imgin.md->datatype) + { + case _DATATYPE_FLOAT: + for(uint64_t ii=0; ii < *outxsize * *outysize; ii++) + { + imgout.im->array.F[ii] = 0.0; + } + break; + + case _DATATYPE_DOUBLE: + for(uint64_t ii=0; ii < *outxsize * *outysize; ii++) + { + imgout.im->array.D[ii] = 0.0; + } + break; + + case _DATATYPE_UINT8: + for(uint64_t ii=0; ii < *outxsize * *outysize; ii++) + { + imgout.im->array.UI8[ii] = 0; + } + break; + + case _DATATYPE_UINT16: + for(uint64_t ii=0; ii < *outxsize * *outysize; ii++) + { + imgout.im->array.UI16[ii] = 0; + } + break; + + case _DATATYPE_UINT32: + for(uint64_t ii=0; ii < *outxsize * *outysize; ii++) + { + imgout.im->array.UI32[ii] = 0; + } + break; + + case _DATATYPE_UINT64: + for(uint64_t ii=0; ii < *outxsize * *outysize; ii++) + { + imgout.im->array.UI64[ii] = 0; + } + break; + + case _DATATYPE_INT8: + for(uint64_t ii=0; ii < *outxsize * *outysize; ii++) + { + imgout.im->array.SI8[ii] = 0; + } + break; + + case _DATATYPE_INT16: + for(uint64_t ii=0; ii < *outxsize * *outysize; ii++) + { + imgout.im->array.SI16[ii] = 0; + } + break; + + case _DATATYPE_INT32: + for(uint64_t ii=0; ii < *outxsize * *outysize; ii++) + { + imgout.im->array.SI32[ii] = 0; + } + break; + + case _DATATYPE_INT64: + for(uint64_t ii=0; ii < *outxsize * *outysize; ii++) + { + imgout.im->array.SI64[ii] = 0; + } + break; + + } + + + + for(int cropwindow=0; cropwindow < MAXNB_CROPWINDOW ; cropwindow++) + { + if ( *wactive[cropwindow] == 1) + { + uint32_t jjmax = *wcropysize[cropwindow]; + if ( jjmax + *wcropystart[cropwindow] > (*outysize)) + { + jjmax = (*outysize) - *wcropystart[cropwindow]; + } + + uint32_t iimax = *wcropxsize[cropwindow]; + if ( iimax + *wcropxstart[cropwindow] > (*outxsize)) + { + iimax = (*outxsize) - *wcropxstart[cropwindow]; + } + + + for(uint32_t jj = 0; jj < jjmax; jj++) + { + uint64_t indjj = jj + (*wcropystart[cropwindow]); + indjj *= imgin.md->size[0]; + + + if ( *waddmode[cropwindow] == 0 ) + { + switch (imgin.md->datatype) + { + case _DATATYPE_FLOAT: + memcpy( &imgout.im->array.F[ jj * (*wcropxsize[cropwindow])], + &imgin.im->array.F[ indjj + (*wcropxstart[cropwindow]) ], + iimax * SIZEOF_DATATYPE_FLOAT); + break; + + case _DATATYPE_DOUBLE: + memcpy( &imgout.im->array.D[ jj * (*wcropxsize[cropwindow])], + &imgin.im->array.D[ indjj + (*wcropxstart[cropwindow]) ], + iimax * SIZEOF_DATATYPE_DOUBLE); + break; + + case _DATATYPE_UINT8: + memcpy( &imgout.im->array.UI8[ jj * (*wcropxsize[cropwindow])], + &imgin.im->array.UI8[ indjj + (*wcropxstart[cropwindow]) ], + iimax * SIZEOF_DATATYPE_UINT8); + break; + + case _DATATYPE_UINT16: + memcpy( &imgout.im->array.UI16[ jj * (*wcropxsize[cropwindow])], + &imgin.im->array.UI16[ indjj + (*wcropxstart[cropwindow]) ], + iimax * SIZEOF_DATATYPE_UINT16); + break; + + case _DATATYPE_UINT32: + memcpy( &imgout.im->array.UI32[ jj * (*wcropxsize[cropwindow])], + &imgin.im->array.UI32[ indjj + (*wcropxstart[cropwindow]) ], + iimax * SIZEOF_DATATYPE_UINT32); + break; + + case _DATATYPE_UINT64: + memcpy( &imgout.im->array.UI64[ jj * (*wcropxsize[cropwindow])], + &imgin.im->array.UI64[ indjj + (*wcropxstart[cropwindow]) ], + iimax * SIZEOF_DATATYPE_UINT64); + break; + + case _DATATYPE_INT8: + memcpy( &imgout.im->array.SI8[ jj * (*wcropxsize[cropwindow])], + &imgin.im->array.SI8[ indjj + (*wcropxstart[cropwindow]) ], + iimax * SIZEOF_DATATYPE_INT8); + break; + + case _DATATYPE_INT16: + memcpy( &imgout.im->array.SI16[ jj * (*wcropxsize[cropwindow])], + &imgin.im->array.SI16[ indjj + (*wcropxstart[cropwindow]) ], + iimax * SIZEOF_DATATYPE_INT16); + break; + + case _DATATYPE_INT32: + memcpy( &imgout.im->array.SI32[ jj * (*wcropxsize[cropwindow])], + &imgin.im->array.SI32[ indjj + (*wcropxstart[cropwindow]) ], + iimax * SIZEOF_DATATYPE_INT32); + break; + + case _DATATYPE_INT64: + memcpy( &imgout.im->array.SI64[ jj * (*wcropxsize[cropwindow])], + &imgin.im->array.SI64[ indjj + (*wcropxstart[cropwindow]) ], + iimax * SIZEOF_DATATYPE_INT64); + break; + + } + } + else // add pixels + { + switch (imgin.md->datatype) + { + + case _DATATYPE_FLOAT: + for(int ii=0; ii< iimax; ii++) + { + imgout.im->array.F[ jj * (*wcropxsize[cropwindow]) + ii] += imgin.im->array.F[ indjj + (*wcropxstart[cropwindow] + ii)]; + } + break; + + case _DATATYPE_DOUBLE: + for(int ii=0; ii< iimax; ii++) + { + imgout.im->array.D[ jj * (*wcropxsize[cropwindow]) + ii] += imgin.im->array.D[ indjj + (*wcropxstart[cropwindow] + ii)]; + } + break; + + case _DATATYPE_UINT8: + for(int ii=0; ii< iimax; ii++) + { + imgout.im->array.UI8[ jj * (*wcropxsize[cropwindow]) + ii] += imgin.im->array.UI8[ indjj + (*wcropxstart[cropwindow] + ii)]; + } + break; + + case _DATATYPE_UINT16: + for(int ii=0; ii< iimax; ii++) + { + imgout.im->array.UI16[ jj * (*wcropxsize[cropwindow]) + ii] += imgin.im->array.UI16[ indjj + (*wcropxstart[cropwindow] + ii)]; + } + break; + + case _DATATYPE_UINT32: + for(int ii=0; ii< iimax; ii++) + { + imgout.im->array.UI32[ jj * (*wcropxsize[cropwindow]) + ii] += imgin.im->array.UI32[ indjj + (*wcropxstart[cropwindow] + ii)]; + } + break; + + case _DATATYPE_UINT64: + for(int ii=0; ii< iimax; ii++) + { + imgout.im->array.UI64[ jj * (*wcropxsize[cropwindow]) + ii] += imgin.im->array.UI64[ indjj + (*wcropxstart[cropwindow] + ii)]; + } + break; + + case _DATATYPE_INT8: + for(int ii=0; ii< iimax; ii++) + { + imgout.im->array.SI8[ jj * (*wcropxsize[cropwindow]) + ii] += imgin.im->array.SI8[ indjj + (*wcropxstart[cropwindow] + ii)]; + } + break; + + case _DATATYPE_INT16: + for(int ii=0; ii< iimax; ii++) + { + imgout.im->array.SI16[ jj * (*wcropxsize[cropwindow]) + ii] += imgin.im->array.SI16[ indjj + (*wcropxstart[cropwindow] + ii)]; + } + break; + + case _DATATYPE_INT32: + for(int ii=0; ii< iimax; ii++) + { + imgout.im->array.SI32[ jj * (*wcropxsize[cropwindow]) + ii] += imgin.im->array.SI32[ indjj + (*wcropxstart[cropwindow] + ii)]; + } + break; + + case _DATATYPE_INT64: + for(int ii=0; ii< iimax; ii++) + { + imgout.im->array.SI64[ jj * (*wcropxsize[cropwindow]) + ii] += imgin.im->array.SI64[ indjj + (*wcropxstart[cropwindow] + ii)]; + } + break; + } + + } + } + } + } + processinfo_update_output_stream(processinfo, imgout.ID); + + } + INSERT_STD_PROCINFO_COMPUTEFUNC_END + + DEBUG_TRACE_FEXIT(); + return RETURN_SUCCESS; +} + + + + + +INSERT_STD_FPSCLIfunctions + + + + +// Register function in CLI +errno_t +CLIADDCMD_COREMODE_arith__multicrop2D() +{ + CLIcmddata.FPS_customCONFsetup = customCONFsetup; + CLIcmddata.FPS_customCONFcheck = customCONFcheck; + INSERT_STD_CLIREGISTERFUNC + + return RETURN_SUCCESS; +} diff --git a/src/COREMOD_arith/image_multicrop2D.h b/src/COREMOD_arith/image_multicrop2D.h new file mode 100644 index 00000000..3406de69 --- /dev/null +++ b/src/COREMOD_arith/image_multicrop2D.h @@ -0,0 +1,6 @@ +#ifndef COREMOD_ARITH_MULTICROP2D_H +#define COREMOD_ARITH_MULTICROP2D_H + +errno_t CLIADDCMD_COREMODE_arith__multicrop2D(); + +#endif diff --git a/src/CommandLineInterface/CLIcore.h b/src/CommandLineInterface/CLIcore.h index 7a80b0e1..8c8fb6d4 100644 --- a/src/CommandLineInterface/CLIcore.h +++ b/src/CommandLineInterface/CLIcore.h @@ -124,7 +124,7 @@ extern int C_ERRNO; // C errno (from errno.h) exit(0); \ } -#define NB_ARG_MAX 20 +#define NB_ARG_MAX 100 // // ************ lib module init ********************************** diff --git a/src/CommandLineInterface/CLIcore/CLIcore_help.c b/src/CommandLineInterface/CLIcore/CLIcore_help.c index 5821481a..5dbd7691 100644 --- a/src/CommandLineInterface/CLIcore/CLIcore_help.c +++ b/src/CommandLineInterface/CLIcore/CLIcore_help.c @@ -504,41 +504,41 @@ int CLIhelp_make_argstring(CLICMDARGDEF fpscliarg[], switch(fpscliarg[arg].type) { - case CLIARG_FLOAT32: - strcpy(typestring, "float32"); - break; + case CLIARG_FLOAT32: + strcpy(typestring, "float32"); + break; - case CLIARG_FLOAT64: - strcpy(typestring, "float64"); - break; + case CLIARG_FLOAT64: + strcpy(typestring, "float64"); + break; - case CLIARG_INT32: - strcpy(typestring, "int32"); - break; + case CLIARG_INT32: + strcpy(typestring, "int32"); + break; - case CLIARG_UINT32: - strcpy(typestring, "uint32"); - break; + case CLIARG_UINT32: + strcpy(typestring, "uint32"); + break; - case CLIARG_INT64: - strcpy(typestring, "int64"); - break; + case CLIARG_INT64: + strcpy(typestring, "int64"); + break; - case CLIARG_UINT64: - strcpy(typestring, "uint64"); - break; + case CLIARG_UINT64: + strcpy(typestring, "uint64"); + break; - case CLIARG_STR_NOT_IMG: - strcpy(typestring, "string"); - break; + case CLIARG_STR_NOT_IMG: + strcpy(typestring, "string"); + break; - case CLIARG_IMG: - strcpy(typestring, "string"); - break; + case CLIARG_IMG: + strcpy(typestring, "string"); + break; - case CLIARG_STR: - strcpy(typestring, "string"); - break; + case CLIARG_STR: + strcpy(typestring, "string"); + break; } if(arg == 0) @@ -560,8 +560,9 @@ int CLIhelp_make_argstring(CLICMDARGDEF fpscliarg[], typestring, fpscliarg[arg].fpstag); + // max number of chars we can write - int n = STRINGMAXLEN_CMD_SYNTAX - strlen(tmpstr1); + int n = STRINGMAXLEN_CMD_SYNTAX - strlen(tmpstr); if(n > 2) { strncat(tmpstr, tmpstr1, n - 1); @@ -687,24 +688,24 @@ errno_t help_command( data.cmd[cmdi].cmdsettings.triggermode); switch(data.cmd[cmdi].cmdsettings.triggermode) { - case PROCESSINFO_TRIGGERMODE_IMMEDIATE: - printf("IMMEDIATE"); - break; - case PROCESSINFO_TRIGGERMODE_CNT0: - printf("CNT0"); - break; - case PROCESSINFO_TRIGGERMODE_CNT1: - printf("CNT1"); - break; - case PROCESSINFO_TRIGGERMODE_SEMAPHORE: - printf("SEMAPHORE"); - break; - case PROCESSINFO_TRIGGERMODE_DELAY: - printf("DELAY"); - break; - default: - printf("unknown"); - break; + case PROCESSINFO_TRIGGERMODE_IMMEDIATE: + printf("IMMEDIATE"); + break; + case PROCESSINFO_TRIGGERMODE_CNT0: + printf("CNT0"); + break; + case PROCESSINFO_TRIGGERMODE_CNT1: + printf("CNT1"); + break; + case PROCESSINFO_TRIGGERMODE_SEMAPHORE: + printf("SEMAPHORE"); + break; + case PROCESSINFO_TRIGGERMODE_DELAY: + printf("DELAY"); + break; + default: + printf("unknown"); + break; } printf("\n"); @@ -768,92 +769,92 @@ errno_t help_command( switch(data.cmd[cmdi].argdata[argi].type) { - /*case CLIARG_FLOAT: - SNPRINTF_CHECK(valuestring, STRINGMAXLEN_CLICMDARG, "[ float ] %f", - data.cmd[cmdi].argdata[argi].val.f); - break;*/ - - case CLIARG_FLOAT32: - SNPRINTF_CHECK(valuestring, - STRINGMAXLEN_CLICMDARG, - "[float32] %f", - data.cmd[cmdi].argdata[argi].val.f32); - break; + /*case CLIARG_FLOAT: + SNPRINTF_CHECK(valuestring, STRINGMAXLEN_CLICMDARG, "[ float ] %f", + data.cmd[cmdi].argdata[argi].val.f); + break;*/ - case CLIARG_FLOAT64: - SNPRINTF_CHECK(valuestring, - STRINGMAXLEN_CLICMDARG, - "[float64] %lf", - data.cmd[cmdi].argdata[argi].val.f64); - break; + case CLIARG_FLOAT32: + SNPRINTF_CHECK(valuestring, + STRINGMAXLEN_CLICMDARG, + "[float32] %f", + data.cmd[cmdi].argdata[argi].val.f32); + break; - case CLIARG_ONOFF: - SNPRINTF_CHECK(valuestring, - STRINGMAXLEN_CLICMDARG, - "[ ONOFF ] %ld", - data.cmd[cmdi].argdata[argi].val.ui64); - break; + case CLIARG_FLOAT64: + SNPRINTF_CHECK(valuestring, + STRINGMAXLEN_CLICMDARG, + "[float64] %lf", + data.cmd[cmdi].argdata[argi].val.f64); + break; - /*case CLIARG_LONG: - SNPRINTF_CHECK(valuestring, STRINGMAXLEN_CLICMDARG, "[ long ] %ld", - data.cmd[cmdi].argdata[argi].val.l); - break;*/ + case CLIARG_ONOFF: + SNPRINTF_CHECK(valuestring, + STRINGMAXLEN_CLICMDARG, + "[ ONOFF ] %ld", + data.cmd[cmdi].argdata[argi].val.ui64); + break; - case CLIARG_INT32: - SNPRINTF_CHECK(valuestring, - STRINGMAXLEN_CLICMDARG, - "[ int32 ] %d", - data.cmd[cmdi].argdata[argi].val.i32); - break; + /*case CLIARG_LONG: + SNPRINTF_CHECK(valuestring, STRINGMAXLEN_CLICMDARG, "[ long ] %ld", + data.cmd[cmdi].argdata[argi].val.l); + break;*/ - case CLIARG_UINT32: - SNPRINTF_CHECK(valuestring, - STRINGMAXLEN_CLICMDARG, - "[uint32 ] %u", - data.cmd[cmdi].argdata[argi].val.ui32); - break; + case CLIARG_INT32: + SNPRINTF_CHECK(valuestring, + STRINGMAXLEN_CLICMDARG, + "[ int32 ] %d", + data.cmd[cmdi].argdata[argi].val.i32); + break; - case CLIARG_INT64: - SNPRINTF_CHECK(valuestring, - STRINGMAXLEN_CLICMDARG, - "[ int64 ] %ld", - data.cmd[cmdi].argdata[argi].val.i64); - break; + case CLIARG_UINT32: + SNPRINTF_CHECK(valuestring, + STRINGMAXLEN_CLICMDARG, + "[uint32 ] %u", + data.cmd[cmdi].argdata[argi].val.ui32); + break; - case CLIARG_UINT64: - SNPRINTF_CHECK(valuestring, - STRINGMAXLEN_CLICMDARG, - "[uint64 ] %lu", - data.cmd[cmdi].argdata[argi].val.ui64); - break; + case CLIARG_INT64: + SNPRINTF_CHECK(valuestring, + STRINGMAXLEN_CLICMDARG, + "[ int64 ] %ld", + data.cmd[cmdi].argdata[argi].val.i64); + break; - case CLIARG_STR_NOT_IMG: - SNPRINTF_CHECK(valuestring, - STRINGMAXLEN_CLICMDARG, - "[ STRnI ] %s", - data.cmd[cmdi].argdata[argi].val.s); - break; + case CLIARG_UINT64: + SNPRINTF_CHECK(valuestring, + STRINGMAXLEN_CLICMDARG, + "[uint64 ] %lu", + data.cmd[cmdi].argdata[argi].val.ui64); + break; - case CLIARG_IMG: - SNPRINTF_CHECK(valuestring, - STRINGMAXLEN_CLICMDARG, - "[ IMG ] %s", - data.cmd[cmdi].argdata[argi].val.s); - break; + case CLIARG_STR_NOT_IMG: + SNPRINTF_CHECK(valuestring, + STRINGMAXLEN_CLICMDARG, + "[ STRnI ] %s", + data.cmd[cmdi].argdata[argi].val.s); + break; - case CLIARG_STR: - SNPRINTF_CHECK(valuestring, - STRINGMAXLEN_CLICMDARG, - "[ STR ] %s", - data.cmd[cmdi].argdata[argi].val.s); - break; + case CLIARG_IMG: + SNPRINTF_CHECK(valuestring, + STRINGMAXLEN_CLICMDARG, + "[ IMG ] %s", + data.cmd[cmdi].argdata[argi].val.s); + break; - case CLIARG_STREAM: - SNPRINTF_CHECK(valuestring, - STRINGMAXLEN_CLICMDARG, - "[ STREA ] %s", - data.cmd[cmdi].argdata[argi].val.s); - break; + case CLIARG_STR: + SNPRINTF_CHECK(valuestring, + STRINGMAXLEN_CLICMDARG, + "[ STR ] %s", + data.cmd[cmdi].argdata[argi].val.s); + break; + + case CLIARG_STREAM: + SNPRINTF_CHECK(valuestring, + STRINGMAXLEN_CLICMDARG, + "[ STREA ] %s", + data.cmd[cmdi].argdata[argi].val.s); + break; } if(!(data.cmd[cmdi].argdata[argi].flag & CLICMDARG_FLAG_NOCLI)) diff --git a/src/CommandLineInterface/CLIcore/CLIcore_modules.c b/src/CommandLineInterface/CLIcore/CLIcore_modules.c index fd74f874..d8251048 100644 --- a/src/CommandLineInterface/CLIcore/CLIcore_modules.c +++ b/src/CommandLineInterface/CLIcore/CLIcore_modules.c @@ -533,6 +533,7 @@ uint32_t RegisterCLIcmd( STRINGMAXLEN_MODULE_NAME - 1); } + DEBUG_TRACEPOINT("settingsrcfile to %s", CLIcmddata.sourcefilename); strncpy(data.cmd[data.NBcmd].srcfile, CLIcmddata.sourcefilename, STRINGMAXLEN_CMD_SRCFILE - 1); @@ -540,6 +541,7 @@ uint32_t RegisterCLIcmd( strncpy(data.cmd[data.NBcmd].info, CLIcmddata.description, STRINGMAXLEN_CMD_INFO - 1); + // assemble argument syntax string for help char argstring[STRINGMAXLEN_CMD_SYNTAX]; CLIhelp_make_argstring(CLIcmddata.funcfpscliarg, @@ -547,6 +549,7 @@ uint32_t RegisterCLIcmd( argstring); strncpy(data.cmd[data.NBcmd].syntax, argstring, STRINGMAXLEN_CMD_SYNTAX - 1); + // assemble example string for help char cmdexamplestring[STRINGMAXLEN_CMD_EXAMPLE]; CLIhelp_make_cmdexamplestring(CLIcmddata.funcfpscliarg, @@ -556,9 +559,11 @@ uint32_t RegisterCLIcmd( strncpy(data.cmd[data.NBcmd].example, cmdexamplestring, STRINGMAXLEN_CMD_EXAMPLE - 1); + strncpy(data.cmd[data.NBcmd].Ccall, "--callstring--", STRINGMAXLEN_CMD_CCALL - 1); + DEBUG_TRACEPOINT( "define arguments to CLI function from content of " "CLIcmddata.funcfpscliarg"); diff --git a/src/CommandLineInterface/CLIcore/CLIcore_utils.h b/src/CommandLineInterface/CLIcore/CLIcore_utils.h index acb4e57e..02aa0fbb 100644 --- a/src/CommandLineInterface/CLIcore/CLIcore_utils.h +++ b/src/CommandLineInterface/CLIcore/CLIcore_utils.h @@ -312,8 +312,8 @@ typedef struct int processloopOK = 1; \ PROCESSINFO *processinfo = NULL; \ /* set default timeout to 2 sec */ \ - CLIcmddata.cmdsettings->triggertimeout.tv_sec = 0; \ - CLIcmddata.cmdsettings->triggertimeout.tv_nsec = 1000000; \ + CLIcmddata.cmdsettings->triggertimeout.tv_sec = 2; \ + CLIcmddata.cmdsettings->triggertimeout.tv_nsec = 0; \ if (data.fpsptr != NULL) \ { /* If FPS mode, then FPS settings override defaults*/ \ /* data.fpsptr->cmset entries are read by fps_connect */ \