From 80328dac20dd51c4d2daeb25daa2b57180c39486 Mon Sep 17 00:00:00 2001 From: billKarsh Date: Mon, 3 Oct 2016 22:13:14 -0400 Subject: [PATCH] Tab->spc 1_XXX --- 1_CpyFMs/CpyFMs.cpp | 98 +- 1_CpyFMs/makefile | 4 +- 1_Cross_CarveBlocks/countdowndirs.sht | 28 +- 1_Cross_CarveBlocks/cross_carveblocks.cpp | 854 ++--- 1_Cross_CarveBlocks/makefile | 4 +- 1_Cross_LowRes/ScapeMeta.cpp | 116 +- 1_Cross_LowRes/ScapeMeta.h | 16 +- 1_Cross_LowRes/cross_lowres.cpp | 352 +- 1_Cross_LowRes/makefile | 4 +- 1_Cross_Scaffold/cross_scaffold.cpp | 292 +- 1_Cross_Scaffold/makefile | 4 +- 1_Cross_ThisBlock/bsub.sht | 32 +- 1_Cross_ThisBlock/cross_thisblock.cpp | 1116 +++--- 1_Cross_ThisBlock/makefile | 4 +- 1_Cross_TopScripts/cross_topscripts.cpp | 532 +-- 1_Cross_TopScripts/makefile | 4 +- 1_DMesh/ApproximateMatch.cpp | 260 +- 1_DMesh/ApproximateMatch.h | 16 +- 1_DMesh/ApproximateMatch_NoCR.cpp | 82 +- 1_DMesh/CGBL_dmesh.cpp | 742 ++-- 1_DMesh/CGBL_dmesh.h | 116 +- 1_DMesh/CThmUtil.cpp | 876 ++--- 1_DMesh/CThmUtil.h | 264 +- 1_DMesh/CreateMesh.cpp | 1702 ++++----- 1_DMesh/CreateMesh.h | 34 +- 1_DMesh/ImproveMesh.cpp | 490 +-- 1_DMesh/ImproveMesh.h | 26 +- 1_DMesh/InSectionOverlap.cpp | 442 +-- 1_DMesh/InSectionOverlap.h | 10 +- 1_DMesh/RegionToRegionMap.cpp | 950 ++--- 1_DMesh/RegionToRegionMap.h | 16 +- 1_DMesh/dmesh.cpp | 1042 +++--- 1_DMesh/dmesh.h | 14 +- 1_DMesh/dmesh_unused.cpp | 8 +- 1_DMesh/dmeshdriver.cpp | 306 +- 1_DMesh/janelia.cpp | 188 +- 1_DMesh/janelia.h | 2 +- 1_DMesh/makefile | 4 +- 1_DelTiles/DelTiles.cpp | 150 +- 1_DelTiles/makefile | 4 +- 1_EView/eview.cpp | 252 +- 1_EView/makefile | 4 +- 1_LSQi/lsq.cpp | 624 ++-- 1_LSQi/lsq_Layers.cpp | 292 +- 1_LSQi/lsq_Layers.h | 30 +- 1_LSQi/makefile | 4 +- 1_LSQw/lsq_Bounds.cpp | 216 +- 1_LSQw/lsq_Dropout.cpp | 208 +- 1_LSQw/lsq_Dropout.h | 24 +- 1_LSQw/lsq_Error.cpp | 1026 +++--- 1_LSQw/lsq_Globals.cpp | 190 +- 1_LSQw/lsq_Globals.h | 82 +- 1_LSQw/lsq_LoadPoints.cpp | 162 +- 1_LSQw/lsq_LoadPoints.h | 50 +- 1_LSQw/lsq_MPI.cpp | 98 +- 1_LSQw/lsq_Magnitude.cpp | 574 +-- 1_LSQw/lsq_Solve.cpp | 1474 ++++---- 1_LSQw/lsq_Split.cpp | 892 ++--- 1_LSQw/lsq_Split.h | 36 +- 1_LSQw/lsq_Untwist.cpp | 218 +- 1_LSQw/lsq_XArray.cpp | 850 ++--- 1_LSQw/lsq_XArray.h | 18 +- 1_LSQw/lsqw.cpp | 460 +-- 1_LSQw/makefile | 4 +- 1_LsqErr/lsqerr.cpp | 190 +- 1_LsqErr/makefile | 4 +- 1_MRCSD1Lyr/MRCSD1Lyr.cpp | 116 +- 1_MRCSD1Lyr/combinesd.sht | 2 +- 1_MRCSD1Lyr/makefile | 4 +- 1_MRCSD1Lyr/submrcsd.sht | 2 +- 1_MakeIDB/fsub.sht | 18 +- 1_MakeIDB/makefile | 4 +- 1_MakeIDB/makeidb.cpp | 600 ++-- 1_MakeMontages/Retired/cleandown.sht | 44 +- 1_MakeMontages/Retired/montage1.sht | 2 +- 1_MakeMontages/Retired/retired.cpp | 456 +-- 1_MakeMontages/Retired/submon.sht | 14 +- 1_MakeMontages/cleandown1.sht | 18 +- 1_MakeMontages/cleandownpts.sht | 52 +- 1_MakeMontages/cleanlsq.sht | 48 +- 1_MakeMontages/cleanmon.sht | 18 +- 1_MakeMontages/cleansame1.sht | 18 +- 1_MakeMontages/countsamedirs.sht | 28 +- 1_MakeMontages/dreport.sht | 26 +- 1_MakeMontages/dsub.sht | 34 +- 1_MakeMontages/gathermons.sht | 12 +- 1_MakeMontages/makefile | 4 +- 1_MakeMontages/makemontages.cpp | 1652 ++++----- 1_MakeMontages/mreport.sht | 14 +- 1_MakeMontages/msub.sht | 18 +- 1_MakeMontages/sreport.sht | 26 +- 1_MakeMontages/ssub.sht | 32 +- 1_Mosaic_current/json-include/json/reader.h | 40 +- 1_Mosaic_current/json-include/json/value.h | 96 +- 1_Mosaic_current/json_batchallocator.h | 4 +- 1_Mosaic_current/json_reader.cpp | 134 +- 1_Mosaic_current/json_value.cpp | 166 +- 1_Mosaic_current/json_valueiterator.inl | 16 +- 1_Mosaic_current/json_writer.cpp | 84 +- 1_Mosaic_current/makefile | 4 +- 1_Mosaic_current/mos.cpp | 3520 +++++++++---------- 1_Mosaic_current/mos_back.cpp | 2712 +++++++------- 1_Mosaic_current/mos_back2.cpp | 2964 ++++++++-------- 1_Mosaic_current/submos.sht | 14 +- 1_Ptestx/makefile | 4 +- 1_Ptestx/ptestx.cpp | 268 +- 1_Reformat/makefile | 4 +- 1_Reformat/reformat.cpp | 388 +- 1_RemoveRefTiles/RemoveRefTiles.cpp | 112 +- 1_RemoveRefTiles/makefile | 4 +- 1_Scapeops/makefile | 4 +- 1_Scapeops/scapeops.cpp | 904 ++--- 1_ShtMaker/makefile | 4 +- 1_ShtMaker/shtmaker.cpp | 58 +- 1_Thumbs/CGBL_Thumbs.cpp | 450 +-- 1_Thumbs/CGBL_Thumbs.h | 86 +- 1_Thumbs/Thumbs.cpp | 74 +- 1_Thumbs/Thumbs.h | 8 +- 1_Thumbs/ThumbsDriver.cpp | 146 +- 1_Thumbs/Thumbs_NoCR.cpp | 64 +- 1_Thumbs/makefile | 4 +- 1_Tiny/makefile | 4 +- 1_Tiny/tiny.cpp | 944 ++--- 1_Tiny/tiny_billnew.cpp | 924 ++--- 1_TopScripts/makefile | 4 +- 1_TopScripts/topscripts.cpp | 268 +- 1_ViewSD/ViewSD.cpp | 206 +- 1_ViewSD/makefile | 4 +- 1_XView/makefile | 4 +- 1_XView/xview.cpp | 1322 +++---- 130 files changed, 19232 insertions(+), 19232 deletions(-) diff --git a/1_CpyFMs/CpyFMs.cpp b/1_CpyFMs/CpyFMs.cpp index 242ba86..ae40f26 100644 --- a/1_CpyFMs/CpyFMs.cpp +++ b/1_CpyFMs/CpyFMs.cpp @@ -24,13 +24,13 @@ class CArgs_ldir { public: - const char *infile, - *outdir; + const char *infile, + *outdir; public: - CArgs_ldir() : infile(NULL), outdir("NoSuch") {}; + CArgs_ldir() : infile(NULL), outdir("NoSuch") {}; - void SetCmdLine( int argc, char* argv[] ); + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -53,45 +53,45 @@ void CArgs_ldir::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "CpyFMs.log", "w" ); + flog = FileOpenOrDie( "CpyFMs.log", "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Start: %s ", atime ); + fprintf( flog, "Start: %s ", atime ); // parse command line args - if( argc < 3 ) { - printf( "Usage: CpyFMs -d=.\n" ); - exit( 42 ); - } + if( argc < 3 ) { + printf( "Usage: CpyFMs -d=.\n" ); + exit( 42 ); + } - for( int i = 1; i < argc; ++i ) { + for( int i = 1; i < argc; ++i ) { - // echo to log - fprintf( flog, "%s ", argv[i] ); + // echo to log + fprintf( flog, "%s ", argv[i] ); - if( argv[i][0] != '-' ) - infile = argv[i]; - else if( GetArgStr( outdir, "-d=", argv[i] ) ) - ; - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - exit( 42 ); - } - } + if( argv[i][0] != '-' ) + infile = argv[i]; + else if( GetArgStr( outdir, "-d=", argv[i] ) ) + ; + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + exit( 42 ); + } + } - fprintf( flog, "\n\n" ); - fflush( flog ); + fprintf( flog, "\n\n" ); + fflush( flog ); - freopen( "CpyFMs.log", "a", stdout ); - freopen( "CpyFMs.log", "a", stderr ); + freopen( "CpyFMs.log", "a", stdout ); + freopen( "CpyFMs.log", "a", stderr ); } /* --------------------------------------------------------------- */ @@ -100,28 +100,28 @@ void CArgs_ldir::SetCmdLine( int argc, char* argv[] ) static void Process() { - FILE *f = FileOpenOrDie( gArgs.infile, "r", flog ); - CLineScan LS; + FILE *f = FileOpenOrDie( gArgs.infile, "r", flog ); + CLineScan LS; - for(;;) { + for(;;) { - char path[2048], cmd[2048]; - int z, id; + char path[2048], cmd[2048]; + int z, id; - if( LS.Get( f ) <= 0 ) - break; + if( LS.Get( f ) <= 0 ) + break; - sscanf( LS.line, "%d;%d;%[^;]", &z, &id, path ); + sscanf( LS.line, "%d;%d;%[^;]", &z, &id, path ); - sprintf( cmd, "cp '%s' '%s/%d/%d/fm.tif'", - path, gArgs.outdir, z, id ); + sprintf( cmd, "cp '%s' '%s/%d/%d/fm.tif'", + path, gArgs.outdir, z, id ); - fprintf( flog, "%s\n", cmd ); + fprintf( flog, "%s\n", cmd ); - system( cmd ); - } + system( cmd ); + } - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -134,22 +134,22 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* ------- */ /* Process */ /* ------- */ - Process(); + Process(); /* ---- */ /* Done */ /* ---- */ - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_CpyFMs/makefile b/1_CpyFMs/makefile index 8a44446..38a59ef 100644 --- a/1_CpyFMs/makefile +++ b/1_CpyFMs/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_Cross_CarveBlocks/countdowndirs.sht b/1_Cross_CarveBlocks/countdowndirs.sht index 196984c..d278b68 100644 --- a/1_Cross_CarveBlocks/countdowndirs.sht +++ b/1_Cross_CarveBlocks/countdowndirs.sht @@ -10,9 +10,9 @@ export MRC_TRIM=12 if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi cd .. @@ -21,17 +21,17 @@ cnt=0 for lyr in $(seq $1 $last) do - if [ -d "$lyr" ] - then - cd $lyr - - for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') - do - cnt=$(($cnt+1)) - done - - echo z= $lyr cum= $cnt - cd .. - fi + if [ -d "$lyr" ] + then + cd $lyr + + for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') + do + cnt=$(($cnt+1)) + done + + echo z= $lyr cum= $cnt + cd .. + fi done diff --git a/1_Cross_CarveBlocks/cross_carveblocks.cpp b/1_Cross_CarveBlocks/cross_carveblocks.cpp index 2c4440f..ee6b7c7 100644 --- a/1_Cross_CarveBlocks/cross_carveblocks.cpp +++ b/1_Cross_CarveBlocks/cross_carveblocks.cpp @@ -23,26 +23,26 @@ class Block { public: - vector vID; + vector vID; }; class BlockSet { public: - vector K; - int w, h, - kx, ky, - dx, dy, - nb; + vector K; + int w, h, + kx, ky, + dx, dy, + nb; private: - void OrientLayer( int is0, int isN ); - void SetDims(); - void PartitionTiles( int is0, int isN ); - void Consolidate(); - void ReportBlocks( int z ); + void OrientLayer( int is0, int isN ); + void SetDims(); + void PartitionTiles( int is0, int isN ); + void Consolidate(); + void ReportBlocks( int z ); public: - void CarveIntoBlocks( int is0, int isN ); - void WriteParams( int za, int zb ); + void CarveIntoBlocks( int is0, int isN ); + void WriteParams( int za, int zb ); }; /* --------------------------------------------------------------- */ @@ -52,15 +52,15 @@ class BlockSet { class CArgs_alnmon { public: - const char *srcscaf, - *script; - int zmin, - zmax; + const char *srcscaf, + *script; + int zmin, + zmax; public: - CArgs_alnmon() - : srcscaf(NULL), script(NULL), zmin(0), zmax(32768) {}; + CArgs_alnmon() + : srcscaf(NULL), script(NULL), zmin(0), zmax(32768) {}; - void SetCmdLine( int argc, char* argv[] ); + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -72,7 +72,7 @@ static ScriptParams scr; static CTileSet TS; static FILE* flog = NULL; static int gW = 0, // universal pic dims - gH = 0; + gH = 0; @@ -87,58 +87,58 @@ void CArgs_alnmon::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "cross_carveblocks.log", "w" ); + flog = FileOpenOrDie( "cross_carveblocks.log", "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Carve blocks: %s ", atime ); + fprintf( flog, "Carve blocks: %s ", atime ); // parse command line args - if( argc < 4 ) { - printf( - "Usage: cross_carveblocks srcscaf" - " -script=scriptpath -z=i,j.\n" ); - exit( 42 ); - } - - vector vi; - - for( int i = 1; i < argc; ++i ) { - - // echo to log - fprintf( flog, "%s ", argv[i] ); - - if( argv[i][0] != '-' ) - srcscaf = argv[i]; - else if( GetArgStr( script, "-script=", argv[i] ) ) - ; - else if( GetArgList( vi, "-z=", argv[i] ) ) { - - if( 2 == vi.size() ) { - zmin = vi[0]; - zmax = vi[1]; - } - else { - fprintf( flog, - "Bad format in -z [%s].\n", argv[i] ); - exit( 42 ); - } - } - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n\n" ); - fflush( flog ); + if( argc < 4 ) { + printf( + "Usage: cross_carveblocks srcscaf" + " -script=scriptpath -z=i,j.\n" ); + exit( 42 ); + } + + vector vi; + + for( int i = 1; i < argc; ++i ) { + + // echo to log + fprintf( flog, "%s ", argv[i] ); + + if( argv[i][0] != '-' ) + srcscaf = argv[i]; + else if( GetArgStr( script, "-script=", argv[i] ) ) + ; + else if( GetArgList( vi, "-z=", argv[i] ) ) { + + if( 2 == vi.size() ) { + zmin = vi[0]; + zmax = vi[1]; + } + else { + fprintf( flog, + "Bad format in -z [%s].\n", argv[i] ); + exit( 42 ); + } + } + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n\n" ); + fflush( flog ); } /* --------------------------------------------------------------- */ @@ -147,32 +147,32 @@ void CArgs_alnmon::SetCmdLine( int argc, char* argv[] ) static void WriteTestblockFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "testblock.sht" ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Put this script into a Dx_y folder to try or debug block.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Options:\n" ); - fprintf( f, "# -evalalldz\t\t;force evaluation of all maxdz layers\n" ); - fprintf( f, "# -abdbg\t\t\t;make diagnostic images and exit (Z^Z-1)\n" ); - fprintf( f, "# -abdbg=k\t\t\t;make diagnostic images and exit (Z^k)\n" ); - fprintf( f, "# -abctr=0\t\t\t;debug at this a-to-b angle\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "export MRC_TRIM=12\n" ); - fprintf( f, "\n" ); - fprintf( f, "QSUB_1NODE.sht 7 \"x\" \"\" %d \"cross_thisblock -script=%s\"\n", - scr.blockslots, gArgs.script ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "testblock.sht" ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Put this script into a Dx_y folder to try or debug block.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Options:\n" ); + fprintf( f, "# -evalalldz\t\t;force evaluation of all maxdz layers\n" ); + fprintf( f, "# -abdbg\t\t\t;make diagnostic images and exit (Z^Z-1)\n" ); + fprintf( f, "# -abdbg=k\t\t\t;make diagnostic images and exit (Z^k)\n" ); + fprintf( f, "# -abctr=0\t\t\t;debug at this a-to-b angle\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "export MRC_TRIM=12\n" ); + fprintf( f, "\n" ); + fprintf( f, "QSUB_1NODE.sht 7 \"x\" \"\" %d \"cross_thisblock -script=%s\"\n", + scr.blockslots, gArgs.script ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -181,61 +181,61 @@ static void WriteTestblockFile() static void WriteBSubFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "bsub.sht" ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Fifth step in cross-layer alignment.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > cross_thisblock -script=scriptpath\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Do one block alignment job, data read from 'blockdat.txt'.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Options:\n" ); - fprintf( f, "# -evalalldz\t\t;force evaluation of all maxdz layers\n" ); - fprintf( f, "# -abdbg\t\t\t;make diagnostic images and exit (Z^Z-1)\n" ); - fprintf( f, "# -abdbg=k\t\t\t;make diagnostic images and exit (Z^k)\n" ); - fprintf( f, "# -abctr=0\t\t\t;debug at this a-to-b angle\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "export MRC_TRIM=12\n" ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "cd ..\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\techo $lyr\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tcd $lyr\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tfor jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}')\n" ); - fprintf( f, "\t\tdo\n" ); - fprintf( f, "\t\t\tcd $jb\n" ); - fprintf( f, "\t\t\tQSUB_1NODE.sht 7 \"x$jb-$lyr\" \"\" %d \"cross_thisblock -script=%s\"\n", - scr.blockslots, gArgs.script ); - fprintf( f, "\t\t\tcd ..\n" ); - fprintf( f, "\t\tdone\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tcd ..\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "bsub.sht" ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Fifth step in cross-layer alignment.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > cross_thisblock -script=scriptpath\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Do one block alignment job, data read from 'blockdat.txt'.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Options:\n" ); + fprintf( f, "# -evalalldz\t\t;force evaluation of all maxdz layers\n" ); + fprintf( f, "# -abdbg\t\t\t;make diagnostic images and exit (Z^Z-1)\n" ); + fprintf( f, "# -abdbg=k\t\t\t;make diagnostic images and exit (Z^k)\n" ); + fprintf( f, "# -abctr=0\t\t\t;debug at this a-to-b angle\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "export MRC_TRIM=12\n" ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "cd ..\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\techo $lyr\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tcd $lyr\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tfor jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}')\n" ); + fprintf( f, "\t\tdo\n" ); + fprintf( f, "\t\t\tcd $jb\n" ); + fprintf( f, "\t\t\tQSUB_1NODE.sht 7 \"x$jb-$lyr\" \"\" %d \"cross_thisblock -script=%s\"\n", + scr.blockslots, gArgs.script ); + fprintf( f, "\t\t\tcd ..\n" ); + fprintf( f, "\t\tdone\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tcd ..\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -244,52 +244,52 @@ static void WriteBSubFile() static void WriteCountdowndirsFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "countdowndirs.sht" ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Count all 'Dx_y' dirs in layer range\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./countdowndirs.sht i j\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "export MRC_TRIM=12\n" ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "cd ..\n" ); - fprintf( f, "\n" ); - fprintf( f, "cnt=0\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tcd $lyr\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tfor jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}')\n" ); - fprintf( f, "\t\tdo\n" ); - fprintf( f, "\t\t\tcnt=$(($cnt+1))\n" ); - fprintf( f, "\t\tdone\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\techo z= $lyr cum= $cnt\n" ); - fprintf( f, "\t\tcd ..\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "countdowndirs.sht" ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Count all 'Dx_y' dirs in layer range\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./countdowndirs.sht i j\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "export MRC_TRIM=12\n" ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "cd ..\n" ); + fprintf( f, "\n" ); + fprintf( f, "cnt=0\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tcd $lyr\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tfor jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}')\n" ); + fprintf( f, "\t\tdo\n" ); + fprintf( f, "\t\t\tcnt=$(($cnt+1))\n" ); + fprintf( f, "\t\tdone\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\techo z= $lyr cum= $cnt\n" ); + fprintf( f, "\t\tcd ..\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -298,40 +298,40 @@ static void WriteCountdowndirsFile() static void WriteReportFiles() { - char buf[2048]; - FILE *f; + char buf[2048]; + FILE *f; // errors - sprintf( buf, "breport.sht" ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Sixth step in cross-layer alignment.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Run this after bsub completes to compile tables\n" ); - fprintf( f, "# of block alignment errors, FAILs and make sizes.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./breport.sht\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "ls -l ../*/D*/xD*.e* > BlockErrs.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "ls -l ../*/D*/xD*.o* > BlockOuts.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "ls -l ../*/D*/make.down > BlockMakes.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "grep FAIL ../*/D*/cross_thisblock.log > BlockFAIL.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "grep -e \"Final coverage\" ../*/D*/cross_thisblock.log > BlockCoverage.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "grep -e \"PeakHunt: Best\" ../*/D*/cross_thisblock.log > BlockTForms.txt\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + sprintf( buf, "breport.sht" ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Sixth step in cross-layer alignment.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Run this after bsub completes to compile tables\n" ); + fprintf( f, "# of block alignment errors, FAILs and make sizes.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./breport.sht\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "ls -l ../*/D*/xD*.e* > BlockErrs.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "ls -l ../*/D*/xD*.o* > BlockOuts.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "ls -l ../*/D*/make.down > BlockMakes.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "grep FAIL ../*/D*/cross_thisblock.log > BlockFAIL.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "grep -e \"Final coverage\" ../*/D*/cross_thisblock.log > BlockCoverage.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "grep -e \"PeakHunt: Best\" ../*/D*/cross_thisblock.log > BlockTForms.txt\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -344,37 +344,37 @@ void BlockSet::OrientLayer( int is0, int isN ) { // Collect all tile corners in (C) - vector C, cnr; - Set4Corners( cnr, gW, gH ); + vector C, cnr; + Set4Corners( cnr, gW, gH ); - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - vector c( 4 ); - memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); - TS.vtil[i].T.Transform( c ); + vector c( 4 ); + memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); + TS.vtil[i].T.Transform( c ); - for( int i = 0; i < 4; ++i ) - C.push_back( c[i] ); - } + for( int i = 0; i < 4; ++i ) + C.push_back( c[i] ); + } // Rotate layer upright and translate to (0,0) - TAffine R; - DBox B; - int deg = TightestBBox( B, C ); + TAffine R; + DBox B; + int deg = TightestBBox( B, C ); - R.NUSetRot( deg*PI/180 ); + R.NUSetRot( deg*PI/180 ); - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - TAffine& T = TS.vtil[i].T; + TAffine& T = TS.vtil[i].T; - T = R * T; - T.AddXY( -B.L, -B.B ); - } + T = R * T; + T.AddXY( -B.L, -B.B ); + } - w = int(B.R - B.L) + 1; - h = int(B.T - B.B) + 1; + w = int(B.R - B.L) + 1; + h = int(B.T - B.B) + 1; } /* --------------------------------------------------------------- */ @@ -385,15 +385,15 @@ void BlockSet::OrientLayer( int is0, int isN ) // void BlockSet::SetDims() { - dx = scr.crossblocksize; - dy = dx; - dx *= gW; - dy *= gH; - kx = (int)ceil( (double)w / dx ); - ky = (int)ceil( (double)h / dy ); - dx = w / kx; - dy = h / ky; - nb = kx * ky; + dx = scr.crossblocksize; + dy = dx; + dx *= gW; + dy *= gH; + kx = (int)ceil( (double)w / dx ); + ky = (int)ceil( (double)h / dy ); + dx = w / kx; + dy = h / ky; + nb = kx * ky; } /* --------------------------------------------------------------- */ @@ -404,35 +404,35 @@ void BlockSet::SetDims() // void BlockSet::PartitionTiles( int is0, int isN ) { - K.clear(); - K.resize( nb ); + K.clear(); + K.resize( nb ); - int W2 = gW/2, - H2 = gH/2; + int W2 = gW/2, + H2 = gH/2; - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - Point p( W2, H2 ); - int ix, iy; + Point p( W2, H2 ); + int ix, iy; - TS.vtil[i].T.Transform( p ); + TS.vtil[i].T.Transform( p ); - ix = int(p.x / dx); + ix = int(p.x / dx); - if( ix < 0 ) - ix = 0; - else if( ix >= kx ) - ix = kx - 1; + if( ix < 0 ) + ix = 0; + else if( ix >= kx ) + ix = kx - 1; - iy = int(p.y / dy); + iy = int(p.y / dy); - if( iy < 0 ) - iy = 0; - else if( iy >= ky ) - iy = ky - 1; + if( iy < 0 ) + iy = 0; + else if( iy >= ky ) + iy = ky - 1; - K[ix + kx*iy].vID.push_back( i ); - } + K[ix + kx*iy].vID.push_back( i ); + } } /* --------------------------------------------------------------- */ @@ -443,112 +443,112 @@ void BlockSet::PartitionTiles( int is0, int isN ) // void BlockSet::Consolidate() { - if( nb <= 1 ) - return; + if( nb <= 1 ) + return; - vector pc; + vector pc; - int lowcount = - int(scr.crossblocksize * scr.crossblocksize * 0.25), - W2 = gW/2, - H2 = gH/2; + int lowcount = + int(scr.crossblocksize * scr.crossblocksize * 0.25), + W2 = gW/2, + H2 = gH/2; - bool changed; + bool changed; - do { // until no changes + do { // until no changes - changed = false; + changed = false; - // find lowest occupancy + // find lowest occupancy - int cmin = 0, imin; + int cmin = 0, imin; - for( int i = 0; i < nb; ++i ) { + for( int i = 0; i < nb; ++i ) { - int ic = K[i].vID.size(); + int ic = K[i].vID.size(); - if( !ic || ic >= lowcount ) - continue; + if( !ic || ic >= lowcount ) + continue; - if( !cmin || ic < cmin ) { - cmin = ic; - imin = i; - } - } + if( !cmin || ic < cmin ) { + cmin = ic; + imin = i; + } + } - if( !cmin ) - break; + if( !cmin ) + break; - // calc cell centers if not yet done + // calc cell centers if not yet done - if( !pc.size() ) { + if( !pc.size() ) { - pc.resize( nb ); + pc.resize( nb ); - for( int i = 0; i < nb; ++i ) { + for( int i = 0; i < nb; ++i ) { - int iy = i / kx, - ix = i - kx * iy; + int iy = i / kx, + ix = i - kx * iy; - pc[i].x = ix * dx + dx/2; - pc[i].y = iy * dy + dy/2; - } - } + pc[i].x = ix * dx + dx/2; + pc[i].y = iy * dy + dy/2; + } + } - // regroup each of the tiles in imin to nearest 4-neib + // regroup each of the tiles in imin to nearest 4-neib - for( int k = 0; k < cmin; ++k ) { + for( int k = 0; k < cmin; ++k ) { - Point P( W2, H2 ); + Point P( W2, H2 ); - TS.vtil[K[imin].vID[k]].T.Transform( P ); + TS.vtil[K[imin].vID[k]].T.Transform( P ); - double dnear = 0, d; - int iy = imin / kx, - ix = imin - kx * iy, - inear, ii; + double dnear = 0, d; + int iy = imin / kx, + ix = imin - kx * iy, + inear, ii; - if( iy > 0 && K[ii = imin-kx].vID.size() ) { + if( iy > 0 && K[ii = imin-kx].vID.size() ) { - dnear = P.y - pc[ii].y; - inear = ii; - } + dnear = P.y - pc[ii].y; + inear = ii; + } - if( iy < ky-1 && K[ii = imin+kx].vID.size() && - (!dnear || (d = pc[ii].y - P.y) < dnear) ) { + if( iy < ky-1 && K[ii = imin+kx].vID.size() && + (!dnear || (d = pc[ii].y - P.y) < dnear) ) { - dnear = d; - inear = ii; - } + dnear = d; + inear = ii; + } - if( ix > 0 && K[ii = imin-1].vID.size() && - (!dnear || (d = P.x - pc[ii].x) < dnear) ) { + if( ix > 0 && K[ii = imin-1].vID.size() && + (!dnear || (d = P.x - pc[ii].x) < dnear) ) { - dnear = d; - inear = ii; - } + dnear = d; + inear = ii; + } - if( ix < kx-1 && K[ii = imin+1].vID.size() && - (!dnear || (d = pc[ii].x - P.x) < dnear) ) { + if( ix < kx-1 && K[ii = imin+1].vID.size() && + (!dnear || (d = pc[ii].x - P.x) < dnear) ) { - dnear = d; - inear = ii; - } + dnear = d; + inear = ii; + } - if( !dnear ) - break; + if( !dnear ) + break; - // merge + // merge - changed = true; + changed = true; - K[inear].vID.push_back( K[imin].vID[k] ); - } + K[inear].vID.push_back( K[imin].vID[k] ); + } - if( changed ) - K[imin].vID.clear(); + if( changed ) + K[imin].vID.clear(); - } while( changed ); + } while( changed ); } /* --------------------------------------------------------------- */ @@ -559,41 +559,41 @@ void BlockSet::Consolidate() // void BlockSet::ReportBlocks( int z ) { - int ntiles = 0; + int ntiles = 0; - fprintf( flog, "\nZ %d, Array %dx%d, Tiles(i,j):\n", z, kx, ky ); + fprintf( flog, "\nZ %d, Array %dx%d, Tiles(i,j):\n", z, kx, ky ); // Report occupancy - for( int i = 0; i < nb; ++i ) { + for( int i = 0; i < nb; ++i ) { - int iy = i / kx, - ix = i - kx * iy, - ij = K[i].vID.size(); + int iy = i / kx, + ix = i - kx * iy, + ij = K[i].vID.size(); - fprintf( flog, "%d%c", ij, (ix == kx - 1 ? '\n' : '\t') ); - ntiles += ij; - } + fprintf( flog, "%d%c", ij, (ix == kx - 1 ? '\n' : '\t') ); + ntiles += ij; + } - fprintf( flog, "Total = %d\n", ntiles ); + fprintf( flog, "Total = %d\n", ntiles ); // Report block centers - fprintf( flog, "Block centers:\n" ); + fprintf( flog, "Block centers:\n" ); - for( int i = 0; i < nb; ++i ) { + for( int i = 0; i < nb; ++i ) { - int iy = i / kx, - ix = i - kx * iy; + int iy = i / kx, + ix = i - kx * iy; - if( K[i].vID.size() ) { + if( K[i].vID.size() ) { - fprintf( flog, "D%d_%d %d %d\n", - ix, iy, - ix * dx + dx/2, - iy * dy + dy/2 ); - } - } + fprintf( flog, "D%d_%d %d %d\n", + ix, iy, + ix * dx + dx/2, + iy * dy + dy/2 ); + } + } } /* --------------------------------------------------------------- */ @@ -602,11 +602,11 @@ void BlockSet::ReportBlocks( int z ) void BlockSet::CarveIntoBlocks( int is0, int isN ) { - OrientLayer( is0, isN ); - SetDims(); - PartitionTiles( is0, isN ); - Consolidate(); - ReportBlocks( TS.vtil[is0].z ); + OrientLayer( is0, isN ); + SetDims(); + PartitionTiles( is0, isN ); + Consolidate(); + ReportBlocks( TS.vtil[is0].z ); } /* --------------------------------------------------------------- */ @@ -624,39 +624,39 @@ void BlockSet::WriteParams( int za, int zb ) // several tries to get a good match (yes, even if we exceed // blockmaxdz to get those tries). - int zmin = max( zb + 1 - scr.blockmaxdz, gArgs.zmin ); + int zmin = max( zb + 1 - scr.blockmaxdz, gArgs.zmin ); - for( int i = 0; i < nb; ++i ) { + for( int i = 0; i < nb; ++i ) { - int nID; + int nID; - if( nID = K[i].vID.size() ) { + if( nID = K[i].vID.size() ) { - char path[256]; - int iy = i / kx, - ix = i - kx * iy; + char path[256]; + int iy = i / kx, + ix = i - kx * iy; - // make Dx_y folder; - // cross_thisblock will make ThmPair files as needed - sprintf( path, "../%d", za ); - CreateJobsDir( path, ix, iy, za, -1, flog ); + // make Dx_y folder; + // cross_thisblock will make ThmPair files as needed + sprintf( path, "../%d", za ); + CreateJobsDir( path, ix, iy, za, -1, flog ); - // write params file - sprintf( path, "../%d/D%d_%d/blockdat.txt", za, ix, iy ); - FILE *f = FileOpenOrDie( path, "w", flog ); + // write params file + sprintf( path, "../%d/D%d_%d/blockdat.txt", za, ix, iy ); + FILE *f = FileOpenOrDie( path, "w", flog ); - fprintf( f, "scaf=%s\n", gArgs.srcscaf ); + fprintf( f, "scaf=%s\n", gArgs.srcscaf ); - fprintf( f, "ZaZmin=%d,%d\n", za, zmin ); + fprintf( f, "ZaZmin=%d,%d\n", za, zmin ); - // list actual tile-IDs (TS.vtil[].id) - fprintf( f, "nIDs=%d\n", nID ); - for( int j = 0; j < nID; ++j ) - fprintf( f, "%d\n", TS.vtil[K[i].vID[j]].id ); + // list actual tile-IDs (TS.vtil[].id) + fprintf( f, "nIDs=%d\n", nID ); + for( int j = 0; j < nID; ++j ) + fprintf( f, "%d\n", TS.vtil[K[i].vID[j]].id ); - fclose( f ); - } - } + fclose( f ); + } + } } /* --------------------------------------------------------------- */ @@ -665,32 +665,32 @@ void BlockSet::WriteParams( int za, int zb ) static void ForEachLayer() { - int is0, isN, zb; + int is0, isN, zb; // Lowest layer - just get zb - TS.GetLayerLimits( is0 = 0, isN ); + TS.GetLayerLimits( is0 = 0, isN ); - if( isN == -1 ) - return; + if( isN == -1 ) + return; - zb = TS.vtil[is0].z; + zb = TS.vtil[is0].z; // Loop over layers above first - TS.GetLayerLimits( is0 = isN, isN ); + TS.GetLayerLimits( is0 = isN, isN ); - while( isN != -1 ) { + while( isN != -1 ) { - BlockSet BS; - int za = TS.vtil[is0].z; + BlockSet BS; + int za = TS.vtil[is0].z; - BS.CarveIntoBlocks( is0, isN ); - BS.WriteParams( za, zb ); + BS.CarveIntoBlocks( is0, isN ); + BS.WriteParams( za, zb ); - zb = za; - TS.GetLayerLimits( is0 = isN, isN ); - } + zb = za; + TS.GetLayerLimits( is0 = isN, isN ); + } } /* --------------------------------------------------------------- */ @@ -703,60 +703,60 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); - TS.SetLogFile( flog ); + TS.SetLogFile( flog ); - if( !ReadScriptParams( scr, gArgs.script, flog ) ) - exit( 42 ); + if( !ReadScriptParams( scr, gArgs.script, flog ) ) + exit( 42 ); /* ------------- */ /* Read src file */ /* ------------- */ - string idb; + string idb; - IDBFromTemp( idb, "..", flog ); + IDBFromTemp( idb, "..", flog ); - if( idb.empty() ) - exit( 42 ); + if( idb.empty() ) + exit( 42 ); - TS.FillFromRgns( gArgs.srcscaf, idb, gArgs.zmin, gArgs.zmax ); + TS.FillFromRgns( gArgs.srcscaf, idb, gArgs.zmin, gArgs.zmax ); - fprintf( flog, "Got %d images.\n", (int)TS.vtil.size() ); + fprintf( flog, "Got %d images.\n", (int)TS.vtil.size() ); - if( !TS.vtil.size() ) - goto exit; + if( !TS.vtil.size() ) + goto exit; - TS.SetTileDimsFromImageFile(); - TS.GetTileDims( gW, gH ); + TS.SetTileDimsFromImageFile(); + TS.GetTileDims( gW, gH ); - TS.SortAll_z_id(); + TS.SortAll_z_id(); /* ------------- */ /* Driver script */ /* ------------- */ - WriteTestblockFile(); - WriteBSubFile(); - WriteCountdowndirsFile(); - WriteReportFiles(); + WriteTestblockFile(); + WriteBSubFile(); + WriteCountdowndirsFile(); + WriteReportFiles(); /* ----- */ /* Carve */ /* ----- */ - ForEachLayer(); + ForEachLayer(); /* ---- */ /* Done */ /* ---- */ exit: - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_Cross_CarveBlocks/makefile b/1_Cross_CarveBlocks/makefile index 9d94324..18913b0 100644 --- a/1_Cross_CarveBlocks/makefile +++ b/1_Cross_CarveBlocks/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_Cross_LowRes/ScapeMeta.cpp b/1_Cross_LowRes/ScapeMeta.cpp index 4644f0e..2bc1188 100644 --- a/1_Cross_LowRes/ScapeMeta.cpp +++ b/1_Cross_LowRes/ScapeMeta.cpp @@ -15,69 +15,69 @@ static bool ReadLog1( CLog &L, int z ) { - char buf[256]; - sprintf( buf, "scplogs/scp_%d.log", z ); + char buf[256]; + sprintf( buf, "scplogs/scp_%d.log", z ); - if( !DskExists( buf ) ) - return false; + if( !DskExists( buf ) ) + return false; - FILE *f = FileOpenOrDie( buf, "r" ); - CLineScan LS; - bool gotM = false; + FILE *f = FileOpenOrDie( buf, "r" ); + CLineScan LS; + bool gotM = false; - while( LS.Get( f ) > 0 ) { + while( LS.Get( f ) > 0 ) { - if( LS.line[0] != '*' ) - continue; + if( LS.line[0] != '*' ) + continue; - char key = LS.line[1]; + char key = LS.line[1]; - LS.Get( f ); + LS.Get( f ); - if( key == 'M' ) { + if( key == 'M' ) { - CScapeMeta &E = L.M; + CScapeMeta &E = L.M; - sscanf( LS.line, - "%d %d [%lf,%lf,%lf,%lf] %d [%d,%d] [%lf,%lf]", - &E.z, &E.deg, &E.B.L, &E.B.R, &E.B.B, &E.B.T, - &E.scl, &E.ws, &E.hs, &E.x0, &E.y0 ); + sscanf( LS.line, + "%d %d [%lf,%lf,%lf,%lf] %d [%d,%d] [%lf,%lf]", + &E.z, &E.deg, &E.B.L, &E.B.R, &E.B.B, &E.B.T, + &E.scl, &E.ws, &E.hs, &E.x0, &E.y0 ); - gotM = true; - } - else if( key == 'A' ) { + gotM = true; + } + else if( key == 'A' ) { - CScapeMeta &E = L.A; + CScapeMeta &E = L.A; - sscanf( LS.line, - "%d %d [%lf,%lf,%lf,%lf] %d [%d,%d] [%lf,%lf]", - &E.z, &E.deg, &E.B.L, &E.B.R, &E.B.B, &E.B.T, - &E.scl, &E.ws, &E.hs, &E.x0, &E.y0 ); - } - else if( key == 'B' ) { + sscanf( LS.line, + "%d %d [%lf,%lf,%lf,%lf] %d [%d,%d] [%lf,%lf]", + &E.z, &E.deg, &E.B.L, &E.B.R, &E.B.B, &E.B.T, + &E.scl, &E.ws, &E.hs, &E.x0, &E.y0 ); + } + else if( key == 'B' ) { - CScapeMeta &E = L.B; + CScapeMeta &E = L.B; - sscanf( LS.line, - "%d %d [%lf,%lf,%lf,%lf] %d [%d,%d] [%lf,%lf]", - &E.z, &E.deg, &E.B.L, &E.B.R, &E.B.B, &E.B.T, - &E.scl, &E.ws, &E.hs, &E.x0, &E.y0 ); - } - else if( key == 'T' ) { + sscanf( LS.line, + "%d %d [%lf,%lf,%lf,%lf] %d [%d,%d] [%lf,%lf]", + &E.z, &E.deg, &E.B.L, &E.B.R, &E.B.B, &E.B.T, + &E.scl, &E.ws, &E.hs, &E.x0, &E.y0 ); + } + else if( key == 'T' ) { - double *t = L.T.t; + double *t = L.T.t; - sscanf( LS.line + 1, - "%lf,%lf,%lf,%lf,%lf,%lf", - &t[0], &t[1], &t[2], - &t[3], &t[4], &t[5] ); + sscanf( LS.line + 1, + "%lf,%lf,%lf,%lf,%lf,%lf", + &t[0], &t[1], &t[2], + &t[3], &t[4], &t[5] ); - break; - } - } + break; + } + } - fclose( f ); - return gotM; + fclose( f ); + return gotM; } /* --------------------------------------------------------------- */ @@ -86,26 +86,26 @@ static bool ReadLog1( CLog &L, int z ) int ReadLogs( vector &vL, int zmin, int zmax ) { - for( int z = zmin; z <= zmax; ) { + for( int z = zmin; z <= zmax; ) { - CLog L; + CLog L; - L.A.z = -1; + L.A.z = -1; - if( ReadLog1( L, z ) ) { + if( ReadLog1( L, z ) ) { - vL.push_back( L ); + vL.push_back( L ); - if( L.A.z == -1 ) - break; + if( L.A.z == -1 ) + break; - z = L.A.z; - } - else - ++z; - } + z = L.A.z; + } + else + ++z; + } - return vL.size(); + return vL.size(); } diff --git a/1_Cross_LowRes/ScapeMeta.h b/1_Cross_LowRes/ScapeMeta.h index 72f1030..4362eba 100644 --- a/1_Cross_LowRes/ScapeMeta.h +++ b/1_Cross_LowRes/ScapeMeta.h @@ -13,18 +13,18 @@ class CScapeMeta { public: - DBox B; - double x0, y0; - int z, - deg, - scl, - ws, hs; + DBox B; + double x0, y0; + int z, + deg, + scl, + ws, hs; }; class CLog { public: - CScapeMeta M, A, B; - TAffine T; + CScapeMeta M, A, B; + TAffine T; }; /* --------------------------------------------------------------- */ diff --git a/1_Cross_LowRes/cross_lowres.cpp b/1_Cross_LowRes/cross_lowres.cpp index 9e11008..edfcc87 100644 --- a/1_Cross_LowRes/cross_lowres.cpp +++ b/1_Cross_LowRes/cross_lowres.cpp @@ -23,13 +23,13 @@ class CArgs_alnmon { public: - int zmin, - zmax; - bool table; + int zmin, + zmax; + bool table; public: - CArgs_alnmon() : zmin(0), zmax(32768), table(false) {}; + CArgs_alnmon() : zmin(0), zmax(32768), table(false) {}; - void SetCmdLine( int argc, char* argv[] ); + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -52,55 +52,55 @@ void CArgs_alnmon::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "cross_lowres.log", "w" ); + flog = FileOpenOrDie( "cross_lowres.log", "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Assemble stack: %s ", atime ); + fprintf( flog, "Assemble stack: %s ", atime ); // parse command line args - if( argc < 2 ) { - printf( - "Usage: cross_lowres -z=i,j [options].\n" ); - exit( 42 ); - } - - vector vi; - - for( int i = 1; i < argc; ++i ) { - - // echo to log - fprintf( flog, "%s ", argv[i] ); - - if( GetArgList( vi, "-z=", argv[i] ) ) { - - if( 2 == vi.size() ) { - zmin = vi[0]; - zmax = vi[1]; - } - else { - fprintf( flog, - "Bad format in -z [%s].\n", argv[i] ); - exit( 42 ); - } - } - else if( IsArg( "-table", argv[i] ) ) - table = true; - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n\n" ); - fflush( flog ); + if( argc < 2 ) { + printf( + "Usage: cross_lowres -z=i,j [options].\n" ); + exit( 42 ); + } + + vector vi; + + for( int i = 1; i < argc; ++i ) { + + // echo to log + fprintf( flog, "%s ", argv[i] ); + + if( GetArgList( vi, "-z=", argv[i] ) ) { + + if( 2 == vi.size() ) { + zmin = vi[0]; + zmax = vi[1]; + } + else { + fprintf( flog, + "Bad format in -z [%s].\n", argv[i] ); + exit( 42 ); + } + } + else if( IsArg( "-table", argv[i] ) ) + table = true; + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n\n" ); + fflush( flog ); } /* --------------------------------------------------------------- */ @@ -108,46 +108,46 @@ void CArgs_alnmon::SetCmdLine( int argc, char* argv[] ) /* --------------------------------------------------------------- */ static void MakeTAffines( - vector &vT, - const vector &vL ) + vector &vT, + const vector &vL ) { - int nL = vT.size(); + int nL = vT.size(); // T[0] is just indentity, defining global coords. // Create T[1]...T[n] taking image[j] -> image[0]. - for( int ia = 1; ia < nL; ++ia ) { + for( int ia = 1; ia < nL; ++ia ) { - TAffine Taa; - int ib = ia - 1; + TAffine Taa; + int ib = ia - 1; - // Begin by constructing Tba (image[a] -> image[b]) + // Begin by constructing Tba (image[a] -> image[b]) - // A image -> A content - Taa.AddXY( vL[ia].M.x0, vL[ia].M.y0 ); + // A image -> A content + Taa.AddXY( vL[ia].M.x0, vL[ia].M.y0 ); - // Image size -> strip size - Taa.MulXY( (double)vL[ia].M.scl / vL[ib].A.scl ); + // Image size -> strip size + Taa.MulXY( (double)vL[ia].M.scl / vL[ib].A.scl ); - // A content -> A strip - Taa.AddXY( -vL[ib].A.x0, -vL[ib].A.y0 ); + // A content -> A strip + Taa.AddXY( -vL[ib].A.x0, -vL[ib].A.y0 ); - // A strip -> B strip - vT[ia] = vL[ib].T * Taa; + // A strip -> B strip + vT[ia] = vL[ib].T * Taa; - // B strip -> B content - vT[ia].AddXY( vL[ib].B.x0, vL[ib].B.y0 ); + // B strip -> B content + vT[ia].AddXY( vL[ib].B.x0, vL[ib].B.y0 ); - // Strip size -> image size - vT[ia].MulXY( (double)vL[ib].B.scl / vL[ib].M.scl ); + // Strip size -> image size + vT[ia].MulXY( (double)vL[ib].B.scl / vL[ib].M.scl ); - // B content -> B image - vT[ia].AddXY( -vL[ib].M.x0, -vL[ib].M.y0 ); + // B content -> B image + vT[ia].AddXY( -vL[ib].M.x0, -vL[ib].M.y0 ); - // Now convert Tba to global transform T0a - // T0a = T01.T12...Tba. - vT[ia] = vT[ib] * vT[ia]; - } + // Now convert Tba to global transform T0a + // T0a = T01.T12...Tba. + vT[ia] = vT[ib] * vT[ia]; + } } /* --------------------------------------------------------------- */ @@ -155,28 +155,28 @@ static void MakeTAffines( /* --------------------------------------------------------------- */ static void MakeBounds( - DBox &B, - const vector &vL, - const vector &vT ) + DBox &B, + const vector &vL, + const vector &vT ) { - int nL = vT.size(); + int nL = vT.size(); - B.L = BIGD, B.R = -BIGD, - B.B = BIGD, B.T = -BIGD; + B.L = BIGD, B.R = -BIGD, + B.B = BIGD, B.T = -BIGD; - for( int i = 0; i < nL; ++i ) { + for( int i = 0; i < nL; ++i ) { - vector cnr; - Set4Corners( cnr, vL[i].M.ws, vL[i].M.hs ); - vT[i].Transform( cnr ); + vector cnr; + Set4Corners( cnr, vL[i].M.ws, vL[i].M.hs ); + vT[i].Transform( cnr ); - for( int k = 0; k < 4; ++k ) { - B.L = fmin( B.L, cnr[k].x ); - B.R = fmax( B.R, cnr[k].x ); - B.B = fmin( B.B, cnr[k].y ); - B.T = fmax( B.T, cnr[k].y ); - } - } + for( int k = 0; k < 4; ++k ) { + B.L = fmin( B.L, cnr[k].x ); + B.R = fmax( B.R, cnr[k].x ); + B.B = fmin( B.B, cnr[k].y ); + B.T = fmax( B.T, cnr[k].y ); + } + } } /* --------------------------------------------------------------- */ @@ -184,44 +184,44 @@ static void MakeBounds( /* --------------------------------------------------------------- */ static void WriteTrakEM2Layer( - FILE* f, - int &oid, - const CLog &L, - const TAffine &T ) + FILE* f, + int &oid, + const CLog &L, + const TAffine &T ) { // Layer prologue - fprintf( f, - "\t\t\n", - oid++, L.M.z ); + fprintf( f, + "\t\t\n", + oid++, L.M.z ); // Tile - just tile 0 - fprintf( f, - "\t\t\t\n", - oid++, L.M.ws, L.M.hs, - T.t[0], T.t[3], T.t[1], T.t[4], T.t[2], T.t[5], - L.M.z, L.M.z, L.M.ws, L.M.hs ); + fprintf( f, + "\t\t\t\n", + oid++, L.M.ws, L.M.hs, + T.t[0], T.t[3], T.t[1], T.t[4], T.t[2], T.t[5], + L.M.z, L.M.z, L.M.ws, L.M.hs ); // Layer epilogue - fprintf( f, "\t\t\n" ); + fprintf( f, "\t\t\n" ); } /* --------------------------------------------------------------- */ @@ -229,55 +229,55 @@ static void WriteTrakEM2Layer( /* --------------------------------------------------------------- */ static void WriteTrakEM2( - const char *path, - DBox &B, - const vector &vL, - const vector &vT ) + const char *path, + DBox &B, + const vector &vL, + const vector &vT ) { // Open file - FILE *f = FileOpenOrDie( path, "w" ); + FILE *f = FileOpenOrDie( path, "w" ); // Prologue + bounds - int oid = 3; + int oid = 3; - fprintf( f, "\n" ); + fprintf( f, "\n" ); - TrakEM2WriteDTD( f ); + TrakEM2WriteDTD( f ); - fprintf( f, "\n" ); + fprintf( f, "\n" ); - fprintf( f, - "\t\n" ); + fprintf( f, + "\t\n" ); - fprintf( f, - "\t\n", - oid++, B.R - B.L, B.T - B.B ); + fprintf( f, + "\t\n", + oid++, B.R - B.L, B.T - B.B ); // Layers - int nL = vT.size(); + int nL = vT.size(); - for( int i = 0; i < nL; ++i ) - WriteTrakEM2Layer( f, oid, vL[i], vT[i] ); + for( int i = 0; i < nL; ++i ) + WriteTrakEM2Layer( f, oid, vL[i], vT[i] ); // Epilogue - fprintf( f, "\t\n" ); - fprintf( f, "\n" ); - fclose( f ); + fprintf( f, "\t\n" ); + fprintf( f, "\n" ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -288,24 +288,24 @@ static void WriteTrakEM2( // static void Tabulate( const vector &vL, int nL ) { - FILE *f = FileOpenOrDie( "striptable.txt", "w" ); + FILE *f = FileOpenOrDie( "striptable.txt", "w" ); - fprintf( f, "lyr\tA\tt0\tt1\tX\tt3\tt4\tY\n" ); + fprintf( f, "lyr\tA\tt0\tt1\tX\tt3\tt4\tY\n" ); - --nL; + --nL; - for( int ib = 0; ib < nL; ++ib ) { + for( int ib = 0; ib < nL; ++ib ) { - const TAffine &T = vL[ib].T; + const TAffine &T = vL[ib].T; - fprintf( f, "%d\t%f\t" - "%f\t%f\t%f\t%f\t%f\t%f\n", - vL[ib].A.z, T.GetRadians() * 180/PI, - T.t[0], T.t[1], T.t[2], T.t[3], T.t[4], T.t[5] ); - } + fprintf( f, "%d\t%f\t" + "%f\t%f\t%f\t%f\t%f\t%f\n", + vL[ib].A.z, T.GetRadians() * 180/PI, + T.t[0], T.t[1], T.t[2], T.t[3], T.t[4], T.t[5] ); + } - fclose( f ); - exit( 42 ); + fclose( f ); + exit( 42 ); } /* --------------------------------------------------------------- */ @@ -316,30 +316,30 @@ static void BuildStack() { // Get log data - vector vL; - int nL = ReadLogs( vL, gArgs.zmin, gArgs.zmax ); + vector vL; + int nL = ReadLogs( vL, gArgs.zmin, gArgs.zmax ); - if( gArgs.table ) - Tabulate( vL, nL ); + if( gArgs.table ) + Tabulate( vL, nL ); - if( !nL ) - return; + if( !nL ) + return; // Make layer TForms - vector vT( nL ); + vector vT( nL ); - MakeTAffines( vT, vL ); + MakeTAffines( vT, vL ); // Calculate bounds - DBox B; + DBox B; - MakeBounds( B, vL, vT ); + MakeBounds( B, vL, vT ); // Write - WriteTrakEM2( "LowRes.xml", B, vL, vT ); + WriteTrakEM2( "LowRes.xml", B, vL, vT ); } /* --------------------------------------------------------------- */ @@ -352,22 +352,22 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* ----------- */ /* Build stack */ /* ----------- */ - BuildStack(); + BuildStack(); /* ---- */ /* Done */ /* ---- */ - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_Cross_LowRes/makefile b/1_Cross_LowRes/makefile index eaf2232..61c2b51 100644 --- a/1_Cross_LowRes/makefile +++ b/1_Cross_LowRes/makefile @@ -12,8 +12,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_Cross_Scaffold/cross_scaffold.cpp b/1_Cross_Scaffold/cross_scaffold.cpp index d965177..2c5c3bf 100644 --- a/1_Cross_Scaffold/cross_scaffold.cpp +++ b/1_Cross_Scaffold/cross_scaffold.cpp @@ -28,21 +28,21 @@ using namespace ns_pipergns; class CArgs_alnmon { public: - const char *srcmons, - *xml_lowres; - int zmin, - zmax; + const char *srcmons, + *xml_lowres; + int zmin, + zmax; public: - CArgs_alnmon() - { - srcmons = NULL; - xml_lowres = "LowRes.xml"; - zmin = 0; - zmax = 32768; - }; - - void SetCmdLine( int argc, char* argv[] ); + CArgs_alnmon() + { + srcmons = NULL; + xml_lowres = "LowRes.xml"; + zmin = 0; + zmax = 32768; + }; + + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -66,57 +66,57 @@ void CArgs_alnmon::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "cross_scaffold.log", "w" ); + flog = FileOpenOrDie( "cross_scaffold.log", "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Assemble stack: %s ", atime ); + fprintf( flog, "Assemble stack: %s ", atime ); // parse command line args - if( argc < 3 ) { - printf( - "Usage: cross_scaffold srcmons -z=i,j [options].\n" ); - exit( 42 ); - } - - vector vi; - - for( int i = 1; i < argc; ++i ) { - - // echo to log - fprintf( flog, "%s ", argv[i] ); - - if( argv[i][0] != '-' ) - srcmons = argv[i]; - else if( GetArgStr( xml_lowres, "-lowres=", argv[i] ) ) - ; - else if( GetArgList( vi, "-z=", argv[i] ) ) { - - if( 2 == vi.size() ) { - zmin = vi[0]; - zmax = vi[1]; - } - else { - fprintf( flog, - "Bad format in -z [%s].\n", argv[i] ); - exit( 42 ); - } - } - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n\n" ); - fflush( flog ); + if( argc < 3 ) { + printf( + "Usage: cross_scaffold srcmons -z=i,j [options].\n" ); + exit( 42 ); + } + + vector vi; + + for( int i = 1; i < argc; ++i ) { + + // echo to log + fprintf( flog, "%s ", argv[i] ); + + if( argv[i][0] != '-' ) + srcmons = argv[i]; + else if( GetArgStr( xml_lowres, "-lowres=", argv[i] ) ) + ; + else if( GetArgList( vi, "-z=", argv[i] ) ) { + + if( 2 == vi.size() ) { + zmin = vi[0]; + zmax = vi[1]; + } + else { + fprintf( flog, + "Bad format in -z [%s].\n", argv[i] ); + exit( 42 ); + } + } + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n\n" ); + fflush( flog ); } /* --------------------------------------------------------------- */ @@ -125,16 +125,16 @@ void CArgs_alnmon::SetCmdLine( int argc, char* argv[] ) static void LoadTAffines( vector &vT ) { - XML_TKEM xml( gArgs.xml_lowres, flog ); - TiXmlElement* layer = xml.GetFirstLayer(); - int nz = 0; + XML_TKEM xml( gArgs.xml_lowres, flog ); + TiXmlElement* layer = xml.GetFirstLayer(); + int nz = 0; - for( ; layer; layer = layer->NextSiblingElement() ) { + for( ; layer; layer = layer->NextSiblingElement() ) { - TiXmlElement* p = layer->FirstChildElement( "t2_patch" ); + TiXmlElement* p = layer->FirstChildElement( "t2_patch" ); - vT[nz++].ScanTrackEM2( p->Attribute( "transform" ) ); - } + vT[nz++].ScanTrackEM2( p->Attribute( "transform" ) ); + } } /* --------------------------------------------------------------- */ @@ -145,123 +145,123 @@ static void UpdateTAffines() { // Get log data - vector vL; - int nL = ReadLogs( vL, gArgs.zmin, gArgs.zmax ); + vector vL; + int nL = ReadLogs( vL, gArgs.zmin, gArgs.zmax ); - if( !nL ) - return; + if( !nL ) + return; // Get scaled-down image -> 0-image TForms - vector vTs( nL ); + vector vTs( nL ); - LoadTAffines( vTs ); + LoadTAffines( vTs ); // Build whole montage TForms - vector vTm( nL ); + vector vTm( nL ); - for( int ia = 1; ia < nL; ++ia ) { + for( int ia = 1; ia < nL; ++ia ) { - const CScapeMeta &Ma = vL[ia].M; - const CScapeMeta &M0 = vL[0].M; - TAffine R0i, Ra, t, s; + const CScapeMeta &Ma = vL[ia].M; + const CScapeMeta &M0 = vL[0].M; + TAffine R0i, Ra, t, s; - // A-montage -> A-oriented - Ra.NUSetRot( Ma.deg*PI/180 ); + // A-montage -> A-oriented + Ra.NUSetRot( Ma.deg*PI/180 ); - // A-oriented -> A-image (like Scape.cpp) - s.NUSetScl( 1.0/Ma.scl ); - t = s * Ra; - t.AddXY( -Ma.x0, -Ma.y0 ); + // A-oriented -> A-image (like Scape.cpp) + s.NUSetScl( 1.0/Ma.scl ); + t = s * Ra; + t.AddXY( -Ma.x0, -Ma.y0 ); - // A-image -> 0-image - t = vTs[ia] * t; + // A-image -> 0-image + t = vTs[ia] * t; - // 0-image -> 0-image oriented - R0i.InverseOf( vTs[0] ); - t = R0i * t; + // 0-image -> 0-image oriented + R0i.InverseOf( vTs[0] ); + t = R0i * t; - // 0-image oriented -> 0-oriented (reverse Scape.cpp) - t.AddXY( M0.x0, M0.y0 ); - s.NUSetScl( M0.scl ); - t = s * t; + // 0-image oriented -> 0-oriented (reverse Scape.cpp) + t.AddXY( M0.x0, M0.y0 ); + s.NUSetScl( M0.scl ); + t = s * t; - // 0-oriented -> 0-montage - R0i.NUSetRot( -M0.deg*PI/180 ); - vTm[ia] = R0i * t; - } + // 0-oriented -> 0-montage + R0i.NUSetRot( -M0.deg*PI/180 ); + vTm[ia] = R0i * t; + } // Apply - char out[128], buf[2048]; - bool isbin; + char out[128], buf[2048]; + bool isbin; - // create destination + // create destination - isbin = (strstr( FileNamePtr( gArgs.srcmons ), "X_A_BIN" ) - != NULL); + isbin = (strstr( FileNamePtr( gArgs.srcmons ), "X_A_BIN" ) + != NULL); - if( isbin ) - strcpy( out, "X_A_BIN_scaf" ); - else - strcpy( out, "X_A_TXT_scaf" ); + if( isbin ) + strcpy( out, "X_A_BIN_scaf" ); + else + strcpy( out, "X_A_TXT_scaf" ); - DskCreateDir( out, flog ); + DskCreateDir( out, flog ); - // copy data for lowest layer + // copy data for lowest layer - sprintf( buf, "cp %s/*_%d* %s", gArgs.srcmons, gArgs.zmin, out ); - system( buf ); + sprintf( buf, "cp %s/*_%d* %s", gArgs.srcmons, gArgs.zmin, out ); + system( buf ); - // load and modify above layers + // load and modify above layers - for( int z = gArgs.zmin + 1; z <= gArgs.zmax; ++z ) { + for( int z = gArgs.zmin + 1; z <= gArgs.zmax; ++z ) { - Rgns R; - int ib; + Rgns R; + int ib; - if( !R.Init( idb, z, flog ) ) - continue; + if( !R.Init( idb, z, flog ) ) + continue; - if( !R.Load( gArgs.srcmons ) ) - continue; + if( !R.Load( gArgs.srcmons ) ) + continue; - // find TAffine for this z + // find TAffine for this z - for( ib = 0; ib < nL; ++ib ) { + for( ib = 0; ib < nL; ++ib ) { - if( vL[ib].M.z == z ) - break; - } + if( vL[ib].M.z == z ) + break; + } - if( ib >= nL ) - continue; + if( ib >= nL ) + continue; - map::iterator mi, en = R.m.end(); + map::iterator mi, en = R.m.end(); - for( mi = R.m.begin(); mi != en; ) { + for( mi = R.m.begin(); mi != en; ) { - int id = mi->first, - j0 = mi->second, - jlim = (++mi == en ? R.nr : mi->second); + int id = mi->first, + j0 = mi->second, + jlim = (++mi == en ? R.nr : mi->second); - for( int j = j0; j < jlim; ++j ) { + for( int j = j0; j < jlim; ++j ) { - if( !FLAG_ISUSED( R.flag[j] ) ) - continue; + if( !FLAG_ISUSED( R.flag[j] ) ) + continue; - TAffine &T = X_AS_AFF( R.x, j ); + TAffine &T = X_AS_AFF( R.x, j ); - T = vTm[ib] * T; - } - } + T = vTm[ib] * T; + } + } - if( isbin ) - R.SaveBIN( out, true ); - else - R.SaveTXT( out ); - } + if( isbin ) + R.SaveBIN( out, true ); + else + R.SaveTXT( out ); + } } /* --------------------------------------------------------------- */ @@ -274,28 +274,28 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); - IDBFromTemp( idb, "..", flog ); + IDBFromTemp( idb, "..", flog ); - if( idb.empty() ) - exit( 42 ); + if( idb.empty() ) + exit( 42 ); /* ------------- */ /* Update TForms */ /* ------------- */ - UpdateTAffines(); + UpdateTAffines(); /* ---- */ /* Done */ /* ---- */ exit: - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_Cross_Scaffold/makefile b/1_Cross_Scaffold/makefile index 7b17633..fa2cc12 100644 --- a/1_Cross_Scaffold/makefile +++ b/1_Cross_Scaffold/makefile @@ -12,9 +12,9 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_Cross_ThisBlock/bsub.sht b/1_Cross_ThisBlock/bsub.sht index 1262151..3c2bd41 100644 --- a/1_Cross_ThisBlock/bsub.sht +++ b/1_Cross_ThisBlock/bsub.sht @@ -18,28 +18,28 @@ export MRC_TRIM=12 if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi cd .. for lyr in $(seq $1 $last) do - echo $lyr - if [ -d "$lyr" ] - then - cd $lyr - - for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') - do - cd $jb - QSUB_1NODE.sht 7 "x$jb-$lyr" "" 8 "cross_thisblock -script=../../scriptparams.txt" - cd .. - done - - cd .. - fi + echo $lyr + if [ -d "$lyr" ] + then + cd $lyr + + for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') + do + cd $jb + QSUB_1NODE.sht 7 "x$jb-$lyr" "" 8 "cross_thisblock -script=../../scriptparams.txt" + cd .. + done + + cd .. + fi done diff --git a/1_Cross_ThisBlock/cross_thisblock.cpp b/1_Cross_ThisBlock/cross_thisblock.cpp index bae18dc..d081c7e 100644 --- a/1_Cross_ThisBlock/cross_thisblock.cpp +++ b/1_Cross_ThisBlock/cross_thisblock.cpp @@ -40,23 +40,23 @@ using namespace std; class BlkZ { public: - TAffine T; - double R; - int Z, - used; + TAffine T; + double R; + int Z, + used; public: - BlkZ( TAffine T, double R, int Z ) - : T(T), R(R), Z(Z), used(0) {}; + BlkZ( TAffine T, double R, int Z ) + : T(T), R(R), Z(Z), used(0) {}; }; class Pair { public: - double area; - int id, iz; + double area; + int id, iz; public: - Pair() {}; // for resize() - Pair( double area, int id, int iz ) - : area(area), id(id), iz(iz) {}; + Pair() {}; // for resize() + Pair( double area, int id, int iz ) + : area(area), id(id), iz(iz) {}; }; /* --------------------------------------------------------------- */ @@ -66,44 +66,44 @@ class Pair { class CSuperscape { public: - vector vID; - DBox bb; // oriented bounding box - Point Opts; // origin of aligned point list - double x0, y0; // scape corner in oriented system - uint8 *ras; // scape pixels - uint32 ws, hs; // scape dims - int is0, isN; // layer index range - int clbl, rsvd; // 'A' or 'B' + vector vID; + DBox bb; // oriented bounding box + Point Opts; // origin of aligned point list + double x0, y0; // scape corner in oriented system + uint8 *ras; // scape pixels + uint32 ws, hs; // scape dims + int is0, isN; // layer index range + int clbl, rsvd; // 'A' or 'B' public: - CSuperscape() : ras(NULL) {}; + CSuperscape() : ras(NULL) {}; - virtual ~CSuperscape() - {KillRas();}; + virtual ~CSuperscape() + {KillRas();}; - void SetLabel( int clbl ) - {this->clbl = clbl;}; + void SetLabel( int clbl ) + {this->clbl = clbl;}; - void KillRas() - { - if( ras ) { - RasterFree( ras ); - ras = NULL; - } - }; + void KillRas() + { + if( ras ) { + RasterFree( ras ); + ras = NULL; + } + }; - int FindLayerIndices( int next_isN ); - void vID_From_sID(); - void CalcBBox(); + int FindLayerIndices( int next_isN ); + void vID_From_sID(); + void CalcBBox(); - bool MakeRasA(); - bool MakeRasB( const DBox &Abb ); + bool MakeRasA(); + bool MakeRasB( const DBox &Abb ); - void DrawRas(); - bool Load( FILE* flog ); + void DrawRas(); + bool Load( FILE* flog ); - bool MakePoints( vector &v, vector &p ); - void WriteMeta(); + bool MakePoints( vector &v, vector &p ); + void WriteMeta(); }; /* --------------------------------------------------------------- */ @@ -112,12 +112,12 @@ class CSuperscape { class CBlockDat { public: - char scaf[2048]; - int za, zmin; - int ntil; - set sID; + char scaf[2048]; + int za, zmin; + int ntil; + set sID; public: - void ReadFile(); + void ReadFile(); }; /* --------------------------------------------------------------- */ @@ -127,17 +127,17 @@ class CBlockDat { class CArgs_scp { public: - double abctr; - const char *script; - int dbgz; - bool evalalldz, - abdbg; + double abctr; + const char *script; + int dbgz; + bool evalalldz, + abdbg; public: - CArgs_scp() - : abctr(0), script(NULL), - dbgz(-1), evalalldz(false), abdbg(false) {}; + CArgs_scp() + : abctr(0), script(NULL), + dbgz(-1), evalalldz(false), abdbg(false) {}; - void SetCmdLine( int argc, char* argv[] ); + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -151,7 +151,7 @@ static CBlockDat gDat; static CTileSet TS; static FILE* flog = NULL; static int gW = 0, // universal pic dims - gH = 0; + gH = 0; @@ -166,49 +166,49 @@ void CArgs_scp::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "cross_thisblock.log", "w" ); + flog = FileOpenOrDie( "cross_thisblock.log", "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Align this block: %s ", atime ); + fprintf( flog, "Align this block: %s ", atime ); // parse command line args - if( argc < 2 ) { - printf( - "Usage: cross_thisblock -script=scriptpath [options].\n" ); - exit( 42 ); - } - - for( int i = 1; i < argc; ++i ) { - - // echo to log - fprintf( flog, "%s ", argv[i] ); - - if( GetArgStr( script, "-script=", argv[i] ) ) - ; - else if( GetArg( &abctr, "-abctr=%lf", argv[i] ) ) - ; - else if( GetArg( &dbgz, "-abdbg=%d", argv[i] ) ) - abdbg = true; - else if( IsArg( "-evalalldz", argv[i] ) ) - evalalldz = true; - else if( IsArg( "-abdbg", argv[i] ) ) - abdbg = true; - else { - printf( "Did not understand option [%s].\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n" ); - fflush( flog ); + if( argc < 2 ) { + printf( + "Usage: cross_thisblock -script=scriptpath [options].\n" ); + exit( 42 ); + } + + for( int i = 1; i < argc; ++i ) { + + // echo to log + fprintf( flog, "%s ", argv[i] ); + + if( GetArgStr( script, "-script=", argv[i] ) ) + ; + else if( GetArg( &abctr, "-abctr=%lf", argv[i] ) ) + ; + else if( GetArg( &dbgz, "-abdbg=%d", argv[i] ) ) + abdbg = true; + else if( IsArg( "-evalalldz", argv[i] ) ) + evalalldz = true; + else if( IsArg( "-abdbg", argv[i] ) ) + abdbg = true; + else { + printf( "Did not understand option [%s].\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n" ); + fflush( flog ); } /* --------------------------------------------------------------- */ @@ -217,38 +217,38 @@ void CArgs_scp::SetCmdLine( int argc, char* argv[] ) void CBlockDat::ReadFile() { - FILE *f = FileOpenOrDie( "blockdat.txt", "r", flog ); - CLineScan LS; - int item = 0; - - while( LS.Get( f ) > 0 ) { - - if( item == 0 ) { - sscanf( LS.line, "scaf=%s", scaf ); - item = 1; - } - else if( item == 1 ) { - sscanf( LS.line, "ZaZmin=%d,%d", &za, &zmin ); - item = 2; - } - else if( item == 2 ) { - sscanf( LS.line, "nIDs=%d", &ntil ); - item = 3; - } - else { - - for( int i = 0; i < ntil; ++i ) { - - int id; - - sscanf( LS.line, "%d", &id ); - sID.insert( id ); - LS.Get( f ); - } - } - } - - fclose( f ); + FILE *f = FileOpenOrDie( "blockdat.txt", "r", flog ); + CLineScan LS; + int item = 0; + + while( LS.Get( f ) > 0 ) { + + if( item == 0 ) { + sscanf( LS.line, "scaf=%s", scaf ); + item = 1; + } + else if( item == 1 ) { + sscanf( LS.line, "ZaZmin=%d,%d", &za, &zmin ); + item = 2; + } + else if( item == 2 ) { + sscanf( LS.line, "nIDs=%d", &ntil ); + item = 3; + } + else { + + for( int i = 0; i < ntil; ++i ) { + + int id; + + sscanf( LS.line, "%d", &id ); + sID.insert( id ); + LS.Get( f ); + } + } + } + + fclose( f ); } /* --------------------------------------------------------------- */ @@ -261,8 +261,8 @@ void CBlockDat::ReadFile() // int CSuperscape::FindLayerIndices( int next_isN ) { - TS.GetLayerLimitsR( is0, isN = next_isN ); - return is0; + TS.GetLayerLimitsR( is0, isN = next_isN ); + return is0; } /* --------------------------------------------------------------- */ @@ -277,20 +277,20 @@ int CSuperscape::FindLayerIndices( int next_isN ) // void CSuperscape::vID_From_sID() { - int n = 0; + int n = 0; - vID.resize( gDat.ntil ); + vID.resize( gDat.ntil ); - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - if( gDat.sID.find( TS.vtil[i].id ) != gDat.sID.end() ) { + if( gDat.sID.find( TS.vtil[i].id ) != gDat.sID.end() ) { - vID[n++] = i; + vID[n++] = i; - if( n == gDat.ntil ) - break; - } - } + if( n == gDat.ntil ) + break; + } + } } /* --------------------------------------------------------------- */ @@ -299,27 +299,27 @@ void CSuperscape::vID_From_sID() void CSuperscape::CalcBBox() { - bb.L = BIGD; - bb.R = -BIGD; - bb.B = BIGD; - bb.T = -BIGD; - - vector cnr; - Set4Corners( cnr, gW, gH ); - - for( int i = 0; i < gDat.ntil; ++i ) { - - vector c( 4 ); - memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); - TS.vtil[vID[i]].T.Transform( c ); - - for( int k = 0; k < 4; ++k ) { - bb.L = fmin( bb.L, c[k].x ); - bb.R = fmax( bb.R, c[k].x ); - bb.B = fmin( bb.B, c[k].y ); - bb.T = fmax( bb.T, c[k].y ); - } - } + bb.L = BIGD; + bb.R = -BIGD; + bb.B = BIGD; + bb.T = -BIGD; + + vector cnr; + Set4Corners( cnr, gW, gH ); + + for( int i = 0; i < gDat.ntil; ++i ) { + + vector c( 4 ); + memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); + TS.vtil[vID[i]].T.Transform( c ); + + for( int k = 0; k < 4; ++k ) { + bb.L = fmin( bb.L, c[k].x ); + bb.R = fmax( bb.R, c[k].x ); + bb.B = fmin( bb.B, c[k].y ); + bb.T = fmax( bb.T, c[k].y ); + } + } } /* --------------------------------------------------------------- */ @@ -328,12 +328,12 @@ void CSuperscape::CalcBBox() bool CSuperscape::MakeRasA() { - ras = TS.Scape( ws, hs, x0, y0, - vID, inv_scl, 1, 0, - scr.legendremaxorder, scr.rendersdevcnts, - scr.maskoutresin, scr.blockslots ); + ras = TS.Scape( ws, hs, x0, y0, + vID, inv_scl, 1, 0, + scr.legendremaxorder, scr.rendersdevcnts, + scr.maskoutresin, scr.blockslots ); - return (ras != NULL); + return (ras != NULL); } /* --------------------------------------------------------------- */ @@ -342,45 +342,45 @@ bool CSuperscape::MakeRasA() bool CSuperscape::MakeRasB( const DBox &Abb ) { - vector vid; - int W2 = gW/2, H2 = gH/2; + vector vid; + int W2 = gW/2, H2 = gH/2; - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - const CUTile& U = TS.vtil[i]; + const CUTile& U = TS.vtil[i]; - Point p( W2, H2 ); - U.T.Transform( p ); + Point p( W2, H2 ); + U.T.Transform( p ); - if( p.x >= Abb.L && p.x <= Abb.R && - p.y >= Abb.B && p.y <= Abb.T ) { + if( p.x >= Abb.L && p.x <= Abb.R && + p.y >= Abb.B && p.y <= Abb.T ) { - vid.push_back( i ); - } - } + vid.push_back( i ); + } + } - if( vid.size() < 0.05 * gDat.ntil ) { + if( vid.size() < 0.05 * gDat.ntil ) { - fprintf( flog, "Low B tile count [%ld] for z=%d.\n", - vid.size(), TS.vtil[is0].z ); + fprintf( flog, "Low B tile count [%ld] for z=%d.\n", + vid.size(), TS.vtil[is0].z ); - return false; - } + return false; + } - ras = TS.Scape( ws, hs, x0, y0, - vid, inv_scl, 1, 0, - scr.legendremaxorder, scr.rendersdevcnts, - scr.maskoutresin, scr.blockslots ); + ras = TS.Scape( ws, hs, x0, y0, + vid, inv_scl, 1, 0, + scr.legendremaxorder, scr.rendersdevcnts, + scr.maskoutresin, scr.blockslots ); - if( !ras ) { + if( !ras ) { - fprintf( flog, "Empty B scape for z=%d.\n", - TS.vtil[is0].z ); + fprintf( flog, "Empty B scape for z=%d.\n", + TS.vtil[is0].z ); - return false; - } + return false; + } - return (ras != NULL); + return (ras != NULL); } /* --------------------------------------------------------------- */ @@ -389,11 +389,11 @@ bool CSuperscape::MakeRasB( const DBox &Abb ) void CSuperscape::DrawRas() { - if( ras ) { - char name[128]; - sprintf( name, "Ras_%c_%d.png", clbl, TS.vtil[is0].z ); - Raster8ToPng8( name, ras, ws, hs ); - } + if( ras ) { + char name[128]; + sprintf( name, "Ras_%c_%d.png", clbl, TS.vtil[is0].z ); + Raster8ToPng8( name, ras, ws, hs ); + } } /* --------------------------------------------------------------- */ @@ -402,14 +402,14 @@ void CSuperscape::DrawRas() bool CSuperscape::Load( FILE* flog ) { - char name[128]; + char name[128]; - sprintf( name, "Ras_%c_%d.png", clbl, TS.vtil[is0].z ); - x0 = y0 = 0.0; + sprintf( name, "Ras_%c_%d.png", clbl, TS.vtil[is0].z ); + x0 = y0 = 0.0; - ras = Raster8FromAny( name, ws, hs, flog ); + ras = Raster8FromAny( name, ws, hs, flog ); - return (ras != NULL); + return (ras != NULL); } /* --------------------------------------------------------------- */ @@ -420,50 +420,50 @@ bool CSuperscape::MakePoints( vector &v, vector &p ) { // collect point and value lists - int np = ws * hs, ok = true; + int np = ws * hs, ok = true; - v.clear(); - p.clear(); + v.clear(); + p.clear(); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( ras[i] ) { + if( ras[i] ) { - int iy = i / ws, - ix = i - ws * iy; + int iy = i / ws, + ix = i - ws * iy; - v.push_back( ras[i] ); - p.push_back( Point( ix, iy ) ); - } - } + v.push_back( ras[i] ); + p.push_back( Point( ix, iy ) ); + } + } - if( !(np = p.size()) ) { - ok = false; - goto exit; - } + if( !(np = p.size()) ) { + ok = false; + goto exit; + } // get points origin and translate to zero - DBox ptsbb; + DBox ptsbb; - BBoxFromPoints( ptsbb, p ); - Opts = Point( ptsbb.L, ptsbb.B ); + BBoxFromPoints( ptsbb, p ); + Opts = Point( ptsbb.L, ptsbb.B ); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - p[i].x -= Opts.x; - p[i].y -= Opts.y; - } + p[i].x -= Opts.x; + p[i].y -= Opts.y; + } // normalize values - if( !Normalize( v ) ) - ok = false; + if( !Normalize( v ) ) + ok = false; exit: - KillRas(); + KillRas(); - return ok; + return ok; } /* --------------------------------------------------------------- */ @@ -472,12 +472,12 @@ bool CSuperscape::MakePoints( vector &v, vector &p ) void CSuperscape::WriteMeta() { - fprintf( flog, - "*%c: z scl [ws,hs] [x0,y0]\n", clbl ); + fprintf( flog, + "*%c: z scl [ws,hs] [x0,y0]\n", clbl ); - fprintf( flog, - "%d %d [%d,%d] [%f,%f]\n", - TS.vtil[is0].z, scr.crossscale, ws, hs, x0, y0 ); + fprintf( flog, + "%d %d [%d,%d] [%f,%f]\n", + TS.vtil[is0].z, scr.crossscale, ws, hs, x0, y0 ); } /* --------------------------------------------------------------- */ @@ -485,31 +485,31 @@ void CSuperscape::WriteMeta() /* --------------------------------------------------------------- */ static void FindPairs( - const vector &vZ, - vector > &P, - const CSuperscape &A, - const CSuperscape &B ) + const vector &vZ, + vector > &P, + const CSuperscape &A, + const CSuperscape &B ) { - int iz = vZ.size() - 1; - TAffine Tm = vZ[iz].T; + int iz = vZ.size() - 1; + TAffine Tm = vZ[iz].T; - for( int ia = 0; ia < gDat.ntil; ++ia ) { + for( int ia = 0; ia < gDat.ntil; ++ia ) { - int aid = A.vID[ia]; - vector &p = P[ia]; - TAffine Ta = Tm * TS.vtil[aid].T; + int aid = A.vID[ia]; + vector &p = P[ia]; + TAffine Ta = Tm * TS.vtil[aid].T; - for( int bid = B.is0; bid < B.isN; ++bid ) { + for( int bid = B.is0; bid < B.isN; ++bid ) { - TAffine Tab; - Tab.FromAToB( Ta, TS.vtil[bid].T ); + TAffine Tab; + Tab.FromAToB( Ta, TS.vtil[bid].T ); - double area = TS.ABOlap( aid, bid, &Tab ); + double area = TS.ABOlap( aid, bid, &Tab ); - if( area >= kPairMinOlap ) - p.push_back( Pair( area, bid, iz ) ); - } - } + if( area >= kPairMinOlap ) + p.push_back( Pair( area, bid, iz ) ); + } + } } /* --------------------------------------------------------------- */ @@ -519,129 +519,129 @@ static void FindPairs( // Return true if changes made. // static bool ThisBZ( - vector &vZ, - vector > &P, - const CSuperscape &A, - ThmRec &thm, - int &next_isN ) + vector &vZ, + vector > &P, + const CSuperscape &A, + ThmRec &thm, + int &next_isN ) { - clock_t t0 = StartTiming(); - CSuperscape B; - CThmScan S; - CorRec best; + clock_t t0 = StartTiming(); + CSuperscape B; + CThmScan S; + CorRec best; - fprintf( flog, "\n--- Start B layer ----\n" ); + fprintf( flog, "\n--- Start B layer ----\n" ); - B.SetLabel( 'B' ); - next_isN = B.FindLayerIndices( next_isN ); + B.SetLabel( 'B' ); + next_isN = B.FindLayerIndices( next_isN ); - if( gArgs.abdbg ) { - while( next_isN != -1 && TS.vtil[B.is0].z != gArgs.dbgz ) - next_isN = B.FindLayerIndices( next_isN ); - } + if( gArgs.abdbg ) { + while( next_isN != -1 && TS.vtil[B.is0].z != gArgs.dbgz ) + next_isN = B.FindLayerIndices( next_isN ); + } - if( next_isN == -1 ) { - fprintf( flog, "$$$ Exhausted B layers $$$\n" ); - return false; - } + if( next_isN == -1 ) { + fprintf( flog, "$$$ Exhausted B layers $$$\n" ); + return false; + } - if( !B.MakeRasB( A.bb ) ) - return false; + if( !B.MakeRasB( A.bb ) ) + return false; - B.DrawRas(); + B.DrawRas(); - if( !B.MakePoints( thm.bv, thm.bp ) ) { - fprintf( flog, "No B points for z=%d.\n", TS.vtil[B.is0].z ); - return false; - } + if( !B.MakePoints( thm.bv, thm.bp ) ) { + fprintf( flog, "No B points for z=%d.\n", TS.vtil[B.is0].z ); + return false; + } - B.WriteMeta(); - t0 = StopTiming( flog, "MakeRasB", t0 ); + B.WriteMeta(); + t0 = StopTiming( flog, "MakeRasB", t0 ); - thm.ftc.clear(); - thm.reqArea = int(kPairMinOlap * A.ws * A.hs); - thm.olap1D = 4; - thm.scl = 1; + thm.ftc.clear(); + thm.reqArea = int(kPairMinOlap * A.ws * A.hs); + thm.olap1D = 4; + thm.scl = 1; - int Ox = int(A.x0 - B.x0), - Oy = int(A.y0 - B.y0), - Rx = int((1.0 - scr.blockxyconf) * A.ws), - Ry = int((1.0 - scr.blockxyconf) * A.hs); + int Ox = int(A.x0 - B.x0), + Oy = int(A.y0 - B.y0), + Rx = int((1.0 - scr.blockxyconf) * A.ws), + Ry = int((1.0 - scr.blockxyconf) * A.hs); - S.Initialize( flog, best ); - S.SetRThresh( scr.blockmincorr ); - S.SetNbMaxHt( 0.99 ); - S.SetSweepConstXY( false ); - S.SetSweepPretweak( true ); - S.SetSweepNThreads( scr.blockslots ); - S.SetUseCorrR( true ); - S.SetDisc( Ox, Oy, Rx, Ry ); + S.Initialize( flog, best ); + S.SetRThresh( scr.blockmincorr ); + S.SetNbMaxHt( 0.99 ); + S.SetSweepConstXY( false ); + S.SetSweepPretweak( true ); + S.SetSweepNThreads( scr.blockslots ); + S.SetUseCorrR( true ); + S.SetDisc( Ox, Oy, Rx, Ry ); - if( gArgs.abdbg ) { + if( gArgs.abdbg ) { - S.Pretweaks( 0, gArgs.abctr, thm ); - dbgCor = true; - S.RFromAngle( best, gArgs.abctr, thm ); - } - else { + S.Pretweaks( 0, gArgs.abctr, thm ); + dbgCor = true; + S.RFromAngle( best, gArgs.abctr, thm ); + } + else { - S.Pretweaks( 0, 0, thm ); + S.Pretweaks( 0, 0, thm ); - if( !S.DenovoBestAngle( best, - 0, scr.blocksweepspan / 2, scr.blocksweepstep, - thm, false ) ) { + if( !S.DenovoBestAngle( best, + 0, scr.blocksweepspan / 2, scr.blocksweepstep, + thm, false ) ) { - fprintf( flog, "Low corr [%g] for z=%d.\n", - best.R, TS.vtil[B.is0].z ); + fprintf( flog, "Low corr [%g] for z=%d.\n", + best.R, TS.vtil[B.is0].z ); - return false; - } + return false; + } - Point Aorigin = A.Opts; + Point Aorigin = A.Opts; - best.T.Apply_R_Part( Aorigin ); + best.T.Apply_R_Part( Aorigin ); - best.X += B.Opts.x - Aorigin.x; - best.Y += B.Opts.y - Aorigin.y; + best.X += B.Opts.x - Aorigin.x; + best.Y += B.Opts.y - Aorigin.y; - best.T.SetXY( best.X, best.Y ); + best.T.SetXY( best.X, best.Y ); - fprintf( flog, "*T: [0,1,2,3,4,5] (block-block)\n" ); - fprintf( flog, "[%f,%f,%f,%f,%f,%f]\n", - best.T.t[0], best.T.t[1], best.T.t[2], - best.T.t[3], best.T.t[4], best.T.t[5] ); - } + fprintf( flog, "*T: [0,1,2,3,4,5] (block-block)\n" ); + fprintf( flog, "[%f,%f,%f,%f,%f,%f]\n", + best.T.t[0], best.T.t[1], best.T.t[2], + best.T.t[3], best.T.t[4], best.T.t[5] ); + } - t0 = StopTiming( flog, "Corr", t0 ); + t0 = StopTiming( flog, "Corr", t0 ); - if( gArgs.abdbg ) - return false; + if( gArgs.abdbg ) + return false; // Build: montage -> montage transform - TAffine s, t; + TAffine s, t; - // A montage -> A block image - s.NUSetScl( inv_scl ); - s.AddXY( -A.x0, -A.y0 ); + // A montage -> A block image + s.NUSetScl( inv_scl ); + s.AddXY( -A.x0, -A.y0 ); - // A block image -> B block image - t = best.T * s; + // A block image -> B block image + t = best.T * s; - // B block image -> B montage - t.AddXY( B.x0, B.y0 ); - s.NUSetScl( scr.crossscale ); - best.T = s * t; + // B block image -> B montage + t.AddXY( B.x0, B.y0 ); + s.NUSetScl( scr.crossscale ); + best.T = s * t; // Append to list - vZ.push_back( BlkZ( best.T, best.R, TS.vtil[B.is0].z ) ); + vZ.push_back( BlkZ( best.T, best.R, TS.vtil[B.is0].z ) ); // Accumulate pairs - FindPairs( vZ, P, A, B ); + FindPairs( vZ, P, A, B ); - return true; + return true; } /* --------------------------------------------------------------- */ @@ -653,12 +653,12 @@ class CSort_R_Dec { // Nearest tissue to head of list if close to best R. // Otherwise simply order by R. public: - const vector &vZ; - bool zeroPrime; + const vector &vZ; + bool zeroPrime; public: - CSort_R_Dec( const vector &vZ ); - bool operator() ( const Pair &I, const Pair &J ); - bool IsPrime( const Pair &P ); + CSort_R_Dec( const vector &vZ ); + bool operator() ( const Pair &I, const Pair &J ); + bool IsPrime( const Pair &P ); }; @@ -666,18 +666,18 @@ CSort_R_Dec::CSort_R_Dec( const vector &vZ ) : vZ(vZ) { // Who's the best? - double Rbest = -1; - int nz = vZ.size(); + double Rbest = -1; + int nz = vZ.size(); - for( int i = 0; i < nz; ++i ) { + for( int i = 0; i < nz; ++i ) { - if( vZ[i].R > Rbest ) - Rbest = vZ[i].R; - } + if( vZ[i].R > Rbest ) + Rbest = vZ[i].R; + } // Layer-0 goes to head if better than 90% of best - zeroPrime = (vZ[0].R >= Rbest * 0.90); + zeroPrime = (vZ[0].R >= Rbest * 0.90); } @@ -685,25 +685,25 @@ CSort_R_Dec::CSort_R_Dec( const vector &vZ ) : vZ(vZ) // bool CSort_R_Dec::operator() ( const Pair &I, const Pair &J ) { - if( zeroPrime ) { + if( zeroPrime ) { - if( !I.iz ) { + if( !I.iz ) { - if( J.iz ) - return true; - } - else if( !J.iz ) - return false; - } + if( J.iz ) + return true; + } + else if( !J.iz ) + return false; + } - return (vZ[I.iz].R > vZ[J.iz].R); + return (vZ[I.iz].R > vZ[J.iz].R); } bool CSort_R_Dec::IsPrime( const Pair &P ) { - return (!P.iz && zeroPrime) - || (vZ[P.iz].R >= scr.blocknomcorr); + return (!P.iz && zeroPrime) + || (vZ[P.iz].R >= scr.blocknomcorr); } /* --------------------------------------------------------------- */ @@ -715,51 +715,51 @@ bool CSort_R_Dec::IsPrime( const Pair &P ) // and including the lower quality tissue (scdry filled in). // static double BlockCoverage( - double &scdry, - const vector &vZ, - vector > &P ) + double &scdry, + const vector &vZ, + vector > &P ) { - double prime = 0; + double prime = 0; - scdry = 0; + scdry = 0; - CSort_R_Dec sorter( vZ ); + CSort_R_Dec sorter( vZ ); - for( int ia = 0; ia < gDat.ntil; ++ia ) { + for( int ia = 0; ia < gDat.ntil; ++ia ) { - vector &p = P[ia]; - double sum = 0.0; - int iblast = -1, nb = p.size(); + vector &p = P[ia]; + double sum = 0.0; + int iblast = -1, nb = p.size(); - sort( p.begin(), p.end(), sorter ); + sort( p.begin(), p.end(), sorter ); - // first use only best (prime) + // first use only best (prime) - for( int ib = 0; ib < nb; ++ib ) { + for( int ib = 0; ib < nb; ++ib ) { - if( sorter.IsPrime( p[ib] ) ) - sum += p[iblast = ib].area; - else - break; - } + if( sorter.IsPrime( p[ib] ) ) + sum += p[iblast = ib].area; + else + break; + } - if( sum >= kTileMinCvrg ) { - ++prime; - ++scdry; - } - else { // try adding lesser quality (scdry) + if( sum >= kTileMinCvrg ) { + ++prime; + ++scdry; + } + else { // try adding lesser quality (scdry) - for( int ib = iblast + 1; ib < nb; ++ib ) - sum += p[ib].area; + for( int ib = iblast + 1; ib < nb; ++ib ) + sum += p[ib].area; - if( sum >= kTileMinCvrg ) - ++scdry; - } - } + if( sum >= kTileMinCvrg ) + ++scdry; + } + } - scdry /= gDat.ntil; + scdry /= gDat.ntil; - return prime / gDat.ntil; + return prime / gDat.ntil; } /* --------------------------------------------------------------- */ @@ -770,16 +770,16 @@ static double BlockCoverage( // static double ZSeen( const vector &vZ ) { - double nseen = vZ.size(); + double nseen = vZ.size(); // do at least two - if( nseen < 2 ) - return 0.0; + if( nseen < 2 ) + return 0.0; // actual fraction - const vector &vU = TS.vtil; + const vector &vU = TS.vtil; - return (nseen / (vU[vU.size()-1].z - vU[0].z)); + return (nseen / (vU[vU.size()-1].z - vU[0].z)); } /* --------------------------------------------------------------- */ @@ -787,49 +787,49 @@ static double ZSeen( const vector &vZ ) /* --------------------------------------------------------------- */ static void KeepBest( - vector &vZ, - vector > &P ) + vector &vZ, + vector > &P ) { - for( int ia = 0; ia < gDat.ntil; ++ia ) { + for( int ia = 0; ia < gDat.ntil; ++ia ) { - vector &p = P[ia]; - double sum = 0.0; - int nb = p.size(), - ng = 0, // count good b-tiles - nz = 0; // count z's used + vector &p = P[ia]; + double sum = 0.0; + int nb = p.size(), + ng = 0, // count good b-tiles + nz = 0; // count z's used - // cover a-tile with highest quality, - // but include at least blockreqdz layers + // cover a-tile with highest quality, + // but include at least blockreqdz layers - do { + do { - if( ng >= nb ) - break; + if( ng >= nb ) + break; - int curz = p[ng].iz; + int curz = p[ng].iz; - ++nz; + ++nz; - // add in all b-tiles at curz + // add in all b-tiles at curz - for( int ib = ng; ib < nb; ++ib ) { + for( int ib = ng; ib < nb; ++ib ) { - if( p[ib].iz != curz ) - break; + if( p[ib].iz != curz ) + break; - sum += p[ib].area; - ++ng; + sum += p[ib].area; + ++ng; - vZ[curz].used = 1; - } + vZ[curz].used = 1; + } - } while( sum < kTileNomCvrg || nz < scr.blockreqdz ); + } while( sum < kTileNomCvrg || nz < scr.blockreqdz ); - // kill the rest + // kill the rest - if( ng < nb ) - p.resize( ng ); - } + if( ng < nb ) + p.resize( ng ); + } } /* --------------------------------------------------------------- */ @@ -840,83 +840,83 @@ static void KeepBest( // of images described by (P). // static void WriteMakeFile( - const CSuperscape &A, - const vector &vZ, - const vector > &P ) + const CSuperscape &A, + const vector &vZ, + const vector > &P ) { char ptsbuf[32], - logbuf[32]; - FILE *f; - int nz = vZ.size(), nused = 0; + logbuf[32]; + FILE *f; + int nz = vZ.size(), nused = 0; - for( int i = 0; i < nz; ++i ) - nused += vZ[i].used; + for( int i = 0; i < nz; ++i ) + nused += vZ[i].used; - if( !nused ) { - fprintf( flog, "FAIL: No tiles matched.\n" ); - return; - } + if( !nused ) { + fprintf( flog, "FAIL: No tiles matched.\n" ); + return; + } // open the file - f = FileOpenOrDie( "make.down", "w", flog ); + f = FileOpenOrDie( "make.down", "w", flog ); // write 'all' targets line - fprintf( f, "all: " ); + fprintf( f, "all: " ); - for( int ia = 0; ia < gDat.ntil; ++ia ) { + for( int ia = 0; ia < gDat.ntil; ++ia ) { - const CUTile& a = TS.vtil[A.vID[ia]]; - const vector &p = P[ia]; - int nb = p.size(); + const CUTile& a = TS.vtil[A.vID[ia]]; + const vector &p = P[ia]; + int nb = p.size(); - for( int ib = 0; ib < nb; ++ib ) { + for( int ib = 0; ib < nb; ++ib ) { - const CUTile& b = TS.vtil[p[ib].id]; + const CUTile& b = TS.vtil[p[ib].id]; - fprintf( f, "%d/%d.%d.map.tif ", a.id, b.z, b.id ); - } - } + fprintf( f, "%d/%d.%d.map.tif ", a.id, b.z, b.id ); + } + } - fprintf( f, "\n\n" ); + fprintf( f, "\n\n" ); // Write each 'target: dependencies' line // and each 'rule' line - const char *option_nf = (scr.usingfoldmasks ? "" : " -nf"); + const char *option_nf = (scr.usingfoldmasks ? "" : " -nf"); - for( int ia = 0; ia < gDat.ntil; ++ia ) { + for( int ia = 0; ia < gDat.ntil; ++ia ) { - const CUTile& a = TS.vtil[A.vID[ia]]; - const vector &p = P[ia]; - int nb = p.size(); + const CUTile& a = TS.vtil[A.vID[ia]]; + const vector &p = P[ia]; + int nb = p.size(); - for( int ib = 0; ib < nb; ++ib ) { + for( int ib = 0; ib < nb; ++ib ) { - const CUTile& b = TS.vtil[p[ib].id]; - TAffine T; + const CUTile& b = TS.vtil[p[ib].id]; + TAffine T; - fprintf( f, - "%d/%d.%d.map.tif:\n", - a.id, b.z, b.id ); + fprintf( f, + "%d/%d.%d.map.tif:\n", + a.id, b.z, b.id ); - T = vZ[p[ib].iz].T * a.T; - T.FromAToB( T, b.T ); + T = vZ[p[ib].iz].T * a.T; + T.FromAToB( T, b.T ); - fprintf( f, - "\tptest >>%s 2>%s" - " %d.%d^%d.%d" - " -Tab=%f,%f,%f,%f,%f,%f%s ${EXTRA}\n\n", - NamePtsFile( ptsbuf, a.z, b.z ), - NameLogFile( logbuf, a.z, a.id, b.z, b.id ), - a.z, a.id, b.z, b.id, - T.t[0], T.t[1], T.t[2], T.t[3], T.t[4], T.t[5], - option_nf ); - } - } + fprintf( f, + "\tptest >>%s 2>%s" + " %d.%d^%d.%d" + " -Tab=%f,%f,%f,%f,%f,%f%s ${EXTRA}\n\n", + NamePtsFile( ptsbuf, a.z, b.z ), + NameLogFile( logbuf, a.z, a.id, b.z, b.id ), + a.z, a.id, b.z, b.id, + T.t[0], T.t[1], T.t[2], T.t[3], T.t[4], T.t[5], + option_nf ); + } + } - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -925,19 +925,19 @@ static void WriteMakeFile( static void WriteThumbFiles( const vector &vZ ) { - int nz = vZ.size(); + int nz = vZ.size(); - for( int iz = 0; iz < nz; ++iz ) { + for( int iz = 0; iz < nz; ++iz ) { - if( !vZ[iz].used ) - continue; + if( !vZ[iz].used ) + continue; - char name[128]; - sprintf( name, "ThmPair_%d^%d.txt", gDat.za, vZ[iz].Z ); - FILE *f = FileOpenOrDie( name, "w", flog ); - WriteThmPairHdr( f ); - fclose( f ); - } + char name[128]; + sprintf( name, "ThmPair_%d^%d.txt", gDat.za, vZ[iz].Z ); + FILE *f = FileOpenOrDie( name, "w", flog ); + WriteThmPairHdr( f ); + fclose( f ); + } } /* --------------------------------------------------------------- */ @@ -999,79 +999,79 @@ static void WriteThumbFiles( const vector &vZ ) // static void LayerLoop() { - clock_t t0 = StartTiming(); - vector vZ; - vector > P( gDat.ntil ); - CSuperscape A; - ThmRec thm; - int next_isN; + clock_t t0 = StartTiming(); + vector vZ; + vector > P( gDat.ntil ); + CSuperscape A; + ThmRec thm; + int next_isN; - fprintf( flog, "\n--- Start A layer ----\n" ); + fprintf( flog, "\n--- Start A layer ----\n" ); - A.SetLabel( 'A' ); - next_isN = A.FindLayerIndices( TS.vtil.size() ); - A.vID_From_sID(); - A.CalcBBox(); - A.MakeRasA(); - A.DrawRas(); - A.MakePoints( thm.av, thm.ap ); - A.WriteMeta(); - t0 = StopTiming( flog, "MakeRasA", t0 ); + A.SetLabel( 'A' ); + next_isN = A.FindLayerIndices( TS.vtil.size() ); + A.vID_From_sID(); + A.CalcBBox(); + A.MakeRasA(); + A.DrawRas(); + A.MakePoints( thm.av, thm.ap ); + A.WriteMeta(); + t0 = StopTiming( flog, "MakeRasA", t0 ); - double prime = 0.0, scdry = 0.0; + double prime = 0.0, scdry = 0.0; - for(;;) { + for(;;) { - // align B-block and pair tiles + // align B-block and pair tiles - int changed = ThisBZ( vZ, P, A, thm, next_isN ); + int changed = ThisBZ( vZ, P, A, thm, next_isN ); - // any changes to survey? + // any changes to survey? - if( gArgs.abdbg ) - return; + if( gArgs.abdbg ) + return; - if( next_isN == -1 ) - break; + if( next_isN == -1 ) + break; - if( !changed ) - continue; + if( !changed ) + continue; - // survey the coverage + // survey the coverage - prime = BlockCoverage( scdry, vZ, P ); + prime = BlockCoverage( scdry, vZ, P ); - fprintf( flog, "Block coverage prime %.2f scdry %.2f Z %d\n", - prime, scdry, vZ[vZ.size()-1].Z ); + fprintf( flog, "Block coverage prime %.2f scdry %.2f Z %d\n", + prime, scdry, vZ[vZ.size()-1].Z ); - // force measurement of all layers + // force measurement of all layers - if( gArgs.evalalldz ) - continue; + if( gArgs.evalalldz ) + continue; - // force measurement of at least blockreqdz layers + // force measurement of at least blockreqdz layers - if( vZ.size() < scr.blockreqdz ) - continue; + if( vZ.size() < scr.blockreqdz ) + continue; - // done if satisfied now, or if unlikely to get better + // done if satisfied now, or if unlikely to get better - if( (prime >= scr.blocknomcoverage) || - (scdry >= scr.blocknomcoverage && ZSeen( vZ ) >= 0.50) ) { + if( (prime >= scr.blocknomcoverage) || + (scdry >= scr.blocknomcoverage && ZSeen( vZ ) >= 0.50) ) { - break; - } - } + break; + } + } - fprintf( flog, - "Final coverage prime %.2f scdry %.2f ntiles %d\n", - prime, scdry, gDat.ntil ); + fprintf( flog, + "Final coverage prime %.2f scdry %.2f ntiles %d\n", + prime, scdry, gDat.ntil ); - fprintf( flog, "\n--- Write Files ----\n" ); + fprintf( flog, "\n--- Write Files ----\n" ); - KeepBest( vZ, P ); - WriteMakeFile( A, vZ, P ); - WriteThumbFiles( vZ ); + KeepBest( vZ, P ); + WriteMakeFile( A, vZ, P ); + WriteThumbFiles( vZ ); } /* --------------------------------------------------------------- */ @@ -1080,85 +1080,85 @@ static void LayerLoop() int main( int argc, char* argv[] ) { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); /* ------------------ */ /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); - TS.SetLogFile( flog ); + TS.SetLogFile( flog ); - if( !ReadScriptParams( scr, gArgs.script, flog ) ) - exit( 42 ); + if( !ReadScriptParams( scr, gArgs.script, flog ) ) + exit( 42 ); - if( scr.blockreqdz < 1 ) - scr.blockreqdz == 1; - else if( scr.blockreqdz > scr.blockmaxdz ) - scr.blockreqdz = scr.blockmaxdz; + if( scr.blockreqdz < 1 ) + scr.blockreqdz == 1; + else if( scr.blockreqdz > scr.blockmaxdz ) + scr.blockreqdz = scr.blockmaxdz; - inv_scl = 1.0 / scr.crossscale; + inv_scl = 1.0 / scr.crossscale; /* --------------- */ /* Read block data */ /* --------------- */ - gDat.ReadFile(); + gDat.ReadFile(); - if( gArgs.abdbg ) { + if( gArgs.abdbg ) { - if( gArgs.dbgz == -1 ) - gArgs.dbgz = gDat.za - 1; + if( gArgs.dbgz == -1 ) + gArgs.dbgz = gDat.za - 1; - gDat.zmin = gArgs.dbgz; - } + gDat.zmin = gArgs.dbgz; + } /* ---------------- */ /* Read source data */ /* ---------------- */ - string idb; + string idb; - IDBFromTemp( idb, "../..", flog ); + IDBFromTemp( idb, "../..", flog ); - if( idb.empty() ) - exit( 42 ); + if( idb.empty() ) + exit( 42 ); - TS.FillFromRgns( gDat.scaf, idb, gDat.zmin, gDat.za ); + TS.FillFromRgns( gDat.scaf, idb, gDat.zmin, gDat.za ); - fprintf( flog, "Got %d images.\n", (int)TS.vtil.size() ); + fprintf( flog, "Got %d images.\n", (int)TS.vtil.size() ); - if( !TS.vtil.size() ) - goto exit; + if( !TS.vtil.size() ) + goto exit; - TS.SetTileDimsFromImageFile(); - TS.GetTileDims( gW, gH ); + TS.SetTileDimsFromImageFile(); + TS.GetTileDims( gW, gH ); - t0 = StopTiming( flog, "ReadFile", t0 ); + t0 = StopTiming( flog, "ReadFile", t0 ); /* ------------- */ /* Sort by layer */ /* ------------- */ - TS.SortAll_z(); + TS.SortAll_z(); /* ----- */ /* Stuff */ /* ----- */ - LayerLoop(); + LayerLoop(); /* ---- */ /* Done */ /* ---- */ exit: - fprintf( flog, "\n" ); - VMStats( flog ); - fclose( flog ); + fprintf( flog, "\n" ); + VMStats( flog ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_Cross_ThisBlock/makefile b/1_Cross_ThisBlock/makefile index 660999c..7ff4612 100644 --- a/1_Cross_ThisBlock/makefile +++ b/1_Cross_ThisBlock/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_Cross_TopScripts/cross_topscripts.cpp b/1_Cross_TopScripts/cross_topscripts.cpp index 56644b0..e62656c 100644 --- a/1_Cross_TopScripts/cross_topscripts.cpp +++ b/1_Cross_TopScripts/cross_topscripts.cpp @@ -25,22 +25,22 @@ class CArgs_cross { public: - char srcmons[2048]; - const char *script; - int zmin, - zmax; + char srcmons[2048]; + const char *script; + int zmin, + zmax; public: - CArgs_cross() - { - script = NULL; - zmin = 0; - zmax = 32768; + CArgs_cross() + { + script = NULL; + zmin = 0; + zmax = 32768; - strcpy( srcmons, "X_A_BIN_mons" ); - }; + strcpy( srcmons, "X_A_BIN_mons" ); + }; - void SetCmdLine( int argc, char* argv[] ); + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -66,70 +66,70 @@ void CArgs_cross::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "cross_topscripts.log", "w" ); + flog = FileOpenOrDie( "cross_topscripts.log", "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Make scapeops scripts: %s ", atime ); + fprintf( flog, "Make scapeops scripts: %s ", atime ); // parse command line args - if( argc < 4 ) { - printf( - "Usage: cross_topscripts srcmons" - " -script=scriptpath -z=i,j.\n" ); - exit( 42 ); - } + if( argc < 4 ) { + printf( + "Usage: cross_topscripts srcmons" + " -script=scriptpath -z=i,j.\n" ); + exit( 42 ); + } - vector vi; + vector vi; - for( int i = 1; i < argc; ++i ) { + for( int i = 1; i < argc; ++i ) { - const char *_outdir; + const char *_outdir; - // echo to log - fprintf( flog, "%s ", argv[i] ); + // echo to log + fprintf( flog, "%s ", argv[i] ); - if( argv[i][0] != '-' ) - DskAbsPath( srcmons, sizeof(srcmons), argv[i], flog ); - else if( GetArgStr( script, "-script=", argv[i] ) ) - ; - else if( GetArgList( vi, "-z=", argv[i] ) ) { + if( argv[i][0] != '-' ) + DskAbsPath( srcmons, sizeof(srcmons), argv[i], flog ); + else if( GetArgStr( script, "-script=", argv[i] ) ) + ; + else if( GetArgList( vi, "-z=", argv[i] ) ) { - if( 2 == vi.size() ) { - zmin = vi[0]; - zmax = vi[1]; - } - else { - fprintf( flog, - "Bad format in -z [%s].\n", argv[i] ); - exit( 42 ); - } - } - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - exit( 42 ); - } - } + if( 2 == vi.size() ) { + zmin = vi[0]; + zmax = vi[1]; + } + else { + fprintf( flog, + "Bad format in -z [%s].\n", argv[i] ); + exit( 42 ); + } + } + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + exit( 42 ); + } + } - fprintf( flog, "\n\n" ); + fprintf( flog, "\n\n" ); - if( !DskExists( srcmons ) ) { + if( !DskExists( srcmons ) ) { - fprintf( flog, - "Can't find [%s].\n" - "(Did you run gathermons.sht yet?)\n", srcmons ); + fprintf( flog, + "Can't find [%s].\n" + "(Did you run gathermons.sht yet?)\n", srcmons ); - exit( 42 ); - } + exit( 42 ); + } - fflush( flog ); + fflush( flog ); } /* --------------------------------------------------------------- */ @@ -138,34 +138,34 @@ void CArgs_cross::SetCmdLine( int argc, char* argv[] ) static void GetZList( vector &zlist ) { - const char *name = FileNamePtr( gArgs.srcmons ); - char path[2048]; + const char *name = FileNamePtr( gArgs.srcmons ); + char path[2048]; - if( strstr( name, "X_A_BIN" ) ) { + if( strstr( name, "X_A_BIN" ) ) { - for( int z = gArgs.zmin; z <= gArgs.zmax; ++z ) { + for( int z = gArgs.zmin; z <= gArgs.zmax; ++z ) { - sprintf( path, "%s/X_A_%d.bin", gArgs.srcmons, z ); + sprintf( path, "%s/X_A_%d.bin", gArgs.srcmons, z ); - if( DskExists( path ) ) - zlist.push_back( z ); - } - } - else if( strstr( name, "X_A_TXT" ) ) { + if( DskExists( path ) ) + zlist.push_back( z ); + } + } + else if( strstr( name, "X_A_TXT" ) ) { - for( int z = gArgs.zmin; z <= gArgs.zmax; ++z ) { + for( int z = gArgs.zmin; z <= gArgs.zmax; ++z ) { - sprintf( path, "%s/X_A_%d.txt", gArgs.srcmons, z ); + sprintf( path, "%s/X_A_%d.txt", gArgs.srcmons, z ); - if( DskExists( path ) ) - zlist.push_back( z ); - } - } - else { - fprintf( flog, - "Unsupported montage folder type [%s].\n", gArgs.srcmons ); - exit( 42 ); - } + if( DskExists( path ) ) + zlist.push_back( z ); + } + } + else { + fprintf( flog, + "Unsupported montage folder type [%s].\n", gArgs.srcmons ); + exit( 42 ); + } } /* --------------------------------------------------------------- */ @@ -175,7 +175,7 @@ static void GetZList( vector &zlist ) static void CreateTopDir() { // create top subdir - DskCreateDir( gtopdir, flog ); + DskCreateDir( gtopdir, flog ); } /* --------------------------------------------------------------- */ @@ -186,89 +186,89 @@ static void WriteSubscapes( vector &zlist ) { // compose common argument string - char sopt[2048]; + char sopt[2048]; - sprintf( sopt, - "'%s' -script=%s -idb=%s -mb", - gArgs.srcmons, gArgs.script, idb.c_str() ); + sprintf( sopt, + "'%s' -script=%s -idb=%s -mb", + gArgs.srcmons, gArgs.script, idb.c_str() ); // open file - char path[2048]; - FILE *f; + char path[2048]; + FILE *f; - sprintf( path, "%s/subscapes.sht", gtopdir ); - f = FileOpenOrDie( path, "w", flog ); + sprintf( path, "%s/subscapes.sht", gtopdir ); + f = FileOpenOrDie( path, "w", flog ); // header - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# First step in cross-layer alignment.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > scapeops srcmons -script=scriptpath -idb=idbpath [options]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Required:\n" ); - fprintf( f, "# srcmons\t\t\t\t;collected independent montages\n" ); - fprintf( f, "# -script=scriptpath\t;alignment pipeline params file\n" ); - fprintf( f, "# -idb=idbpath\t\t\t;path to idb directory\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Scapeops does montage drawing and/or strip aligning as follows:\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# If drawing a montage...\n" ); - fprintf( f, "#\n" ); - fprintf( f, "#\t-mb -zb=%%d\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# If aligning strips...\n" ); - fprintf( f, "#\n" ); - fprintf( f, "#\t-ab -za=%%d -zb=%%d\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Options:\n" ); - fprintf( f, "# -mb\t\t\t;make montage for layer zb\n" ); - fprintf( f, "# -ab\t\t\t;align layer za to zb\n" ); - fprintf( f, "# -za\t\t\t;layer za used only with -ab option\n" ); - fprintf( f, "# -zb\t\t\t;required layer zb\n" ); - fprintf( f, "# -abdbg\t\t;make diagnostic strip images and exit\n" ); - fprintf( f, "# -abdbgfull\t;make diagnostic full images and exit\n" ); - fprintf( f, "# -abctr=0\t\t;debug at this a-to-b angle\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Create output subdirs\n" ); - fprintf( f, "mkdir -p strips\n" ); - fprintf( f, "mkdir -p montages\n" ); - fprintf( f, "mkdir -p scplogs\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Submit layer pairs\n" ); + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# First step in cross-layer alignment.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > scapeops srcmons -script=scriptpath -idb=idbpath [options]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Required:\n" ); + fprintf( f, "# srcmons\t\t\t\t;collected independent montages\n" ); + fprintf( f, "# -script=scriptpath\t;alignment pipeline params file\n" ); + fprintf( f, "# -idb=idbpath\t\t\t;path to idb directory\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Scapeops does montage drawing and/or strip aligning as follows:\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# If drawing a montage...\n" ); + fprintf( f, "#\n" ); + fprintf( f, "#\t-mb -zb=%%d\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# If aligning strips...\n" ); + fprintf( f, "#\n" ); + fprintf( f, "#\t-ab -za=%%d -zb=%%d\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Options:\n" ); + fprintf( f, "# -mb\t\t\t;make montage for layer zb\n" ); + fprintf( f, "# -ab\t\t\t;align layer za to zb\n" ); + fprintf( f, "# -za\t\t\t;layer za used only with -ab option\n" ); + fprintf( f, "# -zb\t\t\t;required layer zb\n" ); + fprintf( f, "# -abdbg\t\t;make diagnostic strip images and exit\n" ); + fprintf( f, "# -abdbgfull\t;make diagnostic full images and exit\n" ); + fprintf( f, "# -abctr=0\t\t;debug at this a-to-b angle\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Create output subdirs\n" ); + fprintf( f, "mkdir -p strips\n" ); + fprintf( f, "mkdir -p montages\n" ); + fprintf( f, "mkdir -p scplogs\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Submit layer pairs\n" ); // write all but last layer - int nz = zlist.size(); + int nz = zlist.size(); - for( int iz = 1; iz < nz; ++iz ) { + for( int iz = 1; iz < nz; ++iz ) { - fprintf( f, - "QSUB_1NODE.sht 5 \"sc-%d\" \"-j y -o out.txt\" %d" - " \"scapeops %s -ab -za=%d -zb=%d\"\n", - zlist[iz - 1], scr.stripslots, - sopt, zlist[iz], zlist[iz - 1] ); - } + fprintf( f, + "QSUB_1NODE.sht 5 \"sc-%d\" \"-j y -o out.txt\" %d" + " \"scapeops %s -ab -za=%d -zb=%d\"\n", + zlist[iz - 1], scr.stripslots, + sopt, zlist[iz], zlist[iz - 1] ); + } // last layer - fprintf( f, "\n" ); - fprintf( f, "# Just montage last layer\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Just montage last layer\n" ); - fprintf( f, - "QSUB_1NODE.sht 6 \"sc-%d\" \"-j y -o out.txt\" %d" - " \"scapeops %s -zb=%d\"\n", - zlist[nz - 1], scr.stripslots, - sopt, zlist[nz - 1] ); + fprintf( f, + "QSUB_1NODE.sht 6 \"sc-%d\" \"-j y -o out.txt\" %d" + " \"scapeops %s -zb=%d\"\n", + zlist[nz - 1], scr.stripslots, + sopt, zlist[nz - 1] ); - fprintf( f, "\n" ); + fprintf( f, "\n" ); - fclose( f ); - FileScriptPerms( path ); + fclose( f ); + FileScriptPerms( path ); } /* --------------------------------------------------------------- */ @@ -277,39 +277,39 @@ static void WriteSubscapes( vector &zlist ) static void WriteLowresgo() { - char path[2048]; - FILE *f; - - sprintf( path, "%s/lowresgo.sht", gtopdir ); - f = FileOpenOrDie( path, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Second step in cross-layer alignment.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Collects output from scapeops into 'LowRes.xml' stack\n" ); - fprintf( f, "# having one reduced scale montage per layer.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# You must subsequently view and edit LowRes.xml using TrakEM2.\n" ); - fprintf( f, "# Correct mistakes using 'Align with Manual Landmarks' feature\n" ); - fprintf( f, "# and then Save result with the same name.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > cross_lowres -z=i,j [options]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Required:\n" ); - fprintf( f, "# -z=i,j\t\t;assemble layers in range z=[i..j]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Options:\n" ); - fprintf( f, "# -table\t\t;write debugging striptable.txt and exit\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "cross_lowres -z=%d,%d\n", - gArgs.zmin, gArgs.zmax ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( path ); + char path[2048]; + FILE *f; + + sprintf( path, "%s/lowresgo.sht", gtopdir ); + f = FileOpenOrDie( path, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Second step in cross-layer alignment.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Collects output from scapeops into 'LowRes.xml' stack\n" ); + fprintf( f, "# having one reduced scale montage per layer.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# You must subsequently view and edit LowRes.xml using TrakEM2.\n" ); + fprintf( f, "# Correct mistakes using 'Align with Manual Landmarks' feature\n" ); + fprintf( f, "# and then Save result with the same name.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > cross_lowres -z=i,j [options]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Required:\n" ); + fprintf( f, "# -z=i,j\t\t;assemble layers in range z=[i..j]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Options:\n" ); + fprintf( f, "# -table\t\t;write debugging striptable.txt and exit\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "cross_lowres -z=%d,%d\n", + gArgs.zmin, gArgs.zmax ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( path ); } /* --------------------------------------------------------------- */ @@ -318,40 +318,40 @@ static void WriteLowresgo() static void WriteScafgo() { - char path[2048]; - FILE *f; - - sprintf( path, "%s/scafgo.sht", gtopdir ); - f = FileOpenOrDie( path, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Third step in cross-layer alignment.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Apply the coarse layer-layer tforms from 'LowRes.xml' to the\n" ); - fprintf( f, "# individual tiles in srcmons. The new coarsely aligned stack\n" ); - fprintf( f, "# will be created in cross_wkspc and will be named X_A_BIN_scaf\n" ); - fprintf( f, "# or X_A_TXT_scaf following the type of srcmons. The scaffold\n" ); - fprintf( f, "# serves both as the input for the block-block alignment, and\n" ); - fprintf( f, "# as the starting guess for the final LSQ alignment.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > cross_scaffold srcmons -z=i,j [options]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Required:\n" ); - fprintf( f, "# srcmons\t\t\t\t;collected independent montages\n" ); - fprintf( f, "# -z=i,j\t\t\t\t;align layers in range z=[i..j]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Options:\n" ); - fprintf( f, "# -lowres=LowRes.xml\t;alternate coarse alignment reference\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "cross_scaffold %s -z=%d,%d\n", - gArgs.srcmons, gArgs.zmin, gArgs.zmax ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( path ); + char path[2048]; + FILE *f; + + sprintf( path, "%s/scafgo.sht", gtopdir ); + f = FileOpenOrDie( path, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Third step in cross-layer alignment.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Apply the coarse layer-layer tforms from 'LowRes.xml' to the\n" ); + fprintf( f, "# individual tiles in srcmons. The new coarsely aligned stack\n" ); + fprintf( f, "# will be created in cross_wkspc and will be named X_A_BIN_scaf\n" ); + fprintf( f, "# or X_A_TXT_scaf following the type of srcmons. The scaffold\n" ); + fprintf( f, "# serves both as the input for the block-block alignment, and\n" ); + fprintf( f, "# as the starting guess for the final LSQ alignment.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > cross_scaffold srcmons -z=i,j [options]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Required:\n" ); + fprintf( f, "# srcmons\t\t\t\t;collected independent montages\n" ); + fprintf( f, "# -z=i,j\t\t\t\t;align layers in range z=[i..j]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Options:\n" ); + fprintf( f, "# -lowres=LowRes.xml\t;alternate coarse alignment reference\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "cross_scaffold %s -z=%d,%d\n", + gArgs.srcmons, gArgs.zmin, gArgs.zmax ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( path ); } /* --------------------------------------------------------------- */ @@ -360,14 +360,14 @@ static void WriteScafgo() static char* BuildScafPath( char srcscaf[2048] ) { - DskAbsPath( srcscaf, 2048, gtopdir, flog ); + DskAbsPath( srcscaf, 2048, gtopdir, flog ); - if( strstr( FileNamePtr( gArgs.srcmons ), "X_A_BIN" ) ) - strcat( srcscaf, "/X_A_BIN_scaf" ); - else - strcat( srcscaf, "/X_A_TXT_scaf" ); + if( strstr( FileNamePtr( gArgs.srcmons ), "X_A_BIN" ) ) + strcat( srcscaf, "/X_A_BIN_scaf" ); + else + strcat( srcscaf, "/X_A_TXT_scaf" ); - return srcscaf; + return srcscaf; } /* --------------------------------------------------------------- */ @@ -376,36 +376,36 @@ static char* BuildScafPath( char srcscaf[2048] ) static void WriteCarvego() { - char path[2048], srcscaf[2048]; - FILE *f; - - sprintf( path, "%s/carvego.sht", gtopdir ); - f = FileOpenOrDie( path, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Fourth step in cross-layer alignment.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Carve each scaffold layer into blocks of size crossblocksize\n" ); - fprintf( f, "# and create new script 'bsub.sht' to distribute block-block\n" ); - fprintf( f, "# alignment jobs to cluster.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > cross_carveblocks srcscaf -script=scriptpath -z=i,j\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Required:\n" ); - fprintf( f, "# srcscaf\t\t\t\t;scaffold created by scafgo.sht\n" ); - fprintf( f, "# -script=scriptpath\t;alignment pipeline params file\n" ); - fprintf( f, "# -z=i,j\t\t\t\t;align layers in range z=[i..j]\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "cross_carveblocks %s -script=%s -z=%d,%d\n", - BuildScafPath( srcscaf ), gArgs.script, - gArgs.zmin, gArgs.zmax ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( path ); + char path[2048], srcscaf[2048]; + FILE *f; + + sprintf( path, "%s/carvego.sht", gtopdir ); + f = FileOpenOrDie( path, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Fourth step in cross-layer alignment.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Carve each scaffold layer into blocks of size crossblocksize\n" ); + fprintf( f, "# and create new script 'bsub.sht' to distribute block-block\n" ); + fprintf( f, "# alignment jobs to cluster.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > cross_carveblocks srcscaf -script=scriptpath -z=i,j\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Required:\n" ); + fprintf( f, "# srcscaf\t\t\t\t;scaffold created by scafgo.sht\n" ); + fprintf( f, "# -script=scriptpath\t;alignment pipeline params file\n" ); + fprintf( f, "# -z=i,j\t\t\t\t;align layers in range z=[i..j]\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "cross_carveblocks %s -script=%s -z=%d,%d\n", + BuildScafPath( srcscaf ), gArgs.script, + gArgs.zmin, gArgs.zmax ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( path ); } /* --------------------------------------------------------------- */ @@ -414,53 +414,53 @@ static void WriteCarvego() int main( int argc, char* argv[] ) { - vector zlist; + vector zlist; /* ------------------ */ /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); - IDBFromTemp( idb, ".", flog ); + IDBFromTemp( idb, ".", flog ); - if( idb.empty() ) - exit( 42 ); + if( idb.empty() ) + exit( 42 ); - if( !ReadScriptParams( scr, gArgs.script, flog ) ) - exit( 42 ); + if( !ReadScriptParams( scr, gArgs.script, flog ) ) + exit( 42 ); /* ---------------- */ /* Read source data */ /* ---------------- */ - GetZList( zlist ); + GetZList( zlist ); - if( zlist.size() < 2 ) { - fprintf( flog, "Fewer than 2 layers -- do nothing.\n" ); - goto exit; - } + if( zlist.size() < 2 ) { + fprintf( flog, "Fewer than 2 layers -- do nothing.\n" ); + goto exit; + } /* -------------- */ /* Create content */ /* -------------- */ - CreateTopDir(); + CreateTopDir(); - WriteSubscapes( zlist ); - WriteLowresgo(); - WriteScafgo(); - WriteCarvego(); + WriteSubscapes( zlist ); + WriteLowresgo(); + WriteScafgo(); + WriteCarvego(); /* ---- */ /* Done */ /* ---- */ exit: - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_Cross_TopScripts/makefile b/1_Cross_TopScripts/makefile index 1edf1b9..1879a94 100644 --- a/1_Cross_TopScripts/makefile +++ b/1_Cross_TopScripts/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_DMesh/ApproximateMatch.cpp b/1_DMesh/ApproximateMatch.cpp index 2099e03..f00673a 100644 --- a/1_DMesh/ApproximateMatch.cpp +++ b/1_DMesh/ApproximateMatch.cpp @@ -5,92 +5,92 @@ /* - Notes - ----- - matchparams.txt cases out most parameters to allow separate - treatment for same and cross layer. - - Here we seek a composite transform: Trgd * Tdfm * Tpretwk. - - File params PRETWEAK and TWEAKS determine whether Tpretwk - is different from unity. PRETWEAK enables small amounts of - distortion to be automatically added to boost signal iff - no solution > RTRSH is found otherwise. TWEAKS is applied - after a solution is found, to optimize the starting point - for subsequent mesh phase. - - Tdfm is hierarchically set by separating it from the initial - Tab, but can be overridden by file params {SCALE, XSCALE, - YSCALE, SKEW}. These are overridden if provided on command - line. All that is overridden if command line -Tdfm given. - - The primary job of this function, though, is to seek a - refinement of the initial tform Tab. Several strategies - (modes) are available to accommodate user's assessment - of Tab initial accuracy. - - MODE=N (small neighborhood search) is used when the Tab are - already roughly known from a prior alignment. Here, file param - LIMXY is used as the search radius within the correlation image, - and the simple maximum R peak criterion is used. If -CTR= is - given on the command line then that angle is used instead of - that from Tab. This forces greater angle consistency in a block. - - MODE=M (N + zero angle) is really the same as N mode with - -CTR=0, but the command line -CTR=0 can be omitted for - convenience. This is appropriate for montaging to force - greater angle consistency. - - In all other modes where an angle sweep is used, correlation - peak determination uses F mode. This convolves the correlation - image with a peak enhancing (LOG + I) filter, and peak hunting - requires that no F-value be higher than NBMXHT * F-peak within - a specified guard zone of a putative F-peak. - - Sweeping in MODE=Y (dynamic angle hunting) is used when little - is known about the angle to begin with. As best angles are found - within a local block of tiles they are tabulated so that a median - of these can be taken as the starting guess for subsequent tile - pairs. At the start of a block when there are too few entries - to get a consensus, a denovo guess is made from Tab or given - -CTR= angle. The range of angles explored is cased out as - HFANGDN for the denovo phase and HFANGPR for the prior angles - phase, which can be set much narrower than the former. - - MODE=C (center angle search) is used when the approximate - angle is already known but still benefits from a refining - sweep centered upon that estimate. Here, the central angle - can either be implicit in the Tab of the idb, overridden - by the command line Tab, or given explicitly as -CTR=. - - MODE=Z (zero angle search) is really the same as C mode, but - the angle used is identically zero and need not be specified - as a parameter. This is appropriate for denovo montaging when - the stage coordinates are of unknown quality. If the stage - coordinates are trustworthy then N or M mode is preferred. - - If the inital Tab is believed close, then the overlapping areas - of the images can be determined from Tab. The FFT operations - are sped up linearly vs the image area. Moreover, correlation - peak hunting can be foiled by noise, so making smaller areas - increases robustness. We crop the images using Tab, but guided - by file param XYCONF which is a confidence value in range [0,1]. - Zero signifies no confidence in Tab and the images are not - cropped. If the value is one, the overlap rectangles derived - from Tab are used without modification, while intermediate - confidence values add some margin to the rectangles to avoid - excluding the peak. - - All correlation work is done at reduced scale THMDEC (2^N). - This increases speed and can squeeze out fine detail which - is often less reliably correlated than larger features. The - final result is double-checked at full scale and if consistent - with THMDEC scale, full scale coordinates are used. - - In angle sweep modes, file param LIMXY (if non-zero) is used - to constrain solutions to a disc of that size. It is often - better to reject an uncertain result to avoid introducing - stresses in later pipeline stages. + Notes + ----- + matchparams.txt cases out most parameters to allow separate + treatment for same and cross layer. + + Here we seek a composite transform: Trgd * Tdfm * Tpretwk. + + File params PRETWEAK and TWEAKS determine whether Tpretwk + is different from unity. PRETWEAK enables small amounts of + distortion to be automatically added to boost signal iff + no solution > RTRSH is found otherwise. TWEAKS is applied + after a solution is found, to optimize the starting point + for subsequent mesh phase. + + Tdfm is hierarchically set by separating it from the initial + Tab, but can be overridden by file params {SCALE, XSCALE, + YSCALE, SKEW}. These are overridden if provided on command + line. All that is overridden if command line -Tdfm given. + + The primary job of this function, though, is to seek a + refinement of the initial tform Tab. Several strategies + (modes) are available to accommodate user's assessment + of Tab initial accuracy. + + MODE=N (small neighborhood search) is used when the Tab are + already roughly known from a prior alignment. Here, file param + LIMXY is used as the search radius within the correlation image, + and the simple maximum R peak criterion is used. If -CTR= is + given on the command line then that angle is used instead of + that from Tab. This forces greater angle consistency in a block. + + MODE=M (N + zero angle) is really the same as N mode with + -CTR=0, but the command line -CTR=0 can be omitted for + convenience. This is appropriate for montaging to force + greater angle consistency. + + In all other modes where an angle sweep is used, correlation + peak determination uses F mode. This convolves the correlation + image with a peak enhancing (LOG + I) filter, and peak hunting + requires that no F-value be higher than NBMXHT * F-peak within + a specified guard zone of a putative F-peak. + + Sweeping in MODE=Y (dynamic angle hunting) is used when little + is known about the angle to begin with. As best angles are found + within a local block of tiles they are tabulated so that a median + of these can be taken as the starting guess for subsequent tile + pairs. At the start of a block when there are too few entries + to get a consensus, a denovo guess is made from Tab or given + -CTR= angle. The range of angles explored is cased out as + HFANGDN for the denovo phase and HFANGPR for the prior angles + phase, which can be set much narrower than the former. + + MODE=C (center angle search) is used when the approximate + angle is already known but still benefits from a refining + sweep centered upon that estimate. Here, the central angle + can either be implicit in the Tab of the idb, overridden + by the command line Tab, or given explicitly as -CTR=. + + MODE=Z (zero angle search) is really the same as C mode, but + the angle used is identically zero and need not be specified + as a parameter. This is appropriate for denovo montaging when + the stage coordinates are of unknown quality. If the stage + coordinates are trustworthy then N or M mode is preferred. + + If the inital Tab is believed close, then the overlapping areas + of the images can be determined from Tab. The FFT operations + are sped up linearly vs the image area. Moreover, correlation + peak hunting can be foiled by noise, so making smaller areas + increases robustness. We crop the images using Tab, but guided + by file param XYCONF which is a confidence value in range [0,1]. + Zero signifies no confidence in Tab and the images are not + cropped. If the value is one, the overlap rectangles derived + from Tab are used without modification, while intermediate + confidence values add some margin to the rectangles to avoid + excluding the peak. + + All correlation work is done at reduced scale THMDEC (2^N). + This increases speed and can squeeze out fine detail which + is often less reliably correlated than larger features. The + final result is double-checked at full scale and if consistent + with THMDEC scale, full scale coordinates are used. + + In angle sweep modes, file param LIMXY (if non-zero) is used + to constrain solutions to a disc of that size. It is often + better to reject an uncertain result to avoid introducing + stresses in later pipeline stages. /* @@ -113,84 +113,84 @@ // See notes in ApproximateMatch.cpp. // bool ApproximateMatch( - vector &guesses, - const PixPair &px, - const ConnRegion &acr, - const ConnRegion &bcr, - FILE* flog ) + vector &guesses, + const PixPair &px, + const ConnRegion &acr, + const ConnRegion &bcr, + FILE* flog ) { - CThmUtil U( GBL.A, acr.id, GBL.B, bcr.id, px, - GBL.Tab, GBL.ctx.OLAP2D, flog ); + CThmUtil U( GBL.A, acr.id, GBL.B, bcr.id, px, + GBL.Tab, GBL.ctx.OLAP2D, flog ); - U.SetParams( - GBL.ctx.HFANGDN, GBL.ctx.HFANGPR, GBL.ctx.RTRSH, - GBL.ctx.OLAP1D, GBL.ctx.MODE, GBL.ctx.LIMXY, - GBL.mch.WTHMPR ); + U.SetParams( + GBL.ctx.HFANGDN, GBL.ctx.HFANGPR, GBL.ctx.RTRSH, + GBL.ctx.OLAP1D, GBL.ctx.MODE, GBL.ctx.LIMXY, + GBL.mch.WTHMPR ); /* ------------------- */ /* Handle bypass modes */ /* ------------------- */ - if( GBL.ctx.MODE == 'E' ) - return U.Echo( guesses ); + if( GBL.ctx.MODE == 'E' ) + return U.Echo( guesses ); - if( GBL.ctx.MODE == 'F' ) - return U.FromLog( guesses ); + if( GBL.ctx.MODE == 'F' ) + return U.FromLog( guesses ); /* ------------------- */ /* Handle search modes */ /* ------------------- */ - CThmScan S; - CorRec best; + CThmScan S; + CorRec best; - S.Initialize( flog, best ); - S.SetTdfm( GBL.ctx.Tdfm ); - S.SetRThresh( GBL.ctx.RTRSH ); - S.SetNbMaxHt( GBL.ctx.NBMXHT ); - S.SetSweepConstXY( true ); - S.SetSweepPretweak( GBL.mch.PRETWEAK ); - S.SetUseCorrR( true ); - S.SetDisc( 0, 0, -1, -1 ); + S.Initialize( flog, best ); + S.SetTdfm( GBL.ctx.Tdfm ); + S.SetRThresh( GBL.ctx.RTRSH ); + S.SetNbMaxHt( GBL.ctx.NBMXHT ); + S.SetSweepConstXY( true ); + S.SetSweepPretweak( GBL.mch.PRETWEAK ); + S.SetUseCorrR( true ); + S.SetDisc( 0, 0, -1, -1 ); /* ----------------------- */ /* Create image thumbnails */ /* ----------------------- */ - OlapRec olp; - ThmRec thm; - int nPriorAngles = U.SetStartingAngle( - GBL.ctx.Tdfm, GBL.arg.CTR ); + OlapRec olp; + ThmRec thm; + int nPriorAngles = U.SetStartingAngle( + GBL.ctx.Tdfm, GBL.arg.CTR ); - if( !U.Crop( olp, acr, bcr, GBL.ctx.XYCONF ) ) - return false; + if( !U.Crop( olp, acr, bcr, GBL.ctx.XYCONF ) ) + return false; - if( !U.MakeThumbs( thm, olp, GBL.ctx.THMDEC ) ) - return false; + if( !U.MakeThumbs( thm, olp, GBL.ctx.THMDEC ) ) + return false; /* ------ */ /* Search */ /* ------ */ - if( GBL.ctx.MODE == 'N' ) { + if( GBL.ctx.MODE == 'N' ) { - if( !U.Disc( best, S, thm, olp, GBL.mch.PRETWEAK ) ) - return false; - } - else if( !U.Sweep( best, S, thm, nPriorAngles ) ) - return false; + if( !U.Disc( best, S, thm, olp, GBL.mch.PRETWEAK ) ) + return false; + } + else if( !U.Sweep( best, S, thm, nPriorAngles ) ) + return false; /* ------ */ /* Finish */ /* ------ */ - if( U.Finish( best, S, thm, olp, GBL.mch.TWEAKS ) ) { + if( U.Finish( best, S, thm, olp, GBL.mch.TWEAKS ) ) { - guesses.push_back( best.T ); - return true; - } + guesses.push_back( best.T ); + return true; + } - return false; + return false; } diff --git a/1_DMesh/ApproximateMatch.h b/1_DMesh/ApproximateMatch.h index 172dc91..db98251 100644 --- a/1_DMesh/ApproximateMatch.h +++ b/1_DMesh/ApproximateMatch.h @@ -13,15 +13,15 @@ /* --------------------------------------------------------------- */ bool ApproximateMatch_NoCR( - vector &guesses, - const PixPair &px, - FILE* flog ); + vector &guesses, + const PixPair &px, + FILE* flog ); bool ApproximateMatch( - vector &guesses, - const PixPair &px, - const ConnRegion &acr, - const ConnRegion &bcr, - FILE* flog ); + vector &guesses, + const PixPair &px, + const ConnRegion &acr, + const ConnRegion &bcr, + FILE* flog ); diff --git a/1_DMesh/ApproximateMatch_NoCR.cpp b/1_DMesh/ApproximateMatch_NoCR.cpp index 3c20f7f..627a80c 100644 --- a/1_DMesh/ApproximateMatch_NoCR.cpp +++ b/1_DMesh/ApproximateMatch_NoCR.cpp @@ -23,81 +23,81 @@ // See notes in ApproximateMatch.cpp. // bool ApproximateMatch_NoCR( - vector &guesses, - const PixPair &px, - FILE* flog ) + vector &guesses, + const PixPair &px, + FILE* flog ) { - CThmUtil U( GBL.A, 1, GBL.B, 1, px, - GBL.Tab, GBL.ctx.OLAP2D, flog ); + CThmUtil U( GBL.A, 1, GBL.B, 1, px, + GBL.Tab, GBL.ctx.OLAP2D, flog ); - U.SetParams( - GBL.ctx.HFANGDN, GBL.ctx.HFANGPR, GBL.ctx.RTRSH, - GBL.ctx.OLAP1D, GBL.ctx.MODE, GBL.ctx.LIMXY, - GBL.mch.WTHMPR ); + U.SetParams( + GBL.ctx.HFANGDN, GBL.ctx.HFANGPR, GBL.ctx.RTRSH, + GBL.ctx.OLAP1D, GBL.ctx.MODE, GBL.ctx.LIMXY, + GBL.mch.WTHMPR ); /* ------------------- */ /* Handle bypass modes */ /* ------------------- */ - if( GBL.ctx.MODE == 'E' ) - return U.Echo( guesses ); + if( GBL.ctx.MODE == 'E' ) + return U.Echo( guesses ); - if( GBL.ctx.MODE == 'F' ) - return U.FromLog( guesses ); + if( GBL.ctx.MODE == 'F' ) + return U.FromLog( guesses ); /* ------------------- */ /* Handle search modes */ /* ------------------- */ - CThmScan S; - CorRec best; + CThmScan S; + CorRec best; - S.Initialize( flog, best ); - S.SetTdfm( GBL.ctx.Tdfm ); - S.SetRThresh( GBL.ctx.RTRSH ); - S.SetNbMaxHt( GBL.ctx.NBMXHT ); - S.SetSweepConstXY( true ); - S.SetSweepPretweak( GBL.mch.PRETWEAK ); - S.SetUseCorrR( true ); - S.SetDisc( 0, 0, -1, -1 ); + S.Initialize( flog, best ); + S.SetTdfm( GBL.ctx.Tdfm ); + S.SetRThresh( GBL.ctx.RTRSH ); + S.SetNbMaxHt( GBL.ctx.NBMXHT ); + S.SetSweepConstXY( true ); + S.SetSweepPretweak( GBL.mch.PRETWEAK ); + S.SetUseCorrR( true ); + S.SetDisc( 0, 0, -1, -1 ); /* ----------------------- */ /* Create image thumbnails */ /* ----------------------- */ - OlapRec olp; - ThmRec thm; - int nPriorAngles = U.SetStartingAngle( - GBL.ctx.Tdfm, GBL.arg.CTR ); + OlapRec olp; + ThmRec thm; + int nPriorAngles = U.SetStartingAngle( + GBL.ctx.Tdfm, GBL.arg.CTR ); - U.Crop_NoCR( olp, GBL.ctx.XYCONF ); + U.Crop_NoCR( olp, GBL.ctx.XYCONF ); - if( !U.MakeThumbs( thm, olp, GBL.ctx.THMDEC ) ) - return false; + if( !U.MakeThumbs( thm, olp, GBL.ctx.THMDEC ) ) + return false; /* ------ */ /* Search */ /* ------ */ - if( GBL.ctx.MODE == 'N' ) { + if( GBL.ctx.MODE == 'N' ) { - if( !U.Disc( best, S, thm, olp, GBL.mch.PRETWEAK ) ) - return false; - } - else if( !U.Sweep( best, S, thm, nPriorAngles ) ) - return false; + if( !U.Disc( best, S, thm, olp, GBL.mch.PRETWEAK ) ) + return false; + } + else if( !U.Sweep( best, S, thm, nPriorAngles ) ) + return false; /* ------ */ /* Finish */ /* ------ */ - if( U.Finish( best, S, thm, olp, GBL.mch.TWEAKS ) ) { + if( U.Finish( best, S, thm, olp, GBL.mch.TWEAKS ) ) { - guesses.push_back( best.T ); - return true; - } + guesses.push_back( best.T ); + return true; + } - return false; + return false; } diff --git a/1_DMesh/CGBL_dmesh.cpp b/1_DMesh/CGBL_dmesh.cpp index 5171bb7..83a0da3 100644 --- a/1_DMesh/CGBL_dmesh.cpp +++ b/1_DMesh/CGBL_dmesh.cpp @@ -44,46 +44,46 @@ CGBL_dmesh GBL; static void PrintUsage() { - fprintf( stderr, - "\n" - "Usage: za.ia^zb.ib [ options ], where,\n" - "\n" - " ia < 0 implies {za,ia} set via -jtilea option,\n" - " ib < 0 implies {zb,ib} set via -jtileb option.\n" - "\n" - " Options:\n" - " -jtilea=\n" - " -jtileb=\n" - " -prm=\n" - " -Tdfm=\n" - " -Tab=\n" - " -Ta=\n" - " -Tb=\n" - " -SCALE=\n" - " -XSCALE=\n" - " -YSCALE=\n" - " -SKEW=\n" - " -ima=\n" - " -imb=\n" - " -fma=\n" - " -fmb=\n" - " -FLD=\n" - " -MODE=\n" - " -CTR=\n" - " -tr\n" - " -ws\n" - " -nf\n" - " -sf\n" - " -Tmsh=\n" - " -XYexp=\n" - " -json\n" - " -v\n" - " -comp_png=\n" - " -registered_png=\n" - " -heatmap\n" - " -dbgcor\n" - "\n" - ); + fprintf( stderr, + "\n" + "Usage: za.ia^zb.ib [ options ], where,\n" + "\n" + " ia < 0 implies {za,ia} set via -jtilea option,\n" + " ib < 0 implies {zb,ib} set via -jtileb option.\n" + "\n" + " Options:\n" + " -jtilea=\n" + " -jtileb=\n" + " -prm=\n" + " -Tdfm=\n" + " -Tab=\n" + " -Ta=\n" + " -Tb=\n" + " -SCALE=\n" + " -XSCALE=\n" + " -YSCALE=\n" + " -SKEW=\n" + " -ima=\n" + " -imb=\n" + " -fma=\n" + " -fmb=\n" + " -FLD=\n" + " -MODE=\n" + " -CTR=\n" + " -tr\n" + " -ws\n" + " -nf\n" + " -sf\n" + " -Tmsh=\n" + " -XYexp=\n" + " -json\n" + " -v\n" + " -comp_png=\n" + " -registered_png=\n" + " -heatmap\n" + " -dbgcor\n" + "\n" + ); } /* --------------------------------------------------------------- */ @@ -92,33 +92,33 @@ static void PrintUsage() CGBL_dmesh::CGBL_dmesh() { - _arg.SCALE = 999.0; - _arg.XSCALE = 999.0; - _arg.YSCALE = 999.0; - _arg.SKEW = 999.0; - _arg.matchparams = NULL; - _arg.ima = NULL; - _arg.imb = NULL; - _arg.FLD = 0; - _arg.MODE = 0; - - arg.CTR = 999.0; - arg.fma = NULL; - arg.fmb = NULL; - arg.comp_png = NULL; - arg.registered_png = NULL; - arg.Transpose = false; - arg.WithinSection = false; - arg.SingleFold = false; - arg.JSON = false; - arg.Verbose = false; - arg.Heatmap = false; - - A.z = 0; - A.id = ID_UNSET; - - B.z = 0; - B.id = ID_UNSET; + _arg.SCALE = 999.0; + _arg.XSCALE = 999.0; + _arg.YSCALE = 999.0; + _arg.SKEW = 999.0; + _arg.matchparams = NULL; + _arg.ima = NULL; + _arg.imb = NULL; + _arg.FLD = 0; + _arg.MODE = 0; + + arg.CTR = 999.0; + arg.fma = NULL; + arg.fmb = NULL; + arg.comp_png = NULL; + arg.registered_png = NULL; + arg.Transpose = false; + arg.WithinSection = false; + arg.SingleFold = false; + arg.JSON = false; + arg.Verbose = false; + arg.Heatmap = false; + + A.z = 0; + A.id = ID_UNSET; + + B.z = 0; + B.id = ID_UNSET; } /* --------------------------------------------------------------- */ @@ -129,372 +129,372 @@ bool CGBL_dmesh::SetCmdLine( int argc, char* argv[] ) { // Parse args - const char *key = NULL; - vector vD; - - for( int i = 1; i < argc; ++i ) { - - if( argv[i][0] != '-' ) - key = argv[i]; - else if( GetArgList( vD, "-Tdfm=", argv[i] ) ) { - - if( 6 == vD.size() ) - _arg.Tdfm.push_back( TAffine( &vD[0] ) ); - else { - fprintf( stderr, - "main: WARNING: Bad format in -Tdfm [%s].\n", - argv[i] ); - } - } - else if( GetArgList( vD, "-Tab=", argv[i] ) ) { - - if( 6 == vD.size() ) - _arg.Tab.push_back( TAffine( &vD[0] ) ); - else { - fprintf( stderr, - "main: WARNING: Bad format in -Tab [%s].\n", - argv[i] ); - } - } - else if( GetArgList( vD, "-Ta=", argv[i] ) ) { - - if( 6 == vD.size() ) - _arg.Ta.push_back( TAffine( &vD[0] ) ); - else { - fprintf( stderr, - "main: WARNING: Bad format in -Ta [%s].\n", - argv[i] ); - } - } - else if( GetArgList( vD, "-Tb=", argv[i] ) ) { - - if( 6 == vD.size() ) - _arg.Tb.push_back( TAffine( &vD[0] ) ); - else { - fprintf( stderr, - "main: WARNING: Bad format in -Tb [%s].\n", - argv[i] ); - } - } - else if( GetArg( &_arg.SCALE, "-SCALE=%lf", argv[i] ) ) - ; - else if( GetArg( &_arg.XSCALE, "-XSCALE=%lf", argv[i] ) ) - ; - else if( GetArg( &_arg.YSCALE, "-YSCALE=%lf", argv[i] ) ) - ; - else if( GetArg( &_arg.SKEW, "-SKEW=%lf", argv[i] ) ) - ; - else if( GetArgStr( _arg.matchparams, "-prm=", argv[i] ) ) - ; - else if( GetArgStr( _arg.ima, "-ima=", argv[i] ) ) - ; - else if( GetArgStr( _arg.imb, "-imb=", argv[i] ) ) - ; - else if( GetArg( &_arg.FLD, "-FLD=%c", argv[i] ) ) - ; - else if( GetArg( &_arg.MODE, "-MODE=%c", argv[i] ) ) - ; - else if( GetArg( &arg.CTR, "-CTR=%lf", argv[i] ) ) - ; - else if( GetArgStr( arg.fma, "-fma=", argv[i] ) ) - ; - else if( GetArgStr( arg.fmb, "-fmb=", argv[i] ) ) - ; - else if( GetArgStr( arg.comp_png, "-comp_png=", argv[i] ) ) - ; - else if( GetArgStr( arg.registered_png, "-registered_png=", argv[i] ) ) - ; - else if( IsArg( "-tr", argv[i] ) ) - arg.Transpose = true; - else if( IsArg( "-ws", argv[i] ) ) - arg.WithinSection = true; - else if( IsArg( "-nf", argv[i] ) ) - _arg.FLD = 'N'; - else if( IsArg( "-sf", argv[i] ) ) - arg.SingleFold = true; - else if( IsArg( "-json", argv[i] ) ) - arg.JSON = true; - else if( IsArg( "-v", argv[i] ) ) - arg.Verbose = true; - else if( IsArg( "-heatmap", argv[i] ) ) - arg.Heatmap = true; - else if( IsArg( "-dbgcor", argv[i] ) ) - dbgCor = true; - else if( GetArgList( vD, "-Tmsh=", argv[i] ) ) { - - if( 6 == vD.size() ) - Tmsh.push_back( TAffine( &vD[0] ) ); - else { - fprintf( stderr, - "main: WARNING: Bad format in -Tmsh [%s].\n", - argv[i] ); - } - } - else if( GetArgList( vD, "-XYexp=", argv[i] ) ) { - - if( 2 == vD.size() ) - XYexp.push_back( Point( vD[0], vD[1] ) ); - else { - fprintf( stderr, - "main: WARNING: Bad format in -XYexp [%s].\n", - argv[i] ); - } - } - else if( GetTileSpecFromURL( A, "-jtilea=", argv[i] ) ) - ; - else if( GetTileSpecFromURL( B, "-jtileb=", argv[i] ) ) - ; - else { - fprintf( stderr, - "Did not understand option '%s'.\n", argv[i] ); - return false; - } - } + const char *key = NULL; + vector vD; + + for( int i = 1; i < argc; ++i ) { + + if( argv[i][0] != '-' ) + key = argv[i]; + else if( GetArgList( vD, "-Tdfm=", argv[i] ) ) { + + if( 6 == vD.size() ) + _arg.Tdfm.push_back( TAffine( &vD[0] ) ); + else { + fprintf( stderr, + "main: WARNING: Bad format in -Tdfm [%s].\n", + argv[i] ); + } + } + else if( GetArgList( vD, "-Tab=", argv[i] ) ) { + + if( 6 == vD.size() ) + _arg.Tab.push_back( TAffine( &vD[0] ) ); + else { + fprintf( stderr, + "main: WARNING: Bad format in -Tab [%s].\n", + argv[i] ); + } + } + else if( GetArgList( vD, "-Ta=", argv[i] ) ) { + + if( 6 == vD.size() ) + _arg.Ta.push_back( TAffine( &vD[0] ) ); + else { + fprintf( stderr, + "main: WARNING: Bad format in -Ta [%s].\n", + argv[i] ); + } + } + else if( GetArgList( vD, "-Tb=", argv[i] ) ) { + + if( 6 == vD.size() ) + _arg.Tb.push_back( TAffine( &vD[0] ) ); + else { + fprintf( stderr, + "main: WARNING: Bad format in -Tb [%s].\n", + argv[i] ); + } + } + else if( GetArg( &_arg.SCALE, "-SCALE=%lf", argv[i] ) ) + ; + else if( GetArg( &_arg.XSCALE, "-XSCALE=%lf", argv[i] ) ) + ; + else if( GetArg( &_arg.YSCALE, "-YSCALE=%lf", argv[i] ) ) + ; + else if( GetArg( &_arg.SKEW, "-SKEW=%lf", argv[i] ) ) + ; + else if( GetArgStr( _arg.matchparams, "-prm=", argv[i] ) ) + ; + else if( GetArgStr( _arg.ima, "-ima=", argv[i] ) ) + ; + else if( GetArgStr( _arg.imb, "-imb=", argv[i] ) ) + ; + else if( GetArg( &_arg.FLD, "-FLD=%c", argv[i] ) ) + ; + else if( GetArg( &_arg.MODE, "-MODE=%c", argv[i] ) ) + ; + else if( GetArg( &arg.CTR, "-CTR=%lf", argv[i] ) ) + ; + else if( GetArgStr( arg.fma, "-fma=", argv[i] ) ) + ; + else if( GetArgStr( arg.fmb, "-fmb=", argv[i] ) ) + ; + else if( GetArgStr( arg.comp_png, "-comp_png=", argv[i] ) ) + ; + else if( GetArgStr( arg.registered_png, "-registered_png=", argv[i] ) ) + ; + else if( IsArg( "-tr", argv[i] ) ) + arg.Transpose = true; + else if( IsArg( "-ws", argv[i] ) ) + arg.WithinSection = true; + else if( IsArg( "-nf", argv[i] ) ) + _arg.FLD = 'N'; + else if( IsArg( "-sf", argv[i] ) ) + arg.SingleFold = true; + else if( IsArg( "-json", argv[i] ) ) + arg.JSON = true; + else if( IsArg( "-v", argv[i] ) ) + arg.Verbose = true; + else if( IsArg( "-heatmap", argv[i] ) ) + arg.Heatmap = true; + else if( IsArg( "-dbgcor", argv[i] ) ) + dbgCor = true; + else if( GetArgList( vD, "-Tmsh=", argv[i] ) ) { + + if( 6 == vD.size() ) + Tmsh.push_back( TAffine( &vD[0] ) ); + else { + fprintf( stderr, + "main: WARNING: Bad format in -Tmsh [%s].\n", + argv[i] ); + } + } + else if( GetArgList( vD, "-XYexp=", argv[i] ) ) { + + if( 2 == vD.size() ) + XYexp.push_back( Point( vD[0], vD[1] ) ); + else { + fprintf( stderr, + "main: WARNING: Bad format in -XYexp [%s].\n", + argv[i] ); + } + } + else if( GetTileSpecFromURL( A, "-jtilea=", argv[i] ) ) + ; + else if( GetTileSpecFromURL( B, "-jtileb=", argv[i] ) ) + ; + else { + fprintf( stderr, + "Did not understand option '%s'.\n", argv[i] ); + return false; + } + } // Decode labels in key - { - int az, aid, bz, bid; + { + int az, aid, bz, bid; - if( !key || - (4 != sscanf( key, "%d.%d^%d.%d", &az, &aid, &bz, &bid )) ) { + if( !key || + (4 != sscanf( key, "%d.%d^%d.%d", &az, &aid, &bz, &bid )) ) { - PrintUsage(); - return false; - } - else { + PrintUsage(); + return false; + } + else { - if( A.id == ID_UNSET ) { - A.z = az; - A.id = aid; - } + if( A.id == ID_UNSET ) { + A.z = az; + A.id = aid; + } - if( B.id == ID_UNSET ) { - B.z = bz; - B.id = bid; - } - } - } + if( B.id == ID_UNSET ) { + B.z = bz; + B.id = bid; + } + } + } // Start logging - fprintf( stderr, "\n---- dmesh start ----\n" ); + fprintf( stderr, "\n---- dmesh start ----\n" ); // Record start time - time_t t0 = time( NULL ); - fprintf( stderr, "main: Start: %s\n", ctime(&t0) ); + time_t t0 = time( NULL ); + fprintf( stderr, "main: Start: %s\n", ctime(&t0) ); // Get default parameters - if( !ReadMatchParams( mch, A.z, B.z, _arg.matchparams, stderr ) ) - return false; + if( !ReadMatchParams( mch, A.z, B.z, _arg.matchparams, stderr ) ) + return false; // Which file params to use according to (same,cross) layer - double cSCALE=1, cXSCALE=1, cYSCALE=1, cSKEW=0; - int cDfmFromTab; - - ctx.FLD = mch.FLD; - - if( A.z == B.z ) { - - cDfmFromTab = mch.TAB2DFM_SL; - - //ctx.Tdfm = identity (default) - ctx.XYCONF = mch.XYCONF_SL; - ctx.NBMXHT = mch.NBMXHT_SL; - ctx.HFANGDN = mch.HFANGDN_SL; - ctx.HFANGPR = mch.HFANGPR_SL; - ctx.RTRSH = mch.RTRSH_SL; - ctx.RIT = mch.RIT_SL; - ctx.RFA = mch.RFA_SL; - ctx.RFT = mch.RFT_SL; - ctx.OLAP2D = mch.OLAP2D_SL; - ctx.MODE = mch.MODE_SL; - ctx.THMDEC = mch.THMDEC_SL; - ctx.OLAP1D = mch.OLAP1D_SL; - ctx.LIMXY = mch.LIMXY_SL; - ctx.OPT = mch.OPT_SL; - } - else { - - cSCALE = mch.SCALE; - cXSCALE = mch.XSCALE; - cYSCALE = mch.YSCALE; - cSKEW = mch.SKEW; - - ctx.Tdfm.ComposeDfm( cSCALE, cXSCALE, cYSCALE, 0, cSKEW ); - - cDfmFromTab = mch.TAB2DFM_XL; - - ctx.XYCONF = mch.XYCONF_XL; - ctx.NBMXHT = mch.NBMXHT_XL; - ctx.HFANGDN = mch.HFANGDN_XL; - ctx.HFANGPR = mch.HFANGPR_XL; - ctx.RTRSH = mch.RTRSH_XL; - ctx.RIT = mch.RIT_XL; - ctx.RFA = mch.RFA_XL; - ctx.RFT = mch.RFT_XL; - ctx.OLAP2D = mch.OLAP2D_XL; - ctx.MODE = mch.MODE_XL; - ctx.THMDEC = mch.THMDEC_XL; - ctx.OLAP1D = mch.OLAP1D_XL; - ctx.LIMXY = mch.LIMXY_XL; - ctx.OPT = true; - } + double cSCALE=1, cXSCALE=1, cYSCALE=1, cSKEW=0; + int cDfmFromTab; + + ctx.FLD = mch.FLD; + + if( A.z == B.z ) { + + cDfmFromTab = mch.TAB2DFM_SL; + + //ctx.Tdfm = identity (default) + ctx.XYCONF = mch.XYCONF_SL; + ctx.NBMXHT = mch.NBMXHT_SL; + ctx.HFANGDN = mch.HFANGDN_SL; + ctx.HFANGPR = mch.HFANGPR_SL; + ctx.RTRSH = mch.RTRSH_SL; + ctx.RIT = mch.RIT_SL; + ctx.RFA = mch.RFA_SL; + ctx.RFT = mch.RFT_SL; + ctx.OLAP2D = mch.OLAP2D_SL; + ctx.MODE = mch.MODE_SL; + ctx.THMDEC = mch.THMDEC_SL; + ctx.OLAP1D = mch.OLAP1D_SL; + ctx.LIMXY = mch.LIMXY_SL; + ctx.OPT = mch.OPT_SL; + } + else { + + cSCALE = mch.SCALE; + cXSCALE = mch.XSCALE; + cYSCALE = mch.YSCALE; + cSKEW = mch.SKEW; + + ctx.Tdfm.ComposeDfm( cSCALE, cXSCALE, cYSCALE, 0, cSKEW ); + + cDfmFromTab = mch.TAB2DFM_XL; + + ctx.XYCONF = mch.XYCONF_XL; + ctx.NBMXHT = mch.NBMXHT_XL; + ctx.HFANGDN = mch.HFANGDN_XL; + ctx.HFANGPR = mch.HFANGPR_XL; + ctx.RTRSH = mch.RTRSH_XL; + ctx.RIT = mch.RIT_XL; + ctx.RFA = mch.RFA_XL; + ctx.RFT = mch.RFT_XL; + ctx.OLAP2D = mch.OLAP2D_XL; + ctx.MODE = mch.MODE_XL; + ctx.THMDEC = mch.THMDEC_XL; + ctx.OLAP1D = mch.OLAP1D_XL; + ctx.LIMXY = mch.LIMXY_XL; + ctx.OPT = true; + } // Fetch Til2Img entries (using image overrides) - fprintf( stderr, "\n---- Input images ----\n" ); + fprintf( stderr, "\n---- Input images ----\n" ); - if( A.id >= 0 || B.id >= 0 ) - IDBFromTemp( idb, "../../", stderr ); + if( A.id >= 0 || B.id >= 0 ) + IDBFromTemp( idb, "../../", stderr ); - if( A.id >= 0 ) { + if( A.id >= 0 ) { - if( !IDBT2IGet1( A.t2i, idb, A.z, A.id, _arg.ima, stderr ) ) - return false; - } - else if( _arg.ima ) - A.t2i.path = _arg.ima; + if( !IDBT2IGet1( A.t2i, idb, A.z, A.id, _arg.ima, stderr ) ) + return false; + } + else if( _arg.ima ) + A.t2i.path = _arg.ima; - if( B.id >= 0 ) { + if( B.id >= 0 ) { - if( !IDBT2IGet1( B.t2i, idb, B.z, B.id, _arg.imb, stderr ) ) - return false; - } - else if( _arg.imb ) - B.t2i.path = _arg.imb; + if( !IDBT2IGet1( B.t2i, idb, B.z, B.id, _arg.imb, stderr ) ) + return false; + } + else if( _arg.imb ) + B.t2i.path = _arg.imb; - PrintTil2Img( stderr, 'A', A.t2i ); - PrintTil2Img( stderr, 'B', B.t2i ); + PrintTil2Img( stderr, 'A', A.t2i ); + PrintTil2Img( stderr, 'B', B.t2i ); - fprintf( stderr, "\n" ); + fprintf( stderr, "\n" ); // Commandline parameter overrides - fprintf( stderr, "\n---- Command-line overrides ----\n" ); + fprintf( stderr, "\n---- Command-line overrides ----\n" ); - if( _arg.Tab.size() ) { + if( _arg.Tab.size() ) { - Tab = _arg.Tab[0]; + Tab = _arg.Tab[0]; - // remove lens parts of Tab coming from cross_thisblock + // remove lens parts of Tab coming from cross_thisblock - if( mch.PXLENS && A.z != B.z ) { + if( mch.PXLENS && A.z != B.z ) { - CAffineLens LN; + CAffineLens LN; - if( !LN.ReadIDB( idb, stderr ) ) - return false; + if( !LN.ReadIDB( idb, stderr ) ) + return false; - LN.UpdateTFormRHS( Tab, A.t2i.cam, true ); - LN.UpdateTFormLHS( Tab, B.t2i.cam, false ); - } + LN.UpdateTFormRHS( Tab, A.t2i.cam, true ); + LN.UpdateTFormLHS( Tab, B.t2i.cam, false ); + } - Tab.TPrint( stderr, "Tab= " ); - } - else if( _arg.Ta.size() || _arg.Tb.size() ) { + Tab.TPrint( stderr, "Tab= " ); + } + else if( _arg.Ta.size() || _arg.Tb.size() ) { - TAffine Ta, Tb; + TAffine Ta, Tb; - if( _arg.Ta.size() ) - Ta = _arg.Ta[0]; + if( _arg.Ta.size() ) + Ta = _arg.Ta[0]; - if( _arg.Tb.size() ) - Tb = _arg.Tb[0]; + if( _arg.Tb.size() ) + Tb = _arg.Tb[0]; - Tab.FromAToB( Ta, Tb ); + Tab.FromAToB( Ta, Tb ); - Ta.TPrint( stderr, "Ta= " ); - Tb.TPrint( stderr, "Tb= " ); - Tab.TPrint( stderr, "Tab= " ); - } - else - Tab.FromAToB( A.t2i.T, B.t2i.T ); + Ta.TPrint( stderr, "Ta= " ); + Tb.TPrint( stderr, "Tb= " ); + Tab.TPrint( stderr, "Tab= " ); + } + else + Tab.FromAToB( A.t2i.T, B.t2i.T ); - int altTdfm = false; + int altTdfm = false; - if( _arg.Tdfm.size() ) { + if( _arg.Tdfm.size() ) { - ctx.Tdfm = _arg.Tdfm[0]; - altTdfm = true; - } - else { + ctx.Tdfm = _arg.Tdfm[0]; + altTdfm = true; + } + else { - if( _arg.SCALE != 999.0 ) { - cSCALE = _arg.SCALE; - altTdfm = true; - fprintf( stderr, "SCALE=%g\n", _arg.SCALE ); - } + if( _arg.SCALE != 999.0 ) { + cSCALE = _arg.SCALE; + altTdfm = true; + fprintf( stderr, "SCALE=%g\n", _arg.SCALE ); + } - if( _arg.XSCALE != 999.0 ) { - cXSCALE = _arg.XSCALE; - altTdfm = true; - fprintf( stderr, "XSCALE=%g\n", _arg.XSCALE ); - } + if( _arg.XSCALE != 999.0 ) { + cXSCALE = _arg.XSCALE; + altTdfm = true; + fprintf( stderr, "XSCALE=%g\n", _arg.XSCALE ); + } - if( _arg.YSCALE != 999.0 ) { - cYSCALE = _arg.YSCALE; - altTdfm = true; - fprintf( stderr, "YSCALE=%g\n", _arg.YSCALE ); - } + if( _arg.YSCALE != 999.0 ) { + cYSCALE = _arg.YSCALE; + altTdfm = true; + fprintf( stderr, "YSCALE=%g\n", _arg.YSCALE ); + } - if( _arg.SKEW != 999.0 ) { - cSKEW = _arg.SKEW; - altTdfm = true; - fprintf( stderr, "SKEW=%g\n", _arg.SKEW ); - } + if( _arg.SKEW != 999.0 ) { + cSKEW = _arg.SKEW; + altTdfm = true; + fprintf( stderr, "SKEW=%g\n", _arg.SKEW ); + } - if( altTdfm ) - ctx.Tdfm.ComposeDfm( cSCALE, cXSCALE, cYSCALE, 0, cSKEW ); - } + if( altTdfm ) + ctx.Tdfm.ComposeDfm( cSCALE, cXSCALE, cYSCALE, 0, cSKEW ); + } - if( !altTdfm && cDfmFromTab ) { + if( !altTdfm && cDfmFromTab ) { - TAffine R; - R.NUSetRot( -Tab.GetRadians() ); + TAffine R; + R.NUSetRot( -Tab.GetRadians() ); - ctx.Tdfm = Tab; - ctx.Tdfm.SetXY( 0, 0 ); - ctx.Tdfm = R * ctx.Tdfm; - } + ctx.Tdfm = Tab; + ctx.Tdfm.SetXY( 0, 0 ); + ctx.Tdfm = R * ctx.Tdfm; + } - ctx.Tdfm.TPrint( stderr, "Tdfm=" ); + ctx.Tdfm.TPrint( stderr, "Tdfm=" ); - if( _arg.FLD ) { - ctx.FLD = _arg.FLD; - fprintf( stderr, "FLD=%c\n", _arg.FLD ); - } + if( _arg.FLD ) { + ctx.FLD = _arg.FLD; + fprintf( stderr, "FLD=%c\n", _arg.FLD ); + } - if( ctx.FLD == 'X' ) { - ctx.FLD = (GBL.A.z == GBL.B.z ? 'N' : 'Y'); - fprintf( stderr, "FLD=%c (was X)\n", ctx.FLD ); - } + if( ctx.FLD == 'X' ) { + ctx.FLD = (GBL.A.z == GBL.B.z ? 'N' : 'Y'); + fprintf( stderr, "FLD=%c (was X)\n", ctx.FLD ); + } - if( _arg.MODE ) { - ctx.MODE = _arg.MODE; - fprintf( stderr, "MODE=%c\n", _arg.MODE ); - } + if( _arg.MODE ) { + ctx.MODE = _arg.MODE; + fprintf( stderr, "MODE=%c\n", _arg.MODE ); + } - if( ctx.MODE == 'Z' ) { - ctx.MODE = 'C'; - arg.CTR = 0.0; - fprintf( stderr, "MODE=C (was Z)\n" ); - } - else if( ctx.MODE == 'M' ) { - ctx.MODE = 'N'; - arg.CTR = 0.0; - fprintf( stderr, "MODE=N (was M)\n" ); - } + if( ctx.MODE == 'Z' ) { + ctx.MODE = 'C'; + arg.CTR = 0.0; + fprintf( stderr, "MODE=C (was Z)\n" ); + } + else if( ctx.MODE == 'M' ) { + ctx.MODE = 'N'; + arg.CTR = 0.0; + fprintf( stderr, "MODE=N (was M)\n" ); + } - if( arg.CTR != 999.0 ) - fprintf( stderr, "CTR=%g\n", arg.CTR ); - - fprintf( stderr, "\n" ); - - return true; + if( arg.CTR != 999.0 ) + fprintf( stderr, "CTR=%g\n", arg.CTR ); + + fprintf( stderr, "\n" ); + + return true; } diff --git a/1_DMesh/CGBL_dmesh.h b/1_DMesh/CGBL_dmesh.h index f658a21..3c3b683 100644 --- a/1_DMesh/CGBL_dmesh.h +++ b/1_DMesh/CGBL_dmesh.h @@ -17,86 +17,86 @@ class CGBL_dmesh { // ===== private: - typedef struct { - vector Tdfm, - Tab, - Ta, - Tb; - double SCALE, - XSCALE, - YSCALE, - SKEW; - const char *matchparams, - *ima, // override idb paths - *imb; - int FLD, - MODE; - } PrvDrvArgs; + typedef struct { + vector Tdfm, + Tab, + Ta, + Tb; + double SCALE, + XSCALE, + YSCALE, + SKEW; + const char *matchparams, + *ima, // override idb paths + *imb; + int FLD, + MODE; + } PrvDrvArgs; public: - typedef struct { - double CTR; - const char *fma, // override idb paths - *fmb, - *comp_png, // override comp.png path - *registered_png; // override registered.png path - bool Transpose, // transpose all images - WithinSection, // overlap within a section - SingleFold, // assign id=1 to all non-fold rgns - JSON, // output JSON format - Verbose, // run inspect diagnostics - Heatmap; // run CorrView - } DriverArgs; - - typedef struct { - TAffine Tdfm; - double XYCONF, - NBMXHT, - HFANGDN, - HFANGPR, - RTRSH, - RIT, - RFA, - RFT; - long OLAP2D; - int FLD, - MODE, - THMDEC, - OLAP1D, - LIMXY, - OPT; - } CntxtDep; + typedef struct { + double CTR; + const char *fma, // override idb paths + *fmb, + *comp_png, // override comp.png path + *registered_png; // override registered.png path + bool Transpose, // transpose all images + WithinSection, // overlap within a section + SingleFold, // assign id=1 to all non-fold rgns + JSON, // output JSON format + Verbose, // run inspect diagnostics + Heatmap; // run CorrView + } DriverArgs; + + typedef struct { + TAffine Tdfm; + double XYCONF, + NBMXHT, + HFANGDN, + HFANGPR, + RTRSH, + RIT, + RFA, + RFT; + long OLAP2D; + int FLD, + MODE, + THMDEC, + OLAP1D, + LIMXY, + OPT; + } CntxtDep; // ============ // Data members // ============ private: - PrvDrvArgs _arg; + PrvDrvArgs _arg; public: - DriverArgs arg; - TAffine Tab; // start thumbs here - vector Tmsh; // bypass thumbs, start mesh here - vector XYexp; // command line expected XY - MatchParams mch; - CntxtDep ctx; - string idb; - PicSpec A, B; + DriverArgs arg; + TAffine Tab; // start thumbs here + vector Tmsh; // bypass thumbs, start mesh here + vector XYexp; // command line expected XY + MatchParams mch; + CntxtDep ctx; + string idb; + PicSpec A, B; // ================= // Object management // ================= public: - CGBL_dmesh(); + CGBL_dmesh(); // ========= // Interface // ========= public: - bool SetCmdLine( int argc, char* argv[] ); + bool SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ diff --git a/1_DMesh/CThmUtil.cpp b/1_DMesh/CThmUtil.cpp index 3fa91cf..cef2b59 100644 --- a/1_DMesh/CThmUtil.cpp +++ b/1_DMesh/CThmUtil.cpp @@ -19,8 +19,8 @@ bool CThmUtil::Echo( vector &guesses ) { - guesses.push_back( Tab ); - return true; + guesses.push_back( Tab ); + return true; } /* --------------------------------------------------------------- */ @@ -29,18 +29,18 @@ bool CThmUtil::Echo( vector &guesses ) bool CThmUtil::FromLog( vector &guesses ) { - ThmPair tpr; - int ok; + ThmPair tpr; + int ok; - ok = ReadThmPair( tpr, - A.z, A.id, acr, - B.z, B.id, bcr, flog ) - && !tpr.err; + ok = ReadThmPair( tpr, + A.z, A.id, acr, + B.z, B.id, bcr, flog ) + && !tpr.err; - if( ok ) - guesses.push_back( tpr.T ); + if( ok ) + guesses.push_back( tpr.T ); - return ok; + return ok; } /* --------------------------------------------------------------- */ @@ -51,13 +51,13 @@ bool CThmUtil::FromLog( vector &guesses ) // static void RotateTab( TAffine &Tab, const TAffine &Tdfm, double ang0 ) { - TAffine R; - double Vx = Tab.t[2], - Vy = Tab.t[5]; + TAffine R; + double Vx = Tab.t[2], + Vy = Tab.t[5]; - R.NUSetRot( ang0 * PI/180.0 ); - Tab = R * Tdfm; - Tab.SetXY( Vx, Vy ); + R.NUSetRot( ang0 * PI/180.0 ); + Tab = R * Tdfm; + Tab.SetXY( Vx, Vy ); } /* --------------------------------------------------------------- */ @@ -87,73 +87,73 @@ static void RotateTab( TAffine &Tab, const TAffine &Tdfm, double ang0 ) // int CThmUtil::SetStartingAngle( const TAffine &Tdfm, double CTR ) { - vector tpr; - int ntpr, nprior = 0; + vector tpr; + int ntpr, nprior = 0; // Handle modes N, C (includes M, Z) - if( MODE == 'N' || MODE == 'C' ) { + if( MODE == 'N' || MODE == 'C' ) { - if( CTR != 999.0 ) - ang0 = CTR; - else - ang0 = 180.0/PI * Tab.GetRadians(); + if( CTR != 999.0 ) + ang0 = CTR; + else + ang0 = 180.0/PI * Tab.GetRadians(); - nprior = 1; - goto adjust_olap; - } + nprior = 1; + goto adjust_olap; + } // Handle mode Y: Try to get prior angles - if( ReadAllThmPair( tpr, A.z, B.z, flog ) - && (ntpr = tpr.size()) ) { + if( ReadAllThmPair( tpr, A.z, B.z, flog ) + && (ntpr = tpr.size()) ) { - vector A; + vector A; - for( int i = 0; i < ntpr; ++i ) { + for( int i = 0; i < ntpr; ++i ) { - if( !tpr[i].err ) - A.push_back( tpr[i].A ); - } + if( !tpr[i].err ) + A.push_back( tpr[i].A ); + } - if( (nprior = A.size()) >= 4 ) - ang0 = MedianVal( A ); - else - nprior = 0; - } + if( (nprior = A.size()) >= 4 ) + ang0 = MedianVal( A ); + else + nprior = 0; + } // Otherwise guess for denovo case - if( !nprior ) { + if( !nprior ) { - if( CTR != 999.0 ) - ang0 = CTR; - else - ang0 = 180.0/PI * Tab.GetRadians(); - } + if( CTR != 999.0 ) + ang0 = CTR; + else + ang0 = 180.0/PI * Tab.GetRadians(); + } // Force tiny ang0 to zero - if( fabs( ang0 ) < 0.001 ) - ang0 = 0.0; + if( fabs( ang0 ) < 0.001 ) + ang0 = 0.0; // Adjust OLAP2D_XL adjust_olap: - if( A.z != B.z ) { + if( A.z != B.z ) { - double a = ang0 * PI/180.0, - c = cos( a ), - s = sin( a ); + double a = ang0 * PI/180.0, + c = cos( a ), + s = sin( a ); - OLAP2D = long(OLAP2D / fmax( c*c, s*s )); - } + OLAP2D = long(OLAP2D / fmax( c*c, s*s )); + } // Adjust Tab - RotateTab( Tab, Tdfm, ang0 ); + RotateTab( Tab, Tdfm, ang0 ); - return nprior; + return nprior; } /* --------------------------------------------------------------- */ @@ -161,31 +161,31 @@ int CThmUtil::SetStartingAngle( const TAffine &Tdfm, double CTR ) /* --------------------------------------------------------------- */ void CThmUtil::SubI_ThesePoints( - SubI &S, - const vector &v, - const vector &p ) + SubI &S, + const vector &v, + const vector &p ) { - IBox B; - int w = px.ws, - np = p.size(); + IBox B; + int w = px.ws, + np = p.size(); - BBoxFromPoints( B, p ); + BBoxFromPoints( B, p ); - S.v.resize( np ); - S.p.resize( np ); + S.v.resize( np ); + S.p.resize( np ); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - const Point& P = p[i]; + const Point& P = p[i]; - S.v[i] = v[int(P.x) + w * int(P.y)]; - S.p[i].x = P.x - B.L; - S.p[i].y = P.y - B.B; - } + S.v[i] = v[int(P.x) + w * int(P.y)]; + S.p[i].x = P.x - B.L; + S.p[i].y = P.y - B.B; + } - S.O = Point( B.L, B.B ); - S.w = B.R - B.L + 1; - S.h = B.T - B.B + 1; + S.O = Point( B.L, B.B ); + S.w = B.R - B.L + 1; + S.h = B.T - B.B + 1; } /* --------------------------------------------------------------- */ @@ -193,43 +193,43 @@ void CThmUtil::SubI_ThesePoints( /* --------------------------------------------------------------- */ bool CThmUtil::SubI_ThisBox( - SubI &S, - const vector &v, - const vector &p, - const IBox &Bolap ) + SubI &S, + const vector &v, + const vector &p, + const IBox &Bolap ) { // Select points in box - int np = p.size(); + int np = p.size(); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - const Point& P = p[i]; + const Point& P = p[i]; - if( P.x >= Bolap.L && P.x <= Bolap.R && - P.y >= Bolap.B && P.y <= Bolap.T ) { + if( P.x >= Bolap.L && P.x <= Bolap.R && + P.y >= Bolap.B && P.y <= Bolap.T ) { - S.p.push_back( P ); - } - } + S.p.push_back( P ); + } + } // Enough points? - if( S.p.size() <= OLAP2D ) { + if( S.p.size() <= OLAP2D ) { - fprintf( flog, - "FAIL: SubI_ThisBox:" - " Small intersection %ld (required %ld).\n", - S.p.size(), OLAP2D ); + fprintf( flog, + "FAIL: SubI_ThisBox:" + " Small intersection %ld (required %ld).\n", + S.p.size(), OLAP2D ); - return false; - } + return false; + } // Set SubI - SubI_ThesePoints( S, v, S.p ); + SubI_ThesePoints( S, v, S.p ); - return true; + return true; } /* --------------------------------------------------------------- */ @@ -241,18 +241,18 @@ bool CThmUtil::SubI_ThisBox( // Return true always as convenience. // bool CThmUtil::Olap_WholeImage( - OlapRec &olp, - const vector &apts, - const vector &bpts ) + OlapRec &olp, + const vector &apts, + const vector &bpts ) { - fprintf( flog, - "Subimage: Using whole images, apix=%ld, bpix=%ld\n", - apts.size(), bpts.size() ); + fprintf( flog, + "Subimage: Using whole images, apix=%ld, bpix=%ld\n", + apts.size(), bpts.size() ); - SubI_ThesePoints( olp.a, *px.avs_aln, apts ); - SubI_ThesePoints( olp.b, *px.bvs_aln, bpts ); + SubI_ThesePoints( olp.a, *px.avs_aln, apts ); + SubI_ThesePoints( olp.b, *px.bvs_aln, bpts ); - return true; + return true; } /* --------------------------------------------------------------- */ @@ -260,51 +260,51 @@ bool CThmUtil::Olap_WholeImage( /* --------------------------------------------------------------- */ bool CThmUtil::Olap_TheseBoxes_NoCR( - OlapRec &olp, - const IBox &Ba, - const IBox &Bb ) + OlapRec &olp, + const IBox &Ba, + const IBox &Bb ) { - int WW = px.ws, - ow = Ba.R - Ba.L + 1, - oh = Ba.T - Ba.B + 1, - np = ow * oh; + int WW = px.ws, + ow = Ba.R - Ba.L + 1, + oh = Ba.T - Ba.B + 1, + np = ow * oh; - fprintf( flog, - "Subimage: Using intersection, w=%d, h=%d, pix=%d\n", - ow, oh, np ); + fprintf( flog, + "Subimage: Using intersection, w=%d, h=%d, pix=%d\n", + ow, oh, np ); // Points - MakeZeroBasedPoints( olp.a.p, ow, oh ); - olp.b.p = olp.a.p; + MakeZeroBasedPoints( olp.a.p, ow, oh ); + olp.b.p = olp.a.p; // Values - const vector& av = *px.avs_aln; - const vector& bv = *px.bvs_aln; + const vector& av = *px.avs_aln; + const vector& bv = *px.bvs_aln; - olp.a.v.resize( np ); - olp.b.v.resize( np ); + olp.a.v.resize( np ); + olp.b.v.resize( np ); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - int y = i / ow; - int x = i - ow * y; + int y = i / ow; + int x = i - ow * y; - olp.a.v[i] = av[Ba.L + x + WW*(Ba.B + y)]; - olp.b.v[i] = bv[Bb.L + x + WW*(Bb.B + y)]; - } + olp.a.v[i] = av[Ba.L + x + WW*(Ba.B + y)]; + olp.b.v[i] = bv[Bb.L + x + WW*(Bb.B + y)]; + } // Dimensions - olp.a.O = Point( Ba.L, Ba.B ); - olp.b.O = Point( Bb.L, Bb.B ); - olp.a.w = ow; - olp.b.w = ow; - olp.a.h = oh; - olp.b.h = oh; + olp.a.O = Point( Ba.L, Ba.B ); + olp.b.O = Point( Bb.L, Bb.B ); + olp.a.w = ow; + olp.b.w = ow; + olp.a.h = oh; + olp.b.h = oh; - return true; + return true; } /* --------------------------------------------------------------- */ @@ -317,32 +317,32 @@ bool CThmUtil::Olap_TheseBoxes_NoCR( // bool CThmUtil::Olap_WholeImage_NoCR( OlapRec &olp ) { - int w = px.ws, - h = px.hs; + int w = px.ws, + h = px.hs; - fprintf( flog, - "Subimage: Using whole images, pix=%d\n", w * h ); + fprintf( flog, + "Subimage: Using whole images, pix=%d\n", w * h ); // Values - olp.a.v = *px.avs_aln; - olp.b.v = *px.bvs_aln; + olp.a.v = *px.avs_aln; + olp.b.v = *px.bvs_aln; // Points - MakeZeroBasedPoints( olp.a.p, w, h ); - olp.b.p = olp.a.p; + MakeZeroBasedPoints( olp.a.p, w, h ); + olp.b.p = olp.a.p; // Dimensions - olp.a.O = Point( 0, 0 ); - olp.b.O = olp.a.O; - olp.a.w = w; - olp.b.w = w; - olp.a.h = h; - olp.b.h = h; + olp.a.O = Point( 0, 0 ); + olp.b.O = olp.a.O; + olp.a.w = w; + olp.b.w = w; + olp.a.h = h; + olp.b.h = h; - return true; + return true; } /* --------------------------------------------------------------- */ @@ -353,24 +353,24 @@ void CThmUtil::GetOlapBoxes( IBox &Ba, IBox &Bb, double XYCONF ) { // Get displacements of a in b-system - int dx, dy; + int dx, dy; - { - Point XY; + { + Point XY; - Tab.Transform( XY ); + Tab.Transform( XY ); - dx = int(XYCONF * XY.x / px.scl); - dy = int(XYCONF * XY.y / px.scl); - } + dx = int(XYCONF * XY.x / px.scl); + dy = int(XYCONF * XY.y / px.scl); + } // Use offsets and image size to determine // {Ba, Bb} overlap boxes. - int w = px.ws, - h = px.hs; + int w = px.ws, + h = px.hs; - BoxesFromShifts( Ba, Bb, w, h, w, h, dx, dy ); + BoxesFromShifts( Ba, Bb, w, h, w, h, dx, dy ); } /* --------------------------------------------------------------- */ @@ -383,46 +383,46 @@ void CThmUtil::GetOlapBoxes( IBox &Ba, IBox &Bb, double XYCONF ) // Return true if non-empty olap. // bool CThmUtil::Crop( - OlapRec &olp, - const ConnRegion &acr, - const ConnRegion &bcr, - double XYCONF ) + OlapRec &olp, + const ConnRegion &acr, + const ConnRegion &bcr, + double XYCONF ) { // Use whole images if no confidence - if( !XYCONF ) - return Olap_WholeImage( olp, acr.pts, bcr.pts ); + if( !XYCONF ) + return Olap_WholeImage( olp, acr.pts, bcr.pts ); // Get overlap boxes - IBox Ba, Bb; + IBox Ba, Bb; - GetOlapBoxes( Ba, Bb, XYCONF ); + GetOlapBoxes( Ba, Bb, XYCONF ); // Test if sufficient overlap - int ow = Ba.R - Ba.L + 1, - oh = Ba.T - Ba.B + 1, - min1d = max( OLAP1D, 8 ); + int ow = Ba.R - Ba.L + 1, + oh = Ba.T - Ba.B + 1, + min1d = max( OLAP1D, 8 ); - if( ow < min1d || oh < min1d ) { - fprintf( flog, "Subimage: 1D overlap too small.\n" ); - return Olap_WholeImage( olp, acr.pts, bcr.pts ); - } + if( ow < min1d || oh < min1d ) { + fprintf( flog, "Subimage: 1D overlap too small.\n" ); + return Olap_WholeImage( olp, acr.pts, bcr.pts ); + } // Set using overlap - fprintf( flog, - "Subimage: Using intersection, w=%d, h=%d, pix=%d\n", - ow, oh, ow * oh ); + fprintf( flog, + "Subimage: Using intersection, w=%d, h=%d, pix=%d\n", + ow, oh, ow * oh ); - if( !SubI_ThisBox( olp.a, *px.avs_aln, acr.pts, Ba ) || - !SubI_ThisBox( olp.b, *px.bvs_aln, bcr.pts, Bb ) ) { + if( !SubI_ThisBox( olp.a, *px.avs_aln, acr.pts, Ba ) || + !SubI_ThisBox( olp.b, *px.bvs_aln, bcr.pts, Bb ) ) { - return false; - } + return false; + } - return true; + return true; } /* --------------------------------------------------------------- */ @@ -438,29 +438,29 @@ bool CThmUtil::Crop_NoCR( OlapRec &olp, double XYCONF ) { // Use whole images if no confidence - if( !XYCONF ) - return Olap_WholeImage_NoCR( olp ); + if( !XYCONF ) + return Olap_WholeImage_NoCR( olp ); // Get overlap boxes - IBox Ba, Bb; + IBox Ba, Bb; - GetOlapBoxes( Ba, Bb, XYCONF ); + GetOlapBoxes( Ba, Bb, XYCONF ); // Test if sufficient overlap - int ow = Ba.R - Ba.L + 1, - oh = Ba.T - Ba.B + 1, - min1d = max( OLAP1D, 8 ); + int ow = Ba.R - Ba.L + 1, + oh = Ba.T - Ba.B + 1, + min1d = max( OLAP1D, 8 ); - if( ow < min1d || oh < min1d ) { - fprintf( flog, "Subimage: 1D overlap too small.\n" ); - return Olap_WholeImage_NoCR( olp ); - } + if( ow < min1d || oh < min1d ) { + fprintf( flog, "Subimage: 1D overlap too small.\n" ); + return Olap_WholeImage_NoCR( olp ); + } // Set using overlap - return Olap_TheseBoxes_NoCR( olp, Ba, Bb ); + return Olap_TheseBoxes_NoCR( olp, Ba, Bb ); } /* --------------------------------------------------------------- */ @@ -468,58 +468,58 @@ bool CThmUtil::Crop_NoCR( OlapRec &olp, double XYCONF ) /* --------------------------------------------------------------- */ bool CThmUtil::MakeThumbs( - ThmRec &thm, - const OlapRec &olp, - int decfactor ) + ThmRec &thm, + const OlapRec &olp, + int decfactor ) { - thm.av = olp.a.v; - thm.bv = olp.b.v; - thm.ap = olp.a.p; - thm.bp = olp.b.p; - thm.ftc.clear(); - thm.reqArea = OLAP2D; - thm.olap1D = OLAP1D; - thm.scl = decfactor; + thm.av = olp.a.v; + thm.bv = olp.b.v; + thm.ap = olp.a.p; + thm.bp = olp.b.p; + thm.ftc.clear(); + thm.reqArea = OLAP2D; + thm.olap1D = OLAP1D; + thm.scl = decfactor; - if( decfactor > 1 ) { + if( decfactor > 1 ) { - DecimateVector( thm.ap, thm.av, olp.a.w, olp.a.h, decfactor ); - DecimateVector( thm.bp, thm.bv, olp.b.w, olp.b.h, decfactor ); + DecimateVector( thm.ap, thm.av, olp.a.w, olp.a.h, decfactor ); + DecimateVector( thm.bp, thm.bv, olp.b.w, olp.b.h, decfactor ); - thm.reqArea /= decfactor * decfactor; - thm.olap1D /= decfactor; + thm.reqArea /= decfactor * decfactor; + thm.olap1D /= decfactor; - fprintf( flog, - "Thumbs: After decimation %ld pts, reqArea %ld, thmscl %d\n", - thm.ap.size(), thm.reqArea, thm.scl ); - } + fprintf( flog, + "Thumbs: After decimation %ld pts, reqArea %ld, thmscl %d\n", + thm.ap.size(), thm.reqArea, thm.scl ); + } - if( thm.ap.size() < thm.reqArea ) { + if( thm.ap.size() < thm.reqArea ) { - fprintf( flog, - "FAIL: Thumbs: Small intersection %ld (required %ld).\n", - thm.ap.size(), thm.reqArea ); + fprintf( flog, + "FAIL: Thumbs: Small intersection %ld (required %ld).\n", + thm.ap.size(), thm.reqArea ); - return false; - } + return false; + } - if( !Normalize( thm.av ) ) { + if( !Normalize( thm.av ) ) { - fprintf( flog, - "FAIL: Thumbs: Image A intersection region: stdev = 0.\n" ); + fprintf( flog, + "FAIL: Thumbs: Image A intersection region: stdev = 0.\n" ); - return false; - } + return false; + } - if( !Normalize( thm.bv ) ) { + if( !Normalize( thm.bv ) ) { - fprintf( flog, - "FAIL: Thumbs: Image B intersection region: stdev = 0.\n" ); + fprintf( flog, + "FAIL: Thumbs: Image B intersection region: stdev = 0.\n" ); - return false; - } + return false; + } - return true; + return true; } /* --------------------------------------------------------------- */ @@ -527,74 +527,74 @@ bool CThmUtil::MakeThumbs( /* --------------------------------------------------------------- */ bool CThmUtil::Disc( - CorRec &best, - CThmScan &S, - ThmRec &thm, - const OlapRec &olp, - int PRETWEAK ) + CorRec &best, + CThmScan &S, + ThmRec &thm, + const OlapRec &olp, + int PRETWEAK ) { - Point delta, TaO = olp.a.O; - int Ox, Oy, Rx; + Point delta, TaO = olp.a.O; + int Ox, Oy, Rx; - Tab.Transform( delta ); - Tab.Apply_R_Part( TaO ); + Tab.Transform( delta ); + Tab.Apply_R_Part( TaO ); - Ox = ROUND((delta.x / px.scl - olp.b.O.x + TaO.x) / thm.scl); - Oy = ROUND((delta.y / px.scl - olp.b.O.y + TaO.y) / thm.scl); - Rx = LIMXY / (px.scl * thm.scl); + Ox = ROUND((delta.x / px.scl - olp.b.O.x + TaO.x) / thm.scl); + Oy = ROUND((delta.y / px.scl - olp.b.O.y + TaO.y) / thm.scl); + Rx = LIMXY / (px.scl * thm.scl); - fprintf( flog, "SetDisc( %d, %d, %d, %d )\n", Ox, Oy, Rx, Rx ); + fprintf( flog, "SetDisc( %d, %d, %d, %d )\n", Ox, Oy, Rx, Rx ); - S.SetUseCorrR( true ); - S.SetDisc( Ox, Oy, Rx, Rx ); - S.RFromAngle( best, ang0, thm ); + S.SetUseCorrR( true ); + S.SetDisc( Ox, Oy, Rx, Rx ); + S.RFromAngle( best, ang0, thm ); - fprintf( flog, - "Initial: R=%6.3f, A=%8.3f, X=%8.2f, Y=%8.2f\n", - best.R, best.A, best.X, best.Y ); + fprintf( flog, + "Initial: R=%6.3f, A=%8.3f, X=%8.2f, Y=%8.2f\n", + best.R, best.A, best.X, best.Y ); - if( dbgCor ) - return false; + if( dbgCor ) + return false; - if( best.R < RTRSH ) { + if( best.R < RTRSH ) { - if( PRETWEAK ) { + if( PRETWEAK ) { - S.Pretweaks( best.R, ang0, thm ); - S.RFromAngle( best, ang0, thm ); + S.Pretweaks( best.R, ang0, thm ); + S.RFromAngle( best, ang0, thm ); - fprintf( flog, - "Tweaked: R=%6.3f, A=%8.3f, X=%8.2f, Y=%8.2f\n", - best.R, best.A, best.X, best.Y ); - } + fprintf( flog, + "Tweaked: R=%6.3f, A=%8.3f, X=%8.2f, Y=%8.2f\n", + best.R, best.A, best.X, best.Y ); + } - if( best.R < RTRSH ) { + if( best.R < RTRSH ) { - fprintf( flog, - "FAIL: Approx: MODE=N R=%g below thresh=%g\n", - best.R, RTRSH ); + fprintf( flog, + "FAIL: Approx: MODE=N R=%g below thresh=%g\n", + best.R, RTRSH ); - return Failure( best, errLowRPrior ); - } - } + return Failure( best, errLowRPrior ); + } + } - Point dS( - (best.X - Ox) * (thm.scl * px.scl), - (best.Y - Oy) * (thm.scl * px.scl) ); - int dR = int(sqrt( dS.RSqr() )); + Point dS( + (best.X - Ox) * (thm.scl * px.scl), + (best.Y - Oy) * (thm.scl * px.scl) ); + int dR = int(sqrt( dS.RSqr() )); - fprintf( flog, - "Peak-Disc: dR %d dX %d dY %d\n", dR, int(dS.x), int(dS.y) ); + fprintf( flog, + "Peak-Disc: dR %d dX %d dY %d\n", dR, int(dS.x), int(dS.y) ); - if( dR >= LIMXY ) { + if( dR >= LIMXY ) { - fprintf( flog, - "FAIL: Approx: Peak outside disc dR=%d\n", dR ); + fprintf( flog, + "FAIL: Approx: Peak outside disc dR=%d\n", dR ); - return Failure( best, errLowRPrior ); - } + return Failure( best, errLowRPrior ); + } - return true; + return true; } /* --------------------------------------------------------------- */ @@ -603,15 +603,15 @@ bool CThmUtil::Disc( void CThmUtil::DebugSweepKill( CThmScan &S, ThmRec thm ) { - const double center = ang0; - const double hlfwid = HFANGPR; - const double step = 0.1; + const double center = ang0; + const double hlfwid = HFANGPR; + const double step = 0.1; - //const double hlfwid = 1.0; - //const double step = 0.01; + //const double hlfwid = 1.0; + //const double step = 0.01; - S.DebugAngs( A.z, A.id, B.z, B.id, center, hlfwid, step, thm ); - exit( 42 ); + S.DebugAngs( A.z, A.id, B.z, B.id, center, hlfwid, step, thm ); + exit( 42 ); } /* --------------------------------------------------------------- */ @@ -619,31 +619,31 @@ void CThmUtil::DebugSweepKill( CThmScan &S, ThmRec thm ) /* --------------------------------------------------------------- */ bool CThmUtil::Sweep( - CorRec &best, - CThmScan &S, - ThmRec &thm, - int nPrior ) + CorRec &best, + CThmScan &S, + ThmRec &thm, + int nPrior ) { // Debug and exit - //DebugSweepKill( S, thm ); + //DebugSweepKill( S, thm ); - if( dbgCor ) { - S.RFromAngle( best, ang0, thm ); - return false; - } + if( dbgCor ) { + S.RFromAngle( best, ang0, thm ); + return false; + } // Sweep - if( nPrior ) { + if( nPrior ) { - if( !S.UsePriorAngles( best, nPrior, ang0, HFANGPR, thm ) ) - return Failure( best, S.GetErr() ); - } - else if( !S.DenovoBestAngle( best, ang0, HFANGDN, 0.5, thm, true ) ) - return Failure( best, S.GetErr() ); + if( !S.UsePriorAngles( best, nPrior, ang0, HFANGPR, thm ) ) + return Failure( best, S.GetErr() ); + } + else if( !S.DenovoBestAngle( best, ang0, HFANGDN, 0.5, thm, true ) ) + return Failure( best, S.GetErr() ); - return true; + return true; } /* --------------------------------------------------------------- */ @@ -664,16 +664,16 @@ bool CThmUtil::Sweep( // which shows directly how to translate V to the image corner. // void CThmUtil::IsectToImageCoords( - CorRec &best, - Point aO, - const Point &bO ) + CorRec &best, + Point aO, + const Point &bO ) { - best.T.Apply_R_Part( aO ); + best.T.Apply_R_Part( aO ); - best.X += bO.x - aO.x; - best.Y += bO.y - aO.y; + best.X += bO.x - aO.x; + best.Y += bO.y - aO.y; - best.T.SetXY( best.X, best.Y ); + best.T.SetXY( best.X, best.Y ); } /* --------------------------------------------------------------- */ @@ -685,89 +685,89 @@ void CThmUtil::IsectToImageCoords( // ****************************** static void SQD( - double &sqd, - double &prd, - int &N, - const PixPair &px, - const TAffine &T ) + double &sqd, + double &prd, + int &N, + const PixPair &px, + const TAffine &T ) { - sqd = 0.0; - prd = 0.0; - N = 0; + sqd = 0.0; + prd = 0.0; + N = 0; - const vector& av = *px.avs_vfy; - const vector& bv = *px.bvs_vfy; + const vector& av = *px.avs_vfy; + const vector& bv = *px.bvs_vfy; - vector ap, bp; - int w = px.ws, - h = px.hs, - np = w * h; + vector ap, bp; + int w = px.ws, + h = px.hs, + np = w * h; // Fill points - MakeZeroBasedPoints( ap, w, h ); - bp = ap; + MakeZeroBasedPoints( ap, w, h ); + bp = ap; // Sums - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - Point p = ap[i]; + Point p = ap[i]; - T.Transform( p ); + T.Transform( p ); - if( p.x >= 0.0 && p.x < w-1 && - p.y >= 0.0 && p.y < h-1 ) { + if( p.x >= 0.0 && p.x < w-1 && + p.y >= 0.0 && p.y < h-1 ) { - double d = InterpolatePixel( p.x, p.y, bv, w ); + double d = InterpolatePixel( p.x, p.y, bv, w ); - ++N; - prd += av[i] * d; - d -= av[i]; - sqd += d * d; - } - } + ++N; + prd += av[i] * d; + d -= av[i]; + sqd += d * d; + } + } } void CThmUtil::RecordSumSqDif( const TAffine &T ) { - CMutex M; - char name[256]; + CMutex M; + char name[256]; - sprintf( name, "sqd_%d_%d", A.z, B.z ); + sprintf( name, "sqd_%d_%d", A.z, B.z ); - if( M.Get( name ) ) { + if( M.Get( name ) ) { - sprintf( name, "SmSqDf_%d^%d.log", A.z, B.z ); + sprintf( name, "SmSqDf_%d^%d.log", A.z, B.z ); - FILE *f; - int is; + FILE *f; + int is; - f = fopen( name, "r" ); - if( is = (f != NULL) ) - fclose( f ); + f = fopen( name, "r" ); + if( is = (f != NULL) ) + fclose( f ); - f = fopen( name, "a" ); + f = fopen( name, "a" ); - if( f ) { + if( f ) { - if( !is ) - fprintf( f, "TileA\tTileB\tSQ\tR\tN\tSQ/N\tR/N\n" ); + if( !is ) + fprintf( f, "TileA\tTileB\tSQ\tR\tN\tSQ/N\tR/N\n" ); - double sqd, prd; - int N; + double sqd, prd; + int N; - SQD( sqd, prd, N, px, T ); + SQD( sqd, prd, N, px, T ); - fprintf( f, "%d\t%d\t%f\t%f\t%d\t%f\t%f\n", - A.id, B.id, sqd, prd, N, sqd/N, prd/N ); - fflush( f ); - fclose( f ); - } - } + fprintf( f, "%d\t%d\t%f\t%f\t%d\t%f\t%f\n", + A.id, B.id, sqd, prd, N, sqd/N, prd/N ); + fflush( f ); + fclose( f ); + } + } - M.Release(); + M.Release(); } /* --------------------------------------------------------------- */ @@ -776,12 +776,12 @@ void CThmUtil::RecordSumSqDif( const TAffine &T ) void CThmUtil::FullScaleReportToLog( CorRec &best ) { - best.T.MulXY( px.scl ); + best.T.MulXY( px.scl ); - fprintf( flog, "Approx: Returning A=%f, R=%f, X=%f, Y=%f\n", - best.A, best.R, best.T.t[2], best.T.t[5] ); + fprintf( flog, "Approx: Returning A=%f, R=%f, X=%f, Y=%f\n", + best.A, best.R, best.T.t[2], best.T.t[5] ); - best.T.TPrint( flog, "Approx: Best transform " ); + best.T.TPrint( flog, "Approx: Best transform " ); } /* --------------------------------------------------------------- */ @@ -789,20 +789,20 @@ void CThmUtil::FullScaleReportToLog( CorRec &best ) /* --------------------------------------------------------------- */ double CThmUtil::XYChange( - CorRec CR, - ThmRec &thm, - const OlapRec &olp ) + CorRec CR, + ThmRec &thm, + const OlapRec &olp ) { - CR.X *= thm.scl; - CR.Y *= thm.scl; - IsectToImageCoords( CR, olp.a.O, olp.b.O ); - CR.T.MulXY( px.scl ); + CR.X *= thm.scl; + CR.Y *= thm.scl; + IsectToImageCoords( CR, olp.a.O, olp.b.O ); + CR.T.MulXY( px.scl ); - TAffine I; - I.InverseOf( Tab ); - I = I * CR.T; + TAffine I; + I.InverseOf( Tab ); + I = I * CR.T; - return sqrt( I.t[2]*I.t[2] + I.t[5]*I.t[5] ); + return sqrt( I.t[2]*I.t[2] + I.t[5]*I.t[5] ); } /* --------------------------------------------------------------- */ @@ -816,32 +816,32 @@ double CThmUtil::XYChange( // bool CThmUtil::Check_LIMXY( const TAffine &Tbest ) { - TAffine I; + TAffine I; // Always report - Tab.TPrint( flog, "Approx: Orig transform " ); + Tab.TPrint( flog, "Approx: Orig transform " ); - I.InverseOf( Tab ); - I = I * Tbest; - I .TPrint( flog, "Approx: Idnt transform " ); + I.InverseOf( Tab ); + I = I * Tbest; + I .TPrint( flog, "Approx: Idnt transform " ); - double err = sqrt( I.t[2]*I.t[2] + I.t[5]*I.t[5] ); + double err = sqrt( I.t[2]*I.t[2] + I.t[5]*I.t[5] ); - fprintf( flog, "Approx: err = %g, max = %d\n", err, LIMXY ); + fprintf( flog, "Approx: err = %g, max = %d\n", err, LIMXY ); // Optional rejection test - if( LIMXY && err > LIMXY ) { + if( LIMXY && err > LIMXY ) { - fprintf( flog, - "FAIL: Approx: Too different from Tab err=%g, max=%d\n", - err, LIMXY ); + fprintf( flog, + "FAIL: Approx: Too different from Tab err=%g, max=%d\n", + err, LIMXY ); - return false; - } + return false; + } - return true; + return true; } /* --------------------------------------------------------------- */ @@ -850,17 +850,17 @@ bool CThmUtil::Check_LIMXY( const TAffine &Tbest ) void CThmUtil::TabulateResult( const CorRec &best, int err ) { - if( !WTHMPR ) - return; + if( !WTHMPR ) + return; - ThmPair tpr; + ThmPair tpr; - tpr.T = best.T; - tpr.A = best.A; - tpr.R = best.R; - tpr.err = err; + tpr.T = best.T; + tpr.A = best.A; + tpr.R = best.R; + tpr.err = err; - WriteThmPair( tpr, A.z, A.id, acr, B.z, B.id, bcr ); + WriteThmPair( tpr, A.z, A.id, acr, B.z, B.id, bcr ); } /* --------------------------------------------------------------- */ @@ -869,8 +869,8 @@ void CThmUtil::TabulateResult( const CorRec &best, int err ) bool CThmUtil::Failure( const CorRec &best, int err ) { - TabulateResult( best, err ); - return false; + TabulateResult( best, err ); + return false; } /* --------------------------------------------------------------- */ @@ -890,11 +890,11 @@ bool CThmUtil::Failure( const CorRec &best, int err ) // Return true if LIMXY passed. // bool CThmUtil::Finish( - CorRec &best, - CThmScan &S, - ThmRec &thm, - const OlapRec &olp, - int TWEAKS ) + CorRec &best, + CThmScan &S, + ThmRec &thm, + const OlapRec &olp, + int TWEAKS ) { // Tweaks // @@ -905,69 +905,69 @@ bool CThmUtil::Finish( // result of tweaking further be closer to the expected result. // Otherwise we reject the tweaks and revert. - if( TWEAKS ) { + if( TWEAKS ) { - if( A.z != B.z && MODE == 'N' ) { + if( A.z != B.z && MODE == 'N' ) { - CorRec CR0 = best; - TAffine Tptwk; - double err, err0; + CorRec CR0 = best; + TAffine Tptwk; + double err, err0; - err0 = XYChange( best, thm, olp ); - S.GetTptwk( Tptwk ); + err0 = XYChange( best, thm, olp ); + S.GetTptwk( Tptwk ); - S.PostTweaks( best, thm ); + S.PostTweaks( best, thm ); - err = XYChange( best, thm, olp ); + err = XYChange( best, thm, olp ); - fprintf( flog, - "Approx: Tweak effect on R: before %g after %g -- ", - err0, err ); + fprintf( flog, + "Approx: Tweak effect on R: before %g after %g -- ", + err0, err ); - if( err > err0 && err > 0.66 * LIMXY ) { - fprintf( flog, "revert.\n" ); - S.SetTptwk( Tptwk ); - best = CR0; - } - else - fprintf( flog, "keep.\n" ); - } - else - S.PostTweaks( best, thm ); - } + if( err > err0 && err > 0.66 * LIMXY ) { + fprintf( flog, "revert.\n" ); + S.SetTptwk( Tptwk ); + best = CR0; + } + else + fprintf( flog, "keep.\n" ); + } + else + S.PostTweaks( best, thm ); + } // Undo thumb scaling - best.X *= thm.scl; - best.Y *= thm.scl; + best.X *= thm.scl; + best.Y *= thm.scl; // Full resolution (px.scl) adjustment - if( !MakeThumbs( thm, olp, 1 ) ) - return false; + if( !MakeThumbs( thm, olp, 1 ) ) + return false; - S.FinishAtFullRes( best, thm ); + S.FinishAtFullRes( best, thm ); // Translate coords - IsectToImageCoords( best, olp.a.O, olp.b.O ); + IsectToImageCoords( best, olp.a.O, olp.b.O ); // Make Reports - //RecordSumSqDif( best.T ); + //RecordSumSqDif( best.T ); - FullScaleReportToLog( best ); + FullScaleReportToLog( best ); // Sanity check translation - if( !Check_LIMXY( best.T ) ) - return false; + if( !Check_LIMXY( best.T ) ) + return false; // Tabulate - TabulateResult( best, S.GetErr() ); + TabulateResult( best, S.GetErr() ); - return true; + return true; } diff --git a/1_DMesh/CThmUtil.h b/1_DMesh/CThmUtil.h index da48e31..eb3b084 100644 --- a/1_DMesh/CThmUtil.h +++ b/1_DMesh/CThmUtil.h @@ -13,14 +13,14 @@ /* --------------------------------------------------------------- */ typedef struct { - vector v; - vector p; - Point O; // subimage ref. point - int w, h; // sub-img dims + vector v; + vector p; + Point O; // subimage ref. point + int w, h; // sub-img dims } SubI; typedef struct { - SubI a, b; + SubI a, b; } OlapRec; /* --------------------------------------------------------------- */ @@ -30,137 +30,137 @@ typedef struct { class CThmUtil { private: - const PicSpec &A, &B; - const int acr, bcr; - const PixPair &px; - long &OLAP2D; - FILE *flog; + const PicSpec &A, &B; + const int acr, bcr; + const PixPair &px; + long &OLAP2D; + FILE *flog; public: - TAffine - double ang0, - HFANGDN, - HFANGPR, - RTRSH; - int OLAP1D, - MODE, - LIMXY, - WTHMPR; + TAffine + double ang0, + HFANGDN, + HFANGPR, + RTRSH; + int OLAP1D, + MODE, + LIMXY, + WTHMPR; public: - CThmUtil( - const PicSpec &A, - int acr, - const PicSpec &B, - int bcr, - const PixPair &px, - TAffine &Tab, - long &OLAP2D, - FILE *flog ) - : - A(A), B(B), acr(acr), bcr(bcr), - px(px), Tab(Tab), OLAP2D(OLAP2D), - flog(flog), ang0(0.0) - {}; - - void SetParams( - double HFANGDN, - double HFANGPR, - double RTRSH, - int OLAP1D, - int MODE, - int LIMXY, - int WTHMPR ) - { - this->HFANGDN=HFANGDN; this->HFANGPR=HFANGPR; - this->RTRSH=RTRSH; this->OLAP1D=OLAP1D; - this->MODE=MODE; this->LIMXY=LIMXY; - this->WTHMPR=WTHMPR; - }; - - bool Echo( vector &guesses ); - bool FromLog( vector &guesses ); - - int SetStartingAngle( const TAffine &Tdfm, double CTR ); - - void SubI_ThesePoints( - SubI &S, - const vector &v, - const vector &p ); - - bool SubI_ThisBox( - SubI &S, - const vector &v, - const vector &p, - const IBox &Bolap ); - - bool Olap_WholeImage( - OlapRec &olp, - const vector &apts, - const vector &bpts ); - - bool Olap_TheseBoxes_NoCR( - OlapRec &olp, - const IBox &Ba, - const IBox &Bb ); - - bool Olap_WholeImage_NoCR( OlapRec &olp ); - - void GetOlapBoxes( IBox &Ba, IBox &Bb, double XYCONF ); - - bool Crop( - OlapRec &olp, - const ConnRegion &acr, - const ConnRegion &bcr, - double XYCONF ); - - bool Crop_NoCR( OlapRec &olp, double XYCONF ); - - bool MakeThumbs( - ThmRec &thm, - const OlapRec &olp, - int decfactor ); - - bool Disc( - CorRec &best, - CThmScan &S, - ThmRec &thm, - const OlapRec &olp, - int PRETWEAK ); - - void DebugSweepKill( CThmScan &S, ThmRec thm ); - - bool Sweep( - CorRec &best, - CThmScan &S, - ThmRec &thm, - int nPrior ); - - void IsectToImageCoords( - CorRec &best, - Point aO, - const Point &bO ); - - void RecordSumSqDif( const TAffine &T ); - - void FullScaleReportToLog( CorRec &best ); - - double XYChange( - CorRec CR, - ThmRec &thm, - const OlapRec &olp ); - - bool Check_LIMXY( const TAffine &Tbest ); - - void TabulateResult( const CorRec &best, int err ); - bool Failure( const CorRec &best, int err ); - - bool Finish( - CorRec &best, - CThmScan &S, - ThmRec &thm, - const OlapRec &olp, - int TWEAKS ); + CThmUtil( + const PicSpec &A, + int acr, + const PicSpec &B, + int bcr, + const PixPair &px, + TAffine &Tab, + long &OLAP2D, + FILE *flog ) + : + A(A), B(B), acr(acr), bcr(bcr), + px(px), Tab(Tab), OLAP2D(OLAP2D), + flog(flog), ang0(0.0) + {}; + + void SetParams( + double HFANGDN, + double HFANGPR, + double RTRSH, + int OLAP1D, + int MODE, + int LIMXY, + int WTHMPR ) + { + this->HFANGDN=HFANGDN; this->HFANGPR=HFANGPR; + this->RTRSH=RTRSH; this->OLAP1D=OLAP1D; + this->MODE=MODE; this->LIMXY=LIMXY; + this->WTHMPR=WTHMPR; + }; + + bool Echo( vector &guesses ); + bool FromLog( vector &guesses ); + + int SetStartingAngle( const TAffine &Tdfm, double CTR ); + + void SubI_ThesePoints( + SubI &S, + const vector &v, + const vector &p ); + + bool SubI_ThisBox( + SubI &S, + const vector &v, + const vector &p, + const IBox &Bolap ); + + bool Olap_WholeImage( + OlapRec &olp, + const vector &apts, + const vector &bpts ); + + bool Olap_TheseBoxes_NoCR( + OlapRec &olp, + const IBox &Ba, + const IBox &Bb ); + + bool Olap_WholeImage_NoCR( OlapRec &olp ); + + void GetOlapBoxes( IBox &Ba, IBox &Bb, double XYCONF ); + + bool Crop( + OlapRec &olp, + const ConnRegion &acr, + const ConnRegion &bcr, + double XYCONF ); + + bool Crop_NoCR( OlapRec &olp, double XYCONF ); + + bool MakeThumbs( + ThmRec &thm, + const OlapRec &olp, + int decfactor ); + + bool Disc( + CorRec &best, + CThmScan &S, + ThmRec &thm, + const OlapRec &olp, + int PRETWEAK ); + + void DebugSweepKill( CThmScan &S, ThmRec thm ); + + bool Sweep( + CorRec &best, + CThmScan &S, + ThmRec &thm, + int nPrior ); + + void IsectToImageCoords( + CorRec &best, + Point aO, + const Point &bO ); + + void RecordSumSqDif( const TAffine &T ); + + void FullScaleReportToLog( CorRec &best ); + + double XYChange( + CorRec CR, + ThmRec &thm, + const OlapRec &olp ); + + bool Check_LIMXY( const TAffine &Tbest ); + + void TabulateResult( const CorRec &best, int err ); + bool Failure( const CorRec &best, int err ); + + bool Finish( + CorRec &best, + CThmScan &S, + ThmRec &thm, + const OlapRec &olp, + int TWEAKS ); }; diff --git a/1_DMesh/CreateMesh.cpp b/1_DMesh/CreateMesh.cpp index 2cf9207..e6d88db 100644 --- a/1_DMesh/CreateMesh.cpp +++ b/1_DMesh/CreateMesh.cpp @@ -43,13 +43,13 @@ static int dys[8] = {0, 1, 1, 1, 0, -1, -1, -1}; class PQElm { public: - int to; // from node zero to here... - double cost; // and the cost to get here + int to; // from node zero to here... + double cost; // and the cost to get here public: - PQElm( int to, double cost ) : to(to), cost(cost) {}; + PQElm( int to, double cost ) : to(to), cost(cost) {}; - bool operator < ( const PQElm &rhs ) const - {return cost > rhs.cost;}; // priority low if cost high + bool operator < ( const PQElm &rhs ) const + {return cost > rhs.cost;}; // priority low if cost high }; /* --------------------------------------------------------------- */ @@ -60,23 +60,23 @@ class PQElm { class Grf{ public: - int x, y, // vertex coordinates - back; // node we came from - double cost; // cost to get here from node zero + int x, y, // vertex coordinates + back; // node we came from + double cost; // cost to get here from node zero public: - Grf( const vertex &corner, int back, double cost ) - : x(corner.x), y(corner.y), back(back), cost(cost) {}; + Grf( const vertex &corner, int back, double cost ) + : x(corner.x), y(corner.y), back(back), cost(cost) {}; - double Dist( const Grf& rhs ) const; + double Dist( const Grf& rhs ) const; }; double Grf::Dist( const Grf& rhs ) const { - double dx = x - rhs.x, - dy = y - rhs.y; + double dx = x - rhs.x, + dy = y - rhs.y; - return sqrt( dx*dx + dy*dy ); + return sqrt( dx*dx + dy*dy ); } /* --------------------------------------------------------------- */ @@ -84,11 +84,11 @@ double Grf::Dist( const Grf& rhs ) const /* --------------------------------------------------------------- */ static double SegPointDist( - const Grf &v0, - const Grf &v1, - const Grf &v2 ) + const Grf &v0, + const Grf &v1, + const Grf &v2 ) { - return SegPointDist( v0.x, v0.y, v1.x, v1.y, v2.x, v2.y ); + return SegPointDist( v0.x, v0.y, v1.x, v1.y, v2.x, v2.y ); } /* --------------------------------------------------------------- */ @@ -101,12 +101,12 @@ static double SegPointDist( // static double ShortcutCost( const vector &v, int s, int e ) { - double sum = 0.0; + double sum = 0.0; - for( int i = s + 1; i < e; ++i ) - sum += SegPointDist( v[s], v[e], v[i] ); + for( int i = s + 1; i < e; ++i ) + sum += SegPointDist( v[s], v[e], v[i] ); - return sum; + return sum; } /* --------------------------------------------------------------- */ @@ -114,40 +114,40 @@ static double ShortcutCost( const vector &v, int s, int e ) /* --------------------------------------------------------------- */ static void SetEdgeLimits( - double &lmin, - double &lmax, - const IBox &B, - FILE* flog ) + double &lmin, + double &lmax, + const IBox &B, + FILE* flog ) { - int bx = B.R - B.L, by = B.T - B.B; + int bx = B.R - B.L, by = B.T - B.B; // Prefer triangle edges in range [MNL, 2xMNL] and generally // prefer a max:min ratio of about 2:1. - lmin = GBL.mch.MNL, - lmax = 2 * lmin; + lmin = GBL.mch.MNL, + lmax = 2 * lmin; // If region skinnier than typical triangle... - if( bx < lmin || by < lmin ) { + if( bx < lmin || by < lmin ) { - // set trial values - lmin = fmin( bx, by ); - lmax = fmax( bx, by ); + // set trial values + lmin = fmin( bx, by ); + lmax = fmax( bx, by ); - // push lmin down more if lmax small - lmin = fmin( lmin, lmax / 2.0 ); + // push lmin down more if lmax small + lmin = fmin( lmin, lmax / 2.0 ); - // split longer dimension - lmax = lmax / 3.0; + // split longer dimension + lmax = lmax / 3.0; - // push lmax up more to restore 2:1 - lmax = fmax( lmax, 2.0 * lmin ); + // push lmax up more to restore 2:1 + lmax = fmax( lmax, 2.0 * lmin ); - fprintf( flog, - "Reducing minl from [%d %d] to [%f %f].\n", - GBL.mch.MNL, 2*GBL.mch.MNL, lmin, lmax ); - } + fprintf( flog, + "Reducing minl from [%d %d] to [%f %f].\n", + GBL.mch.MNL, 2*GBL.mch.MNL, lmin, lmax ); + } } /* --------------------------------------------------------------- */ @@ -160,26 +160,26 @@ static void SetEdgeLimits( // offset control points to real coords before exiting. // static void MakeMap( - vector &map, - int &w, - int &h, - const IBox &B, - const vector &pts ) + vector &map, + int &w, + int &h, + const IBox &B, + const vector &pts ) { - w = B.R - B.L + 3, - h = B.T - B.B + 3; + w = B.R - B.L + 3, + h = B.T - B.B + 3; - map.resize( w * h, 0 ); + map.resize( w * h, 0 ); - int npts = pts.size(); + int npts = pts.size(); - for( int i = 0; i < npts; ++i ) { + for( int i = 0; i < npts; ++i ) { - int x = int(pts[i].x) - B.L + 1; - int y = int(pts[i].y) - B.B + 1; + int x = int(pts[i].x) - B.L + 1; + int y = int(pts[i].y) - B.B + 1; - map[x + w*y] = 1; - } + map[x + w*y] = 1; + } } /* --------------------------------------------------------------- */ @@ -190,37 +190,37 @@ static void MakeMap( // and return true. // static bool FindLeftEdge( - int &x0, - int &y0, - const vector &map, - int w, - int h, - FILE* flog ) + int &x0, + int &y0, + const vector &map, + int w, + int h, + FILE* flog ) { // We position ourselves at horizizontal midline (1,h/2) // and advance to the right until finding a point. - x0 = 1; - y0 = h/2; + x0 = 1; + y0 = h/2; - for( ; x0 < w; ++x0 ) { + for( ; x0 < w; ++x0 ) { - if( map[x0 + w*y0] ) - return true; - } + if( map[x0 + w*y0] ) + return true; + } // Failed. // This could happen if the overlap cut the connected region // into two parts, neither of which intersects the horizonal // midline. Return failure. - fprintf( flog, "Can't find starting point??\n" ); + fprintf( flog, "Can't find starting point??\n" ); #ifdef CREATEMESH_WRITE_DEBUG_IMAGES - Raster8ToTif8( "Bogus3.tif", &map[0], w, h, flog ); + Raster8ToTif8( "Bogus3.tif", &map[0], w, h, flog ); #endif - return false; + return false; } /* --------------------------------------------------------------- */ @@ -230,62 +230,62 @@ static bool FindLeftEdge( // Return true if successfully find a contiguous boundary. // static bool GetBoundaryPoints( - vector &bndry, - const vector &map, - int w, - int h, - int x0, - int y0, - FILE* flog ) + vector &bndry, + const vector &map, + int w, + int h, + int x0, + int y0, + FILE* flog ) { // Starting at x0, y0 and working CCW, collect all points on the // region boundary. - int x = x0, y = y0, dir = 0; + int x = x0, y = y0, dir = 0; - do { + do { - //fprintf( flog, "-- %6d %6d %3d\n", x, y, dir ); + //fprintf( flog, "-- %6d %6d %3d\n", x, y, dir ); - int op = (dir+4)%8; // sweep starts opposite to dir - int k; + int op = (dir+4)%8; // sweep starts opposite to dir + int k; - // Sweep dir CCW until pointing at non-zero neighbor. - // Note that the sweep always starts behind us and is - // always on our exterior flank. + // Sweep dir CCW until pointing at non-zero neighbor. + // Note that the sweep always starts behind us and is + // always on our exterior flank. - for( k = 1; k <= 8; ++k ) { + for( k = 1; k <= 8; ++k ) { - int j = (op+k)%8, - dx = dxs[j], - dy = dys[j]; + int j = (op+k)%8, + dx = dxs[j], + dy = dys[j]; - if( map[x+dx + w*(y+dy)] ) { + if( map[x+dx + w*(y+dy)] ) { - bndry.push_back( vertex( x, y, j ) ); + bndry.push_back( vertex( x, y, j ) ); - x = x + dx; - y = y + dy; - dir = j; + x = x + dx; + y = y + dy; + dir = j; - goto next_bndry_pt; - } - } + goto next_bndry_pt; + } + } - // Failed + // Failed - fprintf( flog, "Input was an isolated pixel??\n" ); + fprintf( flog, "Input was an isolated pixel??\n" ); #ifdef CREATEMESH_WRITE_DEBUG_IMAGES - Raster8ToTif8( "Bogus4.tif", &map[0], w, h, flog ); + Raster8ToTif8( "Bogus4.tif", &map[0], w, h, flog ); #endif - return false; + return false; next_bndry_pt:; - } while( x != x0 || y != y0 ); + } while( x != x0 || y != y0 ); - return true; + return true; } /* --------------------------------------------------------------- */ @@ -293,47 +293,47 @@ next_bndry_pt:; /* --------------------------------------------------------------- */ static void FindCorners( - vector &corners, - const vector &bndry, - FILE* flog ) + vector &corners, + const vector &bndry, + FILE* flog ) { // Compress the ordered boundary points into a list of corners, // that is, the set of points at which the direction changes. - int nbps = bndry.size(); + int nbps = bndry.size(); - for( int i = 0; i < nbps; ++i ) { + for( int i = 0; i < nbps; ++i ) { - int iprev = (i+nbps-1)%nbps; + int iprev = (i+nbps-1)%nbps; - if( bndry[i].dir != bndry[iprev].dir ) { + if( bndry[i].dir != bndry[iprev].dir ) { - vertex v = bndry[i]; + vertex v = bndry[i]; - v.orig = i; - corners.push_back( v ); - } - } + v.orig = i; + corners.push_back( v ); + } + } - int ncorn = corners.size(); + int ncorn = corners.size(); // print corner count - fprintf( flog, - "Got %d corners from %d boundary points.---\n", ncorn, nbps ); + fprintf( flog, + "Got %d corners from %d boundary points.---\n", ncorn, nbps ); // table of corners - fprintf( flog, " Vtx\t Point\t Vx\t Vy\n" ); + fprintf( flog, " Vtx\t Point\t Vx\t Vy\n" ); - for( int i = 0; i < ncorn; ++i ) { + for( int i = 0; i < ncorn; ++i ) { - const vertex& C = corners[i]; + const vertex& C = corners[i]; - fprintf( flog, "%4d\t%6d\t%6d\t%6d\n", i, C.orig, C.x, C.y ); - } + fprintf( flog, "%4d\t%6d\t%6d\t%6d\n", i, C.orig, C.x, C.y ); + } - fprintf( flog, "\n" ); + fprintf( flog, "\n" ); } /* --------------------------------------------------------------- */ @@ -346,58 +346,58 @@ static void FindCorners( // the corner cutting operation that follows this. // static void SplitLongSides( - vector &corners, - double lmin, - FILE* flog ) + vector &corners, + double lmin, + FILE* flog ) { - int ncorn = corners.size(); + int ncorn = corners.size(); - for( int i = 0; i < ncorn; ++i ) { + for( int i = 0; i < ncorn; ++i ) { - int inext = (i+1)%ncorn; - double dx = corners[inext].x - corners[i].x; - double dy = corners[inext].y - corners[i].y; - double len = sqrt( dx*dx + dy*dy ); + int inext = (i+1)%ncorn; + double dx = corners[inext].x - corners[i].x; + double dy = corners[inext].y - corners[i].y; + double len = sqrt( dx*dx + dy*dy ); - // len > lmin/2 ? + // len > lmin/2 ? - if( 2.0 * len > lmin ) { + if( 2.0 * len > lmin ) { - int nins = int(2.0*len/lmin) + 1; + int nins = int(2.0*len/lmin) + 1; - for( int j = 1; j <= nins; ++j ) { + for( int j = 1; j <= nins; ++j ) { - double frac = double(j)/(nins+1); - vertex nv( int(corners[i].x + dx*frac), - int(corners[i].y + dy*frac) ); + double frac = double(j)/(nins+1); + vertex nv( int(corners[i].x + dx*frac), + int(corners[i].y + dy*frac) ); - corners.insert( corners.begin() + i + j, nv ); + corners.insert( corners.begin() + i + j, nv ); - fprintf( flog, "Inserted at (%d %d).\n", nv.x, nv.y ); - } + fprintf( flog, "Inserted at (%d %d).\n", nv.x, nv.y ); + } - i += nins; - ncorn += nins; - } - } + i += nins; + ncorn += nins; + } + } // print corner count - fprintf( flog, - "\nSplitting long sides gives %d corners.---\n", ncorn ); + fprintf( flog, + "\nSplitting long sides gives %d corners.---\n", ncorn ); // table of corners - fprintf( flog, " Vtx\t Vx\t Vy\n" ); + fprintf( flog, " Vtx\t Vx\t Vy\n" ); - for( int i = 0; i < ncorn; ++i ) { + for( int i = 0; i < ncorn; ++i ) { - const vertex& C = corners[i]; + const vertex& C = corners[i]; - fprintf( flog, "%4d\t%6d\t%6d\n", i, C.x, C.y ); - } + fprintf( flog, "%4d\t%6d\t%6d\n", i, C.x, C.y ); + } - fprintf( flog, "\n" ); + fprintf( flog, "\n" ); } /* --------------------------------------------------------------- */ @@ -411,203 +411,203 @@ static void SplitLongSides( // distances of the cut corners from the new shortcut segment. // static void CutCorners( - vector &edges, - double &lmin, - double lmax, - const vector &corners, - FILE* flog ) + vector &edges, + double &lmin, + double lmax, + const vector &corners, + FILE* flog ) { - int ncorn = corners.size(); - bool big_print = false; + int ncorn = corners.size(); + bool big_print = false; // Attempt up to ten times until lmin adjusted small enough. - for( int II=1; II<=10 && edges.size() < 3; ++II, lmin *= 0.8 ) { + for( int II=1; II<=10 && edges.size() < 3; ++II, lmin *= 0.8 ) { - fprintf( flog, - "Pass %d: Length range [%f, %f].\n\n", II, lmin, lmax ); + fprintf( flog, + "Pass %d: Length range [%f, %f].\n\n", II, lmin, lmax ); - edges.clear(); + edges.clear(); - /* ---------- */ - /* Init graph */ - /* ---------- */ + /* ---------- */ + /* Init graph */ + /* ---------- */ - vector graph; + vector graph; - graph.reserve( ncorn + 1 ); + graph.reserve( ncorn + 1 ); - // Set all back pointers to -1, and all costs to infinity + // Set all back pointers to -1, and all costs to infinity - for( int i = 0; i < ncorn; ++i ) - graph[i] = Grf( corners[i], -1, double(BIG) ); + for( int i = 0; i < ncorn; ++i ) + graph[i] = Grf( corners[i], -1, double(BIG) ); - // Final entry is duplicate of 1st--the home position + // Final entry is duplicate of 1st--the home position - graph[ncorn] = graph[0]; + graph[ncorn] = graph[0]; - /* --------------------------------------------- */ - /* Build low cost path from first to last corner */ - /* --------------------------------------------- */ + /* --------------------------------------------- */ + /* Build low cost path from first to last corner */ + /* --------------------------------------------- */ - // Priority queues, which work like heaps, make sure - // the topmost element has the highest 'priority'. In - // our case, the PQElm::comparison function assigns - // highest priority to the lowest 'cost' element. - // - // We will build a path by enqueing low cost hops and - // dequeing them again to see how we might make further - // hops from there, until we get home. The priority - // queue device makes sure we consider lower cost hops - // ahead of others, which is a fine guess to make, but - // this does not guarantee an optimal overall path. We - // do not require optimality, though, just a good path. + // Priority queues, which work like heaps, make sure + // the topmost element has the highest 'priority'. In + // our case, the PQElm::comparison function assigns + // highest priority to the lowest 'cost' element. + // + // We will build a path by enqueing low cost hops and + // dequeing them again to see how we might make further + // hops from there, until we get home. The priority + // queue device makes sure we consider lower cost hops + // ahead of others, which is a fine guess to make, but + // this does not guarantee an optimal overall path. We + // do not require optimality, though, just a good path. - { - /* ---------------------------------------- */ - /* Initialize queue of intermediate corners */ - /* ---------------------------------------- */ + { + /* ---------------------------------------- */ + /* Initialize queue of intermediate corners */ + /* ---------------------------------------- */ - priority_queue q; + priority_queue q; - q.push( PQElm( 0, 0.0 ) ); - graph[0].cost = 0.0; + q.push( PQElm( 0, 0.0 ) ); + graph[0].cost = 0.0; - /* ------------------------------- */ - /* Process corners until back home */ - /* ------------------------------- */ + /* ------------------------------- */ + /* Process corners until back home */ + /* ------------------------------- */ - while( !q.empty() ) { + while( !q.empty() ) { - /* ------------------------ */ - /* Dequeue an endpoint T.to */ - /* ------------------------ */ + /* ------------------------ */ + /* Dequeue an endpoint T.to */ + /* ------------------------ */ - PQElm T = q.top(); + PQElm T = q.top(); - q.pop(); + q.pop(); - fprintf( flog, - "Node 0 to %4d; xy=(%4d %4d); cost=%f\n", - T.to, graph[T.to].x, graph[T.to].y, T.cost ); + fprintf( flog, + "Node 0 to %4d; xy=(%4d %4d); cost=%f\n", + T.to, graph[T.to].x, graph[T.to].y, T.cost ); - /* --------- */ - /* Home yet? */ - /* --------- */ + /* --------- */ + /* Home yet? */ + /* --------- */ - if( T.to == ncorn ) - break; + if( T.to == ncorn ) + break; - /* ----------------------------------- */ - /* Is it a lower cost way to get here? */ - /* ----------------------------------- */ + /* ----------------------------------- */ + /* Is it a lower cost way to get here? */ + /* ----------------------------------- */ - if( T.cost > graph[T.to].cost ) - continue; + if( T.cost > graph[T.to].cost ) + continue; - /* ------- */ - /* Enqueue */ - /* ------- */ + /* ------- */ + /* Enqueue */ + /* ------- */ - // Starting from the dequeued node [s], consider - // paths to all other downstream nodes [j]. If the - // length is reasonable AND if the cost to get to - // [j] is lower than the current cost at [j], then - // update node [j] AND enter [j] in the queue to - // consider how to proceed from there. + // Starting from the dequeued node [s], consider + // paths to all other downstream nodes [j]. If the + // length is reasonable AND if the cost to get to + // [j] is lower than the current cost at [j], then + // update node [j] AND enter [j] in the queue to + // consider how to proceed from there. - int s = T.to; // the source node + int s = T.to; // the source node - for( int j = s + 1; j < ncorn + 1; ++j ) { + for( int j = s + 1; j < ncorn + 1; ++j ) { - double len = graph[j].Dist( graph[s] ); + double len = graph[j].Dist( graph[s] ); - if( big_print ) { - fprintf( flog, - "Target %3d; xy=(%4d %4d); len=%f\n", - j, graph[j].x, graph[j].y, len ); - } + if( big_print ) { + fprintf( flog, + "Target %3d; xy=(%4d %4d); len=%f\n", + j, graph[j].x, graph[j].y, len ); + } - /* ------------------ */ - /* Length reasonable? */ - /* ------------------ */ + /* ------------------ */ + /* Length reasonable? */ + /* ------------------ */ - if( lmin <= len && len <= lmax ) { + if( lmin <= len && len <= lmax ) { - double cost = - graph[s].cost + ShortcutCost( graph, s, j ); + double cost = + graph[s].cost + ShortcutCost( graph, s, j ); - if( big_print ) { - fprintf( flog, - "Cost: src=%f; tot=%f; trg=%f\n", - graph[s].cost, cost, graph[j].cost ); - } + if( big_print ) { + fprintf( flog, + "Cost: src=%f; tot=%f; trg=%f\n", + graph[s].cost, cost, graph[j].cost ); + } - /* ----------- */ - /* Lower cost? */ - /* ----------- */ + /* ----------- */ + /* Lower cost? */ + /* ----------- */ - if( cost < graph[j].cost ) { + if( cost < graph[j].cost ) { - graph[j].cost = cost; - graph[j].back = s; + graph[j].cost = cost; + graph[j].back = s; - if( big_print ) { - fprintf( flog, - "Pushing node %3d;" - " cost=%f; back=%3d\n", - j, cost, s ); - } + if( big_print ) { + fprintf( flog, + "Pushing node %3d;" + " cost=%f; back=%3d\n", + j, cost, s ); + } - /* --------------------- */ - /* Start again from here */ - /* --------------------- */ + /* --------------------- */ + /* Start again from here */ + /* --------------------- */ - q.push( PQElm( j, cost ) ); - } - } - } - } - } + q.push( PQElm( j, cost ) ); + } + } + } + } + } - /* ------------------- */ - /* All the way around? */ - /* ------------------- */ + /* ------------------- */ + /* All the way around? */ + /* ------------------- */ - if( graph[ncorn].cost == BIG ) { + if( graph[ncorn].cost == BIG ) { - fprintf( flog, - "No path to final vertex??" - " Will reduce lmin and try again.\n" ); - continue; - } + fprintf( flog, + "No path to final vertex??" + " Will reduce lmin and try again.\n" ); + continue; + } - fprintf( flog, "\n" ); + fprintf( flog, "\n" ); - /* ------------------- */ - /* Collect final edges */ - /* ------------------- */ + /* ------------------- */ + /* Collect final edges */ + /* ------------------- */ - // Deduce connectivity by backtracking from final vertex - // and creating the edge list in reverse order (inserting - // new entries at front). This keeps polygon in same order - // as the vertices from which it was made. + // Deduce connectivity by backtracking from final vertex + // and creating the edge list in reverse order (inserting + // new entries at front). This keeps polygon in same order + // as the vertices from which it was made. - for( int i = ncorn; i > 0; i = graph[i].back ) { + for( int i = ncorn; i > 0; i = graph[i].back ) { - const Grf& prev = graph[graph[i].back]; - double d = graph[i].Dist( prev ); + const Grf& prev = graph[graph[i].back]; + double d = graph[i].Dist( prev ); - fprintf( flog, - "Edge from (%4d %4d) to (%4d %4d); len %7.2f\n", - prev.x, prev.y, graph[i].x, graph[i].y, d ); + fprintf( flog, + "Edge from (%4d %4d) to (%4d %4d); len %7.2f\n", + prev.x, prev.y, graph[i].x, graph[i].y, d ); - edges.insert( edges.begin(), - lineseg( prev.x, prev.y, graph[i].x, graph[i].y ) ); - } - } + edges.insert( edges.begin(), + lineseg( prev.x, prev.y, graph[i].x, graph[i].y ) ); + } + } - fprintf( flog, "\n" ); + fprintf( flog, "\n" ); } /* --------------------------------------------------------------- */ @@ -630,93 +630,93 @@ static void CutCorners( // static void UncrossEdges( vector &edges, FILE* flog ) { - int ne = edges.size(), err; + int ne = edges.size(), err; - do { + do { - /* ------------------- */ - /* Print current edges */ - /* ------------------- */ + /* ------------------- */ + /* Print current edges */ + /* ------------------- */ - for( int i = 0; i < ne; ++i ) { + for( int i = 0; i < ne; ++i ) { - const lineseg& L = edges[i]; + const lineseg& L = edges[i]; - fprintf( flog, - "Pgon edge %3d: (%4d %4d) (%4d %4d).\n", - i, L.v[0].x, L.v[0].y, L.v[1].x, L.v[1].y ); - } + fprintf( flog, + "Pgon edge %3d: (%4d %4d) (%4d %4d).\n", + i, L.v[0].x, L.v[0].y, L.v[1].x, L.v[1].y ); + } - /* ---------------------------- */ - /* Look at all edge pairs {i,k} */ - /* ---------------------------- */ + /* ---------------------------- */ + /* Look at all edge pairs {i,k} */ + /* ---------------------------- */ - err = false; + err = false; - for( int i = 0; i < ne - 1 && !err; ++i ) { + for( int i = 0; i < ne - 1 && !err; ++i ) { - for( int k = i + 1; k < ne && !err; ++k ) { + for( int k = i + 1; k < ne && !err; ++k ) { - const lineseg& Li = edges[i]; - const lineseg& Lk = edges[k]; + const lineseg& Li = edges[i]; + const lineseg& Lk = edges[k]; - if( OpenSegsCross( - Li.v[0], Li.v[1], - Lk.v[0], Lk.v[1] ) ) { + if( OpenSegsCross( + Li.v[0], Li.v[1], + Lk.v[0], Lk.v[1] ) ) { - fprintf( flog, - "Edges %d and %d cross; (%4d %4d)-(%4d %4d)" - " and (%4d %4d)-(%4d %4d).\n", i, k, - Li.v[0].x, Li.v[0].y, Li.v[1].x, Li.v[1].y, - Lk.v[0].x, Lk.v[0].y, Lk.v[1].x, Lk.v[1].y ); + fprintf( flog, + "Edges %d and %d cross; (%4d %4d)-(%4d %4d)" + " and (%4d %4d)-(%4d %4d).\n", i, k, + Li.v[0].x, Li.v[0].y, Li.v[1].x, Li.v[1].y, + Lk.v[0].x, Lk.v[0].y, Lk.v[1].x, Lk.v[1].y ); - err = true; + err = true; - /* ------ */ - /* Repair */ - /* ------ */ + /* ------ */ + /* Repair */ + /* ------ */ - // It's cumbersome to address vertices as - // tails and tips of edges, so temporarily - // copy them to a simple vertex list. Note - // that getting tails indeed gets them all - // since the edges describe a closed loop. - // Every tip is someone else's tail. + // It's cumbersome to address vertices as + // tails and tips of edges, so temporarily + // copy them to a simple vertex list. Note + // that getting tails indeed gets them all + // since the edges describe a closed loop. + // Every tip is someone else's tail. - vector v( ne ); + vector v( ne ); - for( int ie = 0; ie < ne; ++ie ) - v[ie] = edges[ie].v[0]; + for( int ie = 0; ie < ne; ++ie ) + v[ie] = edges[ie].v[0]; - // Reverse inclusive range [i+1..k] - // using symmetric pairwise swaps. + // Reverse inclusive range [i+1..k] + // using symmetric pairwise swaps. - int nv = k - (i+1) + 1, // num verts - md = nv / 2; // midpoint + int nv = k - (i+1) + 1, // num verts + md = nv / 2; // midpoint - for( int j = 0; j < md; ++j ) { + for( int j = 0; j < md; ++j ) { - int a = (i+1+j)%ne, - b = (k-j)%ne; - vertex t; + int a = (i+1+j)%ne, + b = (k-j)%ne; + vertex t; - t = v[a]; - v[a] = v[b]; - v[b] = t; - } + t = v[a]; + v[a] = v[b]; + v[b] = t; + } - // Copy all vertices back to edges + // Copy all vertices back to edges - for( int ie = 0; ie < ne; ++ie ) { + for( int ie = 0; ie < ne; ++ie ) { - edges[ie].v[0] = v[ie]; - edges[ie].v[1] = v[(ie+1)%ne]; - } - } - } - } + edges[ie].v[0] = v[ie]; + edges[ie].v[1] = v[(ie+1)%ne]; + } + } + } + } - } while( err ); + } while( err ); } /* --------------------------------------------------------------- */ @@ -729,28 +729,28 @@ static void UncrossEdges( vector &edges, FILE* flog ) // static void ReverseWhole( vector &edges, FILE* flog ) { - double area = AreaOfPolygon( edges ); + double area = AreaOfPolygon( edges ); - fprintf( flog, "After edge untangling area %.2f\n", area ); + fprintf( flog, "After edge untangling area %.2f\n", area ); - if( area < 0.0 ) { + if( area < 0.0 ) { - // reverse every edge + // reverse every edge - fprintf( flog, "Reversing...\n" ); + fprintf( flog, "Reversing...\n" ); - int ne = edges.size(); + int ne = edges.size(); - for( int i = 0; i < ne; ++i ) { + for( int i = 0; i < ne; ++i ) { - lineseg& L = edges[i]; - vertex t; + lineseg& L = edges[i]; + vertex t; - t = L.v[0]; - L.v[0] = L.v[1]; - L.v[1] = t; - } - } + t = L.v[0]; + L.v[0] = L.v[1]; + L.v[1] = t; + } + } } /* --------------------------------------------------------------- */ @@ -764,67 +764,67 @@ static void ReverseWhole( vector &edges, FILE* flog ) // too close to an edge. Deeper in the interior may be better. // static void SetInternalVertices( - vector &vinside, - vector &map, - int w, - int h, - const vector &edges, - int rclear, - FILE* flog ) + vector &vinside, + vector &map, + int w, + int h, + const vector &edges, + int rclear, + FILE* flog ) { /* --------------------------------------------- */ /* Clear map in neighborhood of existing corners */ /* --------------------------------------------- */ - int ne = edges.size(), - np = w * h; + int ne = edges.size(), + np = w * h; - for( int i = 0; i < ne; ++i ) - RemoveFromMap( map, w, h, edges[i].v[0], rclear ); + for( int i = 0; i < ne; ++i ) + RemoveFromMap( map, w, h, edges[i].v[0], rclear ); /* ----------------------------------- */ /* Find well-separated internal points */ /* ----------------------------------- */ - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( map[i] ) { + if( map[i] ) { - /* -------------------------------------------- */ - /* Clear neighborhood around prospective vertex */ - /* -------------------------------------------- */ + /* -------------------------------------------- */ + /* Clear neighborhood around prospective vertex */ + /* -------------------------------------------- */ - int y = i / w; - int x = i - w * y; + int y = i / w; + int x = i - w * y; - fprintf( flog, - "Add internal vertex at (%4d %4d).\n", x, y ); + fprintf( flog, + "Add internal vertex at (%4d %4d).\n", x, y ); - vertex newv( x, y ); + vertex newv( x, y ); - RemoveFromMap( map, w, h, newv, rclear ); + RemoveFromMap( map, w, h, newv, rclear ); - /* -------------------------- */ - /* Apply simple 'inside' test */ - /* -------------------------- */ + /* -------------------------- */ + /* Apply simple 'inside' test */ + /* -------------------------- */ - // Make guaranteed outside point and count edge - // crossings from there to proposed inside point. + // Make guaranteed outside point and count edge + // crossings from there to proposed inside point. - vertex outside( -10, y ); + vertex outside( -10, y ); - int m = CountCrossings( edges, newv, outside ); + int m = CountCrossings( edges, newv, outside ); - if( m & 1 ) - vinside.push_back( newv ); - else if( m ) { + if( m & 1 ) + vinside.push_back( newv ); + else if( m ) { - fprintf( flog, - "Warning: Supposedly internal point is outside" - " - %d crossings. Continuing.\n", m ); - } - } - } + fprintf( flog, + "Warning: Supposedly internal point is outside" + " - %d crossings. Continuing.\n", m ); + } + } + } } /* --------------------------------------------------------------- */ @@ -832,22 +832,22 @@ static void SetInternalVertices( /* --------------------------------------------------------------- */ static void ListEdgesMatlab( - const vector &edges, - FILE* flog ) + const vector &edges, + FILE* flog ) { - int ne = edges.size(); + int ne = edges.size(); - fprintf( flog, - "\n--------- Start Matlab format ------------------\n" ); + fprintf( flog, + "\n--------- Start Matlab format ------------------\n" ); - for( int i = 0; i < ne; ++i ) { + for( int i = 0; i < ne; ++i ) { - const lineseg& L = edges[i]; + const lineseg& L = edges[i]; - fprintf( flog, - "x=[%d %d]; y=[%d %d]; plot(x,y); hold on;\n", - L.v[0].x, L.v[1].x, L.v[0].y, L.v[1].y ); - } + fprintf( flog, + "x=[%d %d]; y=[%d %d]; plot(x,y); hold on;\n", + L.v[0].x, L.v[1].x, L.v[0].y, L.v[1].y ); + } } /* --------------------------------------------------------------- */ @@ -856,22 +856,22 @@ static void ListEdgesMatlab( static int LongestEdge( const vector &edges ) { - double Dmax = -1.0; - int ne = edges.size(), - Imax = -1; + double Dmax = -1.0; + int ne = edges.size(), + Imax = -1; - for( int i = 0; i < ne; ++i ) { + for( int i = 0; i < ne; ++i ) { - double d = edges[i].LenSqr(); + double d = edges[i].LenSqr(); - if( d > Dmax ) { + if( d > Dmax ) { - Dmax = d; - Imax = i; - } - } + Dmax = d; + Imax = i; + } + } - return Imax; + return Imax; } /* --------------------------------------------------------------- */ @@ -882,14 +882,14 @@ static int LongestEdge( const vector &edges ) class UVert { public: - vertex v; - int type, - indx; + vertex v; + int type, + indx; public: - UVert() {}; + UVert() {}; - UVert( const vertex& v, int type, int indx ) - : v(v), type(type), indx(indx) {}; + UVert( const vertex& v, int type, int indx ) + : v(v), type(type), indx(indx) {}; }; @@ -899,51 +899,51 @@ class UVert { // Return uv.size(); // static int UniqueVerts( - vector &uv, - const vector &edges, - const vector &vinside ) + vector &uv, + const vector &edges, + const vector &vinside ) { - int n = edges.size(); + int n = edges.size(); // First add the edge.v0, which are guaranteed unique - for( int i = 0; i < n; ++i ) - uv.push_back( UVert( edges[i].v[0], 0, i ) ); + for( int i = 0; i < n; ++i ) + uv.push_back( UVert( edges[i].v[0], 0, i ) ); // Next add unique edge.v1 // // The v1's are unique from other v1's, but are they // different from listed v0's? - for( int i = 0; i < n; ++i ) { + for( int i = 0; i < n; ++i ) { - const vertex& v = edges[i].v[1]; + const vertex& v = edges[i].v[1]; - // unique? + // unique? - for( int j = 0; j < n; ++j ) { + for( int j = 0; j < n; ++j ) { - if( v == edges[j].v[0] ) - goto next_i; - } + if( v == edges[j].v[0] ) + goto next_i; + } - uv.push_back( UVert( v, 1, i ) ); + uv.push_back( UVert( v, 1, i ) ); next_i:; - } + } // Finally, add internal verts which are always unique - n = vinside.size(); + n = vinside.size(); - for( int i = 0; i < n; ++i ) - uv.push_back( UVert( vinside[i], -1, i ) ); + for( int i = 0; i < n; ++i ) + uv.push_back( UVert( vinside[i], -1, i ) ); // Kill excess space and return count - uv.resize( n = uv.size() ); + uv.resize( n = uv.size() ); - return n; + return n; } /* --------------------------------------------------------------- */ @@ -957,81 +957,81 @@ next_i:; // indx = index into vinside[] or edges[] according to type. // static void BestVertex( - int &type, - int &indx, - const vertex &va, - const vertex &vb, - const vector &edges, - const vector &vinside, - FILE* flog ) + int &type, + int &indx, + const vertex &va, + const vertex &vb, + const vector &edges, + const vector &vinside, + FILE* flog ) { - type = -2; - indx = -1; - - vertex vm( (va.x+vb.x)/2, (va.y+vb.y)/2 ); // midpoint - vector uv; - double Dbest = BIG; - int nu; - - nu = UniqueVerts( uv, edges, vinside ); - - for( int i = 0; i < nu; ++i ) { - - const vertex& vc = uv[i].v; - - if( vc == va || vc == vb ) - continue; - - double D = vm.DistSqr( vc ), - A = AreaOfTriangle( va, vb, vc ); - int L = LeftSide( va, vb, vc ); - - fprintf( flog, - "#%3d (%4d %4d); dist=%12.2f; left=%d; area=%11.2f; ", - i, vc.x, vc.y, D, L, A ); - - // require vc on interior side of va->vb - if( !L ) { - fprintf( flog, "rjct: not L\n" ); - continue; - } - - // require small... - if( D >= Dbest ) { - fprintf( flog, "rjct: big D\n" ); - continue; - } - - // ...but not too small - if( A <= GBL.mch.MTA ) { - fprintf( flog, "rjct: sml A\n" ); - continue; - } - - // don't cross any remaining edges - if( AnyCrossing( edges, va, vc ) ) { - fprintf( flog, "rjct: crs va\n" ); - continue; - } - - // ditto - if( AnyCrossing( edges, vb, vc ) ) { - fprintf( flog, "rjct: crs vb\n" ); - continue; - } - - // don't enclose other vertices - if( AnyInside( va, vb, vc, edges, vinside ) ) { - fprintf( flog, "rjct: any inside\n" ); - continue; - } - - Dbest = D; - type = uv[i].type; - indx = uv[i].indx; - - fprintf( flog, "keep: *\n" ); - } + type = -2; + indx = -1; + + vertex vm( (va.x+vb.x)/2, (va.y+vb.y)/2 ); // midpoint + vector uv; + double Dbest = BIG; + int nu; + + nu = UniqueVerts( uv, edges, vinside ); + + for( int i = 0; i < nu; ++i ) { + + const vertex& vc = uv[i].v; + + if( vc == va || vc == vb ) + continue; + + double D = vm.DistSqr( vc ), + A = AreaOfTriangle( va, vb, vc ); + int L = LeftSide( va, vb, vc ); + + fprintf( flog, + "#%3d (%4d %4d); dist=%12.2f; left=%d; area=%11.2f; ", + i, vc.x, vc.y, D, L, A ); + + // require vc on interior side of va->vb + if( !L ) { + fprintf( flog, "rjct: not L\n" ); + continue; + } + + // require small... + if( D >= Dbest ) { + fprintf( flog, "rjct: big D\n" ); + continue; + } + + // ...but not too small + if( A <= GBL.mch.MTA ) { + fprintf( flog, "rjct: sml A\n" ); + continue; + } + + // don't cross any remaining edges + if( AnyCrossing( edges, va, vc ) ) { + fprintf( flog, "rjct: crs va\n" ); + continue; + } + + // ditto + if( AnyCrossing( edges, vb, vc ) ) { + fprintf( flog, "rjct: crs vb\n" ); + continue; + } + + // don't enclose other vertices + if( AnyInside( va, vb, vc, edges, vinside ) ) { + fprintf( flog, "rjct: any inside\n" ); + continue; + } + + Dbest = D; + type = uv[i].type; + indx = uv[i].indx; + + fprintf( flog, "keep: *\n" ); + } } /* --------------------------------------------------------------- */ @@ -1039,42 +1039,42 @@ static void BestVertex( /* --------------------------------------------------------------- */ static void AddTriangle( - vector &tri, - vector &ctl, - const vertex &va, - const vertex &vb, - const vertex &vc ) + vector &tri, + vector &ctl, + const vertex &va, + const vertex &vb, + const vertex &vc ) { - triangle t; - vector V( 3 ); - int nc = ctl.size(); + triangle t; + vector V( 3 ); + int nc = ctl.size(); - V[0] = va; // makes vertices indexable - V[1] = vb; - V[2] = vc; + V[0] = va; // makes vertices indexable + V[1] = vb; + V[2] = vc; // For each triangle vertex, see if matches existing control point // and either refer to that or add the vertex as new control point. - for( int iv = 0; iv < 3; ++iv ) { + for( int iv = 0; iv < 3; ++iv ) { - for( int ic = 0; ic < nc; ++ic ) { + for( int ic = 0; ic < nc; ++ic ) { - if( ctl[ic] == V[iv] ) { - // matches--use it - t.v[iv] = ic; - goto next_iv; - } - } + if( ctl[ic] == V[iv] ) { + // matches--use it + t.v[iv] = ic; + goto next_iv; + } + } - // no match--append - ctl.push_back( V[iv] ); - t.v[iv] = nc++; + // no match--append + ctl.push_back( V[iv] ); + t.v[iv] = nc++; next_iv:; - } + } - tri.push_back( t ); + tri.push_back( t ); } /* --------------------------------------------------------------- */ @@ -1098,50 +1098,50 @@ next_iv:; // Segments with no overlaps are added to the polygon. // static void UpdatePolygon( - vector &edges, - const vertex &va, - const vertex &vb, - const vertex &vc ) + vector &edges, + const vertex &va, + const vertex &vb, + const vertex &vc ) { // Create a stack of prospective new segments to add. // Initialize stack with va->vc and vc->vb. - stack StackOfSegs; + stack StackOfSegs; - StackOfSegs.push( lineseg( va, vc ) ); - StackOfSegs.push( lineseg( vc, vb ) ); + StackOfSegs.push( lineseg( va, vc ) ); + StackOfSegs.push( lineseg( vc, vb ) ); // Examine segments until none left - for( ; StackOfSegs.size() > 0; ) { + for( ; StackOfSegs.size() > 0; ) { - // Fetch a prospective segment + // Fetch a prospective segment - lineseg test = StackOfSegs.top(); - StackOfSegs.pop(); + lineseg test = StackOfSegs.top(); + StackOfSegs.pop(); - // Check for overlap with each existing edge + // Check for overlap with each existing edge - for( int j = 0; j < edges.size(); ++j ) { + for( int j = 0; j < edges.size(); ++j ) { - if( IsSubseg( StackOfSegs, edges[j], test ) ) { + if( IsSubseg( StackOfSegs, edges[j], test ) ) { - // edge[j] is wholly contained in 'test' so - // we remove edge[j] ourselves. InSubseg() - // has already added the leftover pieces - // to the stack for the next pass. + // edge[j] is wholly contained in 'test' so + // we remove edge[j] ourselves. InSubseg() + // has already added the leftover pieces + // to the stack for the next pass. - edges.erase( edges.begin() + j ); - goto next_seg; - } - } + edges.erase( edges.begin() + j ); + goto next_seg; + } + } - // No overlaps -- add to figure + // No overlaps -- add to figure - edges.push_back( test ); + edges.push_back( test ); next_seg:; - } + } } /* --------------------------------------------------------------- */ @@ -1149,17 +1149,17 @@ next_seg:; /* --------------------------------------------------------------- */ static void OffsetControlPoints( - vector &ctl, - const IBox &B ) + vector &ctl, + const IBox &B ) { - int dx = B.L - 1, dy = B.B - 1; - int nc = ctl.size(); + int dx = B.L - 1, dy = B.B - 1; + int nc = ctl.size(); - for( int i = 0; i < nc; ++i ) { + for( int i = 0; i < nc; ++i ) { - ctl[i].x += dx; - ctl[i].y += dy; - } + ctl[i].x += dx; + ctl[i].y += dy; + } } /* --------------------------------------------------------------- */ @@ -1167,15 +1167,15 @@ static void OffsetControlPoints( /* --------------------------------------------------------------- */ void MeshGetBounds( - IBox &B, - const vector &pts, - FILE* flog ) + IBox &B, + const vector &pts, + FILE* flog ) { - BBoxFromPoints( B, pts ); + BBoxFromPoints( B, pts ); - fprintf( flog, - "Region size is [%d %d] in x, [%d %d] in y.\n", - B.L, B.R, B.B, B.T ); + fprintf( flog, + "Region size is [%d %d] in x, [%d %d] in y.\n", + B.L, B.R, B.B, B.T ); } /* --------------------------------------------------------------- */ @@ -1186,40 +1186,40 @@ void MeshGetBounds( // on the given bounding box. // void MeshMakeSingleTri( - vector &tri, - vector &ctl, - const IBox &B, - FILE* flog ) + vector &tri, + vector &ctl, + const IBox &B, + FILE* flog ) { - tri.resize( 1 ); - ctl.resize( 3 ); + tri.resize( 1 ); + ctl.resize( 3 ); // set one triangle - triangle t; + triangle t; - t.v[0] = 0; - t.v[1] = 1; - t.v[2] = 2; + t.v[0] = 0; + t.v[1] = 1; + t.v[2] = 2; - tri[0] = t; + tri[0] = t; // and its three control points - if( B.R - B.L > B.T - B.B ) { - // horizontal - ctl[0] = vertex( B.L, B.B ); - ctl[1] = vertex( B.R, B.B ); - ctl[2] = vertex( (B.L + B.R) / 2, B.T ); - } - else { - // vertical - ctl[0] = vertex( B.L, B.B ); - ctl[1] = vertex( B.R, (B.B + B.T) / 2 ); - ctl[2] = vertex( B.L, B.T ); - } - - fprintf( flog, "Computed simple triangle.\n" ); + if( B.R - B.L > B.T - B.B ) { + // horizontal + ctl[0] = vertex( B.L, B.B ); + ctl[1] = vertex( B.R, B.B ); + ctl[2] = vertex( (B.L + B.R) / 2, B.T ); + } + else { + // vertical + ctl[0] = vertex( B.L, B.B ); + ctl[1] = vertex( B.R, (B.B + B.T) / 2 ); + ctl[2] = vertex( B.L, B.T ); + } + + fprintf( flog, "Computed simple triangle.\n" ); } /* --------------------------------------------------------------- */ @@ -1245,90 +1245,90 @@ void MeshMakeSingleTri( // the peculiar choice of integer (x,y) in class vertex. // int MeshCreate( - vector &tri, - vector &ctl, - const vector &pts, - const IBox &B, - FILE* flog ) + vector &tri, + vector &ctl, + const vector &pts, + const IBox &B, + FILE* flog ) { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - tri.clear(); - ctl.clear(); + tri.clear(); + ctl.clear(); - int npts = pts.size(); + int npts = pts.size(); /* ---------------------- */ /* Set edge length limits */ /* ---------------------- */ - double lmin, lmax; + double lmin, lmax; - SetEdgeLimits( lmin, lmax, B, flog ); + SetEdgeLimits( lmin, lmax, B, flog ); /* ---------------------------------------- */ /* Make bitmap of ones where we have points */ /* ---------------------------------------- */ - vector map; - int w, h; + vector map; + int w, h; - MakeMap( map, w, h, B, pts ); + MakeMap( map, w, h, B, pts ); /* -------------------------- */ /* Find left edge of boundary */ /* -------------------------- */ - int x0, y0; + int x0, y0; - if( !FindLeftEdge( x0, y0, map, w, h, flog ) ) - return 3; + if( !FindLeftEdge( x0, y0, map, w, h, flog ) ) + return 3; /* --------------------------------- */ /* Get boundary points, then corners */ /* --------------------------------- */ - vector corners; + vector corners; - { - vector bndry; + { + vector bndry; - if( !GetBoundaryPoints( bndry, map, w, h, x0, y0, flog ) ) - return 4; + if( !GetBoundaryPoints( bndry, map, w, h, x0, y0, flog ) ) + return 4; - FindCorners( corners, bndry, flog ); - } + FindCorners( corners, bndry, flog ); + } /* ------------------- */ /* Split long segments */ /* ------------------- */ - SplitLongSides( corners, lmin, flog ); + SplitLongSides( corners, lmin, flog ); /* --------------------------------------- */ /* Reduce segment count by cutting corners */ /* --------------------------------------- */ - vector edges; + vector edges; - CutCorners( edges, lmin, lmax, corners, flog ); + CutCorners( edges, lmin, lmax, corners, flog ); /* ---------------------------------- */ /* Repair any segment crossing errors */ /* ---------------------------------- */ - UncrossEdges( edges, flog ); + UncrossEdges( edges, flog ); - ReverseWhole( edges, flog ); + ReverseWhole( edges, flog ); /* -------------------------------- */ /* Create list of internal vertices */ /* -------------------------------- */ - vector vinside; + vector vinside; - SetInternalVertices( vinside, map, w, h, - edges, int((lmin+lmax)/2), flog ); + SetInternalVertices( vinside, map, w, h, + edges, int((lmin+lmax)/2), flog ); /* ----------------------------- */ /* Divide polygon into triangles */ @@ -1339,144 +1339,144 @@ int MeshCreate( // from the figure. Repeat until no edges remain. The result // will be a list of control points, and referring triangles. - double Aexpect = 0.0; + double Aexpect = 0.0; - for( ; edges.size() > 0; ) { + for( ; edges.size() > 0; ) { - /* ---------- */ - /* Check area */ - /* ---------- */ + /* ---------- */ + /* Check area */ + /* ---------- */ - // At the end of each pass, we calculate the expected - // area for the next pass which is: Alast - Atri. - // We skip expected area test for 1st pass. + // At the end of each pass, we calculate the expected + // area for the next pass which is: Alast - Atri. + // We skip expected area test for 1st pass. - double area = AreaOfPolygon( edges ); + double area = AreaOfPolygon( edges ); - if( area < 0.0 || + if( area < 0.0 || // (tri.size() && fabs( area - Aexpect ) > 0.001) ) { - (tri.size() && fabs( area - Aexpect ) > 1.000) ) { + (tri.size() && fabs( area - Aexpect ) > 1.000) ) { - fprintf( flog, - "Internal error! Area %f < 0, or not expected %f\n", - area, Aexpect ); + fprintf( flog, + "Internal error! Area %f < 0, or not expected %f\n", + area, Aexpect ); - return 5; - } + return 5; + } - /* -------------------- */ - /* Report current state */ - /* -------------------- */ + /* -------------------- */ + /* Report current state */ + /* -------------------- */ - ListEdgesMatlab( edges, flog ); + ListEdgesMatlab( edges, flog ); - fprintf( flog, "\nEdges %ld; Area %f\n", edges.size(), area ); + fprintf( flog, "\nEdges %ld; Area %f\n", edges.size(), area ); - /* ------------------- */ - /* Remove longest edge */ - /* ------------------- */ + /* ------------------- */ + /* Remove longest edge */ + /* ------------------- */ - int which = LongestEdge( edges ); + int which = LongestEdge( edges ); - vertex va( edges[which].v[0] ), - vb( edges[which].v[1] ); + vertex va( edges[which].v[0] ), + vb( edges[which].v[1] ); - edges.erase( edges.begin() + which ); + edges.erase( edges.begin() + which ); - fprintf( flog, - "\nWorking on edge %d; (%d %d) -> (%d %d).\n", - which, va.x, va.y, vb.x, vb.y ); + fprintf( flog, + "\nWorking on edge %d; (%d %d) -> (%d %d).\n", + which, va.x, va.y, vb.x, vb.y ); - /* --------------------------------------- */ - /* Seek best triangle vertex for this edge */ - /* --------------------------------------- */ + /* --------------------------------------- */ + /* Seek best triangle vertex for this edge */ + /* --------------------------------------- */ - int type, indx; + int type, indx; - BestVertex( type, indx, va, vb, edges, vinside, flog ); + BestVertex( type, indx, va, vb, edges, vinside, flog ); - /* ---------------- */ - /* If none found... */ - /* ---------------- */ + /* ---------------- */ + /* If none found... */ + /* ---------------- */ - if( type == -2 ) { + if( type == -2 ) { - fprintf( flog, "\nNo legal triangle at all??" - " %ld triangles so far, area limit %d\n", - tri.size(), GBL.mch.MTA ); + fprintf( flog, "\nNo legal triangle at all??" + " %ld triangles so far, area limit %d\n", + tri.size(), GBL.mch.MTA ); - if( tri.size() > 0 ) { + if( tri.size() > 0 ) { - // We'll call it good if we've got - // at least one triangle already. + // We'll call it good if we've got + // at least one triangle already. - break; - } + break; + } - // There are no triangles to be found, so... - // we'll make one up from the bounding box. + // There are no triangles to be found, so... + // we'll make one up from the bounding box. - fprintf( flog, "STAT: Fall back to single triangle.\n" ); + fprintf( flog, "STAT: Fall back to single triangle.\n" ); - MeshMakeSingleTri( tri, ctl, B, flog ); + MeshMakeSingleTri( tri, ctl, B, flog ); - goto exit; - } + goto exit; + } - /* --------------------------------- */ - /* Construct triangle va->vb->vc->va */ - /* --------------------------------- */ + /* --------------------------------- */ + /* Construct triangle va->vb->vc->va */ + /* --------------------------------- */ - vertex vc = (type < 0 ? vinside[indx] : edges[indx].v[type]); - double Atri = AreaOfTriangle( va, vb, vc ); + vertex vc = (type < 0 ? vinside[indx] : edges[indx].v[type]); + double Atri = AreaOfTriangle( va, vb, vc ); - fprintf( flog, - "Triangle (%d %d) (%d %d) (%d %d); area %f\n", - va.x, va.y, vb.x, vb.y, vc.x, vc.y, Atri ); + fprintf( flog, + "Triangle (%d %d) (%d %d) (%d %d); area %f\n", + va.x, va.y, vb.x, vb.y, vc.x, vc.y, Atri ); - AddTriangle( tri, ctl, va, vb, vc ); + AddTriangle( tri, ctl, va, vb, vc ); - /* -------------------- */ - /* Update list of edges */ - /* -------------------- */ + /* -------------------- */ + /* Update list of edges */ + /* -------------------- */ - UpdatePolygon( edges, va, vb, vc ); + UpdatePolygon( edges, va, vb, vc ); - /* -------------- */ - /* Update vinside */ - /* -------------- */ + /* -------------- */ + /* Update vinside */ + /* -------------- */ - // If the edge came from the internal list, - // it's internal no longer, so remove it. + // If the edge came from the internal list, + // it's internal no longer, so remove it. - if( type == -1 ) - vinside.erase( vinside.begin() + indx ); + if( type == -1 ) + vinside.erase( vinside.begin() + indx ); - /* -------------------- */ - /* Update expected area */ - /* -------------------- */ + /* -------------------- */ + /* Update expected area */ + /* -------------------- */ - Aexpect = area - Atri; - } + Aexpect = area - Atri; + } /* --------------------------------- */ /* Convert back to input coordinates */ /* --------------------------------- */ - OffsetControlPoints( ctl, B ); + OffsetControlPoints( ctl, B ); /* -------------- */ /* Report success */ /* -------------- */ exit: - fprintf( flog, - "\nSTAT: From %d pts, got %ld triangles, %ld control points.\n", - npts, tri.size(), ctl.size() ); + fprintf( flog, + "\nSTAT: From %d pts, got %ld triangles, %ld control points.\n", + npts, tri.size(), ctl.size() ); - StopTiming( flog, "MeshCreate", t0 ); + StopTiming( flog, "MeshCreate", t0 ); - return 0; + return 0; } /* --------------------------------------------------------------- */ @@ -1489,199 +1489,199 @@ int MeshCreate( // Return 0 always (no error). // int MeshCreateX( - vector &tri, - vector &ctl, - const vector &pts, - const IBox &B, - FILE* flog ) + vector &tri, + vector &ctl, + const vector &pts, + const IBox &B, + FILE* flog ) { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - tri.clear(); - ctl.clear(); + tri.clear(); + ctl.clear(); /* --------------- */ /* Regular spacing */ /* --------------- */ - double Dx = GBL.mch.MNL, - Dy = GBL.mch.MNL; - int Lx = B.R - B.L, - Ly = B.T - B.B, - Nx, - Ny; - - if( !Dx || Dx >= Lx ) { - Nx = 1; - Dx = Lx; - } - else { - Nx = int(ceil( Lx / Dx )); - Dx = Lx / Nx; - } - - if( !Dy || Dy >= Ly ) { - Ny = 1; - Dy = Ly; - } - else { - Ny = int(ceil( Ly / Dy )); - Dy = Ly / Ny; - } + double Dx = GBL.mch.MNL, + Dy = GBL.mch.MNL; + int Lx = B.R - B.L, + Ly = B.T - B.B, + Nx, + Ny; + + if( !Dx || Dx >= Lx ) { + Nx = 1; + Dx = Lx; + } + else { + Nx = int(ceil( Lx / Dx )); + Dx = Lx / Nx; + } + + if( !Dy || Dy >= Ly ) { + Ny = 1; + Dy = Ly; + } + else { + Ny = int(ceil( Ly / Dy )); + Dy = Ly / Ny; + } /* ----------------------------------------- */ /* Reduce tri count while Atri < GBL.mch.MTA */ /* ----------------------------------------- */ - if( GBL.A.z != GBL.B.z ) { + if( GBL.A.z != GBL.B.z ) { - while( Nx*Ny > 1 && (Lx*Ly) / (Nx*Ny * 2) < GBL.mch.MTA ) { + while( Nx*Ny > 1 && (Lx*Ly) / (Nx*Ny * 2) < GBL.mch.MTA ) { - if( Nx >= Ny ) - Dx = Lx / --Nx; - else - Dy = Ly / --Ny; - } - } + if( Nx >= Ny ) + Dx = Lx / --Nx; + else + Dy = Ly / --Ny; + } + } /* ----------------------- */ /* Report basic grid specs */ /* ----------------------- */ - fprintf( flog, "Lx Dx Nx: %5d %8.2f %3d\n", Lx, Dx, Nx ); - fprintf( flog, "Ly Dy Ny: %5d %8.2f %3d\n", Ly, Dy, Ny ); + fprintf( flog, "Lx Dx Nx: %5d %8.2f %3d\n", Lx, Dx, Nx ); + fprintf( flog, "Ly Dy Ny: %5d %8.2f %3d\n", Ly, Dy, Ny ); /* ---------- */ /* Create ctl */ /* ---------- */ - for( int iy = 0; iy <= Ny; ++iy ) { + for( int iy = 0; iy <= Ny; ++iy ) { - int y = (iy < Ny ? B.B + int(iy*Dy) : B.T); + int y = (iy < Ny ? B.B + int(iy*Dy) : B.T); - for( int ix = 0; ix <= Nx; ++ix ) { + for( int ix = 0; ix <= Nx; ++ix ) { - int x = (ix < Nx ? B.L + int(ix*Dx) : B.R); + int x = (ix < Nx ? B.L + int(ix*Dx) : B.R); - ctl.push_back( vertex( x, y ) ); - } - } + ctl.push_back( vertex( x, y ) ); + } + } /* ---------- */ /* Create tri */ /* ---------- */ - int w = Nx + 1; + int w = Nx + 1; - for( int iy = 0; iy < Ny; ++iy ) { + for( int iy = 0; iy < Ny; ++iy ) { - for( int ix = 0; ix < Nx; ++ix ) { + for( int ix = 0; ix < Nx; ++ix ) { - triangle t; + triangle t; - t.v[0] = ix + w * iy; - t.v[1] = t.v[0] + 1; - t.v[2] = t.v[0] + w; - tri.push_back( t ); + t.v[0] = ix + w * iy; + t.v[1] = t.v[0] + 1; + t.v[2] = t.v[0] + w; + tri.push_back( t ); - t.v[0] = t.v[2]; - t.v[2] = t.v[0] + 1; - tri.push_back( t ); - } - } + t.v[0] = t.v[2]; + t.v[2] = t.v[0] + 1; + tri.push_back( t ); + } + } /* ---------------- */ /* Remove empty tri */ /* ---------------- */ - const double occ = 0.30; + const double occ = 0.30; - int ntri = tri.size(), - npnt = pts.size(); + int ntri = tri.size(), + npnt = pts.size(); // map pts into their triangles - vector in( ntri, 0 ); + vector in( ntri, 0 ); - for( int i = 0; i < npnt; ++i ) { + for( int i = 0; i < npnt; ++i ) { - vertex v( int(pts[i].x), int(pts[i].y) ); + vertex v( int(pts[i].x), int(pts[i].y) ); - for( int j = 0; j < ntri; ++j ) { + for( int j = 0; j < ntri; ++j ) { - const triangle& T = tri[j]; + const triangle& T = tri[j]; - if( InTriangle( - ctl[T.v[0]], ctl[T.v[1]], ctl[T.v[2]], v ) ) { + if( InTriangle( + ctl[T.v[0]], ctl[T.v[1]], ctl[T.v[2]], v ) ) { - ++in[j]; - break; - } - } - } + ++in[j]; + break; + } + } + } // remove tri with low occupancy - for( int i = ntri - 1; i >= 0; --i ) { + for( int i = ntri - 1; i >= 0; --i ) { - const triangle& T = tri[i]; + const triangle& T = tri[i]; - if( !in[i] || - in[i] <= occ * AreaOfTriangle( - ctl[T.v[0]], ctl[T.v[1]], ctl[T.v[2]] ) ) { + if( !in[i] || + in[i] <= occ * AreaOfTriangle( + ctl[T.v[0]], ctl[T.v[1]], ctl[T.v[2]] ) ) { - tri.erase( tri.begin() + i ); - --ntri; - } - } + tri.erase( tri.begin() + i ); + --ntri; + } + } /* ----------------------- */ /* Remove unreferenced ctl */ /* ----------------------- */ - if( ntri < in.size() ) { + if( ntri < in.size() ) { - fprintf( flog, - "\nOf %ld triangles, %d were above %3d%% occupancy.\n", - in.size(), ntri, int(occ*100.0) ); + fprintf( flog, + "\nOf %ld triangles, %d were above %3d%% occupancy.\n", + in.size(), ntri, int(occ*100.0) ); - for( int i = ctl.size() - 1; i >= 0; --i ) { + for( int i = ctl.size() - 1; i >= 0; --i ) { - for( int j = 0; j < ntri; ++j ) { + for( int j = 0; j < ntri; ++j ) { - const triangle& T = tri[j]; + const triangle& T = tri[j]; - if( T.v[0] == i || T.v[1] == i || T.v[2] == i ) - goto next_i; - } + if( T.v[0] == i || T.v[1] == i || T.v[2] == i ) + goto next_i; + } - // not ref'd + // not ref'd - ctl.erase( ctl.begin() + i ); + ctl.erase( ctl.begin() + i ); - for( int j = 0; j < ntri; ++j ) { + for( int j = 0; j < ntri; ++j ) { - triangle& T = tri[j]; + triangle& T = tri[j]; - if( T.v[0] > i ) --T.v[0]; - if( T.v[1] > i ) --T.v[1]; - if( T.v[2] > i ) --T.v[2]; - } + if( T.v[0] > i ) --T.v[0]; + if( T.v[1] > i ) --T.v[1]; + if( T.v[2] > i ) --T.v[2]; + } next_i:; - } - } + } + } /* ------------ */ /* Final report */ /* ------------ */ - fprintf( flog, - "\nSTAT: From %ld pts, got %ld triangles, %ld control points.\n", - pts.size(), tri.size(), ctl.size() ); + fprintf( flog, + "\nSTAT: From %ld pts, got %ld triangles, %ld control points.\n", + pts.size(), tri.size(), ctl.size() ); - StopTiming( flog, "MeshCreate", t0 ); + StopTiming( flog, "MeshCreate", t0 ); - return 0; + return 0; } diff --git a/1_DMesh/CreateMesh.h b/1_DMesh/CreateMesh.h index a2f9da9..5136800 100644 --- a/1_DMesh/CreateMesh.h +++ b/1_DMesh/CreateMesh.h @@ -13,28 +13,28 @@ /* --------------------------------------------------------------- */ void MeshGetBounds( - IBox &B, - const vector &pts, - FILE* flog ); + IBox &B, + const vector &pts, + FILE* flog ); void MeshMakeSingleTri( - vector &tri, - vector &ctl, - const IBox &B, - FILE* flog ); + vector &tri, + vector &ctl, + const IBox &B, + FILE* flog ); int MeshCreate( - vector &tri, - vector &ctl, - const vector &pts, - const IBox &B, - FILE* flog ); + vector &tri, + vector &ctl, + const vector &pts, + const IBox &B, + FILE* flog ); int MeshCreateX( - vector &tri, - vector &ctl, - const vector &pts, - const IBox &B, - FILE* flog ); + vector &tri, + vector &ctl, + const vector &pts, + const IBox &B, + FILE* flog ); diff --git a/1_DMesh/ImproveMesh.cpp b/1_DMesh/ImproveMesh.cpp index ac493f6..fccd0ab 100644 --- a/1_DMesh/ImproveMesh.cpp +++ b/1_DMesh/ImproveMesh.cpp @@ -52,30 +52,30 @@ // assigned to the tri[] entries here. // static void BarycentricMatrices( - vector &tri, - const vector &ctl, - FILE* flog ) + vector &tri, + const vector &ctl, + FILE* flog ) { - int ntri = tri.size(); + int ntri = tri.size(); - for( int k = 0; k < ntri; ++k ) { + for( int k = 0; k < ntri; ++k ) { - triangle& T = tri[k]; - vertex v0 = ctl[T.v[0]], - v1 = ctl[T.v[1]], - v2 = ctl[T.v[2]]; - double a[3][3]; + triangle& T = tri[k]; + vertex v0 = ctl[T.v[0]], + v1 = ctl[T.v[1]], + v2 = ctl[T.v[2]]; + double a[3][3]; - fprintf( flog, - "Tri: (%d %d) (%d %d) (%d %d).\n", - v0.x, v0.y, v1.x, v1.y, v2.x, v2.y ); + fprintf( flog, + "Tri: (%d %d) (%d %d) (%d %d).\n", + v0.x, v0.y, v1.x, v1.y, v2.x, v2.y ); - a[0][0] = v0.x; a[0][1] = v1.x; a[0][2] = v2.x; - a[1][0] = v0.y; a[1][1] = v1.y; a[1][2] = v2.y; - a[2][0] = 1.0; a[2][1] = 1.0; a[2][2] = 1.0; + a[0][0] = v0.x; a[0][1] = v1.x; a[0][2] = v2.x; + a[1][0] = v0.y; a[1][1] = v1.y; a[1][2] = v2.y; + a[2][0] = 1.0; a[2][1] = 1.0; a[2][2] = 1.0; - Invert3x3Matrix( T.a, a ); - } + Invert3x3Matrix( T.a, a ); + } } /* --------------------------------------------------------------- */ @@ -83,26 +83,26 @@ static void BarycentricMatrices( /* --------------------------------------------------------------- */ static void ListVerticesMatlab( - const vector &tri, - const vector &vrt, - const char* desc, - FILE* flog ) + const vector &tri, + const vector &vrt, + const char* desc, + FILE* flog ) { - fprintf( flog, "\n---- Matlab %s ----\n", desc ); + fprintf( flog, "\n---- Matlab %s ----\n", desc ); - int ntri = tri.size(); + int ntri = tri.size(); - for( int k = 0; k < ntri; ++k ) { + for( int k = 0; k < ntri; ++k ) { - const triangle& T = tri[k]; - vertex v0 = vrt[T.v[0]], - v1 = vrt[T.v[1]], - v2 = vrt[T.v[2]]; + const triangle& T = tri[k]; + vertex v0 = vrt[T.v[0]], + v1 = vrt[T.v[1]], + v2 = vrt[T.v[2]]; - fprintf( flog, - "x=[%d %d %d %d]; y=[%d %d %d %d]; plot(x,y); hold on;\n", - v0.x, v1.x, v2.x, v0.x, v0.y, v1.y, v2.y, v0.y ); - } + fprintf( flog, + "x=[%d %d %d %d]; y=[%d %d %d %d]; plot(x,y); hold on;\n", + v0.x, v1.x, v2.x, v0.x, v0.y, v1.y, v2.y, v0.y ); + } } /* --------------------------------------------------------------- */ @@ -123,36 +123,36 @@ static void ListVerticesMatlab( // as a function of changes in control points (mesh distortion). // static void PointsToMultipliers( - vector > &am, - const vector &tri, - const vector &ctl, - const vector &apts ) + vector > &am, + const vector &tri, + const vector &ctl, + const vector &apts ) { - int npts = apts.size(), - nctl = ctl.size(); + int npts = apts.size(), + nctl = ctl.size(); - am.resize( npts ); + am.resize( npts ); - for( int i = 0; i < npts; ++i ) { + for( int i = 0; i < npts; ++i ) { - Point ap = apts[i]; - int t = BestTriangle( tri, ctl, ap ); - const triangle& T = tri[t]; - double m[3]; + Point ap = apts[i]; + int t = BestTriangle( tri, ctl, ap ); + const triangle& T = tri[t]; + double m[3]; - m[0] = T.a[0][0]*ap.x + T.a[0][1]*ap.y + T.a[0][2]; - m[1] = T.a[1][0]*ap.x + T.a[1][1]*ap.y + T.a[1][2]; - m[2] = T.a[2][0]*ap.x + T.a[2][1]*ap.y + T.a[2][2]; + m[0] = T.a[0][0]*ap.x + T.a[0][1]*ap.y + T.a[0][2]; + m[1] = T.a[1][0]*ap.x + T.a[1][1]*ap.y + T.a[1][2]; + m[2] = T.a[2][0]*ap.x + T.a[2][1]*ap.y + T.a[2][2]; - // all multipliers zero... - vector mlong( nctl, 0.0 ); + // all multipliers zero... + vector mlong( nctl, 0.0 ); - // ...except these three - for( int j = 0; j < 3; ++j ) - mlong[T.v[j]] = m[j]; + // ...except these three + for( int j = 0; j < 3; ++j ) + mlong[T.v[j]] = m[j]; - am[i] = mlong; - } + am[i] = mlong; + } } /* --------------------------------------------------------------- */ @@ -160,26 +160,26 @@ static void PointsToMultipliers( /* --------------------------------------------------------------- */ static void ListPointsMatlab( - const vector &tri, - const vector &pts, - const char* desc, - FILE* flog ) + const vector &tri, + const vector &pts, + const char* desc, + FILE* flog ) { - fprintf( flog, "\n---- Matlab %s ----\n", desc ); + fprintf( flog, "\n---- Matlab %s ----\n", desc ); - int ntri = tri.size(); + int ntri = tri.size(); - for( int k = 0; k < ntri; ++k ) { + for( int k = 0; k < ntri; ++k ) { - const triangle& T = tri[k]; - Point v0 = pts[T.v[0]], - v1 = pts[T.v[1]], - v2 = pts[T.v[2]]; + const triangle& T = tri[k]; + Point v0 = pts[T.v[0]], + v1 = pts[T.v[1]], + v2 = pts[T.v[2]]; - fprintf( flog, - "x=[%f %f %f %f]; y=[%f %f %f %f]; plot(x,y); hold on;\n", - v0.x, v1.x, v2.x, v0.x, v0.y, v1.y, v2.y, v0.y ); - } + fprintf( flog, + "x=[%f %f %f %f]; y=[%f %f %f %f]; plot(x,y); hold on;\n", + v0.x, v1.x, v2.x, v0.x, v0.y, v1.y, v2.y, v0.y ); + } } /* --------------------------------------------------------------- */ @@ -187,22 +187,22 @@ static void ListPointsMatlab( /* --------------------------------------------------------------- */ static void ReportDeltaXY( - const vector &cpts, - const vector &bfor, - FILE* flog ) + const vector &cpts, + const vector &bfor, + FILE* flog ) { - fprintf( flog, "\n---- Deltas ----\n" ); + fprintf( flog, "\n---- Deltas ----\n" ); - int nctl = cpts.size(); + int nctl = cpts.size(); - for( int i = 0; i < nctl; ++i ) { + for( int i = 0; i < nctl; ++i ) { - double d = cpts[i].Dist( bfor[i] ); + double d = cpts[i].Dist( bfor[i] ); - fprintf( flog, - "id=%6d: dx=%8.2f dy=%8.2f d=%8.2f\n", - i, cpts[i].x - bfor[i].x, cpts[i].y - bfor[i].y, d ); - } + fprintf( flog, + "id=%6d: dx=%8.2f dy=%8.2f d=%8.2f\n", + i, cpts[i].x - bfor[i].x, cpts[i].y - bfor[i].y, d ); + } } /* --------------------------------------------------------------- */ @@ -212,59 +212,59 @@ static void ReportDeltaXY( // Return true if overall area changes are within tolerances. // static bool CheckAreas( - const vector &tri, - const vector &orig, - const vector &cpts, - FILE* flog ) + const vector &tri, + const vector &orig, + const vector &cpts, + FILE* flog ) { - fprintf( flog, "\n---- Areas ----\n" ); + fprintf( flog, "\n---- Areas ----\n" ); /* --------------------------- */ /* Get cumulative area changes */ /* --------------------------- */ - double max_pct = 0.0, - sum_A0 = 0.0, - sum_Anew = 0.0; - int ntri = tri.size(); + double max_pct = 0.0, + sum_A0 = 0.0, + sum_Anew = 0.0; + int ntri = tri.size(); - for( int k = 0; k < ntri; ++k ) { + for( int k = 0; k < ntri; ++k ) { - double A0 = tri[k].Area( orig ); + double A0 = tri[k].Area( orig ); - if( GBL.A.z != GBL.B.z ) { + if( GBL.A.z != GBL.B.z ) { - double f = GBL.ctx.Tdfm.EffArea(); + double f = GBL.ctx.Tdfm.EffArea(); - if( f < 0.99 || f > 1.01 ) { + if( f < 0.99 || f > 1.01 ) { - fprintf( flog, - "Modifying old area from %f to %f because scale" - " change was specified.\n", A0, A0 * f ); + fprintf( flog, + "Modifying old area from %f to %f because scale" + " change was specified.\n", A0, A0 * f ); - A0 *= f; - } - } + A0 *= f; + } + } - sum_A0 += A0; + sum_A0 += A0; - double Anew = tri[k].Area( cpts ); - double pct = (Anew - A0) / A0 * 100.0; + double Anew = tri[k].Area( cpts ); + double pct = (Anew - A0) / A0 * 100.0; - sum_Anew += Anew; + sum_Anew += Anew; - fprintf( flog, - "Triangle %d, area was %10.1f, is %10.1f, %6.1f%%\n", - k, A0, Anew, pct ); + fprintf( flog, + "Triangle %d, area was %10.1f, is %10.1f, %6.1f%%\n", + k, A0, Anew, pct ); - max_pct = fmax( max_pct, fabs( pct ) ); - } + max_pct = fmax( max_pct, fabs( pct ) ); + } - double sum_pct = (sum_Anew - sum_A0) / sum_A0 * 100.0; + double sum_pct = (sum_Anew - sum_A0) / sum_A0 * 100.0; - fprintf( flog, - "Combined: area was %10.1f, is %10.1f, %6.1f%%\n", - sum_A0, sum_Anew, sum_pct ); + fprintf( flog, + "Combined: area was %10.1f, is %10.1f, %6.1f%%\n", + sum_A0, sum_Anew, sum_pct ); /* ------------------ */ /* Assess area change */ @@ -275,22 +275,22 @@ static bool CheckAreas( // If new tris cover wide area, use more generous TSC. // - double sum_lim = GBL.mch.TSC; + double sum_lim = GBL.mch.TSC; - if( sum_Anew > 500000 ) - sum_lim *= 4.0/3.0; + if( sum_Anew > 500000 ) + sum_lim *= 4.0/3.0; - if( max_pct > GBL.mch.TMC || fabs( sum_pct ) > sum_lim ) { + if( max_pct > GBL.mch.TMC || fabs( sum_pct ) > sum_lim ) { - fprintf( flog, - "FAIL: Area change too big" - " (max, sum) = (%8.2f%% %8.2f%%), (TMC TSC)=(%f %f).\n", - max_pct, sum_pct, GBL.mch.TMC, sum_lim ); + fprintf( flog, + "FAIL: Area change too big" + " (max, sum) = (%8.2f%% %8.2f%%), (TMC TSC)=(%f %f).\n", + max_pct, sum_pct, GBL.mch.TMC, sum_lim ); - return false; - } + return false; + } - return true; + return true; } /* --------------------------------------------------------------- */ @@ -298,101 +298,101 @@ static bool CheckAreas( /* --------------------------------------------------------------- */ static void TransformsAndCenters( - vector &transforms, - vector ¢ers, - const vector &tri, - const vector &orig, - const vector &cpts, - const TAffine &tr_guess, - FILE* flog ) + vector &transforms, + vector ¢ers, + const vector &tri, + const vector &orig, + const vector &cpts, + const TAffine &tr_guess, + FILE* flog ) { - fprintf( flog, "\n---- Transforms ----\n" ); + fprintf( flog, "\n---- Transforms ----\n" ); - int ntri = tri.size(); + int ntri = tri.size(); - for( int k = 0; k < ntri; ++k ) { + for( int k = 0; k < ntri; ++k ) { - const triangle& T = tri[k]; - int i0 = T.v[0], - i1 = T.v[1], - i2 = T.v[2]; + const triangle& T = tri[k]; + int i0 = T.v[0], + i1 = T.v[1], + i2 = T.v[2]; - // Find transformation that maps original control points - // (orig) into optimized (cpts). - // - // Begin with a transform mapping a unit right triangle - // { (0,0), (1,0), (0,1) } in abstract global space to - // the respective orig vertices { o0, o1, o2 }. To see - // how simple this really is, just apply the TAffine (o) - // that we define below to each of the global vertices. + // Find transformation that maps original control points + // (orig) into optimized (cpts). + // + // Begin with a transform mapping a unit right triangle + // { (0,0), (1,0), (0,1) } in abstract global space to + // the respective orig vertices { o0, o1, o2 }. To see + // how simple this really is, just apply the TAffine (o) + // that we define below to each of the global vertices. - const Point& o0 = orig[i0], - o1 = orig[i1], - o2 = orig[i2]; + const Point& o0 = orig[i0], + o1 = orig[i1], + o2 = orig[i2]; - TAffine o( o1.x - o0.x, o2.x - o0.x, o0.x, - o1.y - o0.y, o2.y - o0.y, o0.y ); + TAffine o( o1.x - o0.x, o2.x - o0.x, o0.x, + o1.y - o0.y, o2.y - o0.y, o0.y ); - // And make a like mapping from global space to (cpts) + // And make a like mapping from global space to (cpts) - const Point& c0 = cpts[i0], - c1 = cpts[i1], - c2 = cpts[i2]; + const Point& c0 = cpts[i0], + c1 = cpts[i1], + c2 = cpts[i2]; - TAffine c( c1.x - c0.x, c2.x - c0.x, c0.x, - c1.y - c0.y, c2.y - c0.y, c0.y ); + TAffine c( c1.x - c0.x, c2.x - c0.x, c0.x, + c1.y - c0.y, c2.y - c0.y, c0.y ); - // Now make transform t = c * o-inv from orig to cpts + // Now make transform t = c * o-inv from orig to cpts - TAffine t, oi; + TAffine t, oi; - oi.InverseOf( o ); - t = c * oi; + oi.InverseOf( o ); + t = c * oi; - t.TPrint( flog ); + t.TPrint( flog ); - // Sanity check the "angular" change + // Sanity check the "angular" change - if( (fabs( t.t[0] - 1.0 ) > 0.1 && - fabs( t.t[0] - tr_guess.t[0] ) > 0.1) - || - (fabs( t.t[4] - 1.0 ) > 0.1 && - fabs( t.t[4] - tr_guess.t[4] ) > 0.1) ) { + if( (fabs( t.t[0] - 1.0 ) > 0.1 && + fabs( t.t[0] - tr_guess.t[0] ) > 0.1) + || + (fabs( t.t[4] - 1.0 ) > 0.1 && + fabs( t.t[4] - tr_guess.t[4] ) > 0.1) ) { - fprintf( flog, - "Large deviation in t[0], t[4]: vertices %d %d %d\n", - i0, i1, i2 ); + fprintf( flog, + "Large deviation in t[0], t[4]: vertices %d %d %d\n", + i0, i1, i2 ); - fprintf( flog, - "orig (%f %f) (%f %f) (%f %f).\n", - o0.x, o0.y, o1.x, o1.y, o2.x, o2.y ); + fprintf( flog, + "orig (%f %f) (%f %f) (%f %f).\n", + o0.x, o0.y, o1.x, o1.y, o2.x, o2.y ); - fprintf( flog, - "cpts (%f %f) (%f %f) (%f %f)\n", - c0.x, c0.y, c1.x, c1.y, c2.x, c2.y ); - } + fprintf( flog, + "cpts (%f %f) (%f %f) (%f %f)\n", + c0.x, c0.y, c1.x, c1.y, c2.x, c2.y ); + } - transforms.push_back( t ); + transforms.push_back( t ); - // Each center is initially just a triangle centroid, - // although any point interior to triangle will do. + // Each center is initially just a triangle centroid, + // although any point interior to triangle will do. - double cenx = (o0.x + o1.x + o2.x) / 3.0, - ceny = (o0.y + o1.y + o2.y) / 3.0; + double cenx = (o0.x + o1.x + o2.x) / 3.0, + ceny = (o0.y + o1.y + o2.y) / 3.0; - // Now we jiggle along a line segment from centroid - // to vertex 0. The purpose is that in rare instances - // when affines are all the same because optimizer did - // nothing, if centers are also colinear, then solver - // matrices become degenerate. Jiggling avoids that. + // Now we jiggle along a line segment from centroid + // to vertex 0. The purpose is that in rare instances + // when affines are all the same because optimizer did + // nothing, if centers are also colinear, then solver + // matrices become degenerate. Jiggling avoids that. - double seglenscl = double(rand()) / (10.0 * RAND_MAX); + double seglenscl = double(rand()) / (10.0 * RAND_MAX); - cenx += seglenscl * (o0.x - cenx); - ceny += seglenscl * (o0.y - ceny); + cenx += seglenscl * (o0.x - cenx); + ceny += seglenscl * (o0.y - ceny); - centers.push_back( Point( cenx, ceny ) ); - } + centers.push_back( Point( cenx, ceny ) ); + } } /* --------------------------------------------------------------- */ @@ -411,48 +411,48 @@ static void TransformsAndCenters( // describe - descriptive string for logs // double ImproveMesh( - vector &transforms, - vector ¢ers, - vector &tri, - const vector &ctl, - const vector &apts, - const vector &av, - const vector &bimg, - int w, - int h, - const TAffine &tr_guess, - double threshold, - FILE *flog, - const char *describe ) + vector &transforms, + vector ¢ers, + vector &tri, + const vector &ctl, + const vector &apts, + const vector &av, + const vector &bimg, + int w, + int h, + const TAffine &tr_guess, + double threshold, + FILE *flog, + const char *describe ) { - fprintf( flog, "\n---- ImproveMesh - %s ----\n", describe ); + fprintf( flog, "\n---- ImproveMesh - %s ----\n", describe ); /* ---------------------- */ /* Init output transforms */ /* ---------------------- */ - transforms.clear(); - centers.clear(); + transforms.clear(); + centers.clear(); /* --------------------------------- */ /* Make point-to-multiplier matrices */ /* --------------------------------- */ - BarycentricMatrices( tri, ctl, flog ); + BarycentricMatrices( tri, ctl, flog ); /* --------------------------------- */ /* Report triangles in Matlab format */ /* --------------------------------- */ - ListVerticesMatlab( tri, ctl, "Vertices", flog ); + ListVerticesMatlab( tri, ctl, "Vertices", flog ); /* --------------------- */ /* Points to multipliers */ /* --------------------- */ - vector > am; + vector > am; - PointsToMultipliers( am, tri, ctl, apts ); + PointsToMultipliers( am, tri, ctl, apts ); /* -------------------- */ /* Init change tracking */ @@ -463,22 +463,22 @@ double ImproveMesh( // (2) bfor: are transformed to B-coords but not optimized // (3) cpts: are the optimized points - int nctl = ctl.size(); - vector orig( nctl ), bfor, cpts; + int nctl = ctl.size(); + vector orig( nctl ), bfor, cpts; - for( int k = 0; k < nctl; ++k ) - orig[k] = Point( ctl[k].x, ctl[k].y ); + for( int k = 0; k < nctl; ++k ) + orig[k] = Point( ctl[k].x, ctl[k].y ); - bfor = orig; - tr_guess.Transform( bfor ); + bfor = orig; + tr_guess.Transform( bfor ); - cpts = bfor; + cpts = bfor; /* ------------- */ /* Optimize mesh */ /* ------------- */ - fprintf( flog, "\n---- ImproveControlPts ----\n" ); + fprintf( flog, "\n---- ImproveControlPts ----\n" ); // On entry, corr temporarily holds the desired final // threshold. On exit, corr is the mesh correlation. @@ -495,51 +495,51 @@ double ImproveMesh( // For homogeneous EM case, mesh optimization works well and // is always recommended. - double corr = threshold; + double corr = threshold; - if( !GBL.ctx.OPT ) - corr = -1; + if( !GBL.ctx.OPT ) + corr = -1; - corr = ImproveControlPts( - cpts, am, av, - bimg, w, h, - flog, describe, - GBL.ctx.RIT, corr ); + corr = ImproveControlPts( + cpts, am, av, + bimg, w, h, + flog, describe, + GBL.ctx.RIT, corr ); - if( corr < threshold ) { + if( corr < threshold ) { - fprintf( flog, - "FAIL: ImproveMesh: corr=%f, below final thresh=%f\n", - corr, threshold ); + fprintf( flog, + "FAIL: ImproveMesh: corr=%f, below final thresh=%f\n", + corr, threshold ); - return corr; - } + return corr; + } /* -------------- */ /* Report results */ /* -------------- */ - ListPointsMatlab( tri, orig, "A-Sys Originals", flog ); - ListPointsMatlab( tri, bfor, "B-Sys Originals", flog ); - ListPointsMatlab( tri, cpts, "B-Sys Optimized", flog ); + ListPointsMatlab( tri, orig, "A-Sys Originals", flog ); + ListPointsMatlab( tri, bfor, "B-Sys Originals", flog ); + ListPointsMatlab( tri, cpts, "B-Sys Optimized", flog ); - ReportDeltaXY( cpts, bfor, flog ); + ReportDeltaXY( cpts, bfor, flog ); /* ----------- */ /* Check areas */ /* ----------- */ - if( !CheckAreas( tri, orig, cpts, flog ) ) - return 0.0; + if( !CheckAreas( tri, orig, cpts, flog ) ) + return 0.0; /* ------------------------------------------ */ /* Get transform and center for each triangle */ /* ------------------------------------------ */ - TransformsAndCenters( transforms, centers, - tri, orig, cpts, tr_guess, flog ); + TransformsAndCenters( transforms, centers, + tri, orig, cpts, tr_guess, flog ); - return corr; + return corr; } diff --git a/1_DMesh/ImproveMesh.h b/1_DMesh/ImproveMesh.h index dc638f1..6364112 100644 --- a/1_DMesh/ImproveMesh.h +++ b/1_DMesh/ImproveMesh.h @@ -12,18 +12,18 @@ /* --------------------------------------------------------------- */ double ImproveMesh( - vector &transforms, - vector ¢ers, - vector &tri, - const vector &ctl, - const vector &apts, - const vector &av, - const vector &bimg, - int w, - int h, - const TAffine &tr_guess, - double threshold, - FILE *flog, - const char *describe ); + vector &transforms, + vector ¢ers, + vector &tri, + const vector &ctl, + const vector &apts, + const vector &av, + const vector &bimg, + int w, + int h, + const TAffine &tr_guess, + double threshold, + FILE *flog, + const char *describe ); diff --git a/1_DMesh/InSectionOverlap.cpp b/1_DMesh/InSectionOverlap.cpp index 542e73a..ce66342 100644 --- a/1_DMesh/InSectionOverlap.cpp +++ b/1_DMesh/InSectionOverlap.cpp @@ -27,7 +27,7 @@ // Tells if a point is inside a given rectangle static bool Inside( int x, int y, int x1, int y1, int x2, int y2 ) { - return x > x1 && x < x2 && y > y1 && y < y2; + return x > x1 && x < x2 && y > y1 && y < y2; } /* --------------------------------------------------------------- */ @@ -40,10 +40,10 @@ static bool Inside( int x, int y, int x1, int y1, int x2, int y2 ) // static bool InSectionLegal( int nx, int ny, void *a ) { - double n = nx * ny; + double n = nx * ny; // 30,000 total pixels, and at least one side is 1500 pixels long - return n > 30000 && (nx >= 1500 || ny > 1500); + return n > 30000 && (nx >= 1500 || ny > 1500); } /* --------------------------------------------------------------- */ @@ -51,23 +51,23 @@ static bool InSectionLegal( int nx, int ny, void *a ) /* --------------------------------------------------------------- */ static void MakeLambda( - vector &l, - Point p, - vector &cpts, - int i0, - int i1, - int i2, - int i3 ) + vector &l, + Point p, + vector &cpts, + int i0, + int i1, + int i2, + int i3 ) { // 0 2 // 1 3 - double alpha = (p.x-cpts[i0].x)/(cpts[i2].x-cpts[i0].x); - double beta = (p.y-cpts[i0].y)/(cpts[i1].y-cpts[i0].y); + double alpha = (p.x-cpts[i0].x)/(cpts[i2].x-cpts[i0].x); + double beta = (p.y-cpts[i0].y)/(cpts[i1].y-cpts[i0].y); - l[i0] = (1-alpha)*(1-beta); - l[i1] = (1-alpha)* beta; - l[i2] = alpha *(1-beta); - l[i3] = alpha * beta; + l[i0] = (1-alpha)*(1-beta); + l[i1] = (1-alpha)* beta; + l[i2] = alpha *(1-beta); + l[i3] = alpha * beta; } /* --------------------------------------------------------------- */ @@ -75,16 +75,16 @@ static void MakeLambda( /* --------------------------------------------------------------- */ static Point PointAvg( - vector &pts, - int i1, - int i2, - int i3, - int i4 ) + vector &pts, + int i1, + int i2, + int i3, + int i4 ) { - Point P( (pts[i1].x + pts[i2].x + pts[i3].x + pts[i4].x)/4, - (pts[i1].y + pts[i2].y + pts[i3].y + pts[i4].y)/4 ); + Point P( (pts[i1].x + pts[i2].x + pts[i3].x + pts[i4].x)/4, + (pts[i1].y + pts[i2].y + pts[i3].y + pts[i4].y)/4 ); - return P; + return P; } /* --------------------------------------------------------------- */ @@ -102,272 +102,272 @@ static Point PointAvg( // flog - log text file // void InSectionOverlap( - int &Npts, - double* &apts, - double* &bpts, - const PixPair &px, - FILE* flog ) + int &Npts, + double* &apts, + double* &bpts, + const PixPair &px, + FILE* flog ) { - const vector& av_aln = *px.avs_aln; - const vector& bv_aln = *px.bvs_aln; - int w = px.ws, - h = px.hs; + const vector& av_aln = *px.avs_aln; + const vector& bv_aln = *px.bvs_aln; + int w = px.ws, + h = px.hs; // Find how each of these regions overlap at the edges, // if indeed they do at all. - const double frame = 0.10 ; // size of the frame - int x1 = int(frame*w); // coord of center hole - int x2 = w - 1 - x1; - int y1 = int(frame*h); - int y2 = h - 1 - y1; + const double frame = 0.10 ; // size of the frame + int x1 = int(frame*w); // coord of center hole + int x2 = w - 1 - x1; + int y1 = int(frame*h); + int y2 = h - 1 - y1; - fprintf( flog, - "Olap: w %d, h %d, x1 %d, y1 %d, x2, %d, y2 %d\n", - w, h, x1, y1, x2, y2 ); + fprintf( flog, + "Olap: w %d, h %d, x1 %d, y1 %d, x2, %d, y2 %d\n", + w, h, x1, y1, x2, y2 ); // Collect normalized points from the frame (border) area // of the images. - vector image2( 4096 * 4096, 0.0 ); - vector ap, bp; - vector av, bv; - MeanStd ma, mb; - double meana, stda, meanb, stdb; + vector image2( 4096 * 4096, 0.0 ); + vector ap, bp; + vector av, bv; + MeanStd ma, mb; + double meana, stda, meanb, stdb; - for( int ix = 0; ix < w; ++ix ) { + for( int ix = 0; ix < w; ++ix ) { - for( int iy = 0; iy < h; ++iy ) { + for( int iy = 0; iy < h; ++iy ) { - if( !Inside( ix, iy, x1, y1, x2, y2 ) ) { + if( !Inside( ix, iy, x1, y1, x2, y2 ) ) { - ma.Element( av_aln[ix + w*iy] ); - mb.Element( bv_aln[ix + w*iy] ); - } - } - } + ma.Element( av_aln[ix + w*iy] ); + mb.Element( bv_aln[ix + w*iy] ); + } + } + } - ma.Stats( meana, stda ); - mb.Stats( meanb, stdb ); + ma.Stats( meana, stda ); + mb.Stats( meanb, stdb ); - fprintf( flog, - "Olap: Frame size %d pixels, %f percent.\n", - ma.HowMany(), ma.HowMany()*100.0 / (w*h) ); + fprintf( flog, + "Olap: Frame size %d pixels, %f percent.\n", + ma.HowMany(), ma.HowMany()*100.0 / (w*h) ); - fprintf( flog, - "Olap: A frame mean = %f and std dev = %f\n", - meana, stda ); + fprintf( flog, + "Olap: A frame mean = %f and std dev = %f\n", + meana, stda ); - fprintf( flog, - "Olap: B frame mean = %f and std dev = %f\n", - meanb, stdb ); + fprintf( flog, + "Olap: B frame mean = %f and std dev = %f\n", + meanb, stdb ); - for( int ix = 0; ix < w; ++ix ) { + for( int ix = 0; ix < w; ++ix ) { - for( int iy = 0; iy < h; ++iy ) { + for( int iy = 0; iy < h; ++iy ) { - if( !Inside( ix, iy, x1, y1, x2, y2 ) ) { + if( !Inside( ix, iy, x1, y1, x2, y2 ) ) { - Point p( ix, iy ); - double apx = (av_aln[ix + w*iy] - meana) / stda, - bpx = (bv_aln[ix + w*iy] - meanb) / stdb; + Point p( ix, iy ); + double apx = (av_aln[ix + w*iy] - meana) / stda, + bpx = (bv_aln[ix + w*iy] - meanb) / stdb; - ap.push_back( p ); - bp.push_back( p ); + ap.push_back( p ); + bp.push_back( p ); - av.push_back( apx ); - bv.push_back( bpx ); + av.push_back( apx ); + bv.push_back( bpx ); - image2[ix + 4096*iy] = bpx; - } - } - } + image2[ix + 4096*iy] = bpx; + } + } + } // Now call the FFT routine to do the actual work.... - double dx, dy; - vector ftc; - double c = CorrPatches( - flog, false, dx, dy, - ap, av, bp, bv, 0, 0, 4000, - InSectionLegal, NULL, - NULL, NULL, ftc ); + double dx, dy; + vector ftc; + double c = CorrPatches( + flog, false, dx, dy, + ap, av, bp, bv, 0, 0, 4000, + InSectionLegal, NULL, + NULL, NULL, ftc ); - if( c < GBL.ctx.RTRSH ) { // empirical + if( c < GBL.ctx.RTRSH ) { // empirical - fprintf( flog, - "Olap: Can't find a good starting point" - " - maximum c = %f\n", c ); + fprintf( flog, + "Olap: Can't find a good starting point" + " - maximum c = %f\n", c ); - Npts = 0; - return; - } + Npts = 0; + return; + } - fprintf( flog, "Olap: dx, dy = %f %f\n", dx, dy ); + fprintf( flog, "Olap: dx, dy = %f %f\n", dx, dy ); - int idx = int(floor(dx+0.5)); // round - int idy = int(floor(dy+0.5)); + int idx = int(floor(dx+0.5)); // round + int idy = int(floor(dy+0.5)); - IBox OL1, OL2; - BoxesFromShifts( OL1, OL2, w, w, w, w, idx, idy ); + IBox OL1, OL2; + BoxesFromShifts( OL1, OL2, w, w, w, w, idx, idy ); // here we assume the box is horizontal. - vector cpts( 8, Point(0.0, 0.0) ); - vector > lambdas; - vector spv; // source pixel values - bool horizontal = OL1.R-OL1.L > OL1.T-OL1.B; - double xm1 = OL1.L + 0.25*(OL1.R-OL1.L); - double xm2 = OL1.L + 0.75*(OL1.R-OL1.L); - double ym1 = OL1.B + 0.25*(OL1.T-OL1.B); - double ym2 = OL1.B + 0.75*(OL1.T-OL1.B); - - if( horizontal ) { - - // Arrange the points like this: - // 0 2 4 6 - // 1 3 5 7 - cpts[1] = Point(OL1.L, OL1.T); - cpts[3] = Point(xm1, OL1.T); - cpts[5] = Point(xm2, OL1.T); - cpts[7] = Point(OL1.R, OL1.T); - cpts[0] = Point(OL1.L, OL1.B); - cpts[2] = Point(xm1, OL1.B); - cpts[4] = Point(xm2, OL1.B); - cpts[6] = Point(OL1.R, OL1.B); - } - else { // box is more vertical - - // 0 1 - // 2 3 - // 4 5 - // 6 7 - cpts[6] = Point(OL1.L, OL1.T); - cpts[7] = Point(OL1.R, OL1.T); - cpts[4] = Point(OL1.L, ym2); - cpts[5] = Point(OL1.R, ym2); - cpts[2] = Point(OL1.L, ym1); - cpts[3] = Point(OL1.R, ym1); - cpts[0] = Point(OL1.L, OL1.B); - cpts[1] = Point(OL1.R, OL1.B); - } - - for( int iy = OL1.B; iy <= OL1.T; ++iy ) { - - for( int ix = OL1.L; ix <= OL1.R; ++ix ) { - - spv.push_back( av_aln[ix + w*iy] ); - vector l( 8, 0.0 ); - Point p( ix, iy ); - - if( horizontal ) { - - if( ix < xm1 ) - MakeLambda( l, p, cpts, 0, 1, 2, 3 ); - else if( ix < xm2 ) - MakeLambda( l, p, cpts, 2, 3, 4, 5 ); - else - MakeLambda( l, p, cpts, 4, 5, 6, 7 ); - } - else { // box is vertical - - if( iy < ym1 ) - MakeLambda( l, p, cpts, 0, 2, 1, 3 ); - else if( iy < ym2 ) - MakeLambda( l, p, cpts, 2, 4, 3, 5 ); - else - MakeLambda( l, p, cpts, 4, 6, 5, 7 ); - } - - lambdas.push_back( l ); - } - } - - vector before = cpts; // start with 8 control points - before.push_back( PointAvg(cpts, 0, 1, 2, 3) ); // add rect centers - before.push_back( PointAvg(cpts, 2, 3, 4, 5) ); - before.push_back( PointAvg(cpts, 4, 5, 6, 7) ); + vector cpts( 8, Point(0.0, 0.0) ); + vector > lambdas; + vector spv; // source pixel values + bool horizontal = OL1.R-OL1.L > OL1.T-OL1.B; + double xm1 = OL1.L + 0.25*(OL1.R-OL1.L); + double xm2 = OL1.L + 0.75*(OL1.R-OL1.L); + double ym1 = OL1.B + 0.25*(OL1.T-OL1.B); + double ym2 = OL1.B + 0.75*(OL1.T-OL1.B); + + if( horizontal ) { + + // Arrange the points like this: + // 0 2 4 6 + // 1 3 5 7 + cpts[1] = Point(OL1.L, OL1.T); + cpts[3] = Point(xm1, OL1.T); + cpts[5] = Point(xm2, OL1.T); + cpts[7] = Point(OL1.R, OL1.T); + cpts[0] = Point(OL1.L, OL1.B); + cpts[2] = Point(xm1, OL1.B); + cpts[4] = Point(xm2, OL1.B); + cpts[6] = Point(OL1.R, OL1.B); + } + else { // box is more vertical + + // 0 1 + // 2 3 + // 4 5 + // 6 7 + cpts[6] = Point(OL1.L, OL1.T); + cpts[7] = Point(OL1.R, OL1.T); + cpts[4] = Point(OL1.L, ym2); + cpts[5] = Point(OL1.R, ym2); + cpts[2] = Point(OL1.L, ym1); + cpts[3] = Point(OL1.R, ym1); + cpts[0] = Point(OL1.L, OL1.B); + cpts[1] = Point(OL1.R, OL1.B); + } + + for( int iy = OL1.B; iy <= OL1.T; ++iy ) { + + for( int ix = OL1.L; ix <= OL1.R; ++ix ) { + + spv.push_back( av_aln[ix + w*iy] ); + vector l( 8, 0.0 ); + Point p( ix, iy ); + + if( horizontal ) { + + if( ix < xm1 ) + MakeLambda( l, p, cpts, 0, 1, 2, 3 ); + else if( ix < xm2 ) + MakeLambda( l, p, cpts, 2, 3, 4, 5 ); + else + MakeLambda( l, p, cpts, 4, 5, 6, 7 ); + } + else { // box is vertical + + if( iy < ym1 ) + MakeLambda( l, p, cpts, 0, 2, 1, 3 ); + else if( iy < ym2 ) + MakeLambda( l, p, cpts, 2, 4, 3, 5 ); + else + MakeLambda( l, p, cpts, 4, 6, 5, 7 ); + } + + lambdas.push_back( l ); + } + } + + vector before = cpts; // start with 8 control points + before.push_back( PointAvg(cpts, 0, 1, 2, 3) ); // add rect centers + before.push_back( PointAvg(cpts, 2, 3, 4, 5) ); + before.push_back( PointAvg(cpts, 4, 5, 6, 7) ); // Now transfer the control points to image b's coordinate system. - for( int i = 0; i < 8; ++i ) { + for( int i = 0; i < 8; ++i ) { - cpts[i].x += dx; - cpts[i].y += dy; - } + cpts[i].x += dx; + cpts[i].y += dy; + } // Now improve the correlation by gradient descent - double threshold = 0.5; + double threshold = 0.5; - c = ImproveControlPts( - cpts, lambdas, spv, image2, 4096, 4096, flog, - "in-section", GBL.ctx.RIT, threshold ); + c = ImproveControlPts( + cpts, lambdas, spv, image2, 4096, 4096, flog, + "in-section", GBL.ctx.RIT, threshold ); - if( c < threshold ) { + if( c < threshold ) { - fprintf( flog, - "Olap: Correlation not good enough - %f\n", c ); + fprintf( flog, + "Olap: Correlation not good enough - %f\n", c ); - Npts = 0; - return; - } + Npts = 0; + return; + } - vector after = cpts; - after.push_back( PointAvg(cpts, 0, 1, 2, 3) ); - after.push_back( PointAvg(cpts, 2, 3, 4, 5) ); - after.push_back( PointAvg(cpts, 4, 5, 6, 7) ); + vector after = cpts; + after.push_back( PointAvg(cpts, 0, 1, 2, 3) ); + after.push_back( PointAvg(cpts, 2, 3, 4, 5) ); + after.push_back( PointAvg(cpts, 4, 5, 6, 7) ); // Keep only the points that map into both images. // Source points will always be inside, by construction, but // some of the target points may fall outside after detailed // matching (rotation, for example). - for( int i = 0; i < after.size(); ) { + for( int i = 0; i < after.size(); ) { - if( after[i].x >= 0 && - after[i].x < w && - after[i].y >= 0 && - after[i].y < w ) { // it's OK + if( after[i].x >= 0 && + after[i].x < w && + after[i].y >= 0 && + after[i].y < w ) { // it's OK - ++i; - } - else { // image - before.erase( before.begin() + i ); - after.erase( after.begin() + i ); - } - } + ++i; + } + else { // image + before.erase( before.begin() + i ); + after.erase( after.begin() + i ); + } + } // fill in points - Npts = after.size(); + Npts = after.size(); - fprintf( flog, "Olap: %d matching points.\n", Npts ); + fprintf( flog, "Olap: %d matching points.\n", Npts ); - apts = (double*)malloc( 2*Npts * sizeof(double) ); - bpts = (double*)malloc( 2*Npts * sizeof(double) ); + apts = (double*)malloc( 2*Npts * sizeof(double) ); + bpts = (double*)malloc( 2*Npts * sizeof(double) ); // scale back to original image size, if bigger than 2K. - int sc = px.scl; + int sc = px.scl; - for( int i = 0; i < Npts; ++i ) { + for( int i = 0; i < Npts; ++i ) { - fprintf( flog, - "Olap: Point (%7.2f %7.2f) in image 1" - " maps to point (%7.2f %7.2f) in image 2," - " delta (%7.2f %7.2f).\n", - sc*before[i].x, sc*before[i].y, - sc*after[i].x, sc*after[i].y, - sc*before[i].x - sc*after[i].x, - sc*before[i].y - sc*after[i].y ); + fprintf( flog, + "Olap: Point (%7.2f %7.2f) in image 1" + " maps to point (%7.2f %7.2f) in image 2," + " delta (%7.2f %7.2f).\n", + sc*before[i].x, sc*before[i].y, + sc*after[i].x, sc*after[i].y, + sc*before[i].x - sc*after[i].x, + sc*before[i].y - sc*after[i].y ); - apts[2*i] = sc*before[i].x; - apts[2*i + 1] = sc*before[i].y; + apts[2*i] = sc*before[i].x; + apts[2*i + 1] = sc*before[i].y; - bpts[2*i] = sc*after[i].x; - bpts[2*i + 1] = sc*after[i].y; - } + bpts[2*i] = sc*after[i].x; + bpts[2*i + 1] = sc*after[i].y; + } } diff --git a/1_DMesh/InSectionOverlap.h b/1_DMesh/InSectionOverlap.h index 7280aa3..c39c3aa 100644 --- a/1_DMesh/InSectionOverlap.h +++ b/1_DMesh/InSectionOverlap.h @@ -11,10 +11,10 @@ /* --------------------------------------------------------------- */ void InSectionOverlap( - int &Npts, - double* &apts, - double* &bpts, - const PixPair &px, - FILE* flog ); + int &Npts, + double* &apts, + double* &bpts, + const PixPair &px, + FILE* flog ); diff --git a/1_DMesh/RegionToRegionMap.cpp b/1_DMesh/RegionToRegionMap.cpp index 600f286..a83a3a8 100644 --- a/1_DMesh/RegionToRegionMap.cpp +++ b/1_DMesh/RegionToRegionMap.cpp @@ -38,9 +38,9 @@ // class CMatch { public: - vector pts; // points in image a - vector a; // value in image a (source) - vector b; // value in image b (target) + vector pts; // points in image a + vector a; // value in image a (source) + vector b; // value in image b (target) }; /* --------------------------------------------------------------- */ @@ -48,20 +48,20 @@ class CMatch { /* --------------------------------------------------------------- */ static double Metric( - const vector &pts, - const vector &av, - const vector &bv, - const char *msg, - FILE* flog ) + const vector &pts, + const vector &av, + const vector &bv, + const char *msg, + FILE* flog ) { - if( GBL.mch.EMM ) { - return EarthMoversMetric( pts, av, bv, - GBL.mch.WDI, msg, flog ); - } - else { - return FourierMatch( pts, av, bv, 25, - GBL.mch.WDI, msg, flog ); - } + if( GBL.mch.EMM ) { + return EarthMoversMetric( pts, av, bv, + GBL.mch.WDI, msg, flog ); + } + else { + return FourierMatch( pts, av, bv, 25, + GBL.mch.WDI, msg, flog ); + } } /* --------------------------------------------------------------- */ @@ -74,81 +74,81 @@ static double Metric( // static int SelfConsistent( const vector &vT, FILE* flog ) { - int nT = vT.size(); + int nT = vT.size(); - if( nT <= 1 ) - return nT; + if( nT <= 1 ) + return nT; // Compute value spread for each transform element - double ang_min = PI; - double ang_max = -PI; - vector pmax( 6, -1e30 ); - vector pmin( 6, 1e30 ); - vector pspan( 6 ); - bool extreme = false; + double ang_min = PI; + double ang_max = -PI; + vector pmax( 6, -1e30 ); + vector pmin( 6, 1e30 ); + vector pspan( 6 ); + bool extreme = false; // Collect maxima and minima - for( int i = 0; i < nT; ++i ) { + for( int i = 0; i < nT; ++i ) { - double ang = vT[i].GetRadians(); + double ang = vT[i].GetRadians(); - // handle atan() branch cuts + // handle atan() branch cuts - if( i > 0 ) { + if( i > 0 ) { - if( ang > ang_max + PI ) - ang = ang - 2.0*PI; - else if( ang < ang_min - PI ) - ang = ang + 2.0*PI; - } + if( ang > ang_max + PI ) + ang = ang - 2.0*PI; + else if( ang < ang_min - PI ) + ang = ang + 2.0*PI; + } - ang_min = fmin( ang_min, ang ); - ang_max = fmax( ang_max, ang ); + ang_min = fmin( ang_min, ang ); + ang_max = fmax( ang_max, ang ); - for( int j = 0; j < 6; ++j ) { - pmax[j] = max( pmax[j], vT[i].t[j] ); - pmin[j] = min( pmin[j], vT[i].t[j] ); - } - } + for( int j = 0; j < 6; ++j ) { + pmax[j] = max( pmax[j], vT[i].t[j] ); + pmin[j] = min( pmin[j], vT[i].t[j] ); + } + } - fprintf( flog, - "\nAngle span: min, max, delta = %f %f %f\n", - ang_min, ang_max, ang_max - ang_min ); + fprintf( flog, + "\nAngle span: min, max, delta = %f %f %f\n", + ang_min, ang_max, ang_max - ang_min ); // Calculate spans - for( int j = 0; j < 6; ++j ) { + for( int j = 0; j < 6; ++j ) { - pspan[j] = pmax[j] - pmin[j]; + pspan[j] = pmax[j] - pmin[j]; - if( j == 2 || j == 5 ) // translation - extreme |= pspan[j] > GBL.mch.LDC; - else // rotation - extreme |= pspan[j] > GBL.mch.LDR; - } + if( j == 2 || j == 5 ) // translation + extreme |= pspan[j] > GBL.mch.LDC; + else // rotation + extreme |= pspan[j] > GBL.mch.LDR; + } // Any extreme spans? - if( ang_max - ang_min > GBL.mch.LDA || extreme ) { + if( ang_max - ang_min > GBL.mch.LDA || extreme ) { - fprintf( flog, - "FAIL: Triangles too different:" - " angles %f %f %f; LDA %f\n", - ang_min, ang_max, ang_max-ang_min, GBL.mch.LDA ); + fprintf( flog, + "FAIL: Triangles too different:" + " angles %f %f %f; LDA %f\n", + ang_min, ang_max, ang_max-ang_min, GBL.mch.LDA ); - fprintf( flog, - "FAIL: Triangles too different:" - " elements %f %f %f %f %f %f; LDR %f LDC %f\n", - pspan[0], pspan[1], pspan[2], - pspan[3], pspan[4], pspan[5], - GBL.mch.LDR, GBL.mch.LDC ); + fprintf( flog, + "FAIL: Triangles too different:" + " elements %f %f %f %f %f %f; LDR %f LDC %f\n", + pspan[0], pspan[1], pspan[2], + pspan[3], pspan[4], pspan[5], + GBL.mch.LDR, GBL.mch.LDC ); - nT = 0; - } + nT = 0; + } - return nT; + return nT; } /* --------------------------------------------------------------- */ @@ -156,61 +156,61 @@ static int SelfConsistent( const vector &vT, FILE* flog ) /* --------------------------------------------------------------- */ static int ThmbConsistent( - const vector &vT, - const TAffine &T0, - FILE* flog ) + const vector &vT, + const TAffine &T0, + FILE* flog ) { // Average the final trans - TAffine A = vT[0]; - int nT = vT.size(); + TAffine A = vT[0]; + int nT = vT.size(); - if( nT > 1 ) { + if( nT > 1 ) { - for( int i = 1; i < nT; ++i ) { + for( int i = 1; i < nT; ++i ) { - for( int j = 0; j < 6; ++j ) - A.t[j] += vT[i].t[j]; - } + for( int j = 0; j < 6; ++j ) + A.t[j] += vT[i].t[j]; + } - for( int j = 0; j < 6; ++j ) - A.t[j] /= nT; - } + for( int j = 0; j < 6; ++j ) + A.t[j] /= nT; + } // Differences - const int f = 2; - double LDR = f * GBL.mch.LDR, - LDC = f * GBL.mch.LDC; - double D[6]; + const int f = 2; + double LDR = f * GBL.mch.LDR, + LDC = f * GBL.mch.LDC; + double D[6]; - for( int i = 0; i < 6; ++i ) - D[i] = fabs( A.t[i] - T0.t[i] ); + for( int i = 0; i < 6; ++i ) + D[i] = fabs( A.t[i] - T0.t[i] ); - fprintf( flog, - "Mesh-Thm:%7.4f %7.4f %8.2f %7.4f %7.4f %8.2f" - " %dx(LDR,LDC)=(%.2f,%.2f) -- ", - D[0], D[1], D[2], D[3], D[4], D[5], - f, LDR, LDC ); + fprintf( flog, + "Mesh-Thm:%7.4f %7.4f %8.2f %7.4f %7.4f %8.2f" + " %dx(LDR,LDC)=(%.2f,%.2f) -- ", + D[0], D[1], D[2], D[3], D[4], D[5], + f, LDR, LDC ); // Check - for( int i = 0; i < 6; ++i ) { + for( int i = 0; i < 6; ++i ) { - if( i == 2 || i == 5 ) { - if( D[i] > LDC ) - goto reject; - } - else if( D[i] > LDR ) - goto reject; - } + if( i == 2 || i == 5 ) { + if( D[i] > LDC ) + goto reject; + } + else if( D[i] > LDR ) + goto reject; + } - fprintf( flog, "OK.\n" ); - return true; + fprintf( flog, "OK.\n" ); + return true; reject: - fprintf( flog, "Reject.\n" ); - return false; + fprintf( flog, "Reject.\n" ); + return false; } /* --------------------------------------------------------------- */ @@ -221,46 +221,46 @@ static int UserConsistent( const vector &vT, FILE* flog ) { // Translations in bounds? - int nT = vT.size(), nXY = GBL.XYexp.size(); + int nT = vT.size(), nXY = GBL.XYexp.size(); - if( nT && nXY ) { + if( nT && nXY ) { - bool allok = true; + bool allok = true; - for( int i = 0; i < nT; ++i ) { + for( int i = 0; i < nT; ++i ) { - bool iok = false; + bool iok = false; - // iok true if ANY bound satisfied + // iok true if ANY bound satisfied - for( int j = 0; j < nXY; ++j ) { + for( int j = 0; j < nXY; ++j ) { - Point p( vT[i].t[2], vT[i].t[5] ); + Point p( vT[i].t[2], vT[i].t[5] ); - iok |= p.Dist( GBL.XYexp[j] ) <= GBL.mch.DXY; - } + iok |= p.Dist( GBL.XYexp[j] ) <= GBL.mch.DXY; + } - if( !iok ) { + if( !iok ) { - fprintf( flog, - "Transform translation (%f %f)" - " not on allowed list, tolerance %f\n", - vT[i].t[2], vT[i].t[5], GBL.mch.DXY ); - } + fprintf( flog, + "Transform translation (%f %f)" + " not on allowed list, tolerance %f\n", + vT[i].t[2], vT[i].t[5], GBL.mch.DXY ); + } - allok &= iok; - } + allok &= iok; + } - if( !allok ) { + if( !allok ) { - fprintf( flog, - "FAIL: Transform not on allowed list.\n" ); + fprintf( flog, + "FAIL: Transform not on allowed list.\n" ); - nT = 0; - } - } + nT = 0; + } + } - return nT; + return nT; } /* --------------------------------------------------------------- */ @@ -268,33 +268,33 @@ static int UserConsistent( const vector &vT, FILE* flog ) /* --------------------------------------------------------------- */ static void ReportCenters( - const vector &vT, - const vector ¢ers, - int napts, - int a_id, - int b_id, - FILE *flog ) + const vector &vT, + const vector ¢ers, + int napts, + int a_id, + int b_id, + FILE *flog ) { - int nc = centers.size(); + int nc = centers.size(); - fprintf( flog, "\nFinal remapping of %d points.\n", napts ); + fprintf( flog, "\nFinal remapping of %d points.\n", napts ); - for( int i = 0; i < nc; ++i ) { + for( int i = 0; i < nc; ++i ) { - const Point& ca = centers[i]; - Point cb = ca; + const Point& ca = centers[i]; + Point cb = ca; - vT[i].Transform( cb ); + vT[i].Transform( cb ); - fprintf( flog, "Center %f %f: ", ca.x, ca.y ); - vT[i].TPrint( flog ); + fprintf( flog, "Center %f %f: ", ca.x, ca.y ); + vT[i].TPrint( flog ); - fprintf( flog, - "Mapping region %d xy= %f %f to region %d xy= %f %f\n", - a_id, ca.x, ca.y, b_id, cb.x, cb.y ); - } + fprintf( flog, + "Mapping region %d xy= %f %f to region %d xy= %f %f\n", + a_id, ca.x, ca.y, b_id, cb.x, cb.y ); + } - fprintf( flog, "\n" ); + fprintf( flog, "\n" ); } /* --------------------------------------------------------------- */ @@ -302,38 +302,38 @@ static void ReportCenters( /* --------------------------------------------------------------- */ static void WriteTrackEMTriangles( - vector &vT, - const vector &tri, - const vector &ctl, - FILE *ftri ) + vector &vT, + const vector &tri, + const vector &ctl, + FILE *ftri ) { - if( !ftri ) - return; + if( !ftri ) + return; - int ntri = tri.size(); + int ntri = tri.size(); - for( int j = 0; j < ntri; ++j ) { + for( int j = 0; j < ntri; ++j ) { - Point p[3]; + Point p[3]; - for( int k = 0; k < 3; ++k ) { + for( int k = 0; k < 3; ++k ) { - const vertex& v = ctl[tri[j].v[k]]; + const vertex& v = ctl[tri[j].v[k]]; - p[k] = Point( v.x, v.y ); - } + p[k] = Point( v.x, v.y ); + } - fprintf( ftri, - "%f %f %f %f %f %f ", - p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y ); + fprintf( ftri, + "%f %f %f %f %f %f ", + p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y ); - for( int k = 0; k < 3; ++k ) - vT[j].Transform( p[k] ); + for( int k = 0; k < 3; ++k ) + vT[j].Transform( p[k] ); - fprintf( ftri, - "%f %f %f %f %f %f\n", - p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y ); - } + fprintf( ftri, + "%f %f %f %f %f %f\n", + p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y ); + } } /* --------------------------------------------------------------- */ @@ -351,24 +351,24 @@ static void WriteTrackEMTriangles( // All work and reporting is in scaled (downsampled) coords. // void RegionToRegionMap( - ffmap &maps, - uint16 *ids, - const PixPair &px, - const ConnRegion &acr, - const ConnRegion &bcr, - TAffine tr_guess, - FILE *flog, - FILE *ftri ) + ffmap &maps, + uint16 *ids, + const PixPair &px, + const ConnRegion &acr, + const ConnRegion &bcr, + TAffine tr_guess, + FILE *flog, + FILE *ftri ) { - TAffine T0 = tr_guess; - int w = px.ws, - h = px.hs, - sc = px.scl, - npix = w * h, - fullw = px.wf, - napts = acr.pts.size(); + TAffine T0 = tr_guess; + int w = px.ws, + h = px.hs, + sc = px.scl, + npix = w * h, + fullw = px.wf, + napts = acr.pts.size(); - fprintf( flog, "\n---- Starting detailed region mapping ----\n" ); + fprintf( flog, "\n---- Starting detailed region mapping ----\n" ); /* ---------------- */ /* Condition images */ @@ -385,83 +385,83 @@ void RegionToRegionMap( // We also create a bitmap IsIn[] with ones only inside the // B connected region. - const vector& av_vfy = *px.avs_vfy; - const vector& bv_vfy = *px.bvs_vfy; - const vector& av_aln = *px.avs_aln; - vector IsIn( npix, 0 ); + const vector& av_vfy = *px.avs_vfy; + const vector& bv_vfy = *px.bvs_vfy; + const vector& av_aln = *px.avs_aln; + vector IsIn( npix, 0 ); // Fill IsIn - { - int nbpts = bcr.pts.size(); + { + int nbpts = bcr.pts.size(); - for( int i = 0; i < nbpts; ++i ) - IsIn[int(bcr.pts[i].x) + w * int(bcr.pts[i].y)] = 1; - } + for( int i = 0; i < nbpts; ++i ) + IsIn[int(bcr.pts[i].x) + w * int(bcr.pts[i].y)] = 1; + } // {av_msh, ap_msh} are subset of A mapping to IsIn - vector ap_msh; - vector av_msh; + vector ap_msh; + vector av_msh; - for( int i = 0; i < napts; ++i ) { + for( int i = 0; i < napts; ++i ) { - const Point& ap = acr.pts[i]; - Point bp = ap; + const Point& ap = acr.pts[i]; + Point bp = ap; - tr_guess.Transform( bp ); + tr_guess.Transform( bp ); - int ix = int(bp.x); - int iy = int(bp.y); + int ix = int(bp.x); + int iy = int(bp.y); - if( ix >= 0 && ix < w && - iy >= 0 && iy < h && - IsIn[ix+w*iy] ) { + if( ix >= 0 && ix < w && + iy >= 0 && iy < h && + IsIn[ix+w*iy] ) { - ap_msh.push_back( ap ); - av_msh.push_back( av_aln[int(ap.x) + w*int(ap.y)] ); - } - } + ap_msh.push_back( ap ); + av_msh.push_back( av_aln[int(ap.x) + w*int(ap.y)] ); + } + } // Region large enough? - fprintf( flog, "Roughly %ld pixels map to B.\n", - ap_msh.size() ); + fprintf( flog, "Roughly %ld pixels map to B.\n", + ap_msh.size() ); - if( ap_msh.size() < GBL.mch.MMA ) { + if( ap_msh.size() < GBL.mch.MMA ) { - fprintf( flog, - "FAIL: Region too small - %ld pixels, MMA %d\n", - ap_msh.size(), GBL.mch.MMA ); + fprintf( flog, + "FAIL: Region too small - %ld pixels, MMA %d\n", + ap_msh.size(), GBL.mch.MMA ); - return; - } + return; + } // Normalize pixel values for ImproveMesh. The av_msh remain // constant and can be normalized once now. ImproveMesh will // select and normalize subsets of the bv_msh in GradDescStep. - vector bv_msh = *px.bvs_aln; + vector bv_msh = *px.bvs_aln; - Normalize( av_msh ); + Normalize( av_msh ); /* ------------------------ */ /* Get common ap_msh bounds */ /* ------------------------ */ - IBox B; + IBox B; - MeshGetBounds( B, ap_msh, flog ); + MeshGetBounds( B, ap_msh, flog ); - if( B.R - B.L + 1 < 10 || - B.T - B.B + 1 < 10 ) { + if( B.R - B.L + 1 < 10 || + B.T - B.B + 1 < 10 ) { - fprintf( flog, - "FAIL: Region too slim - %d pixels, min %d\n", - min( B.R - B.L, B.T - B.B ) + 1, 10 ); + fprintf( flog, + "FAIL: Region too slim - %d pixels, min %d\n", + min( B.R - B.L, B.T - B.B ) + 1, 10 ); - return; - } + return; + } /* -------------------------------------------- */ /* First create a single-triangle "affine" mesh */ @@ -471,362 +471,362 @@ void RegionToRegionMap( // triangle on the region. If we can't get a good signal from // that then a mesh of smaller triangles is unlikely to work. - fprintf( flog, "\n---- Building mesh - affine ----\n" ); + fprintf( flog, "\n---- Building mesh - affine ----\n" ); - vector tri; - vector ctl; - int ntri = 1; + vector tri; + vector ctl; + int ntri = 1; - MeshMakeSingleTri( tri, ctl, B, flog ); + MeshMakeSingleTri( tri, ctl, B, flog ); /* --------------------------- */ /* Run the mesh improver on it */ /* --------------------------- */ - vector transforms; - vector centers; - double corr; + vector transforms; + vector centers; + double corr; - corr = ImproveMesh( - transforms, centers, - tri, ctl, - ap_msh, av_msh, - bv_msh, w, h, - tr_guess, - GBL.ctx.RFA, - flog, "affine" ); + corr = ImproveMesh( + transforms, centers, + tri, ctl, + ap_msh, av_msh, + bv_msh, w, h, + tr_guess, + GBL.ctx.RFA, + flog, "affine" ); - if( !transforms.size() ) - return; - else { + if( !transforms.size() ) + return; + else { - TAffine inv; - inv.InverseOf( transforms[0] ); + TAffine inv; + inv.InverseOf( transforms[0] ); - transforms[0].TPrint( - flog, "Best affine transform: " ); + transforms[0].TPrint( + flog, "Best affine transform: " ); - inv.TPrint( - flog, " Inverse transform: " ); + inv.TPrint( + flog, " Inverse transform: " ); - tr_guess = transforms[0]; - } + tr_guess = transforms[0]; + } /* ------------------------ */ /* Check affine mesh result */ /* ------------------------ */ - fprintf( flog, "\n---- QC - affine ----\n" ); + fprintf( flog, "\n---- QC - affine ----\n" ); - { + { - // collect mapped points + // collect mapped points - CMatch mat; + CMatch mat; - for( int k = 0; k < napts; ++k ) { + for( int k = 0; k < napts; ++k ) { - const Point& ap = acr.pts[k]; - Point bp = ap; + const Point& ap = acr.pts[k]; + Point bp = ap; - tr_guess.Transform( bp ); + tr_guess.Transform( bp ); - if( bp.x >= 0 && bp.x < w-1 && - bp.y >= 0 && bp.y < h-1 && - IsIn[int(bp.x) + w*int(bp.y)] ) { + if( bp.x >= 0 && bp.x < w-1 && + bp.y >= 0 && bp.y < h-1 && + IsIn[int(bp.x) + w*int(bp.y)] ) { - double va = av_vfy[int(ap.x) + w*int(ap.y)]; - double vb = InterpolatePixel( bp.x, bp.y, bv_vfy, w ); + double va = av_vfy[int(ap.x) + w*int(ap.y)]; + double vb = InterpolatePixel( bp.x, bp.y, bv_vfy, w ); - mat.pts.push_back( ap ); - mat.a.push_back( va ); - mat.b.push_back( vb ); - } - } + mat.pts.push_back( ap ); + mat.a.push_back( va ); + mat.b.push_back( vb ); + } + } - Normalize( mat.a ); - Normalize( mat.b ); + Normalize( mat.a ); + Normalize( mat.b ); - // get cross-corr, Fourier metric, yellow + // get cross-corr, Fourier metric, yellow - double fm, y; - double sum = 0.0; - int N = mat.a.size(); + double fm, y; + double sum = 0.0; + int N = mat.a.size(); - for( int i = 0; i < N; ++i ) - sum += mat.a[i] * mat.b[i]; + for( int i = 0; i < N; ++i ) + sum += mat.a[i] * mat.b[i]; - fm = Metric( mat.pts, mat.a, mat.b, "AFF", flog ); + fm = Metric( mat.pts, mat.a, mat.b, "AFF", flog ); - y = PercentYellow( mat.a, mat.b, flog ); + y = PercentYellow( mat.a, mat.b, flog ); - fprintf( flog, - "Affine Triangle: %d points, corr %f, fm %f, yellow %.2f\n", - N, sum/N, fm, y ); + fprintf( flog, + "Affine Triangle: %d points, corr %f, fm %f, yellow %.2f\n", + N, sum/N, fm, y ); - // Assess result quality + // Assess result quality - if( GBL.mch.EMM ) { + if( GBL.mch.EMM ) { - if( fm > 2.0*GBL.mch.EMT ) { + if( fm > 2.0*GBL.mch.EMT ) { - fprintf( flog, - "FAIL: Kicking out - Initial EMM too big (%f)," - " 2*EMT %f\n", fm, 2.0*GBL.mch.EMT ); + fprintf( flog, + "FAIL: Kicking out - Initial EMM too big (%f)," + " 2*EMT %f\n", fm, 2.0*GBL.mch.EMT ); - return; - } - } - else { // use older Fourier Metric + return; + } + } + else { // use older Fourier Metric - if( fm < GBL.mch.IFM ) { + if( fm < GBL.mch.IFM ) { - fprintf( flog, - "FAIL: Kicking out - Initial FM too low (%f)," - " IFM %f\n", fm, GBL.mch.IFM ); + fprintf( flog, + "FAIL: Kicking out - Initial FM too low (%f)," + " IFM %f\n", fm, GBL.mch.IFM ); - for( int wvlen = 5; wvlen <= 40; wvlen += 5 ) { + for( int wvlen = 5; wvlen <= 40; wvlen += 5 ) { - double ffm; + double ffm; - ffm = FourierMatch( - mat.pts, mat.a, mat.b, wvlen, - wvlen==5 || GBL.mch.WDI, - "AF2", flog ); + ffm = FourierMatch( + mat.pts, mat.a, mat.b, wvlen, + wvlen==5 || GBL.mch.WDI, + "AF2", flog ); - fprintf( flog, - " wavelength %d, metric %f\n", wvlen, ffm ); - } + fprintf( flog, + " wavelength %d, metric %f\n", wvlen, ffm ); + } - return; - } - } - } + return; + } + } + } - if( GBL.mch.ONE ) { - fprintf( flog, - "Cmd-line directive to use one affine only.\n" ); - goto quality_control; - } + if( GBL.mch.ONE ) { + fprintf( flog, + "Cmd-line directive to use one affine only.\n" ); + goto quality_control; + } /* ----------------------------- */ /* OK, now try a deformable mesh */ /* ----------------------------- */ - fprintf( flog, "\n---- Building mesh - deformable ----\n" ); + fprintf( flog, "\n---- Building mesh - deformable ----\n" ); - if( MeshCreateX( tri, ctl, ap_msh, B, flog ) ) { + if( MeshCreateX( tri, ctl, ap_msh, B, flog ) ) { - fprintf( flog, - "FAIL: Deformable triangular mesh failed - Small overlap?" - " %ld pixels, MMA %d\n", - ap_msh.size(), GBL.mch.MMA ); + fprintf( flog, + "FAIL: Deformable triangular mesh failed - Small overlap?" + " %ld pixels, MMA %d\n", + ap_msh.size(), GBL.mch.MMA ); - return; - } + return; + } - ntri = tri.size(); + ntri = tri.size(); - if( !ntri ) { + if( !ntri ) { - fprintf( flog, - "FAIL: Deformable triangular mesh failed - No triangles." - " %ld pixels, MMA %d\n", - ap_msh.size(), GBL.mch.MMA ); + fprintf( flog, + "FAIL: Deformable triangular mesh failed - No triangles." + " %ld pixels, MMA %d\n", + ap_msh.size(), GBL.mch.MMA ); - return; - } + return; + } /* ----------------------- */ /* Improve deformable mesh */ /* ----------------------- */ - corr = ImproveMesh( - transforms, centers, - tri, ctl, - ap_msh, av_msh, - bv_msh, w, h, - tr_guess, - GBL.ctx.RFT, - flog, "deformable mesh" ); + corr = ImproveMesh( + transforms, centers, + tri, ctl, + ap_msh, av_msh, + bv_msh, w, h, + tr_guess, + GBL.ctx.RFT, + flog, "deformable mesh" ); - if( !transforms.size() ) - return; + if( !transforms.size() ) + return; /* --------------------------------- */ /* Generate quality control measures */ /* --------------------------------- */ quality_control: - fprintf( flog, "\n---- QC - deformable ----\n" ); + fprintf( flog, "\n---- QC - deformable ----\n" ); - vector matches( ntri ); // each triangle - CMatch allp; // over all triangles + vector matches( ntri ); // each triangle + CMatch allp; // over all triangles - fprintf( flog, "Remapping %d points.\n", napts ); + fprintf( flog, "Remapping %d points.\n", napts ); - for( int k = 0; k < napts; ++k ) { + for( int k = 0; k < napts; ++k ) { - const Point& ap = acr.pts[k]; - Point bp = ap; - int t = BestTriangle( tri, ctl, ap ); + const Point& ap = acr.pts[k]; + Point bp = ap; + int t = BestTriangle( tri, ctl, ap ); - transforms[t].Transform( bp ); + transforms[t].Transform( bp ); - if( bp.x >= 0 && bp.x < w-1 && - bp.y >= 0 && bp.y < h-1 && - IsIn[int(bp.x) + w*int(bp.y)] ) { + if( bp.x >= 0 && bp.x < w-1 && + bp.y >= 0 && bp.y < h-1 && + IsIn[int(bp.x) + w*int(bp.y)] ) { - double va = av_vfy[int(ap.x) + w*int(ap.y)]; - double vb = InterpolatePixel( bp.x, bp.y, bv_vfy, w ); + double va = av_vfy[int(ap.x) + w*int(ap.y)]; + double vb = InterpolatePixel( bp.x, bp.y, bv_vfy, w ); - matches[t].pts.push_back( ap ); - matches[t].a.push_back( va ); - matches[t].b.push_back( vb ); + matches[t].pts.push_back( ap ); + matches[t].a.push_back( va ); + matches[t].b.push_back( vb ); - allp.pts.push_back( ap ); - allp.a.push_back( va ); - allp.b.push_back( vb ); - } - } + allp.pts.push_back( ap ); + allp.a.push_back( va ); + allp.b.push_back( vb ); + } + } - Normalize( allp.a ); - Normalize( allp.b ); + Normalize( allp.a ); + Normalize( allp.b ); // Get Fourier metric over all triangles - double dfm; + double dfm; - dfm = Metric( allp.pts, allp.a, allp.b, "DEF", flog ); + dfm = Metric( allp.pts, allp.a, allp.b, "DEF", flog ); - fprintf( flog, "All points, deformable, dfm %f\n\n", dfm ); + fprintf( flog, "All points, deformable, dfm %f\n\n", dfm ); // Sum over triangles: cross-corr, Fourier metric, yellow... - double weighted_sum = 0.0; - double weighted_yellow = 0.0; - int sum_pts = 0; + double weighted_sum = 0.0; + double weighted_yellow = 0.0; + int sum_pts = 0; - for( int k = 0; k < ntri; ++k ) { + for( int k = 0; k < ntri; ++k ) { - double fm, y; - double sum = 0.0; - int N = matches[k].a.size(); + double fm, y; + double sum = 0.0; + int N = matches[k].a.size(); - if( N ) { + if( N ) { - if( !Normalize( matches[k].a ) || - !Normalize( matches[k].b ) ) { + if( !Normalize( matches[k].a ) || + !Normalize( matches[k].b ) ) { - fprintf( flog, - "Triangle %d: Likely empty; skip metrics.\n\n", k ); - continue; - } + fprintf( flog, + "Triangle %d: Likely empty; skip metrics.\n\n", k ); + continue; + } - for( int i = 0; i < N; ++i ) - sum += matches[k].a[i] * matches[k].b[i]; + for( int i = 0; i < N; ++i ) + sum += matches[k].a[i] * matches[k].b[i]; - fm = Metric( matches[k].pts, - matches[k].a, matches[k].b, "TRI", flog ); + fm = Metric( matches[k].pts, + matches[k].a, matches[k].b, "TRI", flog ); - y = PercentYellow( matches[k].a, matches[k].b, flog ); + y = PercentYellow( matches[k].a, matches[k].b, flog ); - fprintf( flog, - "Triangle %d: %d points, corr %f, fm %f, yellow %.2f\n\n", - k, N, sum/N, fm, y ); + fprintf( flog, + "Triangle %d: %d points, corr %f, fm %f, yellow %.2f\n\n", + k, N, sum/N, fm, y ); - weighted_sum += fm * N; - weighted_yellow += y * N; - sum_pts += N; - } - } + weighted_sum += fm * N; + weighted_yellow += y * N; + sum_pts += N; + } + } // ...and get weighted average scores - double score = weighted_sum / sum_pts; - double yell = weighted_yellow / sum_pts; + double score = weighted_sum / sum_pts; + double yell = weighted_yellow / sum_pts; /* --------------------- */ /* Assess result quality */ /* --------------------- */ - fprintf( flog, "\n---- Final reports ----\n" ); + fprintf( flog, "\n---- Final reports ----\n" ); - char buf[128]; - string reason; + char buf[128]; + string reason; - if( yell < GBL.mch.FYL ) { - sprintf( buf, " [Yellow=%g < FYL=%g]", yell, GBL.mch.FYL ); - reason += buf; - } + if( yell < GBL.mch.FYL ) { + sprintf( buf, " [Yellow=%g < FYL=%g]", yell, GBL.mch.FYL ); + reason += buf; + } - if( GBL.mch.EMM ) { + if( GBL.mch.EMM ) { - fprintf( flog, - "STAT: Overall %d points, corr %.4f," - " EMM %.4f, weighted EMM %.4f," - " cor+dfm %.4f, weighted yellow %6.4f\n", - sum_pts, corr, dfm, score, corr+dfm, yell ); + fprintf( flog, + "STAT: Overall %d points, corr %.4f," + " EMM %.4f, weighted EMM %.4f," + " cor+dfm %.4f, weighted yellow %6.4f\n", + sum_pts, corr, dfm, score, corr+dfm, yell ); - if( score > GBL.mch.EMT ) { - sprintf( buf, - " [Weighted EMM=%g > EMT=%g]", score, GBL.mch.EMT ); - reason += buf; - } + if( score > GBL.mch.EMT ) { + sprintf( buf, + " [Weighted EMM=%g > EMT=%g]", score, GBL.mch.EMT ); + reason += buf; + } - if( dfm > GBL.mch.EMT*1.10 ) { - sprintf( buf, - " [EMM=%g > %g = (EMT=%g * 1.10)]", - dfm, GBL.mch.EMT*1.10, GBL.mch.EMT ); - reason += buf; - } + if( dfm > GBL.mch.EMT*1.10 ) { + sprintf( buf, + " [EMM=%g > %g = (EMT=%g * 1.10)]", + dfm, GBL.mch.EMT*1.10, GBL.mch.EMT ); + reason += buf; + } - //if( score > dfm*1.1 && score > GBL.mch.EMT/2.0 ) { - // reason += " [not great EMM, and Weighted EMM" - // " is higher by more than 10%]"; - //} - } - else { // use older Fourier metric + //if( score > dfm*1.1 && score > GBL.mch.EMT/2.0 ) { + // reason += " [not great EMM, and Weighted EMM" + // " is higher by more than 10%]"; + //} + } + else { // use older Fourier metric - fprintf( flog, - "STAT: Overall %d points, corr %.4f," - " dfm %.4f, weighted Fourier %.4f," - " cor+dfm %.4f, weighted yellow %6.4f\n", - sum_pts, corr, dfm, score, corr+dfm, yell ); + fprintf( flog, + "STAT: Overall %d points, corr %.4f," + " dfm %.4f, weighted Fourier %.4f," + " cor+dfm %.4f, weighted yellow %6.4f\n", + sum_pts, corr, dfm, score, corr+dfm, yell ); - if( dfm < GBL.mch.FFM ) - reason += " [Final Fourier too low]"; + if( dfm < GBL.mch.FFM ) + reason += " [Final Fourier too low]"; - if( sum_pts < 400000 && score < GBL.mch.FFM ) - reason += " [Small region and weighted metric < dfm]"; + if( sum_pts < 400000 && score < GBL.mch.FFM ) + reason += " [Small region and weighted metric < dfm]"; - if( score < 0.75*dfm ) - reason += " [Weighted less than 0.75 of dfm]"; + if( score < 0.75*dfm ) + reason += " [Weighted less than 0.75 of dfm]"; - if( corr+dfm < GBL.mch.CPD ) - reason += " [Sum of corr+dfm too low]"; - } + if( corr+dfm < GBL.mch.CPD ) + reason += " [Sum of corr+dfm too low]"; + } // Failed if any reason cited - if( reason.length() ) { + if( reason.length() ) { - fprintf( flog, - "FAIL: Overall rejected:%s.\n", reason.c_str() ); + fprintf( flog, + "FAIL: Overall rejected:%s.\n", reason.c_str() ); - return; - } + return; + } /* ------------------ */ /* Consistency checks */ /* ------------------ */ - if( !SelfConsistent( transforms, flog ) || - !ThmbConsistent( transforms, T0, flog ) || - !UserConsistent( transforms, flog ) ) { + if( !SelfConsistent( transforms, flog ) || + !ThmbConsistent( transforms, T0, flog ) || + !UserConsistent( transforms, flog ) ) { - return; - } + return; + } /* ---------------------- */ /* Success...make reports */ @@ -834,11 +834,11 @@ void RegionToRegionMap( // Report centers in log - ReportCenters( transforms, centers, napts, acr.id, bcr.id, flog ); + ReportCenters( transforms, centers, napts, acr.id, bcr.id, flog ); // Print triangles {A} and Tr{A}, for trakEM - WriteTrackEMTriangles( transforms, tri, ctl, ftri ); + WriteTrackEMTriangles( transforms, tri, ctl, ftri ); /* ------------------------------------ */ /* Collect results into data structures */ @@ -846,38 +846,38 @@ void RegionToRegionMap( // Append maps entries - int next_id = maps.transforms.size() + 10; + int next_id = maps.transforms.size() + 10; - for( int k = 0; k < ntri; ++k ) { + for( int k = 0; k < ntri; ++k ) { - maps.transforms.push_back( transforms[k] ); - maps.centers.push_back( centers[k] ); - } + maps.transforms.push_back( transforms[k] ); + maps.centers.push_back( centers[k] ); + } // Paint ids with points that map a -> b - for( int k = 0; k < napts; ++k ) { + for( int k = 0; k < napts; ++k ) { - const Point& ap = acr.pts[k]; - Point bp = ap; - int t = BestTriangle( tri, ctl, ap ); + const Point& ap = acr.pts[k]; + Point bp = ap; + int t = BestTriangle( tri, ctl, ap ); - transforms[t].Transform( bp ); + transforms[t].Transform( bp ); - if( bp.x >= 0 && bp.x < w && - bp.y >= 0 && bp.y < h && - IsIn[int(bp.x) + w*int(bp.y)] ) { + if( bp.x >= 0 && bp.x < w && + bp.y >= 0 && bp.y < h && + IsIn[int(bp.x) + w*int(bp.y)] ) { - int ix = int(ap.x); - int iy = int(ap.y); + int ix = int(ap.x); + int iy = int(ap.y); - for( int x = 0; x < sc; ++x ) { + for( int x = 0; x < sc; ++x ) { - for( int y = 0; y < sc; ++y ) - ids[sc*ix+x + fullw*(sc*iy+y)] = next_id + t; - } - } - } + for( int y = 0; y < sc; ++y ) + ids[sc*ix+x + fullw*(sc*iy+y)] = next_id + t; + } + } + } } diff --git a/1_DMesh/RegionToRegionMap.h b/1_DMesh/RegionToRegionMap.h index 62d1550..ed44a83 100644 --- a/1_DMesh/RegionToRegionMap.h +++ b/1_DMesh/RegionToRegionMap.h @@ -13,13 +13,13 @@ /* --------------------------------------------------------------- */ void RegionToRegionMap( - ffmap &maps, - uint16 *ids, - const PixPair &px, - const ConnRegion &acr, - const ConnRegion &bcr, - TAffine tr_guess, - FILE *flog, - FILE *ftri ); + ffmap &maps, + uint16 *ids, + const PixPair &px, + const ConnRegion &acr, + const ConnRegion &bcr, + TAffine tr_guess, + FILE *flog, + FILE *ftri ); diff --git a/1_DMesh/dmesh.cpp b/1_DMesh/dmesh.cpp index 27b388b..34dd134 100644 --- a/1_DMesh/dmesh.cpp +++ b/1_DMesh/dmesh.cpp @@ -28,65 +28,65 @@ class CStatus { public: - int argn, - brgn, - thmok, - ntri; + int argn, + brgn, + thmok, + ntri; public: - CStatus( int argn, int brgn ) - : argn(argn), brgn(brgn), thmok(0), ntri(0) {}; + CStatus( int argn, int brgn ) + : argn(argn), brgn(brgn), thmok(0), ntri(0) {}; }; class Match { public: - double weight; - Point pa, pb; - int ra, rb; // subregions + double weight; + Point pa, pb; + int ra, rb; // subregions public: - Match( - int ra, - int rb, - const Point& pa, - const Point& pb ) - : weight(1.0), pa(pa), pb(pb), ra(ra), rb(rb) {}; + Match( + int ra, + int rb, + const Point& pa, + const Point& pb ) + : weight(1.0), pa(pa), pb(pb), ra(ra), rb(rb) {}; }; class Matches { private: - vector vM; + vector vM; public: - void Tabulate( - const PixPair &px, - const vector &vstat, - const ffmap &maps, - const uint8* fold_mask_a, - const uint8* fold_mask_b, - int wf, - int hf, - FILE *flog ); - void WriteAs_CPOINT2(); - void WriteAs_JSON(); - static void WriteEmpty_JSON(); + void Tabulate( + const PixPair &px, + const vector &vstat, + const ffmap &maps, + const uint8* fold_mask_a, + const uint8* fold_mask_b, + int wf, + int hf, + FILE *flog ); + void WriteAs_CPOINT2(); + void WriteAs_JSON(); + static void WriteEmpty_JSON(); private: - static bool GetMutex( CMutex &M, const char *tag, const char **sud ); - static void JSON_head(); - static void JSON_tail(); - void JSON_ps(); - void JSON_qs(); - void JSON_ws(); - int index( int &i0, int &iLim, int ra, int rb ); - void FitAffine( - const PixPair &px, - int argn, - int brgn, - FILE *flog ); - void FitHmgphy( - const PixPair &px, - int argn, - int brgn, - FILE *flog ); + static bool GetMutex( CMutex &M, const char *tag, const char **sud ); + static void JSON_head(); + static void JSON_tail(); + void JSON_ps(); + void JSON_qs(); + void JSON_ws(); + int index( int &i0, int &iLim, int ra, int rb ); + void FitAffine( + const PixPair &px, + int argn, + int brgn, + FILE *flog ); + void FitHmgphy( + const PixPair &px, + int argn, + int brgn, + FILE *flog ); }; /* --------------------------------------------------------------- */ @@ -96,201 +96,201 @@ class Matches { // Catalogue good feature matches, grouped by (argn,brgn). // void Matches::Tabulate( - const PixPair &px, - const vector &vstat, - const ffmap &maps, - const uint8* fold_mask_a, - const uint8* fold_mask_b, - int wf, - int hf, - FILE *flog ) + const PixPair &px, + const vector &vstat, + const ffmap &maps, + const uint8* fold_mask_a, + const uint8* fold_mask_b, + int wf, + int hf, + FILE *flog ) { - fprintf( flog, - "\n---- Tabulating point matches ----\n" ); + fprintf( flog, + "\n---- Tabulating point matches ----\n" ); - int nstat = vstat.size(), tr0 = 0; + int nstat = vstat.size(), tr0 = 0; // For each region pair (vstat entry)... - for( int istat = 0; istat < nstat; tr0 += vstat[istat++].ntri ) { + for( int istat = 0; istat < nstat; tr0 += vstat[istat++].ntri ) { - int trlim = vstat[istat].ntri; + int trlim = vstat[istat].ntri; - if( !trlim ) - continue; + if( !trlim ) + continue; - trlim += tr0; + trlim += tr0; - // Good points for this region pair + // Good points for this region pair - vector vGood; + vector vGood; - // For each A-triangle... + // For each A-triangle... - for( int itr = tr0; itr < trlim; ++itr ) { + for( int itr = tr0; itr < trlim; ++itr ) { - Point pa = maps.centers[itr], - pb = pa; - int ra, rb, ix, iy; + Point pa = maps.centers[itr], + pb = pa; + int ra, rb, ix, iy; - // Lookup for A-point + // Lookup for A-point - ix = int(pa.x); - iy = int(pa.y); + ix = int(pa.x); + iy = int(pa.y); - if( ix >= 0 && ix < wf && iy >= 0 && iy < hf ) { + if( ix >= 0 && ix < wf && iy >= 0 && iy < hf ) { - ra = fold_mask_a[ix + wf*iy]; + ra = fold_mask_a[ix + wf*iy]; - if( ra <= 0 ) { + if( ra <= 0 ) { - fprintf( flog, - "Tabulate: Rgn %d -> %d Tri %d:" - " A-centroid has bad mask value: mask=%d @ (%d, %d).\n", - vstat[istat].argn, vstat[istat].brgn, itr, - ra, ix, iy ); + fprintf( flog, + "Tabulate: Rgn %d -> %d Tri %d:" + " A-centroid has bad mask value: mask=%d @ (%d, %d).\n", + vstat[istat].argn, vstat[istat].brgn, itr, + ra, ix, iy ); - continue; - } + continue; + } - if( ra != vstat[istat].argn ) { + if( ra != vstat[istat].argn ) { - fprintf( flog, - "Tabulate: Rgn %d -> %d Tri %d:" - " A-centroid not in stat block: mask=%d.\n", - vstat[istat].argn, vstat[istat].brgn, itr, - ra ); + fprintf( flog, + "Tabulate: Rgn %d -> %d Tri %d:" + " A-centroid not in stat block: mask=%d.\n", + vstat[istat].argn, vstat[istat].brgn, itr, + ra ); - continue; - } - } - else { + continue; + } + } + else { - fprintf( flog, - "Tabulate: Rgn %d -> %d Tri %d:" - " A-centroid out of A-image bounds: (%d, %d).\n", - vstat[istat].argn, vstat[istat].brgn, itr, - ix, iy ); + fprintf( flog, + "Tabulate: Rgn %d -> %d Tri %d:" + " A-centroid out of A-image bounds: (%d, %d).\n", + vstat[istat].argn, vstat[istat].brgn, itr, + ix, iy ); - continue; - } + continue; + } - // Lookup for B-point + // Lookup for B-point - maps.transforms[itr].Transform( pb ); + maps.transforms[itr].Transform( pb ); - ix = int(pb.x); - iy = int(pb.y); + ix = int(pb.x); + iy = int(pb.y); - if( ix >= 0 && ix < wf && iy >= 0 && iy < hf ) { + if( ix >= 0 && ix < wf && iy >= 0 && iy < hf ) { - rb = fold_mask_b[ix + wf*iy]; + rb = fold_mask_b[ix + wf*iy]; - if( rb <= 0 ) { + if( rb <= 0 ) { - fprintf( flog, - "Tabulate: Rgn %d -> %d Tri %d:" - " B-centroid has bad mask value: mask=%d @ (%d, %d).\n", - vstat[istat].argn, vstat[istat].brgn, itr, - rb, ix, iy ); + fprintf( flog, + "Tabulate: Rgn %d -> %d Tri %d:" + " B-centroid has bad mask value: mask=%d @ (%d, %d).\n", + vstat[istat].argn, vstat[istat].brgn, itr, + rb, ix, iy ); - continue; - } + continue; + } - if( rb != vstat[istat].brgn ) { + if( rb != vstat[istat].brgn ) { - fprintf( flog, - "Tabulate: Rgn %d -> %d Tri %d:" - " B-centroid not in stat block: mask=%d.\n", - vstat[istat].argn, vstat[istat].brgn, itr, - rb ); + fprintf( flog, + "Tabulate: Rgn %d -> %d Tri %d:" + " B-centroid not in stat block: mask=%d.\n", + vstat[istat].argn, vstat[istat].brgn, itr, + rb ); - continue; - } - } - else { + continue; + } + } + else { - fprintf( flog, - "Tabulate: Rgn %d -> %d Tri %d:" - " B-centroid out of B-image bounds: (%d, %d).\n", - vstat[istat].argn, vstat[istat].brgn, itr, - ix, iy ); + fprintf( flog, + "Tabulate: Rgn %d -> %d Tri %d:" + " B-centroid out of B-image bounds: (%d, %d).\n", + vstat[istat].argn, vstat[istat].brgn, itr, + ix, iy ); - continue; - } + continue; + } - // It's good; set it aside + // It's good; set it aside - vGood.push_back( Match( ra, rb, pa, pb ) ); - } + vGood.push_back( Match( ra, rb, pa, pb ) ); + } - // Keep good points only if sufficiently many... - // Although the mesh triangles have already passed sanity checks, - // a bad mapping at this stage should still raise doubts about - // whether the optimizer worked. We'll keep the good ones only - // if a clear majority of matches look good. + // Keep good points only if sufficiently many... + // Although the mesh triangles have already passed sanity checks, + // a bad mapping at this stage should still raise doubts about + // whether the optimizer worked. We'll keep the good ones only + // if a clear majority of matches look good. - int nG = vGood.size(); + int nG = vGood.size(); - if( nG >= 0.80 * vstat[istat].ntri ) - vM.insert( vM.end(), vGood.begin(), vGood.end() ); - else - nG = 0; + if( nG >= 0.80 * vstat[istat].ntri ) + vM.insert( vM.end(), vGood.begin(), vGood.end() ); + else + nG = 0; - fprintf( flog, - "Tabulate: Rgn %d -> %d:" - " Keeping %d of %d point-pairs.\n", - vstat[istat].argn, vstat[istat].brgn, - nG, vstat[istat].ntri ); + fprintf( flog, + "Tabulate: Rgn %d -> %d:" + " Keeping %d of %d point-pairs.\n", + vstat[istat].argn, vstat[istat].brgn, + nG, vstat[istat].ntri ); - if( !nG ) - continue; + if( !nG ) + continue; - // Model the transforms obtained from point pairs + // Model the transforms obtained from point pairs #if FITAFF - FitAffine( px, - vstat[istat].argn, - vstat[istat].brgn, flog ); + FitAffine( px, + vstat[istat].argn, + vstat[istat].brgn, flog ); #endif #if FITHMG - FitHmgphy( px, - vstat[istat].argn, - vstat[istat].brgn, flog ); + FitHmgphy( px, + vstat[istat].argn, + vstat[istat].brgn, flog ); #endif - } + } } void Matches::WriteAs_CPOINT2() { - int np = vM.size(); + int np = vM.size(); - if( !np ) - return; + if( !np ) + return; - const char *sud; - CMutex M; + const char *sud; + CMutex M; - if( GetMutex( M, "P", &sud ) ) { + if( GetMutex( M, "P", &sud ) ) { - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - const Match &m = vM[i]; + const Match &m = vM[i]; - printf( - "CPOINT2" - " %d.%d-%d %f %f" - " %d.%d-%d %f %f\n", - GBL.A.z, GBL.A.id, m.ra, m.pa.x, m.pa.y, - GBL.B.z, GBL.B.id, m.rb, m.pb.x, m.pb.y ); - } + printf( + "CPOINT2" + " %d.%d-%d %f %f" + " %d.%d-%d %f %f\n", + GBL.A.z, GBL.A.id, m.ra, m.pa.x, m.pa.y, + GBL.B.z, GBL.B.id, m.rb, m.pb.x, m.pb.y ); + } - fflush( stdout ); - } + fflush( stdout ); + } - M.Release(); + M.Release(); } @@ -308,127 +308,127 @@ void Matches::WriteAs_CPOINT2() // void Matches::WriteAs_JSON() { - CMutex M; + CMutex M; - if( GetMutex( M, "P", NULL ) ) { + if( GetMutex( M, "P", NULL ) ) { - JSON_head(); + JSON_head(); - if( vM.size() ) { - JSON_ps(); - JSON_qs(); - JSON_ws(); - } + if( vM.size() ) { + JSON_ps(); + JSON_qs(); + JSON_ws(); + } - JSON_tail(); - } + JSON_tail(); + } - M.Release(); + M.Release(); } void Matches::WriteEmpty_JSON() { - CMutex M; + CMutex M; - if( GetMutex( M, "P", NULL ) ) { + if( GetMutex( M, "P", NULL ) ) { - JSON_head(); - JSON_tail(); - } + JSON_head(); + JSON_tail(); + } - M.Release(); + M.Release(); } bool Matches::GetMutex( CMutex &M, const char *tag, const char **sud ) { - const char *_sud; - char name[256]; + const char *_sud; + char name[256]; - if( GBL.A.z < GBL.B.z ) - _sud = "up"; - else if( GBL.A.z == GBL.B.z ) - _sud = "same"; - else - _sud = "down"; + if( GBL.A.z < GBL.B.z ) + _sud = "up"; + else if( GBL.A.z == GBL.B.z ) + _sud = "same"; + else + _sud = "down"; - sprintf( name, "%s_%d_%s", _sud, GBL.A.z, tag ); + sprintf( name, "%s_%d_%s", _sud, GBL.A.z, tag ); - if( sud ) - *sud = _sud; + if( sud ) + *sud = _sud; - return M.Get( name ); + return M.Get( name ); } void Matches::JSON_head() { - printf( "{\n" ); - printf( " \"matches\": {\n" ); + printf( "{\n" ); + printf( " \"matches\": {\n" ); } void Matches::JSON_tail() { - printf( " }\n" ); - printf( "}\n" ); + printf( " }\n" ); + printf( "}\n" ); - fflush( stdout ); + fflush( stdout ); } void Matches::JSON_ps() { - int n = vM.size(); + int n = vM.size(); - printf( " \"p\": [[" ); + printf( " \"p\": [[" ); - printf( "%.4f", vM[0].pa.x ); - for( int i = 1; i < n; ++i ) - printf( ",%.4f", vM[i].pa.x ); + printf( "%.4f", vM[0].pa.x ); + for( int i = 1; i < n; ++i ) + printf( ",%.4f", vM[i].pa.x ); - printf( "],[" ); + printf( "],[" ); - printf( "%.4f", vM[0].pa.y ); - for( int i = 1; i < n; ++i ) - printf( ",%.4f", vM[i].pa.y ); + printf( "%.4f", vM[0].pa.y ); + for( int i = 1; i < n; ++i ) + printf( ",%.4f", vM[i].pa.y ); - printf( "]],\n" ); + printf( "]],\n" ); } void Matches::JSON_qs() { - int n = vM.size(); + int n = vM.size(); - printf( " \"q\": [[" ); + printf( " \"q\": [[" ); - printf( "%.4f", vM[0].pb.x ); - for( int i = 1; i < n; ++i ) - printf( ",%.4f", vM[i].pb.x ); + printf( "%.4f", vM[0].pb.x ); + for( int i = 1; i < n; ++i ) + printf( ",%.4f", vM[i].pb.x ); - printf( "],[" ); + printf( "],[" ); - printf( "%.4f", vM[0].pb.y ); - for( int i = 1; i < n; ++i ) - printf( ",%.4f", vM[i].pb.y ); + printf( "%.4f", vM[0].pb.y ); + for( int i = 1; i < n; ++i ) + printf( ",%.4f", vM[i].pb.y ); - printf( "]],\n" ); + printf( "]],\n" ); } void Matches::JSON_ws() { - int n = vM.size(); + int n = vM.size(); - printf( " \"w\": [" ); + printf( " \"w\": [" ); - printf( "%.4g", vM[0].weight ); - for( int i = 1; i < n; ++i ) - printf( ",%.4g", vM[i].weight ); + printf( "%.4g", vM[0].weight ); + for( int i = 1; i < n; ++i ) + printf( ",%.4g", vM[i].weight ); - printf( "]\n" ); + printf( "]\n" ); } @@ -436,255 +436,255 @@ void Matches::JSON_ws() // int Matches::index( int &i0, int &iLim, int ra, int rb ) { - i0 = -1; - iLim = -1; + i0 = -1; + iLim = -1; - int n = vM.size(); + int n = vM.size(); // seek start - for( int i = 0; i < n; ++i ) { + for( int i = 0; i < n; ++i ) { - const Match &m = vM[i]; + const Match &m = vM[i]; - if( m.ra == ra && m.rb == rb ) { - i0 = i; - iLim = i + 1; - goto seek_lim; - } - } + if( m.ra == ra && m.rb == rb ) { + i0 = i; + iLim = i + 1; + goto seek_lim; + } + } - return 0; + return 0; // seek lim seek_lim: - while( iLim < n ) { + while( iLim < n ) { - const Match &m = vM[iLim]; + const Match &m = vM[iLim]; - if( m.ra == ra && m.rb == rb ) - ++iLim; - else - break; - } + if( m.ra == ra && m.rb == rb ) + ++iLim; + else + break; + } exit: - return iLim - i0; + return iLim - i0; } void Matches::FitAffine( - const PixPair &px, - int argn, - int brgn, - FILE *flog ) + const PixPair &px, + int argn, + int brgn, + FILE *flog ) { - int i0, iLim, np = index( i0, iLim, argn, brgn ); + int i0, iLim, np = index( i0, iLim, argn, brgn ); - if( np < 3 ) { - fprintf( flog, - "Pipe: Too few points to fit affine [%d].\n", np ); - return; - } + if( np < 3 ) { + fprintf( flog, + "Pipe: Too few points to fit affine [%d].\n", np ); + return; + } // Create system of normal equations - double RHS[6]; - double LHS[6*6]; - int i1[3] = { 0, 1, 2 }, - i2[3] = { 3, 4, 5 }; + double RHS[6]; + double LHS[6*6]; + int i1[3] = { 0, 1, 2 }, + i2[3] = { 3, 4, 5 }; - Zero_Quick( LHS, RHS, 6 ); + Zero_Quick( LHS, RHS, 6 ); - for( int i = i0; i < iLim; ++i ) { + for( int i = i0; i < iLim; ++i ) { - const Point& A = vM[i].pa; - const Point& B = vM[i].pb; + const Point& A = vM[i].pa; + const Point& B = vM[i].pb; - double v[3] = { A.x, A.y, 1.0 }; + double v[3] = { A.x, A.y, 1.0 }; - AddConstraint_Quick( LHS, RHS, 6, 3, i1, v, B.x ); - AddConstraint_Quick( LHS, RHS, 6, 3, i2, v, B.y ); - } + AddConstraint_Quick( LHS, RHS, 6, 3, i1, v, B.x ); + AddConstraint_Quick( LHS, RHS, 6, 3, i2, v, B.y ); + } // Solve - fprintf( flog, - "Pipe: Aff solver returns: %d\n", Solve_Quick( LHS, RHS, 6 ) ); + fprintf( flog, + "Pipe: Aff solver returns: %d\n", Solve_Quick( LHS, RHS, 6 ) ); - TAffine T( &RHS[0] ); + TAffine T( &RHS[0] ); // Report - T.TPrint( flog, "Pipe: FitAffine: " ); + T.TPrint( flog, "Pipe: FitAffine: " ); #if FITTAB - { - const char *sud; - CMutex M; + { + const char *sud; + CMutex M; - if( GetMutex( M, "A", &sud ) ) { + if( GetMutex( M, "A", &sud ) ) { - char name[256]; - sprintf( name, "aff.%s", sud ); - FILE *f = fopen( name, "a" ); + char name[256]; + sprintf( name, "aff.%s", sud ); + FILE *f = fopen( name, "a" ); - if( f ) { + if( f ) { - // Write entry + // Write entry - fprintf( f, - "AFFINE" - " %d.%d-%d %d.%d-%d" - " %f %f %f %f %f %f\n", - GBL.A.z, GBL.A.id, argn, - GBL.B.z, GBL.B.id, brgn, - RHS[0], RHS[1], RHS[2], - RHS[3], RHS[4], RHS[5] ); + fprintf( f, + "AFFINE" + " %d.%d-%d %d.%d-%d" + " %f %f %f %f %f %f\n", + GBL.A.z, GBL.A.id, argn, + GBL.B.z, GBL.B.id, brgn, + RHS[0], RHS[1], RHS[2], + RHS[3], RHS[4], RHS[5] ); - fflush( f ); - fclose( f ); - } - } + fflush( f ); + fclose( f ); + } + } - M.Release(); - } + M.Release(); + } #endif // RMS error - double E = 0; + double E = 0; - for( int i = i0; i < iLim; ++i ) { + for( int i = i0; i < iLim; ++i ) { - Point a = vM[i].pa; + Point a = vM[i].pa; - T.Transform( a ); + T.Transform( a ); - double err = a.DistSqr( vM[i].pb ); + double err = a.DistSqr( vM[i].pb ); - E += err; - } + E += err; + } - E = sqrt( E / np ); + E = sqrt( E / np ); - fprintf( flog, "Pipe: FitAffineRMSerr: %g\n", E ); + fprintf( flog, "Pipe: FitAffineRMSerr: %g\n", E ); // Paint #if FITDRAW - YellowView( px, T, flog ); + YellowView( px, T, flog ); #endif } void Matches::FitHmgphy( - const PixPair &px, - int argn, - int brgn, - FILE *flog ) + const PixPair &px, + int argn, + int brgn, + FILE *flog ) { - int i0, iLim, np = index( i0, iLim, argn, brgn ); + int i0, iLim, np = index( i0, iLim, argn, brgn ); - if( np < 4 ) { - fprintf( flog, - "Pipe: Too few points to fit homography [%d].\n", np ); - return; - } + if( np < 4 ) { + fprintf( flog, + "Pipe: Too few points to fit homography [%d].\n", np ); + return; + } // Create system of normal equations - double RHS[8]; - double LHS[8*8]; - int i1[5] = { 0, 1, 2, 6, 7 }, - i2[5] = { 3, 4, 5, 6, 7 }; + double RHS[8]; + double LHS[8*8]; + int i1[5] = { 0, 1, 2, 6, 7 }, + i2[5] = { 3, 4, 5, 6, 7 }; - Zero_Quick( LHS, RHS, 8 ); + Zero_Quick( LHS, RHS, 8 ); - for( int i = i0; i < iLim; ++i ) { + for( int i = i0; i < iLim; ++i ) { - const Point& A = vM[i].pa; - const Point& B = vM[i].pb; + const Point& A = vM[i].pa; + const Point& B = vM[i].pb; - double v[5] = { A.x, A.y, 1.0, -A.x*B.x, -A.y*B.x }; + double v[5] = { A.x, A.y, 1.0, -A.x*B.x, -A.y*B.x }; - AddConstraint_Quick( LHS, RHS, 8, 5, i1, v, B.x ); + AddConstraint_Quick( LHS, RHS, 8, 5, i1, v, B.x ); - v[3] = -A.x*B.y; - v[4] = -A.y*B.y; + v[3] = -A.x*B.y; + v[4] = -A.y*B.y; - AddConstraint_Quick( LHS, RHS, 8, 5, i2, v, B.y ); - } + AddConstraint_Quick( LHS, RHS, 8, 5, i2, v, B.y ); + } // Solve - fprintf( flog, - "Pipe: Hmg solver returns: %d\n", Solve_Quick( LHS, RHS, 8 ) ); + fprintf( flog, + "Pipe: Hmg solver returns: %d\n", Solve_Quick( LHS, RHS, 8 ) ); - THmgphy T( &RHS[0] ); + THmgphy T( &RHS[0] ); // Report - T.TPrint( flog, "Pipe: FitHmgphy: " ); + T.TPrint( flog, "Pipe: FitHmgphy: " ); #if FITTAB - { - const char *sud; - CMutex M; + { + const char *sud; + CMutex M; - if( GetMutex( M, "H", &sud ) ) { + if( GetMutex( M, "H", &sud ) ) { - char name[256]; - sprintf( name, "hmg.%s", sud ); - FILE *f = fopen( name, "a" ); + char name[256]; + sprintf( name, "hmg.%s", sud ); + FILE *f = fopen( name, "a" ); - if( f ) { + if( f ) { - // Write entry + // Write entry - fprintf( f, - "HMGPHY" - " %d.%d-%d %d.%d-%d" - " %f %f %f %f %f %f %.12g %.12g\n", - GBL.A.z, GBL.A.id, argn, - GBL.B.z, GBL.B.id, brgn, - RHS[0], RHS[1], RHS[2], - RHS[3], RHS[4], RHS[5], - RHS[6], RHS[7] ); + fprintf( f, + "HMGPHY" + " %d.%d-%d %d.%d-%d" + " %f %f %f %f %f %f %.12g %.12g\n", + GBL.A.z, GBL.A.id, argn, + GBL.B.z, GBL.B.id, brgn, + RHS[0], RHS[1], RHS[2], + RHS[3], RHS[4], RHS[5], + RHS[6], RHS[7] ); - fflush( f ); - fclose( f ); - } - } + fflush( f ); + fclose( f ); + } + } - M.Release(); - } + M.Release(); + } #endif // RMS error - double E = 0; + double E = 0; - for( int i = i0; i < iLim; ++i ) { + for( int i = i0; i < iLim; ++i ) { - Point a = vM[i].pa; + Point a = vM[i].pa; - T.Transform( a ); + T.Transform( a ); - double err = a.DistSqr( vM[i].pb ); + double err = a.DistSqr( vM[i].pb ); - E += err; - } + E += err; + } - E = sqrt( E / np ); + E = sqrt( E / np ); - fprintf( flog, "Pipe: FitHmgphyRMSerr: %g\n", E ); + fprintf( flog, "Pipe: FitHmgphyRMSerr: %g\n", E ); // Paint #if FITDRAW - YellowView( px, T, flog ); + YellowView( px, T, flog ); #endif } @@ -693,53 +693,53 @@ void Matches::FitHmgphy( /* --------------------------------------------------------------- */ static bool RoughMatch( - vector &guesses, - const PixPair &px, - CCropMask &CM, - const ConnRegion &acr, - const ConnRegion &bcr, - FILE* flog ) + vector &guesses, + const PixPair &px, + CCropMask &CM, + const ConnRegion &acr, + const ConnRegion &bcr, + FILE* flog ) { - if( guesses.size() > 0 ) - return true; + if( guesses.size() > 0 ) + return true; - if( GBL.ctx.FLD == 'N' - && !GBL.mch.PXRESMSK - && !CM.IsFile( GBL.idb ) ) { + if( GBL.ctx.FLD == 'N' + && !GBL.mch.PXRESMSK + && !CM.IsFile( GBL.idb ) ) { - // Call NoCR at most once. Possible states - // are {0=never called, 1=failed, 2=success}. + // Call NoCR at most once. Possible states + // are {0=never called, 1=failed, 2=success}. - static vector T; - static int state = 0; + static vector T; + static int state = 0; - int calledthistime = false; + int calledthistime = false; - if( !state ) { - state = 1 + ApproximateMatch_NoCR( T, px, flog ); - calledthistime = true; - } + if( !state ) { + state = 1 + ApproximateMatch_NoCR( T, px, flog ); + calledthistime = true; + } - if( state == 2 ) { + if( state == 2 ) { - if( !calledthistime ) { - fprintf( flog, "\n---- Thumbnail matching ----\n" ); - T[0].TPrint( flog, "Reuse Approx: Best transform " ); - } + if( !calledthistime ) { + fprintf( flog, "\n---- Thumbnail matching ----\n" ); + T[0].TPrint( flog, "Reuse Approx: Best transform " ); + } - guesses.push_back( T[0] ); - return true; - } + guesses.push_back( T[0] ); + return true; + } - if( !calledthistime ) { - fprintf( flog, "\n---- Thumbnail matching ----\n" ); - fprintf( flog, "FAIL: Approx: Case already failed.\n" ); - } + if( !calledthistime ) { + fprintf( flog, "\n---- Thumbnail matching ----\n" ); + fprintf( flog, "FAIL: Approx: Case already failed.\n" ); + } - return false; - } - else - return ApproximateMatch( guesses, px, acr, bcr, flog ); + return false; + } + else + return ApproximateMatch( guesses, px, acr, bcr, flog ); } /* --------------------------------------------------------------- */ @@ -748,18 +748,18 @@ static bool RoughMatch( static void UpscaleCoords( ffmap &maps, int scale ) { - int nT; + int nT; - if( scale > 1 && (nT = maps.transforms.size()) ) { + if( scale > 1 && (nT = maps.transforms.size()) ) { - for( int i = 0; i < nT; ++i ) { + for( int i = 0; i < nT; ++i ) { - maps.transforms[i].MulXY( scale ); + maps.transforms[i].MulXY( scale ); - maps.centers[i].x *= scale; - maps.centers[i].y *= scale; - } - } + maps.centers[i].x *= scale; + maps.centers[i].y *= scale; + } + } } /* --------------------------------------------------------------- */ @@ -777,24 +777,24 @@ static void UpscaleCoords( ffmap &maps, int scale ) // flog - detailed output // void PipelineDeformableMap( - int &Ntrans, - double* &tr_array, - uint16* map_mask, - const PixPair &px, - const uint8* fold_mask_a, - const uint8* fold_mask_b, - FILE* flog ) + int &Ntrans, + double* &tr_array, + uint16* map_mask, + const PixPair &px, + const uint8* fold_mask_a, + const uint8* fold_mask_b, + FILE* flog ) { - int wf = px.wf, hf = px.hf; + int wf = px.wf, hf = px.hf; /* --------------- */ /* Default results */ /* --------------- */ - Ntrans = 0; - tr_array = NULL; + Ntrans = 0; + tr_array = NULL; - memset( map_mask, 0, wf * hf * sizeof(uint16) ); + memset( map_mask, 0, wf * hf * sizeof(uint16) ); /* --------------------------------- */ /* Create the connected region lists */ @@ -803,157 +803,157 @@ void PipelineDeformableMap( // Note that the connected region lists are always // at the reduced resolution, if this is used. - fprintf( flog, "\n---- Connected regions ----\n" ); + fprintf( flog, "\n---- Connected regions ----\n" ); - vector Acr, Bcr; - CCropMask CM; + vector Acr, Bcr; + CCropMask CM; - if( GBL.ctx.FLD == 'N' - && !GBL.mch.PXRESMSK - && !CM.IsFile( GBL.idb ) ) { + if( GBL.ctx.FLD == 'N' + && !GBL.mch.PXRESMSK + && !CM.IsFile( GBL.idb ) ) { - fprintf( flog, "Forcing single connected region.\n" ); + fprintf( flog, "Forcing single connected region.\n" ); - ConnRgnForce1( Acr, px.ws, px.hs ); - Bcr = Acr; - } - else { + ConnRgnForce1( Acr, px.ws, px.hs ); + Bcr = Acr; + } + else { - ConnRgnsFromFoldMask( Acr, fold_mask_a, - wf, hf, px.scl, uint32(0.9 * GBL.mch.MMA), flog ); + ConnRgnsFromFoldMask( Acr, fold_mask_a, + wf, hf, px.scl, uint32(0.9 * GBL.mch.MMA), flog ); - ConnRgnsFromFoldMask( Bcr, fold_mask_b, - wf, hf, px.scl, uint32(0.9 * GBL.mch.MMA), flog ); - } + ConnRgnsFromFoldMask( Bcr, fold_mask_b, + wf, hf, px.scl, uint32(0.9 * GBL.mch.MMA), flog ); + } /* ----------------------------------------- */ /* Find mappings for each region-region pair */ /* ----------------------------------------- */ - vector vstat; - ffmap maps; // transforms and centers - FILE *ftri = NULL; + vector vstat; + ffmap maps; // transforms and centers + FILE *ftri = NULL; - //ftri = fopen( "Triangles.txt", "w" ); + //ftri = fopen( "Triangles.txt", "w" ); - for( int i = 0; i < Acr.size(); ++i ) { + for( int i = 0; i < Acr.size(); ++i ) { - for( int j = 0; j < Bcr.size(); ++j ) { + for( int j = 0; j < Bcr.size(); ++j ) { - fprintf( flog, "\n---- Begin A-%d to B-%d ----\n", - Acr[i].id, Bcr[j].id ); + fprintf( flog, "\n---- Begin A-%d to B-%d ----\n", + Acr[i].id, Bcr[j].id ); - // start list with user's transform arguments + // start list with user's transform arguments - CStatus stat( Acr[i].id, Bcr[j].id ); - vector guesses = GBL.Tmsh; + CStatus stat( Acr[i].id, Bcr[j].id ); + vector guesses = GBL.Tmsh; - if( RoughMatch( guesses, - px, CM, Acr[i], Bcr[j], flog ) ) { + if( RoughMatch( guesses, + px, CM, Acr[i], Bcr[j], flog ) ) { - stat.thmok = true; + stat.thmok = true; - // Try to get detailed mesh solution from each - // guess {user + all returned from RoughMatch}. - // The first to be successful (diff count > 0) - // causes break. + // Try to get detailed mesh solution from each + // guess {user + all returned from RoughMatch}. + // The first to be successful (diff count > 0) + // causes break. - for( int k = 0; k < guesses.size(); ++k ) { + for( int k = 0; k < guesses.size(); ++k ) { - int count = maps.transforms.size(); + int count = maps.transforms.size(); - // Downscale coordinates - guesses[k].MulXY( 1.0 / px.scl ); + // Downscale coordinates + guesses[k].MulXY( 1.0 / px.scl ); - RegionToRegionMap( maps, map_mask, - px, Acr[i], Bcr[j], - guesses[k], flog, ftri ); + RegionToRegionMap( maps, map_mask, + px, Acr[i], Bcr[j], + guesses[k], flog, ftri ); - count = maps.transforms.size() - count; + count = maps.transforms.size() - count; - stat.ntri = count; + stat.ntri = count; - if( count ) - break; - } - } + if( count ) + break; + } + } - vstat.push_back( stat ); - } - } + vstat.push_back( stat ); + } + } - //if( ftri ) - // fclose( ftri ); + //if( ftri ) + // fclose( ftri ); /* ------------ */ /* Report total */ /* ------------ */ - Ntrans = maps.transforms.size(); + Ntrans = maps.transforms.size(); - fprintf( flog, - "Pipe: Returning %d total transforms.\n", Ntrans ); + fprintf( flog, + "Pipe: Returning %d total transforms.\n", Ntrans ); /* ---------------- */ /* Report by region */ /* ---------------- */ - fprintf( flog, - "\n---- Summary Region-region results ----\n" ); + fprintf( flog, + "\n---- Summary Region-region results ----\n" ); - fprintf( flog, - "Pipe: Table Headers {Az t r Bz t r thmok ntri}\n" ); + fprintf( flog, + "Pipe: Table Headers {Az t r Bz t r thmok ntri}\n" ); - int nstat = vstat.size(); + int nstat = vstat.size(); - for( int i = 0; i < nstat; ++i ) { + for( int i = 0; i < nstat; ++i ) { - const CStatus& S = vstat[i]; + const CStatus& S = vstat[i]; - fprintf( flog, - "FOUND: %5d %4d %3d %5d %4d %3d %3d %3d\n", - GBL.A.z, GBL.A.id, S.argn, - GBL.B.z, GBL.B.id, S.brgn, - S.thmok, S.ntri ); - } + fprintf( flog, + "FOUND: %5d %4d %3d %5d %4d %3d %3d %3d\n", + GBL.A.z, GBL.A.id, S.argn, + GBL.B.z, GBL.B.id, S.brgn, + S.thmok, S.ntri ); + } /* ---------------- */ /* Feature matches */ /* ---------------- */ - if( Ntrans ) { + if( Ntrans ) { - // Report results at full image size + // Report results at full image size - UpscaleCoords( maps, px.scl ); + UpscaleCoords( maps, px.scl ); - Matches AB; + Matches AB; - AB.Tabulate( px, vstat, maps, - fold_mask_a, fold_mask_b, wf, hf, flog ); + AB.Tabulate( px, vstat, maps, + fold_mask_a, fold_mask_b, wf, hf, flog ); - if( GBL.arg.JSON ) - AB.WriteAs_JSON(); - else - AB.WriteAs_CPOINT2(); + if( GBL.arg.JSON ) + AB.WriteAs_JSON(); + else + AB.WriteAs_CPOINT2(); - tr_array = (double*)malloc( Ntrans * 6 * sizeof(double) ); + tr_array = (double*)malloc( Ntrans * 6 * sizeof(double) ); - for( int i = 0; i < Ntrans; ++i ) { + for( int i = 0; i < Ntrans; ++i ) { - maps.transforms[i].ToMatlab(); - maps.transforms[i].CopyOut( tr_array + i*6 ); - } + maps.transforms[i].ToMatlab(); + maps.transforms[i].CopyOut( tr_array + i*6 ); + } - fprintf( flog, "\n" ); - } - else { + fprintf( flog, "\n" ); + } + else { - if( GBL.arg.JSON ) - Matches::WriteEmpty_JSON(); + if( GBL.arg.JSON ) + Matches::WriteEmpty_JSON(); - memset( map_mask, 0, wf * hf * sizeof(uint16) ); - } + memset( map_mask, 0, wf * hf * sizeof(uint16) ); + } } diff --git a/1_DMesh/dmesh.h b/1_DMesh/dmesh.h index 18d832c..d39f9c9 100644 --- a/1_DMesh/dmesh.h +++ b/1_DMesh/dmesh.h @@ -12,12 +12,12 @@ /* --------------------------------------------------------------- */ void PipelineDeformableMap( - int &Ntrans, - double* &tr_array, - uint16* map_mask, - const PixPair &px, - const uint8* fold_mask_a, - const uint8* fold_mask_b, - FILE* flog ); + int &Ntrans, + double* &tr_array, + uint16* map_mask, + const PixPair &px, + const uint8* fold_mask_a, + const uint8* fold_mask_b, + FILE* flog ); diff --git a/1_DMesh/dmesh_unused.cpp b/1_DMesh/dmesh_unused.cpp index 7e1db9f..ff6a323 100644 --- a/1_DMesh/dmesh_unused.cpp +++ b/1_DMesh/dmesh_unused.cpp @@ -13,10 +13,10 @@ for(int i=0; i<8; i++) { double dx, dy; ftc.clear(); // no caching wanted here double c = CorrPatches( - of, false, dx, dy, - ap, av, bp, bv, 0, 0, 4000, - BigEnough, (void *)size, - NULL, NULL, ftc ); + of, false, dx, dy, + ap, av, bp, bv, 0, 0, 4000, + BigEnough, (void *)size, + NULL, NULL, ftc ); fprintf(of, " JT: %4d by %4d, size %6d, corr %f, dx, dy = %9.2f, %9.2f\n", int(sqrt(ap.size())), int(sqrt(bp.size())), diff --git a/1_DMesh/dmeshdriver.cpp b/1_DMesh/dmeshdriver.cpp index 07b5c7d..6cf9d76 100644 --- a/1_DMesh/dmeshdriver.cpp +++ b/1_DMesh/dmeshdriver.cpp @@ -50,126 +50,126 @@ // free( rmap ); // static void CalcTransforms( - uint16* &rmap, - int &Ntrans, - TAffine* &tfs, - TAffine* &ifs, - const PixPair &px ) + uint16* &rmap, + int &Ntrans, + TAffine* &tfs, + TAffine* &ifs, + const PixPair &px ) { - char sfile[256]; - FILE* f = NULL; - uint8 *fold_mask_a, - *fold_mask_b; - double* tr_array = NULL; - clock_t t0; - int wf, hf; + char sfile[256]; + FILE* f = NULL; + uint8 *fold_mask_a, + *fold_mask_b; + double* tr_array = NULL; + clock_t t0; + int wf, hf; /* --------------- */ /* Initialize data */ /* --------------- */ - fprintf( stderr, "\n---- Foldmaps ----\n" ); + fprintf( stderr, "\n---- Foldmaps ----\n" ); - wf = px.wf; - hf = px.hf; - Ntrans = 0; - rmap = (uint16*)malloc( wf * hf * sizeof(uint16) ); + wf = px.wf; + hf = px.hf; + Ntrans = 0; + rmap = (uint16*)malloc( wf * hf * sizeof(uint16) ); - // Note that the foldmasks are always at full resolution. + // Note that the foldmasks are always at full resolution. - { - CCropMask CM, *pCM = &CM; + { + CCropMask CM, *pCM = &CM; - if( !CM.ReadIDB( GBL.idb, stderr ) ) - pCM = NULL; + if( !CM.ReadIDB( GBL.idb, stderr ) ) + pCM = NULL; - fold_mask_a = GetFoldMask( - GBL.idb, GBL.A, GBL.arg.fma, - px.resmska, pCM, - wf, hf, (GBL.ctx.FLD == 'N'), - GBL.arg.Transpose, GBL.arg.SingleFold, - stderr ); + fold_mask_a = GetFoldMask( + GBL.idb, GBL.A, GBL.arg.fma, + px.resmska, pCM, + wf, hf, (GBL.ctx.FLD == 'N'), + GBL.arg.Transpose, GBL.arg.SingleFold, + stderr ); - fold_mask_b = GetFoldMask( - GBL.idb, GBL.B, GBL.arg.fmb, - px.resmskb, pCM, - wf, hf, (GBL.ctx.FLD == 'N'), - GBL.arg.Transpose, GBL.arg.SingleFold, - stderr ); - } + fold_mask_b = GetFoldMask( + GBL.idb, GBL.B, GBL.arg.fmb, + px.resmskb, pCM, + wf, hf, (GBL.ctx.FLD == 'N'), + GBL.arg.Transpose, GBL.arg.SingleFold, + stderr ); + } /* ------------- */ /* Call Pipeline */ /* ------------- */ - t0 = StartTiming(); + t0 = StartTiming(); - PipelineDeformableMap( - Ntrans, tr_array, rmap, - px, fold_mask_a, fold_mask_b, stderr ); + PipelineDeformableMap( + Ntrans, tr_array, rmap, + px, fold_mask_a, fold_mask_b, stderr ); - StopTiming( stderr, "Alignment", t0 ); + StopTiming( stderr, "Alignment", t0 ); - RasterFree( fold_mask_a ); - RasterFree( fold_mask_b ); + RasterFree( fold_mask_a ); + RasterFree( fold_mask_b ); /* -------------- */ /* Report results */ /* -------------- */ - if( GBL.mch.WMT ) { + if( GBL.mch.WMT ) { - sprintf( sfile, "../%d/%d.%d.map.tif", - GBL.A.id, GBL.B.z, GBL.B.id ); + sprintf( sfile, "../%d/%d.%d.map.tif", + GBL.A.id, GBL.B.z, GBL.B.id ); - Raster16ToTif8( sfile, rmap, wf, hf ); - } + Raster16ToTif8( sfile, rmap, wf, hf ); + } - fprintf( stderr, "\nmain: Got %d mapping regions.\n", Ntrans ); + fprintf( stderr, "\nmain: Got %d mapping regions.\n", Ntrans ); /* ------------------------------- */ /* Convert tform arrays to objects */ /* ------------------------------- */ - tfs = new TAffine[Ntrans]; - ifs = new TAffine[Ntrans]; + tfs = new TAffine[Ntrans]; + ifs = new TAffine[Ntrans]; - if( GBL.mch.WTT ) { + if( GBL.mch.WTT ) { - sprintf( sfile, "../%d/%d.%d.tf.txt", - GBL.A.id, GBL.B.z, GBL.B.id ); + sprintf( sfile, "../%d/%d.%d.tf.txt", + GBL.A.id, GBL.B.z, GBL.B.id ); - f = fopen( sfile, "w" ); - } + f = fopen( sfile, "w" ); + } - for( int i = 0; i < Ntrans; ++i ) { + for( int i = 0; i < Ntrans; ++i ) { - // copy-in Matlab-style values - for( int j = 0; j < 6; ++j ) - tfs[i].t[j] = tr_array[i*6+j]; + // copy-in Matlab-style values + for( int j = 0; j < 6; ++j ) + tfs[i].t[j] = tr_array[i*6+j]; - // print in Matlab format - if( f ) { - fprintf( f, "%9.6f %9.6f %9.6f %9.6f %10.2f %10.2f\n", - tfs[i].t[0], tfs[i].t[1], tfs[i].t[2], - tfs[i].t[3], tfs[i].t[4], tfs[i].t[5] ); - } + // print in Matlab format + if( f ) { + fprintf( f, "%9.6f %9.6f %9.6f %9.6f %10.2f %10.2f\n", + tfs[i].t[0], tfs[i].t[1], tfs[i].t[2], + tfs[i].t[3], tfs[i].t[4], tfs[i].t[5] ); + } - // now convert to our format - tfs[i].FromMatlab(); - ifs[i].InverseOf( tfs[i] ); + // now convert to our format + tfs[i].FromMatlab(); + ifs[i].InverseOf( tfs[i] ); - fprintf( stderr, "main: Transform %3d: ", i ); - tfs[i].TPrint( stderr ); - } + fprintf( stderr, "main: Transform %3d: ", i ); + tfs[i].TPrint( stderr ); + } - fprintf( stderr, "\n" ); + fprintf( stderr, "\n" ); - if( f ) - fclose( f ); + if( f ) + fclose( f ); - if( tr_array ) - free( tr_array ); + if( tr_array ) + free( tr_array ); } /* --------------------------------------------------------------- */ @@ -178,19 +178,19 @@ static void CalcTransforms( static void Decomp( const TAffine &T, const char *label ) { - fprintf( stderr, "main: %s: ", label ); - T.TPrint( stderr ); + fprintf( stderr, "main: %s: ", label ); + T.TPrint( stderr ); - double r = T.GetRadians(); - TAffine R, D; + double r = T.GetRadians(); + TAffine R, D; - R.NUSetRot( -r ); - D = R * T; + R.NUSetRot( -r ); + D = R * T; - fprintf( stderr, "main: Degrees: %g\n", r*180/PI ); - D.TPrint( stderr, "main: Residue: " ); + fprintf( stderr, "main: Degrees: %g\n", r*180/PI ); + D.TPrint( stderr, "main: Residue: " ); - fprintf( stderr, "\n" ); + fprintf( stderr, "\n" ); } /* --------------------------------------------------------------- */ @@ -199,28 +199,28 @@ static void Decomp( const TAffine &T, const char *label ) static void ReportAveTAffine( int Ntrans, const TAffine* tfs ) { - if( !Ntrans ) - return; + if( !Ntrans ) + return; - TAffine I, T = tfs[0]; + TAffine I, T = tfs[0]; - if( Ntrans > 1 ) { + if( Ntrans > 1 ) { - for( int i = 1; i < Ntrans; ++i ) { + for( int i = 1; i < Ntrans; ++i ) { - for( int j = 0; j < 6; ++j ) - T.t[j] += tfs[i].t[j]; - } + for( int j = 0; j < 6; ++j ) + T.t[j] += tfs[i].t[j]; + } - for( int j = 0; j < 6; ++j ) - T.t[j] /= Ntrans; - } + for( int j = 0; j < 6; ++j ) + T.t[j] /= Ntrans; + } - T.t[2] = T.t[5] = 0.0; + T.t[2] = T.t[5] = 0.0; - Decomp( T, "Average" ); - I.InverseOf( T ); - Decomp( I, "Inverse" ); + Decomp( T, "Average" ); + I.InverseOf( T ); + Decomp( I, "Inverse" ); } /* --------------------------------------------------------------- */ @@ -229,113 +229,113 @@ static void ReportAveTAffine( int Ntrans, const TAffine* tfs ) int main( int argc, char* argv[] ) { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); /* ------------------ */ /* Parse command line */ /* ------------------ */ - if( !GBL.SetCmdLine( argc, argv ) ) - return 42; + if( !GBL.SetCmdLine( argc, argv ) ) + return 42; /* ---------- */ /* Get images */ /* ---------- */ - PixPair px; - uint16* rmap = NULL; - TAffine* tfs = NULL; - TAffine* ifs = NULL; - int Ntrans = 0; + PixPair px; + uint16* rmap = NULL; + TAffine* tfs = NULL; + TAffine* ifs = NULL; + int Ntrans = 0; - if( !px.Load( - GBL.A, GBL.B, GBL.idb, - GBL.mch.PXLENS, GBL.mch.PXRESMSK, GBL.mch.PXBRO, - GBL.mch.PXDOG, GBL.mch.PXDOG_R1, GBL.mch.PXDOG_R2, - stderr, GBL.arg.Transpose ) ) { + if( !px.Load( + GBL.A, GBL.B, GBL.idb, + GBL.mch.PXLENS, GBL.mch.PXRESMSK, GBL.mch.PXBRO, + GBL.mch.PXDOG, GBL.mch.PXDOG_R1, GBL.mch.PXDOG_R2, + stderr, GBL.arg.Transpose ) ) { - goto exit; - } + goto exit; + } /* ------------------- */ /* Scaling adjustments */ /* ------------------- */ - GBL.ctx.OLAP1D /= px.scl; - GBL.ctx.OLAP2D /= (px.scl * px.scl); - GBL.mch.MNL /= px.scl; - GBL.mch.MTA /= (px.scl * px.scl); - GBL.mch.MMA /= (px.scl * px.scl); + GBL.ctx.OLAP1D /= px.scl; + GBL.ctx.OLAP2D /= (px.scl * px.scl); + GBL.mch.MNL /= px.scl; + GBL.mch.MTA /= (px.scl * px.scl); + GBL.mch.MMA /= (px.scl * px.scl); /* ----------------------- */ /* Just test overlap code? */ /* ----------------------- */ - if( GBL.arg.WithinSection ) { + if( GBL.arg.WithinSection ) { - double *apts = NULL; - double *bpts = NULL; - int Npts; + double *apts = NULL; + double *bpts = NULL; + int Npts; - clock_t t1 = StartTiming(); + clock_t t1 = StartTiming(); - InSectionOverlap( Npts, apts, bpts, px, stderr ); + InSectionOverlap( Npts, apts, bpts, px, stderr ); - StopTiming( stderr, "InSectionOverlap", t1 ); + StopTiming( stderr, "InSectionOverlap", t1 ); - fprintf( stderr, - "main: InSectionOverlap returned %d points.\n", Npts ); + fprintf( stderr, + "main: InSectionOverlap returned %d points.\n", Npts ); - if( apts ) - free( apts ); + if( apts ) + free( apts ); - if( bpts ) - free( bpts ); + if( bpts ) + free( bpts ); - goto exit; - } + goto exit; + } /* ------------- */ /* Call Pipeline */ /* ------------- */ - CalcTransforms( rmap, Ntrans, tfs, ifs, px ); + CalcTransforms( rmap, Ntrans, tfs, ifs, px ); - ReportAveTAffine( Ntrans, tfs ); + ReportAveTAffine( Ntrans, tfs ); /* ----------- */ /* Diagnostics */ /* ----------- */ - if( Ntrans && GBL.arg.Verbose ) { + if( Ntrans && GBL.arg.Verbose ) { - ABOverlay( px, rmap, Ntrans, tfs, ifs, - GBL.arg.comp_png, stderr ); + ABOverlay( px, rmap, Ntrans, tfs, ifs, + GBL.arg.comp_png, stderr ); - RunCorrView( px, rmap, tfs, GBL.arg.Heatmap, - GBL.arg.registered_png, stderr ); - } + RunCorrView( px, rmap, tfs, GBL.arg.Heatmap, + GBL.arg.registered_png, stderr ); + } /* ------- */ /* Cleanup */ /* ------- */ - fprintf( stderr, "main: Normal completion for dmesh run.\n" ); + fprintf( stderr, "main: Normal completion for dmesh run.\n" ); - if( ifs ) - delete [] ifs; + if( ifs ) + delete [] ifs; - if( tfs ) - delete [] tfs; + if( tfs ) + delete [] tfs; - if( rmap ) - free( rmap ); + if( rmap ) + free( rmap ); exit: - StopTiming( stderr, "Total", t0 ); - VMStats( stderr ); + StopTiming( stderr, "Total", t0 ); + VMStats( stderr ); - return 0; + return 0; } diff --git a/1_DMesh/janelia.cpp b/1_DMesh/janelia.cpp index e311b39..b2ce132 100644 --- a/1_DMesh/janelia.cpp +++ b/1_DMesh/janelia.cpp @@ -66,10 +66,10 @@ static string stripQuotes( string &s ) { - if( s.find( "\"" ) == 0 ) - return s.substr( 1, s.length() - 2 ); - else - return s; + if( s.find( "\"" ) == 0 ) + return s.substr( 1, s.length() - 2 ); + else + return s; } /* --------------------------------------------------------------- */ @@ -86,43 +86,43 @@ static string stripQuotes( string &s ) // static bool copy_img_from_URL( string &output_path, string url ) { - CURL *easy_handle = curl_easy_init(); - bool ok = false; + CURL *easy_handle = curl_easy_init(); + bool ok = false; - if( easy_handle ) { + if( easy_handle ) { - string suffix = url.substr( url.find_last_of(".") ); + string suffix = url.substr( url.find_last_of(".") ); - output_path = tmpnam( NULL ) + suffix; + output_path = tmpnam( NULL ) + suffix; - // Open file + // Open file - FILE *fp = fopen( output_path.c_str(), "wb" ); + FILE *fp = fopen( output_path.c_str(), "wb" ); - if( !fp ) { - (void)perror( "Extract: The following error occurred: " ); - goto exit; - } + if( !fp ) { + (void)perror( "Extract: The following error occurred: " ); + goto exit; + } - curl_easy_setopt( easy_handle, CURLOPT_URL, url.c_str() ); - curl_easy_setopt( easy_handle, CURLOPT_WRITEFUNCTION, NULL ); - curl_easy_setopt( easy_handle, CURLOPT_WRITEDATA, fp ); + curl_easy_setopt( easy_handle, CURLOPT_URL, url.c_str() ); + curl_easy_setopt( easy_handle, CURLOPT_WRITEFUNCTION, NULL ); + curl_easy_setopt( easy_handle, CURLOPT_WRITEDATA, fp ); - // Grab image + // Grab image - CURLcode imgresult = curl_easy_perform( easy_handle ); + CURLcode imgresult = curl_easy_perform( easy_handle ); - if( imgresult ) - fprintf( stderr, "Extract: Cannot grab the image.\n" ); - else - ok = true; + if( imgresult ) + fprintf( stderr, "Extract: Cannot grab the image.\n" ); + else + ok = true; - fclose( fp ); - } + fclose( fp ); + } exit: - curl_easy_cleanup( easy_handle ); - return ok; + curl_easy_cleanup( easy_handle ); + return ok; } /* --------------------------------------------------------------- */ @@ -133,12 +133,12 @@ static bool copy_img_from_URL( string &output_path, string url ) // static string url_to_path( string &url ) { - string prefix = "file:"; + string prefix = "file:"; - if( url.find( prefix ) == 0 ) - return url.substr( prefix.length() ); - else - return url; + if( url.find( prefix ) == 0 ) + return url.substr( prefix.length() ); + else + return url; } /* --------------------------------------------------------------- */ @@ -146,49 +146,49 @@ static string url_to_path( string &url ) /* --------------------------------------------------------------- */ static void Tokenize( - vector &tokens, - const string &str, - const string &delimiters, - bool stripQ ) + vector &tokens, + const string &str, + const string &delimiters, + bool stripQ ) { - string::size_type start, stop = 0; + string::size_type start, stop = 0; - for(;;) { + for(;;) { - start = str.find_first_not_of( delimiters, stop ); + start = str.find_first_not_of( delimiters, stop ); - if( start == string::npos ) - return; + if( start == string::npos ) + return; - stop = str.find_first_of( delimiters, start + 1 ); + stop = str.find_first_of( delimiters, start + 1 ); - string tok = str.substr( start, stop - start ); - - if( stripQ ) - tokens.push_back( stripQuotes( tok ) ); - else - tokens.push_back( tok ); - } + string tok = str.substr( start, stop - start ); + + if( stripQ ) + tokens.push_back( stripQuotes( tok ) ); + else + tokens.push_back( tok ); + } } static size_t WriteCallback( void *src, size_t size, size_t nmemb, void *dst ) { - size_t bytes = size * nmemb; + size_t bytes = size * nmemb; - ((std::string*)dst)->append( (char*)src, bytes ); + ((std::string*)dst)->append( (char*)src, bytes ); - return bytes; + return bytes; } #define GETDOUBLE( field, name ) \ - if( !tokens2[0].compare( name ) ) \ - {field = strtod( tokens2[2].c_str(), NULL );} + if( !tokens2[0].compare( name ) ) \ + {field = strtod( tokens2[2].c_str(), NULL );} #define GETSTRING( field, name ) \ - if( !tokens2[0].compare( name ) ) \ - {field = tokens2[2];} + if( !tokens2[0].compare( name ) ) \ + {field = tokens2[2];} // URL examples: @@ -203,59 +203,59 @@ static size_t WriteCallback( void *src, size_t size, size_t nmemb, void *dst ) // bool GetTileSpecFromURL( PicSpec &P, const char *pat, char *argv ) { - int len = strlen( pat ); + int len = strlen( pat ); - if( !strncmp( argv, pat, len ) ) { + if( !strncmp( argv, pat, len ) ) { - std::string readBuffer; - CURL *easy_handle = curl_easy_init(); - CURLcode res; + std::string readBuffer; + CURL *easy_handle = curl_easy_init(); + CURLcode res; // curl_easy_setopt( easy_handle, CURLOPT_VERBOSE, 1L ); - curl_easy_setopt( easy_handle, CURLOPT_URL, argv + len ); - curl_easy_setopt( easy_handle, CURLOPT_WRITEFUNCTION, WriteCallback ); - curl_easy_setopt( easy_handle, CURLOPT_WRITEDATA, &readBuffer ); + curl_easy_setopt( easy_handle, CURLOPT_URL, argv + len ); + curl_easy_setopt( easy_handle, CURLOPT_WRITEFUNCTION, WriteCallback ); + curl_easy_setopt( easy_handle, CURLOPT_WRITEDATA, &readBuffer ); - res = curl_easy_perform( easy_handle ); - curl_easy_cleanup( easy_handle ); + res = curl_easy_perform( easy_handle ); + curl_easy_cleanup( easy_handle ); - if( res ) { - fprintf( stderr, "jtile: Can't parse [%s].\n", argv ); - return false; - } + if( res ) { + fprintf( stderr, "jtile: Can't parse [%s].\n", argv ); + return false; + } - vector tokens; - Tokenize( tokens, readBuffer, "\n", false ); + vector tokens; + Tokenize( tokens, readBuffer, "\n", false ); - for( int i = 0, n = tokens.size(); i < n; ++i ) { + for( int i = 0, n = tokens.size(); i < n; ++i ) { - vector tokens2; - Tokenize( tokens2, tokens[i], " ,\n", true ); + vector tokens2; + Tokenize( tokens2, tokens[i], " ,\n", true ); - if( tokens2.size() != 3 ) - continue; + if( tokens2.size() != 3 ) + continue; - GETDOUBLE( P.z, "z" ); - GETSTRING( P.t2i.path, "imageUrl" ); - GETDOUBLE( P.t2i.T.t[2], "stageX" ); - GETDOUBLE( P.t2i.T.t[5], "stageY" ); - GETDOUBLE( P.t2i.col, "imageCol" ); - GETDOUBLE( P.t2i.row, "imageRow" ); - GETDOUBLE( P.t2i.cam, "camera" ); - } + GETDOUBLE( P.z, "z" ); + GETSTRING( P.t2i.path, "imageUrl" ); + GETDOUBLE( P.t2i.T.t[2], "stageX" ); + GETDOUBLE( P.t2i.T.t[5], "stageY" ); + GETDOUBLE( P.t2i.col, "imageCol" ); + GETDOUBLE( P.t2i.row, "imageRow" ); + GETDOUBLE( P.t2i.cam, "camera" ); + } // copy_img_from_URL( P.t2i.path, P.t2i.path ); - P.t2i.path = url_to_path( P.t2i.path ); - P.t2i.id = -1; + P.t2i.path = url_to_path( P.t2i.path ); + P.t2i.id = -1; - if( P.t2i.path.size() > 0 ) { + if( P.t2i.path.size() > 0 ) { - P.id = -1; - return true; - } - } + P.id = -1; + return true; + } + } - return false; + return false; } #endif // USE_CURL diff --git a/1_DMesh/janelia.h b/1_DMesh/janelia.h index d5c6955..7618251 100644 --- a/1_DMesh/janelia.h +++ b/1_DMesh/janelia.h @@ -14,7 +14,7 @@ bool GetTileSpecFromURL( PicSpec &P, const char *pat, char *argv ); #else bool GetTileSpecFromURL( PicSpec &P, const char *pat, char *argv ) - {return false;} + {return false;} #endif diff --git a/1_DMesh/makefile b/1_DMesh/makefile index 3510ed9..4183a1d 100644 --- a/1_DMesh/makefile +++ b/1_DMesh/makefile @@ -31,8 +31,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_DelTiles/DelTiles.cpp b/1_DelTiles/DelTiles.cpp index d257359..9affbf8 100644 --- a/1_DelTiles/DelTiles.cpp +++ b/1_DelTiles/DelTiles.cpp @@ -28,12 +28,12 @@ using namespace std; class CArgs_xml { public: - char *xmlfile, - *txtfile; + char *xmlfile, + *txtfile; public: - CArgs_xml() : xmlfile(NULL), txtfile(NULL) {}; + CArgs_xml() : xmlfile(NULL), txtfile(NULL) {}; - void SetCmdLine( int argc, char* argv[] ); + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -60,33 +60,33 @@ void CArgs_xml::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "DelTiles.log", "w" ); + flog = FileOpenOrDie( "DelTiles.log", "w" ); // parse command line args - if( argc < 3 ) { - printf( - "Usage: DelTiles [options].\n" ); - exit( 42 ); - } - - for( int i = 1; i < argc; ++i ) { - - if( argv[i][0] != '-' ) { - - if( !xmlfile ) - xmlfile = argv[i]; - else - txtfile = argv[i]; - } - else { - printf( "Did not understand option [%s].\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n\n" ); - fflush( flog ); + if( argc < 3 ) { + printf( + "Usage: DelTiles [options].\n" ); + exit( 42 ); + } + + for( int i = 1; i < argc; ++i ) { + + if( argv[i][0] != '-' ) { + + if( !xmlfile ) + xmlfile = argv[i]; + else + txtfile = argv[i]; + } + else { + printf( "Did not understand option [%s].\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n\n" ); + fflush( flog ); } /* --------------------------------------------------------------- */ @@ -95,29 +95,29 @@ void CArgs_xml::SetCmdLine( int argc, char* argv[] ) static void LoadList() { - FILE *f = FileOpenOrDie( gArgs.txtfile, "r", flog ); - CLineScan LS; + FILE *f = FileOpenOrDie( gArgs.txtfile, "r", flog ); + CLineScan LS; - for(;;) { + for(;;) { - if( LS.Get( f ) <= 0 ) - break; + if( LS.Get( f ) <= 0 ) + break; - MZID R; + MZID R; - sscanf( LS.line, "%d\t%d", &R.z, &R.id ); + sscanf( LS.line, "%d\t%d", &R.z, &R.id ); - if( R.z < zlo ) - zlo = R.z; + if( R.z < zlo ) + zlo = R.z; - if( R.z > zhi ) - zhi = R.z; + if( R.z > zhi ) + zhi = R.z; - Z.insert( R.z ); - M.insert( R ); - } + Z.insert( R.z ); + M.insert( R ); + } - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -126,21 +126,21 @@ static void LoadList() static void DeleteTiles( TiXmlElement* layer, int z ) { - MZID key; - TiXmlElement* p = layer->FirstChildElement( "t2_patch" ); - TiXmlElement* nextT; + MZID key; + TiXmlElement* p = layer->FirstChildElement( "t2_patch" ); + TiXmlElement* nextT; - key.z = z; + key.z = z; - for( ; p; p = nextT ) { + for( ; p; p = nextT ) { - nextT = p->NextSiblingElement(); + nextT = p->NextSiblingElement(); - key.id = IDFromPatch( p ); + key.id = IDFromPatch( p ); - if( M.find( key ) != M.end() ) - layer->RemoveChild( p ); - } + if( M.find( key ) != M.end() ) + layer->RemoveChild( p ); + } } /* --------------------------------------------------------------- */ @@ -153,39 +153,39 @@ static void Edit() /* Open */ /* ---- */ - XML_TKEM xml( gArgs.xmlfile, flog ); - TiXmlElement* layer = xml.GetFirstLayer(); + XML_TKEM xml( gArgs.xmlfile, flog ); + TiXmlElement* layer = xml.GetFirstLayer(); /* --------- */ /* Do layers */ /* --------- */ - TiXmlNode* lyrset = layer->Parent(); - TiXmlElement* nextL; + TiXmlNode* lyrset = layer->Parent(); + TiXmlElement* nextL; - for( ; layer; layer = nextL ) { + for( ; layer; layer = nextL ) { - nextL = layer->NextSiblingElement(); + nextL = layer->NextSiblingElement(); - int z = atoi( layer->Attribute( "z" ) ); + int z = atoi( layer->Attribute( "z" ) ); - if( z > zhi ) - break; + if( z > zhi ) + break; - if( z < zlo || Z.find( z ) == Z.end() ) - continue; + if( z < zlo || Z.find( z ) == Z.end() ) + continue; - DeleteTiles( layer, z ); + DeleteTiles( layer, z ); - if( !layer->FirstChildElement( "t2_patch" ) ) - lyrset->RemoveChild( layer ); - } + if( !layer->FirstChildElement( "t2_patch" ) ) + lyrset->RemoveChild( layer ); + } /* ---- */ /* Save */ /* ---- */ - xml.Save( "xmltmp.txt", true ); + xml.Save( "xmltmp.txt", true ); } /* --------------------------------------------------------------- */ @@ -198,28 +198,28 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* ---------------- */ /* Map (z,id) to sd */ /* ---------------- */ - LoadList(); + LoadList(); /* ---- */ /* Edit */ /* ---- */ - Edit(); + Edit(); /* ---- */ /* Done */ /* ---- */ - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_DelTiles/makefile b/1_DelTiles/makefile index 5fa3f6b..1ea144e 100644 --- a/1_DelTiles/makefile +++ b/1_DelTiles/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_EView/eview.cpp b/1_EView/eview.cpp index d4fa610..40d8a2d 100644 --- a/1_EView/eview.cpp +++ b/1_EView/eview.cpp @@ -26,9 +26,9 @@ class CHst { public: - long *all, *sam, *dwn; + long *all, *sam, *dwn; public: - void Read( const char *path ); + void Read( const char *path ); }; /* --------------------------------------------------------------- */ @@ -37,16 +37,16 @@ class CHst { class CArgs { public: - char *inA, *inB; - int zilo, zihi, - lim, div; + char *inA, *inB; + int zilo, zihi, + lim, div; public: - CArgs() : - inA(NULL), inB(NULL), - zilo(0), zihi(32768), - lim(500), div(10) {}; + CArgs() : + inA(NULL), inB(NULL), + zilo(0), zihi(32768), + lim(500), div(10) {}; - void SetCmdLine( int argc, char* argv[] ); + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -70,55 +70,55 @@ void CArgs::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "eview.txt", "w" ); + flog = FileOpenOrDie( "eview.txt", "w" ); // parse command line args - if( argc < 3 ) { - printf( "Usage: eview fileA [fileB] -z=i,j [options].\n" ); - exit( 42 ); - } - - vector vi; - - for( int i = 1; i < argc; ++i ) { - - if( argv[i][0] != '-' ) { - - if( !inA ) - inA = argv[i]; - else - inB = argv[i]; - } - else if( GetArgList( vi, "-z=", argv[i] ) ) { - - if( 2 == vi.size() ) { - zilo = vi[0]; - zihi = vi[1]; - } - else { - fprintf( flog, "Bad format in -z [%s].\n", argv[i] ); - exit( 42 ); - } - } - else if( GetArg( &lim, "-lim=%d", argv[i] ) ) - ; - else if( GetArg( &div, "-div=%d", argv[i] ) ) - ; - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - exit( 42 ); - } - } + if( argc < 3 ) { + printf( "Usage: eview fileA [fileB] -z=i,j [options].\n" ); + exit( 42 ); + } + + vector vi; + + for( int i = 1; i < argc; ++i ) { + + if( argv[i][0] != '-' ) { + + if( !inA ) + inA = argv[i]; + else + inB = argv[i]; + } + else if( GetArgList( vi, "-z=", argv[i] ) ) { + + if( 2 == vi.size() ) { + zilo = vi[0]; + zihi = vi[1]; + } + else { + fprintf( flog, "Bad format in -z [%s].\n", argv[i] ); + exit( 42 ); + } + } + else if( GetArg( &lim, "-lim=%d", argv[i] ) ) + ; + else if( GetArg( &div, "-div=%d", argv[i] ) ) + ; + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + exit( 42 ); + } + } // headers - fprintf( flog, "Err\tAall\tAsam\tAdwn" ); + fprintf( flog, "Err\tAall\tAsam\tAdwn" ); - if( inB ) - fprintf( flog, "\tBall\tBsam\tBdwn\n" ); - else - fprintf( flog, "\n" ); + if( inB ) + fprintf( flog, "\tBall\tBsam\tBdwn\n" ); + else + fprintf( flog, "\n" ); } /* --------------------------------------------------------------- */ @@ -127,75 +127,75 @@ void CArgs::SetCmdLine( int argc, char* argv[] ) void CHst::Read( const char *path ) { - int emax = gArgs.lim * gArgs.div; - int bytes = (emax + 1)*sizeof(long); + int emax = gArgs.lim * gArgs.div; + int bytes = (emax + 1)*sizeof(long); - all = (long*)malloc( bytes ); - sam = (long*)malloc( bytes ); - dwn = (long*)malloc( bytes ); + all = (long*)malloc( bytes ); + sam = (long*)malloc( bytes ); + dwn = (long*)malloc( bytes ); - memset( all, 0, bytes ); - memset( sam, 0, bytes ); - memset( dwn, 0, bytes ); + memset( all, 0, bytes ); + memset( sam, 0, bytes ); + memset( dwn, 0, bytes ); - vector ve; + vector ve; - for( int z = gArgs.zilo; z <= gArgs.zihi; ++z ) { + for( int z = gArgs.zilo; z <= gArgs.zihi; ++z ) { - char buf[2048]; - FILE *f; - long n; + char buf[2048]; + FILE *f; + long n; - /* ---- */ - /* Same */ - /* ---- */ + /* ---- */ + /* Same */ + /* ---- */ - sprintf( buf, "%s/Err_S_%d.bin", path, z ); - n = (long)DskBytes( buf ) / sizeof(float); + sprintf( buf, "%s/Err_S_%d.bin", path, z ); + n = (long)DskBytes( buf ) / sizeof(float); - if( !n ) - continue; + if( !n ) + continue; - ve.resize( n ); + ve.resize( n ); - f = FileOpenOrDie( buf, "rb" ); - fread( &ve[0], sizeof(float), n, f ); - fclose( f ); + f = FileOpenOrDie( buf, "rb" ); + fread( &ve[0], sizeof(float), n, f ); + fclose( f ); - for( int i = 0; i < n; ++i ) { + for( int i = 0; i < n; ++i ) { - double e = gArgs.div * ve[i]; - int ibin = (e < emax ? int(e) : emax); + double e = gArgs.div * ve[i]; + int ibin = (e < emax ? int(e) : emax); - ++all[ibin]; - ++sam[ibin]; - } + ++all[ibin]; + ++sam[ibin]; + } - /* ---- */ - /* Down */ - /* ---- */ + /* ---- */ + /* Down */ + /* ---- */ - sprintf( buf, "%s/Err_D_%d.bin", path, z ); - n = (long)DskBytes( buf ) / sizeof(float); + sprintf( buf, "%s/Err_D_%d.bin", path, z ); + n = (long)DskBytes( buf ) / sizeof(float); - if( !n ) - continue; + if( !n ) + continue; - ve.resize( n ); + ve.resize( n ); - f = FileOpenOrDie( buf, "rb" ); - fread( &ve[0], sizeof(float), n, f ); - fclose( f ); + f = FileOpenOrDie( buf, "rb" ); + fread( &ve[0], sizeof(float), n, f ); + fclose( f ); - for( int i = 0; i < n; ++i ) { + for( int i = 0; i < n; ++i ) { - double e = gArgs.div * ve[i]; - int ibin = (e < emax ? int(e) : emax); + double e = gArgs.div * ve[i]; + int ibin = (e < emax ? int(e) : emax); - ++all[ibin]; - ++dwn[ibin]; - } - } + ++all[ibin]; + ++dwn[ibin]; + } + } } /* --------------------------------------------------------------- */ @@ -204,25 +204,25 @@ void CHst::Read( const char *path ) static void Record() { - int n = gArgs.lim * gArgs.div + 1; - - for( int i = 0; i < n; ++i ) { - - if( gArgs.inB ) { - - fprintf( flog, - "%.4f\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\n", - double(i + 1)/gArgs.div, - A.all[i], A.sam[i], A.dwn[i], - B.all[i], B.sam[i], B.dwn[i] ); - } - else { - fprintf( flog, - "%.4f\t%ld\t%ld\t%ld\n", - double(i + 1)/gArgs.div, - A.all[i], A.sam[i], A.dwn[i] ); - } - } + int n = gArgs.lim * gArgs.div + 1; + + for( int i = 0; i < n; ++i ) { + + if( gArgs.inB ) { + + fprintf( flog, + "%.4f\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\n", + double(i + 1)/gArgs.div, + A.all[i], A.sam[i], A.dwn[i], + B.all[i], B.sam[i], B.dwn[i] ); + } + else { + fprintf( flog, + "%.4f\t%ld\t%ld\t%ld\n", + double(i + 1)/gArgs.div, + A.all[i], A.sam[i], A.dwn[i] ); + } + } } /* --------------------------------------------------------------- */ @@ -235,30 +235,30 @@ int main( int argc, char **argv ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* ---- */ /* Read */ /* ---- */ - A.Read( gArgs.inA ); + A.Read( gArgs.inA ); - if( gArgs.inB ) - B.Read( gArgs.inB ); + if( gArgs.inB ) + B.Read( gArgs.inB ); /* ----- */ /* Print */ /* ----- */ - Record(); + Record(); /* ---- */ /* Done */ /* ---- */ - fclose( flog ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_EView/makefile b/1_EView/makefile index 704745f..6dcf7f5 100644 --- a/1_EView/makefile +++ b/1_EView/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_LSQi/lsq.cpp b/1_LSQi/lsq.cpp index 38e3f8f..02ced43 100644 --- a/1_LSQi/lsq.cpp +++ b/1_LSQi/lsq.cpp @@ -28,50 +28,50 @@ class CArgs { public: - double Wr, // Aff -> (1-Wr)*Aff + Wr*Rgd - Etol; // point error tolerance - char tempdir[2048], // master workspace - cachedir[2048]; // {catalog, pnts} files - const char *prior, // start from these solutions - *mode; // {catalog,eval,split,A2A,A2H,H2H} - int zilo, // my output range - zihi, - zolo, // extended input range - zohi, - regtype, // regularizer {T,R} - iters, // solve iterations - splitmin, // separate islands > splitmin tiles - zpernode, // max layers per node - maxthreads; // maximum threads per node - bool catclr, // remake point catalog - untwist, // iff prior are affines - local; // run locally (no qsub) if 1 worker + double Wr, // Aff -> (1-Wr)*Aff + Wr*Rgd + Etol; // point error tolerance + char tempdir[2048], // master workspace + cachedir[2048]; // {catalog, pnts} files + const char *prior, // start from these solutions + *mode; // {catalog,eval,split,A2A,A2H,H2H} + int zilo, // my output range + zihi, + zolo, // extended input range + zohi, + regtype, // regularizer {T,R} + iters, // solve iterations + splitmin, // separate islands > splitmin tiles + zpernode, // max layers per node + maxthreads; // maximum threads per node + bool catclr, // remake point catalog + untwist, // iff prior are affines + local; // run locally (no qsub) if 1 worker public: - CArgs() - { - Wr = 0.001; - Etol = 30; - tempdir[0] = 0; - cachedir[0] = 0; - prior = NULL; - mode = "A2A"; - zilo = 0; - zihi = 0; - zolo = -1; - zohi = -1; - regtype = 'R'; - iters = 2000; - splitmin = 1000; - zpernode = 200; - maxthreads = 1; - catclr = false; - untwist = false; - local = false; - }; - - void SetCmdLine( int argc, char* argv[] ); - void LaunchWorkers( const vector &vL ); + CArgs() + { + Wr = 0.001; + Etol = 30; + tempdir[0] = 0; + cachedir[0] = 0; + prior = NULL; + mode = "A2A"; + zilo = 0; + zihi = 0; + zolo = -1; + zohi = -1; + regtype = 'R'; + iters = 2000; + splitmin = 1000; + zpernode = 200; + maxthreads = 1; + catclr = false; + untwist = false; + local = false; + }; + + void SetCmdLine( int argc, char* argv[] ); + void LaunchWorkers( const vector &vL ); }; /* --------------------------------------------------------------- */ @@ -93,145 +93,145 @@ void CArgs::SetCmdLine( int argc, char* argv[] ) { // Name front end log - freopen( "lsq.txt", "w", stdout ); + freopen( "lsq.txt", "w", stdout ); // Parse command line args - printf( "---- Read params ----\n" ); - - if( argc < 3 ) { - printf( - "Usage: lsq -temp=path -zi=i,j [options].\n" ); - exit( 42 ); - } - - vector vi; - - for( int i = 1; i < argc; ++i ) { - - const char *instr; - - if( GetArgStr( instr, "-temp=", argv[i] ) ) { - - DskAbsPath( tempdir, sizeof(tempdir), instr, stdout ); - printf( "Temp dir: '%s'.\n", tempdir ); - } - else if( GetArgStr( instr, "-cache=", argv[i] ) ) { - - DskAbsPath( cachedir, sizeof(cachedir), instr, stdout ); - printf( "Cache dir: '%s'.\n", cachedir ); - } - else if( GetArgStr( prior, "-prior=", argv[i] ) ) - printf( "Prior solutions: '%s'.\n", prior ); - else if( GetArgStr( mode, "-mode=", argv[i] ) ) - printf( "Mode: '%s'.\n", mode ); - else if( GetArgList( vi, "-zi=", argv[i] ) ) { - - if( 2 == vi.size() ) { - zilo = vi[0]; - zihi = vi[1]; - printf( "zi [%d %d]\n", zilo, zihi ); - } - else { - printf( "Bad format in -zi [%s].\n", argv[i] ); - exit( 42 ); - } - } - else if( GetArgList( vi, "-zo=", argv[i] ) ) { - - if( 2 == vi.size() ) { - zolo = vi[0]; - zohi = vi[1]; - printf( "zo [%d %d]\n", zolo, zohi ); - } - else { - printf( "Bad format in -zo [%s].\n", argv[i] ); - exit( 42 ); - } - } - else if( GetArg( &Wr, "-Wr=T,%lf", argv[i] ) ) { - regtype = 'T'; - printf( "Rglizer Wr: T, %g\n", Wr ); - } - else if( GetArg( &Wr, "-Wr=R,%lf", argv[i] ) ) { - regtype = 'R'; - printf( "Rglizer Wr: R, %g\n", Wr ); - } - else if( GetArg( &Etol, "-Etol=%lf", argv[i] ) ) - printf( "Error tol: %g\n", Etol ); - else if( GetArg( &iters, "-iters=%d", argv[i] ) ) - printf( "Iterations: %d\n", iters ); - else if( GetArg( &splitmin, "-splitmin=%d", argv[i] ) ) - ; - else if( GetArg( &zpernode, "-zpernode=%d", argv[i] ) ) - ; - else if( GetArg( &maxthreads, "-maxthreads=%d", argv[i] ) ) - ; - else if( IsArg( "-catclr", argv[i] ) ) - catclr = true; - else if( IsArg( "-untwist", argv[i] ) ) - untwist = true; - else if( IsArg( "-local", argv[i] ) ) - local = true; - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - exit( 42 ); - } - } + printf( "---- Read params ----\n" ); + + if( argc < 3 ) { + printf( + "Usage: lsq -temp=path -zi=i,j [options].\n" ); + exit( 42 ); + } + + vector vi; + + for( int i = 1; i < argc; ++i ) { + + const char *instr; + + if( GetArgStr( instr, "-temp=", argv[i] ) ) { + + DskAbsPath( tempdir, sizeof(tempdir), instr, stdout ); + printf( "Temp dir: '%s'.\n", tempdir ); + } + else if( GetArgStr( instr, "-cache=", argv[i] ) ) { + + DskAbsPath( cachedir, sizeof(cachedir), instr, stdout ); + printf( "Cache dir: '%s'.\n", cachedir ); + } + else if( GetArgStr( prior, "-prior=", argv[i] ) ) + printf( "Prior solutions: '%s'.\n", prior ); + else if( GetArgStr( mode, "-mode=", argv[i] ) ) + printf( "Mode: '%s'.\n", mode ); + else if( GetArgList( vi, "-zi=", argv[i] ) ) { + + if( 2 == vi.size() ) { + zilo = vi[0]; + zihi = vi[1]; + printf( "zi [%d %d]\n", zilo, zihi ); + } + else { + printf( "Bad format in -zi [%s].\n", argv[i] ); + exit( 42 ); + } + } + else if( GetArgList( vi, "-zo=", argv[i] ) ) { + + if( 2 == vi.size() ) { + zolo = vi[0]; + zohi = vi[1]; + printf( "zo [%d %d]\n", zolo, zohi ); + } + else { + printf( "Bad format in -zo [%s].\n", argv[i] ); + exit( 42 ); + } + } + else if( GetArg( &Wr, "-Wr=T,%lf", argv[i] ) ) { + regtype = 'T'; + printf( "Rglizer Wr: T, %g\n", Wr ); + } + else if( GetArg( &Wr, "-Wr=R,%lf", argv[i] ) ) { + regtype = 'R'; + printf( "Rglizer Wr: R, %g\n", Wr ); + } + else if( GetArg( &Etol, "-Etol=%lf", argv[i] ) ) + printf( "Error tol: %g\n", Etol ); + else if( GetArg( &iters, "-iters=%d", argv[i] ) ) + printf( "Iterations: %d\n", iters ); + else if( GetArg( &splitmin, "-splitmin=%d", argv[i] ) ) + ; + else if( GetArg( &zpernode, "-zpernode=%d", argv[i] ) ) + ; + else if( GetArg( &maxthreads, "-maxthreads=%d", argv[i] ) ) + ; + else if( IsArg( "-catclr", argv[i] ) ) + catclr = true; + else if( IsArg( "-untwist", argv[i] ) ) + untwist = true; + else if( IsArg( "-local", argv[i] ) ) + local = true; + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + exit( 42 ); + } + } // Mode valid? - if( !strcmp( mode, "catalog" ) ) - goto mode_ok; - if( !strcmp( mode, "eval" ) ) { - iters = 0; - goto mode_ok; - } - if( !strcmp( mode, "split" ) ) { - iters = 0; - goto mode_ok; - } - if( !strcmp( mode, "A2A" ) ) - goto mode_ok; - if( !strcmp( mode, "A2H" ) ) - goto mode_ok; - if( !strcmp( mode, "H2H" ) ) - goto mode_ok; - - printf( "Invalid -mode string [%s].\n", mode ); - exit( 42 ); + if( !strcmp( mode, "catalog" ) ) + goto mode_ok; + if( !strcmp( mode, "eval" ) ) { + iters = 0; + goto mode_ok; + } + if( !strcmp( mode, "split" ) ) { + iters = 0; + goto mode_ok; + } + if( !strcmp( mode, "A2A" ) ) + goto mode_ok; + if( !strcmp( mode, "A2H" ) ) + goto mode_ok; + if( !strcmp( mode, "H2H" ) ) + goto mode_ok; + + printf( "Invalid -mode string [%s].\n", mode ); + exit( 42 ); // Default cache folder name mode_ok: - if( !cachedir[0] ) - DskAbsPath( cachedir, sizeof(cachedir), "lsqcache", stdout ); + if( !cachedir[0] ) + DskAbsPath( cachedir, sizeof(cachedir), "lsqcache", stdout ); // Default zo range = zi range - if( zolo == -1 ) { - zolo = zilo; - zohi = zihi; - } + if( zolo == -1 ) { + zolo = zilo; + zohi = zihi; + } // Explicit starting solution needed if {solve stack, eval, split} - if( !strcmp( mode, "catalog" ) ) - ; - else if( zilo != zihi - || !strcmp( mode, "eval" ) - || !strcmp( mode, "split" ) ) { - - if( !prior ) { - printf( "Missing -prior option.\n" ); - exit( 42 ); - } - - if( !DskExists( prior ) ) { - printf( "Priors not found [%s].\n", prior ); - exit( 42 ); - } - } + if( !strcmp( mode, "catalog" ) ) + ; + else if( zilo != zihi + || !strcmp( mode, "eval" ) + || !strcmp( mode, "split" ) ) { + + if( !prior ) { + printf( "Missing -prior option.\n" ); + exit( 42 ); + } + + if( !DskExists( prior ) ) { + printf( "Priors not found [%s].\n", prior ); + exit( 42 ); + } + } } /* --------------------------------------------------------------- */ @@ -241,47 +241,47 @@ void CArgs::SetCmdLine( int argc, char* argv[] ) // Determine dependency range [zolo,zohi]. // static void ZoFromZi( - int &zolo, - int &zohi, - int zilo_icat, - int zihi_icat, - const vector &vL ) + int &zolo, + int &zohi, + int zilo_icat, + int zihi_icat, + const vector &vL ) { - static int maxspan = LayerCat_MaxSpan( vL ); + static int maxspan = LayerCat_MaxSpan( vL ); - int imax; + int imax; // zolo: lowest z that any interior layer touches - zolo = vL[zilo_icat].Lowest(); - imax = min( zilo_icat + maxspan, zihi_icat ); + zolo = vL[zilo_icat].Lowest(); + imax = min( zilo_icat + maxspan, zihi_icat ); - for( int icat = imax; icat > zilo_icat; --icat ) { + for( int icat = imax; icat > zilo_icat; --icat ) { - int z = vL[icat].Lowest(); + int z = vL[icat].Lowest(); - if( z < zolo ) - zolo = z; - } + if( z < zolo ) + zolo = z; + } // zohi: highest z that touches interior - int zihi = vL[zihi_icat].z; + int zihi = vL[zihi_icat].z; - imax = min( zihi_icat + maxspan, vL.size() - 1 ); + imax = min( zihi_icat + maxspan, vL.size() - 1 ); - for( int icat = imax; icat > zihi_icat; --icat ) { + for( int icat = imax; icat > zihi_icat; --icat ) { - if( vL[icat].Lowest() <= zihi ) { + if( vL[icat].Lowest() <= zihi ) { - zohi = vL[icat].z; - return; - } - } + zohi = vL[icat].z; + return; + } + } // Default - zohi = zihi; + zohi = zihi; } /* --------------------------------------------------------------- */ @@ -290,134 +290,134 @@ static void ZoFromZi( void CArgs::LaunchWorkers( const vector &vL ) { - printf( "\n---- Launching workers ----\n" ); + printf( "\n---- Launching workers ----\n" ); // How many workers? - int nL = vL.size(), - nwks = nL / zpernode; + int nL = vL.size(), + nwks = nL / zpernode; - if( nL - nwks * zpernode > 0 ) - ++nwks; + if( nL - nwks * zpernode > 0 ) + ++nwks; // Rebalance the load. - if( nwks > 1 ) { + if( nwks > 1 ) { - int zper = nL / nwks; + int zper = nL / nwks; - if( nL - nwks * zper > 0 ) - ++zper; + if( nL - nwks * zper > 0 ) + ++zper; - zpernode = zper; - } + zpernode = zper; + } - printf( "Workers %d, z-per-node %d.\n", nwks, zpernode ); + printf( "Workers %d, z-per-node %d.\n", nwks, zpernode ); // Launch the appropriate worker set. - char buf[2048]; - - if( nwks <= 1 ) { - - // 1 worker - - if( local || maxthreads <= 1 ) { // pass flow in-process - - if( maxthreads < 1 ) - maxthreads = 1; - - sprintf( buf, - "lsqw -nwks=%d -temp=%s" - " -cache=%s -prior=%s" - " -mode=%s -Wr=%c,%g -Etol=%g -iters=%d" - " -splitmin=%d -maxthreads=%d" - " -zi=%d,%d -zo=%d,%d" - "%s", - nwks, tempdir, - cachedir, (prior ? prior : ""), - mode, regtype, Wr, Etol, iters, - splitmin, maxthreads, - zilo, zihi, zolo, zohi, - (untwist ? " -untwist" : "") ); - } - else { // qsub for desired slots - - sprintf( buf, - "QSUB_1NODE.sht 8 \"lsqw\" \"\" %d" - " \"lsqw -nwks=%d -temp=%s" - " -cache=%s -prior=%s" - " -mode=%s -Wr=%c,%g -Etol=%g -iters=%d" - " -splitmin=%d -maxthreads=%d" - " -zi=%d,%d -zo=%d,%d" - "%s\"", - maxthreads, - nwks, tempdir, - cachedir, (prior ? prior : ""), - mode, regtype, Wr, Etol, iters, - splitmin, maxthreads, - zilo, zihi, zolo, zohi, - (untwist ? " -untwist" : "") ); - } - } - else { - - // Write 'ranges.txt' telling each worker which - // layers it's responsible for and which it needs. - - FILE *f = FileOpenOrDie( "ranges.txt", "w" ); - int zilo_icat = 0, - zihi_icat = min( zpernode, nL ) - 1; - - for( int iw = 0; iw < nwks; ++iw ) { - - ZoFromZi( zolo, zohi, zilo_icat, zihi_icat, vL ); - - fprintf( f, "%d zi=%d,%d zo=%d,%d\n", - iw, vL[zilo_icat].z, vL[zihi_icat].z, zolo, zohi ); - - zilo_icat = zihi_icat + 1; - zihi_icat = min( zilo_icat + zpernode, nL ) - 1; - } - - fclose( f ); - - // Write script 'mpigo.sht' to: - // (1) clean up host list 'sge.txt' --> 'hosts.txt'. - // (2) call mpirun using 'hosts.txt' file. - - f = FileOpenOrDie( "mpigo.sht", "w" ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "tail -n +2 sge.txt > hosts.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "mpirun -perhost 1 -n %d -machinefile hosts.txt" - " lsqw -nwks=%d -temp=%s" - " -cache=%s -prior=%s" - " -mode=%s -Wr=%c,%g -Etol=%g -iters=%d" - " -splitmin=%d -maxthreads=%d" - "%s\n", - nwks, - nwks, tempdir, - cachedir, (prior ? prior : ""), - mode, regtype, Wr, Etol, iters, - splitmin, maxthreads, - (untwist ? " -untwist" : "") ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( "mpigo.sht" ); - - // Submit request to run 'mpigo.sht' script - - sprintf( buf, "QSUB_MNODE.sht 1 \"lsqmpi\" \"-o sge.txt\"" - " %d \"./mpigo.sht\"", nwks * maxthreads ); - } - - printf( "Launch <>\n<%s>\n", buf ); - - system( buf ); + char buf[2048]; + + if( nwks <= 1 ) { + + // 1 worker + + if( local || maxthreads <= 1 ) { // pass flow in-process + + if( maxthreads < 1 ) + maxthreads = 1; + + sprintf( buf, + "lsqw -nwks=%d -temp=%s" + " -cache=%s -prior=%s" + " -mode=%s -Wr=%c,%g -Etol=%g -iters=%d" + " -splitmin=%d -maxthreads=%d" + " -zi=%d,%d -zo=%d,%d" + "%s", + nwks, tempdir, + cachedir, (prior ? prior : ""), + mode, regtype, Wr, Etol, iters, + splitmin, maxthreads, + zilo, zihi, zolo, zohi, + (untwist ? " -untwist" : "") ); + } + else { // qsub for desired slots + + sprintf( buf, + "QSUB_1NODE.sht 8 \"lsqw\" \"\" %d" + " \"lsqw -nwks=%d -temp=%s" + " -cache=%s -prior=%s" + " -mode=%s -Wr=%c,%g -Etol=%g -iters=%d" + " -splitmin=%d -maxthreads=%d" + " -zi=%d,%d -zo=%d,%d" + "%s\"", + maxthreads, + nwks, tempdir, + cachedir, (prior ? prior : ""), + mode, regtype, Wr, Etol, iters, + splitmin, maxthreads, + zilo, zihi, zolo, zohi, + (untwist ? " -untwist" : "") ); + } + } + else { + + // Write 'ranges.txt' telling each worker which + // layers it's responsible for and which it needs. + + FILE *f = FileOpenOrDie( "ranges.txt", "w" ); + int zilo_icat = 0, + zihi_icat = min( zpernode, nL ) - 1; + + for( int iw = 0; iw < nwks; ++iw ) { + + ZoFromZi( zolo, zohi, zilo_icat, zihi_icat, vL ); + + fprintf( f, "%d zi=%d,%d zo=%d,%d\n", + iw, vL[zilo_icat].z, vL[zihi_icat].z, zolo, zohi ); + + zilo_icat = zihi_icat + 1; + zihi_icat = min( zilo_icat + zpernode, nL ) - 1; + } + + fclose( f ); + + // Write script 'mpigo.sht' to: + // (1) clean up host list 'sge.txt' --> 'hosts.txt'. + // (2) call mpirun using 'hosts.txt' file. + + f = FileOpenOrDie( "mpigo.sht", "w" ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "tail -n +2 sge.txt > hosts.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "mpirun -perhost 1 -n %d -machinefile hosts.txt" + " lsqw -nwks=%d -temp=%s" + " -cache=%s -prior=%s" + " -mode=%s -Wr=%c,%g -Etol=%g -iters=%d" + " -splitmin=%d -maxthreads=%d" + "%s\n", + nwks, + nwks, tempdir, + cachedir, (prior ? prior : ""), + mode, regtype, Wr, Etol, iters, + splitmin, maxthreads, + (untwist ? " -untwist" : "") ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( "mpigo.sht" ); + + // Submit request to run 'mpigo.sht' script + + sprintf( buf, "QSUB_MNODE.sht 1 \"lsqmpi\" \"-o sge.txt\"" + " %d \"./mpigo.sht\"", nwks * maxthreads ); + } + + printf( "Launch <>\n<%s>\n", buf ); + + system( buf ); } /* --------------------------------------------------------------- */ @@ -426,22 +426,22 @@ void CArgs::LaunchWorkers( const vector &vL ) int main( int argc, char **argv ) { - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); - vector vL; + vector vL; - if( !LayerCat( vL, gArgs.tempdir, gArgs.cachedir, - gArgs.zolo, gArgs.zohi, gArgs.catclr ) ) { + if( !LayerCat( vL, gArgs.tempdir, gArgs.cachedir, + gArgs.zolo, gArgs.zohi, gArgs.catclr ) ) { - exit( 42 ); - } + exit( 42 ); + } - if( strcmp( gArgs.mode, "catalog" ) ) - gArgs.LaunchWorkers( vL ); + if( strcmp( gArgs.mode, "catalog" ) ) + gArgs.LaunchWorkers( vL ); - VMStats( stdout ); + VMStats( stdout ); - return 0; + return 0; } diff --git a/1_LSQi/lsq_Layers.cpp b/1_LSQi/lsq_Layers.cpp index c8dd29d..ffd4439 100644 --- a/1_LSQi/lsq_Layers.cpp +++ b/1_LSQi/lsq_Layers.cpp @@ -26,268 +26,268 @@ static Layer *_L; static void FreeNamelist( struct dirent** &namelist, int n ) { - if( namelist ) { + if( namelist ) { - while( n-- > 0 ) - free( namelist[n] ); + while( n-- > 0 ) + free( namelist[n] ); - free( namelist ); - namelist = NULL; - } + free( namelist ); + namelist = NULL; + } } static int ThmPair( const struct dirent* E ) { - if( E->d_name[0] == 'T' && E->d_name[1] == 'h' ) { + if( E->d_name[0] == 'T' && E->d_name[1] == 'h' ) { - int za, zb; + int za, zb; - if( 2 == sscanf( E->d_name, "ThmPair_%d^%d", &za, &zb ) - && za == _L->z ) { + if( 2 == sscanf( E->d_name, "ThmPair_%d^%d", &za, &zb ) + && za == _L->z ) { - _L->zdown.insert( zb ); - } - } + _L->zdown.insert( zb ); + } + } - return 0; + return 0; } static void ScanThmPairs( const char *subdir ) { - char dir[2048]; - sprintf( dir, "%s/%s", _d, subdir ); + char dir[2048]; + sprintf( dir, "%s/%s", _d, subdir ); - struct dirent **namelist = NULL; + struct dirent **namelist = NULL; - int n = scandir( dir, &namelist, ThmPair, alphasort ); + int n = scandir( dir, &namelist, ThmPair, alphasort ); - FreeNamelist( namelist, n ); + FreeNamelist( namelist, n ); } static int SorD( const struct dirent* E ) { - if( E->d_name[0] == 'S' ) { + if( E->d_name[0] == 'S' ) { - int x, y; - if( 2 == sscanf( E->d_name + 1, "%d_%d", &x, &y ) ) { + int x, y; + if( 2 == sscanf( E->d_name + 1, "%d_%d", &x, &y ) ) { - if( x > _L->sx ) - _L->sx = x; + if( x > _L->sx ) + _L->sx = x; - if( y > _L->sy ) - _L->sy = y; - } - } + if( y > _L->sy ) + _L->sy = y; + } + } - if( E->d_name[0] == 'D' ) { + if( E->d_name[0] == 'D' ) { - int x, y; - if( 2 == sscanf( E->d_name + 1, "%d_%d", &x, &y ) ) { + int x, y; + if( 2 == sscanf( E->d_name + 1, "%d_%d", &x, &y ) ) { - if( x > _L->dx ) - _L->dx = x; + if( x > _L->dx ) + _L->dx = x; - if( y > _L->dy ) - _L->dy = y; + if( y > _L->dy ) + _L->dy = y; - ScanThmPairs( E->d_name ); - } - } + ScanThmPairs( E->d_name ); + } + } - return 0; + return 0; } static bool ScanThisZ( Layer &L, const char *top, int z ) { - char dir[2048]; - sprintf( dir, "%s/%d", top, z ); + char dir[2048]; + sprintf( dir, "%s/%d", top, z ); - _d = dir; - _L = &L; - L.z = z; + _d = dir; + _L = &L; + L.z = z; - struct dirent **namelist = NULL; + struct dirent **namelist = NULL; - int n = scandir( dir, &namelist, SorD, alphasort ); + int n = scandir( dir, &namelist, SorD, alphasort ); - FreeNamelist( namelist, n ); + FreeNamelist( namelist, n ); - return (n >= 0); // ok (no error) + return (n >= 0); // ok (no error) } static void NewCat( - vector &vL, - const char *tempdir, - const char *cachedir, - int zolo, - int zohi ) + vector &vL, + const char *tempdir, + const char *cachedir, + int zolo, + int zohi ) { - DskCreateDir( cachedir, stdout ); + DskCreateDir( cachedir, stdout ); - char buf[2048]; - sprintf( buf, "%s/catalog.txt", cachedir ); - FILE *f = FileOpenOrDie( buf, "w" ); + char buf[2048]; + sprintf( buf, "%s/catalog.txt", cachedir ); + FILE *f = FileOpenOrDie( buf, "w" ); // Query range header - fprintf( f, "zo %d %d\n", zolo, zohi ); + fprintf( f, "zo %d %d\n", zolo, zohi ); - for( int z = zolo; z <= zohi; ++z ) { + for( int z = zolo; z <= zohi; ++z ) { - Layer L; + Layer L; - ScanThisZ( L, tempdir, z ); + ScanThisZ( L, tempdir, z ); - if( L.sx > -1 ) { + if( L.sx > -1 ) { - fprintf( f, "%d S %d %d D %d %d Z %ld :", - z, L.sx, L.sy, L.dx, L.dy, L.zdown.size() ); + fprintf( f, "%d S %d %d D %d %d Z %ld :", + z, L.sx, L.sy, L.dx, L.dy, L.zdown.size() ); - for( set::iterator it = L.zdown.begin(); - it != L.zdown.end(); - ++it ) { + for( set::iterator it = L.zdown.begin(); + it != L.zdown.end(); + ++it ) { - fprintf( f, " %d", *it ); - } + fprintf( f, " %d", *it ); + } - fprintf( f, "\n" ); + fprintf( f, "\n" ); - vL.push_back( L ); - } - } + vL.push_back( L ); + } + } - fclose( f ); + fclose( f ); } static bool LoadCat( - vector &vL, - const char *cachedir, - int zolo, - int zohi ) + vector &vL, + const char *cachedir, + int zolo, + int zohi ) { - char buf[2048]; - sprintf( buf, "%s/catalog.txt", cachedir ); + char buf[2048]; + sprintf( buf, "%s/catalog.txt", cachedir ); - if( !DskExists( buf ) ) - return false; + if( !DskExists( buf ) ) + return false; - FILE *f = FileOpenOrDie( buf, "r" ); - CLineScan LS; + FILE *f = FileOpenOrDie( buf, "r" ); + CLineScan LS; // Is file appropriate range? - if( LS.Get( f ) > 0 ) { + if( LS.Get( f ) > 0 ) { - int lo, hi; + int lo, hi; - if( 2 != sscanf( LS.line, "zo %d %d", &lo, &hi ) ) - goto fail; + if( 2 != sscanf( LS.line, "zo %d %d", &lo, &hi ) ) + goto fail; - if( zolo < lo || zohi > hi ) - goto exit; - } - else - goto fail; + if( zolo < lo || zohi > hi ) + goto exit; + } + else + goto fail; // Read entries - while( LS.Get( f ) > 0 ) { + while( LS.Get( f ) > 0 ) { - Layer L; - int K, k, nz; + Layer L; + int K, k, nz; - if( 1 != sscanf( LS.line, "%d%n", &L.z, &K ) ) - goto fail; + if( 1 != sscanf( LS.line, "%d%n", &L.z, &K ) ) + goto fail; - if( L.z > zohi ) - break; + if( L.z > zohi ) + break; - if( L.z < zolo ) - continue; + if( L.z < zolo ) + continue; - if( 5 != sscanf( LS.line+K, " S %d %d D %d %d Z %d :%n", - &L.sx, &L.sy, &L.dx, &L.dy, &nz, &k ) ) { + if( 5 != sscanf( LS.line+K, " S %d %d D %d %d Z %d :%n", + &L.sx, &L.sy, &L.dx, &L.dy, &nz, &k ) ) { - goto fail; - } + goto fail; + } - while( nz-- > 0 ) { + while( nz-- > 0 ) { - int z; + int z; - K += k; + K += k; - if( 1 != sscanf( LS.line+K, "%d%n", &z, &k ) ) - goto fail; + if( 1 != sscanf( LS.line+K, "%d%n", &z, &k ) ) + goto fail; - L.zdown.insert( z ); - } + L.zdown.insert( z ); + } - vL.push_back( L ); - } + vL.push_back( L ); + } exit: - if( f ) - fclose( f ); + if( f ) + fclose( f ); - return !vL.empty(); + return !vL.empty(); fail: - printf( "Catalog: Remaking due to format error.\n" ); + printf( "Catalog: Remaking due to format error.\n" ); - vL.clear(); + vL.clear(); - if( f ) - fclose( f ); + if( f ) + fclose( f ); - return false; + return false; } bool LayerCat( - vector &vL, - const char *tempdir, - const char *cachedir, - int zolo, - int zohi, - bool catclr ) + vector &vL, + const char *tempdir, + const char *cachedir, + int zolo, + int zohi, + bool catclr ) { - printf( "\n---- Cataloging ----\n" ); + printf( "\n---- Cataloging ----\n" ); - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - if( catclr || !LoadCat( vL, cachedir, zolo, zohi ) ) - NewCat( vL, tempdir, cachedir, zolo, zohi ); + if( catclr || !LoadCat( vL, cachedir, zolo, zohi ) ) + NewCat( vL, tempdir, cachedir, zolo, zohi ); - if( vL.empty() ) { - printf( "Catalog: No catalog data in range.\n" ); - return false; - } + if( vL.empty() ) { + printf( "Catalog: No catalog data in range.\n" ); + return false; + } - StopTiming( stdout, "Catalog", t0 ); + StopTiming( stdout, "Catalog", t0 ); - return true; + return true; } int LayerCat_MaxSpan( const vector& vL ) { - int maxspan = 0, nL = vL.size(); + int maxspan = 0, nL = vL.size(); - for( int i = 0; i < nL; ++i ) { + for( int i = 0; i < nL; ++i ) { - int span = vL[i].z - vL[i].Lowest(); + int span = vL[i].z - vL[i].Lowest(); - if( span > maxspan ) - maxspan = span; - } + if( span > maxspan ) + maxspan = span; + } - return maxspan; + return maxspan; } diff --git a/1_LSQi/lsq_Layers.h b/1_LSQi/lsq_Layers.h index 1c61881..d433f53 100644 --- a/1_LSQi/lsq_Layers.h +++ b/1_LSQi/lsq_Layers.h @@ -14,17 +14,17 @@ using namespace std; class Layer { public: - int z, - sx, sy, - dx, dy; - set zdown; + int z, + sx, sy, + dx, dy; + set zdown; public: - Layer() : sx(-1), sy(-1), dx(-1), dy(-1) {}; + Layer() : sx(-1), sy(-1), dx(-1), dy(-1) {}; - inline int Lowest() const - { - return (zdown.size() ? *zdown.begin() : z); - }; + inline int Lowest() const + { + return (zdown.size() ? *zdown.begin() : z); + }; }; /* --------------------------------------------------------------- */ @@ -32,12 +32,12 @@ class Layer { /* --------------------------------------------------------------- */ bool LayerCat( - vector &vL, - const char *tempdir, - const char *cachedir, - int zolo, - int zohi, - bool catclr ); + vector &vL, + const char *tempdir, + const char *cachedir, + int zolo, + int zohi, + bool catclr ); int LayerCat_MaxSpan( const vector& vL ); diff --git a/1_LSQi/makefile b/1_LSQi/makefile index 5c52004..150f440 100644 --- a/1_LSQi/makefile +++ b/1_LSQi/makefile @@ -16,8 +16,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_LSQw/lsq_Bounds.cpp b/1_LSQw/lsq_Bounds.cpp index 826fc13..43f31da 100644 --- a/1_LSQw/lsq_Bounds.cpp +++ b/1_LSQw/lsq_Bounds.cpp @@ -40,49 +40,49 @@ static int nthr; void* _Bounds( void* ithr ) { - int nb = zihi - zilo + 1; - vector cnr; - Set4Corners( cnr, gW, gH ); + int nb = zihi - zilo + 1; + vector cnr; + Set4Corners( cnr, gW, gH ); // For each box... - for( int ib = (long)ithr; ib < nb; ib += nthr ) { + for( int ib = (long)ithr; ib < nb; ib += nthr ) { - int iz = ib + zilo; - const Rgns& R = vR[iz]; - const vector& x = gX->X[iz]; - DBox& B = vB[ib]; + int iz = ib + zilo; + const Rgns& R = vR[iz]; + const vector& x = gX->X[iz]; + DBox& B = vB[ib]; - B.L = BIGD; - B.R = -BIGD; - B.B = BIGD; - B.T = -BIGD; + B.L = BIGD; + B.R = -BIGD; + B.B = BIGD; + B.T = -BIGD; - // For each rgn... + // For each rgn... - for( int ir = 0; ir < R.nr; ++ir ) { + for( int ir = 0; ir < R.nr; ++ir ) { - if( !FLAG_ISUSED( R.flag[ir] ) ) - continue; + if( !FLAG_ISUSED( R.flag[ir] ) ) + continue; - vector c( 4 ); - memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); + vector c( 4 ); + memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); - if( gX->NE == 6 ) - X_AS_AFF( x, ir ).Transform( c ); - else - X_AS_HMY( x, ir ).Transform( c ); + if( gX->NE == 6 ) + X_AS_AFF( x, ir ).Transform( c ); + else + X_AS_HMY( x, ir ).Transform( c ); - for( int k = 0; k < 4; ++k ) { - B.L = fmin( B.L, c[k].x ); - B.R = fmax( B.R, c[k].x ); - B.B = fmin( B.B, c[k].y ); - B.T = fmax( B.T, c[k].y ); - } - } - } + for( int k = 0; k < 4; ++k ) { + B.L = fmin( B.L, c[k].x ); + B.R = fmax( B.R, c[k].x ); + B.B = fmin( B.B, c[k].y ); + B.T = fmax( B.T, c[k].y ); + } + } + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -95,19 +95,19 @@ void* _Bounds( void* ithr ) // static void CalcLayerwiseBoxes( const XArray &X ) { - gX = &X; + gX = &X; - int nb = zihi - zilo + 1; + int nb = zihi - zilo + 1; - vB.resize( nb ); + vB.resize( nb ); - nthr = maxthreads; + nthr = maxthreads; - if( nthr > nb ) - nthr = nb; + if( nthr > nb ) + nthr = nb; - if( !EZThreads( _Bounds, nthr, 1, "_Bounds" ) ) - exit( 42 ); + if( !EZThreads( _Bounds, nthr, 1, "_Bounds" ) ) + exit( 42 ); } /* --------------------------------------------------------------- */ @@ -118,41 +118,41 @@ static void GlobalBounds( DBox &B ) { // Calc my local overall box - int nb = zihi - zilo + 1; + int nb = zihi - zilo + 1; - B = vB[0]; + B = vB[0]; - for( int ib = 1; ib < nb; ++ib ) { + for( int ib = 1; ib < nb; ++ib ) { - const DBox& b = vB[ib]; + const DBox& b = vB[ib]; - B.L = fmin( B.L, b.L ); - B.R = fmax( B.R, b.R ); - B.B = fmin( B.B, b.B ); - B.T = fmax( B.T, b.T ); - } + B.L = fmin( B.L, b.L ); + B.R = fmax( B.R, b.R ); + B.B = fmin( B.B, b.B ); + B.T = fmax( B.T, b.T ); + } // Send my box to master; then get global box from master - if( wkid > 0 ) { - MPISend( &B, sizeof(DBox), 0, wkid ); - MPIRecv( &B, sizeof(DBox), 0, wkid ); - } - else if( nwks > 1 ) { - - for( int iw = 1; iw < nwks; ++iw ) { - - DBox b; - MPIRecv( &b, sizeof(DBox), iw, iw ); - B.L = fmin( B.L, b.L ); - B.R = fmax( B.R, b.R ); - B.B = fmin( B.B, b.B ); - B.T = fmax( B.T, b.T ); - } - - for( int iw = 1; iw < nwks; ++iw ) - MPISend( &B, sizeof(DBox), iw, iw ); - } + if( wkid > 0 ) { + MPISend( &B, sizeof(DBox), 0, wkid ); + MPIRecv( &B, sizeof(DBox), 0, wkid ); + } + else if( nwks > 1 ) { + + for( int iw = 1; iw < nwks; ++iw ) { + + DBox b; + MPIRecv( &b, sizeof(DBox), iw, iw ); + B.L = fmin( B.L, b.L ); + B.R = fmax( B.R, b.R ); + B.B = fmin( B.B, b.B ); + B.T = fmax( B.T, b.T ); + } + + for( int iw = 1; iw < nwks; ++iw ) + MPISend( &B, sizeof(DBox), iw, iw ); + } } /* --------------------------------------------------------------- */ @@ -161,36 +161,36 @@ static void GlobalBounds( DBox &B ) void* _Apply( void* ithr ) { - double xorg = -vB[0].L, - yorg = -vB[0].B; - int nL = zohi - zolo + 1; - THmgphy M( 1,0,xorg, 0,1,yorg, 0,0 ); + double xorg = -vB[0].L, + yorg = -vB[0].B; + int nL = zohi - zolo + 1; + THmgphy M( 1,0,xorg, 0,1,yorg, 0,0 ); // For each layer... - for( int iL = (long)ithr; iL < nL; iL += nthr ) { + for( int iL = (long)ithr; iL < nL; iL += nthr ) { - int iz = iL + zolo; - const Rgns& R = vR[iz]; - const vector& x = gX->X[iz]; + int iz = iL + zolo; + const Rgns& R = vR[iz]; + const vector& x = gX->X[iz]; - // For each rgn... + // For each rgn... - for( int ir = 0; ir < R.nr; ++ir ) { + for( int ir = 0; ir < R.nr; ++ir ) { - if( !FLAG_ISUSED( R.flag[ir] ) ) - continue; + if( !FLAG_ISUSED( R.flag[ir] ) ) + continue; - if( gX->NE == 6 ) - X_AS_AFF( x, ir ).AddXY( xorg, yorg ); - else { - THmgphy& T = X_AS_HMY( x, ir ); - T = M * T; - } - } - } + if( gX->NE == 6 ) + X_AS_AFF( x, ir ).AddXY( xorg, yorg ); + else { + THmgphy& T = X_AS_HMY( x, ir ); + T = M * T; + } + } + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -199,15 +199,15 @@ void* _Apply( void* ithr ) static void Apply() { - int nb = zohi - zolo + 1; + int nb = zohi - zolo + 1; - nthr = maxthreads; + nthr = maxthreads; - if( nthr > nb ) - nthr = nb; + if( nthr > nb ) + nthr = nb; - if( !EZThreads( _Apply, nthr, 1, "_Apply" ) ) - exit( 42 ); + if( !EZThreads( _Apply, nthr, 1, "_Apply" ) ) + exit( 42 ); } /* --------------------------------------------------------------- */ @@ -218,30 +218,30 @@ static void Apply() // void Bounds( DBox &B, const XArray &X ) { - printf( "\n---- Bounds ----\n" ); + printf( "\n---- Bounds ----\n" ); - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - CalcLayerwiseBoxes( X ); - GlobalBounds( B ); + CalcLayerwiseBoxes( X ); + GlobalBounds( B ); // Adjust all transform origins - vB[0] = B; - Apply(); - vB.clear(); + vB[0] = B; + Apply(); + vB.clear(); // Report pretty enclosing bounds - B.R = ceil( B.R - B.L + 1 ); - B.T = ceil( B.T - B.B + 1 ); - B.L = 0; - B.B = 0; + B.R = ceil( B.R - B.L + 1 ); + B.T = ceil( B.T - B.B + 1 ); + B.L = 0; + B.B = 0; - printf( "Global bounds: x=[0 %.2f] y=[0 %.2f].\n", - B.R, B.T ); + printf( "Global bounds: x=[0 %.2f] y=[0 %.2f].\n", + B.R, B.T ); - StopTiming( stdout, "Bounds", t0 ); + StopTiming( stdout, "Bounds", t0 ); } diff --git a/1_LSQw/lsq_Dropout.cpp b/1_LSQw/lsq_Dropout.cpp index 03bea15..1f7f9e9 100644 --- a/1_LSQw/lsq_Dropout.cpp +++ b/1_LSQw/lsq_Dropout.cpp @@ -36,59 +36,59 @@ static int nthr; void* _Scan( void* ithr ) { - int nd = zihi - zilo + 1; + int nd = zihi - zilo + 1; // For each layer... - for( int id = (long)ithr; id < nd; id += nthr ) { - - int iz = id + zilo; - const Rgns& R = vR[iz]; - Dropout& D = vD[id]; - FILE *q = NULL; - - D.rmax += R.nr; - - // For each rgn... - - for( int ir = 0; ir < R.nr; ++ir ) { - - if( R.flag[ir] ) { - - if( !q ) { - DskCreateDir( "Dropouts", stdout ); - char buf[64]; - sprintf( buf, "Dropouts/drop_%d.txt", R.z ); - q = FileOpenOrDie( buf, "w" ); - } - - int z, i, r; - RealZIDR( z, i, r, iz, ir ); - - if( FLAG_ISREAD( R.flag[ir] ) ) { - fprintf( q, "R %d.%d-%d\n", z, i, r ); - ++D.read; - } - else if( FLAG_ISPNTS( R.flag[ir] ) ) { - fprintf( q, "P %d.%d-%d\n", z, i, r ); - ++D.pnts; - } - else if( FLAG_ISKILL( R.flag[ir] ) ) { - fprintf( q, "K %d.%d-%d\n", z, i, r ); - ++D.kill; - } - else if( FLAG_ISCUTD( R.flag[ir] ) ) { - fprintf( q, "C %d.%d-%d\n", z, i, r ); - ++D.cutd; - } - } - } - - if( q ) - fclose( q ); - } - - return NULL; + for( int id = (long)ithr; id < nd; id += nthr ) { + + int iz = id + zilo; + const Rgns& R = vR[iz]; + Dropout& D = vD[id]; + FILE *q = NULL; + + D.rmax += R.nr; + + // For each rgn... + + for( int ir = 0; ir < R.nr; ++ir ) { + + if( R.flag[ir] ) { + + if( !q ) { + DskCreateDir( "Dropouts", stdout ); + char buf[64]; + sprintf( buf, "Dropouts/drop_%d.txt", R.z ); + q = FileOpenOrDie( buf, "w" ); + } + + int z, i, r; + RealZIDR( z, i, r, iz, ir ); + + if( FLAG_ISREAD( R.flag[ir] ) ) { + fprintf( q, "R %d.%d-%d\n", z, i, r ); + ++D.read; + } + else if( FLAG_ISPNTS( R.flag[ir] ) ) { + fprintf( q, "P %d.%d-%d\n", z, i, r ); + ++D.pnts; + } + else if( FLAG_ISKILL( R.flag[ir] ) ) { + fprintf( q, "K %d.%d-%d\n", z, i, r ); + ++D.kill; + } + else if( FLAG_ISCUTD( R.flag[ir] ) ) { + fprintf( q, "C %d.%d-%d\n", z, i, r ); + ++D.cutd; + } + } + } + + if( q ) + fclose( q ); + } + + return NULL; } /* --------------------------------------------------------------- */ @@ -97,17 +97,17 @@ void* _Scan( void* ithr ) static void ScanEachLayer() { - int nd = zihi - zilo + 1; + int nd = zihi - zilo + 1; - vD.resize( nd ); + vD.resize( nd ); - nthr = maxthreads; + nthr = maxthreads; - if( nthr > nd ) - nthr = nd; + if( nthr > nd ) + nthr = nd; - if( !EZThreads( _Scan, nthr, 1, "_ScanEachLayer" ) ) - exit( 42 ); + if( !EZThreads( _Scan, nthr, 1, "_ScanEachLayer" ) ) + exit( 42 ); } /* --------------------------------------------------------------- */ @@ -116,47 +116,47 @@ static void ScanEachLayer() void Dropout::GatherCounts() { - int nd = zihi - zilo + 1; - - for( int id = 0; id < nd; ++id ) - Add( vD[id] ); - - if( nwks > 1 ) { - printf( - "Worker %03d: MAX %9ld READ %9ld" - " PNTS %9ld KILL %9ld CUTD %9ld\n", - wkid, rmax, read, pnts, kill, cutd ); - } - else { - printf( - "All workers: MAX %9ld READ %9ld" - " PNTS %9ld KILL %9ld CUTD %9ld\n", - rmax, read, pnts, kill, cutd ); - } - - if( wkid > 0 ) - MPISend( this, sizeof(Dropout), 0, wkid ); - else if( nwks > 1 ) { - - for( int iw = 1; iw < nwks; ++iw ) { - - Dropout D; - MPIRecv( &D, sizeof(Dropout), iw, iw ); - Add( D ); - - printf( - "Worker %03d: MAX %9ld READ %9ld" - " PNTS %9ld KILL %9ld CUTD %9ld\n", - iw, D.rmax, D.read, D.pnts, D.kill, D.cutd ); - } - - printf( - "--------------------------------------------" - "-------------------------------------------\n" - " Total: MAX %9ld READ %9ld" - " PNTS %9ld KILL %9ld CUTD %9ld\n\n", - rmax, read, pnts, kill, cutd ); - } + int nd = zihi - zilo + 1; + + for( int id = 0; id < nd; ++id ) + Add( vD[id] ); + + if( nwks > 1 ) { + printf( + "Worker %03d: MAX %9ld READ %9ld" + " PNTS %9ld KILL %9ld CUTD %9ld\n", + wkid, rmax, read, pnts, kill, cutd ); + } + else { + printf( + "All workers: MAX %9ld READ %9ld" + " PNTS %9ld KILL %9ld CUTD %9ld\n", + rmax, read, pnts, kill, cutd ); + } + + if( wkid > 0 ) + MPISend( this, sizeof(Dropout), 0, wkid ); + else if( nwks > 1 ) { + + for( int iw = 1; iw < nwks; ++iw ) { + + Dropout D; + MPIRecv( &D, sizeof(Dropout), iw, iw ); + Add( D ); + + printf( + "Worker %03d: MAX %9ld READ %9ld" + " PNTS %9ld KILL %9ld CUTD %9ld\n", + iw, D.rmax, D.read, D.pnts, D.kill, D.cutd ); + } + + printf( + "--------------------------------------------" + "-------------------------------------------\n" + " Total: MAX %9ld READ %9ld" + " PNTS %9ld KILL %9ld CUTD %9ld\n\n", + rmax, read, pnts, kill, cutd ); + } } /* --------------------------------------------------------------- */ @@ -165,15 +165,15 @@ void Dropout::GatherCounts() void Dropout::Scan() { - printf( "\n---- Dropouts ----\n" ); + printf( "\n---- Dropouts ----\n" ); - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - ScanEachLayer(); - GatherCounts(); - vD.clear(); + ScanEachLayer(); + GatherCounts(); + vD.clear(); - StopTiming( stdout, "Drops ", t0 ); + StopTiming( stdout, "Drops ", t0 ); } diff --git a/1_LSQw/lsq_Dropout.h b/1_LSQw/lsq_Dropout.h index 56f5c91..9a452a7 100644 --- a/1_LSQw/lsq_Dropout.h +++ b/1_LSQw/lsq_Dropout.h @@ -9,20 +9,20 @@ class Dropout { public: - long rmax, read, pnts, kill, cutd; + long rmax, read, pnts, kill, cutd; private: - void Add( const Dropout& rhs ) - { - rmax += rhs.rmax; - read += rhs.read; - pnts += rhs.pnts; - kill += rhs.kill; - cutd += rhs.cutd; - }; - void GatherCounts(); + void Add( const Dropout& rhs ) + { + rmax += rhs.rmax; + read += rhs.read; + pnts += rhs.pnts; + kill += rhs.kill; + cutd += rhs.cutd; + }; + void GatherCounts(); public: - Dropout() : rmax(0), read(0), pnts(0), kill(0), cutd(0) {}; - void Scan(); + Dropout() : rmax(0), read(0), pnts(0), kill(0), cutd(0) {}; + void Scan(); }; diff --git a/1_LSQw/lsq_Error.cpp b/1_LSQw/lsq_Error.cpp index 8607fbb..4e915e8 100644 --- a/1_LSQw/lsq_Error.cpp +++ b/1_LSQw/lsq_Error.cpp @@ -33,99 +33,99 @@ namespace error { class FileErr { // Buffered file writing private: - static const int bufsize = 2048; - FILE* f; - vector ve; - int n; + static const int bufsize = 2048; + FILE* f; + vector ve; + int n; public: - FileErr( int SorD, int z ); - virtual ~FileErr(); - void Add( double err ); + FileErr( int SorD, int z ); + virtual ~FileErr(); + void Add( double err ); }; class EI { // Error and point using local indexing public: - double e; - int i; // index into vC[] + double e; + int i; // index into vC[] public: - EI() : e(-1), i(-1) {}; + EI() : e(-1), i(-1) {}; - bool operator < ( const EI &rhs ) const - {return e > rhs.e;}; + bool operator < ( const EI &rhs ) const + {return e > rhs.e;}; }; class EG { // Error and point using global indexing public: - double e; - int z1, i1, r1, // global idb values - z2, i2, r2; + double e; + int z1, i1, r1, // global idb values + z2, i2, r2; public: - EG() : e(-1) {}; + EG() : e(-1) {}; - void FromEI( const EI &rhs ); + void FromEI( const EI &rhs ); - bool operator < ( const EG &rhs ) const - {return e > rhs.e;}; + bool operator < ( const EG &rhs ) const + {return e > rhs.e;}; }; class Stat { // statistics summaries using local point indexing private: - vector::iterator eis0, eid0; + vector::iterator eis0, eid0; public: - vector eis, eid; // topn - double sms, smd; // sum - int ns, nd; // count - EI cur; // current + vector eis, eid; // topn + double sms, smd; // sum + int ns, nd; // count + EI cur; // current public: - // accumulate layerwise data - void Init(); - void AddS(); - void AddD(); - - // combine - void Init_Smy( const Stat &rhs ); - void Add_Smy( const Stat &rhs ); - void SmyMyLayers(); - void Total( const Stat &rhs ); - - // report - double RMSS() const {return (ns ? sqrt( sms/ns ) : -1);}; - double RMSD() const {return (nd ? sqrt( smd/nd ) : -1);}; - void Topn( FILE *f, int SorD ) const; + // accumulate layerwise data + void Init(); + void AddS(); + void AddD(); + + // combine + void Init_Smy( const Stat &rhs ); + void Add_Smy( const Stat &rhs ); + void SmyMyLayers(); + void Total( const Stat &rhs ); + + // report + double RMSS() const {return (ns ? sqrt( sms/ns ) : -1);}; + double RMSD() const {return (nd ? sqrt( smd/nd ) : -1);}; + void Topn( FILE *f, int SorD ) const; }; class StatG { // Stat type using cross-worker global indexing private: - typedef struct { - double sms, smd; - int ns, nd; - EG egs[TOPN], - egd[TOPN]; - } MPIBUF; + typedef struct { + double sms, smd; + int ns, nd; + EG egs[TOPN], + egd[TOPN]; + } MPIBUF; private: - vector::iterator egs0, egd0; + vector::iterator egs0, egd0; public: - vector egs, egd; // topn - double sms, smd; // sum - int ns, nd; // count + vector egs, egd; // topn + double sms, smd; // sum + int ns, nd; // count public: - // Scatter, gather - void FromStat( const Stat &rhs ); - void Send(); - void Recv( int iw ); - void Add( const StatG &rhs ); - - // combine - void Total( const StatG &rhs ); - - // report - double RMSS() const {return (ns ? sqrt( sms/ns ) : -1);}; - double RMSD() const {return (nd ? sqrt( smd/nd ) : -1);}; - void Topn( FILE *f, int SorD ) const; + // Scatter, gather + void FromStat( const Stat &rhs ); + void Send(); + void Recv( int iw ); + void Add( const StatG &rhs ); + + // combine + void Total( const StatG &rhs ); + + // report + double RMSS() const {return (ns ? sqrt( sms/ns ) : -1);}; + double RMSD() const {return (nd ? sqrt( smd/nd ) : -1);}; + void Topn( FILE *f, int SorD ) const; }; } // namespace error @@ -139,8 +139,8 @@ using namespace error; static const XArray *gX; static vector vS; static double Etol, - fnlrms = -1, - fnlmax = -1; + fnlrms = -1, + fnlmax = -1; static int nthr; @@ -154,14 +154,14 @@ static int nthr; FileErr::FileErr( int SorD, int z ) : f(NULL), n(0) { - if( SorD == 'S' || zolo != zohi ) { + if( SorD == 'S' || zolo != zohi ) { - char buf[32]; - sprintf( buf, "Error/Err_%c_%d.bin", SorD, z ); - f = FileOpenOrDie( buf, "wb" ); + char buf[32]; + sprintf( buf, "Error/Err_%c_%d.bin", SorD, z ); + f = FileOpenOrDie( buf, "wb" ); - ve.resize( bufsize ); - } + ve.resize( bufsize ); + } } /* --------------------------------------------------------------- */ @@ -170,13 +170,13 @@ FileErr::FileErr( int SorD, int z ) : f(NULL), n(0) FileErr::~FileErr() { - if( f ) { + if( f ) { - if( n ) - fwrite( &ve[0], sizeof(float), n, f ); + if( n ) + fwrite( &ve[0], sizeof(float), n, f ); - fclose( f ); - } + fclose( f ); + } } /* --------------------------------------------------------------- */ @@ -185,12 +185,12 @@ FileErr::~FileErr() void FileErr::Add( double err ) { - ve[n++] = (float)sqrt( err ); + ve[n++] = (float)sqrt( err ); - if( n >= bufsize ) { - fwrite( &ve[0], sizeof(float), n, f ); - n = 0; - } + if( n >= bufsize ) { + fwrite( &ve[0], sizeof(float), n, f ); + n = 0; + } } /* --------------------------------------------------------------- */ @@ -199,12 +199,12 @@ void FileErr::Add( double err ) void EG::FromEI( const EI &rhs ) { - const CorrPnt& C = vC[rhs.i]; + const CorrPnt& C = vC[rhs.i]; - if( (e = rhs.e) > -1 ) { - RealZIDR( z1, i1, r1, C.z1, C.i1 ); - RealZIDR( z2, i2, r2, C.z2, C.i2 ); - } + if( (e = rhs.e) > -1 ) { + RealZIDR( z1, i1, r1, C.z1, C.i1 ); + RealZIDR( z2, i2, r2, C.z2, C.i2 ); + } } /* --------------------------------------------------------------- */ @@ -213,17 +213,17 @@ void EG::FromEI( const EI &rhs ) void Stat::Init() { - eis.resize( TOPN ); - eis0 = eis.begin(); - sms = 0.0; - ns = 0; - - if( zolo != zohi ) { - eid.resize( TOPN ); - eid0 = eid.begin(); - smd = 0.0; - nd = 0; - } + eis.resize( TOPN ); + eis0 = eis.begin(); + sms = 0.0; + ns = 0; + + if( zolo != zohi ) { + eid.resize( TOPN ); + eid0 = eid.begin(); + smd = 0.0; + nd = 0; + } } /* --------------------------------------------------------------- */ @@ -232,15 +232,15 @@ void Stat::Init() void Stat::AddS() { - EI& ei = eis[TOPL]; + EI& ei = eis[TOPL]; - sms += cur.e; - ++ns; + sms += cur.e; + ++ns; - if( cur.e > ei.e ) { - ei = cur; - sort( eis0, eis0 + TOPN ); - } + if( cur.e > ei.e ) { + ei = cur; + sort( eis0, eis0 + TOPN ); + } } /* --------------------------------------------------------------- */ @@ -249,15 +249,15 @@ void Stat::AddS() void Stat::AddD() { - EI& ei = eid[TOPL]; + EI& ei = eid[TOPL]; - smd += cur.e; - ++nd; + smd += cur.e; + ++nd; - if( cur.e > ei.e ) { - ei = cur; - sort( eid0, eid0 + TOPN ); - } + if( cur.e > ei.e ) { + ei = cur; + sort( eid0, eid0 + TOPN ); + } } /* --------------------------------------------------------------- */ @@ -268,19 +268,19 @@ void Stat::AddD() // void Stat::Init_Smy( const Stat &rhs ) { - eis.resize( 2*TOPN ); - eis0 = eis.begin(); - memcpy( &eis[0], &rhs.eis[0], TOPN * sizeof(EI) ); - sms = rhs.sms; - ns = rhs.ns; - - if( zolo != zohi ) { - eid.resize( 2*TOPN ); - eid0 = eid.begin(); - memcpy( &eid[0], &rhs.eid[0], TOPN * sizeof(EI) ); - smd = rhs.smd; - nd = rhs.nd; - } + eis.resize( 2*TOPN ); + eis0 = eis.begin(); + memcpy( &eis[0], &rhs.eis[0], TOPN * sizeof(EI) ); + sms = rhs.sms; + ns = rhs.ns; + + if( zolo != zohi ) { + eid.resize( 2*TOPN ); + eid0 = eid.begin(); + memcpy( &eid[0], &rhs.eid[0], TOPN * sizeof(EI) ); + smd = rhs.smd; + nd = rhs.nd; + } } /* --------------------------------------------------------------- */ @@ -289,20 +289,20 @@ void Stat::Init_Smy( const Stat &rhs ) void Stat::Add_Smy( const Stat &rhs ) { - sms += rhs.sms; - ns += rhs.ns; + sms += rhs.sms; + ns += rhs.ns; - memcpy( &eis[TOPN], &rhs.eis[0], TOPN * sizeof(EI) ); - sort( eis0, eis0 + 2*TOPN ); + memcpy( &eis[TOPN], &rhs.eis[0], TOPN * sizeof(EI) ); + sort( eis0, eis0 + 2*TOPN ); - if( zolo != zohi ) { + if( zolo != zohi ) { - smd += rhs.smd; - nd += rhs.nd; + smd += rhs.smd; + nd += rhs.nd; - memcpy( &eid[TOPN], &rhs.eid[0], TOPN * sizeof(EI) ); - sort( eid0, eid0 + 2*TOPN ); - } + memcpy( &eid[TOPN], &rhs.eid[0], TOPN * sizeof(EI) ); + sort( eid0, eid0 + 2*TOPN ); + } } /* --------------------------------------------------------------- */ @@ -311,12 +311,12 @@ void Stat::Add_Smy( const Stat &rhs ) void Stat::SmyMyLayers() { - int nL = zihi - zilo + 1; + int nL = zihi - zilo + 1; - Init_Smy( vS[0] ); + Init_Smy( vS[0] ); - for( int iL = 1; iL < nL; ++iL ) - Add_Smy( vS[iL] ); + for( int iL = 1; iL < nL; ++iL ) + Add_Smy( vS[iL] ); } /* --------------------------------------------------------------- */ @@ -327,14 +327,14 @@ void Stat::SmyMyLayers() // void Stat::Total( const Stat &rhs ) { - eis.resize( 2*TOPN ); - eis0 = eis.begin(); - sms = rhs.sms + rhs.smd; - ns = rhs.ns + rhs.nd; - - memcpy( &eis[0], &rhs.eis[0], TOPN * sizeof(EI) ); - memcpy( &eis[TOPN], &rhs.eid[0], TOPN * sizeof(EI) ); - sort( eis0, eis0 + 2*TOPN ); + eis.resize( 2*TOPN ); + eis0 = eis.begin(); + sms = rhs.sms + rhs.smd; + ns = rhs.ns + rhs.nd; + + memcpy( &eis[0], &rhs.eis[0], TOPN * sizeof(EI) ); + memcpy( &eis[TOPN], &rhs.eid[0], TOPN * sizeof(EI) ); + sort( eis0, eis0 + 2*TOPN ); } /* --------------------------------------------------------------- */ @@ -345,40 +345,40 @@ void Stat::Topn( FILE *f, int SorD ) const { // print the errors... - const vector& vei = (SorD == 'S' ? eis : eid); - int ne = 0; + const vector& vei = (SorD == 'S' ? eis : eid); + int ne = 0; - for( int i = 0; i < TOPN; ++i ) { + for( int i = 0; i < TOPN; ++i ) { - double e = vei[i].e; + double e = vei[i].e; - if( e > -1 ) { - fprintf( f, "\t%.2f", sqrt( e ) ); - ++ne; - } - } + if( e > -1 ) { + fprintf( f, "\t%.2f", sqrt( e ) ); + ++ne; + } + } // ...and their labels - if( ne ) { + if( ne ) { - for( int i = 0; i < ne; ++i ) { + for( int i = 0; i < ne; ++i ) { - const CorrPnt& C = vC[vei[i].i]; - int z1, i1, r1, - z2, i2, r2; + const CorrPnt& C = vC[vei[i].i]; + int z1, i1, r1, + z2, i2, r2; - RealZIDR( z1, i1, r1, C.z1, C.i1 ); - RealZIDR( z2, i2, r2, C.z2, C.i2 ); + RealZIDR( z1, i1, r1, C.z1, C.i1 ); + RealZIDR( z2, i2, r2, C.z2, C.i2 ); - fprintf( f, "\t%d.%d-%d^%d.%d-%d", - z1, i1, r1, z2, i2, r2 ); - } - } - else - fprintf( f, "-1\n" ); + fprintf( f, "\t%d.%d-%d^%d.%d-%d", + z1, i1, r1, z2, i2, r2 ); + } + } + else + fprintf( f, "-1\n" ); - fprintf( f, "\n" ); + fprintf( f, "\n" ); } /* --------------------------------------------------------------- */ @@ -387,25 +387,25 @@ void Stat::Topn( FILE *f, int SorD ) const void StatG::FromStat( const Stat &rhs ) { - egs.resize( 2*TOPN ); - egs0 = egs.begin(); - sms = rhs.sms; - ns = rhs.ns; + egs.resize( 2*TOPN ); + egs0 = egs.begin(); + sms = rhs.sms; + ns = rhs.ns; - for( int i = 0; i < TOPN; ++i ) - egs[i].FromEI( rhs.eis[i] ); + for( int i = 0; i < TOPN; ++i ) + egs[i].FromEI( rhs.eis[i] ); - egd.resize( 2*TOPN ); - smd = rhs.smd; - nd = rhs.nd; + egd.resize( 2*TOPN ); + smd = rhs.smd; + nd = rhs.nd; - if( zolo != zohi ) { + if( zolo != zohi ) { - egd0 = egd.begin(); + egd0 = egd.begin(); - for( int i = 0; i < TOPN; ++i ) - egd[i].FromEI( rhs.eid[i] ); - } + for( int i = 0; i < TOPN; ++i ) + egd[i].FromEI( rhs.eid[i] ); + } } /* --------------------------------------------------------------- */ @@ -414,16 +414,16 @@ void StatG::FromStat( const Stat &rhs ) void StatG::Send() { - MPIBUF B; + MPIBUF B; - B.sms = sms; - B.smd = smd; - B.ns = ns; - B.nd = nd; - memcpy( B.egs, &egs[0], TOPN * sizeof(EG) ); - memcpy( B.egd, &egd[0], TOPN * sizeof(EG) ); + B.sms = sms; + B.smd = smd; + B.ns = ns; + B.nd = nd; + memcpy( B.egs, &egs[0], TOPN * sizeof(EG) ); + memcpy( B.egd, &egd[0], TOPN * sizeof(EG) ); - MPISend( &B, sizeof(MPIBUF), 0, wkid ); + MPISend( &B, sizeof(MPIBUF), 0, wkid ); } /* --------------------------------------------------------------- */ @@ -432,21 +432,21 @@ void StatG::Send() void StatG::Recv( int iw ) { - MPIBUF B; - MPIRecv( &B, sizeof(MPIBUF), iw, iw ); + MPIBUF B; + MPIRecv( &B, sizeof(MPIBUF), iw, iw ); - egs.resize( 2*TOPN ); - egs0 = egs.begin(); + egs.resize( 2*TOPN ); + egs0 = egs.begin(); - egd.resize( 2*TOPN ); - egd0 = egd.begin(); + egd.resize( 2*TOPN ); + egd0 = egd.begin(); - sms = B.sms; - smd = B.smd; - ns = B.ns; - nd = B.nd; - memcpy( &egs[0], B.egs, TOPN * sizeof(EG) ); - memcpy( &egd[0], B.egd, TOPN * sizeof(EG) ); + sms = B.sms; + smd = B.smd; + ns = B.ns; + nd = B.nd; + memcpy( &egs[0], B.egs, TOPN * sizeof(EG) ); + memcpy( &egd[0], B.egd, TOPN * sizeof(EG) ); } /* --------------------------------------------------------------- */ @@ -455,20 +455,20 @@ void StatG::Recv( int iw ) void StatG::Add( const StatG &rhs ) { - sms += rhs.sms; - ns += rhs.ns; + sms += rhs.sms; + ns += rhs.ns; - memcpy( &egs[TOPN], &rhs.egs[0], TOPN * sizeof(EG) ); - sort( egs0, egs0 + 2*TOPN ); + memcpy( &egs[TOPN], &rhs.egs[0], TOPN * sizeof(EG) ); + sort( egs0, egs0 + 2*TOPN ); - if( zolo != zohi ) { + if( zolo != zohi ) { - smd += rhs.smd; - nd += rhs.nd; + smd += rhs.smd; + nd += rhs.nd; - memcpy( &egd[TOPN], &rhs.egd[0], TOPN * sizeof(EG) ); - sort( egd0, egd0 + 2*TOPN ); - } + memcpy( &egd[TOPN], &rhs.egd[0], TOPN * sizeof(EG) ); + sort( egd0, egd0 + 2*TOPN ); + } } /* --------------------------------------------------------------- */ @@ -479,14 +479,14 @@ void StatG::Add( const StatG &rhs ) // void StatG::Total( const StatG &rhs ) { - egs.resize( 2*TOPN ); - egs0 = egs.begin(); - sms = rhs.sms + rhs.smd; - ns = rhs.ns + rhs.nd; - - memcpy( &egs[0], &rhs.egs[0], TOPN * sizeof(EG) ); - memcpy( &egs[TOPN], &rhs.egd[0], TOPN * sizeof(EG) ); - sort( egs0, egs0 + 2*TOPN ); + egs.resize( 2*TOPN ); + egs0 = egs.begin(); + sms = rhs.sms + rhs.smd; + ns = rhs.ns + rhs.nd; + + memcpy( &egs[0], &rhs.egs[0], TOPN * sizeof(EG) ); + memcpy( &egs[TOPN], &rhs.egd[0], TOPN * sizeof(EG) ); + sort( egs0, egs0 + 2*TOPN ); } /* --------------------------------------------------------------- */ @@ -497,35 +497,35 @@ void StatG::Topn( FILE *f, int SorD ) const { // print the errors... - const vector& veg = (SorD == 'S' ? egs : egd); - int ne = 0; + const vector& veg = (SorD == 'S' ? egs : egd); + int ne = 0; - for( int i = 0; i < TOPN; ++i ) { + for( int i = 0; i < TOPN; ++i ) { - double e = veg[i].e; + double e = veg[i].e; - if( e > -1 ) { - fprintf( f, "\t%.2f", sqrt( e ) ); - ++ne; - } - } + if( e > -1 ) { + fprintf( f, "\t%.2f", sqrt( e ) ); + ++ne; + } + } // ...and their labels - if( ne ) { + if( ne ) { - for( int i = 0; i < ne; ++i ) { + for( int i = 0; i < ne; ++i ) { - const EG& G = veg[i]; + const EG& G = veg[i]; - fprintf( f, "\t%d.%d-%d^%d.%d-%d", - G.z1, G.i1, G.r1, G.z2, G.i2, G.r2 ); - } - } - else - fprintf( f, "-1\n" ); + fprintf( f, "\t%d.%d-%d^%d.%d-%d", + G.z1, G.i1, G.r1, G.z2, G.i2, G.r2 ); + } + } + else + fprintf( f, "-1\n" ); - fprintf( f, "\n" ); + fprintf( f, "\n" ); } /* --------------------------------------------------------------- */ @@ -534,118 +534,118 @@ void StatG::Topn( FILE *f, int SorD ) const void* _ErrorA( void* ithr ) { - int ns = zihi - zilo + 1; + int ns = zihi - zilo + 1; // For each layer... - for( int is = (long)ithr; is < ns; is += nthr ) { + for( int is = (long)ithr; is < ns; is += nthr ) { - int iz = is + zilo; - Stat& S = vS[is]; - const Rgns& Ra = vR[iz]; - const vector& xa = gX->X[iz]; - FileErr FS( 'S', Ra.z ), - FD( 'D', Ra.z ); + int iz = is + zilo; + Stat& S = vS[is]; + const Rgns& Ra = vR[iz]; + const vector& xa = gX->X[iz]; + FileErr FS( 'S', Ra.z ), + FD( 'D', Ra.z ); - S.Init(); + S.Init(); - // For each rgn... + // For each rgn... - for( int ir = 0; ir < Ra.nr; ++ir ) { + for( int ir = 0; ir < Ra.nr; ++ir ) { - if( !FLAG_ISUSED( Ra.flag[ir] ) ) - continue; + if( !FLAG_ISUSED( Ra.flag[ir] ) ) + continue; - const vector& P = Ra.pts[ir]; - const TAffine* Ta = &X_AS_AFF( xa, ir ); - const TAffine* Tb; - int lastbi, - lastbz = -1, - np = P.size(); + const vector& P = Ra.pts[ir]; + const TAffine* Ta = &X_AS_AFF( xa, ir ); + const TAffine* Tb; + int lastbi, + lastbz = -1, + np = P.size(); - // For each of its points... + // For each of its points... - for( int ip = 0; ip < np; ++ip ) { + for( int ip = 0; ip < np; ++ip ) { - const CorrPnt& C = vC[S.cur.i = P[ip]]; + const CorrPnt& C = vC[S.cur.i = P[ip]]; - if( !C.used ) - continue; + if( !C.used ) + continue; - if( C.z1 == C.z2 ) { + if( C.z1 == C.z2 ) { - // no double counting - if( C.i1 != ir ) - continue; + // no double counting + if( C.i1 != ir ) + continue; - if( C.z2 != lastbz ) { - lastbz = C.z2; - lastbi = -1; - } + if( C.z2 != lastbz ) { + lastbz = C.z2; + lastbi = -1; + } - if( C.i2 != lastbi ) { + if( C.i2 != lastbi ) { - if( !FLAG_ISUSED( Ra.flag[C.i2] ) ) - continue; + if( !FLAG_ISUSED( Ra.flag[C.i2] ) ) + continue; - Tb = &X_AS_AFF( xa, C.i2 ); - lastbi = C.i2; - } + Tb = &X_AS_AFF( xa, C.i2 ); + lastbi = C.i2; + } - Point pa = C.p1, - pb = C.p2; + Point pa = C.p1, + pb = C.p2; - Ta->Transform( pa ); - Tb->Transform( pb ); + Ta->Transform( pa ); + Tb->Transform( pb ); - S.cur.e = pb.DistSqr( pa ); + S.cur.e = pb.DistSqr( pa ); - if( S.cur.e > Etol ) - continue; + if( S.cur.e > Etol ) + continue; - S.AddS(); - FS.Add( S.cur.e ); - } - else if( C.z1 == zolo ) - continue; - else if( FLAG_ISCUTD( Ra.flag[ir] ) ) - continue; - else if( C.z1 == iz ) { + S.AddS(); + FS.Add( S.cur.e ); + } + else if( C.z1 == zolo ) + continue; + else if( FLAG_ISCUTD( Ra.flag[ir] ) ) + continue; + else if( C.z1 == iz ) { - if( C.z2 != lastbz ) { - lastbz = C.z2; - lastbi = -1; - } + if( C.z2 != lastbz ) { + lastbz = C.z2; + lastbi = -1; + } - if( C.i2 != lastbi ) { + if( C.i2 != lastbi ) { - if( !FLAG_ISUNCT( vR[C.z2].flag[C.i2] ) ) - continue; + if( !FLAG_ISUNCT( vR[C.z2].flag[C.i2] ) ) + continue; - Tb = &X_AS_AFF( gX->X[C.z2], C.i2 ); - lastbi = C.i2; - } + Tb = &X_AS_AFF( gX->X[C.z2], C.i2 ); + lastbi = C.i2; + } - Point pa = C.p1, - pb = C.p2; + Point pa = C.p1, + pb = C.p2; - Ta->Transform( pa ); - Tb->Transform( pb ); + Ta->Transform( pa ); + Tb->Transform( pb ); - S.cur.e = pb.DistSqr( pa ); + S.cur.e = pb.DistSqr( pa ); - if( S.cur.e > Etol ) - continue; + if( S.cur.e > Etol ) + continue; - S.AddD(); - FD.Add( S.cur.e ); - } - } - } - } + S.AddD(); + FD.Add( S.cur.e ); + } + } + } + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -654,117 +654,117 @@ void* _ErrorA( void* ithr ) void* _ErrorH( void* ithr ) { - int ns = zihi - zilo + 1; + int ns = zihi - zilo + 1; // For each layer... - for( int is = (long)ithr; is < ns; is += nthr ) { + for( int is = (long)ithr; is < ns; is += nthr ) { - int iz = is + zilo; - Stat& S = vS[is]; - const Rgns& Ra = vR[iz]; - const vector& xa = gX->X[iz]; - FileErr FS( 'S', Ra.z ), - FD( 'D', Ra.z ); + int iz = is + zilo; + Stat& S = vS[is]; + const Rgns& Ra = vR[iz]; + const vector& xa = gX->X[iz]; + FileErr FS( 'S', Ra.z ), + FD( 'D', Ra.z ); - S.Init(); + S.Init(); - // For each rgn... + // For each rgn... - for( int ir = 0; ir < Ra.nr; ++ir ) { + for( int ir = 0; ir < Ra.nr; ++ir ) { - if( !FLAG_ISUSED( Ra.flag[ir] ) ) - continue; + if( !FLAG_ISUSED( Ra.flag[ir] ) ) + continue; - const vector& P = Ra.pts[ir]; - const THmgphy* Ta = &X_AS_HMY( xa, ir ); - const THmgphy* Tb; - int lastbi, - lastbz = -1, - np = P.size(); + const vector& P = Ra.pts[ir]; + const THmgphy* Ta = &X_AS_HMY( xa, ir ); + const THmgphy* Tb; + int lastbi, + lastbz = -1, + np = P.size(); - // For each of its points... + // For each of its points... - for( int ip = 0; ip < np; ++ip ) { + for( int ip = 0; ip < np; ++ip ) { - const CorrPnt& C = vC[S.cur.i = P[ip]]; + const CorrPnt& C = vC[S.cur.i = P[ip]]; - if( !C.used ) - continue; + if( !C.used ) + continue; - if( C.z1 == C.z2 ) { + if( C.z1 == C.z2 ) { - // no double counting - if( C.i1 != ir ) - continue; + // no double counting + if( C.i1 != ir ) + continue; - if( C.z2 != lastbz ) { - lastbz = C.z2; - lastbi = -1; - } + if( C.z2 != lastbz ) { + lastbz = C.z2; + lastbi = -1; + } - if( C.i2 != lastbi ) { + if( C.i2 != lastbi ) { - if( !FLAG_ISUSED( Ra.flag[C.i2] ) ) - continue; + if( !FLAG_ISUSED( Ra.flag[C.i2] ) ) + continue; - Tb = &X_AS_HMY( xa, C.i2 ); - lastbi = C.i2; - } + Tb = &X_AS_HMY( xa, C.i2 ); + lastbi = C.i2; + } - Point pa = C.p1, - pb = C.p2; + Point pa = C.p1, + pb = C.p2; - Ta->Transform( pa ); - Tb->Transform( pb ); + Ta->Transform( pa ); + Tb->Transform( pb ); - S.cur.e = pb.DistSqr( pa ); + S.cur.e = pb.DistSqr( pa ); - if( S.cur.e > Etol ) - continue; + if( S.cur.e > Etol ) + continue; - S.AddS(); - FS.Add( S.cur.e ); - } - else if( C.z1 == zolo ) - continue; - else if( FLAG_ISCUTD( Ra.flag[ir] ) ) - continue; - else if( C.z1 == iz ) { + S.AddS(); + FS.Add( S.cur.e ); + } + else if( C.z1 == zolo ) + continue; + else if( FLAG_ISCUTD( Ra.flag[ir] ) ) + continue; + else if( C.z1 == iz ) { - if( C.z2 != lastbz ) { - lastbz = C.z2; - lastbi = -1; - } + if( C.z2 != lastbz ) { + lastbz = C.z2; + lastbi = -1; + } - if( C.i2 != lastbi ) { + if( C.i2 != lastbi ) { - if( !FLAG_ISUNCT( vR[C.z2].flag[C.i2] ) ) - continue; + if( !FLAG_ISUNCT( vR[C.z2].flag[C.i2] ) ) + continue; - Tb = &X_AS_HMY( gX->X[C.z2], C.i2 ); - lastbi = C.i2; - } + Tb = &X_AS_HMY( gX->X[C.z2], C.i2 ); + lastbi = C.i2; + } - Point pa = C.p1, - pb = C.p2; + Point pa = C.p1, + pb = C.p2; - Ta->Transform( pa ); - Tb->Transform( pb ); + Ta->Transform( pa ); + Tb->Transform( pb ); - S.cur.e = pb.DistSqr( pa ); + S.cur.e = pb.DistSqr( pa ); - if( S.cur.e > Etol ) - continue; + if( S.cur.e > Etol ) + continue; - S.AddD(); - FD.Add( S.cur.e ); - } - } - } - } + S.AddD(); + FD.Add( S.cur.e ); + } + } + } + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -773,33 +773,33 @@ void* _ErrorH( void* ithr ) static void CalcLayerwiseError( const XArray &X ) { - gX = &X; + gX = &X; - int ns = zihi - zilo + 1; + int ns = zihi - zilo + 1; - vS.resize( ns ); + vS.resize( ns ); - nthr = maxthreads; + nthr = maxthreads; - if( nthr > ns ) - nthr = ns; + if( nthr > ns ) + nthr = ns; // Select affine or hmgphy - EZThreadproc proc; - const char *sproc; + EZThreadproc proc; + const char *sproc; - if( X.NE == 6 ) { - proc = _ErrorA; - sproc = "_ErrorA"; - } - else { - proc = _ErrorH; - sproc = "_ErrorH"; - } + if( X.NE == 6 ) { + proc = _ErrorA; + sproc = "_ErrorA"; + } + else { + proc = _ErrorH; + sproc = "_ErrorH"; + } - if( !EZThreads( proc, nthr, 1, sproc ) ) - exit( 42 ); + if( !EZThreads( proc, nthr, 1, sproc ) ) + exit( 42 ); } /* --------------------------------------------------------------- */ @@ -808,59 +808,59 @@ static void CalcLayerwiseError( const XArray &X ) static void WriteLocalFiles() { - char buf[64]; - FILE *f; + char buf[64]; + FILE *f; // Sames - if( !wkid ) - strcpy( buf, "ErrSame.txt" ); - else - sprintf( buf, "ErrTemp/topn_S_%d.txt", wkid ); + if( !wkid ) + strcpy( buf, "ErrSame.txt" ); + else + sprintf( buf, "ErrTemp/topn_S_%d.txt", wkid ); - f = FileOpenOrDie( buf, "w" ); + f = FileOpenOrDie( buf, "w" ); - // header + // header - if( !wkid ) - fprintf( f, "Z\tRMS\tTOPN\n" ); + if( !wkid ) + fprintf( f, "Z\tRMS\tTOPN\n" ); - for( int iz = zilo; iz <= zihi; ++iz ) { + for( int iz = zilo; iz <= zihi; ++iz ) { - const Stat& S = vS[iz - zilo]; + const Stat& S = vS[iz - zilo]; - fprintf( f, "%d\t%.2f", vR[iz].z, S.RMSS() ); - S.Topn( f, 'S' ); - } + fprintf( f, "%d\t%.2f", vR[iz].z, S.RMSS() ); + S.Topn( f, 'S' ); + } - fclose( f ); + fclose( f ); // Downs - if( zolo == zohi ) - return; + if( zolo == zohi ) + return; - if( !wkid ) - strcpy( buf, "ErrDown.txt" ); - else - sprintf( buf, "ErrTemp/topn_D_%d.txt", wkid ); + if( !wkid ) + strcpy( buf, "ErrDown.txt" ); + else + sprintf( buf, "ErrTemp/topn_D_%d.txt", wkid ); - f = FileOpenOrDie( buf, "w" ); + f = FileOpenOrDie( buf, "w" ); - // header + // header - if( !wkid ) - fprintf( f, "Z\tRMS\tTOPN\n" ); + if( !wkid ) + fprintf( f, "Z\tRMS\tTOPN\n" ); - for( int iz = zilo + (zilo == zolo); iz <= zihi; ++iz ) { + for( int iz = zilo + (zilo == zolo); iz <= zihi; ++iz ) { - const Stat& S = vS[iz - zilo]; + const Stat& S = vS[iz - zilo]; - fprintf( f, "%d\t%.2f", vR[iz].z, S.RMSD() ); - S.Topn( f, 'D' ); - } + fprintf( f, "%d\t%.2f", vR[iz].z, S.RMSD() ); + S.Topn( f, 'D' ); + } - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -869,27 +869,27 @@ static void WriteLocalFiles() static void LogLocalSmy( Stat &Sw, const char* title ) { - printf( "%s:\n", title ); + printf( "%s:\n", title ); - printf( "Same RMS %.2f TopN", Sw.RMSS() ); - Sw.Topn( stdout, 'S' ); + printf( "Same RMS %.2f TopN", Sw.RMSS() ); + Sw.Topn( stdout, 'S' ); - fnlrms = Sw.RMSS(); - fnlmax = Sw.eis[0].e; + fnlrms = Sw.RMSS(); + fnlmax = Sw.eis[0].e; - if( zolo != zohi ) { + if( zolo != zohi ) { - printf( "\nDown RMS %.2f TopN", Sw.RMSD() ); - Sw.Topn( stdout, 'D' ); + printf( "\nDown RMS %.2f TopN", Sw.RMSD() ); + Sw.Topn( stdout, 'D' ); - Stat St; - St.Total( Sw ); - printf( "\nAll RMS %.2f TopN", St.RMSS() ); - St.Topn( stdout, 'S' ); + Stat St; + St.Total( Sw ); + printf( "\nAll RMS %.2f TopN", St.RMSS() ); + St.Topn( stdout, 'S' ); - fnlrms = St.RMSS(); - fnlmax = St.eis[0].e; - } + fnlrms = St.RMSS(); + fnlmax = St.eis[0].e; + } } /* --------------------------------------------------------------- */ @@ -898,21 +898,21 @@ static void LogLocalSmy( Stat &Sw, const char* title ) static void LogGlobalSmy( StatG &S0 ) { - printf( "\nAll workers:\n" ); + printf( "\nAll workers:\n" ); - printf( "Same RMS %.2f TopN", S0.RMSS() ); - S0.Topn( stdout, 'S' ); + printf( "Same RMS %.2f TopN", S0.RMSS() ); + S0.Topn( stdout, 'S' ); - printf( "\nDown RMS %.2f TopN", S0.RMSD() ); - S0.Topn( stdout, 'D' ); + printf( "\nDown RMS %.2f TopN", S0.RMSD() ); + S0.Topn( stdout, 'D' ); - StatG St; - St.Total( S0 ); - printf( "\nAll RMS %.2f TopN", St.RMSS() ); - St.Topn( stdout, 'S' ); + StatG St; + St.Total( S0 ); + printf( "\nAll RMS %.2f TopN", St.RMSS() ); + St.Topn( stdout, 'S' ); - fnlrms = St.RMSS(); - fnlmax = St.egs[0].e; + fnlrms = St.RMSS(); + fnlmax = St.egs[0].e; } /* --------------------------------------------------------------- */ @@ -921,50 +921,50 @@ static void LogGlobalSmy( StatG &S0 ) static void Consolidate() { - Stat Sw; + Stat Sw; - Sw.SmyMyLayers(); + Sw.SmyMyLayers(); - if( nwks <= 1 ) - LogLocalSmy( Sw, "All workers" ); - else if( wkid > 0 ) { + if( nwks <= 1 ) + LogLocalSmy( Sw, "All workers" ); + else if( wkid > 0 ) { - StatG Sg; - Sg.FromStat( Sw ); - Sg.Send(); + StatG Sg; + Sg.FromStat( Sw ); + Sg.Send(); - LogLocalSmy( Sw, "This worker" ); - } - else { + LogLocalSmy( Sw, "This worker" ); + } + else { - StatG S0; - S0.FromStat( Sw ); + StatG S0; + S0.FromStat( Sw ); - for( int iw = 1; iw < nwks; ++iw ) { + for( int iw = 1; iw < nwks; ++iw ) { - // accumulate worker stats + // accumulate worker stats - StatG Si; - Si.Recv( iw ); - S0.Add( Si ); + StatG Si; + Si.Recv( iw ); + S0.Add( Si ); - // append temp files + // append temp files - char buf[128]; + char buf[128]; - sprintf( buf, - "cat ErrTemp/topn_S_%d.txt >> ErrSame.txt", iw ); - system( buf ); + sprintf( buf, + "cat ErrTemp/topn_S_%d.txt >> ErrSame.txt", iw ); + system( buf ); - sprintf( buf, - "cat ErrTemp/topn_D_%d.txt >> ErrDown.txt", iw ); - system( buf ); - } + sprintf( buf, + "cat ErrTemp/topn_D_%d.txt >> ErrDown.txt", iw ); + system( buf ); + } - system( "rm -rf ErrTemp" ); - LogLocalSmy( Sw, "This worker" ); - LogGlobalSmy( S0 ); - } + system( "rm -rf ErrTemp" ); + LogLocalSmy( Sw, "This worker" ); + LogGlobalSmy( S0 ); + } } /* --------------------------------------------------------------- */ @@ -986,23 +986,23 @@ static void Consolidate() // void Error( const XArray &X, double inEtol ) { - printf( "\n---- Error statistics ----\n" ); + printf( "\n---- Error statistics ----\n" ); - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - Etol = inEtol * inEtol; + Etol = inEtol * inEtol; - DskCreateDir( "Error", stdout ); + DskCreateDir( "Error", stdout ); - if( nwks > 1 ) - DskCreateDir( "ErrTemp", stdout ); + if( nwks > 1 ) + DskCreateDir( "ErrTemp", stdout ); - CalcLayerwiseError( X ); - WriteLocalFiles(); - Consolidate(); - vS.clear(); + CalcLayerwiseError( X ); + WriteLocalFiles(); + Consolidate(); + vS.clear(); - StopTiming( stdout, "Errors", t0 ); + StopTiming( stdout, "Errors", t0 ); } /* --------------------------------------------------------------- */ @@ -1011,8 +1011,8 @@ void Error( const XArray &X, double inEtol ) void GetFinalError( double &erms, double &emax ) { - erms = fnlrms; - emax = (fnlmax >= 0 ? sqrt( fnlmax ) : -1); + erms = fnlrms; + emax = (fnlmax >= 0 ? sqrt( fnlmax ) : -1); } diff --git a/1_LSQw/lsq_Globals.cpp b/1_LSQw/lsq_Globals.cpp index c1a2717..d9406d7 100644 --- a/1_LSQw/lsq_Globals.cpp +++ b/1_LSQw/lsq_Globals.cpp @@ -18,12 +18,12 @@ string idb; int zLlo, zLhi, // LHS neib needs these - zRlo, zRhi, // RHS neib needs these - zilo, zihi, - zolo, zohi, // index into vR - gW, gH, // image dims - maxthreads = 1, - _reserved; // pad to 8-byte boundary + zRlo, zRhi, // RHS neib needs these + zilo, zihi, + zolo, zohi, // index into vR + gW, gH, // image dims + maxthreads = 1, + _reserved; // pad to 8-byte boundary vector vL; map mZ; vector vR; @@ -44,9 +44,9 @@ vector vC; Rgns::Rgns( int z ) : z(z), cached_id(-1) { - nr = IDBGetIDRgnMap( m, idb, z ); - pts.resize( nr ); - flag.resize( nr, fmRead ); + nr = IDBGetIDRgnMap( m, idb, z ); + pts.resize( nr ); + flag.resize( nr, fmRead ); } /* --------------------------------------------------------------- */ @@ -55,12 +55,12 @@ Rgns::Rgns( int z ) : z(z), cached_id(-1) int Rgns::Map( int id, int r ) { - if( id != cached_id ) { - cached_i = m.find( id )->second + r - 1; - cached_id = id; - } + if( id != cached_id ) { + cached_i = m.find( id )->second + r - 1; + cached_id = id; + } - return cached_i; + return cached_i; } /* --------------------------------------------------------------- */ @@ -69,13 +69,13 @@ int Rgns::Map( int id, int r ) void GetIDB( const char *tempdir ) { - IDBFromTemp( idb, tempdir ); + IDBFromTemp( idb, tempdir ); - if( idb.empty() ) - exit( 42 ); + if( idb.empty() ) + exit( 42 ); - if( !IDBGetImageDims( gW, gH, idb ) ) - exit( 42 ); + if( !IDBGetImageDims( gW, gH, idb ) ) + exit( 42 ); } /* --------------------------------------------------------------- */ @@ -86,40 +86,40 @@ void GetIDB( const char *tempdir ) // void InitTables( int argzilo, int argzihi ) { - printf( "\n---- Initializing tables ----\n" ); + printf( "\n---- Initializing tables ----\n" ); - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - int nL = vL.size(); + int nL = vL.size(); - for( int iL = 0; iL < nL; ++iL ) { + for( int iL = 0; iL < nL; ++iL ) { - int z = vL[iL].z; + int z = vL[iL].z; - mZ[z] = iL; - vR.push_back( Rgns( z ) ); - } + mZ[z] = iL; + vR.push_back( Rgns( z ) ); + } // Turn z-ranges into zero-based indices into vR - if( wkid > 0 ) { - zLlo = mZ.find( zLlo )->second + 1; - zLhi = mZ.find( zLhi )->second; - } + if( wkid > 0 ) { + zLlo = mZ.find( zLlo )->second + 1; + zLhi = mZ.find( zLhi )->second; + } - if( wkid < nwks - 1 ) { - zRlo = mZ.find( zRlo )->second; - zRhi = mZ.find( zRhi )->second - 1; - } + if( wkid < nwks - 1 ) { + zRlo = mZ.find( zRlo )->second; + zRhi = mZ.find( zRhi )->second - 1; + } - MapZPair( zilo, zihi, argzilo, argzihi ); - zolo = 0; - zohi = nL - 1; + MapZPair( zilo, zihi, argzilo, argzihi ); + zolo = 0; + zohi = nL - 1; - printf( "Z-map: < %d %d < [%d (%d %d) %d] > %d %d >\n", - zLlo, zLhi, zolo, zilo, zihi, zohi, zRlo, zRhi ); + printf( "Z-map: < %d %d < [%d (%d %d) %d] > %d %d >\n", + zLlo, zLhi, zolo, zilo, zihi, zohi, zRlo, zRhi ); - StopTiming( stdout, "Table", t0 ); + StopTiming( stdout, "Table", t0 ); } /* --------------------------------------------------------------- */ @@ -130,45 +130,45 @@ void InitTables( int argzilo, int argzihi ) // bool MapZPair( int &ia, int &ib, int za, int zb ) { - static map::iterator en = mZ.end(); + static map::iterator en = mZ.end(); - static int cached_za = -1, cached_zb = -1, - cached_ia, cached_ib; + static int cached_za = -1, cached_zb = -1, + cached_ia, cached_ib; - map::iterator mi; + map::iterator mi; - if( za != cached_za ) { + if( za != cached_za ) { - mi = mZ.find( za ); + mi = mZ.find( za ); - if( mi == en ) - return false; + if( mi == en ) + return false; - cached_ia = mi->second; - cached_za = za; - } + cached_ia = mi->second; + cached_za = za; + } - ia = cached_ia; + ia = cached_ia; - if( zb == cached_za ) - ib = cached_ia; - else { + if( zb == cached_za ) + ib = cached_ia; + else { - if( zb != cached_zb ) { + if( zb != cached_zb ) { - mi = mZ.find( zb ); + mi = mZ.find( zb ); - if( mi == en ) - return false; + if( mi == en ) + return false; - cached_ib = mi->second; - cached_zb = zb; - } + cached_ib = mi->second; + cached_zb = zb; + } - ib = cached_ib; - } + ib = cached_ib; + } - return true; + return true; } /* --------------------------------------------------------------- */ @@ -196,33 +196,33 @@ bool MapZPair( int &ia, int &ib, int za, int zb ) // void RemapIndices() { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - int nc = vC.size(); + int nc = vC.size(); - for( int i = 0; i < nc; ++i ) { + for( int i = 0; i < nc; ++i ) { - CorrPnt& C = vC[i]; + CorrPnt& C = vC[i]; - if( MapZPair( C.z1, C.z2, C.z1, C.z2 ) ) { + if( MapZPair( C.z1, C.z2, C.z1, C.z2 ) ) { - Rgns& R1 = vR[C.z1]; - Rgns& R2 = vR[C.z2]; + Rgns& R1 = vR[C.z1]; + Rgns& R2 = vR[C.z2]; - C.i1 = R1.Map( C.i1, C.r1 ); - C.i2 = R2.Map( C.i2, C.r2 ); + C.i1 = R1.Map( C.i1, C.r1 ); + C.i2 = R2.Map( C.i2, C.r2 ); - C.used = (C.z1 >= zilo && C.z1 <= zihi) - || (C.z2 >= zilo && C.z2 <= zihi); + C.used = (C.z1 >= zilo && C.z1 <= zihi) + || (C.z2 >= zilo && C.z2 <= zihi); - R1.pts[C.i1].push_back( i ); - R2.pts[C.i2].push_back( i ); - } - else - C.used = false; - } + R1.pts[C.i1].push_back( i ); + R2.pts[C.i2].push_back( i ); + } + else + C.used = false; + } - StopTiming( stdout, "Remap", t0 ); + StopTiming( stdout, "Remap", t0 ); } /* --------------------------------------------------------------- */ @@ -234,23 +234,23 @@ void RemapIndices() // void RealZIDR( int &z, int &id, int &r, int iz, int idx ) { - Rgns& R = vR[iz]; + Rgns& R = vR[iz]; - z = R.z; + z = R.z; - map::iterator mi, mn, en = R.m.end(); + map::iterator mi, mn, en = R.m.end(); - for( mi = R.m.begin(); ; mi = mn ) { + for( mi = R.m.begin(); ; mi = mn ) { - mn = mi; + mn = mi; - if( ++mn == en || mn->second > idx ) { + if( ++mn == en || mn->second > idx ) { - id = mi->first; - r = (idx - mi->second) + 1; - return; - } - } + id = mi->first; + r = (idx - mi->second) + 1; + return; + } + } } diff --git a/1_LSQw/lsq_Globals.h b/1_LSQw/lsq_Globals.h index 2209b42..645d348 100644 --- a/1_LSQw/lsq_Globals.h +++ b/1_LSQw/lsq_Globals.h @@ -20,16 +20,16 @@ using namespace std; /* --------------------------------------------------------------- */ enum RgnFlags { - fbDead = 0x01, - fbRead = 0x02, - fbPnts = 0x04, - fbKill = 0x08, - fbCutd = 0x10, - - fmRead = fbRead + fbDead, - fmPnts = fbPnts + fbDead, - fmKill = fbKill + fbDead, - fmUnct = fbCutd + fbDead + fbDead = 0x01, + fbRead = 0x02, + fbPnts = 0x04, + fbKill = 0x08, + fbCutd = 0x10, + + fmRead = fbRead + fbDead, + fmPnts = fbPnts + fbDead, + fmKill = fbKill + fbDead, + fmUnct = fbCutd + fbDead }; #define FLAG_ISUSED( f ) (((f) & fbDead) == 0) @@ -54,38 +54,38 @@ class Rgns { // The rgns for given layer // indexed by 0-based 'idx0' public: - vector > pts; // ea rgn's pts - vector flag; // rgn flags - map m; // map id -> idx0 - int nr, // num rgns - z, // common z - cached_id, - cached_i; + vector > pts; // ea rgn's pts + vector flag; // rgn flags + map m; // map id -> idx0 + int nr, // num rgns + z, // common z + cached_id, + cached_i; public: - Rgns( int z ); - int Map( int id, int r ); + Rgns( int z ); + int Map( int id, int r ); }; class CorrPnt { public: - Point p1, p2; - int z1, z2, // index into vR - i1, i2; // index into vR[iz] - union { - int used; - struct { - uint16 r1, r2; - }; - }; + Point p1, p2; + int z1, z2, // index into vR + i1, i2; // index into vR[iz] + union { + int used; + struct { + uint16 r1, r2; + }; + }; public: - inline bool FromFile( FILE *f ) - { - return 10 == fscanf( f, "CPOINT2" - " %d.%d-%hd %lf %lf" - " %d.%d-%hd %lf %lf\n", - &z1, &i1, &r1, &p1.x, &p1.y, - &z2, &i2, &r2, &p2.x, &p2.y ); - }; + inline bool FromFile( FILE *f ) + { + return 10 == fscanf( f, "CPOINT2" + " %d.%d-%hd %lf %lf" + " %d.%d-%hd %lf %lf\n", + &z1, &i1, &r1, &p1.x, &p1.y, + &z2, &i2, &r2, &p2.x, &p2.y ); + }; }; /* --------------------------------------------------------------- */ @@ -94,11 +94,11 @@ class CorrPnt { extern string idb; extern int zLlo, zLhi, // LHS neib needs these - zRlo, zRhi, // RHS neib needs these - zilo, zihi, - zolo, zohi, // index into vR - gW, gH, // image dims - maxthreads; + zRlo, zRhi, // RHS neib needs these + zilo, zihi, + zolo, zohi, // index into vR + gW, gH, // image dims + maxthreads; extern vector vL; extern map mZ; extern vector vR; diff --git a/1_LSQw/lsq_LoadPoints.cpp b/1_LSQw/lsq_LoadPoints.cpp index db1dbeb..30d6b50 100644 --- a/1_LSQw/lsq_LoadPoints.cpp +++ b/1_LSQw/lsq_LoadPoints.cpp @@ -36,9 +36,9 @@ static pthread_mutex_t mutex_fpnts = PTHREAD_MUTEX_INITIALIZER; char* CLoadPoints::NameBinary( char *buf ) { - sprintf( buf, "%s/pnts_%d_%d_%d.bin", - cachedir, wkid, vR[zolo].z, vR[zohi].z ); - return buf; + sprintf( buf, "%s/pnts_%d_%d_%d.bin", + cachedir, wkid, vR[zolo].z, vR[zohi].z ); + return buf; } /* --------------------------------------------------------------- */ @@ -47,8 +47,8 @@ char* CLoadPoints::NameBinary( char *buf ) bool CLoadPoints::IsBinary() { - char buf[2048]; - return DskExists( NameBinary( buf ) ); + char buf[2048]; + return DskExists( NameBinary( buf ) ); } /* --------------------------------------------------------------- */ @@ -56,15 +56,15 @@ bool CLoadPoints::IsBinary() /* --------------------------------------------------------------- */ void CLoadPoints::AppendJobs( - int z, - int SorD, - int xhi, - int yhi ) + int z, + int SorD, + int xhi, + int yhi ) { - for( int y = 0; y <= yhi; ++y ) { - for( int x = 0; x <= xhi; ++x ) - vJ.push_back( CJob( z, SorD, x, y ) ); - } + for( int y = 0; y <= yhi; ++y ) { + for( int x = 0; x <= xhi; ++x ) + vJ.push_back( CJob( z, SorD, x, y ) ); + } } /* --------------------------------------------------------------- */ @@ -73,45 +73,45 @@ void CLoadPoints::AppendJobs( void* _Gather( void* ithr ) { - const int ngrow = 1000; - int nmax = ngrow; - vector vc( nmax ); + const int ngrow = 1000; + int nmax = ngrow; + vector vc( nmax ); - for( int j = (long)ithr; j < ME->njob; j += ME->nthr ) { + for( int j = (long)ithr; j < ME->njob; j += ME->nthr ) { - CLoadPoints::CJob &J = ME->vJ[j]; + CLoadPoints::CJob &J = ME->vJ[j]; - char buf[2048]; - sprintf( buf, "%s/%d/%c%d_%d/pts.%s", - ME->tempdir, J.z, J.SorD, J.x, J.y, - (J.SorD == 'S' ? "same" : "down") ); + char buf[2048]; + sprintf( buf, "%s/%d/%c%d_%d/pts.%s", + ME->tempdir, J.z, J.SorD, J.x, J.y, + (J.SorD == 'S' ? "same" : "down") ); - FILE *f = fopen( buf, "r" ); + FILE *f = fopen( buf, "r" ); - if( f ) { + if( f ) { - int n = 0; + int n = 0; - for(;;) { + for(;;) { - if( n >= nmax ) - vc.resize( nmax += ngrow ); + if( n >= nmax ) + vc.resize( nmax += ngrow ); - if( vc[n].FromFile( f ) ) - ++n; - else - break; - } + if( vc[n].FromFile( f ) ) + ++n; + else + break; + } - fclose( f ); + fclose( f ); - pthread_mutex_lock( &mutex_fpnts ); - fwrite( &vc[0], sizeof(CorrPnt), n, ME->fpnts ); - pthread_mutex_unlock( &mutex_fpnts ); - } - } + pthread_mutex_lock( &mutex_fpnts ); + fwrite( &vc[0], sizeof(CorrPnt), n, ME->fpnts ); + pthread_mutex_unlock( &mutex_fpnts ); + } + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -120,48 +120,48 @@ void* _Gather( void* ithr ) void CLoadPoints::MakeBinary() { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); // Output binary points file - char buf[2048]; - fpnts = FileOpenOrDie( NameBinary( buf ), "wb" ); + char buf[2048]; + fpnts = FileOpenOrDie( NameBinary( buf ), "wb" ); // Create list of input file specs. // Load sames only for the inner layers. // Load downs for all layers but the lowest. - int nL = vL.size(); + int nL = vL.size(); - for( int iL = 0; iL < nL; ++iL ) { + for( int iL = 0; iL < nL; ++iL ) { - const Layer& L = vL[iL]; - int iz = mZ.find( L.z )->second; + const Layer& L = vL[iL]; + int iz = mZ.find( L.z )->second; - if( iz >= zilo && iz <= zihi ) - AppendJobs( L.z, 'S', L.sx, L.sy ); + if( iz >= zilo && iz <= zihi ) + AppendJobs( L.z, 'S', L.sx, L.sy ); - if( iz ) - AppendJobs( L.z, 'D', L.dx, L.dy ); - } + if( iz ) + AppendJobs( L.z, 'D', L.dx, L.dy ); + } - njob = vJ.size(); + njob = vJ.size(); // Create reader threads to scan points - nthr = maxthreads; + nthr = maxthreads; - if( nthr > njob ) - nthr = njob; + if( nthr > njob ) + nthr = njob; - if( !EZThreads( _Gather, nthr, 1, "_Gather" ) ) - exit( 42 ); + if( !EZThreads( _Gather, nthr, 1, "_Gather" ) ) + exit( 42 ); - fclose( fpnts ); - pthread_mutex_destroy( &mutex_fpnts ); - vJ.clear(); + fclose( fpnts ); + pthread_mutex_destroy( &mutex_fpnts ); + vJ.clear(); - StopTiming( stdout, "WrBin", t0 ); + StopTiming( stdout, "WrBin", t0 ); } /* --------------------------------------------------------------- */ @@ -170,18 +170,18 @@ void CLoadPoints::MakeBinary() void CLoadPoints::LoadBinary() { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - char buf[2048]; - long n = (long)DskBytes( NameBinary( buf ) ) / sizeof(CorrPnt); + char buf[2048]; + long n = (long)DskBytes( NameBinary( buf ) ) / sizeof(CorrPnt); - vC.resize( n ); + vC.resize( n ); - FILE *f = FileOpenOrDie( buf, "rb" ); - fread( &vC[0], sizeof(CorrPnt), n, f ); - fclose( f ); + FILE *f = FileOpenOrDie( buf, "rb" ); + fread( &vC[0], sizeof(CorrPnt), n, f ); + fclose( f ); - StopTiming( stdout, "RdBin", t0 ); + StopTiming( stdout, "RdBin", t0 ); } /* --------------------------------------------------------------- */ @@ -190,24 +190,24 @@ void CLoadPoints::LoadBinary() void CLoadPoints::Load( const char *tempdir, const char *cachedir ) { - printf( "\n---- Loading points ----\n" ); + printf( "\n---- Loading points ----\n" ); - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - ME = this; - this->tempdir = tempdir; - this->cachedir = cachedir; + ME = this; + this->tempdir = tempdir; + this->cachedir = cachedir; - if( !IsBinary() ) - MakeBinary(); + if( !IsBinary() ) + MakeBinary(); - LoadBinary(); + LoadBinary(); - RemapIndices(); + RemapIndices(); - StopTiming( stdout, "Total", t0 ); + StopTiming( stdout, "Total", t0 ); - printf( "Loaded %ld point pairs.\n", vC.size() ); + printf( "Loaded %ld point pairs.\n", vC.size() ); } diff --git a/1_LSQw/lsq_LoadPoints.h b/1_LSQw/lsq_LoadPoints.h index d6dec04..da3d301 100644 --- a/1_LSQw/lsq_LoadPoints.h +++ b/1_LSQw/lsq_LoadPoints.h @@ -14,35 +14,35 @@ using namespace std; /* --------------------------------------------------------------- */ class CLoadPoints { - friend void* _Gather( void* ithr ); + friend void* _Gather( void* ithr ); private: - class CJob { - public: - int z, SorD, x, y; - public: - CJob( int z, int SorD, int x, int y ) - : z(z), SorD(SorD), x(x), y(y) {}; - }; + class CJob { + public: + int z, SorD, x, y; + public: + CJob( int z, int SorD, int x, int y ) + : z(z), SorD(SorD), x(x), y(y) {}; + }; private: - const char *tempdir; - const char *cachedir; - FILE *fpnts; - vector vJ; - int njob, - nthr; + const char *tempdir; + const char *cachedir; + FILE *fpnts; + vector vJ; + int njob, + nthr; private: - char* NameBinary( char *buf ); - bool IsBinary(); - void AppendJobs( - int z, - int SorD, - int xhi, - int yhi ); - void MakeBinary(); - void LoadBinary(); - void Remap(); + char* NameBinary( char *buf ); + bool IsBinary(); + void AppendJobs( + int z, + int SorD, + int xhi, + int yhi ); + void MakeBinary(); + void LoadBinary(); + void Remap(); public: - void Load( const char *tempdir, const char *cachedir ); + void Load( const char *tempdir, const char *cachedir ); }; /* --------------------------------------------------------------- */ diff --git a/1_LSQw/lsq_MPI.cpp b/1_LSQw/lsq_MPI.cpp index 56755e8..1b06659 100644 --- a/1_LSQw/lsq_MPI.cpp +++ b/1_LSQw/lsq_MPI.cpp @@ -14,7 +14,7 @@ /* --------------------------------------------------------------- */ int wkid = 0, // my worker id (main=0) - nwks = 1; // total number workers + nwks = 1; // total number workers @@ -32,70 +32,70 @@ void MPIInit( int& argc, char**& argv ) { // Look for the -nwks=j argument - for( int i = 1; i < argc; ++i ) { - if( GetArg( &nwks, "-nwks=%d", argv[i] ) ) - break; - } + for( int i = 1; i < argc; ++i ) { + if( GetArg( &nwks, "-nwks=%d", argv[i] ) ) + break; + } // Get wkid - int thrdtype = -1; + int thrdtype = -1; - if( nwks > 1 ) { + if( nwks > 1 ) { - // Start MPI + // Start MPI - MPI_Init_thread( &argc, &argv, - MPI_THREAD_FUNNELED, &thrdtype ); + MPI_Init_thread( &argc, &argv, + MPI_THREAD_FUNNELED, &thrdtype ); - MPI_Comm_rank( MPI_COMM_WORLD, &wkid ); - } + MPI_Comm_rank( MPI_COMM_WORLD, &wkid ); + } // Create log file 'lsqw_i' - char slog[32]; - sprintf( slog, "lsqw_%d.txt", wkid ); - freopen( slog, "w", stdout ); + char slog[32]; + sprintf( slog, "lsqw_%d.txt", wkid ); + freopen( slog, "w", stdout ); - printf( "---- Read params ----\n" ); + printf( "---- Read params ----\n" ); // MPI sanity checks - if( nwks > 1 ) { + if( nwks > 1 ) { - // Verify worker count + // Verify worker count - int size; + int size; - MPI_Comm_size( MPI_COMM_WORLD, &size ); + MPI_Comm_size( MPI_COMM_WORLD, &size ); - if( size != nwks ) { + if( size != nwks ) { - printf( - "MPI: Bad worker count: %d, expected %d\n.", - size, nwks ); + printf( + "MPI: Bad worker count: %d, expected %d\n.", + size, nwks ); - MPIExit(); - exit( 42 ); - } + MPIExit(); + exit( 42 ); + } - // Verify desired threading type. - // Funneled means that the application can use - // multiple threads but MPI communicates only - // with the main thread. + // Verify desired threading type. + // Funneled means that the application can use + // multiple threads but MPI communicates only + // with the main thread. - if( thrdtype != MPI_THREAD_FUNNELED ) { + if( thrdtype != MPI_THREAD_FUNNELED ) { - printf( - "MPI: Not funneled thread type." - " Try linking with -mt_mpi.\n" ); + printf( + "MPI: Not funneled thread type." + " Try linking with -mt_mpi.\n" ); - MPIExit(); - exit( 42 ); - } - } + MPIExit(); + exit( 42 ); + } + } - printf( "Worker %d / %d\n", wkid, nwks ); + printf( "Worker %d / %d\n", wkid, nwks ); } /* --------------------------------------------------------------- */ @@ -104,8 +104,8 @@ void MPIInit( int& argc, char**& argv ) void MPIExit() { - if( nwks > 1 ) - MPI_Finalize(); + if( nwks > 1 ) + MPI_Finalize(); } /* --------------------------------------------------------------- */ @@ -116,8 +116,8 @@ void MPIExit() // void MPIWaitForOthers() { - if( nwks > 1 ) - MPI_Barrier( MPI_COMM_WORLD ); + if( nwks > 1 ) + MPI_Barrier( MPI_COMM_WORLD ); } /* --------------------------------------------------------------- */ @@ -126,8 +126,8 @@ void MPIWaitForOthers() bool MPISend( void* buf, int bytes, int wdst, int tag ) { - return MPI_SUCCESS == - MPI_Ssend( buf, bytes, MPI_CHAR, wdst, tag, MPI_COMM_WORLD ); + return MPI_SUCCESS == + MPI_Ssend( buf, bytes, MPI_CHAR, wdst, tag, MPI_COMM_WORLD ); } /* --------------------------------------------------------------- */ @@ -136,10 +136,10 @@ bool MPISend( void* buf, int bytes, int wdst, int tag ) bool MPIRecv( void* buf, int bytes, int wsrc, int tag ) { - MPI_Status st; + MPI_Status st; - return MPI_SUCCESS == - MPI_Recv( buf, bytes, MPI_CHAR, wsrc, tag, MPI_COMM_WORLD, &st ); + return MPI_SUCCESS == + MPI_Recv( buf, bytes, MPI_CHAR, wsrc, tag, MPI_COMM_WORLD, &st ); } diff --git a/1_LSQw/lsq_Magnitude.cpp b/1_LSQw/lsq_Magnitude.cpp index 7a0b218..f498258 100644 --- a/1_LSQw/lsq_Magnitude.cpp +++ b/1_LSQw/lsq_Magnitude.cpp @@ -33,100 +33,100 @@ namespace magnitude { class EI { // Error and point using local indexing public: - double e; - int iz, i; // local tform indices + double e; + int iz, i; // local tform indices public: - EI() : e(-1), iz(0), i(-1) {}; + EI() : e(-1), iz(0), i(-1) {}; }; static bool Sort_EI_inc( const EI &A, const EI &B ) { - if( A.e == -1 ) - return false; - else if( B.e == -1 ) - return true; - return A.e < B.e; + if( A.e == -1 ) + return false; + else if( B.e == -1 ) + return true; + return A.e < B.e; } static bool Sort_EI_dec( const EI &A, const EI &B ) { - return A.e > B.e; + return A.e > B.e; } class EG { // Error and point using global indexing public: - double e; - int z, i, r; // global indices + double e; + int z, i, r; // global indices public: - EG() : e(-1) {}; + EG() : e(-1) {}; - void FromEI( const EI &rhs ); + void FromEI( const EI &rhs ); }; static bool Sort_EG_inc( const EG &A, const EG &B ) { - if( A.e == -1 ) - return false; - else if( B.e == -1 ) - return true; - return A.e < B.e; + if( A.e == -1 ) + return false; + else if( B.e == -1 ) + return true; + return A.e < B.e; } static bool Sort_EG_dec( const EG &A, const EG &B ) { - return A.e > B.e; + return A.e > B.e; } class Stat { // statistics summaries using local point indexing private: - vector::iterator eis0, eib0; + vector::iterator eis0, eib0; public: - vector eis, eib; // topn - double sum; // sum - int n; // count - EI cur; // current + vector eis, eib; // topn + double sum; // sum + int n; // count + EI cur; // current public: - // accumulate layerwise data - void Init( int iz ); - void Add(); - - // combine - void Init_Smy( const Stat &rhs ); - void Add_Smy( const Stat &rhs ); - void SmyMyLayers(); - - // report - double RMS() const {return (n ? sqrt( sum/(2*n) ) : -1);}; - void Topn( FILE *f, int SorB ) const; + // accumulate layerwise data + void Init( int iz ); + void Add(); + + // combine + void Init_Smy( const Stat &rhs ); + void Add_Smy( const Stat &rhs ); + void SmyMyLayers(); + + // report + double RMS() const {return (n ? sqrt( sum/(2*n) ) : -1);}; + void Topn( FILE *f, int SorB ) const; }; class StatG { // Stat type using cross-worker global indexing private: - typedef struct { - double sum; - int n; - EG egs[TOPN], - egb[TOPN]; - } MPIBUF; + typedef struct { + double sum; + int n; + EG egs[TOPN], + egb[TOPN]; + } MPIBUF; private: - vector::iterator egs0, egb0; + vector::iterator egs0, egb0; public: - vector egs, egb; // topn - double sum; // sum - int n; // count + vector egs, egb; // topn + double sum; // sum + int n; // count public: - // Scatter, gather - void FromStat( const Stat &rhs ); - void Send(); - void Recv( int iw ); - void Add( const StatG &rhs ); - - // report - double RMS() const {return (n ? sqrt( sum/(2*n) ) : -1);}; - void Topn( FILE *f, int SorB ) const; + // Scatter, gather + void FromStat( const Stat &rhs ); + void Send(); + void Recv( int iw ); + void Add( const StatG &rhs ); + + // report + double RMS() const {return (n ? sqrt( sum/(2*n) ) : -1);}; + void Topn( FILE *f, int SorB ) const; }; } // namespace magnitude @@ -152,8 +152,8 @@ static int nthr; void EG::FromEI( const EI &rhs ) { - if( (e = rhs.e) > -1 ) - RealZIDR( z, i, r, rhs.iz, rhs.i ); + if( (e = rhs.e) > -1 ) + RealZIDR( z, i, r, rhs.iz, rhs.i ); } /* --------------------------------------------------------------- */ @@ -162,13 +162,13 @@ void EG::FromEI( const EI &rhs ) void Stat::Init( int iz ) { - eis.resize( TOPN ); - eib.resize( TOPN ); - eis0 = eis.begin(); - eib0 = eib.begin(); - sum = 0.0; - n = 0; - cur.iz = iz; + eis.resize( TOPN ); + eib.resize( TOPN ); + eis0 = eis.begin(); + eib0 = eib.begin(); + sum = 0.0; + n = 0; + cur.iz = iz; } /* --------------------------------------------------------------- */ @@ -177,28 +177,28 @@ void Stat::Init( int iz ) void Stat::Add() { - sum += cur.e; - ++n; + sum += cur.e; + ++n; // smallest - { - EI& ei = eis[TOPL]; + { + EI& ei = eis[TOPL]; - if( ei.e == -1 || cur.e < ei.e ) { - ei = cur; - sort( eis0, eis0 + TOPN, Sort_EI_inc ); - } - } + if( ei.e == -1 || cur.e < ei.e ) { + ei = cur; + sort( eis0, eis0 + TOPN, Sort_EI_inc ); + } + } // biggest - { - EI& ei = eib[TOPL]; - - if( cur.e > ei.e ) { - ei = cur; - sort( eib0, eib0 + TOPN, Sort_EI_dec ); - } - } + { + EI& ei = eib[TOPL]; + + if( cur.e > ei.e ) { + ei = cur; + sort( eib0, eib0 + TOPN, Sort_EI_dec ); + } + } } /* --------------------------------------------------------------- */ @@ -209,14 +209,14 @@ void Stat::Add() // void Stat::Init_Smy( const Stat &rhs ) { - eis.resize( 2*TOPN ); - eib.resize( 2*TOPN ); - eis0 = eis.begin(); - eib0 = eib.begin(); - memcpy( &eis[0], &rhs.eis[0], TOPN * sizeof(EI) ); - memcpy( &eib[0], &rhs.eib[0], TOPN * sizeof(EI) ); - sum = rhs.sum; - n = rhs.n; + eis.resize( 2*TOPN ); + eib.resize( 2*TOPN ); + eis0 = eis.begin(); + eib0 = eib.begin(); + memcpy( &eis[0], &rhs.eis[0], TOPN * sizeof(EI) ); + memcpy( &eib[0], &rhs.eib[0], TOPN * sizeof(EI) ); + sum = rhs.sum; + n = rhs.n; } /* --------------------------------------------------------------- */ @@ -225,12 +225,12 @@ void Stat::Init_Smy( const Stat &rhs ) void Stat::Add_Smy( const Stat &rhs ) { - memcpy( &eis[TOPN], &rhs.eis[0], TOPN * sizeof(EI) ); - sort( eis0, eis0 + 2*TOPN, Sort_EI_inc ); - memcpy( &eib[TOPN], &rhs.eib[0], TOPN * sizeof(EI) ); - sort( eib0, eib0 + 2*TOPN, Sort_EI_dec ); - sum += rhs.sum; - n += rhs.n; + memcpy( &eis[TOPN], &rhs.eis[0], TOPN * sizeof(EI) ); + sort( eis0, eis0 + 2*TOPN, Sort_EI_inc ); + memcpy( &eib[TOPN], &rhs.eib[0], TOPN * sizeof(EI) ); + sort( eib0, eib0 + 2*TOPN, Sort_EI_dec ); + sum += rhs.sum; + n += rhs.n; } /* --------------------------------------------------------------- */ @@ -239,12 +239,12 @@ void Stat::Add_Smy( const Stat &rhs ) void Stat::SmyMyLayers() { - int nL = zihi - zilo + 1; + int nL = zihi - zilo + 1; - Init_Smy( vS[0] ); + Init_Smy( vS[0] ); - for( int iL = 1; iL < nL; ++iL ) - Add_Smy( vS[iL] ); + for( int iL = 1; iL < nL; ++iL ) + Add_Smy( vS[iL] ); } /* --------------------------------------------------------------- */ @@ -255,34 +255,34 @@ void Stat::Topn( FILE *f, int SorB ) const { // print the errors... - const vector& vei = (SorB == 'S' ? eis : eib); - int ne = 0; + const vector& vei = (SorB == 'S' ? eis : eib); + int ne = 0; - for( int i = 0; i < TOPN; ++i ) { + for( int i = 0; i < TOPN; ++i ) { - double e = vei[i].e; + double e = vei[i].e; - if( e > -1 ) { - fprintf( f, "\t%.3f", sqrt( e/2 ) ); - ++ne; - } - } + if( e > -1 ) { + fprintf( f, "\t%.3f", sqrt( e/2 ) ); + ++ne; + } + } // ...and their labels - if( ne ) { + if( ne ) { - for( int ie = 0; ie < ne; ++ie ) { + for( int ie = 0; ie < ne; ++ie ) { - int z, i, r; - RealZIDR( z, i, r, vei[ie].iz, vei[ie].i ); - fprintf( f, "\t%d.%d-%d", z, i, r ); - } - } - else - fprintf( f, "-1\n" ); + int z, i, r; + RealZIDR( z, i, r, vei[ie].iz, vei[ie].i ); + fprintf( f, "\t%d.%d-%d", z, i, r ); + } + } + else + fprintf( f, "-1\n" ); - fprintf( f, "\n" ); + fprintf( f, "\n" ); } /* --------------------------------------------------------------- */ @@ -291,17 +291,17 @@ void Stat::Topn( FILE *f, int SorB ) const void StatG::FromStat( const Stat &rhs ) { - egs.resize( 2*TOPN ); - egb.resize( 2*TOPN ); - egs0 = egs.begin(); - egb0 = egb.begin(); - sum = rhs.sum; - n = rhs.n; - - for( int i = 0; i < TOPN; ++i ) { - egs[i].FromEI( rhs.eis[i] ); - egb[i].FromEI( rhs.eib[i] ); - } + egs.resize( 2*TOPN ); + egb.resize( 2*TOPN ); + egs0 = egs.begin(); + egb0 = egb.begin(); + sum = rhs.sum; + n = rhs.n; + + for( int i = 0; i < TOPN; ++i ) { + egs[i].FromEI( rhs.eis[i] ); + egb[i].FromEI( rhs.eib[i] ); + } } /* --------------------------------------------------------------- */ @@ -310,14 +310,14 @@ void StatG::FromStat( const Stat &rhs ) void StatG::Send() { - MPIBUF B; + MPIBUF B; - B.sum = sum; - B.n = n; - memcpy( B.egs, &egs[0], TOPN * sizeof(EG) ); - memcpy( B.egb, &egb[0], TOPN * sizeof(EG) ); + B.sum = sum; + B.n = n; + memcpy( B.egs, &egs[0], TOPN * sizeof(EG) ); + memcpy( B.egb, &egb[0], TOPN * sizeof(EG) ); - MPISend( &B, sizeof(MPIBUF), 0, wkid ); + MPISend( &B, sizeof(MPIBUF), 0, wkid ); } /* --------------------------------------------------------------- */ @@ -326,18 +326,18 @@ void StatG::Send() void StatG::Recv( int iw ) { - MPIBUF B; - MPIRecv( &B, sizeof(MPIBUF), iw, iw ); - - egs.resize( 2*TOPN ); - egs0 = egs.begin(); - egb.resize( 2*TOPN ); - egb0 = egb.begin(); - - sum = B.sum; - n = B.n; - memcpy( &egs[0], B.egs, TOPN * sizeof(EG) ); - memcpy( &egb[0], B.egb, TOPN * sizeof(EG) ); + MPIBUF B; + MPIRecv( &B, sizeof(MPIBUF), iw, iw ); + + egs.resize( 2*TOPN ); + egs0 = egs.begin(); + egb.resize( 2*TOPN ); + egb0 = egb.begin(); + + sum = B.sum; + n = B.n; + memcpy( &egs[0], B.egs, TOPN * sizeof(EG) ); + memcpy( &egb[0], B.egb, TOPN * sizeof(EG) ); } /* --------------------------------------------------------------- */ @@ -346,12 +346,12 @@ void StatG::Recv( int iw ) void StatG::Add( const StatG &rhs ) { - memcpy( &egs[TOPN], &rhs.egs[0], TOPN * sizeof(EG) ); - sort( egs0, egs0 + 2*TOPN, Sort_EG_inc ); - memcpy( &egb[TOPN], &rhs.egb[0], TOPN * sizeof(EG) ); - sort( egb0, egb0 + 2*TOPN, Sort_EG_dec ); - sum += rhs.sum; - n += rhs.n; + memcpy( &egs[TOPN], &rhs.egs[0], TOPN * sizeof(EG) ); + sort( egs0, egs0 + 2*TOPN, Sort_EG_inc ); + memcpy( &egb[TOPN], &rhs.egb[0], TOPN * sizeof(EG) ); + sort( egb0, egb0 + 2*TOPN, Sort_EG_dec ); + sum += rhs.sum; + n += rhs.n; } /* --------------------------------------------------------------- */ @@ -362,34 +362,34 @@ void StatG::Topn( FILE *f, int SorB ) const { // print the errors... - const vector& veg = (SorB == 'S' ? egs : egb); - int ne = 0; + const vector& veg = (SorB == 'S' ? egs : egb); + int ne = 0; - for( int i = 0; i < TOPN; ++i ) { + for( int i = 0; i < TOPN; ++i ) { - double e = veg[i].e; + double e = veg[i].e; - if( e > -1 ) { - fprintf( f, "\t%.3f", sqrt( e/2 ) ); - ++ne; - } - } + if( e > -1 ) { + fprintf( f, "\t%.3f", sqrt( e/2 ) ); + ++ne; + } + } // ...and their labels - if( ne ) { + if( ne ) { - for( int i = 0; i < ne; ++i ) { + for( int i = 0; i < ne; ++i ) { - const EG& G = veg[i]; + const EG& G = veg[i]; - fprintf( f, "\t%d.%d-%d", G.z, G.i, G.r ); - } - } - else - fprintf( f, "-1\n" ); + fprintf( f, "\t%d.%d-%d", G.z, G.i, G.r ); + } + } + else + fprintf( f, "-1\n" ); - fprintf( f, "\n" ); + fprintf( f, "\n" ); } /* --------------------------------------------------------------- */ @@ -398,46 +398,46 @@ void StatG::Topn( FILE *f, int SorB ) const void* _Mag( void* ithr ) { - int ns = zihi - zilo + 1; + int ns = zihi - zilo + 1; // For each layer... - for( int is = (long)ithr; is < ns; is += nthr ) { + for( int is = (long)ithr; is < ns; is += nthr ) { - int iz = is + zilo; - Stat& S = vS[is]; - const Rgns& R = vR[iz]; - const vector& x = gX->X[iz]; + int iz = is + zilo; + Stat& S = vS[is]; + const Rgns& R = vR[iz]; + const vector& x = gX->X[iz]; - S.Init( iz ); + S.Init( iz ); - // For each rgn... + // For each rgn... - for( int ir = 0; ir < R.nr; ++ir ) { + for( int ir = 0; ir < R.nr; ++ir ) { - if( !FLAG_ISUSED( R.flag[ir] ) ) - continue; + if( !FLAG_ISUSED( R.flag[ir] ) ) + continue; - Point p0, p1( 1, 1 ); + Point p0, p1( 1, 1 ); - if( gX->NE == 6 ) { - const TAffine& T = X_AS_AFF( x, ir ); - T.Transform( p0 ); - T.Transform( p1 ); - } - else { - const THmgphy& T = X_AS_HMY( x, ir ); - T.Transform( p0 ); - T.Transform( p1 ); - } + if( gX->NE == 6 ) { + const TAffine& T = X_AS_AFF( x, ir ); + T.Transform( p0 ); + T.Transform( p1 ); + } + else { + const THmgphy& T = X_AS_HMY( x, ir ); + T.Transform( p0 ); + T.Transform( p1 ); + } - S.cur.i = ir; - S.cur.e = p1.DistSqr( p0 ); - S.Add(); - } - } + S.cur.i = ir; + S.cur.e = p1.DistSqr( p0 ); + S.Add(); + } + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -446,19 +446,19 @@ void* _Mag( void* ithr ) static void CalcLayerwiseMags( const XArray &X ) { - gX = &X; + gX = &X; - int ns = zihi - zilo + 1; + int ns = zihi - zilo + 1; - vS.resize( ns ); + vS.resize( ns ); - nthr = maxthreads; + nthr = maxthreads; - if( nthr > ns ) - nthr = ns; + if( nthr > ns ) + nthr = ns; - if( !EZThreads( _Mag, nthr, 1, "_Mag" ) ) - exit( 42 ); + if( !EZThreads( _Mag, nthr, 1, "_Mag" ) ) + exit( 42 ); } /* --------------------------------------------------------------- */ @@ -467,56 +467,56 @@ static void CalcLayerwiseMags( const XArray &X ) static void WriteLocalFiles() { - char buf[64]; - FILE *f; + char buf[64]; + FILE *f; // Smalls - if( !wkid ) - strcpy( buf, "MagSmall.txt" ); - else - sprintf( buf, "MagTemp/topn_S_%d.txt", wkid ); + if( !wkid ) + strcpy( buf, "MagSmall.txt" ); + else + sprintf( buf, "MagTemp/topn_S_%d.txt", wkid ); - f = FileOpenOrDie( buf, "w" ); + f = FileOpenOrDie( buf, "w" ); - // header + // header - if( !wkid ) - fprintf( f, "Z\tRMS\tTOPN\n" ); + if( !wkid ) + fprintf( f, "Z\tRMS\tTOPN\n" ); - for( int iz = zilo; iz <= zihi; ++iz ) { + for( int iz = zilo; iz <= zihi; ++iz ) { - const Stat& S = vS[iz - zilo]; + const Stat& S = vS[iz - zilo]; - fprintf( f, "%d\t%.3f", vR[iz].z, S.RMS() ); - S.Topn( f, 'S' ); - } + fprintf( f, "%d\t%.3f", vR[iz].z, S.RMS() ); + S.Topn( f, 'S' ); + } - fclose( f ); + fclose( f ); // Bigs - if( !wkid ) - strcpy( buf, "MagBig.txt" ); - else - sprintf( buf, "MagTemp/topn_B_%d.txt", wkid ); + if( !wkid ) + strcpy( buf, "MagBig.txt" ); + else + sprintf( buf, "MagTemp/topn_B_%d.txt", wkid ); - f = FileOpenOrDie( buf, "w" ); + f = FileOpenOrDie( buf, "w" ); - // header + // header - if( !wkid ) - fprintf( f, "Z\tRMS\tTOPN\n" ); + if( !wkid ) + fprintf( f, "Z\tRMS\tTOPN\n" ); - for( int iz = zilo; iz <= zihi; ++iz ) { + for( int iz = zilo; iz <= zihi; ++iz ) { - const Stat& S = vS[iz - zilo]; + const Stat& S = vS[iz - zilo]; - fprintf( f, "%d\t%.3f", vR[iz].z, S.RMS() ); - S.Topn( f, 'B' ); - } + fprintf( f, "%d\t%.3f", vR[iz].z, S.RMS() ); + S.Topn( f, 'B' ); + } - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -525,13 +525,13 @@ static void WriteLocalFiles() static void LogLocalSmy( Stat &Sw, const char* title ) { - printf( "%s:\n", title ); + printf( "%s:\n", title ); - printf( "Small RMS %.3f TopN", Sw.RMS() ); - Sw.Topn( stdout, 'S' ); + printf( "Small RMS %.3f TopN", Sw.RMS() ); + Sw.Topn( stdout, 'S' ); - printf( "\nBig RMS %.3f TopN", Sw.RMS() ); - Sw.Topn( stdout, 'B' ); + printf( "\nBig RMS %.3f TopN", Sw.RMS() ); + Sw.Topn( stdout, 'B' ); } /* --------------------------------------------------------------- */ @@ -540,13 +540,13 @@ static void LogLocalSmy( Stat &Sw, const char* title ) static void LogGlobalSmy( StatG &S0 ) { - printf( "\nAll workers:\n" ); + printf( "\nAll workers:\n" ); - printf( "Small RMS %.3f TopN", S0.RMS() ); - S0.Topn( stdout, 'S' ); + printf( "Small RMS %.3f TopN", S0.RMS() ); + S0.Topn( stdout, 'S' ); - printf( "\nBig RMS %.3f TopN", S0.RMS() ); - S0.Topn( stdout, 'B' ); + printf( "\nBig RMS %.3f TopN", S0.RMS() ); + S0.Topn( stdout, 'B' ); } /* --------------------------------------------------------------- */ @@ -555,50 +555,50 @@ static void LogGlobalSmy( StatG &S0 ) static void Consolidate() { - Stat Sw; + Stat Sw; - Sw.SmyMyLayers(); + Sw.SmyMyLayers(); - if( nwks <= 1 ) - LogLocalSmy( Sw, "All workers" ); - else if( wkid > 0 ) { + if( nwks <= 1 ) + LogLocalSmy( Sw, "All workers" ); + else if( wkid > 0 ) { - StatG Sg; - Sg.FromStat( Sw ); - Sg.Send(); + StatG Sg; + Sg.FromStat( Sw ); + Sg.Send(); - LogLocalSmy( Sw, "This worker" ); - } - else { + LogLocalSmy( Sw, "This worker" ); + } + else { - StatG S0; - S0.FromStat( Sw ); + StatG S0; + S0.FromStat( Sw ); - for( int iw = 1; iw < nwks; ++iw ) { + for( int iw = 1; iw < nwks; ++iw ) { - // accumulate worker stats + // accumulate worker stats - StatG Si; - Si.Recv( iw ); - S0.Add( Si ); + StatG Si; + Si.Recv( iw ); + S0.Add( Si ); - // append temp files + // append temp files - char buf[128]; + char buf[128]; - sprintf( buf, - "cat MagTemp/topn_S_%d.txt >> MagSmall.txt", iw ); - system( buf ); + sprintf( buf, + "cat MagTemp/topn_S_%d.txt >> MagSmall.txt", iw ); + system( buf ); - sprintf( buf, - "cat MagTemp/topn_B_%d.txt >> MagBig.txt", iw ); - system( buf ); - } + sprintf( buf, + "cat MagTemp/topn_B_%d.txt >> MagBig.txt", iw ); + system( buf ); + } - system( "rm -rf MagTemp" ); - LogLocalSmy( Sw, "This worker" ); - LogGlobalSmy( S0 ); - } + system( "rm -rf MagTemp" ); + LogLocalSmy( Sw, "This worker" ); + LogGlobalSmy( S0 ); + } } /* --------------------------------------------------------------- */ @@ -615,19 +615,19 @@ static void Consolidate() // void Magnitude( const XArray &X ) { - printf( "\n---- Magnitudes ----\n" ); + printf( "\n---- Magnitudes ----\n" ); - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - if( nwks > 1 ) - DskCreateDir( "MagTemp", stdout ); + if( nwks > 1 ) + DskCreateDir( "MagTemp", stdout ); - CalcLayerwiseMags( X ); - WriteLocalFiles(); - Consolidate(); - vS.clear(); + CalcLayerwiseMags( X ); + WriteLocalFiles(); + Consolidate(); + vS.clear(); - StopTiming( stdout, "Mags", t0 ); + StopTiming( stdout, "Mags", t0 ); } diff --git a/1_LSQw/lsq_Solve.cpp b/1_LSQw/lsq_Solve.cpp index 41085c7..1010d82 100644 --- a/1_LSQw/lsq_Solve.cpp +++ b/1_LSQw/lsq_Solve.cpp @@ -49,22 +49,22 @@ static const double sqrtol = sin( 15 * PI/180 ); class Todo { // Which 0-based {iz,ir} a thread should work on public: - int iz, ir; + int iz, ir; public: - Todo() {}; - Todo( int iz, int ir ) : iz(iz), ir(ir) {}; - bool First( int ithr ); - bool Next(); - static bool UseThreads( int minrgns ); - static int RgnCount(); + Todo() {}; + Todo( int iz, int ir ) : iz(iz), ir(ir) {}; + bool First( int ithr ); + bool Next(); + static bool UseThreads( int minrgns ); + static int RgnCount(); }; class Thrdat { // Each thread's edit tracking data public: - vector vmark, // update pnt used flags - vcutd, // cut down pts - vkill; // can't rescue + vector vmark, // update pnt used flags + vcutd, // cut down pts + vkill; // can't rescue }; /* --------------------------------------------------------------- */ @@ -75,8 +75,8 @@ static double Wr, Etol; static XArray *Xs, *Xd; static vector vthr; static int regtype, - editdelay, - pass, nthr; + editdelay, + pass, nthr; @@ -89,22 +89,22 @@ static int regtype, bool Todo::First( int ithr ) { - ir = ithr; + ir = ithr; - for( iz = zilo; iz <= zihi; ++iz ) { + for( iz = zilo; iz <= zihi; ++iz ) { - const Rgns& R = vR[iz]; + const Rgns& R = vR[iz]; - for( ; ir < R.nr; ir += nthr ) { + for( ; ir < R.nr; ir += nthr ) { - if( FLAG_ISUSED( R.flag[ir] ) ) - return true; - } + if( FLAG_ISUSED( R.flag[ir] ) ) + return true; + } - ir -= R.nr; - } + ir -= R.nr; + } - return false; + return false; } /* --------------------------------------------------------------- */ @@ -113,22 +113,22 @@ bool Todo::First( int ithr ) bool Todo::Next() { - ir += nthr; + ir += nthr; - for( ; iz <= zihi; ++iz ) { + for( ; iz <= zihi; ++iz ) { - const Rgns& R = vR[iz]; + const Rgns& R = vR[iz]; - for( ; ir < R.nr; ir += nthr ) { + for( ; ir < R.nr; ir += nthr ) { - if( FLAG_ISUSED( R.flag[ir] ) ) - return true; - } + if( FLAG_ISUSED( R.flag[ir] ) ) + return true; + } - ir -= R.nr; - } + ir -= R.nr; + } - return false; + return false; } /* --------------------------------------------------------------- */ @@ -137,23 +137,23 @@ bool Todo::Next() int Todo::RgnCount() { - int N = 0; + int N = 0; - for( int iz = zilo; iz <= zihi; ++iz ) { + for( int iz = zilo; iz <= zihi; ++iz ) { - const vector& f = vR[iz].flag; - int nr = vR[iz].nr; + const vector& f = vR[iz].flag; + int nr = vR[iz].nr; - for( int ir = 0; ir < nr; ++ir ) { + for( int ir = 0; ir < nr; ++ir ) { - if( FLAG_ISUSED( f[ir] ) ) - ++N; - } - } + if( FLAG_ISUSED( f[ir] ) ) + ++N; + } + } - printf( "NRgns: %d\n", N ); + printf( "NRgns: %d\n", N ); - return N; + return N; } /* --------------------------------------------------------------- */ @@ -162,42 +162,42 @@ int Todo::RgnCount() static bool SortPnts( int a, int b ) { - const CorrPnt& A = vC[a]; - const CorrPnt& B = vC[b]; - - if( A.z1 < B.z1 ) - return true; - if( A.z1 > B.z1 ) - return false; - if( A.i1 < B.i1 ) - return true; - if( A.i1 > B.i1 ) - return false; - - if( A.z2 < B.z2 ) - return true; - if( A.z2 > B.z2 ) - return false; - if( A.i2 < B.i2 ) - return true; - if( A.i2 > B.i2 ) - return false; - - if( A.p1.x < B.p1.x ) - return true; - if( A.p1.x > B.p1.x ) - return false; - if( A.p1.y < B.p1.y ) - return true; - if( A.p1.y > B.p1.y ) - return false; - - if( A.p2.x < B.p2.x ) - return true; - if( A.p2.x > B.p2.x ) - return false; - - return A.p2.y < B.p2.y; + const CorrPnt& A = vC[a]; + const CorrPnt& B = vC[b]; + + if( A.z1 < B.z1 ) + return true; + if( A.z1 > B.z1 ) + return false; + if( A.i1 < B.i1 ) + return true; + if( A.i1 > B.i1 ) + return false; + + if( A.z2 < B.z2 ) + return true; + if( A.z2 > B.z2 ) + return false; + if( A.i2 < B.i2 ) + return true; + if( A.i2 > B.i2 ) + return false; + + if( A.p1.x < B.p1.x ) + return true; + if( A.p1.x > B.p1.x ) + return false; + if( A.p1.y < B.p1.y ) + return true; + if( A.p1.y > B.p1.y ) + return false; + + if( A.p2.x < B.p2.x ) + return true; + if( A.p2.x > B.p2.x ) + return false; + + return A.p2.y < B.p2.y; } /* --------------------------------------------------------------- */ @@ -206,23 +206,23 @@ static bool SortPnts( int a, int b ) static void ShortenList( const Todo& Q, int ithr, int minpts ) { - vector keep; - vector& vp = vR[Q.iz].pts[Q.ir]; - int np = vp.size(), - nu; - - for( int ip = 0; ip < np; ++ip ) { - - if( vC[vp[ip]].used ) - keep.push_back( vp[ip] ); - } - - if( (nu = keep.size()) >= minpts ) { - vp.resize( nu ); - memcpy( &vp[0], &keep[0], nu * sizeof(int) ); - } - else - KILL( Q ); + vector keep; + vector& vp = vR[Q.iz].pts[Q.ir]; + int np = vp.size(), + nu; + + for( int ip = 0; ip < np; ++ip ) { + + if( vC[vp[ip]].used ) + keep.push_back( vp[ip] ); + } + + if( (nu = keep.size()) >= minpts ) { + vp.resize( nu ); + memcpy( &vp[0], &keep[0], nu * sizeof(int) ); + } + else + KILL( Q ); } /* --------------------------------------------------------------- */ @@ -231,110 +231,110 @@ static void ShortenList( const Todo& Q, int ithr, int minpts ) static void Cut_A2A( double *RHS, const Todo& Q, int ithr ) { - int i1[3] = { 0, 1, 2 }, - i2[3] = { 3, 4, 5 }; + int i1[3] = { 0, 1, 2 }, + i2[3] = { 3, 4, 5 }; // For rgn Q... - CRigid *rgd; - const Rgns& R = vR[Q.iz]; - const vector& vp = R.pts[Q.ir]; - int np = vp.size(), - nu = 0; // count pts used + CRigid *rgd; + const Rgns& R = vR[Q.iz]; + const vector& vp = R.pts[Q.ir]; + int np = vp.size(), + nu = 0; // count pts used - if( regtype == 'R' ) - rgd = new CRigid; - else - rgd = new CTrans; + if( regtype == 'R' ) + rgd = new CRigid; + else + rgd = new CTrans; - double LHS[6*6]; - TAffine* Ta = &X_AS_AFF( Xs->X[Q.iz], Q.ir ); - TAffine* Tb; - int lastbi = -1; + double LHS[6*6]; + TAffine* Ta = &X_AS_AFF( Xs->X[Q.iz], Q.ir ); + TAffine* Tb; + int lastbi = -1; - Zero_Quick( LHS, RHS, 6 ); + Zero_Quick( LHS, RHS, 6 ); - // For each of its points... + // For each of its points... - for( int ip = 0; ip < np; ++ip ) { + for( int ip = 0; ip < np; ++ip ) { - CorrPnt& C = vC[vp[ip]]; + CorrPnt& C = vC[vp[ip]]; - if( !C.used || C.z1 != C.z2 ) - continue; + if( !C.used || C.z1 != C.z2 ) + continue; - Point A, B; + Point A, B; - // Which of {1,2} is the A-side? + // Which of {1,2} is the A-side? - if( C.i1 == Q.ir ) { // A is 1 + if( C.i1 == Q.ir ) { // A is 1 - if( C.i2 != lastbi ) { + if( C.i2 != lastbi ) { - if( !FLAG_ISUSED( vR[C.z2].flag[C.i2] ) ) - continue; + if( !FLAG_ISUSED( vR[C.z2].flag[C.i2] ) ) + continue; - Tb = &X_AS_AFF( Xs->X[C.z2], C.i2 ); - lastbi = C.i2; - } + Tb = &X_AS_AFF( Xs->X[C.z2], C.i2 ); + lastbi = C.i2; + } - Ta->Transform( A = C.p1 ); - Tb->Transform( B = C.p2 ); + Ta->Transform( A = C.p1 ); + Tb->Transform( B = C.p2 ); - if( pass > editdelay && A.DistSqr( B ) > Etol ) - continue; + if( pass > editdelay && A.DistSqr( B ) > Etol ) + continue; - B.x = Wb * B.x + (1 - Wb) * A.x; - B.y = Wb * B.y + (1 - Wb) * A.y; - A = C.p1; + B.x = Wb * B.x + (1 - Wb) * A.x; + B.y = Wb * B.y + (1 - Wb) * A.y; + A = C.p1; - rgd->Add( A, B ); - } - else { // A is 2 + rgd->Add( A, B ); + } + else { // A is 2 - if( C.i1 != lastbi ) { + if( C.i1 != lastbi ) { - if( !FLAG_ISUSED( vR[C.z1].flag[C.i1] ) ) - continue; + if( !FLAG_ISUSED( vR[C.z1].flag[C.i1] ) ) + continue; - Tb = &X_AS_AFF( Xs->X[C.z1], C.i1 ); - lastbi = C.i1; - } + Tb = &X_AS_AFF( Xs->X[C.z1], C.i1 ); + lastbi = C.i1; + } - Ta->Transform( A = C.p2 ); - Tb->Transform( B = C.p1 ); + Ta->Transform( A = C.p2 ); + Tb->Transform( B = C.p1 ); - if( pass > editdelay && A.DistSqr( B ) > Etol ) - continue; + if( pass > editdelay && A.DistSqr( B ) > Etol ) + continue; - B.x = Wb * B.x + (1 - Wb) * A.x; - B.y = Wb * B.y + (1 - Wb) * A.y; - A = C.p2; + B.x = Wb * B.x + (1 - Wb) * A.x; + B.y = Wb * B.y + (1 - Wb) * A.y; + A = C.p2; - rgd->Add( A, B ); - } + rgd->Add( A, B ); + } - ++nu; + ++nu; - double v[3] = { A.x, A.y, 1.0 }; + double v[3] = { A.x, A.y, 1.0 }; - AddConstraint_Quick( LHS, RHS, 6, 3, i1, v, B.x ); - AddConstraint_Quick( LHS, RHS, 6, 3, i2, v, B.y ); - } + AddConstraint_Quick( LHS, RHS, 6, 3, i1, v, B.x ); + AddConstraint_Quick( LHS, RHS, 6, 3, i2, v, B.y ); + } - if( nu < 3 || !Solve_Quick( LHS, RHS, 6 ) ) - KILL( Q ); - else { + if( nu < 3 || !Solve_Quick( LHS, RHS, 6 ) ) + KILL( Q ); + else { - rgd->Regularize( RHS, 6, Wr ); + rgd->Regularize( RHS, 6, Wr ); - if( X_AS_AFF( RHS, 0 ).Squareness() > sqrtol ) - KILL( Q ); - else - CUTD( Q ); - } + if( X_AS_AFF( RHS, 0 ).Squareness() > sqrtol ) + KILL( Q ); + else + CUTD( Q ); + } - delete rgd; + delete rgd; } /* --------------------------------------------------------------- */ @@ -343,108 +343,108 @@ static void Cut_A2A( double *RHS, const Todo& Q, int ithr ) static void Cut_A2H( double *RHS, const Todo& Q, int ithr ) { - int i1[5] = { 0, 1, 2, 6, 7 }, - i2[5] = { 3, 4, 5, 6, 7 }; + int i1[5] = { 0, 1, 2, 6, 7 }, + i2[5] = { 3, 4, 5, 6, 7 }; // For rgn Q... - CRigid *rgd; - const Rgns& R = vR[Q.iz]; - const vector& vp = R.pts[Q.ir]; - int np = vp.size(), - nu = 0; // count pts used + CRigid *rgd; + const Rgns& R = vR[Q.iz]; + const vector& vp = R.pts[Q.ir]; + int np = vp.size(), + nu = 0; // count pts used - if( regtype == 'R' ) - rgd = new CRigid; - else - rgd = new CTrans; + if( regtype == 'R' ) + rgd = new CRigid; + else + rgd = new CTrans; - double LHS[8*8]; - TAffine* Ta = &X_AS_AFF( Xs->X[Q.iz], Q.ir ); - TAffine* Tb; - int lastbi = -1; + double LHS[8*8]; + TAffine* Ta = &X_AS_AFF( Xs->X[Q.iz], Q.ir ); + TAffine* Tb; + int lastbi = -1; - Zero_Quick( LHS, RHS, 8 ); + Zero_Quick( LHS, RHS, 8 ); - // For each of its points... + // For each of its points... - for( int ip = 0; ip < np; ++ip ) { + for( int ip = 0; ip < np; ++ip ) { - const CorrPnt& C = vC[vp[ip]]; + const CorrPnt& C = vC[vp[ip]]; - if( !C.used || C.z1 != C.z2 ) - continue; + if( !C.used || C.z1 != C.z2 ) + continue; - Point A, B; + Point A, B; - // Which of {1,2} is the A-side? + // Which of {1,2} is the A-side? - if( C.i1 == Q.ir ) { // A is 1 + if( C.i1 == Q.ir ) { // A is 1 - if( C.i2 != lastbi ) { + if( C.i2 != lastbi ) { - if( !FLAG_ISUSED( vR[C.z2].flag[C.i2] ) ) - continue; + if( !FLAG_ISUSED( vR[C.z2].flag[C.i2] ) ) + continue; - Tb = &X_AS_AFF( Xs->X[C.z2], C.i2 ); - lastbi = C.i2; - } + Tb = &X_AS_AFF( Xs->X[C.z2], C.i2 ); + lastbi = C.i2; + } - Ta->Transform( A = C.p1 ); - Tb->Transform( B = C.p2 ); + Ta->Transform( A = C.p1 ); + Tb->Transform( B = C.p2 ); - B.x = Wb * B.x + (1 - Wb) * A.x; - B.y = Wb * B.y + (1 - Wb) * A.y; - A = C.p1; + B.x = Wb * B.x + (1 - Wb) * A.x; + B.y = Wb * B.y + (1 - Wb) * A.y; + A = C.p1; - rgd->Add( A, B ); - } - else { // A is 2 + rgd->Add( A, B ); + } + else { // A is 2 - if( C.i1 != lastbi ) { + if( C.i1 != lastbi ) { - if( !FLAG_ISUSED( vR[C.z1].flag[C.i1] ) ) - continue; + if( !FLAG_ISUSED( vR[C.z1].flag[C.i1] ) ) + continue; - Tb = &X_AS_AFF( Xs->X[C.z1], C.i1 ); - lastbi = C.i1; - } + Tb = &X_AS_AFF( Xs->X[C.z1], C.i1 ); + lastbi = C.i1; + } - Ta->Transform( A = C.p2 ); - Tb->Transform( B = C.p1 ); + Ta->Transform( A = C.p2 ); + Tb->Transform( B = C.p1 ); - B.x = Wb * B.x + (1 - Wb) * A.x; - B.y = Wb * B.y + (1 - Wb) * A.y; - A = C.p2; + B.x = Wb * B.x + (1 - Wb) * A.x; + B.y = Wb * B.y + (1 - Wb) * A.y; + A = C.p2; - rgd->Add( A, B ); - } + rgd->Add( A, B ); + } - ++nu; + ++nu; - double v[5] = { A.x, A.y, 1.0, -A.x*B.x, -A.y*B.x }; + double v[5] = { A.x, A.y, 1.0, -A.x*B.x, -A.y*B.x }; - AddConstraint_Quick( LHS, RHS, 8, 5, i1, v, B.x ); + AddConstraint_Quick( LHS, RHS, 8, 5, i1, v, B.x ); - v[3] = -A.x*B.y; - v[4] = -A.y*B.y; + v[3] = -A.x*B.y; + v[4] = -A.y*B.y; - AddConstraint_Quick( LHS, RHS, 8, 5, i2, v, B.y ); - } + AddConstraint_Quick( LHS, RHS, 8, 5, i2, v, B.y ); + } - if( nu < 4 || !Solve_Quick( LHS, RHS, 8 ) ) - KILL( Q ); - else { + if( nu < 4 || !Solve_Quick( LHS, RHS, 8 ) ) + KILL( Q ); + else { - rgd->Regularize( RHS, 8, Wr ); + rgd->Regularize( RHS, 8, Wr ); - if( X_AS_HMY( RHS, 0 ).Squareness() > sqrtol ) - KILL( Q ); - else - CUTD( Q ); - } + if( X_AS_HMY( RHS, 0 ).Squareness() > sqrtol ) + KILL( Q ); + else + CUTD( Q ); + } - delete rgd; + delete rgd; } /* --------------------------------------------------------------- */ @@ -453,114 +453,114 @@ static void Cut_A2H( double *RHS, const Todo& Q, int ithr ) static void Cut_H2H( double *RHS, const Todo& Q, int ithr ) { - int i1[5] = { 0, 1, 2, 6, 7 }, - i2[5] = { 3, 4, 5, 6, 7 }; + int i1[5] = { 0, 1, 2, 6, 7 }, + i2[5] = { 3, 4, 5, 6, 7 }; // For rgn Q... - CRigid *rgd; - const Rgns& R = vR[Q.iz]; - const vector& vp = R.pts[Q.ir]; - int np = vp.size(), - nu = 0; // count pts used + CRigid *rgd; + const Rgns& R = vR[Q.iz]; + const vector& vp = R.pts[Q.ir]; + int np = vp.size(), + nu = 0; // count pts used - if( regtype == 'R' ) - rgd = new CRigid; - else - rgd = new CTrans; + if( regtype == 'R' ) + rgd = new CRigid; + else + rgd = new CTrans; - double LHS[8*8]; - THmgphy* Ta = &X_AS_HMY( Xs->X[Q.iz], Q.ir ); - THmgphy* Tb; - int lastbi = -1; + double LHS[8*8]; + THmgphy* Ta = &X_AS_HMY( Xs->X[Q.iz], Q.ir ); + THmgphy* Tb; + int lastbi = -1; - Zero_Quick( LHS, RHS, 8 ); + Zero_Quick( LHS, RHS, 8 ); - // For each of its points... + // For each of its points... - for( int ip = 0; ip < np; ++ip ) { + for( int ip = 0; ip < np; ++ip ) { - CorrPnt& C = vC[vp[ip]]; + CorrPnt& C = vC[vp[ip]]; - if( !C.used || C.z1 != C.z2 ) - continue; + if( !C.used || C.z1 != C.z2 ) + continue; - Point A, B; + Point A, B; - // Which of {1,2} is the A-side? + // Which of {1,2} is the A-side? - if( C.i1 == Q.ir ) { // A is 1 + if( C.i1 == Q.ir ) { // A is 1 - if( C.i2 != lastbi ) { + if( C.i2 != lastbi ) { - if( !FLAG_ISUSED( vR[C.z2].flag[C.i2] ) ) - continue; + if( !FLAG_ISUSED( vR[C.z2].flag[C.i2] ) ) + continue; - Tb = &X_AS_HMY( Xs->X[C.z2], C.i2 ); - lastbi = C.i2; - } + Tb = &X_AS_HMY( Xs->X[C.z2], C.i2 ); + lastbi = C.i2; + } - Ta->Transform( A = C.p1 ); - Tb->Transform( B = C.p2 ); + Ta->Transform( A = C.p1 ); + Tb->Transform( B = C.p2 ); - if( pass > editdelay && A.DistSqr( B ) > Etol ) - continue; + if( pass > editdelay && A.DistSqr( B ) > Etol ) + continue; - B.x = Wb * B.x + (1 - Wb) * A.x; - B.y = Wb * B.y + (1 - Wb) * A.y; - A = C.p1; + B.x = Wb * B.x + (1 - Wb) * A.x; + B.y = Wb * B.y + (1 - Wb) * A.y; + A = C.p1; - rgd->Add( A, B ); - } - else { // A is 2 + rgd->Add( A, B ); + } + else { // A is 2 - if( C.i1 != lastbi ) { + if( C.i1 != lastbi ) { - if( !FLAG_ISUSED( vR[C.z1].flag[C.i1] ) ) - continue; + if( !FLAG_ISUSED( vR[C.z1].flag[C.i1] ) ) + continue; - Tb = &X_AS_HMY( Xs->X[C.z1], C.i1 ); - lastbi = C.i1; - } + Tb = &X_AS_HMY( Xs->X[C.z1], C.i1 ); + lastbi = C.i1; + } - Ta->Transform( A = C.p2 ); - Tb->Transform( B = C.p1 ); + Ta->Transform( A = C.p2 ); + Tb->Transform( B = C.p1 ); - if( pass > editdelay && A.DistSqr( B ) > Etol ) - continue; + if( pass > editdelay && A.DistSqr( B ) > Etol ) + continue; - B.x = Wb * B.x + (1 - Wb) * A.x; - B.y = Wb * B.y + (1 - Wb) * A.y; - A = C.p2; + B.x = Wb * B.x + (1 - Wb) * A.x; + B.y = Wb * B.y + (1 - Wb) * A.y; + A = C.p2; - rgd->Add( A, B ); - } + rgd->Add( A, B ); + } - ++nu; + ++nu; - double v[5] = { A.x, A.y, 1.0, -A.x*B.x, -A.y*B.x }; + double v[5] = { A.x, A.y, 1.0, -A.x*B.x, -A.y*B.x }; - AddConstraint_Quick( LHS, RHS, 8, 5, i1, v, B.x ); + AddConstraint_Quick( LHS, RHS, 8, 5, i1, v, B.x ); - v[3] = -A.x*B.y; - v[4] = -A.y*B.y; + v[3] = -A.x*B.y; + v[4] = -A.y*B.y; - AddConstraint_Quick( LHS, RHS, 8, 5, i2, v, B.y ); - } + AddConstraint_Quick( LHS, RHS, 8, 5, i2, v, B.y ); + } - if( nu < 4 || !Solve_Quick( LHS, RHS, 8 ) ) - KILL( Q ); - else { + if( nu < 4 || !Solve_Quick( LHS, RHS, 8 ) ) + KILL( Q ); + else { - rgd->Regularize( RHS, 8, Wr ); + rgd->Regularize( RHS, 8, Wr ); - if( X_AS_HMY( RHS, 0 ).Squareness() > sqrtol ) - KILL( Q ); - else - CUTD( Q ); - } + if( X_AS_HMY( RHS, 0 ).Squareness() > sqrtol ) + KILL( Q ); + else + CUTD( Q ); + } - delete rgd; + delete rgd; } /* --------------------------------------------------------------- */ @@ -569,163 +569,163 @@ static void Cut_H2H( double *RHS, const Todo& Q, int ithr ) static void* _A2A( void* ithr ) { - Todo Q; + Todo Q; - if( !Q.First( (long)ithr ) ) - return NULL; + if( !Q.First( (long)ithr ) ) + return NULL; - int i1[3] = { 0, 1, 2 }, - i2[3] = { 3, 4, 5 }; + int i1[3] = { 0, 1, 2 }, + i2[3] = { 3, 4, 5 }; // For each of my rgns... - do { + do { - CRigid *rgd; - Rgns& R = vR[Q.iz]; - vector& vp = R.pts[Q.ir]; - int np = vp.size(), - nu = 0; // count pts used + CRigid *rgd; + Rgns& R = vR[Q.iz]; + vector& vp = R.pts[Q.ir]; + int np = vp.size(), + nu = 0; // count pts used - if( np < 3 ) { - KILL( Q ); - continue; - } + if( np < 3 ) { + KILL( Q ); + continue; + } - if( regtype == 'R' ) - rgd = new CRigid; - else - rgd = new CTrans; + if( regtype == 'R' ) + rgd = new CRigid; + else + rgd = new CTrans; - double *RHS = X_AS_AFF( Xd->X[Q.iz], Q.ir ).t; - double LHS[6*6]; - TAffine* Ta = &X_AS_AFF( Xs->X[Q.iz], Q.ir ); - TAffine* Tb; - int lastbi, - lastbz = -1; + double *RHS = X_AS_AFF( Xd->X[Q.iz], Q.ir ).t; + double LHS[6*6]; + TAffine* Ta = &X_AS_AFF( Xs->X[Q.iz], Q.ir ); + TAffine* Tb; + int lastbi, + lastbz = -1; - Zero_Quick( LHS, RHS, 6 ); + Zero_Quick( LHS, RHS, 6 ); - // Sort the points so that cummulative rounding - // error tends to be same independent of nwks. + // Sort the points so that cummulative rounding + // error tends to be same independent of nwks. - if( !pass ) - sort( vp.begin(), vp.end(), SortPnts ); + if( !pass ) + sort( vp.begin(), vp.end(), SortPnts ); - // For each of its points... + // For each of its points... - for( int ip = 0; ip < np; ++ip ) { + for( int ip = 0; ip < np; ++ip ) { - CorrPnt& C = vC[vp[ip]]; + CorrPnt& C = vC[vp[ip]]; - if( !C.used ) - continue; + if( !C.used ) + continue; - Point A, B; + Point A, B; - // Which of {1,2} is the A-side? + // Which of {1,2} is the A-side? - if( C.z1 == Q.iz && C.i1 == Q.ir ) { // A is 1 + if( C.z1 == Q.iz && C.i1 == Q.ir ) { // A is 1 - if( C.z2 != lastbz ) { - lastbz = C.z2; - lastbi = -1; - } + if( C.z2 != lastbz ) { + lastbz = C.z2; + lastbi = -1; + } - if( C.i2 != lastbi ) { + if( C.i2 != lastbi ) { - if( !FLAG_ISUSED( vR[C.z2].flag[C.i2] ) ) { + if( !FLAG_ISUSED( vR[C.z2].flag[C.i2] ) ) { - // Here's a pnt that's 'used' referencing - // a rgn that's not. It's inefficient, so - // we'll get such points marked 'not used'. + // Here's a pnt that's 'used' referencing + // a rgn that's not. It's inefficient, so + // we'll get such points marked 'not used'. - MARK( Todo( C.z2, C.i2 ) ); - continue; - } + MARK( Todo( C.z2, C.i2 ) ); + continue; + } - Tb = &X_AS_AFF( Xs->X[C.z2], C.i2 ); - lastbi = C.i2; - } + Tb = &X_AS_AFF( Xs->X[C.z2], C.i2 ); + lastbi = C.i2; + } - Ta->Transform( A = C.p1 ); - Tb->Transform( B = C.p2 ); + Ta->Transform( A = C.p1 ); + Tb->Transform( B = C.p2 ); - if( pass > editdelay && A.DistSqr( B ) > Etol ) - continue; + if( pass > editdelay && A.DistSqr( B ) > Etol ) + continue; - B.x = Wb * B.x + (1 - Wb) * A.x; - B.y = Wb * B.y + (1 - Wb) * A.y; - A = C.p1; + B.x = Wb * B.x + (1 - Wb) * A.x; + B.y = Wb * B.y + (1 - Wb) * A.y; + A = C.p1; - rgd->Add( A, B ); - } - else { // A is 2 + rgd->Add( A, B ); + } + else { // A is 2 - if( C.z1 != lastbz ) { - lastbz = C.z1; - lastbi = -1; - } + if( C.z1 != lastbz ) { + lastbz = C.z1; + lastbi = -1; + } - if( C.i1 != lastbi ) { + if( C.i1 != lastbi ) { - if( !FLAG_ISUSED( vR[C.z1].flag[C.i1] ) ) { + if( !FLAG_ISUSED( vR[C.z1].flag[C.i1] ) ) { - // Here's a pnt that's 'used' referencing - // a rgn that's not. It's inefficient, so - // we'll get such points marked 'not used'. + // Here's a pnt that's 'used' referencing + // a rgn that's not. It's inefficient, so + // we'll get such points marked 'not used'. - MARK( Todo( C.z1, C.i1 ) ); - continue; - } + MARK( Todo( C.z1, C.i1 ) ); + continue; + } - Tb = &X_AS_AFF( Xs->X[C.z1], C.i1 ); - lastbi = C.i1; - } + Tb = &X_AS_AFF( Xs->X[C.z1], C.i1 ); + lastbi = C.i1; + } - Ta->Transform( A = C.p2 ); - Tb->Transform( B = C.p1 ); + Ta->Transform( A = C.p2 ); + Tb->Transform( B = C.p1 ); - if( pass > editdelay && A.DistSqr( B ) > Etol ) - continue; + if( pass > editdelay && A.DistSqr( B ) > Etol ) + continue; - B.x = Wb * B.x + (1 - Wb) * A.x; - B.y = Wb * B.y + (1 - Wb) * A.y; - A = C.p2; + B.x = Wb * B.x + (1 - Wb) * A.x; + B.y = Wb * B.y + (1 - Wb) * A.y; + A = C.p2; - rgd->Add( A, B ); - } + rgd->Add( A, B ); + } - ++nu; + ++nu; - double v[3] = { A.x, A.y, 1.0 }; + double v[3] = { A.x, A.y, 1.0 }; - AddConstraint_Quick( LHS, RHS, 6, 3, i1, v, B.x ); - AddConstraint_Quick( LHS, RHS, 6, 3, i2, v, B.y ); - } + AddConstraint_Quick( LHS, RHS, 6, 3, i1, v, B.x ); + AddConstraint_Quick( LHS, RHS, 6, 3, i2, v, B.y ); + } - if( nu < 3 ) - KILL( Q ); - else if( !Solve_Quick( LHS, RHS, 6 ) ) - Cut_A2A( RHS, Q, (long)ithr ); - else { + if( nu < 3 ) + KILL( Q ); + else if( !Solve_Quick( LHS, RHS, 6 ) ) + Cut_A2A( RHS, Q, (long)ithr ); + else { - rgd->Regularize( RHS, 6, Wr ); + rgd->Regularize( RHS, 6, Wr ); - if( pass >= editdelay - && X_AS_AFF( RHS, 0 ).Squareness() > sqrtol ) { + if( pass >= editdelay + && X_AS_AFF( RHS, 0 ).Squareness() > sqrtol ) { - Cut_A2A( RHS, Q, (long)ithr ); - } - else if( nu < np ) - ShortenList( Q, (long)ithr, 3 ); - } + Cut_A2A( RHS, Q, (long)ithr ); + } + else if( nu < np ) + ShortenList( Q, (long)ithr, 3 ); + } - delete rgd; + delete rgd; - } while( Q.Next() ); + } while( Q.Next() ); - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -748,160 +748,160 @@ static void* _A2A( void* ithr ) // static void* _A2H( void* ithr ) { - Todo Q; + Todo Q; - if( !Q.First( (long)ithr ) ) - return NULL; + if( !Q.First( (long)ithr ) ) + return NULL; - int i1[5] = { 0, 1, 2, 6, 7 }, - i2[5] = { 3, 4, 5, 6, 7 }; + int i1[5] = { 0, 1, 2, 6, 7 }, + i2[5] = { 3, 4, 5, 6, 7 }; // For each of my rgns... - do { + do { - CRigid *rgd; - Rgns& R = vR[Q.iz]; - vector& vp = R.pts[Q.ir]; - int np = vp.size(), - nu = 0; // count pts used + CRigid *rgd; + Rgns& R = vR[Q.iz]; + vector& vp = R.pts[Q.ir]; + int np = vp.size(), + nu = 0; // count pts used - if( np < 4 ) { - KILL( Q ); - continue; - } + if( np < 4 ) { + KILL( Q ); + continue; + } - if( regtype == 'R' ) - rgd = new CRigid; - else - rgd = new CTrans; + if( regtype == 'R' ) + rgd = new CRigid; + else + rgd = new CTrans; - double *RHS = X_AS_HMY( Xd->X[Q.iz], Q.ir ).t; - double LHS[8*8]; - TAffine* Ta = &X_AS_AFF( Xs->X[Q.iz], Q.ir ); - TAffine* Tb; - int lastbi, - lastbz = -1; + double *RHS = X_AS_HMY( Xd->X[Q.iz], Q.ir ).t; + double LHS[8*8]; + TAffine* Ta = &X_AS_AFF( Xs->X[Q.iz], Q.ir ); + TAffine* Tb; + int lastbi, + lastbz = -1; - Zero_Quick( LHS, RHS, 8 ); + Zero_Quick( LHS, RHS, 8 ); - // Sort the points so that cummulative rounding - // error tends to be same independent of nwks. + // Sort the points so that cummulative rounding + // error tends to be same independent of nwks. - if( !pass ) - sort( vp.begin(), vp.end(), SortPnts ); + if( !pass ) + sort( vp.begin(), vp.end(), SortPnts ); - // For each of its points... + // For each of its points... - for( int ip = 0; ip < np; ++ip ) { + for( int ip = 0; ip < np; ++ip ) { - const CorrPnt& C = vC[vp[ip]]; + const CorrPnt& C = vC[vp[ip]]; - if( !C.used ) - continue; + if( !C.used ) + continue; - Point A, B; + Point A, B; - // Which of {1,2} is the A-side? + // Which of {1,2} is the A-side? - if( C.z1 == Q.iz && C.i1 == Q.ir ) { // A is 1 + if( C.z1 == Q.iz && C.i1 == Q.ir ) { // A is 1 - if( C.z2 != lastbz ) { - lastbz = C.z2; - lastbi = -1; - } + if( C.z2 != lastbz ) { + lastbz = C.z2; + lastbi = -1; + } - if( C.i2 != lastbi ) { + if( C.i2 != lastbi ) { - if( !FLAG_ISUSED( vR[C.z2].flag[C.i2] ) ) { + if( !FLAG_ISUSED( vR[C.z2].flag[C.i2] ) ) { - // Here's a pnt that's 'used' referencing - // a rgn that's not. It's inefficient, so - // we'll get such points marked 'not used'. + // Here's a pnt that's 'used' referencing + // a rgn that's not. It's inefficient, so + // we'll get such points marked 'not used'. - MARK( Todo( C.z2, C.i2 ) ); - continue; - } + MARK( Todo( C.z2, C.i2 ) ); + continue; + } - Tb = &X_AS_AFF( Xs->X[C.z2], C.i2 ); - lastbi = C.i2; - } + Tb = &X_AS_AFF( Xs->X[C.z2], C.i2 ); + lastbi = C.i2; + } - Ta->Transform( A = C.p1 ); - Tb->Transform( B = C.p2 ); + Ta->Transform( A = C.p1 ); + Tb->Transform( B = C.p2 ); - B.x = Wb * B.x + (1 - Wb) * A.x; - B.y = Wb * B.y + (1 - Wb) * A.y; - A = C.p1; + B.x = Wb * B.x + (1 - Wb) * A.x; + B.y = Wb * B.y + (1 - Wb) * A.y; + A = C.p1; - rgd->Add( A, B ); - } - else { // A is 2 + rgd->Add( A, B ); + } + else { // A is 2 - if( C.z1 != lastbz ) { - lastbz = C.z1; - lastbi = -1; - } + if( C.z1 != lastbz ) { + lastbz = C.z1; + lastbi = -1; + } - if( C.i1 != lastbi ) { + if( C.i1 != lastbi ) { - if( !FLAG_ISUSED( vR[C.z1].flag[C.i1] ) ) { + if( !FLAG_ISUSED( vR[C.z1].flag[C.i1] ) ) { - // Here's a pnt that's 'used' referencing - // a rgn that's not. It's inefficient, so - // we'll get those point marked 'not used'. + // Here's a pnt that's 'used' referencing + // a rgn that's not. It's inefficient, so + // we'll get those point marked 'not used'. - MARK( Todo( C.z1, C.i1 ) ); - continue; - } + MARK( Todo( C.z1, C.i1 ) ); + continue; + } - Tb = &X_AS_AFF( Xs->X[C.z1], C.i1 ); - lastbi = C.i1; - } + Tb = &X_AS_AFF( Xs->X[C.z1], C.i1 ); + lastbi = C.i1; + } - Ta->Transform( A = C.p2 ); - Tb->Transform( B = C.p1 ); + Ta->Transform( A = C.p2 ); + Tb->Transform( B = C.p1 ); - B.x = Wb * B.x + (1 - Wb) * A.x; - B.y = Wb * B.y + (1 - Wb) * A.y; - A = C.p2; + B.x = Wb * B.x + (1 - Wb) * A.x; + B.y = Wb * B.y + (1 - Wb) * A.y; + A = C.p2; - rgd->Add( A, B ); - } + rgd->Add( A, B ); + } - ++nu; + ++nu; - double v[5] = { A.x, A.y, 1.0, -A.x*B.x, -A.y*B.x }; + double v[5] = { A.x, A.y, 1.0, -A.x*B.x, -A.y*B.x }; - AddConstraint_Quick( LHS, RHS, 8, 5, i1, v, B.x ); + AddConstraint_Quick( LHS, RHS, 8, 5, i1, v, B.x ); - v[3] = -A.x*B.y; - v[4] = -A.y*B.y; + v[3] = -A.x*B.y; + v[4] = -A.y*B.y; - AddConstraint_Quick( LHS, RHS, 8, 5, i2, v, B.y ); - } + AddConstraint_Quick( LHS, RHS, 8, 5, i2, v, B.y ); + } - if( nu < 4 ) - KILL( Q ); - else if( !Solve_Quick( LHS, RHS, 8 ) ) - Cut_A2H( RHS, Q, (long)ithr ); - else { + if( nu < 4 ) + KILL( Q ); + else if( !Solve_Quick( LHS, RHS, 8 ) ) + Cut_A2H( RHS, Q, (long)ithr ); + else { - rgd->Regularize( RHS, 8, Wr ); + rgd->Regularize( RHS, 8, Wr ); - if( X_AS_HMY( RHS, 0 ).Squareness() > sqrtol ) { + if( X_AS_HMY( RHS, 0 ).Squareness() > sqrtol ) { - Cut_A2H( RHS, Q, (long)ithr ); - } - else if( nu < np ) - ShortenList( Q, (long)ithr, 4 ); - } + Cut_A2H( RHS, Q, (long)ithr ); + } + else if( nu < np ) + ShortenList( Q, (long)ithr, 4 ); + } - delete rgd; + delete rgd; - } while( Q.Next() ); + } while( Q.Next() ); - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -910,167 +910,167 @@ static void* _A2H( void* ithr ) static void* _H2H( void* ithr ) { - Todo Q; + Todo Q; - if( !Q.First( (long)ithr ) ) - return NULL; + if( !Q.First( (long)ithr ) ) + return NULL; - int i1[5] = { 0, 1, 2, 6, 7 }, - i2[5] = { 3, 4, 5, 6, 7 }; + int i1[5] = { 0, 1, 2, 6, 7 }, + i2[5] = { 3, 4, 5, 6, 7 }; // For each of my rgns... - do { + do { - CRigid *rgd; - Rgns& R = vR[Q.iz]; - vector& vp = R.pts[Q.ir]; - int np = vp.size(), - nu = 0; // count pts used + CRigid *rgd; + Rgns& R = vR[Q.iz]; + vector& vp = R.pts[Q.ir]; + int np = vp.size(), + nu = 0; // count pts used - if( np < 4 ) { - KILL( Q ); - continue; - } + if( np < 4 ) { + KILL( Q ); + continue; + } - if( regtype == 'R' ) - rgd = new CRigid; - else - rgd = new CTrans; + if( regtype == 'R' ) + rgd = new CRigid; + else + rgd = new CTrans; - double *RHS = X_AS_HMY( Xd->X[Q.iz], Q.ir ).t; - double LHS[8*8]; - THmgphy* Ta = &X_AS_HMY( Xs->X[Q.iz], Q.ir ); - THmgphy* Tb; - int lastbi, - lastbz = -1; + double *RHS = X_AS_HMY( Xd->X[Q.iz], Q.ir ).t; + double LHS[8*8]; + THmgphy* Ta = &X_AS_HMY( Xs->X[Q.iz], Q.ir ); + THmgphy* Tb; + int lastbi, + lastbz = -1; - Zero_Quick( LHS, RHS, 8 ); + Zero_Quick( LHS, RHS, 8 ); - // Sort the points so that cummulative rounding - // error tends to be same independent of nwks. + // Sort the points so that cummulative rounding + // error tends to be same independent of nwks. - if( !pass ) - sort( vp.begin(), vp.end(), SortPnts ); + if( !pass ) + sort( vp.begin(), vp.end(), SortPnts ); - // For each of its points... + // For each of its points... - for( int ip = 0; ip < np; ++ip ) { + for( int ip = 0; ip < np; ++ip ) { - CorrPnt& C = vC[vp[ip]]; + CorrPnt& C = vC[vp[ip]]; - if( !C.used ) - continue; + if( !C.used ) + continue; - Point A, B; + Point A, B; - // Which of {1,2} is the A-side? + // Which of {1,2} is the A-side? - if( C.z1 == Q.iz && C.i1 == Q.ir ) { // A is 1 + if( C.z1 == Q.iz && C.i1 == Q.ir ) { // A is 1 - if( C.z2 != lastbz ) { - lastbz = C.z2; - lastbi = -1; - } + if( C.z2 != lastbz ) { + lastbz = C.z2; + lastbi = -1; + } - if( C.i2 != lastbi ) { + if( C.i2 != lastbi ) { - if( !FLAG_ISUSED( vR[C.z2].flag[C.i2] ) ) { + if( !FLAG_ISUSED( vR[C.z2].flag[C.i2] ) ) { - // Here's a pnt that's 'used' referencing - // a rgn that's not. It's inefficient, so - // we'll get those point marked 'not used'. + // Here's a pnt that's 'used' referencing + // a rgn that's not. It's inefficient, so + // we'll get those point marked 'not used'. - MARK( Todo( C.z2, C.i2 ) ); - continue; - } + MARK( Todo( C.z2, C.i2 ) ); + continue; + } - Tb = &X_AS_HMY( Xs->X[C.z2], C.i2 ); - lastbi = C.i2; - } + Tb = &X_AS_HMY( Xs->X[C.z2], C.i2 ); + lastbi = C.i2; + } - Ta->Transform( A = C.p1 ); - Tb->Transform( B = C.p2 ); + Ta->Transform( A = C.p1 ); + Tb->Transform( B = C.p2 ); - if( pass > editdelay && A.DistSqr( B ) > Etol ) - continue; + if( pass > editdelay && A.DistSqr( B ) > Etol ) + continue; - B.x = Wb * B.x + (1 - Wb) * A.x; - B.y = Wb * B.y + (1 - Wb) * A.y; - A = C.p1; + B.x = Wb * B.x + (1 - Wb) * A.x; + B.y = Wb * B.y + (1 - Wb) * A.y; + A = C.p1; - rgd->Add( A, B ); - } - else { // A is 2 + rgd->Add( A, B ); + } + else { // A is 2 - if( C.z1 != lastbz ) { - lastbz = C.z1; - lastbi = -1; - } + if( C.z1 != lastbz ) { + lastbz = C.z1; + lastbi = -1; + } - if( C.i1 != lastbi ) { + if( C.i1 != lastbi ) { - if( !FLAG_ISUSED( vR[C.z1].flag[C.i1] ) ) { + if( !FLAG_ISUSED( vR[C.z1].flag[C.i1] ) ) { - // Here's a pnt that's 'used' referencing - // a rgn that's not. It's inefficient, so - // we'll get those point marked 'not used'. + // Here's a pnt that's 'used' referencing + // a rgn that's not. It's inefficient, so + // we'll get those point marked 'not used'. - MARK( Todo( C.z1, C.i1 ) ); - continue; - } + MARK( Todo( C.z1, C.i1 ) ); + continue; + } - Tb = &X_AS_HMY( Xs->X[C.z1], C.i1 ); - lastbi = C.i1; - } + Tb = &X_AS_HMY( Xs->X[C.z1], C.i1 ); + lastbi = C.i1; + } - Ta->Transform( A = C.p2 ); - Tb->Transform( B = C.p1 ); + Ta->Transform( A = C.p2 ); + Tb->Transform( B = C.p1 ); - if( pass > editdelay && A.DistSqr( B ) > Etol ) - continue; + if( pass > editdelay && A.DistSqr( B ) > Etol ) + continue; - B.x = Wb * B.x + (1 - Wb) * A.x; - B.y = Wb * B.y + (1 - Wb) * A.y; - A = C.p2; + B.x = Wb * B.x + (1 - Wb) * A.x; + B.y = Wb * B.y + (1 - Wb) * A.y; + A = C.p2; - rgd->Add( A, B ); - } + rgd->Add( A, B ); + } - ++nu; + ++nu; - double v[5] = { A.x, A.y, 1.0, -A.x*B.x, -A.y*B.x }; + double v[5] = { A.x, A.y, 1.0, -A.x*B.x, -A.y*B.x }; - AddConstraint_Quick( LHS, RHS, 8, 5, i1, v, B.x ); + AddConstraint_Quick( LHS, RHS, 8, 5, i1, v, B.x ); - v[3] = -A.x*B.y; - v[4] = -A.y*B.y; + v[3] = -A.x*B.y; + v[4] = -A.y*B.y; - AddConstraint_Quick( LHS, RHS, 8, 5, i2, v, B.y ); - } + AddConstraint_Quick( LHS, RHS, 8, 5, i2, v, B.y ); + } - if( nu < 4 ) - KILL( Q ); - else if( !Solve_Quick( LHS, RHS, 8 ) ) - Cut_H2H( RHS, Q, (long)ithr ); - else { + if( nu < 4 ) + KILL( Q ); + else if( !Solve_Quick( LHS, RHS, 8 ) ) + Cut_H2H( RHS, Q, (long)ithr ); + else { - rgd->Regularize( RHS, 8, Wr ); + rgd->Regularize( RHS, 8, Wr ); - if( pass >= editdelay - && X_AS_HMY( RHS, 0 ).Squareness() > sqrtol ) { + if( pass >= editdelay + && X_AS_HMY( RHS, 0 ).Squareness() > sqrtol ) { - Cut_H2H( RHS, Q, (long)ithr ); - } - else if( nu < np ) - ShortenList( Q, (long)ithr, 4 ); - } + Cut_H2H( RHS, Q, (long)ithr ); + } + else if( nu < np ) + ShortenList( Q, (long)ithr, 4 ); + } - delete rgd; + delete rgd; - } while( Q.Next() ); + } while( Q.Next() ); - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -1109,86 +1109,86 @@ static void* _H2H( void* ithr ) // static void UpdateFlags() { - int ncut = 0, nkil = 0; - int nt = vthr.size(); + int ncut = 0, nkil = 0; + int nt = vthr.size(); // For each thread's lists... - for( int it = 0; it < nt; ++it ) { + for( int it = 0; it < nt; ++it ) { - vector& vmrk = vthr[it].vmark; - vector& vcut = vthr[it].vcutd; - vector& vkil = vthr[it].vkill; - int ne; // n edits + vector& vmrk = vthr[it].vmark; + vector& vcut = vthr[it].vcutd; + vector& vkil = vthr[it].vkill; + int ne; // n edits - // Process marks + // Process marks - ne = vmrk.size(); + ne = vmrk.size(); - for( int ie = 0; ie < ne; ++ie ) { + for( int ie = 0; ie < ne; ++ie ) { - const Todo& e = vmrk[ie]; - Rgns& R = vR[e.iz]; - vector& vp = R.pts[e.ir]; - int np = vp.size(); + const Todo& e = vmrk[ie]; + Rgns& R = vR[e.iz]; + vector& vp = R.pts[e.ir]; + int np = vp.size(); - // mark all its pnts - for( int ip = 0; ip < np; ++ip ) - vC[vp[ip]].used = false; - } + // mark all its pnts + for( int ip = 0; ip < np; ++ip ) + vC[vp[ip]].used = false; + } - // Process cuts + // Process cuts - ne = vcut.size(); - ncut += ne; + ne = vcut.size(); + ncut += ne; - for( int ie = 0; ie < ne; ++ie ) { + for( int ie = 0; ie < ne; ++ie ) { - const Todo& e = vcut[ie]; - Rgns& R = vR[e.iz]; - vector& vp = R.pts[e.ir]; - int np = vp.size(); + const Todo& e = vcut[ie]; + Rgns& R = vR[e.iz]; + vector& vp = R.pts[e.ir]; + int np = vp.size(); - // mark rgn cutd - FLAG_ADDCUTD( R.flag[e.ir] ); + // mark rgn cutd + FLAG_ADDCUTD( R.flag[e.ir] ); - // mark its cross-pnts - for( int ip = 0; ip < np; ++ip ) { + // mark its cross-pnts + for( int ip = 0; ip < np; ++ip ) { - CorrPnt& C = vC[vp[ip]]; + CorrPnt& C = vC[vp[ip]]; - if( C.z1 != C.z2 ) - C.used = false; - } - } + if( C.z1 != C.z2 ) + C.used = false; + } + } - // Process kills + // Process kills - ne = vkil.size(); - nkil += ne; + ne = vkil.size(); + nkil += ne; - for( int ie = 0; ie < ne; ++ie ) { + for( int ie = 0; ie < ne; ++ie ) { - const Todo& e = vkil[ie]; - Rgns& R = vR[e.iz]; - vector& vp = R.pts[e.ir]; - int np = vp.size(); + const Todo& e = vkil[ie]; + Rgns& R = vR[e.iz]; + vector& vp = R.pts[e.ir]; + int np = vp.size(); - // mark rgn killed - FLAG_ADDKILL( R.flag[e.ir] ); + // mark rgn killed + FLAG_ADDKILL( R.flag[e.ir] ); - // mark all its pnts - for( int ip = 0; ip < np; ++ip ) - vC[vp[ip]].used = false; - } - } + // mark all its pnts + for( int ip = 0; ip < np; ++ip ) + vC[vp[ip]].used = false; + } + } // Report activity this pass - if( ncut || nkil ) { - printf( "Pass %d: tiles [cutd, killed] = [%d, %d].\n", - pass, ncut, nkil ); - } + if( ncut || nkil ) { + printf( "Pass %d: tiles [cutd, killed] = [%d, %d].\n", + pass, ncut, nkil ); + } } /* --------------------------------------------------------------- */ @@ -1199,20 +1199,20 @@ static void Do1Pass( EZThreadproc proc ) { // multithreaded phase - vthr.clear(); - vthr.resize( nthr ); + vthr.clear(); + vthr.resize( nthr ); - if( !EZThreads( proc, nthr, 1, "Solveproc" ) ) - exit( 42 ); + if( !EZThreads( proc, nthr, 1, "Solveproc" ) ) + exit( 42 ); // single-threaded phase - UpdateFlags(); - vthr.clear(); + UpdateFlags(); + vthr.clear(); // synchronize - Xd->Updt(); + Xd->Updt(); } /* --------------------------------------------------------------- */ @@ -1232,9 +1232,9 @@ static void Do1Pass( EZThreadproc proc ) // void SetSolveParams( int type, double inWr, double inEtol ) { - Etol = inEtol * inEtol; - Wr = inWr; - regtype = type; + Etol = inEtol * inEtol; + Wr = inWr; + regtype = type; } /* --------------------------------------------------------------- */ @@ -1249,39 +1249,39 @@ void SetSolveParams( int type, double inWr, double inEtol ) // void Solve( XArray &Xsrc, XArray &Xdst, int iters ) { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); /* ---------------------- */ /* Mode specific settings */ /* ---------------------- */ - EZThreadproc proc; - int cS, cD; - - if( Xsrc.NE == 6 ) { - - cS = 'A'; - - if( Xdst.NE == 6 ) { - editdelay = max( iters / 4, 200 ); - proc = _A2A; - cD = 'A'; - } - else { - editdelay = 0; // not applied in A2H - proc = _A2H; - cD = 'H'; - } - } - else { - editdelay = max( iters / 100, 4 ); - proc = _H2H; - cS = 'H'; - cD = 'H'; - } - - printf( "Solve: %c to %c (Wr %c, %g Etol %g iters %d)\n", - cS, cD, regtype, Wr, sqrt( Etol ), iters ); + EZThreadproc proc; + int cS, cD; + + if( Xsrc.NE == 6 ) { + + cS = 'A'; + + if( Xdst.NE == 6 ) { + editdelay = max( iters / 4, 200 ); + proc = _A2A; + cD = 'A'; + } + else { + editdelay = 0; // not applied in A2H + proc = _A2H; + cD = 'H'; + } + } + else { + editdelay = max( iters / 100, 4 ); + proc = _H2H; + cS = 'H'; + cD = 'H'; + } + + printf( "Solve: %c to %c (Wr %c, %g Etol %g iters %d)\n", + cS, cD, regtype, Wr, sqrt( Etol ), iters ); /* -------- */ /* Set nthr */ @@ -1290,36 +1290,36 @@ void Solve( XArray &Xsrc, XArray &Xdst, int iters ) // Balance work/thread vs. thread overhead. // Revisit if workload altered. - const int minrgnsperthr = 8; + const int minrgnsperthr = 8; - int nrgn = Todo::RgnCount(); + int nrgn = Todo::RgnCount(); - nthr = maxthreads; + nthr = maxthreads; - while( nthr > 1 && nrgn < minrgnsperthr * nthr ) - --nthr; + while( nthr > 1 && nrgn < minrgnsperthr * nthr ) + --nthr; - printf( "NThrd: %d\n", nthr ); + printf( "NThrd: %d\n", nthr ); /* ------- */ /* Iterate */ /* ------- */ - Xs = &Xsrc; - Xd = &Xdst; + Xs = &Xsrc; + Xd = &Xdst; - for( pass = 0; pass < iters; ++pass ) { + for( pass = 0; pass < iters; ++pass ) { - Do1Pass( proc ); + Do1Pass( proc ); - // swap Xs<->Xd - XArray *Xt = Xs; Xs = Xd; Xd = Xt; + // swap Xs<->Xd + XArray *Xt = Xs; Xs = Xd; Xd = Xt; - if( !((long)DeltaSeconds( t0 ) % 300) ) - fflush( stdout ); - } + if( !((long)DeltaSeconds( t0 ) % 300) ) + fflush( stdout ); + } - StopTiming( stdout, "Solve", t0 ); + StopTiming( stdout, "Solve", t0 ); } diff --git a/1_LSQw/lsq_Split.cpp b/1_LSQw/lsq_Split.cpp index 5895d87..f028b66 100644 --- a/1_LSQw/lsq_Split.cpp +++ b/1_LSQw/lsq_Split.cpp @@ -29,9 +29,9 @@ using namespace std; class GDrty { // Has this worker dirtied his L/R? public: - uint8 L, R; + uint8 L, R; public: - GDrty() : L(1), R(1) {}; + GDrty() : L(1), R(1) {}; }; /* --------------------------------------------------------------- */ @@ -44,9 +44,9 @@ static vector gdrty; static vector drtyS, drtyD; static vector vzd; static int nthr, - saveclr, - maxspan, - zs; + saveclr, + maxspan, + zs; @@ -61,12 +61,12 @@ static int nthr, // void Split::Resize() { - int nz = zohi - zolo + 1; + int nz = zohi - zolo + 1; - K.resize( nz ); + K.resize( nz ); - for( int iz = 0; iz < nz; ++iz ) - K[iz].resize( vR[iz].nr, 0 ); + for( int iz = 0; iz < nz; ++iz ) + K[iz].resize( vR[iz].nr, 0 ); } /* --------------------------------------------------------------- */ @@ -75,70 +75,70 @@ void Split::Resize() static void* _ColorMontages( void* ithr ) { - for( int iz = zilo + (long)ithr; iz <= zihi; iz += nthr ) { + for( int iz = zilo + (long)ithr; iz <= zihi; iz += nthr ) { - const Rgns& R = vR[iz]; - vector& k = ME->K[iz]; - int clr = (R.z ? PERZ * R.z : 1) - 1; + const Rgns& R = vR[iz]; + vector& k = ME->K[iz]; + int clr = (R.z ? PERZ * R.z : 1) - 1; - for( int ir = 0; ir < R.nr; ++ir ) { + for( int ir = 0; ir < R.nr; ++ir ) { - // Valid tile? - if( !FLAG_ISUSED( R.flag[ir] ) ) - continue; + // Valid tile? + if( !FLAG_ISUSED( R.flag[ir] ) ) + continue; - // Already assigned? - if( k[ir] ) - continue; + // Already assigned? + if( k[ir] ) + continue; - // New seed; new stack; new color - stack s; - s.push( ir ); - ++clr; + // New seed; new stack; new color + stack s; + s.push( ir ); + ++clr; - while( !s.empty() ) { + while( !s.empty() ) { - // Process this guy + // Process this guy - int jr = s.top(); - s.pop(); + int jr = s.top(); + s.pop(); - if( k[jr] ) - continue; + if( k[jr] ) + continue; - k[jr] = clr; + k[jr] = clr; - // Push neighbors that are: - // same-layer, virgin, valid. + // Push neighbors that are: + // same-layer, virgin, valid. - const vector& P = R.pts[jr]; - int np = P.size(), prev = -1; + const vector& P = R.pts[jr]; + int np = P.size(), prev = -1; - for( int ip = 0; ip < np; ++ip ) { + for( int ip = 0; ip < np; ++ip ) { - const CorrPnt& C = vC[P[ip]]; + const CorrPnt& C = vC[P[ip]]; - if( !C.used ) - continue; + if( !C.used ) + continue; - if( C.z1 != iz || C.z2 != iz ) - continue; + if( C.z1 != iz || C.z2 != iz ) + continue; - int other = (C.i1 == jr ? C.i2 : C.i1); + int other = (C.i1 == jr ? C.i2 : C.i1); - if( other == prev ) - continue; + if( other == prev ) + continue; - prev = other; + prev = other; - if( !k[other] && FLAG_ISUSED( R.flag[other] ) ) - s.push( other ); - } - } - } - } + if( !k[other] && FLAG_ISUSED( R.flag[other] ) ) + s.push( other ); + } + } + } + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -149,16 +149,16 @@ static void* _ColorMontages( void* ithr ) // void Split::ColorMontages() { - int nz = zihi - zilo + 1; + int nz = zihi - zilo + 1; - ME = (Split*)this; - nthr = maxthreads; + ME = (Split*)this; + nthr = maxthreads; - if( nthr > nz ) - nthr = nz; + if( nthr > nz ) + nthr = nz; - if( !EZThreads( _ColorMontages, nthr, 1, "_ColorMontages" ) ) - exit( 42 ); + if( !EZThreads( _ColorMontages, nthr, 1, "_ColorMontages" ) ) + exit( 42 ); } /* --------------------------------------------------------------- */ @@ -169,24 +169,24 @@ void Split::GUpdt() { // Send my GDrty to master; then get global vector - if( wkid > 0 ) { + if( wkid > 0 ) { - // send mine - MPISend( &gdrty[wkid], sizeof(GDrty), 0, wkid ); + // send mine + MPISend( &gdrty[wkid], sizeof(GDrty), 0, wkid ); - // get all - MPIRecv( &gdrty[0], nwks * sizeof(GDrty), 0, wkid ); - } - else if( nwks > 1 ) { + // get all + MPIRecv( &gdrty[0], nwks * sizeof(GDrty), 0, wkid ); + } + else if( nwks > 1 ) { - // get each worker - for( int iw = 1; iw < nwks; ++iw ) - MPIRecv( &gdrty[iw], sizeof(GDrty), iw, iw ); + // get each worker + for( int iw = 1; iw < nwks; ++iw ) + MPIRecv( &gdrty[iw], sizeof(GDrty), iw, iw ); - // send each worker - for( int iw = 1; iw < nwks; ++iw ) - MPISend( &gdrty[0], nwks * sizeof(GDrty), iw, iw ); - } + // send each worker + for( int iw = 1; iw < nwks; ++iw ) + MPISend( &gdrty[0], nwks * sizeof(GDrty), iw, iw ); + } } /* --------------------------------------------------------------- */ @@ -195,40 +195,40 @@ void Split::GUpdt() bool Split::KSend( int zlo, int zhi, int toLorR ) { - void *buf; - int bytes, - wdst; + void *buf; + int bytes, + wdst; - if( toLorR == 'L' ) { + if( toLorR == 'L' ) { - if( !gdrty[wkid].L ) - return true; + if( !gdrty[wkid].L ) + return true; - wdst = wkid - 1; + wdst = wkid - 1; - if( wdst < 0 ) - return true; - } - else { + if( wdst < 0 ) + return true; + } + else { - if( !gdrty[wkid].R ) - return true; + if( !gdrty[wkid].R ) + return true; - wdst = wkid + 1; + wdst = wkid + 1; - if( wdst >= nwks ) - return true; - } + if( wdst >= nwks ) + return true; + } - for( int iz = zlo; iz <= zhi; ++iz ) { + for( int iz = zlo; iz <= zhi; ++iz ) { - buf = (void*)&K[iz][0]; - bytes = sizeof(int) * vR[iz].nr; + buf = (void*)&K[iz][0]; + bytes = sizeof(int) * vR[iz].nr; - MPISend( buf, bytes, wdst, iz - zlo ); - } + MPISend( buf, bytes, wdst, iz - zlo ); + } - return true; + return true; } /* --------------------------------------------------------------- */ @@ -237,39 +237,39 @@ bool Split::KSend( int zlo, int zhi, int toLorR ) bool Split::KRecv( int zlo, int zhi, int fmLorR ) { - void *buf; - int bytes, - wsrc; + void *buf; + int bytes, + wsrc; - if( fmLorR == 'L' ) { + if( fmLorR == 'L' ) { - wsrc = wkid - 1; + wsrc = wkid - 1; - if( wsrc < 0 ) - return true; + if( wsrc < 0 ) + return true; - if( !gdrty[wsrc].R ) - return true; - } - else { - wsrc = wkid + 1; + if( !gdrty[wsrc].R ) + return true; + } + else { + wsrc = wkid + 1; - if( wsrc >= nwks ) - return true; + if( wsrc >= nwks ) + return true; - if( !gdrty[wsrc].L ) - return true; - } + if( !gdrty[wsrc].L ) + return true; + } - for( int iz = zlo; iz <= zhi; ++iz ) { + for( int iz = zlo; iz <= zhi; ++iz ) { - buf = (void*)&K[iz][0]; - bytes = sizeof(int) * vR[iz].nr; + buf = (void*)&K[iz][0]; + bytes = sizeof(int) * vR[iz].nr; - MPIRecv( buf, bytes, wsrc, iz - zlo ); - } + MPIRecv( buf, bytes, wsrc, iz - zlo ); + } - return true; + return true; } /* --------------------------------------------------------------- */ @@ -278,8 +278,8 @@ bool Split::KRecv( int zlo, int zhi, int fmLorR ) bool Split::KUpdt() { - if( nwks <= 1 ) - return true; + if( nwks <= 1 ) + return true; // To avoid deadlocks, we arrange that at any given time, // any node is just sending or just receiving. Easily done @@ -287,31 +287,31 @@ bool Split::KUpdt() // Odd send - if( wkid & 1 ) { + if( wkid & 1 ) { - KSend( zLlo, zLhi, 'L' ); - KSend( zRlo, zRhi, 'R' ); - } - else { + KSend( zLlo, zLhi, 'L' ); + KSend( zRlo, zRhi, 'R' ); + } + else { - KRecv( zihi + 1, zohi, 'R' ); - KRecv( zolo, zilo - 1, 'L' ); - } + KRecv( zihi + 1, zohi, 'R' ); + KRecv( zolo, zilo - 1, 'L' ); + } // Even send - if( !(wkid & 1) ) { + if( !(wkid & 1) ) { - KSend( zLlo, zLhi, 'L' ); - KSend( zRlo, zRhi, 'R' ); - } - else { + KSend( zLlo, zLhi, 'L' ); + KSend( zRlo, zRhi, 'R' ); + } + else { - KRecv( zihi + 1, zohi, 'R' ); - KRecv( zolo, zilo - 1, 'L' ); - } + KRecv( zihi + 1, zohi, 'R' ); + KRecv( zolo, zilo - 1, 'L' ); + } - return true; + return true; } /* --------------------------------------------------------------- */ @@ -320,72 +320,72 @@ bool Split::KUpdt() static void* _Propagate1( void* ithr ) { - int nd = vzd.size(); + int nd = vzd.size(); - const Rgns& Rs = vR[zs]; - vector& ks = ME->K[zs]; + const Rgns& Rs = vR[zs]; + vector& ks = ME->K[zs]; - for( int id = (long)ithr; id < nd; id += nthr ) { + for( int id = (long)ithr; id < nd; id += nthr ) { - int zd = vzd[id]; - vector& kd = ME->K[zd]; - int nd = vR[zd].nr; + int zd = vzd[id]; + vector& kd = ME->K[zd]; + int nd = vR[zd].nr; - for( int ir = 0; ir < Rs.nr; ++ir ) { + for( int ir = 0; ir < Rs.nr; ++ir ) { - int ksrc = ks[ir]; + int ksrc = ks[ir]; - // Valid tile? - if( !ksrc ) - continue; + // Valid tile? + if( !ksrc ) + continue; - const vector& P = Rs.pts[ir]; - int np = P.size(); + const vector& P = Rs.pts[ir]; + int np = P.size(); - for( int ip = 0; ip < np; ++ip ) { + for( int ip = 0; ip < np; ++ip ) { - const CorrPnt& C = vC[P[ip]]; + const CorrPnt& C = vC[P[ip]]; - if( !C.used ) - continue; + if( !C.used ) + continue; - int jr; + int jr; - if( C.z1 == zd ) - jr = C.i1; - else if( C.z2 == zd ) - jr = C.i2; - else - continue; + if( C.z1 == zd ) + jr = C.i1; + else if( C.z2 == zd ) + jr = C.i2; + else + continue; - int kdst = kd[jr]; + int kdst = kd[jr]; - if( !kdst ) - continue; + if( !kdst ) + continue; - if( kdst == ksrc ) - continue; + if( kdst == ksrc ) + continue; - // Note any difference by setting the - // drtyD flag now. But at this time, - // we only update dst colors if the - // src color is lower. If the dst is - // lower, it will propagate to us on - // a later loop iteration. + // Note any difference by setting the + // drtyD flag now. But at this time, + // we only update dst colors if the + // src color is lower. If the dst is + // lower, it will propagate to us on + // a later loop iteration. - drtyD[zd] = 1; + drtyD[zd] = 1; - if( ksrc < kdst ) { - for( int ik = 0; ik < nd; ++ik ) { - if( kd[ik] == kdst ) - kd[ik] = ksrc; - } - } - } - } - } + if( ksrc < kdst ) { + for( int ik = 0; ik < nd; ++ik ) { + if( kd[ik] == kdst ) + kd[ik] = ksrc; + } + } + } + } + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -400,26 +400,26 @@ static void* _Propagate1( void* ithr ) // void Split::Propagate1() { - vzd.clear(); + vzd.clear(); - int zlo = max( zs - maxspan, zilo ), - zhi = min( zs + maxspan, zihi ), - nd = zhi - zlo + 1; + int zlo = max( zs - maxspan, zilo ), + zhi = min( zs + maxspan, zihi ), + nd = zhi - zlo + 1; - for( int i = 0; i < nd; ++i ) { - if( i + zlo != zs ) - vzd.push_back( i + zlo ); - } + for( int i = 0; i < nd; ++i ) { + if( i + zlo != zs ) + vzd.push_back( i + zlo ); + } - ME = (Split*)this; - nd = vzd.size(); - nthr = maxthreads; + ME = (Split*)this; + nd = vzd.size(); + nthr = maxthreads; - if( nthr > nd ) - nthr = nd; + if( nthr > nd ) + nthr = nd; - if( !EZThreads( _Propagate1, nthr, 1, "_Propagate1" ) ) - exit( 42 ); + if( !EZThreads( _Propagate1, nthr, 1, "_Propagate1" ) ) + exit( 42 ); } /* --------------------------------------------------------------- */ @@ -433,50 +433,50 @@ void Split::Propagate1() void Split::PropagateLocally() { // clear cummulative dst flags - gdrty[wkid].L = 0; - gdrty[wkid].R = 0; + gdrty[wkid].L = 0; + gdrty[wkid].R = 0; - for(;;) { + for(;;) { - memset( &drtyD[0], 0, zohi - zolo + 1 ); + memset( &drtyD[0], 0, zohi - zolo + 1 ); - /* ---------- */ - /* Do a round */ - /* ---------- */ + /* ---------- */ + /* Do a round */ + /* ---------- */ - for( zs = zolo; zs <= zohi; ++zs ) { + for( zs = zolo; zs <= zohi; ++zs ) { - if( drtyS[zs] ) - Propagate1(); - } + if( drtyS[zs] ) + Propagate1(); + } - /* ------------------ */ - /* Neighbors touched? */ - /* ------------------ */ + /* ------------------ */ + /* Neighbors touched? */ + /* ------------------ */ - if( wkid > 0 ) { - for( int iz = zLlo; iz <= zLhi; ++iz ) - gdrty[wkid].L |= drtyD[iz]; - } + if( wkid > 0 ) { + for( int iz = zLlo; iz <= zLhi; ++iz ) + gdrty[wkid].L |= drtyD[iz]; + } - if( wkid + 1 < nwks ) { - for( int iz = zRlo; iz <= zRhi; ++iz ) - gdrty[wkid].R |= drtyD[iz]; - } + if( wkid + 1 < nwks ) { + for( int iz = zRlo; iz <= zRhi; ++iz ) + gdrty[wkid].R |= drtyD[iz]; + } - /* ----- */ - /* Done? */ - /* ----- */ + /* ----- */ + /* Done? */ + /* ----- */ - memcpy( &drtyS[0], &drtyD[0], zohi - zolo + 1 ); + memcpy( &drtyS[0], &drtyD[0], zohi - zolo + 1 ); - int drty = 0; - for( int iz = zilo; iz <= zihi; ++iz ) - drty |= drtyD[iz]; + int drty = 0; + for( int iz = zilo; iz <= zihi; ++iz ) + drty |= drtyD[iz]; - if( !drty ) - break; - } + if( !drty ) + break; + } } /* --------------------------------------------------------------- */ @@ -485,10 +485,10 @@ void Split::PropagateLocally() void Split::ReportCount( const map& m ) { - map::const_iterator it, ie = m.end(); + map::const_iterator it, ie = m.end(); - for( it = m.begin(); it != ie; ++it ) - printf( "Color %9d Count %9d\n", it->first, it->second ); + for( it = m.begin(); it != ie; ++it ) + printf( "Color %9d Count %9d\n", it->first, it->second ); } /* --------------------------------------------------------------- */ @@ -498,121 +498,121 @@ void Split::ReportCount( const map& m ) class mpiclr { // share color map with workers public: - int first, second; + int first, second; public: - mpiclr() {}; - mpiclr( map::iterator& it ) - : first(it->first), second(it->second) {}; + mpiclr() {}; + mpiclr( map::iterator& it ) + : first(it->first), second(it->second) {}; }; void Split::CountColors( map& m ) { // Cache iterator and end() - map::iterator it, ie = m.end(); - int clast = -1; + map::iterator it, ie = m.end(); + int clast = -1; // Calc my colors - for( int iz = zilo; iz <= zihi; ++iz ) { + for( int iz = zilo; iz <= zihi; ++iz ) { - vector& k = K[iz]; - int nr = vR[iz].nr; + vector& k = K[iz]; + int nr = vR[iz].nr; - for( int ir = 0; ir < nr; ++ir ) { + for( int ir = 0; ir < nr; ++ir ) { - int clr = k[ir]; + int clr = k[ir]; - if( !clr ) - continue; + if( !clr ) + continue; - if( clr != clast ) - it = m.find( clast = clr ); + if( clr != clast ) + it = m.find( clast = clr ); - if( it != ie ) - ++it->second; - else { // new entry: reset cache - m[clr] = 1; - ie = m.end(); - clast = -1; - } - } - } + if( it != ie ) + ++it->second; + else { // new entry: reset cache + m[clr] = 1; + ie = m.end(); + clast = -1; + } + } + } // Report my subcounts - if( nwks > 1 ) - printf( "This worker:\n" ); - else - printf( "All workers:\n" ); + if( nwks > 1 ) + printf( "This worker:\n" ); + else + printf( "All workers:\n" ); - ReportCount( m ); + ReportCount( m ); // Send my colors to master; then get global colors - if( wkid > 0 ) { + if( wkid > 0 ) { - // send count - int nm = m.size(); - MPISend( &nm, sizeof(int), 0, wkid ); + // send count + int nm = m.size(); + MPISend( &nm, sizeof(int), 0, wkid ); - // send elems - for( it = m.begin(); it != ie; ++it ) { - mpiclr c( it ); - MPISend( &c, sizeof(mpiclr), 0, wkid ); - } + // send elems + for( it = m.begin(); it != ie; ++it ) { + mpiclr c( it ); + MPISend( &c, sizeof(mpiclr), 0, wkid ); + } - // get count - m.clear(); - MPIRecv( &nm, sizeof(int), 0, wkid ); + // get count + m.clear(); + MPIRecv( &nm, sizeof(int), 0, wkid ); - // get elems - for( int i = 0; i < nm; ++i ) { - mpiclr c; - MPIRecv( &c, sizeof(mpiclr), 0, wkid ); - m[c.first] = c.second; - } - } - else if( nwks > 1 ) { + // get elems + for( int i = 0; i < nm; ++i ) { + mpiclr c; + MPIRecv( &c, sizeof(mpiclr), 0, wkid ); + m[c.first] = c.second; + } + } + else if( nwks > 1 ) { - int nm; + int nm; - // get each worker - for( int iw = 1; iw < nwks; ++iw ) { + // get each worker + for( int iw = 1; iw < nwks; ++iw ) { - MPIRecv( &nm, sizeof(int), iw, iw ); + MPIRecv( &nm, sizeof(int), iw, iw ); - for( int i = 0; i < nm; ++i ) { + for( int i = 0; i < nm; ++i ) { - mpiclr c; - MPIRecv( &c, sizeof(mpiclr), iw, iw ); + mpiclr c; + MPIRecv( &c, sizeof(mpiclr), iw, iw ); - it = m.find( c.first ); + it = m.find( c.first ); - if( it != m.end() ) - it->second += c.second; - else - m[c.first] = c.second; - } - } + if( it != m.end() ) + it->second += c.second; + else + m[c.first] = c.second; + } + } - // send each worker - nm = m.size(); - ie = m.end(); + // send each worker + nm = m.size(); + ie = m.end(); - for( int iw = 1; iw < nwks; ++iw ) { + for( int iw = 1; iw < nwks; ++iw ) { - MPISend( &nm, sizeof(int), iw, iw ); + MPISend( &nm, sizeof(int), iw, iw ); - for( it = m.begin(); it != ie; ++it ) { - mpiclr c( it ); - MPISend( &c, sizeof(mpiclr), iw, iw ); - } - } + for( it = m.begin(); it != ie; ++it ) { + mpiclr c( it ); + MPISend( &c, sizeof(mpiclr), iw, iw ); + } + } - printf( "\nAll workers:\n" ); - ReportCount( m ); - } + printf( "\nAll workers:\n" ); + ReportCount( m ); + } } /* --------------------------------------------------------------- */ @@ -621,72 +621,72 @@ void Split::CountColors( map& m ) static void SaveXBin( const vector &x, int z ) { - char buf[64]; - FILE *f; + char buf[64]; + FILE *f; - sprintf( buf, "%s/X_%c_%d.bin", - gpath, (ME->X.NE == 6 ? 'A' : 'H'), z ); + sprintf( buf, "%s/X_%c_%d.bin", + gpath, (ME->X.NE == 6 ? 'A' : 'H'), z ); - f = FileOpenOrDie( buf, "wb" ); - fwrite( &x[0], sizeof(double), x.size(), f ); - fclose( f ); + f = FileOpenOrDie( buf, "wb" ); + fwrite( &x[0], sizeof(double), x.size(), f ); + fclose( f ); } static void SaveFBin( const vector &f, int z ) { - char buf[64]; - FILE *q; + char buf[64]; + FILE *q; - sprintf( buf, "%s/F_%d.bin", gpath, z ); - q = FileOpenOrDie( buf, "wb" ); - fwrite( &f[0], sizeof(uint8), f.size(), q ); - fclose( q ); + sprintf( buf, "%s/F_%d.bin", gpath, z ); + q = FileOpenOrDie( buf, "wb" ); + fwrite( &f[0], sizeof(uint8), f.size(), q ); + fclose( q ); } static void* _Save( void* ithr ) { - for( int iz = zilo + (long)ithr; iz <= zihi; iz += nthr ) { - - const Rgns& R = vR[iz]; - vector& k = ME->K[iz]; - vector f = R.flag; - - // Flag adjustment: - // Basically, we preserve existing flags, - // but if it's not the right color, mark - // it as 'transform missing'. - // - // Saveclr is set by caller: - // >0 => match specific color - // -1 => consolidate remaining colors - // 0 => not implemented. - - if( saveclr >= 0 ) { - - for( int j = 0; j < R.nr; ++j ) { - - if( k[j] == saveclr ) - k[j] = -1; // mark it removed - else // kill all others - f[j] = fmRead; - } - } - else { // save all positive colors together - - for( int j = 0; j < R.nr; ++j ) { - - if( k[j] <= 0 ) // not these - f[j] = fmRead; - } - } - - SaveXBin( ME->X.X[iz], R.z ); - SaveFBin( f, R.z ); - } - - return NULL; + for( int iz = zilo + (long)ithr; iz <= zihi; iz += nthr ) { + + const Rgns& R = vR[iz]; + vector& k = ME->K[iz]; + vector f = R.flag; + + // Flag adjustment: + // Basically, we preserve existing flags, + // but if it's not the right color, mark + // it as 'transform missing'. + // + // Saveclr is set by caller: + // >0 => match specific color + // -1 => consolidate remaining colors + // 0 => not implemented. + + if( saveclr >= 0 ) { + + for( int j = 0; j < R.nr; ++j ) { + + if( k[j] == saveclr ) + k[j] = -1; // mark it removed + else // kill all others + f[j] = fmRead; + } + } + else { // save all positive colors together + + for( int j = 0; j < R.nr; ++j ) { + + if( k[j] <= 0 ) // not these + f[j] = fmRead; + } + } + + SaveXBin( ME->X.X[iz], R.z ); + SaveFBin( f, R.z ); + } + + return NULL; } /* --------------------------------------------------------------- */ @@ -697,29 +697,29 @@ static void* _Save( void* ithr ) // void Split::Save() { - char buf[64]; - int nz = zihi - zilo + 1; + char buf[64]; + int nz = zihi - zilo + 1; - ME = (Split*)this; - gpath = buf; - nthr = maxthreads; + ME = (Split*)this; + gpath = buf; + nthr = maxthreads; - if( nthr > nz ) - nthr = nz; + if( nthr > nz ) + nthr = nz; - if( saveclr > 0 ) { - sprintf( buf, "Splits/X_%c_BIN_CLR%d", - (X.NE == 6 ? 'A' : 'H'), saveclr ); - } - else { - sprintf( buf, "Splits/X_%c_BIN_REM", - (X.NE == 6 ? 'A' : 'H') ); - } + if( saveclr > 0 ) { + sprintf( buf, "Splits/X_%c_BIN_CLR%d", + (X.NE == 6 ? 'A' : 'H'), saveclr ); + } + else { + sprintf( buf, "Splits/X_%c_BIN_REM", + (X.NE == 6 ? 'A' : 'H') ); + } - DskCreateDir( buf, stdout ); + DskCreateDir( buf, stdout ); - if( !EZThreads( _Save, nthr, 1, "_SplitSave" ) ) - exit( 42 ); + if( !EZThreads( _Save, nthr, 1, "_SplitSave" ) ) + exit( 42 ); } /* --------------------------------------------------------------- */ @@ -728,41 +728,41 @@ void Split::Save() void Split::BreakOut( const map& m ) { - int nm = m.size(); + int nm = m.size(); - if( nm <= 1 ) { - printf( - "No splits created;" - " (single color or all below splitmin).\n" ); - return; - } + if( nm <= 1 ) { + printf( + "No splits created;" + " (single color or all below splitmin).\n" ); + return; + } // Splits folder - DskCreateDir( "Splits", stdout ); + DskCreateDir( "Splits", stdout ); // First separately write each color over threshold. // The Save operation will replace that color by (-1) // removing it from the K vectors. - map::const_iterator it, ie = m.end(); + map::const_iterator it, ie = m.end(); - for( it = m.begin(); it != ie; ++it ) { + for( it = m.begin(); it != ie; ++it ) { - if( it->second >= splitmin ) { + if( it->second >= splitmin ) { - saveclr = it->first; - Save(); - --nm; - } - } + saveclr = it->first; + Save(); + --nm; + } + } // Now consolidate remaining 'REM' fragments. - if( nm > 0 ) { - saveclr = -1; - Save(); - } + if( nm > 0 ) { + saveclr = -1; + Save(); + } } /* --------------------------------------------------------------- */ @@ -771,82 +771,82 @@ void Split::BreakOut( const map& m ) void Split::Run() { - printf( "\n---- Split ----\n" ); + printf( "\n---- Split ----\n" ); - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); // Init color workspace - Resize(); + Resize(); // First colorize montages alone - ColorMontages(); + ColorMontages(); // Initially everything dirty - gdrty.resize( nwks ); - gdrty[0].L = 0; - gdrty[nwks - 1].R = 0; + gdrty.resize( nwks ); + gdrty[0].L = 0; + gdrty[nwks - 1].R = 0; - drtyS.resize( zohi - zolo + 1, 1 ); - drtyD.resize( zohi - zolo + 1, 0 ); + drtyS.resize( zohi - zolo + 1, 1 ); + drtyD.resize( zohi - zolo + 1, 0 ); - maxspan = LayerCat_MaxSpan( vL ); + maxspan = LayerCat_MaxSpan( vL ); // Propagate colors across Z until no changes - for(;;) { + for(;;) { - /* ---------- */ - /* Do a round */ - /* ---------- */ + /* ---------- */ + /* Do a round */ + /* ---------- */ - // get src data - KUpdt(); + // get src data + KUpdt(); - // set src flags - if( wkid > 0 && gdrty[wkid - 1].R ) { + // set src flags + if( wkid > 0 && gdrty[wkid - 1].R ) { - for( int iz = zolo; iz < zilo; ++iz ) - drtyS[iz] = 1; - } + for( int iz = zolo; iz < zilo; ++iz ) + drtyS[iz] = 1; + } - if( wkid + 1 < nwks && gdrty[wkid + 1].L ) { + if( wkid + 1 < nwks && gdrty[wkid + 1].L ) { - for( int iz = zihi + 1; iz <= zohi; ++iz ) - drtyS[iz] = 1; - } + for( int iz = zihi + 1; iz <= zohi; ++iz ) + drtyS[iz] = 1; + } - PropagateLocally(); + PropagateLocally(); - /* -------------- */ - /* Done globally? */ - /* -------------- */ + /* -------------- */ + /* Done globally? */ + /* -------------- */ - GUpdt(); + GUpdt(); - int drty = 0; - for( int iw = 0; iw < nwks; ++iw ) - drty |= gdrty[iw].L | gdrty[iw].R; + int drty = 0; + for( int iw = 0; iw < nwks; ++iw ) + drty |= gdrty[iw].L | gdrty[iw].R; - if( !drty ) - break; - } + if( !drty ) + break; + } - vzd.clear(); - drtyD.clear(); - drtyS.clear(); - gdrty.clear(); + vzd.clear(); + drtyD.clear(); + drtyS.clear(); + gdrty.clear(); // Split according to final coloring - map m; + map m; - CountColors( m ); - BreakOut( m ); + CountColors( m ); + BreakOut( m ); - StopTiming( stdout, "Split", t0 ); + StopTiming( stdout, "Split", t0 ); } diff --git a/1_LSQw/lsq_Split.h b/1_LSQw/lsq_Split.h index c21da07..2067b92 100644 --- a/1_LSQw/lsq_Split.h +++ b/1_LSQw/lsq_Split.h @@ -15,27 +15,27 @@ using namespace std; class Split { public: - const XArray& X; - vector > K; // color - int splitmin; + const XArray& X; + vector > K; // color + int splitmin; public: - Split( const XArray& X, int splitmin ) - : X(X), splitmin(splitmin) {}; + Split( const XArray& X, int splitmin ) + : X(X), splitmin(splitmin) {}; private: - void Resize(); - void ColorMontages(); - void GUpdt(); - bool KSend( int zlo, int zhi, int toLorR ); - bool KRecv( int zlo, int zhi, int fmLorR ); - bool KUpdt(); - void Propagate1(); - void PropagateLocally(); - void ReportCount( const map& m ); - void CountColors( map& m ); - void Save(); - void BreakOut( const map& m ); + void Resize(); + void ColorMontages(); + void GUpdt(); + bool KSend( int zlo, int zhi, int toLorR ); + bool KRecv( int zlo, int zhi, int fmLorR ); + bool KUpdt(); + void Propagate1(); + void PropagateLocally(); + void ReportCount( const map& m ); + void CountColors( map& m ); + void Save(); + void BreakOut( const map& m ); public: - void Run(); + void Run(); }; diff --git a/1_LSQw/lsq_Untwist.cpp b/1_LSQw/lsq_Untwist.cpp index 08d0d30..8ff1e69 100644 --- a/1_LSQw/lsq_Untwist.cpp +++ b/1_LSQw/lsq_Untwist.cpp @@ -23,8 +23,8 @@ class AIO { public: - int z; - TAffine A; + int z; + TAffine A; }; /* --------------------------------------------------------------- */ @@ -46,71 +46,71 @@ static int nthr; void* _RgdSums( void* ithr ) { - int nb = vA.size(); + int nb = vA.size(); // For each B-layer... - for( int ib = (long)ithr; ib < nb; ib += nthr ) { + for( int ib = (long)ithr; ib < nb; ib += nthr ) { - // Form the sums + // Form the sums - CRigid rgd; - int ia = ib + 1; - const Rgns& Rb = vR[ib]; - const Rgns& Ra = vR[ia]; - const vector& xb = gX->X[ib]; - const vector& xa = gX->X[ia]; - AIO& A = vA[ib]; + CRigid rgd; + int ia = ib + 1; + const Rgns& Rb = vR[ib]; + const Rgns& Ra = vR[ia]; + const vector& xb = gX->X[ib]; + const vector& xa = gX->X[ia]; + AIO& A = vA[ib]; - // For each A-layer rgn... + // For each A-layer rgn... - for( int ir = 0; ir < Ra.nr; ++ir ) { + for( int ir = 0; ir < Ra.nr; ++ir ) { - if( !FLAG_ISUSED( Ra.flag[ir] ) ) - continue; + if( !FLAG_ISUSED( Ra.flag[ir] ) ) + continue; - const vector& P = Ra.pts[ir]; - const TAffine* Ta = &X_AS_AFF( xa, ir ); - const TAffine* Tb; - int lastb = -1, - np = P.size(); + const vector& P = Ra.pts[ir]; + const TAffine* Ta = &X_AS_AFF( xa, ir ); + const TAffine* Tb; + int lastb = -1, + np = P.size(); - // For each of its points... + // For each of its points... - for( int ip = 0; ip < np; ++ip ) { + for( int ip = 0; ip < np; ++ip ) { - const CorrPnt& C = vC[P[ip]]; + const CorrPnt& C = vC[P[ip]]; - // Want only zA onto zB + // Want only zA onto zB - if( C.z1 != ia || C.z2 != ib ) - continue; + if( C.z1 != ia || C.z2 != ib ) + continue; - if( C.i2 != lastb ) { + if( C.i2 != lastb ) { - if( !FLAG_ISUSED( Rb.flag[C.i2] ) ) - continue; + if( !FLAG_ISUSED( Rb.flag[C.i2] ) ) + continue; - Tb = &X_AS_AFF( xb, C.i2 ); - lastb = C.i2; - } + Tb = &X_AS_AFF( xb, C.i2 ); + lastb = C.i2; + } - Point pa = C.p1, - pb = C.p2; + Point pa = C.p1, + pb = C.p2; - Ta->Transform( pa ); - Tb->Transform( pb ); - rgd.Add( pa, pb ); - } - } + Ta->Transform( pa ); + Tb->Transform( pb ); + rgd.Add( pa, pb ); + } + } - // Set transform + // Set transform - A.z = Ra.z; - rgd.Solve( A.A ); - } + A.z = Ra.z; + rgd.Solve( A.A ); + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -121,19 +121,19 @@ void* _RgdSums( void* ithr ) // static void CalcMyPairwiseTForms( XArray &X ) { - gX = &X; + gX = &X; - int nb = zohi - zolo; // this many b-layers + int nb = zohi - zolo; // this many b-layers - vA.resize( nb ); + vA.resize( nb ); - nthr = maxthreads; + nthr = maxthreads; - if( nthr > nb ) - nthr = nb; + if( nthr > nb ) + nthr = nb; - if( !EZThreads( _RgdSums, nthr, 1, "_RgdSums" ) ) - exit( 42 ); + if( !EZThreads( _RgdSums, nthr, 1, "_RgdSums" ) ) + exit( 42 ); } /* --------------------------------------------------------------- */ @@ -149,19 +149,19 @@ static void WriteMyTForms() { // If I'm not the last worker... - if( wkid >= nwks - 1 ) - return; + if( wkid >= nwks - 1 ) + return; // Each entry affects layer zA or higher, so write blocks: // 'zA A' - char buf[32]; - DskCreateDir( "Untwist", stdout ); - sprintf( buf, "Untwist/%d.bin", wkid ); + char buf[32]; + DskCreateDir( "Untwist", stdout ); + sprintf( buf, "Untwist/%d.bin", wkid ); - FILE *f = FileOpenOrDie( buf, "wb" ); - fwrite( &vA[0], sizeof(AIO), vA.size(), f ); - fclose( f ); + FILE *f = FileOpenOrDie( buf, "wb" ); + fwrite( &vA[0], sizeof(AIO), vA.size(), f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -177,37 +177,37 @@ static void WriteMyTForms() // static void AccumulateBefores( TAffine &A0 ) { - int z0 = vR[zolo].z, - zlast = -1; + int z0 = vR[zolo].z, + zlast = -1; - for( int iw = 0; iw < wkid; ++iw ) { + for( int iw = 0; iw < wkid; ++iw ) { - char buf[32]; - sprintf( buf, "Untwist/%d.bin", iw ); + char buf[32]; + sprintf( buf, "Untwist/%d.bin", iw ); - int n = (int)DskBytes( buf ) / sizeof(AIO); - vector aio( n ); + int n = (int)DskBytes( buf ) / sizeof(AIO); + vector aio( n ); - FILE *f = FileOpenOrDie( buf, "rb" ); - fread( &aio[0], sizeof(AIO), n, f ); - fclose( f ); + FILE *f = FileOpenOrDie( buf, "rb" ); + fread( &aio[0], sizeof(AIO), n, f ); + fclose( f ); - for( int i = 0; i < n; ++i ) { + for( int i = 0; i < n; ++i ) { - const AIO& A = aio[i]; + const AIO& A = aio[i]; - if( A.z > z0 ) - return; + if( A.z > z0 ) + return; - // monotonic z rule + // monotonic z rule - if( A.z <= zlast ) - continue; + if( A.z <= zlast ) + continue; - A0 = A.A * A0; - zlast = A.z; - } - } + A0 = A.A * A0; + zlast = A.z; + } + } } /* --------------------------------------------------------------- */ @@ -218,26 +218,26 @@ static void AccumulateBefores( TAffine &A0 ) // static void Apply( TAffine &A0 ) { - int nz = zohi - zolo + 1; + int nz = zohi - zolo + 1; - for( int iz = (wkid ? 0 : 1); iz < nz; ++iz ) { + for( int iz = (wkid ? 0 : 1); iz < nz; ++iz ) { - if( iz ) - A0 = vA[iz - 1].A * A0; + if( iz ) + A0 = vA[iz - 1].A * A0; - const Rgns& R = vR[iz]; - vector& x = gX->X[iz]; + const Rgns& R = vR[iz]; + vector& x = gX->X[iz]; - for( int ir = 0; ir < R.nr; ++ir ) { + for( int ir = 0; ir < R.nr; ++ir ) { - if( !FLAG_ISUSED( R.flag[ir] ) ) - continue; + if( !FLAG_ISUSED( R.flag[ir] ) ) + continue; - TAffine& T = X_AS_AFF( x, ir ); + TAffine& T = X_AS_AFF( x, ir ); - T = A0 * T; - } - } + T = A0 * T; + } + } } /* --------------------------------------------------------------- */ @@ -253,30 +253,30 @@ static void Apply( TAffine &A0 ) // void UntwistAffines( XArray &X ) { - if( X.NE != 6 || zolo >= zohi ) - return; + if( X.NE != 6 || zolo >= zohi ) + return; - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - CalcMyPairwiseTForms( X ); - WriteMyTForms(); + CalcMyPairwiseTForms( X ); + WriteMyTForms(); - MPIWaitForOthers(); + MPIWaitForOthers(); - TAffine A0; - AccumulateBefores( A0 ); + TAffine A0; + AccumulateBefores( A0 ); - Apply( A0 ); - vA.clear(); + Apply( A0 ); + vA.clear(); // Cleanup - MPIWaitForOthers(); + MPIWaitForOthers(); - if( nwks > 1 && !wkid ) - system( "rm -rf Untwist" ); + if( nwks > 1 && !wkid ) + system( "rm -rf Untwist" ); - StopTiming( stdout, "Untwist", t0 ); + StopTiming( stdout, "Untwist", t0 ); } diff --git a/1_LSQw/lsq_XArray.cpp b/1_LSQw/lsq_XArray.cpp index e8ce841..3720ecd 100644 --- a/1_LSQw/lsq_XArray.cpp +++ b/1_LSQw/lsq_XArray.cpp @@ -42,54 +42,54 @@ static int nthr; static void* _AFromIDB( void* ithr ) { - for( int iz = zolo + (long)ithr; iz <= zohi; iz += nthr ) { + for( int iz = zolo + (long)ithr; iz <= zohi; iz += nthr ) { - Rgns& R = vR[iz]; - vector& x = ME->X[iz]; - vector t2i; + Rgns& R = vR[iz]; + vector& x = ME->X[iz]; + vector t2i; - // Get rgn #1 tforms + // Get rgn #1 tforms - if( !IDBT2IGet_JustIDandT( t2i, idb, R.z ) ) - exit( 42 ); + if( !IDBT2IGet_JustIDandT( t2i, idb, R.z ) ) + exit( 42 ); - x.resize( R.nr * 6 ); + x.resize( R.nr * 6 ); - int nt = t2i.size(); - map::iterator en = R.m.end(); + int nt = t2i.size(); + map::iterator en = R.m.end(); - // For each transform in IDB... + // For each transform in IDB... - for( int it = 0; it < nt; ++it ) { + for( int it = 0; it < nt; ++it ) { - // Get its block start and limit {j0,jlim} + // Get its block start and limit {j0,jlim} - const Til2Img& T = t2i[it]; - map::iterator mi = R.m.find( T.id ); - int j0, jlim; + const Til2Img& T = t2i[it]; + map::iterator mi = R.m.find( T.id ); + int j0, jlim; - if( mi == en ) - continue; + if( mi == en ) + continue; - j0 = mi->second; - jlim = (++mi != en ? mi->second : R.nr); + j0 = mi->second; + jlim = (++mi != en ? mi->second : R.nr); - // Propagate rgn #1 tform to all block members + // Propagate rgn #1 tform to all block members - for( int j = j0; j < jlim; ++j ) { + for( int j = j0; j < jlim; ++j ) { - if( R.pts[j].size() >= 3 ) { + if( R.pts[j].size() >= 3 ) { - T.T.CopyOut( &x[j * 6] ); - FLAG_SETUSED( R.flag[j] ); - } - else - FLAG_SETPNTS( R.flag[j] ); - } - } - } + T.T.CopyOut( &x[j * 6] ); + FLAG_SETUSED( R.flag[j] ); + } + else + FLAG_SETPNTS( R.flag[j] ); + } + } + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -108,118 +108,118 @@ static void* _AFromIDB( void* ithr ) class CIDRA { public: - TAffine A; - int id, r; + TAffine A; + int id, r; public: - inline bool FromFile( FILE *f ) - { - return 8 == fscanf( f, - " %d %d %lf %lf %lf %lf %lf %lf%*[^\r\n][\r\n]", - &id, &r, - &A.t[0], &A.t[1], &A.t[2], - &A.t[3], &A.t[4], &A.t[5] ); - }; + inline bool FromFile( FILE *f ) + { + return 8 == fscanf( f, + " %d %d %lf %lf %lf %lf %lf %lf%*[^\r\n][\r\n]", + &id, &r, + &A.t[0], &A.t[1], &A.t[2], + &A.t[3], &A.t[4], &A.t[5] ); + }; }; static bool Read_vA( vector &vA, int z ) { - char buf[2048]; - FILE *f; - CIDRA A; - bool nf = true; // default = no folds + char buf[2048]; + FILE *f; + CIDRA A; + bool nf = true; // default = no folds - sprintf( buf, "%s/X_A_%d.txt", gpath, z ); - f = FileOpenOrDie( buf, "r" ); + sprintf( buf, "%s/X_A_%d.txt", gpath, z ); + f = FileOpenOrDie( buf, "r" ); - while( A.FromFile( f ) ) { + while( A.FromFile( f ) ) { - if( A.r > 1 ) - nf = false; + if( A.r > 1 ) + nf = false; - vA.push_back( A ); - } + vA.push_back( A ); + } - fclose( f ); + fclose( f ); - return nf; + return nf; } static void* _AFromTxt( void* ithr ) { - for( int iz = zolo + (long)ithr; iz <= zohi; iz += nthr ) { + for( int iz = zolo + (long)ithr; iz <= zohi; iz += nthr ) { - Rgns& R = vR[iz]; - vector& x = ME->X[iz]; - vector vA; - int in = (iz >= zilo && iz <= zihi ), - nf = Read_vA( vA, R.z ); + Rgns& R = vR[iz]; + vector& x = ME->X[iz]; + vector vA; + int in = (iz >= zilo && iz <= zihi ), + nf = Read_vA( vA, R.z ); - x.resize( R.nr * 6 ); + x.resize( R.nr * 6 ); - int na = vA.size(); - map::iterator en = R.m.end(); + int na = vA.size(); + map::iterator en = R.m.end(); - if( !nf ) { // Propagate rgn #1 to all block members + if( !nf ) { // Propagate rgn #1 to all block members - // For each transform in vA... + // For each transform in vA... - for( int ia = 0; ia < na; ++ia ) { + for( int ia = 0; ia < na; ++ia ) { - // Get its block start and limit {j0,jlim} + // Get its block start and limit {j0,jlim} - const CIDRA& A = vA[ia]; - map::iterator mi = R.m.find( A.id ); - int j0, jlim; + const CIDRA& A = vA[ia]; + map::iterator mi = R.m.find( A.id ); + int j0, jlim; - if( mi == en ) - continue; + if( mi == en ) + continue; - j0 = mi->second; - jlim = (++mi != en ? mi->second : R.nr); + j0 = mi->second; + jlim = (++mi != en ? mi->second : R.nr); - // Propagate rgn #1 tform to all block members + // Propagate rgn #1 tform to all block members - for( int j = j0; j < jlim; ++j ) { + for( int j = j0; j < jlim; ++j ) { - if( !in || R.pts[j].size() >= 3 ) { - A.A.CopyOut( &x[j * 6] ); - FLAG_SETUSED( R.flag[j] ); - } - else - FLAG_SETPNTS( R.flag[j] ); - } - } - } - else { // Move each A to its specified position + if( !in || R.pts[j].size() >= 3 ) { + A.A.CopyOut( &x[j * 6] ); + FLAG_SETUSED( R.flag[j] ); + } + else + FLAG_SETPNTS( R.flag[j] ); + } + } + } + else { // Move each A to its specified position - // For each transform in vA... + // For each transform in vA... - for( int ia = 0; ia < na; ++ia ) { + for( int ia = 0; ia < na; ++ia ) { - // Get its location j + // Get its location j - const CIDRA& A = vA[ia]; - map::iterator mi = R.m.find( A.id ); - int j; + const CIDRA& A = vA[ia]; + map::iterator mi = R.m.find( A.id ); + int j; - if( mi == en ) - continue; + if( mi == en ) + continue; - j = mi->second + A.r - 1; + j = mi->second + A.r - 1; - if( !in || R.pts[j].size() >= 3 ) { - A.A.CopyOut( &x[j * 6] ); - FLAG_SETUSED( R.flag[j] ); - } - else - FLAG_SETPNTS( R.flag[j] ); - } - } - } + if( !in || R.pts[j].size() >= 3 ) { + A.A.CopyOut( &x[j * 6] ); + FLAG_SETUSED( R.flag[j] ); + } + else + FLAG_SETPNTS( R.flag[j] ); + } + } + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -238,119 +238,119 @@ static void* _AFromTxt( void* ithr ) class CIDRH { public: - THmgphy H; - int id, r; + THmgphy H; + int id, r; public: - inline bool FromFile( FILE *f ) - { - return 10 == fscanf( f, - " %d %d %lf %lf %lf %lf %lf %lf %lf %lf%*[^\r\n][\r\n]", - &id, &r, - &H.t[0], &H.t[1], &H.t[2], - &H.t[3], &H.t[4], &H.t[5], - &H.t[6], &H.t[7] ); - }; + inline bool FromFile( FILE *f ) + { + return 10 == fscanf( f, + " %d %d %lf %lf %lf %lf %lf %lf %lf %lf%*[^\r\n][\r\n]", + &id, &r, + &H.t[0], &H.t[1], &H.t[2], + &H.t[3], &H.t[4], &H.t[5], + &H.t[6], &H.t[7] ); + }; }; static bool Read_vH( vector &vH, int z ) { - char buf[2048]; - FILE *f; - CIDRH H; - bool nf = true; // default = no folds + char buf[2048]; + FILE *f; + CIDRH H; + bool nf = true; // default = no folds - sprintf( buf, "%s/X_H_%d.txt", gpath, z ); - f = FileOpenOrDie( buf, "r" ); + sprintf( buf, "%s/X_H_%d.txt", gpath, z ); + f = FileOpenOrDie( buf, "r" ); - while( H.FromFile( f ) ) { + while( H.FromFile( f ) ) { - if( H.r > 1 ) - nf = false; + if( H.r > 1 ) + nf = false; - vH.push_back( H ); - } + vH.push_back( H ); + } - fclose( f ); + fclose( f ); - return nf; + return nf; } static void* _HFromTxt( void* ithr ) { - for( int iz = zolo + (long)ithr; iz <= zohi; iz += nthr ) { + for( int iz = zolo + (long)ithr; iz <= zohi; iz += nthr ) { - Rgns& R = vR[iz]; - vector& x = ME->X[iz]; - vector vH; - int in = (iz >= zilo && iz <= zihi ), - nf = Read_vH( vH, R.z ); + Rgns& R = vR[iz]; + vector& x = ME->X[iz]; + vector vH; + int in = (iz >= zilo && iz <= zihi ), + nf = Read_vH( vH, R.z ); - x.resize( R.nr * 8 ); + x.resize( R.nr * 8 ); - int nh = vH.size(); - map::iterator en = R.m.end(); + int nh = vH.size(); + map::iterator en = R.m.end(); - if( !nf ) { // Propagate rgn #1 to all block members + if( !nf ) { // Propagate rgn #1 to all block members - // For each transform in vH... + // For each transform in vH... - for( int ih = 0; ih < nh; ++ih ) { + for( int ih = 0; ih < nh; ++ih ) { - // Get its block start and limit {j0,jlim} + // Get its block start and limit {j0,jlim} - const CIDRH& H = vH[ih]; - map::iterator mi = R.m.find( H.id ); - int j0, jlim; + const CIDRH& H = vH[ih]; + map::iterator mi = R.m.find( H.id ); + int j0, jlim; - if( mi == en ) - continue; + if( mi == en ) + continue; - j0 = mi->second; - jlim = (++mi != en ? mi->second : R.nr); + j0 = mi->second; + jlim = (++mi != en ? mi->second : R.nr); - // Propagate rgn #1 tform to all block members + // Propagate rgn #1 tform to all block members - for( int j = j0; j < jlim; ++j ) { + for( int j = j0; j < jlim; ++j ) { - if( !in || R.pts[j].size() >= 4 ) { - H.H.CopyOut( &x[j * 8] ); - FLAG_SETUSED( R.flag[j] ); - } - else - FLAG_SETPNTS( R.flag[j] ); - } - } - } - else { // Move each H to its specified position + if( !in || R.pts[j].size() >= 4 ) { + H.H.CopyOut( &x[j * 8] ); + FLAG_SETUSED( R.flag[j] ); + } + else + FLAG_SETPNTS( R.flag[j] ); + } + } + } + else { // Move each H to its specified position - // For each transform in vH... + // For each transform in vH... - for( int ih = 0; ih < nh; ++ih ) { + for( int ih = 0; ih < nh; ++ih ) { - // Get its location j + // Get its location j - const CIDRH& H = vH[ih]; - map::iterator mi = R.m.find( H.id ); - int j; + const CIDRH& H = vH[ih]; + map::iterator mi = R.m.find( H.id ); + int j; - if( mi == en ) - continue; + if( mi == en ) + continue; - j = mi->second + H.r - 1; + j = mi->second + H.r - 1; - if( !in || R.pts[j].size() >= 4 ) { - H.H.CopyOut( &x[j * 8] ); - FLAG_SETUSED( R.flag[j] ); - } - else - FLAG_SETPNTS( R.flag[j] ); - } - } - } + if( !in || R.pts[j].size() >= 4 ) { + H.H.CopyOut( &x[j * 8] ); + FLAG_SETUSED( R.flag[j] ); + } + else + FLAG_SETPNTS( R.flag[j] ); + } + } + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -359,59 +359,59 @@ static void* _HFromTxt( void* ithr ) static void ReadXBin( vector &x, int z ) { - char buf[2048]; - FILE *f; + char buf[2048]; + FILE *f; - sprintf( buf, "%s/X_%c_%d.bin", - gpath, (ME->NE == 6 ? 'A' : 'H'), z ); + sprintf( buf, "%s/X_%c_%d.bin", + gpath, (ME->NE == 6 ? 'A' : 'H'), z ); - f = FileOpenOrDie( buf, "rb" ); - fread( &x[0], sizeof(double), x.size(), f ); - fclose( f ); + f = FileOpenOrDie( buf, "rb" ); + fread( &x[0], sizeof(double), x.size(), f ); + fclose( f ); } static void ReadFBin( vector &f, int z ) { - char buf[2048]; - FILE *q; + char buf[2048]; + FILE *q; - sprintf( buf, "%s/F_%d.bin", gpath, z ); - q = FileOpenOrDie( buf, "rb" ); - fread( &f[0], sizeof(uint8), f.size(), q ); - fclose( q ); + sprintf( buf, "%s/F_%d.bin", gpath, z ); + q = FileOpenOrDie( buf, "rb" ); + fread( &f[0], sizeof(uint8), f.size(), q ); + fclose( q ); } static void* _XFromBin( void* ithr ) { - for( int iz = zolo + (long)ithr; iz <= zohi; iz += nthr ) { + for( int iz = zolo + (long)ithr; iz <= zohi; iz += nthr ) { - Rgns& R = vR[iz]; - vector& x = ME->X[iz]; - int minpts = ME->NE / 2; + Rgns& R = vR[iz]; + vector& x = ME->X[iz]; + int minpts = ME->NE / 2; - x.resize( R.nr * ME->NE ); - ReadXBin( x, R.z ); - ReadFBin( R.flag, R.z ); + x.resize( R.nr * ME->NE ); + ReadXBin( x, R.z ); + ReadFBin( R.flag, R.z ); - // If read tforms are in wings we adopt their - // flags as is and our only concern is whether - // they are used or not via FLAG_ISUSED(). - // - // If in our inner range, we test point count. - // - if( iz >= zilo && iz <= zihi ) { + // If read tforms are in wings we adopt their + // flags as is and our only concern is whether + // they are used or not via FLAG_ISUSED(). + // + // If in our inner range, we test point count. + // + if( iz >= zilo && iz <= zihi ) { - for( int j = 0; j < R.nr; ++j ) { + for( int j = 0; j < R.nr; ++j ) { - if( R.pts[j].size() < minpts ) - FLAG_ADDPNTS( R.flag[j] ); - } - } - } + if( R.pts[j].size() < minpts ) + FLAG_ADDPNTS( R.flag[j] ); + } + } + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -420,42 +420,42 @@ static void* _XFromBin( void* ithr ) static void SaveXBin( const vector &x, int z ) { - char buf[64]; - FILE *f; + char buf[64]; + FILE *f; - sprintf( buf, "%s/X_%c_%d.bin", - gpath, (ME->NE == 6 ? 'A' : 'H'), z ); + sprintf( buf, "%s/X_%c_%d.bin", + gpath, (ME->NE == 6 ? 'A' : 'H'), z ); - f = FileOpenOrDie( buf, "wb" ); - fwrite( &x[0], sizeof(double), x.size(), f ); - fclose( f ); + f = FileOpenOrDie( buf, "wb" ); + fwrite( &x[0], sizeof(double), x.size(), f ); + fclose( f ); } static void SaveFBin( const vector &f, int z ) { - char buf[64]; - FILE *q; + char buf[64]; + FILE *q; - sprintf( buf, "%s/F_%d.bin", gpath, z ); - q = FileOpenOrDie( buf, "wb" ); - fwrite( &f[0], sizeof(uint8), f.size(), q ); - fclose( q ); + sprintf( buf, "%s/F_%d.bin", gpath, z ); + q = FileOpenOrDie( buf, "wb" ); + fwrite( &f[0], sizeof(uint8), f.size(), q ); + fclose( q ); } static void* _Save( void* ithr ) { - for( int iz = zilo + (long)ithr; iz <= zihi; iz += nthr ) { + for( int iz = zilo + (long)ithr; iz <= zihi; iz += nthr ) { - const Rgns& R = vR[iz]; - const vector& x = ME->X[iz]; + const Rgns& R = vR[iz]; + const vector& x = ME->X[iz]; - SaveXBin( x, R.z ); - SaveFBin( R.flag, R.z ); - } + SaveXBin( x, R.z ); + SaveFBin( R.flag, R.z ); + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -464,18 +464,18 @@ static void* _Save( void* ithr ) static void* _UpdtFS( void* ithr ) { - int nz = giz.size(); + int nz = giz.size(); - for( int iz = (long)ithr; iz < nz; iz += nthr ) { + for( int iz = (long)ithr; iz < nz; iz += nthr ) { - Rgns& R = vR[giz[iz]]; - vector& x = ME->X[giz[iz]]; + Rgns& R = vR[giz[iz]]; + vector& x = ME->X[giz[iz]]; - ReadXBin( x, R.z ); - ReadFBin( R.flag, R.z ); - } + ReadXBin( x, R.z ); + ReadFBin( R.flag, R.z ); + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -484,14 +484,14 @@ static void* _UpdtFS( void* ithr ) void XArray::Resize( int ne ) { - NE = ne; + NE = ne; - int nz = zohi - zolo + 1; + int nz = zohi - zolo + 1; - X.resize( nz ); + X.resize( nz ); - for( int iz = 0; iz < nz; ++iz ) - X[iz].resize( vR[iz].nr * ne ); + for( int iz = 0; iz < nz; ++iz ) + X[iz].resize( vR[iz].nr * ne ); } /* --------------------------------------------------------------- */ @@ -500,76 +500,76 @@ void XArray::Resize( int ne ) void XArray::Load( const char *path ) { - clock_t t0 = StartTiming(); - - int nz = zohi - zolo + 1; - - X.resize( nz ); - - ME = this; - gpath = path; - nthr = maxthreads; - - if( nthr > nz ) - nthr = nz; - - EZThreadproc proc; - const char *sproc; - - if( !path || !path[0] ) { - NE = 6; - proc = _AFromIDB; - sproc = "AFromIDB"; - } - else { - - const char *name = FileNamePtr( path ); - - if( strstr( name, "X_A" ) ) { - - NE = 6; - - if( strstr( name, "X_A_TXT" ) || - strstr( name, "X_A_MET" ) ) { - - proc = _AFromTxt; - sproc = "AFromTxt"; - } - else if( strstr( name, "X_A_BIN" ) ) { - proc = _XFromBin; - sproc = "XFromBin"; - } - else - goto error; - } - else if( strstr( name, "X_H" ) ) { - - NE = 8; - - if( strstr( name, "X_H_TXT" ) || - strstr( name, "X_H_MET" ) ) { - - proc = _HFromTxt; - sproc = "HFromTxt"; - } - else if( strstr( name, "X_H_BIN" ) ) { - proc = _XFromBin; - sproc = "XFromBin"; - } - else - goto error; - } - else { + clock_t t0 = StartTiming(); + + int nz = zohi - zolo + 1; + + X.resize( nz ); + + ME = this; + gpath = path; + nthr = maxthreads; + + if( nthr > nz ) + nthr = nz; + + EZThreadproc proc; + const char *sproc; + + if( !path || !path[0] ) { + NE = 6; + proc = _AFromIDB; + sproc = "AFromIDB"; + } + else { + + const char *name = FileNamePtr( path ); + + if( strstr( name, "X_A" ) ) { + + NE = 6; + + if( strstr( name, "X_A_TXT" ) || + strstr( name, "X_A_MET" ) ) { + + proc = _AFromTxt; + sproc = "AFromTxt"; + } + else if( strstr( name, "X_A_BIN" ) ) { + proc = _XFromBin; + sproc = "XFromBin"; + } + else + goto error; + } + else if( strstr( name, "X_H" ) ) { + + NE = 8; + + if( strstr( name, "X_H_TXT" ) || + strstr( name, "X_H_MET" ) ) { + + proc = _HFromTxt; + sproc = "HFromTxt"; + } + else if( strstr( name, "X_H_BIN" ) ) { + proc = _XFromBin; + sproc = "XFromBin"; + } + else + goto error; + } + else { error: - printf( "Unknown prior type [%s].\n", name ); - exit( 42 ); - } - } + printf( "Unknown prior type [%s].\n", name ); + exit( 42 ); + } + } - if( !EZThreads( proc, nthr, 1, sproc ) ) - exit( 42 ); + if( !EZThreads( proc, nthr, 1, sproc ) ) + exit( 42 ); - StopTiming( stdout, sproc, t0 ); + StopTiming( stdout, sproc, t0 ); } /* --------------------------------------------------------------- */ @@ -580,25 +580,25 @@ void XArray::Load( const char *path ) // void XArray::Save() const { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - int nz = nz = zihi - zilo + 1; + int nz = nz = zihi - zilo + 1; - char buf[32]; - sprintf( buf, "X_%c_BIN", (NE == 6 ? 'A' : 'H') ); - DskCreateDir( buf, stdout ); + char buf[32]; + sprintf( buf, "X_%c_BIN", (NE == 6 ? 'A' : 'H') ); + DskCreateDir( buf, stdout ); - ME = (XArray*)this; - gpath = buf; - nthr = maxthreads; + ME = (XArray*)this; + gpath = buf; + nthr = maxthreads; - if( nthr > nz ) - nthr = nz; + if( nthr > nz ) + nthr = nz; - if( !EZThreads( _Save, nthr, 1, "_XArraySave" ) ) - exit( 42 ); + if( !EZThreads( _Save, nthr, 1, "_XArraySave" ) ) + exit( 42 ); - StopTiming( stdout, "Save", t0 ); + StopTiming( stdout, "Save", t0 ); } /* --------------------------------------------------------------- */ @@ -611,37 +611,37 @@ void XArray::Save() const // void XArray::UpdtFS() { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - giz.clear(); + giz.clear(); - for( int i = zolo; i < zilo; ++i ) - giz.push_back( i ); + for( int i = zolo; i < zilo; ++i ) + giz.push_back( i ); - for( int i = zihi + 1; i <= zohi; ++i ) - giz.push_back( i ); + for( int i = zihi + 1; i <= zohi; ++i ) + giz.push_back( i ); - int nz = giz.size(); + int nz = giz.size(); - if( !nz ) - return; + if( !nz ) + return; - char buf[32]; - sprintf( buf, "X_%c_BIN", (NE == 6 ? 'A' : 'H') ); + char buf[32]; + sprintf( buf, "X_%c_BIN", (NE == 6 ? 'A' : 'H') ); - ME = this; - gpath = buf; - nthr = maxthreads; + ME = this; + gpath = buf; + nthr = maxthreads; - if( nthr > nz ) - nthr = nz; + if( nthr > nz ) + nthr = nz; - if( !EZThreads( _UpdtFS, nthr, 1, "_UpdtFS" ) ) - exit( 42 ); + if( !EZThreads( _UpdtFS, nthr, 1, "_UpdtFS" ) ) + exit( 42 ); - giz.clear(); + giz.clear(); - StopTiming( stdout, "Updt", t0 ); + StopTiming( stdout, "Updt", t0 ); } /* --------------------------------------------------------------- */ @@ -650,39 +650,39 @@ void XArray::UpdtFS() bool XArray::Send( int zlo, int zhi, int XorF, int toLorR ) { - void *buf; - int bytes, - wdst; + void *buf; + int bytes, + wdst; - if( toLorR == 'L' ) { + if( toLorR == 'L' ) { - wdst = wkid - 1; + wdst = wkid - 1; - if( wdst < 0 ) - return true; - } - else { - wdst = wkid + 1; + if( wdst < 0 ) + return true; + } + else { + wdst = wkid + 1; - if( wdst >= nwks ) - return true; - } + if( wdst >= nwks ) + return true; + } - for( int iz = zlo; iz <= zhi; ++iz ) { + for( int iz = zlo; iz <= zhi; ++iz ) { - if( XorF == 'X' ) { - buf = (void*)&X[iz][0]; - bytes = sizeof(double) * X[iz].size(); - } - else { - buf = (void*)&vR[iz].flag[0]; - bytes = vR[iz].nr; - } + if( XorF == 'X' ) { + buf = (void*)&X[iz][0]; + bytes = sizeof(double) * X[iz].size(); + } + else { + buf = (void*)&vR[iz].flag[0]; + bytes = vR[iz].nr; + } - MPISend( buf, bytes, wdst, iz - zlo ); - } + MPISend( buf, bytes, wdst, iz - zlo ); + } - return true; + return true; } /* --------------------------------------------------------------- */ @@ -691,39 +691,39 @@ bool XArray::Send( int zlo, int zhi, int XorF, int toLorR ) bool XArray::Recv( int zlo, int zhi, int XorF, int fmLorR ) { - void *buf; - int bytes, - wsrc; + void *buf; + int bytes, + wsrc; - if( fmLorR == 'L' ) { + if( fmLorR == 'L' ) { - wsrc = wkid - 1; + wsrc = wkid - 1; - if( wsrc < 0 ) - return true; - } - else { - wsrc = wkid + 1; + if( wsrc < 0 ) + return true; + } + else { + wsrc = wkid + 1; - if( wsrc >= nwks ) - return true; - } + if( wsrc >= nwks ) + return true; + } - for( int iz = zlo; iz <= zhi; ++iz ) { + for( int iz = zlo; iz <= zhi; ++iz ) { - if( XorF == 'X' ) { - buf = (void*)&X[iz][0]; - bytes = sizeof(double) * X[iz].size(); - } - else { - buf = (void*)&vR[iz].flag[0]; - bytes = vR[iz].nr; - } + if( XorF == 'X' ) { + buf = (void*)&X[iz][0]; + bytes = sizeof(double) * X[iz].size(); + } + else { + buf = (void*)&vR[iz].flag[0]; + bytes = vR[iz].nr; + } - MPIRecv( buf, bytes, wsrc, iz - zlo ); - } + MPIRecv( buf, bytes, wsrc, iz - zlo ); + } - return true; + return true; } /* --------------------------------------------------------------- */ @@ -732,8 +732,8 @@ bool XArray::Recv( int zlo, int zhi, int XorF, int fmLorR ) bool XArray::Updt() { - if( nwks <= 1 ) - return true; + if( nwks <= 1 ) + return true; // To avoid deadlocks, we arrange that at any given time, // any node is just sending or just receiving. Easily done @@ -741,43 +741,43 @@ bool XArray::Updt() // Odd send - if( wkid & 1 ) { + if( wkid & 1 ) { - Send( zLlo, zLhi, 'X', 'L' ); - Send( zLlo, zLhi, 'F', 'L' ); + Send( zLlo, zLhi, 'X', 'L' ); + Send( zLlo, zLhi, 'F', 'L' ); - Send( zRlo, zRhi, 'X', 'R' ); - Send( zRlo, zRhi, 'F', 'R' ); - } - else { + Send( zRlo, zRhi, 'X', 'R' ); + Send( zRlo, zRhi, 'F', 'R' ); + } + else { - Recv( zihi + 1, zohi, 'X', 'R' ); - Recv( zihi + 1, zohi, 'F', 'R' ); + Recv( zihi + 1, zohi, 'X', 'R' ); + Recv( zihi + 1, zohi, 'F', 'R' ); - Recv( zolo, zilo - 1, 'X', 'L' ); - Recv( zolo, zilo - 1, 'F', 'L' ); - } + Recv( zolo, zilo - 1, 'X', 'L' ); + Recv( zolo, zilo - 1, 'F', 'L' ); + } // Even send - if( !(wkid & 1) ) { + if( !(wkid & 1) ) { - Send( zLlo, zLhi, 'X', 'L' ); - Send( zLlo, zLhi, 'F', 'L' ); + Send( zLlo, zLhi, 'X', 'L' ); + Send( zLlo, zLhi, 'F', 'L' ); - Send( zRlo, zRhi, 'X', 'R' ); - Send( zRlo, zRhi, 'F', 'R' ); - } - else { + Send( zRlo, zRhi, 'X', 'R' ); + Send( zRlo, zRhi, 'F', 'R' ); + } + else { - Recv( zihi + 1, zohi, 'X', 'R' ); - Recv( zihi + 1, zohi, 'F', 'R' ); + Recv( zihi + 1, zohi, 'X', 'R' ); + Recv( zihi + 1, zohi, 'F', 'R' ); - Recv( zolo, zilo - 1, 'X', 'L' ); - Recv( zolo, zilo - 1, 'F', 'L' ); - } + Recv( zolo, zilo - 1, 'X', 'L' ); + Recv( zolo, zilo - 1, 'F', 'L' ); + } - return true; + return true; } diff --git a/1_LSQw/lsq_XArray.h b/1_LSQw/lsq_XArray.h index daf86b1..0426603 100644 --- a/1_LSQw/lsq_XArray.h +++ b/1_LSQw/lsq_XArray.h @@ -13,18 +13,18 @@ using namespace std; class XArray { public: - int NE; - vector > X; + int NE; + vector > X; public: - void Resize( int ne ); - void Load( const char *path ); - void Save() const; - void UpdtFS(); + void Resize( int ne ); + void Load( const char *path ); + void Save() const; + void UpdtFS(); private: - bool Send( int zlo, int zhi, int XorF, int toLorR ); - bool Recv( int zlo, int zhi, int XorF, int fmLorR ); + bool Send( int zlo, int zhi, int XorF, int toLorR ); + bool Recv( int zlo, int zhi, int XorF, int fmLorR ); public: - bool Updt(); + bool Updt(); }; diff --git a/1_LSQw/lsqw.cpp b/1_LSQw/lsqw.cpp index 0aaf09e..cbe3730 100644 --- a/1_LSQw/lsqw.cpp +++ b/1_LSQw/lsqw.cpp @@ -26,42 +26,42 @@ class CArgs { public: - double Wr, // Aff -> (1-Wr)*Aff + Wr*Rgd - Etol; // point error tolerance - const char *tempdir, // master workspace - *cachedir, // {catalog, pnts} files - *prior, // start from these solutions - *mode; // {catalog,eval,split,A2A,A2H,H2H} - int zilo, // my output range - zihi, - zolo, // extended input range - zohi, - regtype, // regularizer {T,R} - iters, // solve iterations - splitmin; // separate islands > splitmin tiles - bool untwist; // iff prior are affines + double Wr, // Aff -> (1-Wr)*Aff + Wr*Rgd + Etol; // point error tolerance + const char *tempdir, // master workspace + *cachedir, // {catalog, pnts} files + *prior, // start from these solutions + *mode; // {catalog,eval,split,A2A,A2H,H2H} + int zilo, // my output range + zihi, + zolo, // extended input range + zohi, + regtype, // regularizer {T,R} + iters, // solve iterations + splitmin; // separate islands > splitmin tiles + bool untwist; // iff prior are affines public: - CArgs() - { - Wr = 0.001; - Etol = 30; - tempdir = NULL; - cachedir = NULL; - prior = NULL; - mode = NULL; - zilo = 0; - zihi = 0; - zolo = -1; - zohi = -1; - regtype = 'R'; - iters = 2000; - splitmin = 1000; - untwist = false; - }; - - bool SetCmdLine( int argc, char* argv[] ); - bool GetRanges(); + CArgs() + { + Wr = 0.001; + Etol = 30; + tempdir = NULL; + cachedir = NULL; + prior = NULL; + mode = NULL; + zilo = 0; + zihi = 0; + zolo = -1; + zohi = -1; + regtype = 'R'; + iters = 2000; + splitmin = 1000; + untwist = false; + }; + + bool SetCmdLine( int argc, char* argv[] ); + bool GetRanges(); }; /* --------------------------------------------------------------- */ @@ -83,72 +83,72 @@ bool CArgs::SetCmdLine( int argc, char* argv[] ) { // Parse command line args - vector vi; - - for( int i = 1; i < argc; ++i ) { - - if( GetArgStr( tempdir, "-temp=", argv[i] ) ) { - - printf( "Temp dir: '%s'.\n", tempdir ); - GetIDB( tempdir ); - } - else if( GetArgStr( cachedir, "-cache=", argv[i] ) ) - printf( "Cache dir: '%s'.\n", cachedir ); - else if( GetArgStr( prior, "-prior=", argv[i] ) ) - printf( "Prior solutions: '%s'.\n", prior ); - else if( GetArgStr( mode, "-mode=", argv[i] ) ) - printf( "Mode: '%s'.\n", mode ); - else if( GetArg( &nwks, "-nwks=%d", argv[i] ) ) - ; - else if( GetArgList( vi, "-zi=", argv[i] ) ) { - - if( 2 == vi.size() ) { - zilo = vi[0]; - zihi = vi[1]; - printf( "zi [%d %d]\n", zilo, zihi ); - } - else { - printf( "Bad format in -zi [%s].\n", argv[i] ); - return false; - } - } - else if( GetArgList( vi, "-zo=", argv[i] ) ) { - - if( 2 == vi.size() ) { - zolo = vi[0]; - zohi = vi[1]; - printf( "zo [%d %d]\n", zolo, zohi ); - } - else { - printf( "Bad format in -zo [%s].\n", argv[i] ); - return false; - } - } - else if( GetArg( &Wr, "-Wr=T,%lf", argv[i] ) ) { - regtype = 'T'; - printf( "Rglizer Wr: T, %g\n", Wr ); - } - else if( GetArg( &Wr, "-Wr=R,%lf", argv[i] ) ) { - regtype = 'R'; - printf( "Rglizer Wr: R, %g\n", Wr ); - } - else if( GetArg( &Etol, "-Etol=%lf", argv[i] ) ) - printf( "Error tol: %g\n", Etol ); - else if( GetArg( &iters, "-iters=%d", argv[i] ) ) - printf( "Iterations: %d\n", iters ); - else if( GetArg( &splitmin, "-splitmin=%d", argv[i] ) ) - printf( "Split-min: %d\n", splitmin ); - else if( GetArg( &maxthreads, "-maxthreads=%d", argv[i] ) ) - printf( "Maxthreads: %d\n", maxthreads ); - else if( IsArg( "-untwist", argv[i] ) ) - untwist = true; - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - return false; - } - } - - return true; + vector vi; + + for( int i = 1; i < argc; ++i ) { + + if( GetArgStr( tempdir, "-temp=", argv[i] ) ) { + + printf( "Temp dir: '%s'.\n", tempdir ); + GetIDB( tempdir ); + } + else if( GetArgStr( cachedir, "-cache=", argv[i] ) ) + printf( "Cache dir: '%s'.\n", cachedir ); + else if( GetArgStr( prior, "-prior=", argv[i] ) ) + printf( "Prior solutions: '%s'.\n", prior ); + else if( GetArgStr( mode, "-mode=", argv[i] ) ) + printf( "Mode: '%s'.\n", mode ); + else if( GetArg( &nwks, "-nwks=%d", argv[i] ) ) + ; + else if( GetArgList( vi, "-zi=", argv[i] ) ) { + + if( 2 == vi.size() ) { + zilo = vi[0]; + zihi = vi[1]; + printf( "zi [%d %d]\n", zilo, zihi ); + } + else { + printf( "Bad format in -zi [%s].\n", argv[i] ); + return false; + } + } + else if( GetArgList( vi, "-zo=", argv[i] ) ) { + + if( 2 == vi.size() ) { + zolo = vi[0]; + zohi = vi[1]; + printf( "zo [%d %d]\n", zolo, zohi ); + } + else { + printf( "Bad format in -zo [%s].\n", argv[i] ); + return false; + } + } + else if( GetArg( &Wr, "-Wr=T,%lf", argv[i] ) ) { + regtype = 'T'; + printf( "Rglizer Wr: T, %g\n", Wr ); + } + else if( GetArg( &Wr, "-Wr=R,%lf", argv[i] ) ) { + regtype = 'R'; + printf( "Rglizer Wr: R, %g\n", Wr ); + } + else if( GetArg( &Etol, "-Etol=%lf", argv[i] ) ) + printf( "Error tol: %g\n", Etol ); + else if( GetArg( &iters, "-iters=%d", argv[i] ) ) + printf( "Iterations: %d\n", iters ); + else if( GetArg( &splitmin, "-splitmin=%d", argv[i] ) ) + printf( "Split-min: %d\n", splitmin ); + else if( GetArg( &maxthreads, "-maxthreads=%d", argv[i] ) ) + printf( "Maxthreads: %d\n", maxthreads ); + else if( IsArg( "-untwist", argv[i] ) ) + untwist = true; + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + return false; + } + } + + return true; } /* --------------------------------------------------------------- */ @@ -163,69 +163,69 @@ bool CArgs::SetCmdLine( int argc, char* argv[] ) // bool CArgs::GetRanges() { - if( nwks <= 1 ) - return true; + if( nwks <= 1 ) + return true; - FILE *f = FileOpenOrDie( "ranges.txt", "r" ); - CLineScan LS; - int code = 0; // {4=LHS, 2=me, 1=RHS} + FILE *f = FileOpenOrDie( "ranges.txt", "r" ); + CLineScan LS; + int code = 0; // {4=LHS, 2=me, 1=RHS} // Need entries for my left, for me, and my right, // unless I am the far left or right in which case // we preset that success code. - if( !wkid ) - code += 4; - else if( wkid == nwks - 1 ) - code += 1; + if( !wkid ) + code += 4; + else if( wkid == nwks - 1 ) + code += 1; - while( code != 7 && LS.Get( f ) > 0 ) { + while( code != 7 && LS.Get( f ) > 0 ) { - int iw = atoi( LS.line ); + int iw = atoi( LS.line ); - if( iw < wkid - 1 ) - continue; - else if( iw == wkid - 1 ) { // LHS + if( iw < wkid - 1 ) + continue; + else if( iw == wkid - 1 ) { // LHS - int dum1, dum2; + int dum1, dum2; - sscanf( LS.line, "%d zi=%d,%d zo=%d,%d", - &iw, &dum1, &zLlo, &dum2, &zLhi ); + sscanf( LS.line, "%d zi=%d,%d zo=%d,%d", + &iw, &dum1, &zLlo, &dum2, &zLhi ); - zLlo; // InitTables() must set layer after this - code += 4; - } - else if( iw == wkid ) { // me + zLlo; // InitTables() must set layer after this + code += 4; + } + else if( iw == wkid ) { // me - sscanf( LS.line, "%d zi=%d,%d zo=%d,%d", - &iw, &zilo, &zihi, &zolo, &zohi ); + sscanf( LS.line, "%d zi=%d,%d zo=%d,%d", + &iw, &zilo, &zihi, &zolo, &zohi ); - printf( "zi [%d %d]\n", zilo, zihi ); - printf( "zo [%d %d]\n", zolo, zohi ); + printf( "zi [%d %d]\n", zilo, zihi ); + printf( "zo [%d %d]\n", zolo, zohi ); - code += 2; - } - else if( iw == wkid + 1 ) { // RHS + code += 2; + } + else if( iw == wkid + 1 ) { // RHS - int dum1, dum2; + int dum1, dum2; - sscanf( LS.line, "%d zi=%d,%d zo=%d,%d", - &iw, &zRhi, &dum1, &zRlo, &dum2 ); + sscanf( LS.line, "%d zi=%d,%d zo=%d,%d", + &iw, &zRhi, &dum1, &zRlo, &dum2 ); - zRhi; // InitTables() must set layer before this - code += 1; - break; - } - } + zRhi; // InitTables() must set layer before this + code += 1; + break; + } + } - fclose( f ); + fclose( f ); - if( code != 7 ) { - printf( "Ranges.txt: Missing entries for wkid %d.\n", wkid ); - return false; - } + if( code != 7 ) { + printf( "Ranges.txt: Missing entries for wkid %d.\n", wkid ); + return false; + } - return true; + return true; } /* --------------------------------------------------------------- */ @@ -234,26 +234,26 @@ bool CArgs::GetRanges() static void Evaluate( const XArray &X ) { - DBox B; - Bounds( B, X ); + DBox B; + Bounds( B, X ); - Magnitude( X ); - Error( X, gArgs.Etol ); + Magnitude( X ); + Error( X, gArgs.Etol ); - Dropout D; - D.Scan(); + Dropout D; + D.Scan(); - if( !wkid ) { + if( !wkid ) { - double erms, emax; - GetFinalError( erms, emax ); + double erms, emax; + GetFinalError( erms, emax ); - printf( - "\nFINAL RMS %.2f MAX %.2f" - " {Mx,Rd,Pt,Ki,Cd} %ld %ld %ld %ld %ld\n", - erms, emax, - D.rmax, D.read, D.pnts, D.kill, D.cutd ); - } + printf( + "\nFINAL RMS %.2f MAX %.2f" + " {Mx,Rd,Pt,Ki,Cd} %ld %ld %ld %ld %ld\n", + erms, emax, + D.rmax, D.read, D.pnts, D.kill, D.cutd ); + } } /* --------------------------------------------------------------- */ @@ -262,132 +262,132 @@ static void Evaluate( const XArray &X ) int main( int argc, char **argv ) { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); /* ---------- */ /* Parameters */ /* ---------- */ - MPIInit( argc, argv ); + MPIInit( argc, argv ); - if( !gArgs.SetCmdLine( argc, argv ) || - !gArgs.GetRanges() ) { + if( !gArgs.SetCmdLine( argc, argv ) || + !gArgs.GetRanges() ) { - MPIExit(); - exit( 42 ); - } + MPIExit(); + exit( 42 ); + } /* ------------ */ /* Initial data */ /* ------------ */ - if( !LayerCat( vL, gArgs.tempdir, gArgs.cachedir, - gArgs.zolo, gArgs.zohi, false ) ) { + if( !LayerCat( vL, gArgs.tempdir, gArgs.cachedir, + gArgs.zolo, gArgs.zohi, false ) ) { - MPIExit(); - exit( 42 ); - } + MPIExit(); + exit( 42 ); + } - InitTables( gArgs.zilo, gArgs.zihi ); + InitTables( gArgs.zilo, gArgs.zihi ); - { - CLoadPoints *LP = new CLoadPoints; - LP->Load( gArgs.tempdir, gArgs.cachedir ); - delete LP; - } + { + CLoadPoints *LP = new CLoadPoints; + LP->Load( gArgs.tempdir, gArgs.cachedir ); + delete LP; + } /* ----- */ /* Solve */ /* ----- */ - printf( "\n---- Solve ----\n" ); + printf( "\n---- Solve ----\n" ); - SetSolveParams( gArgs.regtype, gArgs.Wr, gArgs.Etol ); + SetSolveParams( gArgs.regtype, gArgs.Wr, gArgs.Etol ); - XArray Xevn, Xodd; + XArray Xevn, Xodd; - if( !strcmp( gArgs.mode, "A2A" ) ) { + if( !strcmp( gArgs.mode, "A2A" ) ) { - Xevn.Load( gArgs.prior ); + Xevn.Load( gArgs.prior ); - if( gArgs.untwist ) - UntwistAffines( Xevn ); + if( gArgs.untwist ) + UntwistAffines( Xevn ); - Xodd.Resize( 6 ); - Solve( Xevn, Xodd, gArgs.iters ); - } - else if( !strcmp( gArgs.mode, "A2H" ) ) { + Xodd.Resize( 6 ); + Solve( Xevn, Xodd, gArgs.iters ); + } + else if( !strcmp( gArgs.mode, "A2H" ) ) { - Xevn.Resize( 8 ); + Xevn.Resize( 8 ); - { // limit A lifetime - XArray *A = new XArray; - A->Load( gArgs.prior ); + { // limit A lifetime + XArray *A = new XArray; + A->Load( gArgs.prior ); - if( gArgs.untwist ) - UntwistAffines( *A ); + if( gArgs.untwist ) + UntwistAffines( *A ); - Solve( *A, Xevn, 1 ); - delete A; - } + Solve( *A, Xevn, 1 ); + delete A; + } - Xodd.Resize( 8 ); - Solve( Xevn, Xodd, gArgs.iters ); - } - else if( !strcmp( gArgs.mode, "H2H" ) ) { + Xodd.Resize( 8 ); + Solve( Xevn, Xodd, gArgs.iters ); + } + else if( !strcmp( gArgs.mode, "H2H" ) ) { - Xevn.Load( gArgs.prior ); - Xodd.Resize( 8 ); - Solve( Xevn, Xodd, gArgs.iters ); - } - else if( !strcmp( gArgs.mode, "eval" ) ) { + Xevn.Load( gArgs.prior ); + Xodd.Resize( 8 ); + Solve( Xevn, Xodd, gArgs.iters ); + } + else if( !strcmp( gArgs.mode, "eval" ) ) { - Xevn.Load( gArgs.prior ); + Xevn.Load( gArgs.prior ); - if( gArgs.untwist ) - UntwistAffines( Xevn ); + if( gArgs.untwist ) + UntwistAffines( Xevn ); - gArgs.iters = 0; - } - else { // split + gArgs.iters = 0; + } + else { // split - Xevn.Load( gArgs.prior ); - gArgs.iters = 0; - } + Xevn.Load( gArgs.prior ); + gArgs.iters = 0; + } - const XArray& Xfinal = ((gArgs.iters & 1) ? Xodd : Xevn); + const XArray& Xfinal = ((gArgs.iters & 1) ? Xodd : Xevn); /* ----------- */ /* Postprocess */ /* ----------- */ - if( gArgs.mode[0] == 's' ) { + if( gArgs.mode[0] == 's' ) { - Split S( Xfinal, gArgs.splitmin ); + Split S( Xfinal, gArgs.splitmin ); - S.Run(); - } - else { + S.Run(); + } + else { - Evaluate( Xfinal ); + Evaluate( Xfinal ); - if( gArgs.mode[0] != 'e' ) - Xfinal.Save(); - } + if( gArgs.mode[0] != 'e' ) + Xfinal.Save(); + } /* ------- */ /* Cleanup */ /* ------- */ - if( !wkid ) { - printf( "\n" ); - StopTiming( stdout, "Lsq", t0 ); - } + if( !wkid ) { + printf( "\n" ); + StopTiming( stdout, "Lsq", t0 ); + } - MPIExit(); - VMStats( stdout ); + MPIExit(); + VMStats( stdout ); - return 0; + return 0; } diff --git a/1_LSQw/makefile b/1_LSQw/makefile index 6b2cd9d..567b768 100644 --- a/1_LSQw/makefile +++ b/1_LSQw/makefile @@ -32,8 +32,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_LsqErr/lsqerr.cpp b/1_LsqErr/lsqerr.cpp index 85e0339..011ca98 100644 --- a/1_LsqErr/lsqerr.cpp +++ b/1_LsqErr/lsqerr.cpp @@ -29,9 +29,9 @@ class CHst { public: - long *all, *sam, *dwn; + long *all, *sam, *dwn; public: - void GetFile( const char *name ); + void GetFile( const char *name ); }; /* --------------------------------------------------------------- */ @@ -40,12 +40,12 @@ class CHst { class CArgs_lsqerr { public: - char *inA, *inB; - int lim, div; + char *inA, *inB; + int lim, div; public: - CArgs_lsqerr() : inA(NULL), inB(NULL), lim(200), div(1) {}; + CArgs_lsqerr() : inA(NULL), inB(NULL), lim(200), div(1) {}; - void SetCmdLine( int argc, char* argv[] ); + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -69,42 +69,42 @@ void CArgs_lsqerr::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "lsqerrhst.txt", "w" ); + flog = FileOpenOrDie( "lsqerrhst.txt", "w" ); // parse command line args - if( argc < 2 ) { - printf( "Usage: lsqerr fileA [fileB] [options].\n" ); - exit( 42 ); - } - - for( int i = 1; i < argc; ++i ) { - - if( argv[i][0] != '-' ) { - - if( !inA ) - inA = argv[i]; - else - inB = argv[i]; - } - else if( GetArg( &lim, "-lim=%d", argv[i] ) ) - ; - else if( GetArg( &div, "-div=%d", argv[i] ) ) - ; - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - exit( 42 ); - } - } + if( argc < 2 ) { + printf( "Usage: lsqerr fileA [fileB] [options].\n" ); + exit( 42 ); + } + + for( int i = 1; i < argc; ++i ) { + + if( argv[i][0] != '-' ) { + + if( !inA ) + inA = argv[i]; + else + inB = argv[i]; + } + else if( GetArg( &lim, "-lim=%d", argv[i] ) ) + ; + else if( GetArg( &div, "-div=%d", argv[i] ) ) + ; + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + exit( 42 ); + } + } // headers - fprintf( flog, "Err\tAall\tAsam\tAdwn" ); + fprintf( flog, "Err\tAall\tAsam\tAdwn" ); - if( inB ) - fprintf( flog, "\tBall\tBsam\tBdwn\n" ); - else - fprintf( flog, "\n" ); + if( inB ) + fprintf( flog, "\tBall\tBsam\tBdwn\n" ); + else + fprintf( flog, "\n" ); } /* --------------------------------------------------------------- */ @@ -113,54 +113,54 @@ void CArgs_lsqerr::SetCmdLine( int argc, char* argv[] ) void CHst::GetFile( const char *name ) { - FILE *f = FileOpenOrDie( name, "r" ); - CLineScan LS; - int emax = gArgs.lim * gArgs.div; - int bytes = (emax + 1)*sizeof(long); + FILE *f = FileOpenOrDie( name, "r" ); + CLineScan LS; + int emax = gArgs.lim * gArgs.div; + int bytes = (emax + 1)*sizeof(long); - all = (long*)malloc( bytes ); - sam = (long*)malloc( bytes ); - dwn = (long*)malloc( bytes ); + all = (long*)malloc( bytes ); + sam = (long*)malloc( bytes ); + dwn = (long*)malloc( bytes ); - memset( all, 0, bytes ); - memset( sam, 0, bytes ); - memset( dwn, 0, bytes ); + memset( all, 0, bytes ); + memset( sam, 0, bytes ); + memset( dwn, 0, bytes ); - if( LS.Get( f ) <= 0 ) - goto close; + if( LS.Get( f ) <= 0 ) + goto close; - for(;;) { + for(;;) { - double err; - int za, ta, ra, zb, tb, rb; + double err; + int za, ta, ra, zb, tb, rb; - if( LS.Get( f ) <= 0 ) - break; + if( LS.Get( f ) <= 0 ) + break; - sscanf( LS.line, - "%d\t%d\t%d\t%d\t%d\t%d\t%lf", - &za, &ta, &ra, &zb, &tb, &rb, &err ); + sscanf( LS.line, + "%d\t%d\t%d\t%d\t%d\t%d\t%lf", + &za, &ta, &ra, &zb, &tb, &rb, &err ); - if( err < 0 ) { - // -2 = not used - // -1 = not inlier - continue; - } + if( err < 0 ) { + // -2 = not used + // -1 = not inlier + continue; + } - err = gArgs.div * sqrt( err ); + err = gArgs.div * sqrt( err ); - int ibin = (err < emax ? int( err ) : emax); + int ibin = (err < emax ? int( err ) : emax); - ++all[ibin]; + ++all[ibin]; - if( za == zb ) - ++sam[ibin]; - else - ++dwn[ibin]; - } + if( za == zb ) + ++sam[ibin]; + else + ++dwn[ibin]; + } close: - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -169,25 +169,25 @@ void CHst::GetFile( const char *name ) static void Record() { - int n = gArgs.lim * gArgs.div + 1; - - for( int i = 0; i < n; ++i ) { - - if( gArgs.inB ) { - - fprintf( flog, - "%.2f\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\n", - double(i + 1)/gArgs.div, - A.all[i], A.sam[i], A.dwn[i], - B.all[i], B.sam[i], B.dwn[i] ); - } - else { - fprintf( flog, - "%.2f\t%ld\t%ld\t%ld\n", - double(i + 1)/gArgs.div, - A.all[i], A.sam[i], A.dwn[i] ); - } - } + int n = gArgs.lim * gArgs.div + 1; + + for( int i = 0; i < n; ++i ) { + + if( gArgs.inB ) { + + fprintf( flog, + "%.2f\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\n", + double(i + 1)/gArgs.div, + A.all[i], A.sam[i], A.dwn[i], + B.all[i], B.sam[i], B.dwn[i] ); + } + else { + fprintf( flog, + "%.2f\t%ld\t%ld\t%ld\n", + double(i + 1)/gArgs.div, + A.all[i], A.sam[i], A.dwn[i] ); + } + } } /* --------------------------------------------------------------- */ @@ -200,30 +200,30 @@ int main( int argc, char **argv ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* ---- */ /* Read */ /* ---- */ - A.GetFile( gArgs.inA ); + A.GetFile( gArgs.inA ); - if( gArgs.inB ) - B.GetFile( gArgs.inB ); + if( gArgs.inB ) + B.GetFile( gArgs.inB ); /* ----- */ /* Print */ /* ----- */ - Record(); + Record(); /* ---- */ /* Done */ /* ---- */ - fclose( flog ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_LsqErr/makefile b/1_LsqErr/makefile index 699ce94..892d11e 100644 --- a/1_LsqErr/makefile +++ b/1_LsqErr/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_MRCSD1Lyr/MRCSD1Lyr.cpp b/1_MRCSD1Lyr/MRCSD1Lyr.cpp index 6b79c2c..66d4217 100644 --- a/1_MRCSD1Lyr/MRCSD1Lyr.cpp +++ b/1_MRCSD1Lyr/MRCSD1Lyr.cpp @@ -28,12 +28,12 @@ class CArgs_xml { public: - char *xmlfile; - int z; + char *xmlfile; + int z; public: - CArgs_xml() : xmlfile(NULL), z(0) {}; + CArgs_xml() : xmlfile(NULL), z(0) {}; - void SetCmdLine( int argc, char* argv[] ); + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -56,30 +56,30 @@ void CArgs_xml::SetCmdLine( int argc, char* argv[] ) { // parse command line args - if( argc < 3 ) { - printf( - "Usage: MRCSD1Lyr -z= [options].\n" ); - exit( 42 ); - } + if( argc < 3 ) { + printf( + "Usage: MRCSD1Lyr -z= [options].\n" ); + exit( 42 ); + } - for( int i = 1; i < argc; ++i ) { + for( int i = 1; i < argc; ++i ) { - if( argv[i][0] != '-' ) - xmlfile = argv[i]; - else if( GetArg( &z, "-z=%d", argv[i] ) ) - ; - else { - printf( "Did not understand option [%s].\n", argv[i] ); - exit( 42 ); - } - } + if( argv[i][0] != '-' ) + xmlfile = argv[i]; + else if( GetArg( &z, "-z=%d", argv[i] ) ) + ; + else { + printf( "Did not understand option [%s].\n", argv[i] ); + exit( 42 ); + } + } // start log - char buf[256]; + char buf[256]; - sprintf( buf, "sd_%d.txt", z ); - flog = FileOpenOrDie( buf, "w" ); + sprintf( buf, "sd_%d.txt", z ); + flog = FileOpenOrDie( buf, "w" ); } /* --------------------------------------------------------------- */ @@ -88,32 +88,32 @@ void CArgs_xml::SetCmdLine( int argc, char* argv[] ) static int GetSD( TiXmlElement* p ) { - vector vras; - uint32 w, h; + vector vras; + uint32 w, h; - if( 1 > ReadRawMRCFile( vras, p->Attribute( "file_path" ), - w, h, NULL ) ) { + if( 1 > ReadRawMRCFile( vras, p->Attribute( "file_path" ), + w, h, NULL ) ) { - return 0; - } + return 0; + } - const uint16* V = &vras[0][0]; - double sd, sm = 0.0, sm2 = 0.0; - int n = w * h; + const uint16* V = &vras[0][0]; + double sd, sm = 0.0, sm2 = 0.0; + int n = w * h; - for( int i = 0; i < n; ++i ) { + for( int i = 0; i < n; ++i ) { - double d = V[i]; + double d = V[i]; - sm += d; - sm2 += d * d; - } + sm += d; + sm2 += d * d; + } - sd = sqrt( (sm2 - sm*sm/n) / (n - 1.0) ); + sd = sqrt( (sm2 - sm*sm/n) / (n - 1.0) ); - FreeMRC( vras ); + FreeMRC( vras ); - return (int)sd; + return (int)sd; } /* --------------------------------------------------------------- */ @@ -122,13 +122,13 @@ static int GetSD( TiXmlElement* p ) static void GetTileSDs( TiXmlElement* layer, int z ) { - TiXmlElement* p = layer->FirstChildElement( "t2_patch" ); + TiXmlElement* p = layer->FirstChildElement( "t2_patch" ); - for( ; p; p = p->NextSiblingElement() ) { + for( ; p; p = p->NextSiblingElement() ) { - fprintf( flog, "%d\t%d\t%d\n", - z, IDFromPatch( p ), GetSD( p ) ); - } + fprintf( flog, "%d\t%d\t%d\n", + z, IDFromPatch( p ), GetSD( p ) ); + } } /* --------------------------------------------------------------- */ @@ -141,25 +141,25 @@ static void Process() /* Open */ /* ---- */ - XML_TKEM xml( gArgs.xmlfile, flog ); - TiXmlElement* layer = xml.GetFirstLayer(); + XML_TKEM xml( gArgs.xmlfile, flog ); + TiXmlElement* layer = xml.GetFirstLayer(); /* -------- */ /* Do layer */ /* -------- */ - for( ; layer; layer = layer->NextSiblingElement() ) { + for( ; layer; layer = layer->NextSiblingElement() ) { - int z = atoi( layer->Attribute( "z" ) ); + int z = atoi( layer->Attribute( "z" ) ); - if( z > gArgs.z ) - break; + if( z > gArgs.z ) + break; - if( z < gArgs.z ) - continue; + if( z < gArgs.z ) + continue; - GetTileSDs( layer, z ); - } + GetTileSDs( layer, z ); + } } /* --------------------------------------------------------------- */ @@ -172,22 +172,22 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* ------- */ /* Process */ /* ------- */ - Process(); + Process(); /* ---- */ /* Done */ /* ---- */ // VMStats( flog ); - fclose( flog ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_MRCSD1Lyr/combinesd.sht b/1_MRCSD1Lyr/combinesd.sht index b528c3a..07ab1dc 100644 --- a/1_MRCSD1Lyr/combinesd.sht +++ b/1_MRCSD1Lyr/combinesd.sht @@ -4,7 +4,7 @@ rm -f sdall.txt for i in $(seq $1 $2) do - cat sd_$i.txt >> sdall.txt + cat sd_$i.txt >> sdall.txt done diff --git a/1_MRCSD1Lyr/makefile b/1_MRCSD1Lyr/makefile index 36f1700..2a040ca 100644 --- a/1_MRCSD1Lyr/makefile +++ b/1_MRCSD1Lyr/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_MRCSD1Lyr/submrcsd.sht b/1_MRCSD1Lyr/submrcsd.sht index 35a623f..823f878 100644 --- a/1_MRCSD1Lyr/submrcsd.sht +++ b/1_MRCSD1Lyr/submrcsd.sht @@ -9,6 +9,6 @@ setenv MRC_TRIM 12 for i in $(seq $2 $3) do - QSUB_1NODE.sht 30 "sd-$i" "-j y -o out.txt" 1 "MRCSD1Lyr $1 -z=$i" + QSUB_1NODE.sht 30 "sd-$i" "-j y -o out.txt" 1 "MRCSD1Lyr $1 -z=$i" done diff --git a/1_MakeIDB/fsub.sht b/1_MakeIDB/fsub.sht index 81b5b98..1cd4d4d 100644 --- a/1_MakeIDB/fsub.sht +++ b/1_MakeIDB/fsub.sht @@ -13,19 +13,19 @@ nslot=4 if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi for lyr in $(seq $1 $last) do - echo $lyr - if [ -d "$lyr" ] - then - cd $lyr - QSUB_1NODE.sht 1 "makefm-$lyr" "-o /dev/null" $nslot "make -f make.fm -j $nproc EXTRA='""'" - cd .. - fi + echo $lyr + if [ -d "$lyr" ] + then + cd $lyr + QSUB_1NODE.sht 1 "makefm-$lyr" "-o /dev/null" $nslot "make -f make.fm -j $nproc EXTRA='""'" + cd .. + fi done diff --git a/1_MakeIDB/makefile b/1_MakeIDB/makefile index faea43b..db665e8 100644 --- a/1_MakeIDB/makefile +++ b/1_MakeIDB/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_MakeIDB/makeidb.cpp b/1_MakeIDB/makeidb.cpp index 8c1df03..2b35cf5 100644 --- a/1_MakeIDB/makeidb.cpp +++ b/1_MakeIDB/makeidb.cpp @@ -60,23 +60,23 @@ class cArgs_idb { public: - const char *infile, - *script, - *outdir; - int zmin, - zmax; + const char *infile, + *script, + *outdir; + int zmin, + zmax; public: - cArgs_idb() - { - infile = - outdir = "NoSuch"; // prevent overwriting real dir - script = NULL; - zmin = 0; - zmax = 32768; - }; - - void SetCmdLine( int argc, char* argv[] ); + cArgs_idb() + { + infile = + outdir = "NoSuch"; // prevent overwriting real dir + script = NULL; + zmin = 0; + zmax = 32768; + }; + + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -104,59 +104,59 @@ void cArgs_idb::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "makeidb.log", "w" ); + flog = FileOpenOrDie( "makeidb.log", "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Make img database: %s ", atime ); + fprintf( flog, "Make img database: %s ", atime ); // parse command line args - if( argc < 4 ) { - printf( "Usage: makeidb " - " -script=scriptpath -idb=idbpath -z=i,j.\n" ); - exit( 42 ); - } - - vector vi; - - for( int i = 1; i < argc; ++i ) { - - // echo to log - fprintf( flog, "%s ", argv[i] ); - - if( argv[i][0] != '-' ) - infile = argv[i]; - else if( GetArgStr( script, "-script=", argv[i] ) ) - ; - else if( GetArgStr( outdir, "-idb=", argv[i] ) ) - ; - else if( GetArgList( vi, "-z=", argv[i] ) ) { - - if( 2 == vi.size() ) { - zmin = vi[0]; - zmax = vi[1]; - } - else { - fprintf( flog, - "Bad format in -z [%s].\n", argv[i] ); - exit( 42 ); - } - } - else { - printf( "Did not understand option [%s].\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n" ); - fflush( flog ); + if( argc < 4 ) { + printf( "Usage: makeidb " + " -script=scriptpath -idb=idbpath -z=i,j.\n" ); + exit( 42 ); + } + + vector vi; + + for( int i = 1; i < argc; ++i ) { + + // echo to log + fprintf( flog, "%s ", argv[i] ); + + if( argv[i][0] != '-' ) + infile = argv[i]; + else if( GetArgStr( script, "-script=", argv[i] ) ) + ; + else if( GetArgStr( outdir, "-idb=", argv[i] ) ) + ; + else if( GetArgList( vi, "-z=", argv[i] ) ) { + + if( 2 == vi.size() ) { + zmin = vi[0]; + zmax = vi[1]; + } + else { + fprintf( flog, + "Bad format in -z [%s].\n", argv[i] ); + exit( 42 ); + } + } + else { + printf( "Did not understand option [%s].\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n" ); + fflush( flog ); } /* --------------------------------------------------------------- */ @@ -167,25 +167,25 @@ static void Make_nmrc_paths() { // topdir gets the full path to the top directory - char topdir[2048]; + char topdir[2048]; - DskAbsPath( topdir, sizeof(topdir), gArgs.outdir, flog ); + DskAbsPath( topdir, sizeof(topdir), gArgs.outdir, flog ); // save mrc names in global vector and replace them in TS - int nt = TS.vtil.size(); + int nt = TS.vtil.size(); - for( int i = 0; i < nt; ++i ) { + for( int i = 0; i < nt; ++i ) { - CUTile& U = TS.vtil[i]; - char path[2048]; + CUTile& U = TS.vtil[i]; + char path[2048]; - sprintf( path, "%s/%d/nmrc/nmrc_%d_%d.png", - topdir, U.z, U.z, U.id ); + sprintf( path, "%s/%d/nmrc/nmrc_%d_%d.png", + topdir, U.z, U.z, U.id ); - vname0.push_back( U.name ); - U.name = path; - } + vname0.push_back( U.name ); + U.name = path; + } } /* --------------------------------------------------------------- */ @@ -194,13 +194,13 @@ static void Make_nmrc_paths() static void CreateTopDir() { - char name[2048]; + char name[2048]; // gtopdir gets the full path to the top directory - DskAbsPath( gtopdir, sizeof(gtopdir), gArgs.outdir, flog ); + DskAbsPath( gtopdir, sizeof(gtopdir), gArgs.outdir, flog ); // create the top dir - DskCreateDir( gArgs.outdir, flog ); + DskCreateDir( gArgs.outdir, flog ); } /* --------------------------------------------------------------- */ @@ -209,20 +209,20 @@ static void CreateTopDir() static void WriteImageparamsFile() { - char name[2048]; - FILE *f; - int w, h; + char name[2048]; + FILE *f; + int w, h; - TS.GetTileDims( w, h ); + TS.GetTileDims( w, h ); - sprintf( name, "%s/imageparams.txt", gArgs.outdir ); + sprintf( name, "%s/imageparams.txt", gArgs.outdir ); - f = FileOpenOrDie( name, "w", flog ); + f = FileOpenOrDie( name, "w", flog ); - fprintf( f, "IDBPATH %s\n", gtopdir ); - fprintf( f, "IMAGESIZE %d %d\n", w, h ); + fprintf( f, "IDBPATH %s\n", gtopdir ); + fprintf( f, "IMAGESIZE %d %d\n", w, h ); - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -231,12 +231,12 @@ static void WriteImageparamsFile() static void CopyCropFile() { - if( !scr.croprectfile.empty() ) { - char buf[2048]; - sprintf( buf, "cp %s %s/crop.txt", - scr.croprectfile.c_str(), gArgs.outdir ); - system( buf ); - } + if( !scr.croprectfile.empty() ) { + char buf[2048]; + sprintf( buf, "cp %s %s/crop.txt", + scr.croprectfile.c_str(), gArgs.outdir ); + system( buf ); + } } /* --------------------------------------------------------------- */ @@ -245,48 +245,48 @@ static void CopyCropFile() static void WriteFSubFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/fsub.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# For layer range, convert mrc images and/or auto-generate foldmasks.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./fsub.sht [zmax]\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "export MRC_TRIM=12\n" ); - fprintf( f, "\n" ); - fprintf( f, "nproc=%d\n", - scr.makefmjparam ); - fprintf( f, "nslot=%d\n", - scr.makefmslots ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\techo $lyr\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tcd $lyr\n" ); - fprintf( f, "\t\tQSUB_1NODE.sht 1 \"makefm-$lyr\" \"-o /dev/null\" $nslot \"make -f make.fm -j $nproc EXTRA='\"\"'\"\n" ); - fprintf( f, "\t\tcd ..\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/fsub.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# For layer range, convert mrc images and/or auto-generate foldmasks.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./fsub.sht [zmax]\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "export MRC_TRIM=12\n" ); + fprintf( f, "\n" ); + fprintf( f, "nproc=%d\n", + scr.makefmjparam ); + fprintf( f, "nslot=%d\n", + scr.makefmslots ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\techo $lyr\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tcd $lyr\n" ); + fprintf( f, "\t\tQSUB_1NODE.sht 1 \"makefm-$lyr\" \"-o /dev/null\" $nslot \"make -f make.fm -j $nproc EXTRA='\"\"'\"\n" ); + fprintf( f, "\t\tcd ..\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -295,25 +295,25 @@ static void WriteFSubFile() static void WriteFReportFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/freport.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Tabulate sizes of all stderr logs from foldmask generation.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./freport.sht\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "ls -l */makefm*.e* > FmErrs.txt\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/freport.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Tabulate sizes of all stderr logs from foldmask generation.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./freport.sht\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "ls -l */makefm*.e* > FmErrs.txt\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -325,10 +325,10 @@ static void WriteFReportFile() // static void CreateLayerDir( char *lyrdir, int L ) { - fprintf( flog, "\n\nCreateLayerDir: layer %d\n", L ); + fprintf( flog, "\n\nCreateLayerDir: layer %d\n", L ); - sprintf( lyrdir, "%s/%d", gArgs.outdir, L ); - DskCreateDir( lyrdir, flog ); + sprintf( lyrdir, "%s/%d", gArgs.outdir, L ); + DskCreateDir( lyrdir, flog ); } /* --------------------------------------------------------------- */ @@ -340,44 +340,44 @@ static void CreateLayerDir( char *lyrdir, int L ) // Create corresponding folder=fm (or folder=fmd). // static void Make_TileToFM( - const char *lyrdir, - const char *file, - const char *folder, - int is0, - int isN ) + const char *lyrdir, + const char *file, + const char *folder, + int is0, + int isN ) { // Open file - char name[2048]; - FILE *f; + char name[2048]; + FILE *f; - sprintf( name, "%s/%s.txt", lyrdir, file ); + sprintf( name, "%s/%s.txt", lyrdir, file ); - f = FileOpenOrDie( name, "w", flog ); + f = FileOpenOrDie( name, "w", flog ); // Header - fprintf( f, "ID\tPath\n" ); + fprintf( f, "ID\tPath\n" ); // Create fm dir - char fmpath[2048]; + char fmpath[2048]; - sprintf( fmpath, "%s/%d/%s", gtopdir, TS.vtil[is0].z, folder ); - DskCreateDir( fmpath, flog ); + sprintf( fmpath, "%s/%d/%s", gtopdir, TS.vtil[is0].z, folder ); + DskCreateDir( fmpath, flog ); // Write sorted entries - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - const CUTile& U = TS.vtil[i]; + const CUTile& U = TS.vtil[i]; - fprintf( f, - "%d\t%s/%s_%d_%d.png\n", - U.id, fmpath, folder, U.z, U.id ); - } + fprintf( f, + "%d\t%s/%s_%d_%d.png\n", + U.id, fmpath, folder, U.z, U.id ); + } - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -391,29 +391,29 @@ static void Make_TileToFM( // static void Make_fmsame( const char *lyrdir, int is0, int isN ) { - char name[2048]; - FILE *f; + char name[2048]; + FILE *f; - sprintf( name, "%s/fm.same", lyrdir ); + sprintf( name, "%s/fm.same", lyrdir ); - f = FileOpenOrDie( name, "w", flog ); + f = FileOpenOrDie( name, "w", flog ); // Create fmpath - char fmpath[2048]; + char fmpath[2048]; - sprintf( fmpath, "%s/%d/fm", gtopdir, TS.vtil[is0].z ); + sprintf( fmpath, "%s/%d/fm", gtopdir, TS.vtil[is0].z ); // FOLDMAP2 entries - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - const CUTile& U = TS.vtil[i]; + const CUTile& U = TS.vtil[i]; - fprintf( f, "FOLDMAP2 %d.%d 1\n", U.z, U.id ); - } + fprintf( f, "FOLDMAP2 %d.%d 1\n", U.z, U.id ); + } - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -429,14 +429,14 @@ static void Make_fmsame( const char *lyrdir, int is0, int isN ) // static void ConvertSpaces( char *out, const char *in ) { - while( *out++ = *in++ ) { + while( *out++ = *in++ ) { - if( in[-1] == ' ' ) { + if( in[-1] == ' ' ) { - out[-1] = '\\'; - *out++ = ' '; - } - } + out[-1] = '\\'; + *out++ = ' '; + } + } } /* --------------------------------------------------------------- */ @@ -448,81 +448,81 @@ static void ConvertSpaces( char *out, const char *in ) // static void Make_MakeFM( const char *lyrdir, int is0, int isN ) { - char name[2048]; - FILE *f; + char name[2048]; + FILE *f; - sprintf( name, "%s/make.fm", lyrdir ); + sprintf( name, "%s/make.fm", lyrdir ); - f = FileOpenOrDie( name, "w", flog ); + f = FileOpenOrDie( name, "w", flog ); // Master target depends on all others - fprintf( f, "all: " ); + fprintf( f, "all: " ); - for( int i = is0; i < isN; ++i ) - fprintf( f, "fm/fm_%d_%d.png ", TS.vtil[is0].z, TS.vtil[i].id ); + for( int i = is0; i < isN; ++i ) + fprintf( f, "fm/fm_%d_%d.png ", TS.vtil[is0].z, TS.vtil[i].id ); - fprintf( f, "\n\n" ); + fprintf( f, "\n\n" ); // Subtargets and rules - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - const CUTile& U = TS.vtil[i]; + const CUTile& U = TS.vtil[i]; #if 0 // target with dependency - char dep[2048]; - ConvertSpaces( dep, vname0[i].c_str() ); - fprintf( f, "fm/fm_%d_%d.png: %s\n", U.z, U.id, dep ); + char dep[2048]; + ConvertSpaces( dep, vname0[i].c_str() ); + fprintf( f, "fm/fm_%d_%d.png: %s\n", U.z, U.id, dep ); #else // target only - fprintf( f, "fm/fm_%d_%d.png:\n", U.z, U.id ); + fprintf( f, "fm/fm_%d_%d.png:\n", U.z, U.id ); #endif - if( scr.usingfoldmasks ) { - if( ismrc ) { - fprintf( f, - "\ttiny %d %d '%s'" - " '-nmrc=nmrc/nmrc_%d_%d.png'" - " '-fm=fm/fm_%d_%d.png'" - " '-fmd=fmd/fmd_%d_%d.png'" - " ${EXTRA}\n", - U.z, U.id, vname0[i].c_str(), - U.z, U.id, - U.z, U.id, - U.z, U.id ); - } - else { - fprintf( f, - "\ttiny %d %d '%s'" - " '-fm=fm/fm_%d_%d.png'" - " '-fmd=fmd/fmd_%d_%d.png'" - " ${EXTRA}\n", - U.z, U.id, vname0[i].c_str(), - U.z, U.id, - U.z, U.id ); - } - } - else { - if( ismrc ) { - fprintf( f, - "\ttiny %d %d '%s'" - " '-nmrc=nmrc/nmrc_%d_%d.png'" - " -nf ${EXTRA}\n", - U.z, U.id, vname0[i].c_str(), - U.z, U.id ); - } - else { - fprintf( f, - "\ttiny %d %d '%s'" - " -nf ${EXTRA}\n", - U.z, U.id, vname0[i].c_str() ); - } - } - } - - fclose( f ); + if( scr.usingfoldmasks ) { + if( ismrc ) { + fprintf( f, + "\ttiny %d %d '%s'" + " '-nmrc=nmrc/nmrc_%d_%d.png'" + " '-fm=fm/fm_%d_%d.png'" + " '-fmd=fmd/fmd_%d_%d.png'" + " ${EXTRA}\n", + U.z, U.id, vname0[i].c_str(), + U.z, U.id, + U.z, U.id, + U.z, U.id ); + } + else { + fprintf( f, + "\ttiny %d %d '%s'" + " '-fm=fm/fm_%d_%d.png'" + " '-fmd=fmd/fmd_%d_%d.png'" + " ${EXTRA}\n", + U.z, U.id, vname0[i].c_str(), + U.z, U.id, + U.z, U.id ); + } + } + else { + if( ismrc ) { + fprintf( f, + "\ttiny %d %d '%s'" + " '-nmrc=nmrc/nmrc_%d_%d.png'" + " -nf ${EXTRA}\n", + U.z, U.id, vname0[i].c_str(), + U.z, U.id ); + } + else { + fprintf( f, + "\ttiny %d %d '%s'" + " -nf ${EXTRA}\n", + U.z, U.id, vname0[i].c_str() ); + } + } + } + + fclose( f ); } /* --------------------------------------------------------------- */ @@ -533,32 +533,32 @@ static void Make_MakeFM( const char *lyrdir, int is0, int isN ) // static void ForEachLayer() { - int is0, isN; + int is0, isN; - TS.GetLayerLimits( is0 = 0, isN ); + TS.GetLayerLimits( is0 = 0, isN ); - while( isN != -1 ) { + while( isN != -1 ) { - char lyrdir[2048]; + char lyrdir[2048]; - CreateLayerDir( lyrdir, TS.vtil[is0].z ); + CreateLayerDir( lyrdir, TS.vtil[is0].z ); - TS.WriteTileToImage( gtopdir, false, ismrc, is0, isN ); + TS.WriteTileToImage( gtopdir, false, ismrc, is0, isN ); - if( scr.usingfoldmasks ) { - Make_TileToFM( lyrdir, "TileToFM", "fm", is0, isN ); - Make_TileToFM( lyrdir, "TileToFMD", "fmd", is0, isN ); - Make_MakeFM( lyrdir, is0, isN ); - } - else { - if( ismrc ) - Make_MakeFM( lyrdir, is0, isN ); - else - Make_fmsame( lyrdir, is0, isN ); - } + if( scr.usingfoldmasks ) { + Make_TileToFM( lyrdir, "TileToFM", "fm", is0, isN ); + Make_TileToFM( lyrdir, "TileToFMD", "fmd", is0, isN ); + Make_MakeFM( lyrdir, is0, isN ); + } + else { + if( ismrc ) + Make_MakeFM( lyrdir, is0, isN ); + else + Make_fmsame( lyrdir, is0, isN ); + } - TS.GetLayerLimits( is0 = isN, isN ); - } + TS.GetLayerLimits( is0 = isN, isN ); + } } /* --------------------------------------------------------------- */ @@ -571,80 +571,80 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); - TS.SetLogFile( flog ); + TS.SetLogFile( flog ); - int isrickfile = !FileIsExt( gArgs.infile, ".xml" ); + int isrickfile = !FileIsExt( gArgs.infile, ".xml" ); - if( !ReadScriptParams( scr, gArgs.script, flog ) ) - goto exit; + if( !ReadScriptParams( scr, gArgs.script, flog ) ) + goto exit; /* ---------------- */ /* Read source file */ /* ---------------- */ - if( isrickfile ) - TS.FillFromRickFile( gArgs.infile, gArgs.zmin, gArgs.zmax ); - else - TS.FillFromTrakEM2( gArgs.infile, gArgs.zmin, gArgs.zmax ); + if( isrickfile ) + TS.FillFromRickFile( gArgs.infile, gArgs.zmin, gArgs.zmax ); + else + TS.FillFromTrakEM2( gArgs.infile, gArgs.zmin, gArgs.zmax ); - fprintf( flog, "Got %d images.\n", (int)TS.vtil.size() ); + fprintf( flog, "Got %d images.\n", (int)TS.vtil.size() ); - if( !TS.vtil.size() ) - goto exit; + if( !TS.vtil.size() ) + goto exit; - if( isrickfile ) - TS.SetTileDimsFromImageFile(); + if( isrickfile ) + TS.SetTileDimsFromImageFile(); - TS.SortAll_z_id(); + TS.SortAll_z_id(); /* ------------------ */ /* Make XML if no IDB */ /* ------------------ */ - if( !gArgs.outdir[0] || !strcmp( gArgs.outdir, "NoSuch" ) ) { + if( !gArgs.outdir[0] || !strcmp( gArgs.outdir, "NoSuch" ) ) { - TS.WriteTrakEM2_EZ( "RawData.xml", - scr.xmlpixeltype, scr.xmlsclmin, scr.xmlsclmax ); + TS.WriteTrakEM2_EZ( "RawData.xml", + scr.xmlpixeltype, scr.xmlsclmin, scr.xmlsclmax ); - goto exit; - } + goto exit; + } /* ------------------------------------ */ /* Redirect from mrc images to our nmrc */ /* ------------------------------------ */ - ismrc = FileIsExt( TS.vtil[0].name.c_str(), ".mrc" ); + ismrc = FileIsExt( TS.vtil[0].name.c_str(), ".mrc" ); - if( ismrc ) - Make_nmrc_paths(); + if( ismrc ) + Make_nmrc_paths(); /* --------------- */ /* Create dir tree */ /* --------------- */ - CreateTopDir(); + CreateTopDir(); - WriteImageparamsFile(); - CopyCropFile(); + WriteImageparamsFile(); + CopyCropFile(); - if( scr.usingfoldmasks || ismrc ) { - WriteFSubFile(); - WriteFReportFile(); - } + if( scr.usingfoldmasks || ismrc ) { + WriteFSubFile(); + WriteFReportFile(); + } - ForEachLayer(); + ForEachLayer(); /* ---- */ /* Done */ /* ---- */ exit: - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_MakeMontages/Retired/cleandown.sht b/1_MakeMontages/Retired/cleandown.sht index c5417c4..0e13827 100644 --- a/1_MakeMontages/Retired/cleandown.sht +++ b/1_MakeMontages/Retired/cleandown.sht @@ -8,32 +8,32 @@ if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi for lyr in $(seq $1 $last) do - echo $lyr - if [ -d "$lyr" ] - then - cd $lyr - - b=$(($lyr - 1)) - - for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') - do - echo $jb - cd $jb - rm -f p* - rm -f q* - hdr=$(printf "Atl\tAcr\tBtl\tBcr\tErr\tDeg\tR\tT0\tT1\tX\tT3\tT4\tY\n") - echo "$hdr" > "ThmPair_"$lyr"^"$b".txt" - cd .. - done - - cd .. - fi + echo $lyr + if [ -d "$lyr" ] + then + cd $lyr + + b=$(($lyr - 1)) + + for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') + do + echo $jb + cd $jb + rm -f p* + rm -f q* + hdr=$(printf "Atl\tAcr\tBtl\tBcr\tErr\tDeg\tR\tT0\tT1\tX\tT3\tT4\tY\n") + echo "$hdr" > "ThmPair_"$lyr"^"$b".txt" + cd .. + done + + cd .. + fi done diff --git a/1_MakeMontages/Retired/montage1.sht b/1_MakeMontages/Retired/montage1.sht index a20d78b..18250cd 100644 --- a/1_MakeMontages/Retired/montage1.sht +++ b/1_MakeMontages/Retired/montage1.sht @@ -19,7 +19,7 @@ cat $idb/$1/fm.same >> pts.all for jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}') do - cat $jb/pts.same >> pts.all + cat $jb/pts.same >> pts.all done mv pts.all montage diff --git a/1_MakeMontages/Retired/retired.cpp b/1_MakeMontages/Retired/retired.cpp index a7762b7..82b3e50 100644 --- a/1_MakeMontages/Retired/retired.cpp +++ b/1_MakeMontages/Retired/retired.cpp @@ -6,25 +6,25 @@ static void WriteSFinishFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/sfinish.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Run finish.sht script on its own cluster node.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./sfinish.sht\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "QSUB_1NODE.sht 9 \"finish\" \"\" 8 \"./finish.sht\"\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/sfinish.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Run finish.sht script on its own cluster node.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./sfinish.sht\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "QSUB_1NODE.sht 9 \"finish\" \"\" 8 \"./finish.sht\"\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -33,28 +33,28 @@ static void WriteSFinishFile() static void WriteFinishFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/finish.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Gather all points to stack folder, cd there, run lsq solver.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# ./finish.sht\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "./combine.sht %d %d\n", - gArgs.zmin, gArgs.zmax ); - fprintf( f, "cd stack\n" ); - fprintf( f, "./runlsq.sht \"\"\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/finish.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Gather all points to stack folder, cd there, run lsq solver.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# ./finish.sht\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "./combine.sht %d %d\n", + gArgs.zmin, gArgs.zmax ); + fprintf( f, "cd stack\n" ); + fprintf( f, "./runlsq.sht \"\"\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -63,61 +63,61 @@ static void WriteFinishFile() static void WriteCombineFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/combine.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Gather all point pair files into stack/pts.all\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./combine.sht \n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "rm -f pts.all\n" ); - fprintf( f, "\n" ); - fprintf( f, "#get line 1, subst 'IDBPATH=xxx' with 'xxx'\n" ); - fprintf( f, "idb=$(sed -n -e 's|IDBPATH \\(.*\\)|\\1|' -e '1p' < imageparams.txt)\n" ); - fprintf( f, "\n" ); - fprintf( f, "cp imageparams.txt pts.all\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $2)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\tcat $idb/$lyr/fm.same >> pts.all\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $2)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\techo $lyr\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tcd $lyr\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tfor jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}')\n" ); - fprintf( f, "\t\tdo\n" ); - fprintf( f, "\t\t\tcat $jb/pts.same >> ../pts.all\n" ); - fprintf( f, "\t\tdone\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tif (($lyr != $1))\n" ); - fprintf( f, "\t\tthen\n" ); - fprintf( f, "\t\t\tfor jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}')\n" ); - fprintf( f, "\t\t\tdo\n" ); - fprintf( f, "\t\t\t\tcat $jb/pts.down >> ../pts.all\n" ); - fprintf( f, "\t\t\tdone\n" ); - fprintf( f, "\t\tfi\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tcd ..\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - fprintf( f, "mv pts.all stack\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/combine.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Gather all point pair files into stack/pts.all\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./combine.sht \n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "rm -f pts.all\n" ); + fprintf( f, "\n" ); + fprintf( f, "#get line 1, subst 'IDBPATH=xxx' with 'xxx'\n" ); + fprintf( f, "idb=$(sed -n -e 's|IDBPATH \\(.*\\)|\\1|' -e '1p' < imageparams.txt)\n" ); + fprintf( f, "\n" ); + fprintf( f, "cp imageparams.txt pts.all\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $2)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\tcat $idb/$lyr/fm.same >> pts.all\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $2)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\techo $lyr\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tcd $lyr\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tfor jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}')\n" ); + fprintf( f, "\t\tdo\n" ); + fprintf( f, "\t\t\tcat $jb/pts.same >> ../pts.all\n" ); + fprintf( f, "\t\tdone\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tif (($lyr != $1))\n" ); + fprintf( f, "\t\tthen\n" ); + fprintf( f, "\t\t\tfor jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}')\n" ); + fprintf( f, "\t\t\tdo\n" ); + fprintf( f, "\t\t\t\tcat $jb/pts.down >> ../pts.all\n" ); + fprintf( f, "\t\t\tdone\n" ); + fprintf( f, "\t\tfi\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tcd ..\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + fprintf( f, "mv pts.all stack\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -126,44 +126,44 @@ static void WriteCombineFile() static void WriteMontage1File() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/montage1.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# For given layer, gather all point pair files into montage/pts.all,\n" ); - fprintf( f, "# cd there, run lsq solver.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./montage1.sht \n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "cd $1\n" ); - fprintf( f, "\n" ); - fprintf( f, "rm -f pts.all\n" ); - fprintf( f, "\n" ); - fprintf( f, "# get line 1, subst 'IDBPATH=xxx' with 'xxx'\n" ); - fprintf( f, "idb=$(sed -n -e 's|IDBPATH \\(.*\\)|\\1|' -e '1p' < ../imageparams.txt)\n" ); - fprintf( f, "\n" ); - fprintf( f, "cp ../imageparams.txt pts.all\n" ); - fprintf( f, "cat $idb/$1/fm.same >> pts.all\n" ); - fprintf( f, "\n" ); - fprintf( f, "for jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}')\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\tcat $jb/pts.same >> pts.all\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - fprintf( f, "mv pts.all montage\n" ); - fprintf( f, "\n" ); - fprintf( f, "cd montage\n" ); - fprintf( f, "./runlsq.sht \"\"\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/montage1.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# For given layer, gather all point pair files into montage/pts.all,\n" ); + fprintf( f, "# cd there, run lsq solver.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./montage1.sht \n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "cd $1\n" ); + fprintf( f, "\n" ); + fprintf( f, "rm -f pts.all\n" ); + fprintf( f, "\n" ); + fprintf( f, "# get line 1, subst 'IDBPATH=xxx' with 'xxx'\n" ); + fprintf( f, "idb=$(sed -n -e 's|IDBPATH \\(.*\\)|\\1|' -e '1p' < ../imageparams.txt)\n" ); + fprintf( f, "\n" ); + fprintf( f, "cp ../imageparams.txt pts.all\n" ); + fprintf( f, "cat $idb/$1/fm.same >> pts.all\n" ); + fprintf( f, "\n" ); + fprintf( f, "for jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}')\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\tcat $jb/pts.same >> pts.all\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + fprintf( f, "mv pts.all montage\n" ); + fprintf( f, "\n" ); + fprintf( f, "cd montage\n" ); + fprintf( f, "./runlsq.sht \"\"\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -172,40 +172,40 @@ static void WriteMontage1File() static void WriteSubmonFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/submon.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# For each layer in range, gather points, cd to layer's montage dir,\n" ); - fprintf( f, "# run lsq there.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./submon.sht [zmax]\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\techo $lyr\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tQSUB_1NODE.sht 4 \"mon-$lyr\" \"\" 8 \"./montage1.sht $lyr\"\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/submon.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# For each layer in range, gather points, cd to layer's montage dir,\n" ); + fprintf( f, "# run lsq there.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./submon.sht [zmax]\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\techo $lyr\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tQSUB_1NODE.sht 4 \"mon-$lyr\" \"\" 8 \"./montage1.sht $lyr\"\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -214,65 +214,65 @@ static void WriteSubmonFile() static void WriteSubmosFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/mosaic/submos.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Heal montage seams and update superpixel data.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > mos [options]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Default sizing is 0,0,-1,-1 meaning natural size.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Options:\n" ); - fprintf( f, "# -d\t\t\t\t;debug\n" ); - fprintf( f, "# -strings\t\t\t;simple-file data labeled by path strings\n" ); - fprintf( f, "# -warp\t\t\t\t;heal seams\n" ); - fprintf( f, "# -nf\t\t\t\t;no folds\n" ); - fprintf( f, "# -a\t\t\t\t;annotate\n" ); - fprintf( f, "# -tiles\t\t\t;make raveler tiles\n" ); - fprintf( f, "# -noflat\t\t\t;no flat image ('before')\n" ); - fprintf( f, "# -nomap\t\t\t;no map image (where data from)\n" ); - fprintf( f, "# -matlab\t\t\t;matlab/closeness order\n" ); - fprintf( f, "# -drn\t\t\t\t;don't renumber superpixels\n" ); - fprintf( f, "# -dms=0.01\t\t\t;don't move strength\n" ); - fprintf( f, "# -fold_dir=path\t;prepended fm location, default=CWD\n" ); - fprintf( f, "# -region_dir=path\t;results go here, default=CWD\n" ); - fprintf( f, "# -gray_dir=path\t;gray images go here, default=CWD\n" ); - fprintf( f, "# -grey_dir=path\t;gray images go here, default=CWD\n" ); - fprintf( f, "# -sp_dir=path\t\t;superpixel maps go here, default=CWD\n" ); - fprintf( f, "# -inv_dir=path\t\t;inverse maps go here, default=CWD\n" ); - fprintf( f, "# -rav_dir=path\t\t;raveler tiles go here, default=CWD\n" ); - fprintf( f, "# -bmap_dir=path\t;boundary maps go here, default=CWD\n" ); - fprintf( f, "# -s=1\t\t\t\t;scale down by this integer\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "export MRC_TRIM=12\n" ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\techo $lyr\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tQSUB_1NODE.sht 10 \"mos-$lyr\" \"\" 8 \"mos ../stack/simple 0,0,-1,-1 $lyr,$lyr -warp%s > mos_$lyr.txt\"\n", - (gArgs.NoFolds ? " -nf" : "") ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/mosaic/submos.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Heal montage seams and update superpixel data.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > mos [options]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Default sizing is 0,0,-1,-1 meaning natural size.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Options:\n" ); + fprintf( f, "# -d\t\t\t\t;debug\n" ); + fprintf( f, "# -strings\t\t\t;simple-file data labeled by path strings\n" ); + fprintf( f, "# -warp\t\t\t\t;heal seams\n" ); + fprintf( f, "# -nf\t\t\t\t;no folds\n" ); + fprintf( f, "# -a\t\t\t\t;annotate\n" ); + fprintf( f, "# -tiles\t\t\t;make raveler tiles\n" ); + fprintf( f, "# -noflat\t\t\t;no flat image ('before')\n" ); + fprintf( f, "# -nomap\t\t\t;no map image (where data from)\n" ); + fprintf( f, "# -matlab\t\t\t;matlab/closeness order\n" ); + fprintf( f, "# -drn\t\t\t\t;don't renumber superpixels\n" ); + fprintf( f, "# -dms=0.01\t\t\t;don't move strength\n" ); + fprintf( f, "# -fold_dir=path\t;prepended fm location, default=CWD\n" ); + fprintf( f, "# -region_dir=path\t;results go here, default=CWD\n" ); + fprintf( f, "# -gray_dir=path\t;gray images go here, default=CWD\n" ); + fprintf( f, "# -grey_dir=path\t;gray images go here, default=CWD\n" ); + fprintf( f, "# -sp_dir=path\t\t;superpixel maps go here, default=CWD\n" ); + fprintf( f, "# -inv_dir=path\t\t;inverse maps go here, default=CWD\n" ); + fprintf( f, "# -rav_dir=path\t\t;raveler tiles go here, default=CWD\n" ); + fprintf( f, "# -bmap_dir=path\t;boundary maps go here, default=CWD\n" ); + fprintf( f, "# -s=1\t\t\t\t;scale down by this integer\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "export MRC_TRIM=12\n" ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\techo $lyr\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tQSUB_1NODE.sht 10 \"mos-$lyr\" \"\" 8 \"mos ../stack/simple 0,0,-1,-1 $lyr,$lyr -warp%s > mos_$lyr.txt\"\n", + (gArgs.NoFolds ? " -nf" : "") ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } diff --git a/1_MakeMontages/Retired/submon.sht b/1_MakeMontages/Retired/submon.sht index 2483c43..fe05038 100644 --- a/1_MakeMontages/Retired/submon.sht +++ b/1_MakeMontages/Retired/submon.sht @@ -9,17 +9,17 @@ if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi for lyr in $(seq $1 $last) do - echo $lyr - if [ -d "$lyr" ] - then - QSUB_1NODE.sht 4 "mon-$lyr" "" 8 "./montage1.sht $lyr" - fi + echo $lyr + if [ -d "$lyr" ] + then + QSUB_1NODE.sht 4 "mon-$lyr" "" 8 "./montage1.sht $lyr" + fi done diff --git a/1_MakeMontages/cleandown1.sht b/1_MakeMontages/cleandown1.sht index 9d98bd9..9f9ae0f 100644 --- a/1_MakeMontages/cleandown1.sht +++ b/1_MakeMontages/cleandown1.sht @@ -8,8 +8,8 @@ if (($# == 0)) then - echo "Need layer number" - exit + echo "Need layer number" + exit fi cd $1 @@ -18,13 +18,13 @@ b=$(($1 - 1)) for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') do - echo $jb - cd $jb - rm -f p* - rm -f q* - hdr=$(printf "Atl\tAcr\tBtl\tBcr\tErr\tDeg\tR\tT0\tT1\tX\tT3\tT4\tY\n") - echo "$hdr" > "ThmPair_"$1"^"$b".txt" - cd .. + echo $jb + cd $jb + rm -f p* + rm -f q* + hdr=$(printf "Atl\tAcr\tBtl\tBcr\tErr\tDeg\tR\tT0\tT1\tX\tT3\tT4\tY\n") + echo "$hdr" > "ThmPair_"$1"^"$b".txt" + cd .. done cd .. diff --git a/1_MakeMontages/cleandownpts.sht b/1_MakeMontages/cleandownpts.sht index bc1767a..b97d0d2 100644 --- a/1_MakeMontages/cleandownpts.sht +++ b/1_MakeMontages/cleandownpts.sht @@ -8,36 +8,36 @@ if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi for lyr in $(seq $1 $last) do - echo $lyr - if [ -d "$lyr" ] - then - cd $lyr - - for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') - do - echo $jb - cd $jb - rm -f p* - rm -f q* - - hdr=$(printf "Atl\tAcr\tBtl\tBcr\tErr\tDeg\tR\tT0\tT1\tX\tT3\tT4\tY\n") - - for tbl in $(find . -name "ThmPair*.txt") - do - echo "$hdr" > "$tbl" - done - - cd .. - done - - cd .. - fi + echo $lyr + if [ -d "$lyr" ] + then + cd $lyr + + for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') + do + echo $jb + cd $jb + rm -f p* + rm -f q* + + hdr=$(printf "Atl\tAcr\tBtl\tBcr\tErr\tDeg\tR\tT0\tT1\tX\tT3\tT4\tY\n") + + for tbl in $(find . -name "ThmPair*.txt") + do + echo "$hdr" > "$tbl" + done + + cd .. + done + + cd .. + fi done diff --git a/1_MakeMontages/cleanlsq.sht b/1_MakeMontages/cleanlsq.sht index 3f1aec2..7d3dcec 100644 --- a/1_MakeMontages/cleanlsq.sht +++ b/1_MakeMontages/cleanlsq.sht @@ -8,36 +8,36 @@ if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi for lyr in $(seq $1 $last) do - echo $lyr - if [ -d "$lyr" ] - then - cd $lyr + echo $lyr + if [ -d "$lyr" ] + then + cd $lyr - for jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}') - do - echo $jb - cd $jb - rm -f results* - rm -f triples* - cd .. - done + for jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}') + do + echo $jb + cd $jb + rm -f results* + rm -f triples* + cd .. + done - for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') - do - echo $jb - cd $jb - rm -f results* - rm -f triples* - cd .. - done + for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') + do + echo $jb + cd $jb + rm -f results* + rm -f triples* + cd .. + done - cd .. - fi + cd .. + fi done diff --git a/1_MakeMontages/cleanmon.sht b/1_MakeMontages/cleanmon.sht index 7717230..e10334c 100644 --- a/1_MakeMontages/cleanmon.sht +++ b/1_MakeMontages/cleanmon.sht @@ -8,8 +8,8 @@ if (($# == 0)) then - echo "Need layer number" - exit + echo "Need layer number" + exit fi #save copy of lsq script @@ -21,13 +21,13 @@ rm -rf montage for jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}') do - echo $jb - cd $jb - rm -f p* - rm -f q* - hdr=$(printf "Atl\tAcr\tBtl\tBcr\tErr\tDeg\tR\tT0\tT1\tX\tT3\tT4\tY\n") - echo "$hdr" > "ThmPair_"$1"^"$1".txt" - cd .. + echo $jb + cd $jb + rm -f p* + rm -f q* + hdr=$(printf "Atl\tAcr\tBtl\tBcr\tErr\tDeg\tR\tT0\tT1\tX\tT3\tT4\tY\n") + echo "$hdr" > "ThmPair_"$1"^"$1".txt" + cd .. done mkdir montage diff --git a/1_MakeMontages/cleansame1.sht b/1_MakeMontages/cleansame1.sht index 176b63e..dc72ca9 100644 --- a/1_MakeMontages/cleansame1.sht +++ b/1_MakeMontages/cleansame1.sht @@ -8,21 +8,21 @@ if (($# == 0)) then - echo "Need layer number" - exit + echo "Need layer number" + exit fi cd $1 for jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}') do - echo $jb - cd $jb - rm -f p* - rm -f q* - hdr=$(printf "Atl\tAcr\tBtl\tBcr\tErr\tDeg\tR\tT0\tT1\tX\tT3\tT4\tY\n") - echo "$hdr" > "ThmPair_"$1"^"$1".txt" - cd .. + echo $jb + cd $jb + rm -f p* + rm -f q* + hdr=$(printf "Atl\tAcr\tBtl\tBcr\tErr\tDeg\tR\tT0\tT1\tX\tT3\tT4\tY\n") + echo "$hdr" > "ThmPair_"$1"^"$1".txt" + cd .. done cd .. diff --git a/1_MakeMontages/countsamedirs.sht b/1_MakeMontages/countsamedirs.sht index 5dee334..f61d335 100644 --- a/1_MakeMontages/countsamedirs.sht +++ b/1_MakeMontages/countsamedirs.sht @@ -10,26 +10,26 @@ export MRC_TRIM=12 if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi cnt=0 for lyr in $(seq $1 $last) do - if [ -d "$lyr" ] - then - cd $lyr - - for jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}') - do - cnt=$(($cnt+1)) - done - - echo z= $lyr cum= $cnt - cd .. - fi + if [ -d "$lyr" ] + then + cd $lyr + + for jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}') + do + cnt=$(($cnt+1)) + done + + echo z= $lyr cum= $cnt + cd .. + fi done diff --git a/1_MakeMontages/dreport.sht b/1_MakeMontages/dreport.sht index ff5f88c..60d25cf 100644 --- a/1_MakeMontages/dreport.sht +++ b/1_MakeMontages/dreport.sht @@ -11,9 +11,9 @@ if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi ls -l */D*/qD*.e* > DownErrs.txt @@ -25,16 +25,16 @@ touch DownNopts.txt for lyr in $(seq $1 $last) do - echo $lyr - if [ -d "$lyr" ] - then - for jb in $(ls -d $lyr/* | grep -E 'D[0-9]{1,}_[0-9]{1,}') - do - if [ -e $jb/make.down -a ! -e $jb/pts.down ] - then - echo "$jb" >> DownNopts.txt - fi - done - fi + echo $lyr + if [ -d "$lyr" ] + then + for jb in $(ls -d $lyr/* | grep -E 'D[0-9]{1,}_[0-9]{1,}') + do + if [ -e $jb/make.down -a ! -e $jb/pts.down ] + then + echo "$jb" >> DownNopts.txt + fi + done + fi done diff --git a/1_MakeMontages/dsub.sht b/1_MakeMontages/dsub.sht index f26d11d..77a3082 100644 --- a/1_MakeMontages/dsub.sht +++ b/1_MakeMontages/dsub.sht @@ -14,31 +14,31 @@ nslot=4 if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi for lyr in $(seq $1 $last) do - echo $lyr - if [ -d "$lyr" ] - then - cd $lyr + echo $lyr + if [ -d "$lyr" ] + then + cd $lyr - for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') - do - cd $jb + for jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}') + do + cd $jb - if [ -e make.down ] - then - QSUB_1NODE.sht 3 "q$jb-$lyr" "-o /dev/null" $nslot "make -f make.down -j $nproc EXTRA='""'" - fi + if [ -e make.down ] + then + QSUB_1NODE.sht 3 "q$jb-$lyr" "-o /dev/null" $nslot "make -f make.down -j $nproc EXTRA='""'" + fi - cd .. - done + cd .. + done - cd .. - fi + cd .. + fi done diff --git a/1_MakeMontages/gathermons.sht b/1_MakeMontages/gathermons.sht index f7ab874..43425e9 100644 --- a/1_MakeMontages/gathermons.sht +++ b/1_MakeMontages/gathermons.sht @@ -10,9 +10,9 @@ dst=X_A_BIN_mons if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi rm -rf $dst @@ -20,9 +20,9 @@ mkdir -p $dst for lyr in $(seq $1 $last) do - if [ -d "$lyr" ] - then - cp $lyr/montage/X_A_BIN/* $dst - fi + if [ -d "$lyr" ] + then + cp $lyr/montage/X_A_BIN/* $dst + fi done diff --git a/1_MakeMontages/makefile b/1_MakeMontages/makefile index c1986db..92a93b6 100644 --- a/1_MakeMontages/makefile +++ b/1_MakeMontages/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_MakeMontages/makemontages.cpp b/1_MakeMontages/makemontages.cpp index fa07b3a..958406e 100644 --- a/1_MakeMontages/makemontages.cpp +++ b/1_MakeMontages/makemontages.cpp @@ -35,42 +35,42 @@ class Pair { public: - int a, b; + int a, b; public: - Pair( int a, int b ) : a(a), b(b) {}; + Pair( int a, int b ) : a(a), b(b) {}; }; class Block { public: - vector P; + vector P; }; class BlockSet { private: - enum { - klowcount = 12 - }; + enum { + klowcount = 12 + }; public: - vector K; - int w, h, - kx, ky, - dx, dy, - nb; + vector K; + int w, h, + kx, ky, + dx, dy, + nb; private: - void OrientLayer( int is0, int isN ); - void SetDims(); - void PartitionJobs( int is0, int isN ); - void Consolidate(); - void ReportBlocks( int z ); + void OrientLayer( int is0, int isN ); + void SetDims(); + void PartitionJobs( int is0, int isN ); + void Consolidate(); + void ReportBlocks( int z ); public: - void CarveIntoBlocks( int is0, int isN ); - void MakeJobs( const char *lyrdir, int z ); + void CarveIntoBlocks( int is0, int isN ); + void MakeJobs( const char *lyrdir, int z ); }; /* --------------------------------------------------------------- */ @@ -80,24 +80,24 @@ class BlockSet { class CArgs_scr { public: - string idb; - const char *outdir, - *script, - *exenam; - int zmin, - zmax; + string idb; + const char *outdir, + *script, + *exenam; + int zmin, + zmax; public: - CArgs_scr() - { - outdir = "NoSuch"; // prevent overwriting real dir - script = NULL; - exenam = "ptest"; - zmin = 0; - zmax = 32768; - }; - - void SetCmdLine( int argc, char* argv[] ); + CArgs_scr() + { + outdir = "NoSuch"; // prevent overwriting real dir + script = NULL; + exenam = "ptest"; + zmin = 0; + zmax = 32768; + }; + + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -110,7 +110,7 @@ static CTileSet TS; static FILE* flog = NULL; static char xmlprms[256] = {0}; static int gW = 0, // universal pic dims - gH = 0; + gH = 0; @@ -125,64 +125,64 @@ void CArgs_scr::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "makemontages.log", "w" ); + flog = FileOpenOrDie( "makemontages.log", "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Make alignment workspace: %s ", atime ); + fprintf( flog, "Make alignment workspace: %s ", atime ); // parse command line args - if( argc < 5 ) { - printf( - "Usage: makemontages temp" - " -script=scriptpath -idb=idbpath -z=i,j" - " [options].\n" ); - exit( 42 ); - } - - vector vi; - const char *pchar; - - for( int i = 1; i < argc; ++i ) { - - // echo to log - fprintf( flog, "%s ", argv[i] ); - - if( argv[i][0] != '-' ) - outdir = argv[i]; - else if( GetArgStr( script, "-script=", argv[i] ) ) - ; - else if( GetArgStr( pchar, "-idb=", argv[i] ) ) - idb=pchar; - else if( GetArgStr( exenam, "-exe=", argv[i] ) ) - ; - else if( GetArgList( vi, "-z=", argv[i] ) ) { - - if( 2 == vi.size() ) { - zmin = vi[0]; - zmax = vi[1]; - } - else { - fprintf( flog, - "Bad format in -z [%s].\n", argv[i] ); - exit( 42 ); - } - } - else { - printf( "Did not understand option [%s].\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n" ); - fflush( flog ); + if( argc < 5 ) { + printf( + "Usage: makemontages temp" + " -script=scriptpath -idb=idbpath -z=i,j" + " [options].\n" ); + exit( 42 ); + } + + vector vi; + const char *pchar; + + for( int i = 1; i < argc; ++i ) { + + // echo to log + fprintf( flog, "%s ", argv[i] ); + + if( argv[i][0] != '-' ) + outdir = argv[i]; + else if( GetArgStr( script, "-script=", argv[i] ) ) + ; + else if( GetArgStr( pchar, "-idb=", argv[i] ) ) + idb=pchar; + else if( GetArgStr( exenam, "-exe=", argv[i] ) ) + ; + else if( GetArgList( vi, "-z=", argv[i] ) ) { + + if( 2 == vi.size() ) { + zmin = vi[0]; + zmax = vi[1]; + } + else { + fprintf( flog, + "Bad format in -z [%s].\n", argv[i] ); + exit( 42 ); + } + } + else { + printf( "Did not understand option [%s].\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n" ); + fflush( flog ); } /* --------------------------------------------------------------- */ @@ -191,23 +191,23 @@ void CArgs_scr::SetCmdLine( int argc, char* argv[] ) static void CreateTopDir() { - char name[2048]; + char name[2048]; // create the top dir - DskCreateDir( gArgs.outdir, flog ); + DskCreateDir( gArgs.outdir, flog ); // copy imageparams here - sprintf( name, "cp %s/imageparams.txt %s", - gArgs.idb.c_str(), gArgs.outdir ); - system( name ); + sprintf( name, "cp %s/imageparams.txt %s", + gArgs.idb.c_str(), gArgs.outdir ); + system( name ); // create stack subdir - sprintf( name, "%s/stack", gArgs.outdir ); - DskCreateDir( name, flog ); + sprintf( name, "%s/stack", gArgs.outdir ); + DskCreateDir( name, flog ); // create mosaic subdir - //sprintf( name, "%s/mosaic", gArgs.outdir ); - //DskCreateDir( name, flog ); + //sprintf( name, "%s/mosaic", gArgs.outdir ); + //DskCreateDir( name, flog ); } /* --------------------------------------------------------------- */ @@ -216,61 +216,61 @@ static void CreateTopDir() static void _WriteRunlsqFile( const char *path, int z, bool final ) { - FILE *f = FileOpenOrDie( path, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Assign each tile (or each subregion if tiles divided by folds)\n" ); - fprintf( f, "# a transform (default is affine) that best describes the mapping\n" ); - fprintf( f, "# of correspondence point pairs from local images to the shared\n" ); - fprintf( f, "# global system.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > lsq -temp=temp0 -zi=i,j [options]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Required:\n" ); - fprintf( f, "# -temp=path\t\t;master workspace (a.k.a. 'temp')\n" ); - fprintf( f, "# -zi=i,j\t\t\t;output tforms in range z=[i..j]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Options:\n" ); - fprintf( f, "# -cache=lsqcache\t;path to {catalog,pnts} data\n" ); - fprintf( f, "# -catclr\t\t\t;rebuild catalog file\n" ); - fprintf( f, "# -zo=p,q\t\t\t;consider input out to z=[p..q]\n" ); - fprintf( f, "# -prior=path\t\t;starting tforms (required if stack)\n" ); - fprintf( f, "# -untwist\t\t\t;untwist prior affines\n" ); - fprintf( f, "# -mode=A2A\t\t\t;action: {catalog,eval,split,A2A,A2H,H2H}\n" ); - fprintf( f, "# -Wr=R,0.001\t\t;Aff -> (1-Wr)*Aff + Wr*(T=Trans, R=Rgd}\n" ); - fprintf( f, "# -Etol=30\t\t\t;max point error (depends upon system size)\n" ); - fprintf( f, "# -iters=2000\t\t;solve iterations\n" ); - fprintf( f, "# -splitmin=1000\t;separate islands > splitmin tiles\n" ); - fprintf( f, "# -zpernode=200\t\t;max layers per cluster node\n" ); - fprintf( f, "# -maxthreads=1\t\t;maximum threads per node\n" ); - fprintf( f, "# -local\t\t\t;run locally (no qsub) if 1 worker\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - - if( !final ) - fprintf( f, "lsq -temp=../../ -zi=%d,%d $1\n", z, z ); - else { - fprintf( f, "lsq -temp=../ -zi=%d,%d" - " -prior=../cross_wkspc/X_A_BIN_scaf -untwist" - " -mode=A2A -Wr=R,0 -Etol=500 -iters=10000" - " -zpernode=200 -maxthreads=%d\n", - gArgs.zmin, gArgs.zmax, scr.slotspernode ); - } - - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( path ); + FILE *f = FileOpenOrDie( path, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Assign each tile (or each subregion if tiles divided by folds)\n" ); + fprintf( f, "# a transform (default is affine) that best describes the mapping\n" ); + fprintf( f, "# of correspondence point pairs from local images to the shared\n" ); + fprintf( f, "# global system.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > lsq -temp=temp0 -zi=i,j [options]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Required:\n" ); + fprintf( f, "# -temp=path\t\t;master workspace (a.k.a. 'temp')\n" ); + fprintf( f, "# -zi=i,j\t\t\t;output tforms in range z=[i..j]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Options:\n" ); + fprintf( f, "# -cache=lsqcache\t;path to {catalog,pnts} data\n" ); + fprintf( f, "# -catclr\t\t\t;rebuild catalog file\n" ); + fprintf( f, "# -zo=p,q\t\t\t;consider input out to z=[p..q]\n" ); + fprintf( f, "# -prior=path\t\t;starting tforms (required if stack)\n" ); + fprintf( f, "# -untwist\t\t\t;untwist prior affines\n" ); + fprintf( f, "# -mode=A2A\t\t\t;action: {catalog,eval,split,A2A,A2H,H2H}\n" ); + fprintf( f, "# -Wr=R,0.001\t\t;Aff -> (1-Wr)*Aff + Wr*(T=Trans, R=Rgd}\n" ); + fprintf( f, "# -Etol=30\t\t\t;max point error (depends upon system size)\n" ); + fprintf( f, "# -iters=2000\t\t;solve iterations\n" ); + fprintf( f, "# -splitmin=1000\t;separate islands > splitmin tiles\n" ); + fprintf( f, "# -zpernode=200\t\t;max layers per cluster node\n" ); + fprintf( f, "# -maxthreads=1\t\t;maximum threads per node\n" ); + fprintf( f, "# -local\t\t\t;run locally (no qsub) if 1 worker\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + + if( !final ) + fprintf( f, "lsq -temp=../../ -zi=%d,%d $1\n", z, z ); + else { + fprintf( f, "lsq -temp=../ -zi=%d,%d" + " -prior=../cross_wkspc/X_A_BIN_scaf -untwist" + " -mode=A2A -Wr=R,0 -Etol=500 -iters=10000" + " -zpernode=200 -maxthreads=%d\n", + gArgs.zmin, gArgs.zmax, scr.slotspernode ); + } + + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( path ); } static void WriteRunlsqFile() { - char buf[2048]; - sprintf( buf, "%s/stack/runlsq.sht", gArgs.outdir ); - _WriteRunlsqFile( buf, -1, true ); + char buf[2048]; + sprintf( buf, "%s/stack/runlsq.sht", gArgs.outdir ); + _WriteRunlsqFile( buf, -1, true ); } /* --------------------------------------------------------------- */ @@ -279,55 +279,55 @@ static void WriteRunlsqFile() static void WriteXviewFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/stack/xviewgo.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Convert Z-file tform data to viewable text or xml.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Z-file organized data can be:\n" ); - fprintf( f, "# - IDB (inpath not specified)\n" ); - fprintf( f, "# - X_A_TXT, X_H_TXT\n" ); - fprintf( f, "# - X_A_MET, X_H_MET\n" ); - fprintf( f, "# - X_A_BIN, X_H_BIN\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > xview inpath -idb=idbpath -z=i,j [options]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Required:\n" ); - fprintf( f, "# inPath\t\t\t;path of a tform source folder\n" ); - fprintf( f, "# -idb=idbpath\t\t;path to idb folder\n" ); - fprintf( f, "# -z=i,j\t\t\t;convert tforms in range z=[i..j]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# ImagePlus type codes used in xml files:\n" ); - fprintf( f, "#\tAUTO\t\t= -1\n" ); - fprintf( f, "#\tGRAY8\t\t= 0\n" ); - fprintf( f, "#\tGRAY16\t\t= 1\n" ); - fprintf( f, "#\tGRAY32\t\t= 2\n" ); - fprintf( f, "#\tCOLOR_256\t= 3\n" ); - fprintf( f, "#\tCOLOR_RGB\t= 4\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Options:\n" ); - fprintf( f, "# -forceWH=w,h\t\t;force bounds (override degcw)\n" ); - fprintf( f, "# -degcw=0\t\t\t;rotate CW degrees\n" ); - fprintf( f, "# -type=X\t\t\t;{T,M,X,B} = {X_?_TXT,X_?_MET,xml,billfile}\n" ); - fprintf( f, "# -meta=path\t\t;billfile with alt image paths\n" ); - fprintf( f, "# -xmltrim=0.0\t\t;trim this much from xml images\n" ); - fprintf( f, "# -xmltype=0\t\t;ImagePlus type code\n" ); - fprintf( f, "# -xmlmin=0\t\t\t;intensity scale\n" ); - fprintf( f, "# -xmlmax=0\t\t\t;intensity scale\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "xview X_A_BIN -idb=%s -z=%d,%d -degcw=0 -type=X%s\n", - gArgs.idb.c_str(), gArgs.zmin, gArgs.zmax, xmlprms ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/stack/xviewgo.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Convert Z-file tform data to viewable text or xml.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Z-file organized data can be:\n" ); + fprintf( f, "# - IDB (inpath not specified)\n" ); + fprintf( f, "# - X_A_TXT, X_H_TXT\n" ); + fprintf( f, "# - X_A_MET, X_H_MET\n" ); + fprintf( f, "# - X_A_BIN, X_H_BIN\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > xview inpath -idb=idbpath -z=i,j [options]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Required:\n" ); + fprintf( f, "# inPath\t\t\t;path of a tform source folder\n" ); + fprintf( f, "# -idb=idbpath\t\t;path to idb folder\n" ); + fprintf( f, "# -z=i,j\t\t\t;convert tforms in range z=[i..j]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# ImagePlus type codes used in xml files:\n" ); + fprintf( f, "#\tAUTO\t\t= -1\n" ); + fprintf( f, "#\tGRAY8\t\t= 0\n" ); + fprintf( f, "#\tGRAY16\t\t= 1\n" ); + fprintf( f, "#\tGRAY32\t\t= 2\n" ); + fprintf( f, "#\tCOLOR_256\t= 3\n" ); + fprintf( f, "#\tCOLOR_RGB\t= 4\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Options:\n" ); + fprintf( f, "# -forceWH=w,h\t\t;force bounds (override degcw)\n" ); + fprintf( f, "# -degcw=0\t\t\t;rotate CW degrees\n" ); + fprintf( f, "# -type=X\t\t\t;{T,M,X,B} = {X_?_TXT,X_?_MET,xml,billfile}\n" ); + fprintf( f, "# -meta=path\t\t;billfile with alt image paths\n" ); + fprintf( f, "# -xmltrim=0.0\t\t;trim this much from xml images\n" ); + fprintf( f, "# -xmltype=0\t\t;ImagePlus type code\n" ); + fprintf( f, "# -xmlmin=0\t\t\t;intensity scale\n" ); + fprintf( f, "# -xmlmax=0\t\t\t;intensity scale\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "xview X_A_BIN -idb=%s -z=%d,%d -degcw=0 -type=X%s\n", + gArgs.idb.c_str(), gArgs.zmin, gArgs.zmax, xmlprms ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -336,36 +336,36 @@ static void WriteXviewFile() static void WriteEviewFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/stack/eviewgo.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Histogram one or two 'Error' folders produced by lsqw.\n" ); - fprintf( f, "# The result is a text file for viewing in Excel.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > eview Error [Error_B] -z=i,j [options]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Required:\n" ); - fprintf( f, "# Error\t\t\t;path to lsqw Error folder\n" ); - fprintf( f, "# -z=i,j\t\t;use data in range z=[i..j]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Options:\n" ); - fprintf( f, "# [Error_B]\t\t;second Error folder for comparison\n" ); - fprintf( f, "# -div=10\t\t;bin width = 1/div\n" ); - fprintf( f, "# -lim=500\t\t;nbins = div*lim + 1 (for oflo)\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "eview Error -z=%d,%d -div=10 -lim=100\n", - gArgs.zmin, gArgs.zmax ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/stack/eviewgo.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Histogram one or two 'Error' folders produced by lsqw.\n" ); + fprintf( f, "# The result is a text file for viewing in Excel.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > eview Error [Error_B] -z=i,j [options]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Required:\n" ); + fprintf( f, "# Error\t\t\t;path to lsqw Error folder\n" ); + fprintf( f, "# -z=i,j\t\t;use data in range z=[i..j]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Options:\n" ); + fprintf( f, "# [Error_B]\t\t;second Error folder for comparison\n" ); + fprintf( f, "# -div=10\t\t;bin width = 1/div\n" ); + fprintf( f, "# -lim=500\t\t;nbins = div*lim + 1 (for oflo)\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "eview Error -z=%d,%d -div=10 -lim=100\n", + gArgs.zmin, gArgs.zmax ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -374,50 +374,50 @@ static void WriteEviewFile() static void WriteCountsamedirsFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/countsamedirs.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Count all 'Sx_y' dirs in layer range\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./countsamedirs.sht i j\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "export MRC_TRIM=12\n" ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "cnt=0\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tcd $lyr\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tfor jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}')\n" ); - fprintf( f, "\t\tdo\n" ); - fprintf( f, "\t\t\tcnt=$(($cnt+1))\n" ); - fprintf( f, "\t\tdone\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\techo z= $lyr cum= $cnt\n" ); - fprintf( f, "\t\tcd ..\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/countsamedirs.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Count all 'Sx_y' dirs in layer range\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./countsamedirs.sht i j\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "export MRC_TRIM=12\n" ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "cnt=0\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tcd $lyr\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tfor jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}')\n" ); + fprintf( f, "\t\tdo\n" ); + fprintf( f, "\t\t\tcnt=$(($cnt+1))\n" ); + fprintf( f, "\t\tdone\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\techo z= $lyr cum= $cnt\n" ); + fprintf( f, "\t\tcd ..\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -426,56 +426,56 @@ static void WriteCountsamedirsFile() static void WriteSSubNFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/ssub.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# For layer range, submit all make.same and use the make option -j \n" ); - fprintf( f, "# to set number of concurrent jobs.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./ssub.sht [zmax]\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "export MRC_TRIM=12\n" ); - fprintf( f, "\n" ); - fprintf( f, "nproc=%d\n", - scr.makesamejparam ); - fprintf( f, "nslot=%d\n", - scr.makesameslots ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\techo $lyr\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tcd $lyr\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tfor jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}')\n" ); - fprintf( f, "\t\tdo\n" ); - fprintf( f, "\t\t\tcd $jb\n" ); - fprintf( f, "\t\t\tQSUB_1NODE.sht 2 \"q$jb-$lyr\" \"-o /dev/null\" $nslot \"make -f make.same -j $nproc EXTRA='\"\"'\"\n" ); - fprintf( f, "\t\t\tcd ..\n" ); - fprintf( f, "\t\tdone\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tcd ..\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/ssub.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# For layer range, submit all make.same and use the make option -j \n" ); + fprintf( f, "# to set number of concurrent jobs.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./ssub.sht [zmax]\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "export MRC_TRIM=12\n" ); + fprintf( f, "\n" ); + fprintf( f, "nproc=%d\n", + scr.makesamejparam ); + fprintf( f, "nslot=%d\n", + scr.makesameslots ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\techo $lyr\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tcd $lyr\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tfor jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}')\n" ); + fprintf( f, "\t\tdo\n" ); + fprintf( f, "\t\t\tcd $jb\n" ); + fprintf( f, "\t\t\tQSUB_1NODE.sht 2 \"q$jb-$lyr\" \"-o /dev/null\" $nslot \"make -f make.same -j $nproc EXTRA='\"\"'\"\n" ); + fprintf( f, "\t\t\tcd ..\n" ); + fprintf( f, "\t\tdone\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tcd ..\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -484,61 +484,61 @@ static void WriteSSubNFile() static void WriteDSubNFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/dsub.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# For layer range, submit all make.down and use the make option -j \n" ); - fprintf( f, "# to set number of concurrent jobs.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./dsub.sht [zmax]\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "export MRC_TRIM=12\n" ); - fprintf( f, "\n" ); - fprintf( f, "nproc=%d\n", - scr.makedownjparam ); - fprintf( f, "nslot=%d\n", - scr.makedownslots ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\techo $lyr\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tcd $lyr\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tfor jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}')\n" ); - fprintf( f, "\t\tdo\n" ); - fprintf( f, "\t\t\tcd $jb\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\t\tif [ -e make.down ]\n" ); - fprintf( f, "\t\t\tthen\n" ); - fprintf( f, "\t\t\t\tQSUB_1NODE.sht 3 \"q$jb-$lyr\" \"-o /dev/null\" $nslot \"make -f make.down -j $nproc EXTRA='\"\"'\"\n" ); - fprintf( f, "\t\t\tfi\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\t\tcd ..\n" ); - fprintf( f, "\t\tdone\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tcd ..\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/dsub.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# For layer range, submit all make.down and use the make option -j \n" ); + fprintf( f, "# to set number of concurrent jobs.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./dsub.sht [zmax]\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "export MRC_TRIM=12\n" ); + fprintf( f, "\n" ); + fprintf( f, "nproc=%d\n", + scr.makedownjparam ); + fprintf( f, "nslot=%d\n", + scr.makedownslots ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\techo $lyr\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tcd $lyr\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tfor jb in $(ls -d * | grep -E 'D[0-9]{1,}_[0-9]{1,}')\n" ); + fprintf( f, "\t\tdo\n" ); + fprintf( f, "\t\t\tcd $jb\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\t\tif [ -e make.down ]\n" ); + fprintf( f, "\t\t\tthen\n" ); + fprintf( f, "\t\t\t\tQSUB_1NODE.sht 3 \"q$jb-$lyr\" \"-o /dev/null\" $nslot \"make -f make.down -j $nproc EXTRA='\"\"'\"\n" ); + fprintf( f, "\t\t\tfi\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\t\tcd ..\n" ); + fprintf( f, "\t\tdone\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tcd ..\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -547,106 +547,106 @@ static void WriteDSubNFile() static void WriteReportFiles() { - char buf[2048]; - FILE *f; + char buf[2048]; + FILE *f; // same - sprintf( buf, "%s/sreport.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# For montages in layer range...\n" ); - fprintf( f, "# Tabulate sizes of all cluster stderr logs for quick view of faults.\n" ); - fprintf( f, "# Tabulate sizes of all 'pts.same' files for consistency checking.\n" ); - fprintf( f, "# Tabulate subblocks for which there were no points.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./sreport.sht [zmax]\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "ls -l */S*/qS*.e* > SameErrs.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "ls -l */S*/pts.same > SamePts.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "rm -f SameNopts.txt\n" ); - fprintf( f, "touch SameNopts.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\techo $lyr\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tfor jb in $(ls -d $lyr/* | grep -E 'S[0-9]{1,}_[0-9]{1,}')\n" ); - fprintf( f, "\t\tdo\n" ); - fprintf( f, "\t\t\tif [ ! -e $jb/pts.same ]\n" ); - fprintf( f, "\t\t\tthen\n" ); - fprintf( f, "\t\t\t\techo \"$jb\" >> SameNopts.txt\n" ); - fprintf( f, "\t\t\tfi\n" ); - fprintf( f, "\t\tdone\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + sprintf( buf, "%s/sreport.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# For montages in layer range...\n" ); + fprintf( f, "# Tabulate sizes of all cluster stderr logs for quick view of faults.\n" ); + fprintf( f, "# Tabulate sizes of all 'pts.same' files for consistency checking.\n" ); + fprintf( f, "# Tabulate subblocks for which there were no points.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./sreport.sht [zmax]\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "ls -l */S*/qS*.e* > SameErrs.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "ls -l */S*/pts.same > SamePts.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "rm -f SameNopts.txt\n" ); + fprintf( f, "touch SameNopts.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\techo $lyr\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tfor jb in $(ls -d $lyr/* | grep -E 'S[0-9]{1,}_[0-9]{1,}')\n" ); + fprintf( f, "\t\tdo\n" ); + fprintf( f, "\t\t\tif [ ! -e $jb/pts.same ]\n" ); + fprintf( f, "\t\t\tthen\n" ); + fprintf( f, "\t\t\t\techo \"$jb\" >> SameNopts.txt\n" ); + fprintf( f, "\t\t\tfi\n" ); + fprintf( f, "\t\tdone\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); // down - sprintf( buf, "%s/dreport.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# For down data in layer range...\n" ); - fprintf( f, "# Tabulate sizes of all cluster stderr logs for quick view of faults.\n" ); - fprintf( f, "# Tabulate sizes of all 'pts.down' files for consistency checking.\n" ); - fprintf( f, "# Tabulate subblocks for which there were no points.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./dreport.sht [zmax]\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "ls -l */D*/qD*.e* > DownErrs.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "ls -l */D*/pts.down > DownPts.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "rm -f DownNopts.txt\n" ); - fprintf( f, "touch DownNopts.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\techo $lyr\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tfor jb in $(ls -d $lyr/* | grep -E 'D[0-9]{1,}_[0-9]{1,}')\n" ); - fprintf( f, "\t\tdo\n" ); - fprintf( f, "\t\t\tif [ -e $jb/make.down -a ! -e $jb/pts.down ]\n" ); - fprintf( f, "\t\t\tthen\n" ); - fprintf( f, "\t\t\t\techo \"$jb\" >> DownNopts.txt\n" ); - fprintf( f, "\t\t\tfi\n" ); - fprintf( f, "\t\tdone\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + sprintf( buf, "%s/dreport.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# For down data in layer range...\n" ); + fprintf( f, "# Tabulate sizes of all cluster stderr logs for quick view of faults.\n" ); + fprintf( f, "# Tabulate sizes of all 'pts.down' files for consistency checking.\n" ); + fprintf( f, "# Tabulate subblocks for which there were no points.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./dreport.sht [zmax]\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "ls -l */D*/qD*.e* > DownErrs.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "ls -l */D*/pts.down > DownPts.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "rm -f DownNopts.txt\n" ); + fprintf( f, "touch DownNopts.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\techo $lyr\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tfor jb in $(ls -d $lyr/* | grep -E 'D[0-9]{1,}_[0-9]{1,}')\n" ); + fprintf( f, "\t\tdo\n" ); + fprintf( f, "\t\t\tif [ -e $jb/make.down -a ! -e $jb/pts.down ]\n" ); + fprintf( f, "\t\t\tthen\n" ); + fprintf( f, "\t\t\t\techo \"$jb\" >> DownNopts.txt\n" ); + fprintf( f, "\t\t\tfi\n" ); + fprintf( f, "\t\tdone\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -655,43 +655,43 @@ static void WriteReportFiles() static void WriteMSubFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/msub.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# For each layer in range, cd to montage dir, run lsq there.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./msub.sht [zmax]\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\techo $lyr\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tcd $lyr/montage\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tQSUB_1NODE.sht 4 \"mon-$lyr\" \"\" 1 \"./runlsq.sht\"\n" ); - fprintf( f, "\n" ); - fprintf( f, "\t\tcd ../..\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/msub.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# For each layer in range, cd to montage dir, run lsq there.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./msub.sht [zmax]\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\techo $lyr\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tcd $lyr/montage\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tQSUB_1NODE.sht 4 \"mon-$lyr\" \"\" 1 \"./runlsq.sht\"\n" ); + fprintf( f, "\n" ); + fprintf( f, "\t\tcd ../..\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -700,42 +700,42 @@ static void WriteMSubFile() static void WriteMReportFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/mreport.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# For layer range, gather list of 'FINAL' lines from lsq.txt files\n" ); - fprintf( f, "# for individual montages. Report these in MonSumy.txt.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./mreport.sht [zmax]\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "rm -rf MonSumy.txt\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\tlog=$lyr/montage/lsqw_0.txt\n" ); - fprintf( f, "\tif [ -f \"$log\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\techo Z $lyr `grep -e \"FINAL*\" $log` >> MonSumy.txt\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/mreport.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# For layer range, gather list of 'FINAL' lines from lsq.txt files\n" ); + fprintf( f, "# for individual montages. Report these in MonSumy.txt.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./mreport.sht [zmax]\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "rm -rf MonSumy.txt\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\tlog=$lyr/montage/lsqw_0.txt\n" ); + fprintf( f, "\tif [ -f \"$log\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\techo Z $lyr `grep -e \"FINAL*\" $log` >> MonSumy.txt\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -744,43 +744,43 @@ static void WriteMReportFile() static void WriteGatherMonsFile() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/gathermons.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# For each layer in range, copy montage results to X_A_BIN_mons.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > ./gathermons.sht [zmax]\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "dst=X_A_BIN_mons\n" ); - fprintf( f, "\n" ); - fprintf( f, "if (($# == 1))\n" ); - fprintf( f, "then\n" ); - fprintf( f, "\tlast=$1\n" ); - fprintf( f, "else\n" ); - fprintf( f, "\tlast=$2\n" ); - fprintf( f, "fi\n" ); - fprintf( f, "\n" ); - fprintf( f, "rm -rf $dst\n" ); - fprintf( f, "mkdir -p $dst\n" ); - fprintf( f, "\n" ); - fprintf( f, "for lyr in $(seq $1 $last)\n" ); - fprintf( f, "do\n" ); - fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); - fprintf( f, "\tthen\n" ); - fprintf( f, "\t\tcp $lyr/montage/X_A_BIN/* $dst\n" ); - fprintf( f, "\tfi\n" ); - fprintf( f, "done\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/gathermons.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# For each layer in range, copy montage results to X_A_BIN_mons.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > ./gathermons.sht [zmax]\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "dst=X_A_BIN_mons\n" ); + fprintf( f, "\n" ); + fprintf( f, "if (($# == 1))\n" ); + fprintf( f, "then\n" ); + fprintf( f, "\tlast=$1\n" ); + fprintf( f, "else\n" ); + fprintf( f, "\tlast=$2\n" ); + fprintf( f, "fi\n" ); + fprintf( f, "\n" ); + fprintf( f, "rm -rf $dst\n" ); + fprintf( f, "mkdir -p $dst\n" ); + fprintf( f, "\n" ); + fprintf( f, "for lyr in $(seq $1 $last)\n" ); + fprintf( f, "do\n" ); + fprintf( f, "\tif [ -d \"$lyr\" ]\n" ); + fprintf( f, "\tthen\n" ); + fprintf( f, "\t\tcp $lyr/montage/X_A_BIN/* $dst\n" ); + fprintf( f, "\tfi\n" ); + fprintf( f, "done\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -789,33 +789,33 @@ static void WriteGatherMonsFile() static void Write_Crossgo() { - char buf[2048]; - FILE *f; - - sprintf( buf, "%s/crossgo.sht", gArgs.outdir ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Given folder of Z-file montage tforms (srcmons),\n" ); - fprintf( f, "# create workspace mytemp/cross_wkspc, and scripts\n" ); - fprintf( f, "# governing cross layer alignment.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > cross_topscripts srcmons -script=scriptpath -z=i,j\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Required:\n" ); - fprintf( f, "# srcmons\t\t\t\t;collected independent montages\n" ); - fprintf( f, "# -script=scriptpath\t;alignment pipeline params file\n" ); - fprintf( f, "# -z=i,j\t\t\t\t;align layers in range z=[i..j]\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "cross_topscripts X_A_BIN_mons -script=%s -z=%d,%d\n", - gArgs.script, gArgs.zmin, gArgs.zmax ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "%s/crossgo.sht", gArgs.outdir ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Given folder of Z-file montage tforms (srcmons),\n" ); + fprintf( f, "# create workspace mytemp/cross_wkspc, and scripts\n" ); + fprintf( f, "# governing cross layer alignment.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > cross_topscripts srcmons -script=scriptpath -z=i,j\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Required:\n" ); + fprintf( f, "# srcmons\t\t\t\t;collected independent montages\n" ); + fprintf( f, "# -script=scriptpath\t;alignment pipeline params file\n" ); + fprintf( f, "# -z=i,j\t\t\t\t;align layers in range z=[i..j]\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "cross_topscripts X_A_BIN_mons -script=%s -z=%d,%d\n", + gArgs.script, gArgs.zmin, gArgs.zmax ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -831,22 +831,22 @@ static void Write_Crossgo() // static void CreateLayerDir( char *lyrdir, int L ) { - fprintf( flog, "\n\nCreateLayerDir: layer %d\n", L ); + fprintf( flog, "\n\nCreateLayerDir: layer %d\n", L ); // Create layer dir - sprintf( lyrdir, "%s/%d", gArgs.outdir, L ); - DskCreateDir( lyrdir, flog ); + sprintf( lyrdir, "%s/%d", gArgs.outdir, L ); + DskCreateDir( lyrdir, flog ); // Create montage subdir - char buf[2048]; - int len; + char buf[2048]; + int len; - len = sprintf( buf, "%s/montage", lyrdir ); - DskCreateDir( buf, flog ); + len = sprintf( buf, "%s/montage", lyrdir ); + DskCreateDir( buf, flog ); // Create montage script - sprintf( buf + len, "/runlsq.sht" ); - _WriteRunlsqFile( buf, L, false ); + sprintf( buf + len, "/runlsq.sht" ); + _WriteRunlsqFile( buf, L, false ); } /* --------------------------------------------------------------- */ @@ -862,16 +862,16 @@ static void CreateLayerDir( char *lyrdir, int L ) // static void CreateTileSubdirs( const char *lyrdir, int is0, int isN ) { - fprintf( flog, "--CreateTileSubdirs: layer %d\n", - TS.vtil[is0].z ); + fprintf( flog, "--CreateTileSubdirs: layer %d\n", + TS.vtil[is0].z ); - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - char subdir[2048]; + char subdir[2048]; - sprintf( subdir, "%s/%d", lyrdir, TS.vtil[i].id ); - DskCreateDir( subdir, flog ); - } + sprintf( subdir, "%s/%d", lyrdir, TS.vtil[i].id ); + DskCreateDir( subdir, flog ); + } } /* --------------------------------------------------------------- */ @@ -882,63 +882,63 @@ static void CreateTileSubdirs( const char *lyrdir, int is0, int isN ) // of images described by (P). // static void WriteMakeFile( - const char *lyrdir, - int SD, - int ix, - int iy, - const vector &P ) + const char *lyrdir, + int SD, + int ix, + int iy, + const vector &P ) { char name[2048], - ptsbuf[32], - logbuf[32]; - FILE *f; - int np = P.size(); + ptsbuf[32], + logbuf[32]; + FILE *f; + int np = P.size(); // open the file - sprintf( name, "%s/%c%d_%d/make.%s", - lyrdir, SD, ix, iy, (SD == 'S' ? "same" : "down") ); + sprintf( name, "%s/%c%d_%d/make.%s", + lyrdir, SD, ix, iy, (SD == 'S' ? "same" : "down") ); - f = FileOpenOrDie( name, "w", flog ); + f = FileOpenOrDie( name, "w", flog ); // write 'all' targets line - fprintf( f, "all: " ); + fprintf( f, "all: " ); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - const CUTile& A = TS.vtil[P[i].a]; - const CUTile& B = TS.vtil[P[i].b]; + const CUTile& A = TS.vtil[P[i].a]; + const CUTile& B = TS.vtil[P[i].b]; - fprintf( f, "%d/%d.%d.map.tif ", A.id, B.z, B.id ); - } + fprintf( f, "%d/%d.%d.map.tif ", A.id, B.z, B.id ); + } - fprintf( f, "\n\n" ); + fprintf( f, "\n\n" ); // Write each 'target: dependencies' line // and each 'rule' line - const char *option_nf = (scr.usingfoldmasks ? "" : " -nf"); + const char *option_nf = (scr.usingfoldmasks ? "" : " -nf"); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - const CUTile& A = TS.vtil[P[i].a]; - const CUTile& B = TS.vtil[P[i].b]; + const CUTile& A = TS.vtil[P[i].a]; + const CUTile& B = TS.vtil[P[i].b]; - fprintf( f, - "%d/%d.%d.map.tif:\n", - A.id, B.z, B.id ); + fprintf( f, + "%d/%d.%d.map.tif:\n", + A.id, B.z, B.id ); - fprintf( f, - "\t%s >>%s 2>%s" - " %d.%d^%d.%d%s ${EXTRA}\n\n", - gArgs.exenam, - NamePtsFile( ptsbuf, A.z, B.z ), - NameLogFile( logbuf, A.z, A.id, B.z, B.id ), - A.z, A.id, B.z, B.id, option_nf ); - } + fprintf( f, + "\t%s >>%s 2>%s" + " %d.%d^%d.%d%s ${EXTRA}\n\n", + gArgs.exenam, + NamePtsFile( ptsbuf, A.z, B.z ), + NameLogFile( logbuf, A.z, A.id, B.z, B.id ), + A.z, A.id, B.z, B.id, option_nf ); + } - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -951,37 +951,37 @@ void BlockSet::OrientLayer( int is0, int isN ) { // Collect all tile corners in (C) - vector C, cnr; - Set4Corners( cnr, gW, gH ); + vector C, cnr; + Set4Corners( cnr, gW, gH ); - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - vector c( 4 ); - memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); - TS.vtil[i].T.Transform( c ); + vector c( 4 ); + memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); + TS.vtil[i].T.Transform( c ); - for( int i = 0; i < 4; ++i ) - C.push_back( c[i] ); - } + for( int i = 0; i < 4; ++i ) + C.push_back( c[i] ); + } // Rotate layer upright and translate to (0,0) - TAffine R; - DBox B; - int deg = TightestBBox( B, C ); + TAffine R; + DBox B; + int deg = TightestBBox( B, C ); - R.NUSetRot( deg*PI/180 ); + R.NUSetRot( deg*PI/180 ); - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - TAffine& T = TS.vtil[i].T; + TAffine& T = TS.vtil[i].T; - T = R * T; - T.AddXY( -B.L, -B.B ); - } + T = R * T; + T.AddXY( -B.L, -B.B ); + } - w = int(B.R - B.L) + 1; - h = int(B.T - B.B) + 1; + w = int(B.R - B.L) + 1; + h = int(B.T - B.B) + 1; } /* --------------------------------------------------------------- */ @@ -992,15 +992,15 @@ void BlockSet::OrientLayer( int is0, int isN ) // void BlockSet::SetDims() { - dx = scr.montageblocksize; - dy = dx; - dx *= gW; - dy *= gH; - kx = (int)ceil( (double)w / dx ); - ky = (int)ceil( (double)h / dy ); - dx = w / kx; - dy = h / ky; - nb = kx * ky; + dx = scr.montageblocksize; + dy = dx; + dx *= gW; + dy *= gH; + kx = (int)ceil( (double)w / dx ); + ky = (int)ceil( (double)h / dy ); + dx = w / kx; + dy = h / ky; + nb = kx * ky; } /* --------------------------------------------------------------- */ @@ -1011,51 +1011,51 @@ void BlockSet::SetDims() // void BlockSet::PartitionJobs( int is0, int isN ) { - K.clear(); - K.resize( nb ); + K.clear(); + K.resize( nb ); - int W2 = gW/2, - H2 = gH/2; + int W2 = gW/2, + H2 = gH/2; - for( int a = is0; a < isN; ++a ) { + for( int a = is0; a < isN; ++a ) { - Point pa( W2, H2 ); - int ix, iy, rowa, cola; + Point pa( W2, H2 ); + int ix, iy, rowa, cola; - TS.vtil[a].T.Transform( pa ); + TS.vtil[a].T.Transform( pa ); - ix = int(pa.x / dx); + ix = int(pa.x / dx); - if( ix < 0 ) - ix = 0; - else if( ix >= kx ) - ix = kx - 1; + if( ix < 0 ) + ix = 0; + else if( ix >= kx ) + ix = kx - 1; - iy = int(pa.y / dy); + iy = int(pa.y / dy); - if( iy < 0 ) - iy = 0; - else if( iy >= ky ) - iy = ky - 1; + if( iy < 0 ) + iy = 0; + else if( iy >= ky ) + iy = ky - 1; - if( scr.ignorecorners ) { + if( scr.ignorecorners ) { - cola = TS.vtil[a].col; - rowa = TS.vtil[a].row; - } + cola = TS.vtil[a].col; + rowa = TS.vtil[a].row; + } - for( int b = a + 1; b < isN; ++b ) { + for( int b = a + 1; b < isN; ++b ) { - if( scr.ignorecorners ) { + if( scr.ignorecorners ) { - if( (TS.vtil[b].row - rowa) * (TS.vtil[b].col - cola) != 0 ) - continue; - } + if( (TS.vtil[b].row - rowa) * (TS.vtil[b].col - cola) != 0 ) + continue; + } - if( TS.ABOlap( a, b ) > scr.mintileolapfrac ) - K[ix + kx*iy].P.push_back( Pair( a, b ) ); - } - } + if( TS.ABOlap( a, b ) > scr.mintileolapfrac ) + K[ix + kx*iy].P.push_back( Pair( a, b ) ); + } + } } /* --------------------------------------------------------------- */ @@ -1066,69 +1066,69 @@ void BlockSet::PartitionJobs( int is0, int isN ) // void BlockSet::Consolidate() { - if( nb <= 1 ) - return; + if( nb <= 1 ) + return; - bool changed; + bool changed; - do { + do { - changed = false; + changed = false; - for( int i = 0; i < nb; ++i ) { + for( int i = 0; i < nb; ++i ) { - int ic = K[i].P.size(); + int ic = K[i].P.size(); - if( !ic || ic >= klowcount ) - continue; + if( !ic || ic >= klowcount ) + continue; - int iy = i / kx, - ix = i - kx * iy, - lowc = 0, - lowi, c; + int iy = i / kx, + ix = i - kx * iy, + lowc = 0, + lowi, c; - // find lowest count neib + // find lowest count neib - if( iy > 0 && (c = K[i-kx].P.size()) ) { - lowc = c; - lowi = i-kx; - } + if( iy > 0 && (c = K[i-kx].P.size()) ) { + lowc = c; + lowi = i-kx; + } - if( iy < ky-1 && (c = K[i+kx].P.size()) && - (!lowc || c < lowc) ) { + if( iy < ky-1 && (c = K[i+kx].P.size()) && + (!lowc || c < lowc) ) { - lowc = c; - lowi = i+kx; - } + lowc = c; + lowi = i+kx; + } - if( ix > 0 && (c = K[i-1].P.size()) && - (!lowc || c < lowc) ) { + if( ix > 0 && (c = K[i-1].P.size()) && + (!lowc || c < lowc) ) { - lowc = c; - lowi = i-1; - } + lowc = c; + lowi = i-1; + } - if( ix < kx-1 && (c = K[i+1].P.size()) && - (!lowc || c < lowc) ) { + if( ix < kx-1 && (c = K[i+1].P.size()) && + (!lowc || c < lowc) ) { - lowc = c; - lowi = i+1; - } + lowc = c; + lowi = i+1; + } - // merge + // merge - if( !lowc ) - continue; + if( !lowc ) + continue; - changed = true; + changed = true; - for( int j = 0; j < ic; ++j ) - K[lowi].P.push_back( K[i].P[j] ); + for( int j = 0; j < ic; ++j ) + K[lowi].P.push_back( K[i].P[j] ); - K[i].P.clear(); - } + K[i].P.clear(); + } - } while( changed ); + } while( changed ); } /* --------------------------------------------------------------- */ @@ -1139,21 +1139,21 @@ void BlockSet::Consolidate() // void BlockSet::ReportBlocks( int z ) { - int njobs = 0; + int njobs = 0; - fprintf( flog, "\nZ %d, Array %dx%d, Jobs(i,j):\n", z, kx, ky ); + fprintf( flog, "\nZ %d, Array %dx%d, Jobs(i,j):\n", z, kx, ky ); - for( int i = 0; i < nb; ++i ) { + for( int i = 0; i < nb; ++i ) { - int iy = i / kx, - ix = i - kx * iy, - ij = K[i].P.size(); + int iy = i / kx, + ix = i - kx * iy, + ij = K[i].P.size(); - fprintf( flog, "%d%c", ij, (ix == kx - 1 ? '\n' : '\t') ); - njobs += ij; - } + fprintf( flog, "%d%c", ij, (ix == kx - 1 ? '\n' : '\t') ); + njobs += ij; + } - fprintf( flog, "Total = %d\n", njobs ); + fprintf( flog, "Total = %d\n", njobs ); } /* --------------------------------------------------------------- */ @@ -1162,11 +1162,11 @@ void BlockSet::ReportBlocks( int z ) void BlockSet::CarveIntoBlocks( int is0, int isN ) { - OrientLayer( is0, isN ); - SetDims(); - PartitionJobs( is0, isN ); - Consolidate(); - ReportBlocks( TS.vtil[is0].z ); + OrientLayer( is0, isN ); + SetDims(); + PartitionJobs( is0, isN ); + Consolidate(); + ReportBlocks( TS.vtil[is0].z ); } /* --------------------------------------------------------------- */ @@ -1175,17 +1175,17 @@ void BlockSet::CarveIntoBlocks( int is0, int isN ) void BlockSet::MakeJobs( const char *lyrdir, int z ) { - for( int i = 0; i < nb; ++i ) { + for( int i = 0; i < nb; ++i ) { - if( K[i].P.size() ) { + if( K[i].P.size() ) { - int iy = i / kx, - ix = i - kx * iy; + int iy = i / kx, + ix = i - kx * iy; - CreateJobsDir( lyrdir, ix, iy, z, z, flog ); - WriteMakeFile( lyrdir, 'S', ix, iy, K[i].P ); - } - } + CreateJobsDir( lyrdir, ix, iy, z, z, flog ); + WriteMakeFile( lyrdir, 'S', ix, iy, K[i].P ); + } + } } /* --------------------------------------------------------------- */ @@ -1196,26 +1196,26 @@ void BlockSet::MakeJobs( const char *lyrdir, int z ) // static void ForEachLayer() { - int is0, isN; + int is0, isN; - TS.GetLayerLimits( is0 = 0, isN ); + TS.GetLayerLimits( is0 = 0, isN ); - while( isN != -1 ) { + while( isN != -1 ) { - char lyrdir[2048]; - BlockSet BS; - int z = TS.vtil[is0].z; + char lyrdir[2048]; + BlockSet BS; + int z = TS.vtil[is0].z; - CreateLayerDir( lyrdir, z ); + CreateLayerDir( lyrdir, z ); - if( scr.createauxdirs ) - CreateTileSubdirs( lyrdir, is0, isN ); + if( scr.createauxdirs ) + CreateTileSubdirs( lyrdir, is0, isN ); - BS.CarveIntoBlocks( is0, isN ); - BS.MakeJobs( lyrdir, z ); + BS.CarveIntoBlocks( is0, isN ); + BS.MakeJobs( lyrdir, z ); - TS.GetLayerLimits( is0 = isN, isN ); - } + TS.GetLayerLimits( is0 = isN, isN ); + } } /* --------------------------------------------------------------- */ @@ -1228,74 +1228,74 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); - TS.SetLogFile( flog ); + TS.SetLogFile( flog ); - if( !ReadScriptParams( scr, gArgs.script, flog ) ) - exit( 42 ); + if( !ReadScriptParams( scr, gArgs.script, flog ) ) + exit( 42 ); - int L = 0; + int L = 0; - if( scr.xmlpixeltype != 0 ) - L += sprintf( xmlprms + L, " -xmltype=%d", scr.xmlpixeltype ); + if( scr.xmlpixeltype != 0 ) + L += sprintf( xmlprms + L, " -xmltype=%d", scr.xmlpixeltype ); - if( scr.xmlsclmin != 0 ) - L += sprintf( xmlprms + L, " -xmlmin=%d", scr.xmlsclmin ); + if( scr.xmlsclmin != 0 ) + L += sprintf( xmlprms + L, " -xmlmin=%d", scr.xmlsclmin ); - if( scr.xmlsclmax != 0 ) - L += sprintf( xmlprms + L, " -xmlmax=%d", scr.xmlsclmax ); + if( scr.xmlsclmax != 0 ) + L += sprintf( xmlprms + L, " -xmlmax=%d", scr.xmlsclmax ); /* ---------------- */ /* Read source data */ /* ---------------- */ - TS.FillFromIDB( gArgs.idb, gArgs.zmin, gArgs.zmax ); + TS.FillFromIDB( gArgs.idb, gArgs.zmin, gArgs.zmax ); - fprintf( flog, "Got %d images.\n", (int)TS.vtil.size() ); + fprintf( flog, "Got %d images.\n", (int)TS.vtil.size() ); - if( !TS.vtil.size() ) - goto exit; + if( !TS.vtil.size() ) + goto exit; - TS.SetTileDimsFromIDB( gArgs.idb ); - TS.GetTileDims( gW, gH ); + TS.SetTileDimsFromIDB( gArgs.idb ); + TS.GetTileDims( gW, gH ); /* ------------------------------------------------- */ /* Within each layer, sort tiles by dist from center */ /* ------------------------------------------------- */ - TS.SortAll_z_r(); + TS.SortAll_z_r(); /* --------------- */ /* Create dir tree */ /* --------------- */ - CreateTopDir(); + CreateTopDir(); - WriteRunlsqFile(); - WriteXviewFile(); - WriteEviewFile(); + WriteRunlsqFile(); + WriteXviewFile(); + WriteEviewFile(); - WriteCountsamedirsFile(); - WriteSSubNFile(); - WriteDSubNFile(); - WriteReportFiles(); - WriteMSubFile(); - WriteMReportFile(); - WriteGatherMonsFile(); - Write_Crossgo(); + WriteCountsamedirsFile(); + WriteSSubNFile(); + WriteDSubNFile(); + WriteReportFiles(); + WriteMSubFile(); + WriteMReportFile(); + WriteGatherMonsFile(); + Write_Crossgo(); - ForEachLayer(); + ForEachLayer(); /* ---- */ /* Done */ /* ---- */ exit: - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_MakeMontages/mreport.sht b/1_MakeMontages/mreport.sht index 59ebd2c..dedb5a6 100644 --- a/1_MakeMontages/mreport.sht +++ b/1_MakeMontages/mreport.sht @@ -9,19 +9,19 @@ if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi rm -rf MonSumy.txt for lyr in $(seq $1 $last) do - log=$lyr/montage/lsqw_0.txt - if [ -f "$log" ] - then - echo Z $lyr `grep -e "FINAL*" $log` >> MonSumy.txt - fi + log=$lyr/montage/lsqw_0.txt + if [ -f "$log" ] + then + echo Z $lyr `grep -e "FINAL*" $log` >> MonSumy.txt + fi done diff --git a/1_MakeMontages/msub.sht b/1_MakeMontages/msub.sht index bcf26e6..c808dee 100644 --- a/1_MakeMontages/msub.sht +++ b/1_MakeMontages/msub.sht @@ -8,21 +8,21 @@ if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi for lyr in $(seq $1 $last) do - echo $lyr - if [ -d "$lyr" ] - then - cd $lyr/montage + echo $lyr + if [ -d "$lyr" ] + then + cd $lyr/montage - QSUB_1NODE.sht 4 "mon-$lyr" "" 1 "./runlsq.sht" + QSUB_1NODE.sht 4 "mon-$lyr" "" 1 "./runlsq.sht" - cd ../.. - fi + cd ../.. + fi done diff --git a/1_MakeMontages/sreport.sht b/1_MakeMontages/sreport.sht index 8e5e36d..c44255e 100644 --- a/1_MakeMontages/sreport.sht +++ b/1_MakeMontages/sreport.sht @@ -11,9 +11,9 @@ if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi ls -l */S*/qS*.e* > SameErrs.txt @@ -25,16 +25,16 @@ touch SameNopts.txt for lyr in $(seq $1 $last) do - echo $lyr - if [ -d "$lyr" ] - then - for jb in $(ls -d $lyr/* | grep -E 'S[0-9]{1,}_[0-9]{1,}') - do - if [ ! -e $jb/pts.same ] - then - echo "$jb" >> SameNopts.txt - fi - done - fi + echo $lyr + if [ -d "$lyr" ] + then + for jb in $(ls -d $lyr/* | grep -E 'S[0-9]{1,}_[0-9]{1,}') + do + if [ ! -e $jb/pts.same ] + then + echo "$jb" >> SameNopts.txt + fi + done + fi done diff --git a/1_MakeMontages/ssub.sht b/1_MakeMontages/ssub.sht index 66f5a8f..d5e9f28 100644 --- a/1_MakeMontages/ssub.sht +++ b/1_MakeMontages/ssub.sht @@ -14,26 +14,26 @@ nslot=4 if (($# == 1)) then - last=$1 + last=$1 else - last=$2 + last=$2 fi for lyr in $(seq $1 $last) do - echo $lyr - if [ -d "$lyr" ] - then - cd $lyr - - for jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}') - do - cd $jb - QSUB_1NODE.sht 2 "q$jb-$lyr" "-o /dev/null" $nslot "make -f make.same -j $nproc EXTRA='""'" - cd .. - done - - cd .. - fi + echo $lyr + if [ -d "$lyr" ] + then + cd $lyr + + for jb in $(ls -d * | grep -E 'S[0-9]{1,}_[0-9]{1,}') + do + cd $jb + QSUB_1NODE.sht 2 "q$jb-$lyr" "-o /dev/null" $nslot "make -f make.same -j $nproc EXTRA='""'" + cd .. + done + + cd .. + fi done diff --git a/1_Mosaic_current/json-include/json/reader.h b/1_Mosaic_current/json-include/json/reader.h index ee1d6a2..a91b863 100644 --- a/1_Mosaic_current/json-include/json/reader.h +++ b/1_Mosaic_current/json-include/json/reader.h @@ -39,7 +39,7 @@ namespace Json { * is \c false. * \return \c true if the document was successfully parsed, \c false if an error occurred. */ - bool parse( const std::string &document, + bool parse( const std::string &document, Value &root, bool collectComments = true ); @@ -53,7 +53,7 @@ namespace Json { * is \c false. * \return \c true if the document was successfully parsed, \c false if an error occurred. */ - bool parse( const char *beginDoc, const char *endDoc, + bool parse( const char *beginDoc, const char *endDoc, Value &root, bool collectComments = true ); @@ -64,7 +64,7 @@ namespace Json { bool collectComments = true ); /** \brief Returns a user friendly string that list errors in the parsed document. - * \return Formatted error message with the list of errors with their location in + * \return Formatted error message with the list of errors with their location in * the parsed document. An empty string is returned if no error occurred * during parsing. */ @@ -110,7 +110,7 @@ namespace Json { bool expectToken( TokenType type, Token &token, const char *message ); bool readToken( Token &token ); void skipSpaces(); - bool match( Location pattern, + bool match( Location pattern, int patternLength ); bool readComment(); bool readCStyleComment(); @@ -124,19 +124,19 @@ namespace Json { bool decodeString( Token &token ); bool decodeString( Token &token, std::string &decoded ); bool decodeDouble( Token &token ); - bool decodeUnicodeCodePoint( Token &token, - Location ¤t, - Location end, + bool decodeUnicodeCodePoint( Token &token, + Location ¤t, + Location end, unsigned int &unicode ); - bool decodeUnicodeEscapeSequence( Token &token, - Location ¤t, - Location end, + bool decodeUnicodeEscapeSequence( Token &token, + Location ¤t, + Location end, unsigned int &unicode ); - bool addError( const std::string &message, + bool addError( const std::string &message, Token &token, Location extra = 0 ); bool recoverFromError( TokenType skipUntilToken ); - bool addErrorAndRecover( const std::string &message, + bool addErrorAndRecover( const std::string &message, Token &token, TokenType skipUntilToken ); void skipUntilSpace(); @@ -146,11 +146,11 @@ namespace Json { int &line, int &column ) const; std::string getLocationLineAndColumn( Location location ) const; - void addComment( Location begin, - Location end, + void addComment( Location begin, + Location end, CommentPlacement placement ); void skipCommentTokens( Token &token ); - + typedef std::stack Nodes; Nodes nodes_; Errors errors_; @@ -179,11 +179,11 @@ namespace Json { Result: \verbatim { - "dir": { - "file": { - // The input stream JSON would be nested here. - } - } + "dir": { + "file": { + // The input stream JSON would be nested here. + } + } } \endverbatim \throw std::exception on parse error. diff --git a/1_Mosaic_current/json-include/json/value.h b/1_Mosaic_current/json-include/json/value.h index 58bfd88..8789459 100644 --- a/1_Mosaic_current/json-include/json/value.h +++ b/1_Mosaic_current/json-include/json/value.h @@ -93,22 +93,22 @@ namespace Json { * - an ordered list of Value * - collection of name/value pairs (javascript object) * - * The type of the held value is represented by a #ValueType and + * The type of the held value is represented by a #ValueType and * can be obtained using type(). * - * values of an #objectValue or #arrayValue can be accessed using operator[]() methods. - * Non const methods will automatically create the a #nullValue element - * if it does not exist. - * The sequence of an #arrayValue will be automatically resize and initialized + * values of an #objectValue or #arrayValue can be accessed using operator[]() methods. + * Non const methods will automatically create the a #nullValue element + * if it does not exist. + * The sequence of an #arrayValue will be automatically resize and initialized * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue. * * The get() methods can be used to obtanis default value in the case the required element * does not exist. * - * It is possible to iterate over the list of a #objectValue values using + * It is possible to iterate over the list of a #objectValue values using * the getMemberNames() method. */ - class JSON_API Value + class JSON_API Value { friend class ValueIteratorBase; # ifdef JSON_VALUE_USE_INTERNAL_MAP @@ -131,10 +131,10 @@ namespace Json { private: #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION # ifndef JSON_VALUE_USE_INTERNAL_MAP - class CZString + class CZString { public: - enum DuplicationPolicy + enum DuplicationPolicy { noDuplication = 0, duplicate, @@ -172,14 +172,14 @@ namespace Json { To create an empty array, pass arrayValue. To create an empty object, pass objectValue. Another Value can then be set to this one by assignment. - This is useful since clear() and resize() will not alter types. + This is useful since clear() and resize() will not alter types. Examples: - \code - Json::Value null_value; // null - Json::Value arr_value(Json::arrayValue); // [] - Json::Value obj_value(Json::objectValue); // {} - \endcode + \code + Json::Value null_value; // null + Json::Value arr_value(Json::arrayValue); // [] + Json::Value obj_value(Json::objectValue); // {} + \endcode */ Value( ValueType type = nullValue ); Value( Int value ); @@ -262,7 +262,7 @@ namespace Json { /// \post type() is unchanged void clear(); - /// Resize the array to size elements. + /// Resize the array to size elements. /// New elements are initialized to null. /// May only be called on nullValue or arrayValue. /// \pre type() is arrayValue or nullValue @@ -279,9 +279,9 @@ namespace Json { /// (You may need to say 'value[0u]' to get your compiler to distinguish /// this from the operator[] which takes a string.) const Value &operator[]( UInt index ) const; - /// If the array contains at least index+1 elements, returns the element value, + /// If the array contains at least index+1 elements, returns the element value, /// otherwise returns defaultValue. - Value get( UInt index, + Value get( UInt index, const Value &defaultValue ) const; /// Return true if index < size(). bool isValidIndex( UInt index ) const; @@ -317,7 +317,7 @@ namespace Json { const Value &operator[]( const CppTL::ConstString &key ) const; # endif /// Return the member named key if it exist, defaultValue otherwise. - Value get( const char *key, + Value get( const char *key, const Value &defaultValue ) const; /// Return the member named key if it exist, defaultValue otherwise. Value get( const std::string &key, @@ -327,7 +327,7 @@ namespace Json { Value get( const CppTL::ConstString &key, const Value &defaultValue ) const; # endif - /// \brief Remove and return the named member. + /// \brief Remove and return the named member. /// /// Do nothing if it did not exist. /// \return the removed Value, or null. @@ -377,7 +377,7 @@ namespace Json { iterator end(); private: - Value &resolveReference( const char *key, + Value &resolveReference( const char *key, bool isStatic ); # ifdef JSON_VALUE_USE_INTERNAL_MAP @@ -492,7 +492,7 @@ namespace Json { const PathArgument &a5 = PathArgument() ); const Value &resolve( const Value &root ) const; - Value resolve( const Value &root, + Value resolve( const Value &root, const Value &defaultValue ) const; /// Creates the "path" to access the specified node and returns a reference on the node. Value &make( Value &root ) const; @@ -503,11 +503,11 @@ namespace Json { void makePath( const std::string &path, const InArgs &in ); - void addPathInArg( const std::string &path, - const InArgs &in, - InArgs::const_iterator &itInArg, + void addPathInArg( const std::string &path, + const InArgs &in, + InArgs::const_iterator &itInArg, PathArgument::Kind kind ); - void invalidPath( const std::string &path, + void invalidPath( const std::string &path, int location ); Args args_; @@ -529,7 +529,7 @@ namespace Json { virtual char *makeMemberName( const char *memberName ) = 0; virtual void releaseMemberName( char *memberName ) = 0; - virtual char *duplicateStringValue( const char *value, + virtual char *duplicateStringValue( const char *value, unsigned int length = unknown ) = 0; virtual void releaseStringValue( char *value ) = 0; }; @@ -578,7 +578,7 @@ namespace Json { } }; * \endcode - */ + */ class JSON_API ValueMapAllocator { public: @@ -599,7 +599,7 @@ namespace Json { { public: enum { itemPerLink = 6 }; // sizeof(ValueInternalLink) = 128 on 32 bits architecture. - enum InternalFlags { + enum InternalFlags { flagAvailable = 0, flagUsed = 1 }; @@ -620,7 +620,7 @@ namespace Json { * list in each bucket to handle collision. There is an addional twist in that * each node of the collision linked list is a page containing a fixed amount of * value. This provides a better compromise between memory usage and speed. - * + * * Each bucket is made up of a chained list of ValueInternalLink. The last * link of a given bucket can be found in the 'previous_' field of the following bucket. * The last link of the last bucket is stored in tailLink_ as it has no following bucket. @@ -638,11 +638,11 @@ namespace Json { # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION struct IteratorState { - IteratorState() + IteratorState() : map_(0) , link_(0) , itemIndex_(0) - , bucketIndex_(0) + , bucketIndex_(0) { } ValueInternalMap *map_; @@ -671,24 +671,24 @@ namespace Json { Value *find( const char *key ); - Value &resolveReference( const char *key, + Value &resolveReference( const char *key, bool isStatic ); void remove( const char *key ); - void doActualRemove( ValueInternalLink *link, + void doActualRemove( ValueInternalLink *link, BucketIndex index, BucketIndex bucketIndex ); ValueInternalLink *&getLastLinkInBucket( BucketIndex bucketIndex ); - Value &setNewItem( const char *key, - bool isStatic, - ValueInternalLink *link, + Value &setNewItem( const char *key, + bool isStatic, + ValueInternalLink *link, BucketIndex index ); - Value &unsafeAdd( const char *key, - bool isStatic, + Value &unsafeAdd( const char *key, + bool isStatic, HashKey hashedKey ); HashKey hash( const char *key ) const; @@ -737,10 +737,10 @@ namespace Json { # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION struct IteratorState // Must be a POD { - IteratorState() + IteratorState() : array_(0) , currentPageIndex_(0) - , currentItemIndex_(0) + , currentItemIndex_(0) { } ValueInternalArray *array_; @@ -811,7 +811,7 @@ class DefaultValueArrayAllocator : public ValueArrayAllocator delete array; } - virtual void reallocateArrayPageIndex( Value **&indexes, + virtual void reallocateArrayPageIndex( Value **&indexes, ValueInternalArray::PageIndex &indexCount, ValueInternalArray::PageIndex minNewIndexCount ) { @@ -824,7 +824,7 @@ class DefaultValueArrayAllocator : public ValueArrayAllocator indexCount = newIndexCount; indexes = static_cast( newIndexes ); } - virtual void releaseArrayPageIndex( Value **indexes, + virtual void releaseArrayPageIndex( Value **indexes, ValueInternalArray::PageIndex indexCount ) { if ( indexes ) @@ -843,7 +843,7 @@ class DefaultValueArrayAllocator : public ValueArrayAllocator } }; \endcode - */ + */ class JSON_API ValueArrayAllocator { public: @@ -854,18 +854,18 @@ class DefaultValueArrayAllocator : public ValueArrayAllocator /** \brief Reallocate array page index. * Reallocates an array of pointer on each page. * \param indexes [input] pointer on the current index. May be \c NULL. - * [output] pointer on the new index of at least - * \a minNewIndexCount pages. + * [output] pointer on the new index of at least + * \a minNewIndexCount pages. * \param indexCount [input] current number of pages in the index. * [output] number of page the reallocated index can handle. * \b MUST be >= \a minNewIndexCount. * \param minNewIndexCount Minimum number of page the new index must be able to * handle. */ - virtual void reallocateArrayPageIndex( Value **&indexes, + virtual void reallocateArrayPageIndex( Value **&indexes, ValueInternalArray::PageIndex &indexCount, ValueInternalArray::PageIndex minNewIndexCount ) = 0; - virtual void releaseArrayPageIndex( Value **indexes, + virtual void releaseArrayPageIndex( Value **indexes, ValueInternalArray::PageIndex indexCount ) = 0; virtual Value *allocateArrayPage() = 0; virtual void releaseArrayPage( Value *value ) = 0; diff --git a/1_Mosaic_current/json_batchallocator.h b/1_Mosaic_current/json_batchallocator.h index 87ea5ed..2ace57a 100644 --- a/1_Mosaic_current/json_batchallocator.h +++ b/1_Mosaic_current/json_batchallocator.h @@ -16,7 +16,7 @@ namespace Json { * It does not allow the destruction of a single object. All the allocated objects * can be destroyed at once. The memory can be either released or reused for future * allocation. - * + * * The in-place new operator must be used to construct the object using the pointer * returned by allocate. */ @@ -65,7 +65,7 @@ class BatchAllocator currentBatch_ = currentBatch_->next_; if ( !currentBatch_ ) // no free batch found, allocate a new one - { + { currentBatch_ = allocateBatch( objectsPerPage_ ); currentBatch_->next_ = batches_; // insert at the head of the list batches_ = currentBatch_; diff --git a/1_Mosaic_current/json_reader.cpp b/1_Mosaic_current/json_reader.cpp index 4eb2d11..09621bd 100644 --- a/1_Mosaic_current/json_reader.cpp +++ b/1_Mosaic_current/json_reader.cpp @@ -23,14 +23,14 @@ Features::Features() } -Features +Features Features::all() { return Features(); } -Features +Features Features::strictMode() { Features features; @@ -43,21 +43,21 @@ Features::strictMode() // //////////////////////////////// -static inline bool +static inline bool in( Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4 ) { return c == c1 || c == c2 || c == c3 || c == c4; } -static inline bool +static inline bool in( Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4, Reader::Char c5 ) { return c == c1 || c == c2 || c == c3 || c == c4 || c == c5; } -static bool -containsNewLine( Reader::Location begin, +static bool +containsNewLine( Reader::Location begin, Reader::Location end ) { for ( ;begin < end; ++begin ) @@ -69,28 +69,28 @@ containsNewLine( Reader::Location begin, static std::string codePointToUTF8(unsigned int cp) { std::string result; - + // based on description from http://en.wikipedia.org/wiki/UTF-8 - if (cp <= 0x7f) + if (cp <= 0x7f) { result.resize(1); result[0] = static_cast(cp); - } - else if (cp <= 0x7FF) + } + else if (cp <= 0x7FF) { result.resize(2); result[1] = static_cast(0x80 | (0x3f & cp)); result[0] = static_cast(0xC0 | (0x1f & (cp >> 6))); - } - else if (cp <= 0xFFFF) + } + else if (cp <= 0xFFFF) { result.resize(3); result[2] = static_cast(0x80 | (0x3f & cp)); result[1] = 0x80 | static_cast((0x3f & (cp >> 6))); result[0] = 0xE0 | static_cast((0xf & (cp >> 12))); } - else if (cp <= 0x10FFFF) + else if (cp <= 0x10FFFF) { result.resize(4); result[3] = static_cast(0x80 | (0x3f & cp)); @@ -119,7 +119,7 @@ Reader::Reader( const Features &features ) bool -Reader::parse( const std::string &document, +Reader::parse( const std::string &document, Value &root, bool collectComments ) { @@ -147,8 +147,8 @@ Reader::parse( std::istream& sin, return parse( doc, root, collectComments ); } -bool -Reader::parse( const char *beginDoc, const char *endDoc, +bool +Reader::parse( const char *beginDoc, const char *endDoc, Value &root, bool collectComments ) { @@ -168,7 +168,7 @@ Reader::parse( const char *beginDoc, const char *endDoc, while ( !nodes_.empty() ) nodes_.pop(); nodes_.push( &root ); - + bool successful = readValue(); Token token; skipCommentTokens( token ); @@ -242,7 +242,7 @@ Reader::readValue() } -void +void Reader::skipCommentTokens( Token &token ) { if ( features_.allowComments_ ) @@ -260,7 +260,7 @@ Reader::skipCommentTokens( Token &token ) } -bool +bool Reader::expectToken( TokenType type, Token &token, const char *message ) { readToken( token ); @@ -270,7 +270,7 @@ Reader::expectToken( TokenType type, Token &token, const char *message ) } -bool +bool Reader::readToken( Token &token ) { skipSpaces(); @@ -345,7 +345,7 @@ Reader::readToken( Token &token ) } -void +void Reader::skipSpaces() { while ( current_ != end_ ) @@ -359,8 +359,8 @@ Reader::skipSpaces() } -bool -Reader::match( Location pattern, +bool +Reader::match( Location pattern, int patternLength ) { if ( end_ - current_ < patternLength ) @@ -402,9 +402,9 @@ Reader::readComment() } -void -Reader::addComment( Location begin, - Location end, +void +Reader::addComment( Location begin, + Location end, CommentPlacement placement ) { assert( collectComments_ ); @@ -422,7 +422,7 @@ Reader::addComment( Location begin, } -bool +bool Reader::readCStyleComment() { while ( current_ != end_ ) @@ -435,7 +435,7 @@ Reader::readCStyleComment() } -bool +bool Reader::readCppStyleComment() { while ( current_ != end_ ) @@ -448,7 +448,7 @@ Reader::readCppStyleComment() } -void +void Reader::readNumber() { while ( current_ != end_ ) @@ -476,7 +476,7 @@ Reader::readString() } -bool +bool Reader::readObject( Token &tokenStart ) { Token tokenName; @@ -493,7 +493,7 @@ Reader::readObject( Token &tokenStart ) return true; if ( tokenName.type_ != tokenString ) break; - + name = ""; if ( !decodeString( tokenName, name ) ) return recoverFromError( tokenObjectEnd ); @@ -501,8 +501,8 @@ Reader::readObject( Token &tokenStart ) Token colon; if ( !readToken( colon ) || colon.type_ != tokenMemberSeparator ) { - return addErrorAndRecover( "Missing ':' after object member name", - colon, + return addErrorAndRecover( "Missing ':' after object member name", + colon, tokenObjectEnd ); } Value &value = currentValue()[ name ]; @@ -514,12 +514,12 @@ Reader::readObject( Token &tokenStart ) Token comma; if ( !readToken( comma ) - || ( comma.type_ != tokenObjectEnd && + || ( comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator && - comma.type_ != tokenComment ) ) + comma.type_ != tokenComment ) ) { - return addErrorAndRecover( "Missing ',' or '}' in object declaration", - comma, + return addErrorAndRecover( "Missing ',' or '}' in object declaration", + comma, tokenObjectEnd ); } bool finalizeTokenOk = true; @@ -529,13 +529,13 @@ Reader::readObject( Token &tokenStart ) if ( comma.type_ == tokenObjectEnd ) return true; } - return addErrorAndRecover( "Missing '}' or object member name", - tokenName, + return addErrorAndRecover( "Missing '}' or object member name", + tokenName, tokenObjectEnd ); } -bool +bool Reader::readArray( Token &tokenStart ) { currentValue() = Value( arrayValue ); @@ -563,12 +563,12 @@ Reader::readArray( Token &tokenStart ) { ok = readToken( token ); } - bool badTokenType = ( token.type_ == tokenArraySeparator && + bool badTokenType = ( token.type_ == tokenArraySeparator && token.type_ == tokenArrayEnd ); if ( !ok || badTokenType ) { - return addErrorAndRecover( "Missing ',' or ']' in array declaration", - token, + return addErrorAndRecover( "Missing ',' or ']' in array declaration", + token, tokenArrayEnd ); } if ( token.type_ == tokenArrayEnd ) @@ -578,14 +578,14 @@ Reader::readArray( Token &tokenStart ) } -bool +bool Reader::decodeNumber( Token &token ) { bool isDouble = false; for ( Location inspect = token.start_; inspect != token.end_; ++inspect ) { - isDouble = isDouble - || in( *inspect, '.', 'e', 'E', '+' ) + isDouble = isDouble + || in( *inspect, '.', 'e', 'E', '+' ) || ( *inspect == '-' && inspect != token.start_ ); } if ( isDouble ) @@ -594,7 +594,7 @@ Reader::decodeNumber( Token &token ) bool isNegative = *current == '-'; if ( isNegative ) ++current; - Value::UInt threshold = (isNegative ? Value::UInt(-Value::minInt) + Value::UInt threshold = (isNegative ? Value::UInt(-Value::minInt) : Value::maxUInt) / 10; Value::UInt value = 0; while ( current < token.end_ ) @@ -616,7 +616,7 @@ Reader::decodeNumber( Token &token ) } -bool +bool Reader::decodeDouble( Token &token ) { double value = 0; @@ -643,7 +643,7 @@ Reader::decodeDouble( Token &token ) } -bool +bool Reader::decodeString( Token &token ) { std::string decoded; @@ -654,7 +654,7 @@ Reader::decodeString( Token &token ) } -bool +bool Reader::decodeString( Token &token, std::string &decoded ) { decoded.reserve( token.end_ - token.start_ - 2 ); @@ -701,9 +701,9 @@ Reader::decodeString( Token &token, std::string &decoded ) } bool -Reader::decodeUnicodeCodePoint( Token &token, - Location ¤t, - Location end, +Reader::decodeUnicodeCodePoint( Token &token, + Location ¤t, + Location end, unsigned int &unicode ) { @@ -720,20 +720,20 @@ Reader::decodeUnicodeCodePoint( Token &token, if (decodeUnicodeEscapeSequence( token, current, end, surrogatePair )) { unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF); - } + } else return false; - } + } else return addError( "expecting another \\u token to begin the second half of a unicode surrogate pair", token, current ); } return true; } -bool -Reader::decodeUnicodeEscapeSequence( Token &token, - Location ¤t, - Location end, +bool +Reader::decodeUnicodeEscapeSequence( Token &token, + Location ¤t, + Location end, unsigned int &unicode ) { if ( end - current < 4 ) @@ -756,8 +756,8 @@ Reader::decodeUnicodeEscapeSequence( Token &token, } -bool -Reader::addError( const std::string &message, +bool +Reader::addError( const std::string &message, Token &token, Location extra ) { @@ -770,7 +770,7 @@ Reader::addError( const std::string &message, } -bool +bool Reader::recoverFromError( TokenType skipUntilToken ) { int errorCount = int(errors_.size()); @@ -787,8 +787,8 @@ Reader::recoverFromError( TokenType skipUntilToken ) } -bool -Reader::addErrorAndRecover( const std::string &message, +bool +Reader::addErrorAndRecover( const std::string &message, Token &token, TokenType skipUntilToken ) { @@ -804,7 +804,7 @@ Reader::currentValue() } -Reader::Char +Reader::Char Reader::getNextChar() { if ( current_ == end_ ) @@ -813,7 +813,7 @@ Reader::getNextChar() } -void +void Reader::getLocationLineAndColumn( Location location, int &line, int &column ) const @@ -854,7 +854,7 @@ Reader::getLocationLineAndColumn( Location location ) const } -std::string +std::string Reader::getFormatedErrorMessages() const { std::string formattedMessage; diff --git a/1_Mosaic_current/json_value.cpp b/1_Mosaic_current/json_value.cpp index 573205f..ba94d2d 100644 --- a/1_Mosaic_current/json_value.cpp +++ b/1_Mosaic_current/json_value.cpp @@ -24,7 +24,7 @@ const Int Value::minInt = Int( ~(UInt(-1)/2) ); const Int Value::maxInt = Int( UInt(-1)/2 ); const UInt Value::maxUInt = UInt(-1); -// A "safe" implementation of strdup. Allow null pointer to be passed. +// A "safe" implementation of strdup. Allow null pointer to be passed. // Also avoid warning on msvc80. // //inline char *safeStringDup( const char *czstring ) @@ -73,7 +73,7 @@ class DefaultValueAllocator : public ValueAllocator releaseStringValue( memberName ); } - virtual char *duplicateStringValue( const char *value, + virtual char *duplicateStringValue( const char *value, unsigned int length = unknown ) { //@todo invesgate this old optimization @@ -103,7 +103,7 @@ static ValueAllocator *&valueAllocator() } static struct DummyValueAllocatorInitializer { - DummyValueAllocatorInitializer() + DummyValueAllocatorInitializer() { valueAllocator(); // ensure valueAllocator() statics are initialized before main(). } @@ -147,7 +147,7 @@ Value::CommentInfo::~CommentInfo() } -void +void Value::CommentInfo::setComment( const char *text ) { if ( comment_ ) @@ -178,7 +178,7 @@ Value::CZString::CZString( int index ) } Value::CZString::CZString( const char *cstr, DuplicationPolicy allocate ) - : cstr_( allocate == duplicate ? valueAllocator()->makeMemberName(cstr) + : cstr_( allocate == duplicate ? valueAllocator()->makeMemberName(cstr) : cstr ) , index_( allocate ) { @@ -199,7 +199,7 @@ Value::CZString::~CZString() valueAllocator()->releaseMemberName( const_cast( cstr_ ) ); } -void +void Value::CZString::swap( CZString &other ) { std::swap( cstr_, other.cstr_ ); @@ -214,16 +214,16 @@ Value::CZString::operator =( const CZString &other ) return *this; } -bool -Value::CZString::operator<( const CZString &other ) const +bool +Value::CZString::operator<( const CZString &other ) const { if ( cstr_ ) return strcmp( cstr_, other.cstr_ ) < 0; return index_ < other.index_; } -bool -Value::CZString::operator==( const CZString &other ) const +bool +Value::CZString::operator==( const CZString &other ) const { if ( cstr_ ) return strcmp( cstr_, other.cstr_ ) == 0; @@ -231,7 +231,7 @@ Value::CZString::operator==( const CZString &other ) const } -int +int Value::CZString::index() const { return index_; @@ -244,7 +244,7 @@ Value::CZString::c_str() const return cstr_; } -bool +bool Value::CZString::isStaticString() const { return index_ == noDuplication; @@ -352,7 +352,7 @@ Value::Value( const char *value ) } -Value::Value( const char *beginValue, +Value::Value( const char *beginValue, const char *endValue ) : type_( stringValue ) , allocated_( true ) @@ -361,7 +361,7 @@ Value::Value( const char *beginValue, , itemIsUsed_( 0 ) #endif { - value_.string_ = valueAllocator()->duplicateStringValue( beginValue, + value_.string_ = valueAllocator()->duplicateStringValue( beginValue, UInt(endValue - beginValue) ); } @@ -374,7 +374,7 @@ Value::Value( const std::string &value ) , itemIsUsed_( 0 ) #endif { - value_.string_ = valueAllocator()->duplicateStringValue( value.c_str(), + value_.string_ = valueAllocator()->duplicateStringValue( value.c_str(), (unsigned int)value.length() ); } @@ -512,7 +512,7 @@ Value::operator=( const Value &other ) return *this; } -void +void Value::swap( Value &other ) { ValueType temp = type_; @@ -524,14 +524,14 @@ Value::swap( Value &other ) other.allocated_ = temp2; } -ValueType +ValueType Value::type() const { return type_; } -int +int Value::compare( const Value &other ) { /* @@ -561,7 +561,7 @@ Value::compare( const Value &other ) return 0; // unreachable } -bool +bool Value::operator <( const Value &other ) const { int typeDelta = type_ - other.type_; @@ -581,8 +581,8 @@ Value::operator <( const Value &other ) const return value_.bool_ < other.value_.bool_; case stringValue: return ( value_.string_ == 0 && other.value_.string_ ) - || ( other.value_.string_ - && value_.string_ + || ( other.value_.string_ + && value_.string_ && strcmp( value_.string_, other.value_.string_ ) < 0 ); #ifndef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: @@ -605,25 +605,25 @@ Value::operator <( const Value &other ) const return 0; // unreachable } -bool +bool Value::operator <=( const Value &other ) const { return !(other > *this); } -bool +bool Value::operator >=( const Value &other ) const { return !(*this < other); } -bool +bool Value::operator >( const Value &other ) const { return other < *this; } -bool +bool Value::operator ==( const Value &other ) const { //if ( type_ != other.type_ ) @@ -647,8 +647,8 @@ Value::operator ==( const Value &other ) const return value_.bool_ == other.value_.bool_; case stringValue: return ( value_.string_ == other.value_.string_ ) - || ( other.value_.string_ - && value_.string_ + || ( other.value_.string_ + && value_.string_ && strcmp( value_.string_, other.value_.string_ ) == 0 ); #ifndef JSON_VALUE_USE_INTERNAL_MAP case arrayValue: @@ -667,7 +667,7 @@ Value::operator ==( const Value &other ) const return 0; // unreachable } -bool +bool Value::operator !=( const Value &other ) const { return !( *this == other ); @@ -681,7 +681,7 @@ Value::asCString() const } -std::string +std::string Value::asString() const { switch ( type_ ) @@ -705,14 +705,14 @@ Value::asString() const } # ifdef JSON_USE_CPPTL -CppTL::ConstString +CppTL::ConstString Value::asConstString() const { return CppTL::ConstString( asString().c_str() ); } # endif -Value::Int +Value::Int Value::asInt() const { switch ( type_ ) @@ -739,7 +739,7 @@ Value::asInt() const return 0; // unreachable; } -Value::UInt +Value::UInt Value::asUInt() const { switch ( type_ ) @@ -766,7 +766,7 @@ Value::asUInt() const return 0; // unreachable; } -double +double Value::asDouble() const { switch ( type_ ) @@ -791,7 +791,7 @@ Value::asDouble() const return 0; // unreachable; } -bool +bool Value::asBool() const { switch ( type_ ) @@ -817,7 +817,7 @@ Value::asBool() const } -bool +bool Value::isConvertibleTo( ValueType other ) const { switch ( type_ ) @@ -869,7 +869,7 @@ Value::isConvertibleTo( ValueType other ) const /// Number of values in array or object -Value::UInt +Value::UInt Value::size() const { switch ( type_ ) @@ -905,7 +905,7 @@ Value::size() const } -bool +bool Value::empty() const { if ( isNull() || isArray() || isObject() ) @@ -922,7 +922,7 @@ Value::operator!() const } -void +void Value::clear() { JSON_ASSERT( type_ == nullValue || type_ == arrayValue || type_ == objectValue ); @@ -947,7 +947,7 @@ Value::clear() } } -void +void Value::resize( UInt newSize ) { JSON_ASSERT( type_ == nullValue || type_ == arrayValue ); @@ -1019,14 +1019,14 @@ Value::operator[]( const char *key ) Value & -Value::resolveReference( const char *key, +Value::resolveReference( const char *key, bool isStatic ) { JSON_ASSERT( type_ == nullValue || type_ == objectValue ); if ( type_ == nullValue ) *this = Value( objectValue ); #ifndef JSON_VALUE_USE_INTERNAL_MAP - CZString actualKey( key, isStatic ? CZString::noDuplication + CZString actualKey( key, isStatic ? CZString::noDuplication : CZString::duplicateOnCopy ); ObjectValues::iterator it = value_.map_->lower_bound( actualKey ); if ( it != value_.map_->end() && (*it).first == actualKey ) @@ -1042,8 +1042,8 @@ Value::resolveReference( const char *key, } -Value -Value::get( UInt index, +Value +Value::get( UInt index, const Value &defaultValue ) const { const Value *value = &((*this)[index]); @@ -1051,7 +1051,7 @@ Value::get( UInt index, } -bool +bool Value::isValidIndex( UInt index ) const { return index < size(); @@ -1121,8 +1121,8 @@ Value::append( const Value &value ) } -Value -Value::get( const char *key, +Value +Value::get( const char *key, const Value &defaultValue ) const { const Value *value = &((*this)[key]); @@ -1130,7 +1130,7 @@ Value::get( const char *key, } -Value +Value Value::get( const std::string &key, const Value &defaultValue ) const { @@ -1170,7 +1170,7 @@ Value::removeMember( const std::string &key ) } # ifdef JSON_USE_CPPTL -Value +Value Value::get( const CppTL::ConstString &key, const Value &defaultValue ) const { @@ -1178,7 +1178,7 @@ Value::get( const CppTL::ConstString &key, } # endif -bool +bool Value::isMember( const char *key ) const { const Value *value = &((*this)[key]); @@ -1186,7 +1186,7 @@ Value::isMember( const char *key ) const } -bool +bool Value::isMember( const std::string &key ) const { return isMember( key.c_str() ); @@ -1194,14 +1194,14 @@ Value::isMember( const std::string &key ) const # ifdef JSON_USE_CPPTL -bool +bool Value::isMember( const CppTL::ConstString &key ) const { return isMember( key.c_str() ); } #endif -Value::Members +Value::Members Value::getMemberNames() const { JSON_ASSERT( type_ == nullValue || type_ == objectValue ); @@ -1239,11 +1239,11 @@ Value::getMemberNames() const //} // // -//EnumValues +//EnumValues //Value::enumValues() const //{ // if ( type_ == objectValue || type_ == arrayValue ) -// return CppTL::Enum::anyValues( *(value_.map_), +// return CppTL::Enum::anyValues( *(value_.map_), // CppTL::Type() ); // return EnumValues(); //} @@ -1258,72 +1258,72 @@ Value::isNull() const } -bool +bool Value::isBool() const { return type_ == booleanValue; } -bool +bool Value::isInt() const { return type_ == intValue; } -bool +bool Value::isUInt() const { return type_ == uintValue; } -bool +bool Value::isIntegral() const { - return type_ == intValue - || type_ == uintValue + return type_ == intValue + || type_ == uintValue || type_ == booleanValue; } -bool +bool Value::isDouble() const { return type_ == realValue; } -bool +bool Value::isNumeric() const { return isIntegral() || isDouble(); } -bool +bool Value::isString() const { return type_ == stringValue; } -bool +bool Value::isArray() const { return type_ == nullValue || type_ == arrayValue; } -bool +bool Value::isObject() const { return type_ == nullValue || type_ == objectValue; } -void +void Value::setComment( const char *comment, CommentPlacement placement ) { @@ -1333,7 +1333,7 @@ Value::setComment( const char *comment, } -void +void Value::setComment( const std::string &comment, CommentPlacement placement ) { @@ -1341,13 +1341,13 @@ Value::setComment( const std::string &comment, } -bool +bool Value::hasComment( CommentPlacement placement ) const { return comments_ != 0 && comments_[placement].comment_ != 0; } -std::string +std::string Value::getComment( CommentPlacement placement ) const { if ( hasComment(placement) ) @@ -1356,7 +1356,7 @@ Value::getComment( CommentPlacement placement ) const } -std::string +std::string Value::toStyledString() const { StyledWriter writer; @@ -1364,7 +1364,7 @@ Value::toStyledString() const } -Value::const_iterator +Value::const_iterator Value::begin() const { switch ( type_ ) @@ -1399,7 +1399,7 @@ Value::begin() const return const_iterator(); } -Value::const_iterator +Value::const_iterator Value::end() const { switch ( type_ ) @@ -1435,7 +1435,7 @@ Value::end() const } -Value::iterator +Value::iterator Value::begin() { switch ( type_ ) @@ -1470,7 +1470,7 @@ Value::begin() return iterator(); } -Value::iterator +Value::iterator Value::end() { switch ( type_ ) @@ -1555,7 +1555,7 @@ Path::Path( const std::string &path, } -void +void Path::makePath( const std::string &path, const InArgs &in ) { @@ -1599,10 +1599,10 @@ Path::makePath( const std::string &path, } -void -Path::addPathInArg( const std::string &path, - const InArgs &in, - InArgs::const_iterator &itInArg, +void +Path::addPathInArg( const std::string &path, + const InArgs &in, + InArgs::const_iterator &itInArg, PathArgument::Kind kind ) { if ( itInArg == in.end() ) @@ -1620,8 +1620,8 @@ Path::addPathInArg( const std::string &path, } -void -Path::invalidPath( const std::string &path, +void +Path::invalidPath( const std::string &path, int location ) { // Error: invalid path. @@ -1660,8 +1660,8 @@ Path::resolve( const Value &root ) const } -Value -Path::resolve( const Value &root, +Value +Path::resolve( const Value &root, const Value &defaultValue ) const { const Value *node = &root; diff --git a/1_Mosaic_current/json_valueiterator.inl b/1_Mosaic_current/json_valueiterator.inl index 736e260..067cc97 100644 --- a/1_Mosaic_current/json_valueiterator.inl +++ b/1_Mosaic_current/json_valueiterator.inl @@ -59,7 +59,7 @@ ValueIteratorBase::deref() const } -void +void ValueIteratorBase::increment() { #ifndef JSON_VALUE_USE_INTERNAL_MAP @@ -72,7 +72,7 @@ ValueIteratorBase::increment() } -void +void ValueIteratorBase::decrement() { #ifndef JSON_VALUE_USE_INTERNAL_MAP @@ -85,7 +85,7 @@ ValueIteratorBase::decrement() } -ValueIteratorBase::difference_type +ValueIteratorBase::difference_type ValueIteratorBase::computeDistance( const SelfType &other ) const { #ifndef JSON_VALUE_USE_INTERNAL_MAP @@ -94,7 +94,7 @@ ValueIteratorBase::computeDistance( const SelfType &other ) const # else // Iterator for null value are initialized using the default // constructor, which initialize current_ to the default - // std::map::iterator. As begin() and end() are two instance + // std::map::iterator. As begin() and end() are two instance // of the default std::map::iterator, they can not be compared. // To allow this, we handle this comparison specifically. if ( isNull_ && other.isNull_ ) @@ -122,7 +122,7 @@ ValueIteratorBase::computeDistance( const SelfType &other ) const } -bool +bool ValueIteratorBase::isEqual( const SelfType &other ) const { #ifndef JSON_VALUE_USE_INTERNAL_MAP @@ -139,7 +139,7 @@ ValueIteratorBase::isEqual( const SelfType &other ) const } -void +void ValueIteratorBase::copy( const SelfType &other ) { #ifndef JSON_VALUE_USE_INTERNAL_MAP @@ -152,7 +152,7 @@ ValueIteratorBase::copy( const SelfType &other ) } -Value +Value ValueIteratorBase::key() const { #ifndef JSON_VALUE_USE_INTERNAL_MAP @@ -176,7 +176,7 @@ ValueIteratorBase::key() const } -UInt +UInt ValueIteratorBase::index() const { #ifndef JSON_VALUE_USE_INTERNAL_MAP diff --git a/1_Mosaic_current/json_writer.cpp b/1_Mosaic_current/json_writer.cpp index cdf4188..6eaf497 100644 --- a/1_Mosaic_current/json_writer.cpp +++ b/1_Mosaic_current/json_writer.cpp @@ -20,14 +20,14 @@ static bool isControlCharacter(char ch) static bool containsControlCharacter( const char* str ) { - while ( *str ) + while ( *str ) { if ( isControlCharacter( *(str++) ) ) return true; } return false; } -static void uintToString( unsigned int value, +static void uintToString( unsigned int value, char *¤t ) { *--current = 0; @@ -66,10 +66,10 @@ std::string valueToString( UInt value ) std::string valueToString( double value ) { char buffer[32]; -#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with visual studio 2005 to avoid warning. - sprintf_s(buffer, sizeof(buffer), "%#.16g", value); -#else - sprintf(buffer, "%#.16g", value); +#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with visual studio 2005 to avoid warning. + sprintf_s(buffer, sizeof(buffer), "%#.16g", value); +#else + sprintf(buffer, "%#.16g", value); #endif char* ch = buffer + strlen(buffer) - 1; if (*ch != '0') return buffer; // nothing to truncate, so save time @@ -149,9 +149,9 @@ std::string valueToQuotedString( const char *value ) // Even though \/ is considered a legal escape in JSON, a bare // slash is also legal, so I see no reason to escape it. // (I hope I am not misunderstanding something. - // blep notes: actually escaping \/ may be useful in javascript to avoid 0 ); } if ( !isMultiLine ) // check if line length > max line length @@ -432,7 +432,7 @@ StyledWriter::isMultineArray( const Value &value ) } -void +void StyledWriter::pushValue( const std::string &value ) { if ( addChildValues_ ) @@ -442,7 +442,7 @@ StyledWriter::pushValue( const std::string &value ) } -void +void StyledWriter::writeIndent() { if ( !document_.empty() ) @@ -457,7 +457,7 @@ StyledWriter::writeIndent() } -void +void StyledWriter::writeWithIndent( const std::string &value ) { writeIndent(); @@ -465,14 +465,14 @@ StyledWriter::writeWithIndent( const std::string &value ) } -void +void StyledWriter::indent() { indentString_ += std::string( indentSize_, ' ' ); } -void +void StyledWriter::unindent() { assert( int(indentString_.size()) >= indentSize_ ); @@ -480,7 +480,7 @@ StyledWriter::unindent() } -void +void StyledWriter::writeCommentBeforeValue( const Value &root ) { if ( !root.hasComment( commentBefore ) ) @@ -490,7 +490,7 @@ StyledWriter::writeCommentBeforeValue( const Value &root ) } -void +void StyledWriter::writeCommentAfterValueOnSameLine( const Value &root ) { if ( root.hasComment( commentAfterOnSameLine ) ) @@ -505,7 +505,7 @@ StyledWriter::writeCommentAfterValueOnSameLine( const Value &root ) } -bool +bool StyledWriter::hasCommentForValue( const Value &value ) { return value.hasComment( commentBefore ) @@ -514,7 +514,7 @@ StyledWriter::hasCommentForValue( const Value &value ) } -std::string +std::string StyledWriter::normalizeEOL( const std::string &text ) { std::string normalized; @@ -563,7 +563,7 @@ StyledStreamWriter::write( std::ostream &out, const Value &root ) } -void +void StyledStreamWriter::writeValue( const Value &value ) { switch ( value.type() ) @@ -624,7 +624,7 @@ StyledStreamWriter::writeValue( const Value &value ) } -void +void StyledStreamWriter::writeArrayValue( const Value &value ) { unsigned size = value.size(); @@ -647,7 +647,7 @@ StyledStreamWriter::writeArrayValue( const Value &value ) writeWithIndent( childValues_[index] ); else { - writeIndent(); + writeIndent(); writeValue( childValue ); } if ( ++index == size ) @@ -677,7 +677,7 @@ StyledStreamWriter::writeArrayValue( const Value &value ) } -bool +bool StyledStreamWriter::isMultineArray( const Value &value ) { int size = value.size(); @@ -687,7 +687,7 @@ StyledStreamWriter::isMultineArray( const Value &value ) { const Value &childValue = value[index]; isMultiLine = isMultiLine || - ( (childValue.isArray() || childValue.isObject()) && + ( (childValue.isArray() || childValue.isObject()) && childValue.size() > 0 ); } if ( !isMultiLine ) // check if line length > max line length @@ -708,7 +708,7 @@ StyledStreamWriter::isMultineArray( const Value &value ) } -void +void StyledStreamWriter::pushValue( const std::string &value ) { if ( addChildValues_ ) @@ -718,7 +718,7 @@ StyledStreamWriter::pushValue( const std::string &value ) } -void +void StyledStreamWriter::writeIndent() { /* @@ -737,7 +737,7 @@ StyledStreamWriter::writeIndent() } -void +void StyledStreamWriter::writeWithIndent( const std::string &value ) { writeIndent(); @@ -745,14 +745,14 @@ StyledStreamWriter::writeWithIndent( const std::string &value ) } -void +void StyledStreamWriter::indent() { indentString_ += indentation_; } -void +void StyledStreamWriter::unindent() { assert( indentString_.size() >= indentation_.size() ); @@ -760,7 +760,7 @@ StyledStreamWriter::unindent() } -void +void StyledStreamWriter::writeCommentBeforeValue( const Value &root ) { if ( !root.hasComment( commentBefore ) ) @@ -770,7 +770,7 @@ StyledStreamWriter::writeCommentBeforeValue( const Value &root ) } -void +void StyledStreamWriter::writeCommentAfterValueOnSameLine( const Value &root ) { if ( root.hasComment( commentAfterOnSameLine ) ) @@ -785,7 +785,7 @@ StyledStreamWriter::writeCommentAfterValueOnSameLine( const Value &root ) } -bool +bool StyledStreamWriter::hasCommentForValue( const Value &value ) { return value.hasComment( commentBefore ) @@ -794,7 +794,7 @@ StyledStreamWriter::hasCommentForValue( const Value &value ) } -std::string +std::string StyledStreamWriter::normalizeEOL( const std::string &text ) { std::string normalized; diff --git a/1_Mosaic_current/makefile b/1_Mosaic_current/makefile index 4111a77..0ed3ba0 100644 --- a/1_Mosaic_current/makefile +++ b/1_Mosaic_current/makefile @@ -18,8 +18,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_Mosaic_current/mos.cpp b/1_Mosaic_current/mos.cpp index 33e3214..f5eda29 100644 --- a/1_Mosaic_current/mos.cpp +++ b/1_Mosaic_current/mos.cpp @@ -36,34 +36,34 @@ using namespace std; class image; static void ReadInput_StrTags( - vector &images, - vector &x1, - vector &x2, - vector &y1, - vector &y2, - vector &z1, - vector &z2, - double &xmin, - double &xmax, - double &ymin, - double &ymax, - uint32 &w, - uint32 &h ); + vector &images, + vector &x1, + vector &x2, + vector &y1, + vector &y2, + vector &z1, + vector &z2, + double &xmin, + double &xmax, + double &ymin, + double &ymax, + uint32 &w, + uint32 &h ); static void ReadInput_NumTags( - vector &images, - vector &x1, - vector &x2, - vector &y1, - vector &y2, - vector &z1, - vector &z2, - double &xmin, - double &xmax, - double &ymin, - double &ymax, - uint32 &w, - uint32 &h ); + vector &images, + vector &x1, + vector &x2, + vector &y1, + vector &y2, + vector &z1, + vector &z2, + double &xmin, + double &xmax, + double &ymin, + double &ymax, + uint32 &w, + uint32 &h ); /* --------------------------------------------------------------- */ /* Types --------------------------------------------------------- */ @@ -71,73 +71,73 @@ static void ReadInput_NumTags( class glob_spot { public: - vector which; // which picture - vector patch; // which patch - vector where; // local coords - Point gpt; // point in global coords spawning these - double moved; // distance it moved + vector which; // which picture + vector patch; // which patch + vector where; // local coords + Point gpt; // point in global coords spawning these + double moved; // distance it moved }; class image { - friend void ReadInput_StrTags( - vector &images, - vector &x1, - vector &x2, - vector &y1, - vector &y2, - vector &z1, - vector &z2, - double &xmin, - double &xmax, - double &ymin, - double &ymax, - uint32 &w, - uint32 &h ); - - friend void ReadInput_NumTags( - vector &images, - vector &x1, - vector &x2, - vector &y1, - vector &y2, - vector &z1, - vector &z2, - double &xmin, - double &xmax, - double &ymin, - double &ymax, - uint32 &w, - uint32 &h ); + friend void ReadInput_StrTags( + vector &images, + vector &x1, + vector &x2, + vector &y1, + vector &y2, + vector &z1, + vector &z2, + double &xmin, + double &xmax, + double &ymin, + double &ymax, + uint32 &w, + uint32 &h ); + + friend void ReadInput_NumTags( + vector &images, + vector &x1, + vector &x2, + vector &y1, + vector &y2, + vector &z1, + vector &z2, + double &xmin, + double &xmax, + double &ymin, + double &ymax, + uint32 &w, + uint32 &h ); private: - char *rname; // raster filename - char *fname; // foldmap filename + char *rname; // raster filename + char *fname; // foldmap filename public: - uint8* raster; // gray scale image - uint8* foldmap; // fold map - uint8* bmap; // boundary map - uint32 w, h; - int layer; // layer number - int tile; // tile index - int FirstGlobalPoint; - int FirstTriangle; - int spbase; // should be added to all sp ids in this image, for uniqueness - char *spname; // super-pixel filename - char *bname; // boundary-map filename - uint16 *spmap; - vector SPmapping; // tells what original SP numbers are mapped to - vector tf; // image to global space, one for each patch (0 unused) - vector inv; // inverse transform - vector >sectors; // forward transform for each sector of each patch - vector >sinvs; // sector inverses - vector FoldmapRenumber; + uint8* raster; // gray scale image + uint8* foldmap; // fold map + uint8* bmap; // boundary map + uint32 w, h; + int layer; // layer number + int tile; // tile index + int FirstGlobalPoint; + int FirstTriangle; + int spbase; // should be added to all sp ids in this image, for uniqueness + char *spname; // super-pixel filename + char *bname; // boundary-map filename + uint16 *spmap; + vector SPmapping; // tells what original SP numbers are mapped to + vector tf; // image to global space, one for each patch (0 unused) + vector inv; // inverse transform + vector >sectors; // forward transform for each sector of each patch + vector >sinvs; // sector inverses + vector FoldmapRenumber; public: - const char* GetRName(); - const char* GetFName(); + const char* GetRName(); + const char* GetFName(); }; @@ -149,15 +149,15 @@ class image { // class Triple { public: - uint16 image; - uint8 patch; - uint8 sector; + uint16 image; + uint8 patch; + uint8 sector; public: - Triple() - : image(0), patch(0), sector(0) {}; + Triple() + : image(0), patch(0), sector(0) {}; - Triple( uint16 i, uint8 p, uint8 s ) - : image(i), patch(p), sector(s) {}; + Triple( uint16 i, uint8 p, uint8 s ) + : image(i), patch(p), sector(s) {}; }; /* --------------------------------------------------------------- */ @@ -167,61 +167,61 @@ class Triple { class CArgs_mos { public: - double DontMoveStrength; - const char *infile, - *fold_dir, - *region_dir, - *gray_dir, - *sp_dir, - *inv_dir, - *rav_dir, - *bmap_dir; - int scale, - x0, y0, xsize, ysize, - lspec1, lspec2; - bool debug, - strings, - warp, - foldmasks, - annotate, - make_tiles, - make_flat, - make_map, - matlab_order, - renumberSuperPixels; + double DontMoveStrength; + const char *infile, + *fold_dir, + *region_dir, + *gray_dir, + *sp_dir, + *inv_dir, + *rav_dir, + *bmap_dir; + int scale, + x0, y0, xsize, ysize, + lspec1, lspec2; + bool debug, + strings, + warp, + foldmasks, + annotate, + make_tiles, + make_flat, + make_map, + matlab_order, + renumberSuperPixels; public: - CArgs_mos() - { - DontMoveStrength = 0.01; - infile = NULL; - fold_dir = "."; // prepended fm loc - region_dir = "."; // where results go - gray_dir = "."; // where gray img go - sp_dir = "."; // where super-pixel maps go - inv_dir = "."; // where inv-map data go - rav_dir = "."; // where raveler tiles go - bmap_dir = "."; // where bndry maps go - scale = 1; // scale down by this - x0 = 0; // user's output origin - y0 = 0; - xsize = -1; // user's output size - ysize = -1; - lspec1 = -1; // user's layer range - lspec2 = -1; - debug = false; - strings = false; - warp = false; // seam healing - foldmasks = true; - annotate = false; - make_tiles = false; // for raveler - make_flat = true; // 'before' montages - make_map = true; // how img generated - matlab_order = false; // matlab or closeness order - renumberSuperPixels = true; - }; - - void SetCmdLine( int argc, char* argv[] ); + CArgs_mos() + { + DontMoveStrength = 0.01; + infile = NULL; + fold_dir = "."; // prepended fm loc + region_dir = "."; // where results go + gray_dir = "."; // where gray img go + sp_dir = "."; // where super-pixel maps go + inv_dir = "."; // where inv-map data go + rav_dir = "."; // where raveler tiles go + bmap_dir = "."; // where bndry maps go + scale = 1; // scale down by this + x0 = 0; // user's output origin + y0 = 0; + xsize = -1; // user's output size + ysize = -1; + lspec1 = -1; // user's layer range + lspec2 = -1; + debug = false; + strings = false; + warp = false; // seam healing + foldmasks = true; + annotate = false; + make_tiles = false; // for raveler + make_flat = true; // 'before' montages + make_map = true; // how img generated + matlab_order = false; // matlab or closeness order + renumberSuperPixels = true; + }; + + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -254,127 +254,127 @@ void CArgs_mos::SetCmdLine( int argc, char* argv[] ) { // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - printf( "Start: %s ", atime ); + printf( "Start: %s ", atime ); // parse command line args - if( argc < 2 ) { - printf( "Usage: mos " - " [xmin,ymin,dx,dy] [minlayer,maxlayer] [options].\n" ); - exit( 42 ); - } - - vector noa; - - for( int i = 1; i < argc; ++i ) { - - // echo to log - printf( "%s ", argv[i] ); - - if( argv[i][0] != '-' ) { - - if( !infile ) - infile = argv[i]; - else - noa.push_back( argv[i] ); - } - else if( GetArg( &DontMoveStrength, "-dms=%lf", argv[i] ) ) - ; - else if( GetArgStr( fold_dir, "-fold_dir=", argv[i] ) ) - ; - else if( GetArgStr( region_dir, "-region_dir=", argv[i] ) ) - ; - else if( GetArgStr( gray_dir, "-gray_dir=", argv[i] ) ) - ; - else if( GetArgStr( gray_dir, "-grey_dir=", argv[i] ) ) - ; - else if( GetArgStr( sp_dir, "-sp_dir=", argv[i] ) ) - ; - else if( GetArgStr( inv_dir, "-inv_dir=", argv[i] ) ) - ; - else if( GetArgStr( rav_dir, "-rav_dir=", argv[i] ) ) - ; - else if( GetArgStr( bmap_dir, "-bmap_dir=", argv[i] ) ) - ; - else if( GetArg( &scale, "-s=%d", argv[i] ) ) - ; - else if( IsArg( "-d", argv[i] ) ) - debug = true; - else if( IsArg( "-strings", argv[i] ) ) - strings = true; - else if( IsArg( "-warp", argv[i] ) ) - warp = true; - else if( IsArg( "-nf", argv[i] ) ) - foldmasks = false; - else if( IsArg( "-a", argv[i] ) ) - annotate = true; - else if( IsArg( "-tiles", argv[i] ) ) - make_tiles = true; - else if( IsArg( "-noflat", argv[i] ) ) - make_flat = false; - else if( IsArg( "-nomap", argv[i] ) ) - make_map = false; - else if( IsArg( "-matlab", argv[i] ) ) - matlab_order = true; - else if( IsArg( "-drn", argv[i] ) ) - renumberSuperPixels = false; - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - exit( 42 ); - } - } - - printf( "\n" ); - - if( warp ) - printf( "Don't move strength = %g\n", DontMoveStrength ); + if( argc < 2 ) { + printf( "Usage: mos " + " [xmin,ymin,dx,dy] [minlayer,maxlayer] [options].\n" ); + exit( 42 ); + } + + vector noa; + + for( int i = 1; i < argc; ++i ) { + + // echo to log + printf( "%s ", argv[i] ); + + if( argv[i][0] != '-' ) { + + if( !infile ) + infile = argv[i]; + else + noa.push_back( argv[i] ); + } + else if( GetArg( &DontMoveStrength, "-dms=%lf", argv[i] ) ) + ; + else if( GetArgStr( fold_dir, "-fold_dir=", argv[i] ) ) + ; + else if( GetArgStr( region_dir, "-region_dir=", argv[i] ) ) + ; + else if( GetArgStr( gray_dir, "-gray_dir=", argv[i] ) ) + ; + else if( GetArgStr( gray_dir, "-grey_dir=", argv[i] ) ) + ; + else if( GetArgStr( sp_dir, "-sp_dir=", argv[i] ) ) + ; + else if( GetArgStr( inv_dir, "-inv_dir=", argv[i] ) ) + ; + else if( GetArgStr( rav_dir, "-rav_dir=", argv[i] ) ) + ; + else if( GetArgStr( bmap_dir, "-bmap_dir=", argv[i] ) ) + ; + else if( GetArg( &scale, "-s=%d", argv[i] ) ) + ; + else if( IsArg( "-d", argv[i] ) ) + debug = true; + else if( IsArg( "-strings", argv[i] ) ) + strings = true; + else if( IsArg( "-warp", argv[i] ) ) + warp = true; + else if( IsArg( "-nf", argv[i] ) ) + foldmasks = false; + else if( IsArg( "-a", argv[i] ) ) + annotate = true; + else if( IsArg( "-tiles", argv[i] ) ) + make_tiles = true; + else if( IsArg( "-noflat", argv[i] ) ) + make_flat = false; + else if( IsArg( "-nomap", argv[i] ) ) + make_map = false; + else if( IsArg( "-matlab", argv[i] ) ) + matlab_order = true; + else if( IsArg( "-drn", argv[i] ) ) + renumberSuperPixels = false; + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + exit( 42 ); + } + } + + printf( "\n" ); + + if( warp ) + printf( "Don't move strength = %g\n", DontMoveStrength ); // user region - if( noa.size() ) { + if( noa.size() ) { - if( 4 != sscanf( noa[0], "%d,%d,%d,%d", - &x0, &y0, &xsize, &ysize ) ) { + if( 4 != sscanf( noa[0], "%d,%d,%d,%d", + &x0, &y0, &xsize, &ysize ) ) { - printf( "Expected [xmin,ymin,dx,dy], got [%s]\n", noa[0] ); - exit( 42 ); - } + printf( "Expected [xmin,ymin,dx,dy], got [%s]\n", noa[0] ); + exit( 42 ); + } - printf( "[0,0,dx,dy] = [%d, %d, %d, %d].\n", - x0, y0, xsize, ysize ); - } + printf( "[0,0,dx,dy] = [%d, %d, %d, %d].\n", + x0, y0, xsize, ysize ); + } // layer range - if( noa.size() > 1 ) { + if( noa.size() > 1 ) { - if( 2 != sscanf( noa[1], "%d,%d", &lspec1, &lspec2 ) ) { + if( 2 != sscanf( noa[1], "%d,%d", &lspec1, &lspec2 ) ) { - printf( "Expected [minlyr,maxlyr], got [%s]\n", noa[1] ); - exit( 42 ); - } + printf( "Expected [minlyr,maxlyr], got [%s]\n", noa[1] ); + exit( 42 ); + } - printf( "Layer range = [%d, %d].\n", lspec1, lspec2 ); - } + printf( "Layer range = [%d, %d].\n", lspec1, lspec2 ); + } // directories - printf( "Fold mask directory = '%s'\n", fold_dir ); - printf( "Region directory = '%s'\n", region_dir ); - printf( "Gray scale directory = '%s'\n", gray_dir ); - printf( "Super-pixel directory = '%s'\n", sp_dir ); - printf( "Inverse-map directory = '%s'\n", inv_dir ); - printf( "Raveler directory = '%s'\n", rav_dir ); - printf( "Boundary directory = '%s'\n", bmap_dir ); + printf( "Fold mask directory = '%s'\n", fold_dir ); + printf( "Region directory = '%s'\n", region_dir ); + printf( "Gray scale directory = '%s'\n", gray_dir ); + printf( "Super-pixel directory = '%s'\n", sp_dir ); + printf( "Inverse-map directory = '%s'\n", inv_dir ); + printf( "Raveler directory = '%s'\n", rav_dir ); + printf( "Boundary directory = '%s'\n", bmap_dir ); - printf( "\n" ); - fflush( stdout ); + printf( "\n" ); + fflush( stdout ); } /* --------------------------------------------------------------- */ @@ -383,17 +383,17 @@ void CArgs_mos::SetCmdLine( int argc, char* argv[] ) const char* image::GetRName() { - if( !rname ) { + if( !rname ) { - const Til2Img *I; + const Til2Img *I; - if( !IDBT2ICacheNGet1( I, idb, layer, tile ) ) - exit( 42 ); + if( !IDBT2ICacheNGet1( I, idb, layer, tile ) ) + exit( 42 ); - rname = strdup( I->path.c_str() ); - } + rname = strdup( I->path.c_str() ); + } - return rname; + return rname; } /* --------------------------------------------------------------- */ @@ -402,20 +402,20 @@ const char* image::GetRName() const char* image::GetFName() { - if( !fname ) { + if( !fname ) { - Til2FM I; + Til2FM I; - if( !IDBTil2FMD( I, idb, layer, tile ) && - !IDBTil2FM( I, idb, layer, tile ) ) { + if( !IDBTil2FMD( I, idb, layer, tile ) && + !IDBTil2FM( I, idb, layer, tile ) ) { - exit( 42 ); - } + exit( 42 ); + } - fname = strdup( I.path.c_str() ); - } + fname = strdup( I.path.c_str() ); + } - return fname; + return fname; } /* --------------------------------------------------------------- */ @@ -430,18 +430,18 @@ const char* image::GetFName() // 'nmrc_z_tile.png' and we decode the z from that. // static int FileNameToLayerNumber( - const vector &dnames, - const vector &lnums, - const char *fname ) + const vector &dnames, + const vector &lnums, + const char *fname ) { /* ----- */ /* nmrc? */ /* ----- */ - const char *s = FileNamePtr( fname ); + const char *s = FileNamePtr( fname ); - if( !strncmp( s, "nmrc_", 5 ) ) - return atoi( s + 5 ); + if( !strncmp( s, "nmrc_", 5 ) ) + return atoi( s + 5 ); /* ------------------ */ /* Otherwise use ldir */ @@ -450,7 +450,7 @@ static int FileNameToLayerNumber( int k; for(k=0; k= dnames.size() ) { printf("Oops - '%s' not in layer directory.\n", fname); exit( 42 ); @@ -485,312 +485,312 @@ return lnums[k]; // needed. // static void ReadInput_StrTags( - vector &images, - vector &x1, - vector &x2, - vector &y1, - vector &y2, - vector &z1, - vector &z2, - double &xmin, - double &xmax, - double &ymin, - double &ymax, - uint32 &w, - uint32 &h ) + vector &images, + vector &x1, + vector &x2, + vector &y1, + vector &y2, + vector &z1, + vector &z2, + double &xmin, + double &xmax, + double &ymin, + double &ymax, + uint32 &w, + uint32 &h ) { - vector dnames; // directory names - vector lnums; // parallel vector of layer numbers - map imap; // map of image names - FILE *fp = FileOpenOrDie( gArgs.infile, "r" ); - CLineScan LS; + vector dnames; // directory names + vector lnums; // parallel vector of layer numbers + map imap; // map of image names + FILE *fp = FileOpenOrDie( gArgs.infile, "r" ); + CLineScan LS; - for(;;) { + for(;;) { - if( LS.Get( fp ) <= 0 ) - break; + if( LS.Get( fp ) <= 0 ) + break; - if( !strncmp( LS.line, "MPOINTS", 7 ) ) { + if( !strncmp( LS.line, "MPOINTS", 7 ) ) { - double a, b, c, d; - int za, zc; + double a, b, c, d; + int za, zc; - if( 6 != sscanf( LS.line + 8, - "%d %lf %lf %d %lf %lf", - &za, &a, &b, &zc, &c, &d ) ) { + if( 6 != sscanf( LS.line + 8, + "%d %lf %lf %d %lf %lf", + &za, &a, &b, &zc, &c, &d ) ) { - printf( "Bad MPOINTS statement '%s'.", LS.line ); - exit( 42 ); - } + printf( "Bad MPOINTS statement '%s'.", LS.line ); + exit( 42 ); + } - if( gArgs.lspec1 < 0 || - (gArgs.lspec1-1 <= za && za <= gArgs.lspec2+1) || - (gArgs.lspec1-1 <= zc && zc <= gArgs.lspec2+1) ) { + if( gArgs.lspec1 < 0 || + (gArgs.lspec1-1 <= za && za <= gArgs.lspec2+1) || + (gArgs.lspec1-1 <= zc && zc <= gArgs.lspec2+1) ) { - z1.push_back( za ); - x1.push_back( a/gArgs.scale ); - y1.push_back( b/gArgs.scale ); + z1.push_back( za ); + x1.push_back( a/gArgs.scale ); + y1.push_back( b/gArgs.scale ); - z2.push_back( zc ); - x2.push_back( c/gArgs.scale ); - y2.push_back( d/gArgs.scale ); - } - } - else if( !strncmp( LS.line, "TRANSFORM", 9 ) ) { + z2.push_back( zc ); + x2.push_back( c/gArgs.scale ); + y2.push_back( d/gArgs.scale ); + } + } + else if( !strncmp( LS.line, "TRANSFORM", 9 ) ) { - char name[2048]; - double a, b, c, d, e, f; - int nprm; + char name[2048]; + double a, b, c, d, e, f; + int nprm; - // newer format has '' delimited name - // older just space separated + // newer format has '' delimited name + // older just space separated - if( LS.line[10] == '\'' ) { - nprm = sscanf( - LS.line + 10, "'%[^']' %lf %lf %lf %lf %lf %lf", - name, &a, &b, &c, &d, &e, &f ); - } - else { - nprm = sscanf( - LS.line + 10, "%s %lf %lf %lf %lf %lf %lf", - name, &a, &b, &c, &d, &e, &f ); - } + if( LS.line[10] == '\'' ) { + nprm = sscanf( + LS.line + 10, "'%[^']' %lf %lf %lf %lf %lf %lf", + name, &a, &b, &c, &d, &e, &f ); + } + else { + nprm = sscanf( + LS.line + 10, "%s %lf %lf %lf %lf %lf %lf", + name, &a, &b, &c, &d, &e, &f ); + } - if( 7 != nprm ) { - printf( "Bad TRANSFORM statement '%s'.", LS.line ); - exit( 42 ); - } + if( 7 != nprm ) { + printf( "Bad TRANSFORM statement '%s'.", LS.line ); + exit( 42 ); + } - TAffine tf( a, b, c/gArgs.scale, d, e, f/gArgs.scale ); - char *fname = strtok( name, " ':" ); + TAffine tf( a, b, c/gArgs.scale, d, e, f/gArgs.scale ); + char *fname = strtok( name, " ':" ); - //printf("File '%s'\n", fname); + //printf("File '%s'\n", fname); - map::iterator imit = imap.find(string(fname)); + map::iterator imit = imap.find(string(fname)); - if( imit == imap.end() ) { + if( imit == imap.end() ) { - // This is normal with single layer image generation. + // This is normal with single layer image generation. - //printf( "File in TRANSFORM has no FOLDMAP - ignored.\n" ); - continue; - } + //printf( "File in TRANSFORM has no FOLDMAP - ignored.\n" ); + continue; + } - int k = imit->second; + int k = imit->second; - // get the rest of the string, now of the form ::123 - int patch = atoi( strtok( NULL, " :'\n" ) ); + // get the rest of the string, now of the form ::123 + int patch = atoi( strtok( NULL, " :'\n" ) ); - printf( "ImageIdx::patch = %d::%d\n", k, patch ); + printf( "ImageIdx::patch = %d::%d\n", k, patch ); - // Make new slot? - if( images[k].tf.size() <= patch ) { + // Make new slot? + if( images[k].tf.size() <= patch ) { - // initialize to an illegal transform - images[k].tf.resize( patch+1, TAffine(0,0,0,0,0,0) ); - images[k].inv.resize( patch+1 ); - } + // initialize to an illegal transform + images[k].tf.resize( patch+1, TAffine(0,0,0,0,0,0) ); + images[k].inv.resize( patch+1 ); + } - images[k].tf[patch] = tf; - } - else if( !strncmp( LS.line, "FOLDMAP", 7 ) ) { + images[k].tf[patch] = tf; + } + else if( !strncmp( LS.line, "FOLDMAP", 7 ) ) { - char *tname = strtok( LS.line + 8, " '\n" ); - char *mname = strtok( NULL, " '\n" ); + char *tname = strtok( LS.line + 8, " '\n" ); + char *mname = strtok( NULL, " '\n" ); - if( !tname || !mname ) { - printf( "Bad FOLDMAP statement '%s'.", LS.line ); - exit( 42 ); - } + if( !tname || !mname ) { + printf( "Bad FOLDMAP statement '%s'.", LS.line ); + exit( 42 ); + } - map::iterator it = imap.find(string(tname)); + map::iterator it = imap.find(string(tname)); - if( it != imap.end() ) - continue; // already seen this one + if( it != imap.end() ) + continue; // already seen this one - // Get image dimensions - if( !w ) { - uint8 *r = Raster8FromAny( tname, w, h ); - RasterFree( r ); - w /= gArgs.scale; - h /= gArgs.scale; - } + // Get image dimensions + if( !w ) { + uint8 *r = Raster8FromAny( tname, w, h ); + RasterFree( r ); + w /= gArgs.scale; + h /= gArgs.scale; + } - image ii; + image ii; - ii.raster = NULL; - ii.foldmap = NULL; - ii.bmap = NULL; - ii.w = w; - ii.h = h; - ii.spbase = 0; - ii.rname = strdup( tname ); - ii.fname = strdup( mname ); - ii.spname = NULL; - ii.bname = NULL; - ii.spmap = NULL; + ii.raster = NULL; + ii.foldmap = NULL; + ii.bmap = NULL; + ii.w = w; + ii.h = h; + ii.spbase = 0; + ii.rname = strdup( tname ); + ii.fname = strdup( mname ); + ii.spname = NULL; + ii.bname = NULL; + ii.spmap = NULL; - ZIDFromFMPath( ii.layer, ii.tile, mname ); + ZIDFromFMPath( ii.layer, ii.tile, mname ); - if( gArgs.lspec1 < 0 || - (gArgs.lspec1 <= ii.layer && ii.layer <= gArgs.lspec2) ) { + if( gArgs.lspec1 < 0 || + (gArgs.lspec1 <= ii.layer && ii.layer <= gArgs.lspec2) ) { - // Point at drawing (d-suffixed) foldmap if exists + // Point at drawing (d-suffixed) foldmap if exists - char *suf = strstr( mname, ".tif" ); + char *suf = strstr( mname, ".tif" ); - if( suf ) { + if( suf ) { - char buf[2048]; + char buf[2048]; - sprintf( buf, "%.*sd.tif", - int(suf - mname), mname ); + sprintf( buf, "%.*sd.tif", + int(suf - mname), mname ); - if( DskExists( buf ) ) { - printf( "Using drawing file '%s'.\n", buf ); - free( ii.fname ); - ii.fname = strdup( buf ); - } - } + if( DskExists( buf ) ) { + printf( "Using drawing file '%s'.\n", buf ); + free( ii.fname ); + ii.fname = strdup( buf ); + } + } - // Finally, add to collection - imap[string(tname)] = images.size(); - images.push_back( ii ); - } - } - else if( !strncmp( LS.line, "SPMAP", 5 ) ) { + // Finally, add to collection + imap[string(tname)] = images.size(); + images.push_back( ii ); + } + } + else if( !strncmp( LS.line, "SPMAP", 5 ) ) { - char name[2048], where[2048]; - int z, nprm; + char name[2048], where[2048]; + int z, nprm; - nprm = sscanf( LS.line + 6, "%s %s %d", name, where, &z ); + nprm = sscanf( LS.line + 6, "%s %s %d", name, where, &z ); - if( nprm < 2 ) { - printf( "Bad SPMAP statement '%s'.", LS.line ); - exit( 42 ); - } + if( nprm < 2 ) { + printf( "Bad SPMAP statement '%s'.", LS.line ); + exit( 42 ); + } - char *fname = strtok( name, " ':" ); + char *fname = strtok( name, " ':" ); - //printf("File '%s'\n", fname); + //printf("File '%s'\n", fname); - map::iterator imit = imap.find(string(fname)); + map::iterator imit = imap.find(string(fname)); - if( imit == imap.end() ) { + if( imit == imap.end() ) { - // This is normal with single layer image generation. - // If it's a layer we care about, print a message. - // Otherwise silently ignore. + // This is normal with single layer image generation. + // If it's a layer we care about, print a message. + // Otherwise silently ignore. - int layer; + int layer; - if( nprm > 2 ) - layer = z; - else - layer = FileNameToLayerNumber( dnames, lnums, fname ); + if( nprm > 2 ) + layer = z; + else + layer = FileNameToLayerNumber( dnames, lnums, fname ); - if( gArgs.lspec1 < 0 || - (gArgs.lspec1 <= layer && layer <= gArgs.lspec2) ) { + if( gArgs.lspec1 < 0 || + (gArgs.lspec1 <= layer && layer <= gArgs.lspec2) ) { - printf( - "File in SPMAP has no image - ignored.\n" ); - } + printf( + "File in SPMAP has no image - ignored.\n" ); + } - continue; - } + continue; + } - int k = imit->second; + int k = imit->second; - printf( "ImageIdx = %d\n", k ); - images[k].spname = strdup( where ); - } - else if( !strncmp( LS.line, "BOUNDARYMAP", 11 ) ) { + printf( "ImageIdx = %d\n", k ); + images[k].spname = strdup( where ); + } + else if( !strncmp( LS.line, "BOUNDARYMAP", 11 ) ) { - char name[2048], where[2048]; - int z, nprm; + char name[2048], where[2048]; + int z, nprm; - nprm = sscanf( LS.line + 12, "%s %s %d", name, where, &z ); + nprm = sscanf( LS.line + 12, "%s %s %d", name, where, &z ); - if( nprm < 2 ) { - printf( "Bad BOUNDARYMAP statement '%s'.", LS.line ); - exit( 42 ); - } + if( nprm < 2 ) { + printf( "Bad BOUNDARYMAP statement '%s'.", LS.line ); + exit( 42 ); + } - char *fname = strtok( name, " ':" ); + char *fname = strtok( name, " ':" ); - //printf("File '%s'\n", fname); + //printf("File '%s'\n", fname); - map::iterator imit = imap.find(string(fname)); + map::iterator imit = imap.find(string(fname)); - if( imit == imap.end() ) { + if( imit == imap.end() ) { - // This is normal with single layer image generation. - // If it's a layer we care about, print a message. - // Otherwise silently ignore. + // This is normal with single layer image generation. + // If it's a layer we care about, print a message. + // Otherwise silently ignore. - int layer; + int layer; - if( nprm > 2 ) - layer = z; - else - layer = FileNameToLayerNumber( dnames, lnums, fname ); + if( nprm > 2 ) + layer = z; + else + layer = FileNameToLayerNumber( dnames, lnums, fname ); - if( gArgs.lspec1 < 0 || - (gArgs.lspec1 <= layer && layer <= gArgs.lspec2) ) { + if( gArgs.lspec1 < 0 || + (gArgs.lspec1 <= layer && layer <= gArgs.lspec2) ) { - printf( - "File in BOUNDARYMAP has no image - ignored.\n" ); - } + printf( + "File in BOUNDARYMAP has no image - ignored.\n" ); + } - continue; - } + continue; + } - int k = imit->second; + int k = imit->second; - printf( "ImageIdx = %d\n", k ); - images[k].bname = strdup( where ); - } - else if( !strncmp( LS.line, "DIR", 3 ) ) { + printf( "ImageIdx = %d\n", k ); + images[k].bname = strdup( where ); + } + else if( !strncmp( LS.line, "DIR", 3 ) ) { - // parallel vectors - char *z = strtok( LS.line + 4, " " ); - char *n = strtok( NULL, " \n" ); + // parallel vectors + char *z = strtok( LS.line + 4, " " ); + char *n = strtok( NULL, " \n" ); - lnums.push_back( atoi( z ) ); - dnames.push_back( strdup( n ) ); - } - else if( !strncmp( LS.line, "IMAGESIZE", 9 ) ) { + lnums.push_back( atoi( z ) ); + dnames.push_back( strdup( n ) ); + } + else if( !strncmp( LS.line, "IMAGESIZE", 9 ) ) { - if( 2 != sscanf( LS.line + 10, "%d %d", &w, &h ) ) { + if( 2 != sscanf( LS.line + 10, "%d %d", &w, &h ) ) { - printf( "Bad IMAGESIZE line '%s'.\n", LS.line ); - exit( 42 ); - } + printf( "Bad IMAGESIZE line '%s'.\n", LS.line ); + exit( 42 ); + } - w /= gArgs.scale; - h /= gArgs.scale; - } - else if( !strncmp( LS.line, "BBOX", 4 ) ) { + w /= gArgs.scale; + h /= gArgs.scale; + } + else if( !strncmp( LS.line, "BBOX", 4 ) ) { - if( 4 != sscanf( LS.line + 5, - "%lf %lf %lf %lf", &xmin, &ymin, &xmax, &ymax ) ) { + if( 4 != sscanf( LS.line + 5, + "%lf %lf %lf %lf", &xmin, &ymin, &xmax, &ymax ) ) { - printf( "Bad BBOX statement '%s'.\n", LS.line ); - exit( 42 ); - } + printf( "Bad BBOX statement '%s'.\n", LS.line ); + exit( 42 ); + } - xmin /= gArgs.scale; - ymin /= gArgs.scale; - xmax /= gArgs.scale; - ymax /= gArgs.scale; - } - else { - printf( "Unknown line '%s'.", LS.line ); - exit( 42 ); - } - } + xmin /= gArgs.scale; + ymin /= gArgs.scale; + xmax /= gArgs.scale; + ymax /= gArgs.scale; + } + else { + printf( "Unknown line '%s'.", LS.line ); + exit( 42 ); + } + } - fclose( fp ); + fclose( fp ); } /* --------------------------------------------------------------- */ @@ -801,15 +801,15 @@ static void ReadInput_StrTags( class ZID { public: - int z, id; + int z, id; public: - ZID( int z, int id ) : z(z), id(id) {}; + ZID( int z, int id ) : z(z), id(id) {}; - bool operator < ( const ZID &rhs ) const - {return z < rhs.z || (z == rhs.z && id < rhs.id);}; + bool operator < ( const ZID &rhs ) const + {return z < rhs.z || (z == rhs.z && id < rhs.id);}; - bool operator == ( const ZID &rhs ) const - {return z == rhs.z && id == rhs.id;}; + bool operator == ( const ZID &rhs ) const + {return z == rhs.z && id == rhs.id;}; }; @@ -835,207 +835,207 @@ class ZID { // to look up paths when needed. // static void ReadInput_NumTags( - vector &images, - vector &x1, - vector &x2, - vector &y1, - vector &y2, - vector &z1, - vector &z2, - double &xmin, - double &xmax, - double &ymin, - double &ymax, - uint32 &w, - uint32 &h ) + vector &images, + vector &x1, + vector &x2, + vector &y1, + vector &y2, + vector &z1, + vector &z2, + double &xmin, + double &xmax, + double &ymin, + double &ymax, + uint32 &w, + uint32 &h ) { - map imap; // map of image names - FILE *fp = FileOpenOrDie( gArgs.infile, "r" ); - CLineScan LS; + map imap; // map of image names + FILE *fp = FileOpenOrDie( gArgs.infile, "r" ); + CLineScan LS; - for(;;) { + for(;;) { - char strbuf[2048]; + char strbuf[2048]; - if( LS.Get( fp ) <= 0 ) - break; + if( LS.Get( fp ) <= 0 ) + break; - if( !strncmp( LS.line, "MPOINTS", 7 ) ) { + if( !strncmp( LS.line, "MPOINTS", 7 ) ) { - double a, b, c, d; - int za, zc; + double a, b, c, d; + int za, zc; - if( 6 != sscanf( LS.line + 8, - "%d %lf %lf %d %lf %lf", - &za, &a, &b, &zc, &c, &d ) ) { + if( 6 != sscanf( LS.line + 8, + "%d %lf %lf %d %lf %lf", + &za, &a, &b, &zc, &c, &d ) ) { - printf( "Bad MPOINTS statement '%s'.", LS.line ); - exit( 42 ); - } + printf( "Bad MPOINTS statement '%s'.", LS.line ); + exit( 42 ); + } - if( gArgs.lspec1 < 0 || - (gArgs.lspec1-1 <= za && za <= gArgs.lspec2+1) || - (gArgs.lspec1-1 <= zc && zc <= gArgs.lspec2+1) ) { + if( gArgs.lspec1 < 0 || + (gArgs.lspec1-1 <= za && za <= gArgs.lspec2+1) || + (gArgs.lspec1-1 <= zc && zc <= gArgs.lspec2+1) ) { - z1.push_back( za ); - x1.push_back( a/gArgs.scale ); - y1.push_back( b/gArgs.scale ); + z1.push_back( za ); + x1.push_back( a/gArgs.scale ); + y1.push_back( b/gArgs.scale ); - z2.push_back( zc ); - x2.push_back( c/gArgs.scale ); - y2.push_back( d/gArgs.scale ); - } - } - else if( !strncmp( LS.line, "TAFFINE", 10 ) ) { + z2.push_back( zc ); + x2.push_back( c/gArgs.scale ); + y2.push_back( d/gArgs.scale ); + } + } + else if( !strncmp( LS.line, "TAFFINE", 10 ) ) { - double a, b, c, d, e, f; - int z, id, rgn; + double a, b, c, d, e, f; + int z, id, rgn; - if( 9 != sscanf( LS.line + 11, - "%d.%d-%d %lf %lf %lf %lf %lf %lf", - &z, &id, &rgn, &a, &b, &c, &d, &e, &f ) ) { + if( 9 != sscanf( LS.line + 11, + "%d.%d-%d %lf %lf %lf %lf %lf %lf", + &z, &id, &rgn, &a, &b, &c, &d, &e, &f ) ) { - printf( "Bad TAFFINE statement '%s'.", LS.line ); - exit( 42 ); - } + printf( "Bad TAFFINE statement '%s'.", LS.line ); + exit( 42 ); + } - if( gArgs.lspec1 >= 0 && - (z < gArgs.lspec1 || gArgs.lspec2 < z) ) { + if( gArgs.lspec1 >= 0 && + (z < gArgs.lspec1 || gArgs.lspec2 < z) ) { - continue; - } + continue; + } - TAffine tf( a, b, c/gArgs.scale, d, e, f/gArgs.scale ); - ZID zid( z, id ); - int k; + TAffine tf( a, b, c/gArgs.scale, d, e, f/gArgs.scale ); + ZID zid( z, id ); + int k; - // get the image entry + // get the image entry - map::iterator it = imap.find( zid ); + map::iterator it = imap.find( zid ); - if( it == imap.end() ) { + if( it == imap.end() ) { - image ii; + image ii; - ii.rname = NULL; - ii.fname = NULL; - ii.raster = NULL; - ii.foldmap = NULL; - ii.bmap = NULL; - ii.w = w; - ii.h = h; - ii.layer = z; - ii.tile = id; - ii.spbase = 0; - ii.spname = NULL; - ii.bname = NULL; - ii.spmap = NULL; + ii.rname = NULL; + ii.fname = NULL; + ii.raster = NULL; + ii.foldmap = NULL; + ii.bmap = NULL; + ii.w = w; + ii.h = h; + ii.layer = z; + ii.tile = id; + ii.spbase = 0; + ii.spname = NULL; + ii.bname = NULL; + ii.spmap = NULL; - imap[zid] = k = images.size(); - images.push_back( ii ); - } - else - k = it->second; + imap[zid] = k = images.size(); + images.push_back( ii ); + } + else + k = it->second; - // adjust TForm storage + // adjust TForm storage - if( images[k].tf.size() <= rgn ) { + if( images[k].tf.size() <= rgn ) { - // initialize to an illegal transform - images[k].tf.resize( rgn+1, TAffine(0,0,0,0,0,0) ); - images[k].inv.resize( rgn+1 ); - } + // initialize to an illegal transform + images[k].tf.resize( rgn+1, TAffine(0,0,0,0,0,0) ); + images[k].inv.resize( rgn+1 ); + } - images[k].tf[rgn] = tf; - } - else if( !strncmp( LS.line, "SPMAP2", 5 ) ) { + images[k].tf[rgn] = tf; + } + else if( !strncmp( LS.line, "SPMAP2", 5 ) ) { - char strbuf[2048]; - int z, id; + char strbuf[2048]; + int z, id; - if( 3 != sscanf( LS.line + 6, - "%d.%d %s", &z, &id, strbuf ) ) { + if( 3 != sscanf( LS.line + 6, + "%d.%d %s", &z, &id, strbuf ) ) { - printf( "Bad SPMAP2 statement '%s'.", LS.line ); - exit( 42 ); - } + printf( "Bad SPMAP2 statement '%s'.", LS.line ); + exit( 42 ); + } - if( gArgs.lspec1 >= 0 && - (z < gArgs.lspec1 || gArgs.lspec2 < z) ) { + if( gArgs.lspec1 >= 0 && + (z < gArgs.lspec1 || gArgs.lspec2 < z) ) { - continue; - } + continue; + } - map::iterator it = imap.find( ZID( z, id ) ); + map::iterator it = imap.find( ZID( z, id ) ); - if( it != imap.end() ) - images[it->second].spname = strdup( strbuf ); - } - else if( !strncmp( LS.line, "BOUNDARYMAP2", 12 ) ) { + if( it != imap.end() ) + images[it->second].spname = strdup( strbuf ); + } + else if( !strncmp( LS.line, "BOUNDARYMAP2", 12 ) ) { - char strbuf[2048]; - int z, id; + char strbuf[2048]; + int z, id; - if( 3 != sscanf( LS.line + 6, - "%d.%d %s", &z, &id, strbuf ) ) { + if( 3 != sscanf( LS.line + 6, + "%d.%d %s", &z, &id, strbuf ) ) { - printf( "Bad BOUNDARYMAP2 statement '%s'.", LS.line ); - exit( 42 ); - } + printf( "Bad BOUNDARYMAP2 statement '%s'.", LS.line ); + exit( 42 ); + } - if( gArgs.lspec1 >= 0 && - (z < gArgs.lspec1 || gArgs.lspec2 < z) ) { + if( gArgs.lspec1 >= 0 && + (z < gArgs.lspec1 || gArgs.lspec2 < z) ) { - continue; - } + continue; + } - map::iterator it = imap.find( ZID( z, id ) ); + map::iterator it = imap.find( ZID( z, id ) ); - if( it != imap.end() ) - images[it->second].bname = strdup( strbuf ); - } - else if( !strncmp( LS.line, "IDBPATH", 7 ) ) { + if( it != imap.end() ) + images[it->second].bname = strdup( strbuf ); + } + else if( !strncmp( LS.line, "IDBPATH", 7 ) ) { - if( !sscanf( LS.line + 8, "%s", strbuf ) ) { + if( !sscanf( LS.line + 8, "%s", strbuf ) ) { - printf( "Bad IDBPATH line '%s'.\n", LS.line ); - exit( 42 ); - } + printf( "Bad IDBPATH line '%s'.\n", LS.line ); + exit( 42 ); + } - idb = strbuf; - } - else if( !strncmp( LS.line, "IMAGESIZE", 9 ) ) { + idb = strbuf; + } + else if( !strncmp( LS.line, "IMAGESIZE", 9 ) ) { - if( 2 != sscanf( LS.line + 10, "%d %d", &w, &h ) ) { + if( 2 != sscanf( LS.line + 10, "%d %d", &w, &h ) ) { - printf( "Bad IMAGESIZE line '%s'.\n", LS.line ); - exit( 42 ); - } + printf( "Bad IMAGESIZE line '%s'.\n", LS.line ); + exit( 42 ); + } - w /= gArgs.scale; - h /= gArgs.scale; - } - else if( !strncmp( LS.line, "BBOX", 4 ) ) { + w /= gArgs.scale; + h /= gArgs.scale; + } + else if( !strncmp( LS.line, "BBOX", 4 ) ) { - if( 4 != sscanf( LS.line + 5, - "%lf %lf %lf %lf", &xmin, &ymin, &xmax, &ymax ) ) { + if( 4 != sscanf( LS.line + 5, + "%lf %lf %lf %lf", &xmin, &ymin, &xmax, &ymax ) ) { - printf( "Bad BBOX statement '%s'.\n", LS.line ); - exit( 42 ); - } + printf( "Bad BBOX statement '%s'.\n", LS.line ); + exit( 42 ); + } - xmin /= gArgs.scale; - ymin /= gArgs.scale; - xmax /= gArgs.scale; - ymax /= gArgs.scale; - } - else { - printf( "Unknown line '%s'.", LS.line ); - exit( 42 ); - } - } + xmin /= gArgs.scale; + ymin /= gArgs.scale; + xmax /= gArgs.scale; + ymax /= gArgs.scale; + } + else { + printf( "Unknown line '%s'.", LS.line ); + exit( 42 ); + } + } - fclose( fp ); + fclose( fp ); } /* --------------------------------------------------------------- */ @@ -1044,19 +1044,19 @@ static void ReadInput_NumTags( static void PrintTransAndInv( FILE *of, const TAffine &tr ) { - TAffine in; + TAffine in; - in.InverseOf( tr ); + in.InverseOf( tr ); - fprintf( of, - "Fwd:%11.8f %11.8f %10.4f %11.8f %11.8f %10.4f\n", - tr.t[0], tr.t[1], tr.t[2], - tr.t[3], tr.t[4], tr.t[5] ); + fprintf( of, + "Fwd:%11.8f %11.8f %10.4f %11.8f %11.8f %10.4f\n", + tr.t[0], tr.t[1], tr.t[2], + tr.t[3], tr.t[4], tr.t[5] ); - fprintf( of, - "Rev:%11.8f %11.8f %10.4f %11.8f %11.8f %10.4f\n", - in.t[0], in.t[1], in.t[2], - in.t[3], in.t[4], in.t[5] ); + fprintf( of, + "Rev:%11.8f %11.8f %10.4f %11.8f %11.8f %10.4f\n", + in.t[0], in.t[1], in.t[2], + in.t[3], in.t[4], in.t[5] ); } /* --------------------------------------------------------------- */ @@ -1066,51 +1066,51 @@ static void PrintTransAndInv( FILE *of, const TAffine &tr ) // Find bounding box in global space. // static void GlobalBounds( - double &xmin, - double &xmax, - double &ymin, - double &ymax, - const vector &images, - int w, - int h ) + double &xmin, + double &xmax, + double &ymin, + double &ymax, + const vector &images, + int w, + int h ) { - if( xmin > BIG/2 ) { + if( xmin > BIG/2 ) { - int ni = images.size(); + int ni = images.size(); - for( int i = 0; i < ni; ++i ) { + for( int i = 0; i < ni; ++i ) { - int nt = images[i].tf.size(); + int nt = images[i].tf.size(); - for( int k = 1; k < nt; ++k ) { + for( int k = 1; k < nt; ++k ) { - const TAffine& T = images[i].tf[k]; + const TAffine& T = images[i].tf[k]; - if( !T.det() ) - continue; + if( !T.det() ) + continue; - vector pts; + vector pts; - pts.push_back( Point( 0.0, 0.0 ) ); - pts.push_back( Point( w-1, 0.0 ) ); - pts.push_back( Point( w-1, h-1 ) ); - pts.push_back( Point( 0.0, h-1 ) ); + pts.push_back( Point( 0.0, 0.0 ) ); + pts.push_back( Point( w-1, 0.0 ) ); + pts.push_back( Point( w-1, h-1 ) ); + pts.push_back( Point( 0.0, h-1 ) ); - for( int j = 0; j < 4; ++j ) { + for( int j = 0; j < 4; ++j ) { - T.Transform( pts[j] ); + T.Transform( pts[j] ); - xmin = fmin( xmin, pts[j].x ); - xmax = fmax( xmax, pts[j].x ); - ymin = fmin( ymin, pts[j].y ); - ymax = fmax( ymax, pts[j].y ); - } - } - } - } + xmin = fmin( xmin, pts[j].x ); + xmax = fmax( xmax, pts[j].x ); + ymin = fmin( ymin, pts[j].y ); + ymax = fmax( ymax, pts[j].y ); + } + } + } + } - printf( "Bounds of global image: x=[%f %f] y=[%f %f].\n", - xmin, xmax, ymin, ymax ); + printf( "Bounds of global image: x=[%f %f] y=[%f %f].\n", + xmin, xmax, ymin, ymax ); } /* --------------------------------------------------------------- */ @@ -1124,92 +1124,92 @@ static void GlobalBounds( // alignment easier. // static void OffsetCoords( - double &xmin, - double &xmax, - double &ymin, - double &ymax, - vector &images, - vector &x1, - vector &x2, - vector &y1, - vector &y2 ) + double &xmin, + double &xmax, + double &ymin, + double &ymax, + vector &images, + vector &x1, + vector &x2, + vector &y1, + vector &y2 ) { - int xfl = int(floor( xmin )); - int yfl = int(floor( ymin )); + int xfl = int(floor( xmin )); + int yfl = int(floor( ymin )); // bounds - xmin -= xfl; - xmax -= xfl; - ymin -= yfl; - ymax -= yfl; + xmin -= xfl; + xmax -= xfl; + ymin -= yfl; + ymax -= yfl; - printf( "Bounds of global image: x=[%f %f] y=[%f %f].\n", - xmin, xmax, ymin, ymax ); + printf( "Bounds of global image: x=[%f %f] y=[%f %f].\n", + xmin, xmax, ymin, ymax ); - if( gArgs.xsize != -1 ) { - xmax = gArgs.xsize; - ymax = gArgs.ysize; - } + if( gArgs.xsize != -1 ) { + xmax = gArgs.xsize; + ymax = gArgs.ysize; + } // transforms - xfl = -(xfl + gArgs.x0); - yfl = -(yfl + gArgs.y0); + xfl = -(xfl + gArgs.x0); + yfl = -(yfl + gArgs.y0); - int ni = images.size(); + int ni = images.size(); - for( int i = 0; i < ni; ++i ) { + for( int i = 0; i < ni; ++i ) { - int nt = images[i].tf.size(); + int nt = images[i].tf.size(); - for( int k = 1; k < nt; ++k ) { + for( int k = 1; k < nt; ++k ) { - TAffine& T = images[i].tf[k]; + TAffine& T = images[i].tf[k]; - if( !T.det() ) - continue; + if( !T.det() ) + continue; - T.AddXY( xfl, yfl ); - images[i].inv[k].InverseOf( T ); - } - } + T.AddXY( xfl, yfl ); + images[i].inv[k].InverseOf( T ); + } + } // debugging - print transforms #if 0 - for( int i = 0; i < ni; ++i ) { + for( int i = 0; i < ni; ++i ) { - int nt = images[i].tf.size(); + int nt = images[i].tf.size(); - for( int k = 1; k < nt; ++k ) { + for( int k = 1; k < nt; ++k ) { - const TAffine& T = images[i].tf[k]; + const TAffine& T = images[i].tf[k]; - if( !T.det() ) - continue; + if( !T.det() ) + continue; - printf( - "Post offset: image %d, layer %d tf[%d]" - " = %f %f %f %f %f %f\n", - i, images[i].layer, k, - T.t[0], T.t[1], T.t[2], - T.t[3], T.t[4], T.t[5] ); - } - } + printf( + "Post offset: image %d, layer %d tf[%d]" + " = %f %f %f %f %f %f\n", + i, images[i].layer, k, + T.t[0], T.t[1], T.t[2], + T.t[3], T.t[4], T.t[5] ); + } + } #endif // correspondence points - int n = x1.size(); + int n = x1.size(); - for( int i = 0; i < n; ++i ) { + for( int i = 0; i < n; ++i ) { - x1[i] += xfl; - x2[i] += xfl; - y1[i] += yfl; - y2[i] += yfl; - } + x1[i] += xfl; + x2[i] += xfl; + y1[i] += yfl; + y2[i] += yfl; + } } /* --------------------------------------------------------------- */ @@ -1218,31 +1218,31 @@ static void OffsetCoords( static uint8* LoadNormImg( const char *name, uint32 &w, uint32 &h ) { - uint8* ras = Raster8FromAny( name, w, h ); + uint8* ras = Raster8FromAny( name, w, h ); - if( !strstr( name, ".mrc" ) ) { + if( !strstr( name, ".mrc" ) ) { - double mean, std; - int np = w * h; - MeanStd m; + double mean, std; + int np = w * h; + MeanStd m; - for( int i = 0; i < np; ++i ) - m.Element( double(ras[i]) ); + for( int i = 0; i < np; ++i ) + m.Element( double(ras[i]) ); - m.Stats( mean, std ); + m.Stats( mean, std ); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - int pix = RND( 127 + (ras[i] - mean) / std * 30.0 ); + int pix = RND( 127 + (ras[i] - mean) / std * 30.0 ); - if( pix > 255 ) - pix = 255; + if( pix > 255 ) + pix = 255; - ras[i] = pix; - } - } + ras[i] = pix; + } + } - return ras; + return ras; } /* --------------------------------------------------------------- */ @@ -1251,14 +1251,14 @@ static uint8* LoadNormImg( const char *name, uint32 &w, uint32 &h ) static void PrintMagnitude( const vector &X ) { - int k = X.size() - 6; + int k = X.size() - 6; - if( k >= 0 ) { + if( k >= 0 ) { - double mag = sqrt( X[k]*X[k] + X[k+1]*X[k+1] ); + double mag = sqrt( X[k]*X[k] + X[k+1]*X[k+1] ); - printf( "Final magnitude is %g\n", mag ); - } + printf( "Final magnitude is %g\n", mag ); + } } /* --------------------------------------------------------------- */ @@ -1269,7 +1269,7 @@ static void PrintMagnitude( const vector &X ) // static bool lr( int sx, int sy, void *arg ) { - return sx == 21 && sy == 21; + return sx == 21 && sy == 21; } /* --------------------------------------------------------------- */ @@ -1280,7 +1280,7 @@ static bool lr( int sx, int sy, void *arg ) // static bool lc( int c1, int c2, void *arg ) { - return true; + return true; } /* --------------------------------------------------------------- */ @@ -1293,12 +1293,12 @@ static bool lc( int c1, int c2, void *arg ) // is part of the image i1, patch patch1. // static void CommonPoint( - vector &spots, - const vector &images, - Point pt, - int i1, - int patch1, - int out_layer ) + vector &spots, + const vector &images, + Point pt, + int i1, + int patch1, + int out_layer ) { Point p1 = pt; printf("image %d, global x,y= %f %f\n", i1, p1.x, p1.y); @@ -1338,12 +1338,12 @@ glob_spot s; // this will contain all the detailed info s.gpt = pt; for(int i=0; i ftc; // cache for Fourier transform @@ -1375,11 +1375,11 @@ for(int i=0; i dx, dy= %f, %f, corr %f\n\n", pt.x, dx, dy, co); if( co < 0.7 ) { @@ -1401,8 +1401,8 @@ if( s.which.size() > 1 ) { printf("More than one image for global point (%f %f)\n", pt.x, pt.y); // and add all the matching spots to the list for each image for(int i=0; i 126 ) - continue; + if( ch < 32 || ch > 126 ) + continue; - // draw as N times original size - //printf("draw character '%c' at %d, %d\n", ch, x, y); + // draw as N times original size + //printf("draw character '%c' at %d, %d\n", ch, x, y); - ch -= 32; + ch -= 32; - int N = 3; + int N = 3; - for( int dy = 0; dy < 7; ++dy ) { + for( int dy = 0; dy < 7; ++dy ) { - for( int dx = 0; dx < 5; ++dx ) { + for( int dx = 0; dx < 5; ++dx ) { - bool bit = (font5x7[ch][dy] & (1 << (4-dx))); + bool bit = (font5x7[ch][dy] & (1 << (4-dx))); - if( !bit ) - continue; + if( !bit ) + continue; - int bx = x + dx*N; - int by = y + dy*N; + int bx = x + dx*N; + int by = y + dy*N; - // draw an N x N box at (bx, by) + // draw an N x N box at (bx, by) - for( int j = 0; j < N; ++j ) { + for( int j = 0; j < N; ++j ) { - for( int k = 0; k < N; ++k ) { + for( int k = 0; k < N; ++k ) { - int m = bx+j + w*(by+k); + int m = bx+j + w*(by+k); - if( m < w*h ) - raster[m] = 0xFF; - } - } - } - } + if( m < w*h ) + raster[m] = 0xFF; + } + } + } + } - x += 6*N; - } + x += 6*N; + } } /* --------------------------------------------------------------- */ @@ -1578,10 +1578,10 @@ static double PseudoAngle( double y, double x ) { bool xish = fabs(y) <= fabs(x); // closer to x than y axis if( x > 0 && xish ) - return y/x; + return y/x; if( y > 0 ) { if( xish ) - return 4 + y/x; + return 4 + y/x; else return 2 - x/y; } @@ -1615,45 +1615,45 @@ vector setback; // pixels we will set back to 0 when we are done int nholes = 0; for(int i=start; i < np; i++) { if( map[i] == 0 ) { - start = i; // so next time resume here - stack st; - st.push(i); - vector boundary( 257, 0 ); // histogram of what we hit. + start = i; // so next time resume here + stack st; + st.push(i); + vector boundary( 257, 0 ); // histogram of what we hit. vector pixels; // 0 valued pixels in this area - while( !st.empty() ) { - int j = st.top(); st.pop(); + while( !st.empty() ) { + int j = st.top(); st.pop(); if( map[j] == 0 ) { - map[j] = 255; // so we won't get it again + map[j] = 255; // so we won't get it again pixels.push_back(j); - int y = j / w; - int x = j - w * y; - if( x-1 >= 0 ) st.push(j-1); else boundary[256]++; + int y = j / w; + int x = j - w * y; + if( x-1 >= 0 ) st.push(j-1); else boundary[256]++; if( x+1 < w ) st.push(j+1); else boundary[256]++; if( y-1 >= 0 ) st.push(j-w); else boundary[256]++; if( y+1 < h ) st.push(j+w); else boundary[256]++; - } + } else {// map value is not 0, add what we ran into to the set of boundary values - if( map[j] != 255 ) boundary[map[j]]++; - } - } + if( map[j] != 255 ) boundary[map[j]]++; + } + } // how many different things did we hit? And what was one of them? int howmany = 0, what = 0; for( int k = 0; k < 256; ++k ) { - if( boundary[k] != 0 ) { - howmany++; + if( boundary[k] != 0 ) { + howmany++; what = k; - } - } + } + } if( howmany == 1 ) { // then we have a hole, or a gap starting at a boundary - for( int k = 0; k < pixels.size(); ++k ) - map[pixels[k]] = what; + for( int k = 0; k < pixels.size(); ++k ) + map[pixels[k]] = what; nholes++; - } - else { // not a pure hole. record pixel values to set back later + } + else { // not a pure hole. record pixel values to set back later for(int k=0; k &images, - int im, - int patch, - Point p1, - vector &tris, - vector &gvtx, - int N, - int *which, - double *amts ) + vector &images, + int im, + int patch, + Point p1, + vector &tris, + vector &gvtx, + int N, + int *which, + double *amts ) { Point p = p1; images[im].tf[patch].Transform( p ); int first_tri = images[im].FirstTriangle + (patch-1)*N; // since N triangle per patch, and - // first one is #1 + // first one is #1 for(int i=first_tri; i < first_tri+N; i++) { if( Inside(tris[i], gvtx, p) ) { - printf("Got one - Point %f %f inside triangle (%f %f) (%f %f) (%f %f)\n", - p.x, p.y, - gvtx[tris[i].v[0]].x, gvtx[tris[i].v[0]].y, - gvtx[tris[i].v[1]].x, gvtx[tris[i].v[1]].y, - gvtx[tris[i].v[2]].x, gvtx[tris[i].v[2]].y ); + printf("Got one - Point %f %f inside triangle (%f %f) (%f %f) (%f %f)\n", + p.x, p.y, + gvtx[tris[i].v[0]].x, gvtx[tris[i].v[0]].y, + gvtx[tris[i].v[1]].x, gvtx[tris[i].v[1]].y, + gvtx[tris[i].v[2]].x, gvtx[tris[i].v[2]].y ); // find barycentric coordinates (linear combo of the three vertices amts[0] = tris[i].a[0][0]*p.x + tris[i].a[0][1]*p.y + tris[i].a[0][2]*1.0; amts[1] = tris[i].a[1][0]*p.x + tris[i].a[1][1]*p.y + tris[i].a[1][2]*1.0; amts[2] = tris[i].a[2][0]*p.x + tris[i].a[2][1]*p.y + tris[i].a[2][2]*1.0; printf("Barycentric coords: %f %f %f\n", amts[0], amts[1], amts[2] ); for(int k=0; k<3; k++) - which[k] = tris[i].v[k]; - return; - } + which[k] = tris[i].v[k]; + return; + } } printf("Oops - no triangle for point (%f %f)\n", p.x, p.y); exit( 42 ); @@ -1734,18 +1734,18 @@ exit( 42 ); // Write triangles out to a text file in a format gnuplot can read. // static void WriteTriangles( - const char *name, - vector &tris, - vector &pts ) + const char *name, + vector &tris, + vector &pts ) { FILE *ft = FileOpenOrDie( name, "w" ); for(int i=0; i &SPmapping ) + uint16 *test, + int w, + int h, + int &MaxSPUsed, + vector &SPmapping ) { int biggest = -1; vector vals(65536,0); @@ -1821,10 +1821,10 @@ int base = MaxSPUsed; // will add this to all int n=0; for(int i=1; i<65536; i++) { // 0 always maps to 0 if( vals[i] != 0 ) { // this value was used - MaxSPUsed++; + MaxSPUsed++; SPmapping[i] = MaxSPUsed; - n++; - } + n++; + } } printf("--- %d different values were used\n", n); // Now do the remapping @@ -1840,11 +1840,11 @@ for(int i=0; i &SPmapping ) + uint32 *test, + int w, + int h, + int &MaxSPUsed, + vector &SPmapping ) { // First find the biggest int biggest = -1; @@ -1853,7 +1853,7 @@ for(int i=0; i &tfs, - int xmin, - int ymin, - int xmax, - int ymax ) + uint32 w, + uint32 h, + vector &tfs, + int xmin, + int ymin, + int xmax, + int ymax ) { // make the four corners vector corners; @@ -1914,7 +1914,7 @@ for(int j=1; j &pts, - const Point ¢er, - double r, - double delta, - uint32 w, - uint32 h ) + vector &pts, + const Point ¢er, + double r, + double delta, + uint32 w, + uint32 h ) { - double lx = center.x - r; - double rx = center.x + r; - double by = center.y - r; - double ty = center.y + r; - vector ppts; // potential points - - for( double d = -r; d <= r; d += delta ) { - - ppts.push_back( Point( lx, center.y + d ) ); - ppts.push_back( Point( rx, center.y + d ) ); - ppts.push_back( Point( center.x + d, by ) ); - ppts.push_back( Point( center.x + d, ty ) ); - } + double lx = center.x - r; + double rx = center.x + r; + double by = center.y - r; + double ty = center.y + r; + vector ppts; // potential points + + for( double d = -r; d <= r; d += delta ) { + + ppts.push_back( Point( lx, center.y + d ) ); + ppts.push_back( Point( rx, center.y + d ) ); + ppts.push_back( Point( center.x + d, by ) ); + ppts.push_back( Point( center.x + d, ty ) ); + } // Now push back upper right corner, which might not be covered. - ppts.push_back( Point( rx, ty ) ); + ppts.push_back( Point( rx, ty ) ); // Now keep only those within the image // (can happen if image is a rectangle, not a square) - int n = ppts.size(); + int n = ppts.size(); - for( int i = 0; i < n; ++i ) { + for( int i = 0; i < n; ++i ) { - if( ppts[i].x >= 0.0 && - ppts[i].x <= w-1 && - ppts[i].y >= 0.0 && - ppts[i].y <= h-1 ) { + if( ppts[i].x >= 0.0 && + ppts[i].x <= w-1 && + ppts[i].y >= 0.0 && + ppts[i].y <= h-1 ) { - pts.push_back( ppts[i] ); - } - } + pts.push_back( ppts[i] ); + } + } } /* --------------------------------------------------------------- */ @@ -2078,70 +2078,70 @@ static void PointsInRing( // distortions are. // static void FillInFromCenterOut( - vector &imap, - vector &PatchFrom, - int nx, - int ny, - int w, - int h, // size of images coming in - double delta_image_space, // smallest size that maps to each pixel on output - vector &images, // the images - vector &relevant_images ) // the ones that are used among them + vector &imap, + vector &PatchFrom, + int nx, + int ny, + int w, + int h, // size of images coming in + double delta_image_space, // smallest size that maps to each pixel on output + vector &images, // the images + vector &relevant_images ) // the ones that are used among them { // find the center of each picture. May not be integer Point center((w-1)/2.0, (h-1)/2.0); int report = 100; for(double r=0.0; r <= max(center.x,center.y)+0.0001; r += delta_image_space) { if( r >= report ) { - printf("Starting radius %f\n", r); - report += 100; - } + printf("Starting radius %f\n", r); + report += 100; + } //compute a ring of radius R vector pts; PointsInRing(pts, center, r, delta_image_space, w, h); // Now transform this by all relevant images for(int k=0; k= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) - continue; - images[i].tf[patch].Transform( p ); // change to global coordinates - ix = ROUND(p.x); - iy = ROUND(p.y); - if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) - continue; // outside the image - //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); - uint32 nn = ix + uint32(iy)*uint32(nx); // index into array - if( imap[nn] == 0 ) { - imap[nn] = k+1; // this pixel will be set by the kth relevant picture - PatchFrom[nn] = patch; - } - else { // already set, but we still might be better (because of finite - // grid in source, rounding to int, ordering ). - Point pt_us = Point(ix,iy); - Point pt_ot = pt_us; - // transform back into original frames. - int oi = relevant_images[imap[nn]-1]; // other image - int op = PatchFrom[nn]; // other patch - images[oi].inv[op].Transform( pt_ot ); - images[i].inv[patch].Transform( pt_us ); - - double d_us = max(abs(pt_us.x-center.x), abs(pt_us.y-center.y)); // L-infinity norm - double d_ot = max(abs(pt_ot.x-center.x), abs(pt_ot.y-center.y)); // L-infinity norm - if( d_us < d_ot ) { - //printf("It CAN happen... d_us= %f, d_ot= %f\n", d_us, d_ot); - imap[nn] = k+1; // this pixel will be set by the ith picture - PatchFrom[nn] = patch; - } - } - } - } + int i = relevant_images[k]; + for(int j=0; j= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) + continue; + images[i].tf[patch].Transform( p ); // change to global coordinates + ix = ROUND(p.x); + iy = ROUND(p.y); + if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) + continue; // outside the image + //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); + uint32 nn = ix + uint32(iy)*uint32(nx); // index into array + if( imap[nn] == 0 ) { + imap[nn] = k+1; // this pixel will be set by the kth relevant picture + PatchFrom[nn] = patch; + } + else { // already set, but we still might be better (because of finite + // grid in source, rounding to int, ordering ). + Point pt_us = Point(ix,iy); + Point pt_ot = pt_us; + // transform back into original frames. + int oi = relevant_images[imap[nn]-1]; // other image + int op = PatchFrom[nn]; // other patch + images[oi].inv[op].Transform( pt_ot ); + images[i].inv[patch].Transform( pt_us ); + + double d_us = max(abs(pt_us.x-center.x), abs(pt_us.y-center.y)); // L-infinity norm + double d_ot = max(abs(pt_ot.x-center.x), abs(pt_ot.y-center.y)); // L-infinity norm + if( d_us < d_ot ) { + //printf("It CAN happen... d_us= %f, d_ot= %f\n", d_us, d_ot); + imap[nn] = k+1; // this pixel will be set by the ith picture + PatchFrom[nn] = patch; + } + } + } + } } } @@ -2157,11 +2157,11 @@ for(double r=0.0; r <= max(center.x,center.y)+0.0001; r += delta_image_space) { // class NameSorter{ public: - const char *name; - int num; + const char *name; + int num; public: - bool operator < ( const NameSorter &rhs ) const - {return strcmp( name, rhs.name ) < 0;}; + bool operator < ( const NameSorter &rhs ) const + {return strcmp( name, rhs.name ) < 0;}; }; /* --------------------------------------------------------------- */ @@ -2170,7 +2170,7 @@ class NameSorter{ static bool NameSortFn( NameSorter a, NameSorter b ) { - return strcmp( a.name, b.name ) > 0; + return strcmp( a.name, b.name ) > 0; } /* --------------------------------------------------------------- */ @@ -2178,15 +2178,15 @@ static bool NameSortFn( NameSorter a, NameSorter b ) /* --------------------------------------------------------------- */ static void FillInMatlabOrder( - vector &imap, - vector &PatchFrom, - int nx, - int ny, - int w, - int h, // size of images coming in - double delta_image_space, // smallest size that maps to each pixel on output - vector &images, // the images - vector &relevant_images) // the ones that are used among them + vector &imap, + vector &PatchFrom, + int nx, + int ny, + int w, + int h, // size of images coming in + double delta_image_space, // smallest size that maps to each pixel on output + vector &images, // the images + vector &relevant_images) // the ones that are used among them { // find the center of each picture. May not be integer Point center((w-1)/2.0, (h-1)/2.0); @@ -2207,36 +2207,36 @@ for(int kk=0; kk= report ) { - printf("Starting radius %f\n", r); - report += 500; - } - //compute a ring of radius R - vector pts; - PointsInRing(pts, center, r, delta_image_space, w, h); - // Now transform this by all relevant images - for(int j=0; j= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) - continue; - images[i].tf[patch].Transform( p ); // change to global coordinates - ix = ROUND(p.x); - iy = ROUND(p.y); - if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) - continue; // outside the image - //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); - uint32 nn = ix + uint32(iy)*uint32(nx); // index into array - if( imap[nn] == 0 ) { - imap[nn] = k+1; // this pixel will be set by the kth relevant picture - PatchFrom[nn] = patch; - } - } - } + if( r >= report ) { + printf("Starting radius %f\n", r); + report += 500; + } + //compute a ring of radius R + vector pts; + PointsInRing(pts, center, r, delta_image_space, w, h); + // Now transform this by all relevant images + for(int j=0; j= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) + continue; + images[i].tf[patch].Transform( p ); // change to global coordinates + ix = ROUND(p.x); + iy = ROUND(p.y); + if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) + continue; // outside the image + //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); + uint32 nn = ix + uint32(iy)*uint32(nx); // index into array + if( imap[nn] == 0 ) { + imap[nn] = k+1; // this pixel will be set by the kth relevant picture + PatchFrom[nn] = patch; + } + } + } } } @@ -2266,18 +2266,18 @@ for(pass=1; pass<=MAX_PASS; pass++) { if( stat(name, &buf) ) { // error, assume directory does not exist if( mkdir(name,0775) ) - printf("mkdir('%s') failed.\n", name); + printf("mkdir('%s') failed.\n", name); else // it worked, stop trying - break; + break; } else { // was able to stat the file; see if it's a directory if( !S_ISDIR(buf.st_mode) ) { - printf("File '%s' exists, but is not a directory.\n", name); - exit( 42 ); - } + printf("File '%s' exists, but is not a directory.\n", name); + exit( 42 ); + } else - break; // file exists and is a directory - } + break; // file exists and is a directory + } } if( pass > MAX_PASS ) exit( 42 ); @@ -2299,14 +2299,14 @@ dir_cache.insert(string(name)); // so each pixel can get a contribution from 1, 2, or 4 pixels. // static void CopyRaster( - uint8 *dest, - int w, - int h, - int dx, - int dy, - uint8 *src, - int sw, - int sh ) + uint8 *dest, + int w, + int h, + int dx, + int dy, + uint8 *src, + int sw, + int sh ) { // Do this a brute force way. Go through all the src pixels, mapping each to dest, // and counting how many map to each. Then average. @@ -2320,17 +2320,17 @@ int swt = sw & (~1); // create copies that are rounded down to nearest even int sht = sh & (~1); // stands for "source height truncated" for(int y=0; y &dir_cache ) + const char* rav_name, + int section, + int level, + int row, + int col, + set &dir_cache ) { // open the 4 relevant tiles - (row,col), (row+1,col), (row,col+1), and (row+1,col+1) uint32 w1, h1, w2, h2, w3, h3, w4, h4; @@ -2462,12 +2462,12 @@ return 1; // Condenses 4 tiles into 1, for SuperPixels. // static int WriteSummaryTileSP( - const char* rav_name, - int section, - int level, - int row, - int col, - set &dir_cache ) + const char* rav_name, + int section, + int level, + int row, + int col, + set &dir_cache ) { // open the 4 relevant tiles - (row,col), (row+1,col), (row,col+1), and (row+1,col+1) uint32 w1, h1, w2, h2, w3, h3, w4, h4; @@ -2535,9 +2535,9 @@ return 1; //Create smaller tiles, for images. // static void CreateLevelNTiles( - const char* rav_name, - int section, - set &dir_cache ) + const char* rav_name, + int section, + set &dir_cache ) { int at_this_level = 1; // so we loop at least once for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for trillions of tiles @@ -2553,7 +2553,7 @@ for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for tril wrote += stat; } at_this_level += wrote; - } + } printf("At level %d, wrote %d tiles\n", level, at_this_level); } } @@ -2565,9 +2565,9 @@ for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for tril //Create smaller tiles, for SuperPixels. // void CreateLevelNTilesSP( - const char* rav_name, - int section, - set &dir_cache ) + const char* rav_name, + int section, + set &dir_cache ) { int at_this_level = 1; // so we loop at least once for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for trillions of tiles @@ -2583,7 +2583,7 @@ for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for tril wrote += stat; } at_this_level += wrote; - } + } printf("SP:At level %d, wrote %d tiles\n", level, at_this_level); } } @@ -2595,49 +2595,49 @@ for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for tril // Updates the meta-data file. For now, just writes. // static void UpdateMetaData( - const char *name, - int section, - int w, - int h ) + const char *name, + int section, + int w, + int h ) { - int zmin, zmax; - FILE *fd = fopen( name, "r" ); + int zmin, zmax; + FILE *fd = fopen( name, "r" ); - if( fd ) { + if( fd ) { - CLineScan LS; - ssize_t read; + CLineScan LS; + ssize_t read; - while( (read = LS.Get( fd )) > 0 ) { + while( (read = LS.Get( fd )) > 0 ) { - //printf( "Retrieved line of length %zu :\n", read ); + //printf( "Retrieved line of length %zu :\n", read ); - if( !strncmp( LS.line, "zmin=", 5 ) ) - zmin = min( section, atoi(LS.line+5) ); - if( !strncmp( LS.line, "zmax=", 5 ) ) - zmax = max( section, atoi(LS.line+5) ); - } + if( !strncmp( LS.line, "zmin=", 5 ) ) + zmin = min( section, atoi(LS.line+5) ); + if( !strncmp( LS.line, "zmax=", 5 ) ) + zmax = max( section, atoi(LS.line+5) ); + } - fclose( fd ); - } - else { // no file yet; make one with one layer - zmin = section; - zmax = section; - } + fclose( fd ); + } + else { // no file yet; make one with one layer + zmin = section; + zmax = section; + } // Now write the new file - fd = FileOpenOrDie( name, "w" ); + fd = FileOpenOrDie( name, "w" ); - fprintf( fd, "version=1\n" ); - fprintf( fd, "width=%d\n", w ); - fprintf( fd, "height=%d\n", h ); - fprintf( fd, "zmin=%d\n", zmin ); - fprintf( fd, "zmax=%d\n", zmax ); - fprintf( fd, "superpixel-format=RGBA\n" ); - fprintf( fd, "channels=\"g;s\"\n" ); + fprintf( fd, "version=1\n" ); + fprintf( fd, "width=%d\n", w ); + fprintf( fd, "height=%d\n", h ); + fprintf( fd, "zmin=%d\n", zmin ); + fprintf( fd, "zmax=%d\n", zmax ); + fprintf( fd, "superpixel-format=RGBA\n" ); + fprintf( fd, "channels=\"g;s\"\n" ); - fclose( fd ); + fclose( fd ); } /* --------------------------------------------------------------- */ @@ -2647,11 +2647,11 @@ static void UpdateMetaData( // Writes the lowest level image tiles. // static int WriteImageTiles( - const char* rav_name, - int section, - const uint8 *image, - int w, - int h ) + const char* rav_name, + int section, + const uint8 *image, + int w, + int h ) { set dir_cache; // names of directories already created string base_name = rav_name; @@ -2671,30 +2671,30 @@ for(int row = 0; row*1024 < h; row++) { sprintf(fname, "%s/%d", base_name.c_str(), row); MakeDirExist(fname, dir_cache); for(int col = 0; col*1024 < w; col++) { - int xmin = col*1024; // bottom scan line - int xmax = min(xmin+1023, w-1); // top scan line + int xmin = col*1024; // bottom scan line + int xmax = min(xmin+1023, w-1); // top scan line sprintf(fname, "%s/%d/%d", base_name.c_str(), row, col); // make the dir for the column - MakeDirExist(fname, dir_cache); + MakeDirExist(fname, dir_cache); sprintf(fname, "%s/%d/%d/g", base_name.c_str(), row, col); // and the grey scale underneath - MakeDirExist(fname, dir_cache); + MakeDirExist(fname, dir_cache); // now, copy the portion of the image from xmin..xmax to ymin..ymax; int new_w = xmax - xmin + 1; int n = 0; - for(int y=ymin; y<=ymax; y++) { + for(int y=ymin; y<=ymax; y++) { uint32 m = uint32(xmin) + uint32(y)*uint32(w); // location of first byte on scan line y of 'image' - for(int x=0; x < new_w; x++) - raster[n++] = image[m++]; - } + for(int x=0; x < new_w; x++) + raster[n++] = image[m++]; + } int dir = section/1000; if( dir == 0 ) // first layers are written in the root directory - sprintf(fname,"%s/%d/%d/g/%03d.png", base_name.c_str(), row, col, section); + sprintf(fname,"%s/%d/%d/g/%03d.png", base_name.c_str(), row, col, section); else { // need another layer of directories - sprintf(fname,"%s/%d/%d/g/%d", base_name.c_str(), row, col, dir*1000); - MakeDirExist(fname, dir_cache); - sprintf(fname,"%s/%d/%d/g/%d/%03d.png", base_name.c_str(), row, col, dir*1000, section); - } + sprintf(fname,"%s/%d/%d/g/%d", base_name.c_str(), row, col, dir*1000); + MakeDirExist(fname, dir_cache); + sprintf(fname,"%s/%d/%d/g/%d/%03d.png", base_name.c_str(), row, col, dir*1000, section); + } Raster8ToPng8( fname, raster, new_w, ymax-ymin+1 ); - } + } } free(raster); @@ -2710,11 +2710,11 @@ return 0; // Writes the lowest level SP tiles. // static int WriteSPTiles( - const char* rav_name, - int section, - uint32 *image, - int w, - int h ) + const char* rav_name, + int section, + uint32 *image, + int w, + int h ) { set dir_cache; // names of directories already created string base_name = rav_name; @@ -2734,30 +2734,30 @@ for(int row = 0; row*1024 < h; row++) { sprintf(fname, "%s/%d", base_name.c_str(), row); MakeDirExist(fname, dir_cache); for(int col = 0; col*1024 < w; col++) { - int xmin = col*1024; // bottom scan line - int xmax = min(xmin+1023, w-1); // top scan line + int xmin = col*1024; // bottom scan line + int xmax = min(xmin+1023, w-1); // top scan line sprintf(fname, "%s/%d/%d", base_name.c_str(), row, col); // make the dir for the column - MakeDirExist(fname, dir_cache); + MakeDirExist(fname, dir_cache); sprintf(fname, "%s/%d/%d/s", base_name.c_str(), row, col); // and the sp map underneath - MakeDirExist(fname, dir_cache); + MakeDirExist(fname, dir_cache); // now, copy the portion of the image from xmin..xmax to ymin..ymax; int new_w = xmax - xmin + 1; int n = 0; - for(int y=ymin; y<=ymax; y++) { + for(int y=ymin; y<=ymax; y++) { uint32 m = uint32(xmin) + uint32(y)*uint32(w); // location of first byte on scan line y of 'image' - for(int x=0; x < new_w; x++) - raster[n++] = image[m++]; - } + for(int x=0; x < new_w; x++) + raster[n++] = image[m++]; + } int dir = section/1000; if (dir == 0) // first layers are written in the root directory - sprintf(fname,"%s/%d/%d/s/%03d.png", base_name.c_str(), row, col, section); + sprintf(fname,"%s/%d/%d/s/%03d.png", base_name.c_str(), row, col, section); else { // need another layer of directories - sprintf(fname,"%s/%d/%d/s/%d", base_name.c_str(), row, col, dir*1000); - MakeDirExist(fname, dir_cache); - sprintf(fname,"%s/%d/%d/s/%d/%03d.png", base_name.c_str(), row, col, dir*1000, section); - } + sprintf(fname,"%s/%d/%d/s/%d", base_name.c_str(), row, col, dir*1000); + MakeDirExist(fname, dir_cache); + sprintf(fname,"%s/%d/%d/s/%d/%03d.png", base_name.c_str(), row, col, dir*1000, section); + } Raster32ToPngRGBA( fname, raster, new_w, ymax-ymin+1 ); - } + } } free(raster); @@ -2774,38 +2774,38 @@ return 0; class Bookmark { public: - string text; - Point pt; - int z; - int body_id; - int image_number; + string text; + Point pt; + int z; + int body_id; + int image_number; public: - bool operator < ( const Bookmark &rhs ) const - {return image_number < rhs.image_number;}; + bool operator < ( const Bookmark &rhs ) const + {return image_number < rhs.image_number;}; }; class Partner { public: - double confidence; - Point pt; - int body_id; - int z; + double confidence; + Point pt; + int body_id; + int z; }; class TBar { public: - string status; - double confidence; - Point pt; - int z; - vector partners; - int body_id; - int image_number; + string status; + double confidence; + Point pt; + int z; + vector partners; + int body_id; + int image_number; public: - bool operator < ( const TBar &rhs ) const - {return image_number < rhs.image_number;}; + bool operator < ( const TBar &rhs ) const + {return image_number < rhs.image_number;}; }; /* --------------------------------------------------------------- */ @@ -2813,9 +2813,9 @@ class TBar { /* --------------------------------------------------------------- */ static bool ReadBookmarks( - char *fname, - int section, - vector &bookmarks ) + char *fname, + int section, + vector &bookmarks ) { Json::Value root; // will contains the root value after parsing. Json::Reader reader; @@ -2856,10 +2856,10 @@ for( unsigned int i = 0; i < nd; ++i ) { Json::Value lo = v["location"]; b.z = lo[2u].asInt(); if( b.z == section ) { - b.pt.x = lo[0u].asDouble(); - b.pt.y = lo[1u].asDouble(); + b.pt.x = lo[0u].asDouble(); + b.pt.y = lo[1u].asDouble(); bookmarks.push_back(b); - } + } } return true; } @@ -2869,9 +2869,9 @@ return true; /* --------------------------------------------------------------- */ static bool ReadSynAnnot( - char *fname, - int section, - vector &tbs ) + char *fname, + int section, + vector &tbs ) { Json::Value root; // will contains the root value after parsing. Json::Reader reader; @@ -2913,27 +2913,27 @@ for( unsigned int i = 0; i < nd; ++i ) { TBar tb; tb.z = lo[2u].asInt(); if( tb.z == section ) { - tb.status = t["status"].asString(); - tb.confidence = t["confidence"].asDouble(); - tb.body_id = t["body ID"].asInt(); - tb.pt.x = lo[0u].asDouble(); - tb.pt.y = lo[1u].asDouble(); - //printf("status is %s, confidence %f, loc %.1f,%lf,%d, %d partners\n", - //tb.status.c_str(), tb.confidence, tb.pt.x, tb.pt.y, tb.z, part.size() ); - for(int j=0; j &images, - bool warp, - vector &tmap, - vector &result ) + const char *name, + char *root, + int section, + int image_no, + vector &images, + bool warp, + vector &tmap, + vector &result ) { uint32 w = images[image_no].w; uint32 h = images[image_no].h; @@ -2976,11 +2976,11 @@ if( strstr(name, "annotations-synapse") != NULL ) { Point p = tbs[j].pt; int ix = int(p.x); int iy = int(p.y); - // make sure it's legal - if( ix < 0 || ix >= w || iy < 0 || iy >= h ) { - printf("Synapse outside diagram?? %d %d %d %d\n", ix, w, iy, h); - continue; - } + // make sure it's legal + if( ix < 0 || ix >= w || iy < 0 || iy >= h ) { + printf("Synapse outside diagram?? %d %d %d %d\n", ix, w, iy, h); + continue; + } int patch = images[image_no].foldmap[ix + w*iy]; // There can be small patches which were not used, so need to check for legality here // // No longer needed since we compress patches and foldmaps on input @@ -2992,13 +2992,13 @@ if( strstr(name, "annotations-synapse") != NULL ) { else { //we are warping int sector = tmap[ix + w*iy]; t = images[image_no].sectors[patch][sector]; - } + } t.Transform( p ); tbs[j].pt = p; - for(int m=0; m &images, - bool warp, - vector &tmap, - vector &result ) + const char *name, + char *root, + int section, + int image_no, + vector &images, + bool warp, + vector &tmap, + vector &result ) { uint32 w = images[image_no].w; uint32 h = images[image_no].h; @@ -3042,7 +3042,7 @@ if( strstr(name, "annotations-bookmarks") != NULL ) { // one, then look up the reverse transformation from global space, and find // the one that maps here. for(int j=0; j= images[i].tf.size() || images[i].tf[patch].det() == 0.0) continue; TAffine t; - if( !warp ) // just one transform per image - t = images[image_no].tf[patch]; // change to global coordinates + if( !warp ) // just one transform per image + t = images[image_no].tf[patch]; // change to global coordinates else { //we are warping - int sector = tmap[ix+iy*w]; + int sector = tmap[ix+iy*w]; t = images[image_no].sectors[patch][sector]; } t.Transform( p ); bookmarks[j].pt = p; - result.push_back(bookmarks[j]); - } + result.push_back(bookmarks[j]); + } } return true; } @@ -3085,27 +3085,27 @@ int main( int argc, char **argv ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* --------------- */ /* Read input file */ /* --------------- */ - vector images; - vector x1, x2, y1, y2; - vector z1, z2; - double xmin = BIG, ymin = BIG; - double xmax = -BIG, ymax = -BIG; - uint32 w = 0, h = 0; - - if( gArgs.strings ) { - ReadInput_StrTags( images, x1, x2, y1, y2, z1, z2, - xmin, xmax, ymin, ymax, w, h ); - } - else { - ReadInput_NumTags( images, x1, x2, y1, y2, z1, z2, - xmin, xmax, ymin, ymax, w, h ); - } + vector images; + vector x1, x2, y1, y2; + vector z1, z2; + double xmin = BIG, ymin = BIG; + double xmax = -BIG, ymax = -BIG; + uint32 w = 0, h = 0; + + if( gArgs.strings ) { + ReadInput_StrTags( images, x1, x2, y1, y2, z1, z2, + xmin, xmax, ymin, ymax, w, h ); + } + else { + ReadInput_NumTags( images, x1, x2, y1, y2, z1, z2, + xmin, xmax, ymin, ymax, w, h ); + } //VMStats( stdout ); //exit( 11 ); @@ -3114,32 +3114,32 @@ int main( int argc, char **argv ) /* Layer span [lowest, highest] */ /* ---------------------------- */ - int lowest, highest, ni = images.size(); + int lowest, highest, ni = images.size(); - if( !ni ) { - printf( "No images in input.\n" ); - exit( 42 ); - } + if( !ni ) { + printf( "No images in input.\n" ); + exit( 42 ); + } - lowest = highest = images[0].layer; + lowest = highest = images[0].layer; - for( int i = 1; i < ni; ++i ) { + for( int i = 1; i < ni; ++i ) { - int z = images[i].layer; + int z = images[i].layer; - if( z < lowest ) - lowest = z; - else if( z > highest ) - highest = z; - } + if( z < lowest ) + lowest = z; + else if( z > highest ) + highest = z; + } /* ---------------------- */ /* Coordinate adjustments */ /* ---------------------- */ - GlobalBounds( xmin, xmax, ymin, ymax, images, w, h ); + GlobalBounds( xmin, xmax, ymin, ymax, images, w, h ); - OffsetCoords( xmin, xmax, ymin, ymax, images, x1, y1, x2, y2 ); + OffsetCoords( xmin, xmax, ymin, ymax, images, x1, y1, x2, y2 ); @@ -3169,8 +3169,8 @@ if( gArgs.lspec1 >= 0 ) { // layer numbers were specified double delta_image_space = 2.0; // implausibly high value for(int i=0; i relevant_images; // See if we find any boundary maps @@ -3238,86 +3238,86 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u int MaxSPUsed = 0; for(int i=0; iimap(nx*ny,0); if( relevant_images.size() > 0xFFFF ) { // since we hold this as 16 bits - printf("Too many images (%d) on layer %d\n", (int)relevant_images.size(), out_layer); - exit( 42 ); - } + printf("Too many images (%d) on layer %d\n", (int)relevant_images.size(), out_layer); + exit( 42 ); + } vectorPatchFrom(nx*ny,0); // Now the choice of fill-in methods if( gArgs.matlab_order ) { - FillInMatlabOrder( imap, PatchFrom, nx, ny, - w, h, delta_image_space, images, relevant_images ); + FillInMatlabOrder( imap, PatchFrom, nx, ny, + w, h, delta_image_space, images, relevant_images ); } else { - FillInFromCenterOut( imap, PatchFrom, nx, ny, - w, h, delta_image_space, images, relevant_images ); - } + FillInFromCenterOut( imap, PatchFrom, nx, ny, + w, h, delta_image_space, images, relevant_images ); + } // Now compress the map/patch array. We assume less than 65536 combinations are used, so we can express // this as a 16 bit TIF. The combinations start at 1, and run sequentially. @@ -3356,22 +3356,22 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vectorhisto(10); // small histogram, for testing for(uint32 i=0; i::iterator it = temp.find(id); if( it == temp.end() ) { // add it - Triple t(imap[i], PatchFrom[i], 0); - temp.insert(pair(id, Triples.size())); + Triple t(imap[i], PatchFrom[i], 0); + temp.insert(pair(id, Triples.size())); printf("New combo %5d: %d %d at %d\n", (int)Triples.size(), t.image, t.patch, i); Triples.push_back(t); - it = temp.find(id); // now should find it, since we just added it - } + it = temp.find(id); // now should find it, since we just added it + } imap[i] = it->second; if( it->second < 10 ) - histo[it->second]++; - } + histo[it->second]++; + } for(int i=0; i<10; i++) - printf("Entry %d used %d times.\n", i, histo[i]); + printf("Entry %d used %d times.\n", i, histo[i]); @@ -3387,7 +3387,7 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u printf("Writing 8 bit map in png format to %s\n", fname); vector copy(nx*ny, 0); // make an 8 bit copy for(int i=0; ibefore(nx*ny,0); for(int y=0; y < ny; y++) { if( (y & 0x3FF) == 0 ) { - printf("."); fflush(stdout); + printf("."); fflush(stdout); } - for(int x=0; x= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate - int ix = int(p.x); - int iy = int(p.y); - double alpha = p.x-ix; - double beta = p.y-iy; - int nn = ix + w*iy; // index into original image - uint8* pic = images[img].raster; - double pix = - (1-alpha)*(1-beta) * pic[nn] + - alpha *(1-beta) * pic[nn+1] + - (1-alpha)* beta * pic[nn+w] + - alpha * beta * pic[nn+w+1]; - before[bi] = ROUND(pix); - } - } // to aid debugging, draw lines at the image boundaries in the before image. + if( from == 0 ) + continue; // no image sets this pixel + int img = relevant_images[from-1]; + Point p(x, y); + images[img].inv[patch].Transform( p ); + // of course, this should be in the image, but let's double check + if( p.x >= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate + int ix = int(p.x); + int iy = int(p.y); + double alpha = p.x-ix; + double beta = p.y-iy; + int nn = ix + w*iy; // index into original image + uint8* pic = images[img].raster; + double pix = + (1-alpha)*(1-beta) * pic[nn] + + alpha *(1-beta) * pic[nn+1] + + (1-alpha)* beta * pic[nn+w] + + alpha * beta * pic[nn+w+1]; + before[bi] = ROUND(pix); + } + } // to aid debugging, draw lines at the image boundaries in the before image. } printf("Done creating before image; draw lines next\n"); if( gArgs.annotate ) { - vector edges; - for(int x=0; x edges; + for(int x=0; x 0 && p.x < nx-1 && p.y > 0 && p.y < ny-1 ) - DrawText(&before[0], nx, ny, fn, int(p.x), int(p.y)); - } - //also to aid in debugging, draw circles at correspondence points - for(int i=0; i 0x7FFFFFFFu ) { // is it *really* big? - printf( "write half\n" ); - sprintf( fname, "before.%05d.a.png", out_layer ); - Raster8ToPng8( fname, &before[0], nx, ny/2 ); - printf( "write the other half\n" ); - sprintf( fname, "before.%05d.b.png", out_layer ); - Raster8ToPng8( fname, &before[nx*ny/2], nx, ny/2 ); - printf( "both written\n" ); - } - else { // this is the usual case - sprintf( fname, "before.%05d.png", out_layer ); - Raster8ToPng8( fname, &before[0], nx, ny ); - } - } + if( nx*ny > 0x7FFFFFFFu ) { // is it *really* big? + printf( "write half\n" ); + sprintf( fname, "before.%05d.a.png", out_layer ); + Raster8ToPng8( fname, &before[0], nx, ny/2 ); + printf( "write the other half\n" ); + sprintf( fname, "before.%05d.b.png", out_layer ); + Raster8ToPng8( fname, &before[nx*ny/2], nx, ny/2 ); + printf( "both written\n" ); + } + else { // this is the usual case + sprintf( fname, "before.%05d.png", out_layer ); + Raster8ToPng8( fname, &before[0], nx, ny ); + } + } @@ -3505,29 +3505,29 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u sprintf( fname, "%s/%s/map.%05d.png", gArgs.region_dir, gArgs.inv_dir, out_layer ); printf( "write Pixel mapping file %s\n", fname ); Raster16ToPng16( fname, &imap[0], nx, ny ); - // ------------------------------------------------ write the mapping text file -------------------- - // This is the text file that contains the transformations that describe how each pixel got there. - sprintf( fname, "%s/%s/mapping.%05d.txt", gArgs.region_dir, gArgs.inv_dir, out_layer ); - FILE *ftxt = FileOpenOrDie( fname, "w" ); - //write the image names, and their indexes - for(int k=0; k gvtx; for(int m=0; m spots; const int delta = 40; for(int ty=0; ty 0 && image2 > 0 ) { // found a boundary + if( image1 != image2 && image1 > 0 && image2 > 0 ) { // found a boundary if (tx - prev_x < delta && // see if it's a duplicate of previous one (indx1 == prev_i1 && indx2 == prev_i2 || indx1 == prev_i2 && indx2 == prev_i1)) - printf("Same images, too close, at %d\n", tx); + printf("Same images, too close, at %d\n", tx); else { // it's Ok - Ntrans++; - int i1 = relevant_images[image1-1]; - int i2 = relevant_images[image2-1]; // point is on boundary of image i1 and i2 - //i2 = i1; // temp, just to make sure we get 0,0 - Point p1(tx,ty); - CommonPoint( spots, images, p1,i1, Triples[indx1].patch, out_layer ); - prev_x = tx; prev_i1 = indx1; prev_i2 = indx2; - } - } - } + Ntrans++; + int i1 = relevant_images[image1-1]; + int i2 = relevant_images[image2-1]; // point is on boundary of image i1 and i2 + //i2 = i1; // temp, just to make sure we get 0,0 + Point p1(tx,ty); + CommonPoint( spots, images, p1,i1, Triples[indx1].patch, out_layer ); + prev_x = tx; prev_i1 = indx1; prev_i2 = indx2; + } + } + } if( Ntrans > 100 ) { - printf("Too many transitions (%d) in map!\n", Ntrans); + printf("Too many transitions (%d) in map!\n", Ntrans); if( !gArgs.debug ) { - printf("Writing map as 'test.png'\n"); - Raster16ToPng16( "test.png", &imap[0], nx, ny ); - } + printf("Writing map as 'test.png'\n"); + Raster16ToPng16( "test.png", &imap[0], nx, ny ); + } exit( 42 ); - } - } + } + } for(int tx=0; tx 0 && image2 > 0 ) { // found a boundary + if( image1 != image2 && image1 > 0 && image2 > 0 ) { // found a boundary if (ty - prev_y < delta && // see if it's a duplicate of previous one (indx1 == prev_i1 && indx2 == prev_i2 || indx1 == prev_i2 && indx2 == prev_i1)) - printf("Same images, too close, at %d\n", ty); + printf("Same images, too close, at %d\n", ty); else { // it's Ok - Ntrans++; - int i1 = relevant_images[image1-1]; // -1 since 0 is reserved for 'no image maps here' - int i2 = relevant_images[image2-1]; // point is on boundary of image i1 and i2 - //i2 = i1; // temp, just to make sure we get 0,0 - Point p1(tx,ty); - CommonPoint( spots, images, p1,i1, Triples[indx1].patch, out_layer ); - prev_y = ty; prev_i1 = indx1; prev_i2 = indx2; - } - } - } + Ntrans++; + int i1 = relevant_images[image1-1]; // -1 since 0 is reserved for 'no image maps here' + int i2 = relevant_images[image2-1]; // point is on boundary of image i1 and i2 + //i2 = i1; // temp, just to make sure we get 0,0 + Point p1(tx,ty); + CommonPoint( spots, images, p1,i1, Triples[indx1].patch, out_layer ); + prev_y = ty; prev_i1 = indx1; prev_i2 = indx2; + } + } + } if( Ntrans > 100 ) { - printf("Too many transitions (%d) in map!\n", Ntrans); + printf("Too many transitions (%d) in map!\n", Ntrans); if( !gArgs.debug ) { - printf("Writing map as 'test.png'\n"); - Raster16ToPng16( "test.png", &imap[0], nx, ny ); - } + printf("Writing map as 'test.png'\n"); + Raster16ToPng16( "test.png", &imap[0], nx, ny ); + } exit( 42 ); - } - } + } + } printf("%d global control points; %d constraints\n", - (int)gvtx.size(), (int)spots.size() ); + (int)gvtx.size(), (int)spots.size() ); int nvs = gvtx.size(); // number of control points // Now generate the constraints. Declare the (sparse) normal matrix and the RHS @@ -3731,33 +3731,33 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vector RHS(2*nvs, 0.0); // // first, add the constraints that each should be near where they started... for(int i=0; i X(2*nvs); fflush(stdout); @@ -3783,7 +3783,7 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vector NewG(nvs); for(int i=0; iMoveThresh ? "<-----" : ""); + printf("Image %d, pt %d, was (%f,%f), now (%f,%f), moved %f %s\n", + i/(N+1), i%(N+1), gvtx[i].x, gvtx[i].y, NewG[i].x, NewG[i].y, move, move>MoveThresh ? "<-----" : ""); if( move > MoveThresh ) { - NewG[i] = gvtx[i]; - NTooFar++; - } - } + NewG[i] = gvtx[i]; + NTooFar++; + } + } // Now, for every patch of every image, compute a vector of N transforms, one corresponding // to each original triangle. for(int m=0; m empty; images[i].sectors.push_back(empty); // since there is no patch 0 images[i].sinvs .push_back(empty); - for(int j=1; j ltfs(N); // an N element vector of transforms - vector invs(N); // and the inverses to these + for(int j=1; j ltfs(N); // an N element vector of transforms + vector invs(N); // and the inverses to these printf("Image %d, patch %d\n", i, j); images[i].tf[j].TPrint(); - for(int k=0; k pts; - PointsInRing(pts, center, r, delta_image_space*0.9, w, h); + vector pts; + PointsInRing(pts, center, r, delta_image_space*0.9, w, h); // Now transform this by all relevant images - for(int k=0; k= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) - continue; - images[i].sectors[patch][sector].Transform( p ); // change to global coordinates - ix = ROUND(p.x); - iy = ROUND(p.y); + continue; + images[i].sectors[patch][sector].Transform( p ); // change to global coordinates + ix = ROUND(p.x); + iy = ROUND(p.y); if( ix == 8557 && iy == 431 ) { printf("Point %f %f in image %s\n", pts[j].x, pts[j].y, images[i].GetRName()); - printf("Maps to pixel %d %d, image %d patch %d sector %d\n", ix, iy, i, patch, sector); + printf("Maps to pixel %d %d, image %d patch %d sector %d\n", ix, iy, i, patch, sector); images[i].sectors[patch][sector].TPrint( stdout, "Transform is " ); images[i]. sinvs[patch][sector].TPrint( stdout, " Inverse is " ); - } + } if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) - continue; // outside the image - //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); - bool dbg = (2642 <= ix && ix <= 2644 && 3398 <= iy && iy <= 3400); + continue; // outside the image + //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); + bool dbg = (2642 <= ix && ix <= 2644 && 3398 <= iy && iy <= 3400); if( dbg ) printf("\nDebugging point %d %d, r=%f, p= %f %f, pts[%d]= %f %f\n", ix, iy, r, p.x, p.y, j, pts[j].x, pts[j].y ); - uint32 nn = uint32(ix) + uint32(iy)*nx; // index into array - if( imap[nn] == 0 ) { - imap[nn] = k+1; // this pixel will be set by the kth relevant picture - PatchFrom[nn] = patch; // patch 'patch', sector 'sector' + uint32 nn = uint32(ix) + uint32(iy)*nx; // index into array + if( imap[nn] == 0 ) { + imap[nn] = k+1; // this pixel will be set by the kth relevant picture + PatchFrom[nn] = patch; // patch 'patch', sector 'sector' SectorFrom[nn]= sector; if( dbg ) printf("Not set, setting to %d %d %d %d\n", k, i, patch, sector); } - else { // already set, but we still might be better (because of finite - // grid in source, rounding to int, ordering ). - Point pt_us = Point(ix,iy); - Point pt_ot = pt_us; - // transform back into original frames. - int oi = relevant_images[imap[nn]-1]; // other image - int op = PatchFrom[nn]; // other patch + else { // already set, but we still might be better (because of finite + // grid in source, rounding to int, ordering ). + Point pt_us = Point(ix,iy); + Point pt_ot = pt_us; + // transform back into original frames. + int oi = relevant_images[imap[nn]-1]; // other image + int op = PatchFrom[nn]; // other patch int os = SectorFrom[nn]; // other sector - images[oi].sinvs[op][os].Transform( pt_ot ); - images[i].sinvs[patch][sector].Transform( pt_us ); - - double d_us = max(abs(pt_us.x-center.x), abs(pt_us.y-center.y)); // L-infinity norm - double d_ot = max(abs(pt_ot.x-center.x), abs(pt_ot.y-center.y)); // L-infinity norm - if( dbg ) printf("Already set to %d %d %d %d, d_us %f, d_ot %f\n", imap[nn]-1, oi, op, os, d_us, d_ot); - if( d_us < d_ot ) { - if( dbg ) printf("It CAN happen #2... d_us= %f, d_ot= %f\n", d_us, d_ot); - // Set it, even though it was previously set, since this is better - imap[nn] = k+1; // this pixel will be set by the ith picture - PatchFrom[nn] = patch; - SectorFrom[nn] = sector; - } - } - } - } - } + images[oi].sinvs[op][os].Transform( pt_ot ); + images[i].sinvs[patch][sector].Transform( pt_us ); + + double d_us = max(abs(pt_us.x-center.x), abs(pt_us.y-center.y)); // L-infinity norm + double d_ot = max(abs(pt_ot.x-center.x), abs(pt_ot.y-center.y)); // L-infinity norm + if( dbg ) printf("Already set to %d %d %d %d, d_us %f, d_ot %f\n", imap[nn]-1, oi, op, os, d_us, d_ot); + if( d_us < d_ot ) { + if( dbg ) printf("It CAN happen #2... d_us= %f, d_ot= %f\n", d_us, d_ot); + // Set it, even though it was previously set, since this is better + imap[nn] = k+1; // this pixel will be set by the ith picture + PatchFrom[nn] = patch; + SectorFrom[nn] = sector; + } + } + } + } + } // Now compress the map/patch/sector array. We assume less than 65536 combinations are used, so we can express // this as a 16 bit TIF. The combinations start at 1, and run sequentially. temp.clear(); // clear the mapping file Triples.resize(1); // and the triples; will fill up as they are found; first entry remains (0,0,0) for(uint32 i=0; i::iterator it = temp.find(id); if( it == temp.end() ) { // add it - Triple t(imap[i], PatchFrom[i], SectorFrom[i]); - temp.insert(pair(id, Triples.size())); + Triple t(imap[i], PatchFrom[i], SectorFrom[i]); + temp.insert(pair(id, Triples.size())); printf("New combo %5d: %3d %3d %3d\n", (int)Triples.size(), t.image, t.patch, t.sector); Triples.push_back(t); - it = temp.find(id); // now should find it, since we just added it - } + it = temp.find(id); // now should find it, since we just added it + } uint32 iy = i/nx; uint32 ix = i - nx*iy; - if( ix == 8557 && iy == 431 ) { - printf("Compress map ix=%d iy=%d\n", ix, iy); + if( ix == 8557 && iy == 431 ) { + printf("Compress map ix=%d iy=%d\n", ix, iy); printf(" imap %d, patch %d, sector %d\n", imap[i], PatchFrom[i], SectorFrom[i]); if( imap[i] > 0 ) - printf("Image %d\n", relevant_images[imap[i]-1] ); - printf(" id = %d = %x\n", id, id); + printf("Image %d\n", relevant_images[imap[i]-1] ); + printf(" id = %d = %x\n", id, id); printf(" it->second = %d\n", it->second); - } + } imap[i] = it->second; - } + } // write the new map file, if requested if( gArgs.make_map ) { sprintf( fname, "%s/%s/map.%05d.png", gArgs.region_dir, gArgs.inv_dir, out_layer ); @@ -4001,79 +4001,79 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u } for(int x=0; x= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate - int ix = int(p.x); - int iy = int(p.y); - double alpha = p.x-ix; - double beta = p.y-iy; - int nn = ix + w*iy; // index into original image - uint8* pic = images[img].raster; - double pix = - (1-alpha)*(1-beta) * pic[nn] + - alpha *(1-beta) * pic[nn+1] + - (1-alpha)* beta * pic[nn+w] + - alpha * beta * pic[nn+w+1]; - before[bi] = ROUND(pix); + Point p(x, y); + images[img].sinvs[patch][sector].Transform( p ); + // of course, this should be in the image, but let's double check + if( p.x >= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate + int ix = int(p.x); + int iy = int(p.y); + double alpha = p.x-ix; + double beta = p.y-iy; + int nn = ix + w*iy; // index into original image + uint8* pic = images[img].raster; + double pix = + (1-alpha)*(1-beta) * pic[nn] + + alpha *(1-beta) * pic[nn+1] + + (1-alpha)* beta * pic[nn+w] + + alpha * beta * pic[nn+w+1]; + before[bi] = ROUND(pix); // for the super-pixel map we want nearest, not interpolation. if( p.x - ix >= 0.5 ) - ix++; + ix++; if( p.y - iy >= 0.5 ) - iy++; + iy++; int px = images[img].spmap[ix + w*iy]; if( px != 0 ) // 0 valued pixels are unassigned, and not translated px += images[img].spbase; spmap[bi] = px; //if( spmap[x+y*nx] == 65536 ) { // Just debugging //printf("w=%d h=%d nx=%d ny=%d patch=%d sector=%d\n", w, h, nx, ny, patch, sector); - //printf("Set to %d. x=%d y=%d ix=%d iy=%d img=%d images[img].spbase=%d images[img].spmap[ix + w*iy] = %d\n", + //printf("Set to %d. x=%d y=%d ix=%d iy=%d img=%d images[img].spbase=%d images[img].spmap[ix + w*iy] = %d\n", //px, x, y, ix, iy, img, images[img].spbase, images[img].spmap[ix + w*iy] ); //exit( 42 ); - //} + //} if( gArgs.debug && px == 0 ) - before[bi] = 255; - } - } // to aid debugging, draw lines at the image boundaries in the before image. + before[bi] = 255; + } + } // to aid debugging, draw lines at the image boundaries in the before image. } if( gArgs.annotate ) { - vector edges; - for(int x=0; x edges; + for(int x=0; x= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate - int ix = int(p.x); - int iy = int(p.y); - double alpha = p.x-ix; - double beta = p.y-iy; - int nn = ix + w*iy; // index into original image - uint8* pic = images[img].bmap; - double pix = - (1-alpha)*(1-beta) * pic[nn] + - alpha *(1-beta) * pic[nn+1] + - (1-alpha)* beta * pic[nn+w] + - alpha * beta * pic[nn+w+1]; - before[x+y*nx] = ROUND(pix); - } - } - } + Point p(x, y); + images[img].sinvs[patch][sector].Transform( p ); + // of course, this should be in the image, but let's double check + if( p.x >= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate + int ix = int(p.x); + int iy = int(p.y); + double alpha = p.x-ix; + double beta = p.y-iy; + int nn = ix + w*iy; // index into original image + uint8* pic = images[img].bmap; + double pix = + (1-alpha)*(1-beta) * pic[nn] + + alpha *(1-beta) * pic[nn+1] + + (1-alpha)* beta * pic[nn+w] + + alpha * beta * pic[nn+w+1]; + before[x+y*nx] = ROUND(pix); + } + } + } if( AnyBMap ) { sprintf( fname, "%s/%s/bmap.%05d.png", gArgs.region_dir, gArgs.bmap_dir, out_layer ); - if( gArgs.make_flat ) + if( gArgs.make_flat ) Raster8ToPng8( fname, &before[0], nx, ny ); - } + } // ------------------------------------------------ write the mapping text file -------------------- // This is the text file that contains the transformations that describe how each pixel got there. @@ -4128,14 +4128,14 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u //write the image names, and their indexes for(int k=0; k volume(biggest+1,0); @@ -4174,24 +4174,24 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vector xmax(biggest+1,-1); vector ymax(biggest+1,-1); for(int y=0; y 0 ) - fprintf(fb,"%d %7d %8d %d %d %d %d\n", out_layer, i, xmin[i], ny-1-ymax[i], xmax[i]-xmin[i]+1, ymax[i]-ymin[i]+1, volume[i]); - } + fprintf(fb,"%d %7d %8d %d %d %d %d\n", out_layer, i, xmin[i], ny-1-ymax[i], xmax[i]-xmin[i]+1, ymax[i]-ymin[i]+1, volume[i]); + } fclose(fb); } @@ -4199,19 +4199,19 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u bool experiment = false; if( experiment ) { vector copy(nx*ny,0); - for(int i=0; i big(bigx*bigy); printf("try to fill the huge array\n"); fflush(stdout); int p1 = nx*ny; int p2 = bigx*bigy; for(int i=0; i not in the original image - else { - //printf("%6d maps to %d (global set of maps)\n", k, m); + for(int k=1; k not in the original image + else { + //printf("%6d maps to %d (global set of maps)\n", k, m); // this could go off the end of the Final Mapping array, if the biggest number // assigned is not used in the final image. Test for this: int n = (m < FinalMapping.size()) ? FinalMapping[m] : 0; - if( n == 0 ) - fprintf(fmap, "%d -2\n", k); // -2 => not used in final image - else - fprintf(fmap, "%d %d\n", k, n); - } - } - } - } + if( n == 0 ) + fprintf(fmap, "%d -2\n", k); // -2 => not used in final image + else + fprintf(fmap, "%d %d\n", k, n); + } + } + } + } fclose(fmap); // Now, for every image that was used, look and see if it had annotation. If so, transform @@ -4255,35 +4255,35 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vector tbars; vector bookmarks; for(int j=0; j which; // which picture - vector patch; // which patch - vector where; // local coords - Point gpt; // point in global coords spawning these - double moved; // distance it moved + vector which; // which picture + vector patch; // which patch + vector where; // local coords + Point gpt; // point in global coords spawning these + double moved; // distance it moved }; class image { public: - uint8* raster; // gray scale image - uint8* foldmap; // fold map - uint8* bmap; // boundary map - uint32 w, h; - int layer; // layer number - int FirstGlobalPoint; - int FirstTriangle; - int spbase; // should be added to all sp ids in this image, for uniqueness - char *rname; // raster filename - char *fname; // foldmap filename - char *spname; // super-pixel filename - char *bname; // boundary-map filename - uint16 *spmap; - vector SPmapping; // tells what original SP numbers are mapped to - vector tf; // image to global space, one for each patch (0 unused) - vector inv; // inverse transform - vector >sectors; // forward transform for each sector of each patch - vector >sinvs; // sector inverses - vector FoldmapRenumber; + uint8* raster; // gray scale image + uint8* foldmap; // fold map + uint8* bmap; // boundary map + uint32 w, h; + int layer; // layer number + int FirstGlobalPoint; + int FirstTriangle; + int spbase; // should be added to all sp ids in this image, for uniqueness + char *rname; // raster filename + char *fname; // foldmap filename + char *spname; // super-pixel filename + char *bname; // boundary-map filename + uint16 *spmap; + vector SPmapping; // tells what original SP numbers are mapped to + vector tf; // image to global space, one for each patch (0 unused) + vector inv; // inverse transform + vector >sectors; // forward transform for each sector of each patch + vector >sinvs; // sector inverses + vector FoldmapRenumber; }; // Class describing a triple of numbers that in turn describe @@ -73,15 +73,15 @@ class image { // class Triple { public: - uint16 image; - uint8 patch; - uint8 sector; + uint16 image; + uint8 patch; + uint8 sector; public: - Triple() - : image(0), patch(0), sector(0) {}; + Triple() + : image(0), patch(0), sector(0) {}; - Triple( uint16 i, uint8 p, uint8 s ) - : image(i), patch(p), sector(s) {}; + Triple( uint16 i, uint8 p, uint8 s ) + : image(i), patch(p), sector(s) {}; }; /* --------------------------------------------------------------- */ @@ -111,18 +111,18 @@ static int nwarn_good_on_edge = 0; // worst case - good correlation, but on edge // 'nmrc_z_tile.png' and we decode the z from that. // static int FileNameToLayerNumber( - const vector &dnames, - const vector &lnums, - const char *fname ) + const vector &dnames, + const vector &lnums, + const char *fname ) { /* ----- */ /* nmrc? */ /* ----- */ - const char *s = FileNamePtr( fname ); + const char *s = FileNamePtr( fname ); - if( !strncmp( s, "nmrc_", 5 ) ) - return atoi( s + 5 ); + if( !strncmp( s, "nmrc_", 5 ) ) + return atoi( s + 5 ); /* ------------------ */ /* Otherwise use ldir */ @@ -131,7 +131,7 @@ static int FileNameToLayerNumber( int k; for(k=0; k= dnames.size() ) { printf("Oops - '%s' not in layer directory.\n", fname); exit( 42 ); @@ -145,19 +145,19 @@ return lnums[k]; static void PrintTransAndInv( FILE *of, const TAffine &tr ) { - TAffine in; + TAffine in; - in.InverseOf( tr ); + in.InverseOf( tr ); - fprintf( of, - "Fwd:%11.8f %11.8f %10.4f %11.8f %11.8f %10.4f\n", - tr.t[0], tr.t[1], tr.t[2], - tr.t[3], tr.t[4], tr.t[5] ); + fprintf( of, + "Fwd:%11.8f %11.8f %10.4f %11.8f %11.8f %10.4f\n", + tr.t[0], tr.t[1], tr.t[2], + tr.t[3], tr.t[4], tr.t[5] ); - fprintf( of, - "Rev:%11.8f %11.8f %10.4f %11.8f %11.8f %10.4f\n", - in.t[0], in.t[1], in.t[2], - in.t[3], in.t[4], in.t[5] ); + fprintf( of, + "Rev:%11.8f %11.8f %10.4f %11.8f %11.8f %10.4f\n", + in.t[0], in.t[1], in.t[2], + in.t[3], in.t[4], in.t[5] ); } /* --------------------------------------------------------------- */ @@ -167,51 +167,51 @@ static void PrintTransAndInv( FILE *of, const TAffine &tr ) // Find bounding box in global space. // static void GlobalBounds( - double &xmin, - double &xmax, - double &ymin, - double &ymax, - const vector &images, - int w, - int h ) + double &xmin, + double &xmax, + double &ymin, + double &ymax, + const vector &images, + int w, + int h ) { - if( xmin > BIG/2 ) { + if( xmin > BIG/2 ) { - int ni = images.size(); + int ni = images.size(); - for( int i = 0; i < ni; ++i ) { + for( int i = 0; i < ni; ++i ) { - int nt = images[i].tf.size(); + int nt = images[i].tf.size(); - for( int k = 1; k < nt; ++k ) { + for( int k = 1; k < nt; ++k ) { - const TAffine& T = images[i].tf[k]; + const TAffine& T = images[i].tf[k]; - if( !T.det() ) - continue; + if( !T.det() ) + continue; - vector pts; + vector pts; - pts.push_back( Point( 0.0, 0.0 ) ); - pts.push_back( Point( w-1, 0.0 ) ); - pts.push_back( Point( w-1, h-1 ) ); - pts.push_back( Point( 0.0, h-1 ) ); + pts.push_back( Point( 0.0, 0.0 ) ); + pts.push_back( Point( w-1, 0.0 ) ); + pts.push_back( Point( w-1, h-1 ) ); + pts.push_back( Point( 0.0, h-1 ) ); - for( int j = 0; j < 4; ++j ) { + for( int j = 0; j < 4; ++j ) { - T.Transform( pts[j] ); + T.Transform( pts[j] ); - xmin = fmin( xmin, pts[j].x ); - xmax = fmax( xmax, pts[j].x ); - ymin = fmin( ymin, pts[j].y ); - ymax = fmax( ymax, pts[j].y ); - } - } - } - } + xmin = fmin( xmin, pts[j].x ); + xmax = fmax( xmax, pts[j].x ); + ymin = fmin( ymin, pts[j].y ); + ymax = fmax( ymax, pts[j].y ); + } + } + } + } - printf( "Bounds of global image: x=[%f %f] y=[%f %f].\n", - xmin, xmax, ymin, ymax ); + printf( "Bounds of global image: x=[%f %f] y=[%f %f].\n", + xmin, xmax, ymin, ymax ); } /* --------------------------------------------------------------- */ @@ -225,96 +225,96 @@ static void GlobalBounds( // alignment easier. // static void OffsetCoords( - double &xmin, - double &xmax, - double &ymin, - double &ymax, - vector &images, - vector &x1, - vector &x2, - vector &y1, - vector &y2, - int x0, - int y0, - int xsize, - int ysize ) + double &xmin, + double &xmax, + double &ymin, + double &ymax, + vector &images, + vector &x1, + vector &x2, + vector &y1, + vector &y2, + int x0, + int y0, + int xsize, + int ysize ) { - int xfl = int(floor( xmin )); - int yfl = int(floor( ymin )); + int xfl = int(floor( xmin )); + int yfl = int(floor( ymin )); // bounds - xmin -= xfl; - xmax -= xfl; - ymin -= yfl; - ymax -= yfl; + xmin -= xfl; + xmax -= xfl; + ymin -= yfl; + ymax -= yfl; - printf( "Bounds of global image: x=[%f %f] y=[%f %f].\n", - xmin, xmax, ymin, ymax ); + printf( "Bounds of global image: x=[%f %f] y=[%f %f].\n", + xmin, xmax, ymin, ymax ); - if( xsize != -1 ) { - xmax = xsize; - ymax = ysize; - } + if( xsize != -1 ) { + xmax = xsize; + ymax = ysize; + } // transforms - xfl = -(xfl + x0); - yfl = -(yfl + y0); + xfl = -(xfl + x0); + yfl = -(yfl + y0); - int ni = images.size(); + int ni = images.size(); - for( int i = 0; i < ni; ++i ) { + for( int i = 0; i < ni; ++i ) { - int nt = images[i].tf.size(); + int nt = images[i].tf.size(); - for( int k = 1; k < nt; ++k ) { + for( int k = 1; k < nt; ++k ) { - TAffine& T = images[i].tf[k]; + TAffine& T = images[i].tf[k]; - if( !T.det() ) - continue; + if( !T.det() ) + continue; - T.AddXY( xfl, yfl ); - images[i].inv[k].InverseOf( T ); - } - } + T.AddXY( xfl, yfl ); + images[i].inv[k].InverseOf( T ); + } + } // debugging - print transforms #if 0 - for( int i = 0; i < ni; ++i ) { + for( int i = 0; i < ni; ++i ) { - int nt = images[i].tf.size(); + int nt = images[i].tf.size(); - for( int k = 1; k < nt; ++k ) { + for( int k = 1; k < nt; ++k ) { - const TAffine& T = images[i].tf[k]; + const TAffine& T = images[i].tf[k]; - if( !T.det() ) - continue; + if( !T.det() ) + continue; - printf( - "Post offset: image %d, layer %d tf[%d]" - " = %f %f %f %f %f %f\n", - i, images[i].layer, k, - T.t[0], T.t[1], T.t[2], - T.t[3], T.t[4], T.t[5] ); - } - } + printf( + "Post offset: image %d, layer %d tf[%d]" + " = %f %f %f %f %f %f\n", + i, images[i].layer, k, + T.t[0], T.t[1], T.t[2], + T.t[3], T.t[4], T.t[5] ); + } + } #endif // correspondence points - int n = x1.size(); + int n = x1.size(); - for( int i = 0; i < n; ++i ) { + for( int i = 0; i < n; ++i ) { - x1[i] += xfl; - x2[i] += xfl; - y1[i] += yfl; - y2[i] += yfl; - } + x1[i] += xfl; + x2[i] += xfl; + y1[i] += yfl; + y2[i] += yfl; + } } /* --------------------------------------------------------------- */ @@ -323,31 +323,31 @@ static void OffsetCoords( static uint8* LoadNormImg( const char *name, uint32 &w, uint32 &h ) { - uint8* ras = Raster8FromAny( name, w, h ); + uint8* ras = Raster8FromAny( name, w, h ); - if( !strstr( name, ".mrc" ) ) { + if( !strstr( name, ".mrc" ) ) { - double mean, std; - int np = w * h; - MeanStd m; + double mean, std; + int np = w * h; + MeanStd m; - for( int i = 0; i < np; ++i ) - m.Element( double(ras[i]) ); + for( int i = 0; i < np; ++i ) + m.Element( double(ras[i]) ); - m.Stats( mean, std ); + m.Stats( mean, std ); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - int pix = RND( 127 + (ras[i] - mean) / std * 30.0 ); + int pix = RND( 127 + (ras[i] - mean) / std * 30.0 ); - if( pix > 255 ) - pix = 255; + if( pix > 255 ) + pix = 255; - ras[i] = pix; - } - } + ras[i] = pix; + } + } - return ras; + return ras; } /* --------------------------------------------------------------- */ @@ -356,14 +356,14 @@ static uint8* LoadNormImg( const char *name, uint32 &w, uint32 &h ) static void PrintMagnitude( const vector &X ) { - int k = X.size() - 6; + int k = X.size() - 6; - if( k >= 0 ) { + if( k >= 0 ) { - double mag = sqrt( X[k]*X[k] + X[k+1]*X[k+1] ); + double mag = sqrt( X[k]*X[k] + X[k+1]*X[k+1] ); - printf( "Final magnitude is %g\n", mag ); - } + printf( "Final magnitude is %g\n", mag ); + } } /* --------------------------------------------------------------- */ @@ -374,7 +374,7 @@ static void PrintMagnitude( const vector &X ) // static bool lr( int sx, int sy, void *arg ) { - return sx == 21 && sy == 21; + return sx == 21 && sy == 21; } /* --------------------------------------------------------------- */ @@ -385,7 +385,7 @@ static bool lr( int sx, int sy, void *arg ) // static bool lc( int c1, int c2, void *arg ) { - return true; + return true; } /* --------------------------------------------------------------- */ @@ -398,12 +398,12 @@ static bool lc( int c1, int c2, void *arg ) // is part of the image i1, patch patch1. // static void CommonPoint( - vector &spots, - const vector &images, - Point pt, - int i1, - int patch1, - int out_layer ) + vector &spots, + const vector &images, + Point pt, + int i1, + int patch1, + int out_layer ) { Point p1 = pt; printf("image %d, global x,y= %f %f\n", i1, p1.x, p1.y); @@ -443,12 +443,12 @@ glob_spot s; // this will contain all the detailed info s.gpt = pt; for(int i=0; i ftc; // cache for Fourier transform @@ -480,11 +480,11 @@ for(int i=0; i dx, dy= %f, %f, corr %f\n\n", pt.x, dx, dy, co); if( co < 0.7 ) { @@ -506,8 +506,8 @@ if( s.which.size() > 1 ) { printf("More than one image for global point (%f %f)\n", pt.x, pt.y); // and add all the matching spots to the list for each image for(int i=0; i 126 ) - continue; + if( ch < 32 || ch > 126 ) + continue; - // draw as N times original size - //printf("draw character '%c' at %d, %d\n", ch, x, y); + // draw as N times original size + //printf("draw character '%c' at %d, %d\n", ch, x, y); - ch -= 32; + ch -= 32; - int N = 3; + int N = 3; - for( int dy = 0; dy < 7; ++dy ) { + for( int dy = 0; dy < 7; ++dy ) { - for( int dx = 0; dx < 5; ++dx ) { + for( int dx = 0; dx < 5; ++dx ) { - bool bit = (font5x7[ch][dy] & (1 << (4-dx))); + bool bit = (font5x7[ch][dy] & (1 << (4-dx))); - if( !bit ) - continue; + if( !bit ) + continue; - int bx = x + dx*N; - int by = y + dy*N; + int bx = x + dx*N; + int by = y + dy*N; - // draw an N x N box at (bx, by) + // draw an N x N box at (bx, by) - for( int j = 0; j < N; ++j ) { + for( int j = 0; j < N; ++j ) { - for( int k = 0; k < N; ++k ) { + for( int k = 0; k < N; ++k ) { - int m = bx+j + w*(by+k); + int m = bx+j + w*(by+k); - if( m < w*h ) - raster[m] = 0xFF; - } - } - } - } + if( m < w*h ) + raster[m] = 0xFF; + } + } + } + } - x += 6*N; - } + x += 6*N; + } } /* --------------------------------------------------------------- */ @@ -683,10 +683,10 @@ static double PseudoAngle( double y, double x ) { bool xish = fabs(y) <= fabs(x); // closer to x than y axis if( x > 0 && xish ) - return y/x; + return y/x; if( y > 0 ) { if( xish ) - return 4 + y/x; + return 4 + y/x; else return 2 - x/y; } @@ -720,45 +720,45 @@ vector setback; // pixels we will set back to 0 when we are done int nholes = 0; for(int i=start; i < np; i++) { if( map[i] == 0 ) { - start = i; // so next time resume here - stack st; - st.push(i); - vector boundary( 257, 0 ); // histogram of what we hit. + start = i; // so next time resume here + stack st; + st.push(i); + vector boundary( 257, 0 ); // histogram of what we hit. vector pixels; // 0 valued pixels in this area - while( !st.empty() ) { - int j = st.top(); st.pop(); + while( !st.empty() ) { + int j = st.top(); st.pop(); if( map[j] == 0 ) { - map[j] = 255; // so we won't get it again + map[j] = 255; // so we won't get it again pixels.push_back(j); - int y = j / w; - int x = j - w * y; - if( x-1 >= 0 ) st.push(j-1); else boundary[256]++; + int y = j / w; + int x = j - w * y; + if( x-1 >= 0 ) st.push(j-1); else boundary[256]++; if( x+1 < w ) st.push(j+1); else boundary[256]++; if( y-1 >= 0 ) st.push(j-w); else boundary[256]++; if( y+1 < h ) st.push(j+w); else boundary[256]++; - } + } else {// map value is not 0, add what we ran into to the set of boundary values - if( map[j] != 255 ) boundary[map[j]]++; - } - } + if( map[j] != 255 ) boundary[map[j]]++; + } + } // how many different things did we hit? And what was one of them? int howmany = 0, what = 0; for( int k = 0; k < 256; ++k ) { - if( boundary[k] != 0 ) { - howmany++; + if( boundary[k] != 0 ) { + howmany++; what = k; - } - } + } + } if( howmany == 1 ) { // then we have a hole, or a gap starting at a boundary - for( int k = 0; k < pixels.size(); ++k ) - map[pixels[k]] = what; + for( int k = 0; k < pixels.size(); ++k ) + map[pixels[k]] = what; nholes++; - } - else { // not a pure hole. record pixel values to set back later + } + else { // not a pure hole. record pixel values to set back later for(int k=0; k &images, - int im, - int patch, - Point p1, - vector &tris, - vector &gvtx, - int N, - int *which, - double *amts ) + vector &images, + int im, + int patch, + Point p1, + vector &tris, + vector &gvtx, + int N, + int *which, + double *amts ) { Point p = p1; images[im].tf[patch].Transform( p ); int first_tri = images[im].FirstTriangle + (patch-1)*N; // since N triangle per patch, and - // first one is #1 + // first one is #1 for(int i=first_tri; i < first_tri+N; i++) { if( Inside(tris[i], gvtx, p) ) { - printf("Got one - Point %f %f inside triangle (%f %f) (%f %f) (%f %f)\n", - p.x, p.y, - gvtx[tris[i].v[0]].x, gvtx[tris[i].v[0]].y, - gvtx[tris[i].v[1]].x, gvtx[tris[i].v[1]].y, - gvtx[tris[i].v[2]].x, gvtx[tris[i].v[2]].y ); + printf("Got one - Point %f %f inside triangle (%f %f) (%f %f) (%f %f)\n", + p.x, p.y, + gvtx[tris[i].v[0]].x, gvtx[tris[i].v[0]].y, + gvtx[tris[i].v[1]].x, gvtx[tris[i].v[1]].y, + gvtx[tris[i].v[2]].x, gvtx[tris[i].v[2]].y ); // find barycentric coordinates (linear combo of the three vertices amts[0] = tris[i].a[0][0]*p.x + tris[i].a[0][1]*p.y + tris[i].a[0][2]*1.0; amts[1] = tris[i].a[1][0]*p.x + tris[i].a[1][1]*p.y + tris[i].a[1][2]*1.0; amts[2] = tris[i].a[2][0]*p.x + tris[i].a[2][1]*p.y + tris[i].a[2][2]*1.0; printf("Barycentric coords: %f %f %f\n", amts[0], amts[1], amts[2] ); for(int k=0; k<3; k++) - which[k] = tris[i].v[k]; - return; - } + which[k] = tris[i].v[k]; + return; + } } printf("Oops - no triangle for point (%f %f)\n", p.x, p.y); exit( 42 ); @@ -839,18 +839,18 @@ exit( 42 ); // Write triangles out to a text file in a format gnuplot can read. // static void WriteTriangles( - const char *name, - vector &tris, - vector &pts ) + const char *name, + vector &tris, + vector &pts ) { FILE *ft = FileOpenOrDie( name, "w" ); for(int i=0; i &SPmapping ) + uint16 *test, + int w, + int h, + int &MaxSPUsed, + vector &SPmapping ) { int biggest = -1; vector vals(65536,0); @@ -926,10 +926,10 @@ int base = MaxSPUsed; // will add this to all int n=0; for(int i=1; i<65536; i++) { // 0 always maps to 0 if( vals[i] != 0 ) { // this value was used - MaxSPUsed++; + MaxSPUsed++; SPmapping[i] = MaxSPUsed; - n++; - } + n++; + } } printf("--- %d different values were used\n", n); // Now do the remapping @@ -945,11 +945,11 @@ for(int i=0; i &SPmapping ) + uint32 *test, + int w, + int h, + int &MaxSPUsed, + vector &SPmapping ) { // First find the biggest int biggest = -1; @@ -958,7 +958,7 @@ for(int i=0; i &tfs, - int xmin, - int ymin, - int xmax, - int ymax ) + uint32 w, + uint32 h, + vector &tfs, + int xmin, + int ymin, + int xmax, + int ymax ) { // make the four corners vector corners; @@ -1019,7 +1019,7 @@ for(int j=1; j &pts, - const Point ¢er, - double r, - double delta, - uint32 w, - uint32 h ) + vector &pts, + const Point ¢er, + double r, + double delta, + uint32 w, + uint32 h ) { - double lx = center.x - r; - double rx = center.x + r; - double by = center.y - r; - double ty = center.y + r; - vector ppts; // potential points - - for( double d = -r; d <= r; d += delta ) { - - ppts.push_back( Point( lx, center.y + d ) ); - ppts.push_back( Point( rx, center.y + d ) ); - ppts.push_back( Point( center.x + d, by ) ); - ppts.push_back( Point( center.x + d, ty ) ); - } + double lx = center.x - r; + double rx = center.x + r; + double by = center.y - r; + double ty = center.y + r; + vector ppts; // potential points + + for( double d = -r; d <= r; d += delta ) { + + ppts.push_back( Point( lx, center.y + d ) ); + ppts.push_back( Point( rx, center.y + d ) ); + ppts.push_back( Point( center.x + d, by ) ); + ppts.push_back( Point( center.x + d, ty ) ); + } // Now push back upper right corner, which might not be covered. - ppts.push_back( Point( rx, ty ) ); + ppts.push_back( Point( rx, ty ) ); // Now keep only those within the image // (can happen if image is a rectangle, not a square) - int n = ppts.size(); + int n = ppts.size(); - for( int i = 0; i < n; ++i ) { + for( int i = 0; i < n; ++i ) { - if( ppts[i].x >= 0.0 && - ppts[i].x <= w-1 && - ppts[i].y >= 0.0 && - ppts[i].y <= h-1 ) { + if( ppts[i].x >= 0.0 && + ppts[i].x <= w-1 && + ppts[i].y >= 0.0 && + ppts[i].y <= h-1 ) { - pts.push_back( ppts[i] ); - } - } + pts.push_back( ppts[i] ); + } + } } /* --------------------------------------------------------------- */ @@ -1183,70 +1183,70 @@ static void PointsInRing( // distortions are. // static void FillInFromCenterOut( - vector &imap, - vector &PatchFrom, - int nx, - int ny, - int w, - int h, // size of images coming in - double delta_image_space, // smallest size that maps to each pixel on output - vector &images, // the images - vector &relevant_images ) // the ones that are used among them + vector &imap, + vector &PatchFrom, + int nx, + int ny, + int w, + int h, // size of images coming in + double delta_image_space, // smallest size that maps to each pixel on output + vector &images, // the images + vector &relevant_images ) // the ones that are used among them { // find the center of each picture. May not be integer Point center((w-1)/2.0, (h-1)/2.0); int report = 100; for(double r=0.0; r <= max(center.x,center.y)+0.0001; r += delta_image_space) { if( r >= report ) { - printf("Starting radius %f\n", r); - report += 100; - } + printf("Starting radius %f\n", r); + report += 100; + } //compute a ring of radius R vector pts; PointsInRing(pts, center, r, delta_image_space, w, h); // Now transform this by all relevant images for(int k=0; k= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) - continue; - images[i].tf[patch].Transform( p ); // change to global coordinates - ix = ROUND(p.x); - iy = ROUND(p.y); - if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) - continue; // outside the image - //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); - uint32 nn = ix + uint32(iy)*uint32(nx); // index into array - if( imap[nn] == 0 ) { - imap[nn] = k+1; // this pixel will be set by the kth relevant picture - PatchFrom[nn] = patch; - } - else { // already set, but we still might be better (because of finite - // grid in source, rounding to int, ordering ). - Point pt_us = Point(ix,iy); - Point pt_ot = pt_us; - // transform back into original frames. - int oi = relevant_images[imap[nn]-1]; // other image - int op = PatchFrom[nn]; // other patch - images[oi].inv[op].Transform( pt_ot ); - images[i].inv[patch].Transform( pt_us ); - - double d_us = max(abs(pt_us.x-center.x), abs(pt_us.y-center.y)); // L-infinity norm - double d_ot = max(abs(pt_ot.x-center.x), abs(pt_ot.y-center.y)); // L-infinity norm - if( d_us < d_ot ) { - //printf("It CAN happen... d_us= %f, d_ot= %f\n", d_us, d_ot); - imap[nn] = k+1; // this pixel will be set by the ith picture - PatchFrom[nn] = patch; - } - } - } - } + int i = relevant_images[k]; + for(int j=0; j= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) + continue; + images[i].tf[patch].Transform( p ); // change to global coordinates + ix = ROUND(p.x); + iy = ROUND(p.y); + if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) + continue; // outside the image + //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); + uint32 nn = ix + uint32(iy)*uint32(nx); // index into array + if( imap[nn] == 0 ) { + imap[nn] = k+1; // this pixel will be set by the kth relevant picture + PatchFrom[nn] = patch; + } + else { // already set, but we still might be better (because of finite + // grid in source, rounding to int, ordering ). + Point pt_us = Point(ix,iy); + Point pt_ot = pt_us; + // transform back into original frames. + int oi = relevant_images[imap[nn]-1]; // other image + int op = PatchFrom[nn]; // other patch + images[oi].inv[op].Transform( pt_ot ); + images[i].inv[patch].Transform( pt_us ); + + double d_us = max(abs(pt_us.x-center.x), abs(pt_us.y-center.y)); // L-infinity norm + double d_ot = max(abs(pt_ot.x-center.x), abs(pt_ot.y-center.y)); // L-infinity norm + if( d_us < d_ot ) { + //printf("It CAN happen... d_us= %f, d_ot= %f\n", d_us, d_ot); + imap[nn] = k+1; // this pixel will be set by the ith picture + PatchFrom[nn] = patch; + } + } + } + } } } @@ -1262,11 +1262,11 @@ for(double r=0.0; r <= max(center.x,center.y)+0.0001; r += delta_image_space) { // class NameSorter{ public: - char *name; - int num; + char *name; + int num; public: - bool operator < ( const NameSorter &rhs ) const - {return strcmp( name, rhs.name ) < 0;}; + bool operator < ( const NameSorter &rhs ) const + {return strcmp( name, rhs.name ) < 0;}; }; /* --------------------------------------------------------------- */ @@ -1275,7 +1275,7 @@ class NameSorter{ static bool NameSortFn( NameSorter a, NameSorter b ) { - return strcmp( a.name, b.name ) > 0; + return strcmp( a.name, b.name ) > 0; } /* --------------------------------------------------------------- */ @@ -1283,15 +1283,15 @@ static bool NameSortFn( NameSorter a, NameSorter b ) /* --------------------------------------------------------------- */ static void FillInMatlabOrder( - vector &imap, - vector &PatchFrom, - int nx, - int ny, - int w, - int h, // size of images coming in - double delta_image_space, // smallest size that maps to each pixel on output - vector &images, // the images - vector &relevant_images) // the ones that are used among them + vector &imap, + vector &PatchFrom, + int nx, + int ny, + int w, + int h, // size of images coming in + double delta_image_space, // smallest size that maps to each pixel on output + vector &images, // the images + vector &relevant_images) // the ones that are used among them { // find the center of each picture. May not be integer Point center((w-1)/2.0, (h-1)/2.0); @@ -1311,36 +1311,36 @@ for(int kk=0; kk= report ) { - printf("Starting radius %f\n", r); - report += 500; - } - //compute a ring of radius R - vector pts; - PointsInRing(pts, center, r, delta_image_space, w, h); - // Now transform this by all relevant images - for(int j=0; j= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) - continue; - images[i].tf[patch].Transform( p ); // change to global coordinates - ix = ROUND(p.x); - iy = ROUND(p.y); - if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) - continue; // outside the image - //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); - uint32 nn = ix + uint32(iy)*uint32(nx); // index into array - if( imap[nn] == 0 ) { - imap[nn] = k+1; // this pixel will be set by the kth relevant picture - PatchFrom[nn] = patch; - } - } - } + if( r >= report ) { + printf("Starting radius %f\n", r); + report += 500; + } + //compute a ring of radius R + vector pts; + PointsInRing(pts, center, r, delta_image_space, w, h); + // Now transform this by all relevant images + for(int j=0; j= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) + continue; + images[i].tf[patch].Transform( p ); // change to global coordinates + ix = ROUND(p.x); + iy = ROUND(p.y); + if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) + continue; // outside the image + //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); + uint32 nn = ix + uint32(iy)*uint32(nx); // index into array + if( imap[nn] == 0 ) { + imap[nn] = k+1; // this pixel will be set by the kth relevant picture + PatchFrom[nn] = patch; + } + } + } } } @@ -1370,18 +1370,18 @@ for(pass=1; pass<=MAX_PASS; pass++) { if( stat(name, &buf) ) { // error, assume directory does not exist if( mkdir(name,0775) ) - printf("mkdir('%s') failed.\n", name); + printf("mkdir('%s') failed.\n", name); else // it worked, stop trying - break; + break; } else { // was able to stat the file; see if it's a directory if( !S_ISDIR(buf.st_mode) ) { - printf("File '%s' exists, but is not a directory.\n", name); - exit( 42 ); - } + printf("File '%s' exists, but is not a directory.\n", name); + exit( 42 ); + } else - break; // file exists and is a directory - } + break; // file exists and is a directory + } } if( pass > MAX_PASS ) exit( 42 ); @@ -1403,14 +1403,14 @@ dir_cache.insert(string(name)); // so each pixel can get a contribution from 1, 2, or 4 pixels. // static void CopyRaster( - uint8 *dest, - int w, - int h, - int dx, - int dy, - uint8 *src, - int sw, - int sh ) + uint8 *dest, + int w, + int h, + int dx, + int dy, + uint8 *src, + int sw, + int sh ) { // Do this a brute force way. Go through all the src pixels, mapping each to dest, // and counting how many map to each. Then average. @@ -1424,17 +1424,17 @@ int swt = sw & (~1); // create copies that are rounded down to nearest even int sht = sh & (~1); // stands for "source height truncated" for(int y=0; y &dir_cache ) + string rav_name, + int section, + int level, + int row, + int col, + set &dir_cache ) { // open the 4 relevant tiles - (row,col), (row+1,col), (row,col+1), and (row+1,col+1) uint32 w1, h1, w2, h2, w3, h3, w4, h4; @@ -1566,12 +1566,12 @@ return 1; // Condenses 4 tiles into 1, for SuperPixels. // static int WriteSummaryTileSP( - string rav_name, - int section, - int level, - int row, - int col, - set &dir_cache ) + string rav_name, + int section, + int level, + int row, + int col, + set &dir_cache ) { // open the 4 relevant tiles - (row,col), (row+1,col), (row,col+1), and (row+1,col+1) uint32 w1, h1, w2, h2, w3, h3, w4, h4; @@ -1639,9 +1639,9 @@ return 1; //Create smaller tiles, for images. // static void CreateLevelNTiles( - string rav_name, - int section, - set &dir_cache ) + string rav_name, + int section, + set &dir_cache ) { int at_this_level = 1; // so we loop at least once for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for trillions of tiles @@ -1657,7 +1657,7 @@ for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for tril wrote += stat; } at_this_level += wrote; - } + } printf("At level %d, wrote %d tiles\n", level, at_this_level); } } @@ -1669,9 +1669,9 @@ for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for tril //Create smaller tiles, for SuperPixels. // void CreateLevelNTilesSP( - string rav_name, - int section, - set &dir_cache ) + string rav_name, + int section, + set &dir_cache ) { int at_this_level = 1; // so we loop at least once for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for trillions of tiles @@ -1687,7 +1687,7 @@ for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for tril wrote += stat; } at_this_level += wrote; - } + } printf("SP:At level %d, wrote %d tiles\n", level, at_this_level); } } @@ -1699,49 +1699,49 @@ for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for tril // Updates the meta-data file. For now, just writes. // static void UpdateMetaData( - const char *name, - int section, - int w, - int h ) + const char *name, + int section, + int w, + int h ) { - int zmin, zmax; - FILE *fd = fopen( name, "r" ); + int zmin, zmax; + FILE *fd = fopen( name, "r" ); - if( fd ) { + if( fd ) { - CLineScan LS; - ssize_t read; + CLineScan LS; + ssize_t read; - while( (read = LS.Get( fd )) > 0 ) { + while( (read = LS.Get( fd )) > 0 ) { - //printf( "Retrieved line of length %zu :\n", read ); + //printf( "Retrieved line of length %zu :\n", read ); - if( !strncmp( LS.line, "zmin=", 5 ) ) - zmin = min( section, atoi(LS.line+5) ); - if( !strncmp( LS.line, "zmax=", 5 ) ) - zmax = max( section, atoi(LS.line+5) ); - } + if( !strncmp( LS.line, "zmin=", 5 ) ) + zmin = min( section, atoi(LS.line+5) ); + if( !strncmp( LS.line, "zmax=", 5 ) ) + zmax = max( section, atoi(LS.line+5) ); + } - fclose( fd ); - } - else { // no file yet; make one with one layer - zmin = section; - zmax = section; - } + fclose( fd ); + } + else { // no file yet; make one with one layer + zmin = section; + zmax = section; + } // Now write the new file - fd = FileOpenOrDie( name, "w" ); + fd = FileOpenOrDie( name, "w" ); - fprintf( fd, "version=1\n" ); - fprintf( fd, "width=%d\n", w ); - fprintf( fd, "height=%d\n", h ); - fprintf( fd, "zmin=%d\n", zmin ); - fprintf( fd, "zmax=%d\n", zmax ); - fprintf( fd, "superpixel-format=RGBA\n" ); - fprintf( fd, "channels=\"g;s\"\n" ); + fprintf( fd, "version=1\n" ); + fprintf( fd, "width=%d\n", w ); + fprintf( fd, "height=%d\n", h ); + fprintf( fd, "zmin=%d\n", zmin ); + fprintf( fd, "zmax=%d\n", zmax ); + fprintf( fd, "superpixel-format=RGBA\n" ); + fprintf( fd, "channels=\"g;s\"\n" ); - fclose( fd ); + fclose( fd ); } /* --------------------------------------------------------------- */ @@ -1751,11 +1751,11 @@ static void UpdateMetaData( // Writes the lowest level image tiles. // static int WriteImageTiles( - const string rav_name, - int section, - const uint8 *image, - int w, - int h ) + const string rav_name, + int section, + const uint8 *image, + int w, + int h ) { set dir_cache; // names of directories already created string base_name = rav_name; @@ -1775,30 +1775,30 @@ for(int row = 0; row*1024 < h; row++) { sprintf(fname, "%s/%d", base_name.c_str(), row); MakeDirExist(fname, dir_cache); for(int col = 0; col*1024 < w; col++) { - int xmin = col*1024; // bottom scan line - int xmax = min(xmin+1023, w-1); // top scan line + int xmin = col*1024; // bottom scan line + int xmax = min(xmin+1023, w-1); // top scan line sprintf(fname, "%s/%d/%d", base_name.c_str(), row, col); // make the dir for the column - MakeDirExist(fname, dir_cache); + MakeDirExist(fname, dir_cache); sprintf(fname, "%s/%d/%d/g", base_name.c_str(), row, col); // and the grey scale underneath - MakeDirExist(fname, dir_cache); + MakeDirExist(fname, dir_cache); // now, copy the portion of the image from xmin..xmax to ymin..ymax; int new_w = xmax - xmin + 1; int n = 0; - for(int y=ymin; y<=ymax; y++) { + for(int y=ymin; y<=ymax; y++) { uint32 m = uint32(xmin) + uint32(y)*uint32(w); // location of first byte on scan line y of 'image' - for(int x=0; x < new_w; x++) - raster[n++] = image[m++]; - } + for(int x=0; x < new_w; x++) + raster[n++] = image[m++]; + } int dir = section/1000; if( dir == 0 ) // first layers are written in the root directory - sprintf(fname,"%s/%d/%d/g/%03d.png", base_name.c_str(), row, col, section); + sprintf(fname,"%s/%d/%d/g/%03d.png", base_name.c_str(), row, col, section); else { // need another layer of directories - sprintf(fname,"%s/%d/%d/g/%d", base_name.c_str(), row, col, dir*1000); - MakeDirExist(fname, dir_cache); - sprintf(fname,"%s/%d/%d/g/%d/%03d.png", base_name.c_str(), row, col, dir*1000, section); - } + sprintf(fname,"%s/%d/%d/g/%d", base_name.c_str(), row, col, dir*1000); + MakeDirExist(fname, dir_cache); + sprintf(fname,"%s/%d/%d/g/%d/%03d.png", base_name.c_str(), row, col, dir*1000, section); + } Raster8ToPng8( fname, raster, new_w, ymax-ymin+1 ); - } + } } free(raster); @@ -1814,11 +1814,11 @@ return 0; // Writes the lowest level SP tiles. // static int WriteSPTiles( - const string rav_name, - int section, - uint32 *image, - int w, - int h ) + const string rav_name, + int section, + uint32 *image, + int w, + int h ) { set dir_cache; // names of directories already created string base_name = rav_name; @@ -1838,30 +1838,30 @@ for(int row = 0; row*1024 < h; row++) { sprintf(fname, "%s/%d", base_name.c_str(), row); MakeDirExist(fname, dir_cache); for(int col = 0; col*1024 < w; col++) { - int xmin = col*1024; // bottom scan line - int xmax = min(xmin+1023, w-1); // top scan line + int xmin = col*1024; // bottom scan line + int xmax = min(xmin+1023, w-1); // top scan line sprintf(fname, "%s/%d/%d", base_name.c_str(), row, col); // make the dir for the column - MakeDirExist(fname, dir_cache); + MakeDirExist(fname, dir_cache); sprintf(fname, "%s/%d/%d/s", base_name.c_str(), row, col); // and the sp map underneath - MakeDirExist(fname, dir_cache); + MakeDirExist(fname, dir_cache); // now, copy the portion of the image from xmin..xmax to ymin..ymax; int new_w = xmax - xmin + 1; int n = 0; - for(int y=ymin; y<=ymax; y++) { + for(int y=ymin; y<=ymax; y++) { uint32 m = uint32(xmin) + uint32(y)*uint32(w); // location of first byte on scan line y of 'image' - for(int x=0; x < new_w; x++) - raster[n++] = image[m++]; - } + for(int x=0; x < new_w; x++) + raster[n++] = image[m++]; + } int dir = section/1000; if (dir == 0) // first layers are written in the root directory - sprintf(fname,"%s/%d/%d/s/%03d.png", base_name.c_str(), row, col, section); + sprintf(fname,"%s/%d/%d/s/%03d.png", base_name.c_str(), row, col, section); else { // need another layer of directories - sprintf(fname,"%s/%d/%d/s/%d", base_name.c_str(), row, col, dir*1000); - MakeDirExist(fname, dir_cache); - sprintf(fname,"%s/%d/%d/s/%d/%03d.png", base_name.c_str(), row, col, dir*1000, section); - } + sprintf(fname,"%s/%d/%d/s/%d", base_name.c_str(), row, col, dir*1000); + MakeDirExist(fname, dir_cache); + sprintf(fname,"%s/%d/%d/s/%d/%03d.png", base_name.c_str(), row, col, dir*1000, section); + } Raster32ToPngRGBA( fname, raster, new_w, ymax-ymin+1 ); - } + } } free(raster); @@ -1878,38 +1878,38 @@ return 0; class Bookmark { public: - string text; - Point pt; - int z; - int body_id; - int image_number; + string text; + Point pt; + int z; + int body_id; + int image_number; public: - bool operator < ( const Bookmark &rhs ) const - {return image_number < rhs.image_number;}; + bool operator < ( const Bookmark &rhs ) const + {return image_number < rhs.image_number;}; }; class Partner { public: - double confidence; - Point pt; - int body_id; - int z; + double confidence; + Point pt; + int body_id; + int z; }; class TBar { public: - string status; - double confidence; - Point pt; - int z; - vector partners; - int body_id; - int image_number; + string status; + double confidence; + Point pt; + int z; + vector partners; + int body_id; + int image_number; public: - bool operator < ( const TBar &rhs ) const - {return image_number < rhs.image_number;}; + bool operator < ( const TBar &rhs ) const + {return image_number < rhs.image_number;}; }; /* --------------------------------------------------------------- */ @@ -1917,9 +1917,9 @@ class TBar { /* --------------------------------------------------------------- */ static bool ReadBookmarks( - char *fname, - int section, - vector &bookmarks ) + char *fname, + int section, + vector &bookmarks ) { Json::Value root; // will contains the root value after parsing. Json::Reader reader; @@ -1960,10 +1960,10 @@ for( unsigned int i = 0; i < nd; ++i ) { Json::Value lo = v["location"]; b.z = lo[2u].asInt(); if( b.z == section ) { - b.pt.x = lo[0u].asDouble(); - b.pt.y = lo[1u].asDouble(); + b.pt.x = lo[0u].asDouble(); + b.pt.y = lo[1u].asDouble(); bookmarks.push_back(b); - } + } } return true; } @@ -1973,9 +1973,9 @@ return true; /* --------------------------------------------------------------- */ static bool ReadSynAnnot( - char *fname, - int section, - vector &tbs ) + char *fname, + int section, + vector &tbs ) { Json::Value root; // will contains the root value after parsing. Json::Reader reader; @@ -2017,27 +2017,27 @@ for( unsigned int i = 0; i < nd; ++i ) { TBar tb; tb.z = lo[2u].asInt(); if( tb.z == section ) { - tb.status = t["status"].asString(); - tb.confidence = t["confidence"].asDouble(); - tb.body_id = t["body ID"].asInt(); - tb.pt.x = lo[0u].asDouble(); - tb.pt.y = lo[1u].asDouble(); - //printf("status is %s, confidence %f, loc %.1f,%lf,%d, %d partners\n", - //tb.status.c_str(), tb.confidence, tb.pt.x, tb.pt.y, tb.z, part.size() ); - for(int j=0; j &images, - bool Warp, - vector &tmap, - vector &result ) + const char *name, + char *root, + int section, + int image_no, + vector &images, + bool Warp, + vector &tmap, + vector &result ) { uint32 w = images[image_no].w; uint32 h = images[image_no].h; @@ -2080,11 +2080,11 @@ if( strstr(name, "annotations-synapse") != NULL ) { Point p = tbs[j].pt; int ix = int(p.x); int iy = int(p.y); - // make sure it's legal - if( ix < 0 || ix >= w || iy < 0 || iy >= h ) { - printf("Synapse outside diagram?? %d %d %d %d\n", ix, w, iy, h); - continue; - } + // make sure it's legal + if( ix < 0 || ix >= w || iy < 0 || iy >= h ) { + printf("Synapse outside diagram?? %d %d %d %d\n", ix, w, iy, h); + continue; + } int patch = images[image_no].foldmap[ix + w*iy]; // There can be small patches which were not used, so need to check for legality here // // No longer needed since we compress patches and foldmaps on input @@ -2096,13 +2096,13 @@ if( strstr(name, "annotations-synapse") != NULL ) { else { //we are warping int sector = tmap[ix + w*iy]; t = images[image_no].sectors[patch][sector]; - } + } t.Transform( p ); tbs[j].pt = p; - for(int m=0; m &images, - bool Warp, - vector &tmap, - vector &result ) + const char *name, + char *root, + int section, + int image_no, + vector &images, + bool Warp, + vector &tmap, + vector &result ) { uint32 w = images[image_no].w; uint32 h = images[image_no].h; @@ -2146,7 +2146,7 @@ if( strstr(name, "annotations-bookmarks") != NULL ) { // one, then look up the reverse transformation from global space, and find // the one that maps here. for(int j=0; j= images[i].tf.size() || images[i].tf[patch].det() == 0.0) continue; TAffine t; - if( !Warp ) // just one transform per image - t = images[image_no].tf[patch]; // change to global coordinates + if( !Warp ) // just one transform per image + t = images[image_no].tf[patch]; // change to global coordinates else { //we are warping - int sector = tmap[ix+iy*w]; + int sector = tmap[ix+iy*w]; t = images[image_no].sectors[patch][sector]; } t.Transform( p ); bookmarks[j].pt = p; - result.push_back(bookmarks[j]); - } + result.push_back(bookmarks[j]); + } } return true; } @@ -2210,28 +2210,28 @@ vectornoa; // non-option arguments for(int i=1; i= 2 ) { if( sscanf(noa[1],"%d,%d,%d,%d", &x0, &y0, &xsize, &ysize) != 4 ) { - printf("Expected x0,y0,xsize,ysize, got '%s'\n", noa[1]); - exit( 42 ); - } + printf("Expected x0,y0,xsize,ysize, got '%s'\n", noa[1]); + exit( 42 ); + } } int lspec1=-1, lspec2; //layers specified by the user if( noa.size() >= 3 ) { if( sscanf(noa[2],"%d,%d", &lspec1, &lspec2) != 2 ) { - printf("Expected min,max layers, got '%s'\n", noa[2]); - exit( 42 ); - } + printf("Expected min,max layers, got '%s'\n", noa[2]); + exit( 42 ); + } } printf( "layer range = [%d, %d].\n", lspec1, lspec2 ); printf( "Fold mask directory = '%s'\n", fold_dir.c_str() ); @@ -2301,310 +2301,310 @@ vector z1, z2; FILE *fp = FileOpenOrDie( noa[0], "r" ); CLineScan *ls = new CLineScan; - for(;;) { + for(;;) { - if( ls->Get( fp ) <= 0 ) - break; + if( ls->Get( fp ) <= 0 ) + break; - if( !strncmp( ls->line, "DIR", 3 ) ) { + if( !strncmp( ls->line, "DIR", 3 ) ) { - // parallel vectors - char *z = strtok( ls->line + 4, " " ); - char *n = strtok( NULL, " \n" ); + // parallel vectors + char *z = strtok( ls->line + 4, " " ); + char *n = strtok( NULL, " \n" ); - lnums.push_back( atoi( z ) ); - dnames.push_back( strdup( n ) ); - } - else if( !strncmp( ls->line, "FOLDMAP", 7 ) ) { + lnums.push_back( atoi( z ) ); + dnames.push_back( strdup( n ) ); + } + else if( !strncmp( ls->line, "FOLDMAP", 7 ) ) { - char *tname = strtok( ls->line + 7, " '\n" ); - char *mname = strtok( NULL, " '\n" ); - int id_dum; + char *tname = strtok( ls->line + 7, " '\n" ); + char *mname = strtok( NULL, " '\n" ); + int id_dum; - if( !tname || !mname ) { - printf( "Bad FOLDMAP statement '%s'.", ls->line ); - exit( 42 ); - } + if( !tname || !mname ) { + printf( "Bad FOLDMAP statement '%s'.", ls->line ); + exit( 42 ); + } - map::iterator it = imap.find(string(tname)); + map::iterator it = imap.find(string(tname)); - if( it != imap.end() ) - continue; // already seen this one + if( it != imap.end() ) + continue; // already seen this one - // Get image dimensions - if( !w ) { - uint8 *r = Raster8FromAny( tname, w, h ); - RasterFree( r ); - w /= scale; - h /= scale; - } + // Get image dimensions + if( !w ) { + uint8 *r = Raster8FromAny( tname, w, h ); + RasterFree( r ); + w /= scale; + h /= scale; + } - image ii; + image ii; - ii.raster = NULL; - ii.foldmap = NULL; - ii.bmap = NULL; - ii.w = w; - ii.h = h; - ii.spbase = 0; - ii.rname = strdup( tname ); - ii.fname = strdup( mname ); - ii.spname = NULL; - ii.bname = NULL; - ii.spmap = NULL; + ii.raster = NULL; + ii.foldmap = NULL; + ii.bmap = NULL; + ii.w = w; + ii.h = h; + ii.spbase = 0; + ii.rname = strdup( tname ); + ii.fname = strdup( mname ); + ii.spname = NULL; + ii.bname = NULL; + ii.spmap = NULL; - ZIDFromFMPath( ii.layer, id_dum, mname ); + ZIDFromFMPath( ii.layer, id_dum, mname ); - if( lspec1 < 0 || - (lspec1 <= ii.layer && ii.layer <= lspec2) ) { + if( lspec1 < 0 || + (lspec1 <= ii.layer && ii.layer <= lspec2) ) { - // Point at drawing (d-suffixed) foldmap if exists + // Point at drawing (d-suffixed) foldmap if exists - char *suf = strstr( mname, ".tif" ); + char *suf = strstr( mname, ".tif" ); - if( suf ) { + if( suf ) { - char buf[2048]; + char buf[2048]; - sprintf( buf, "%.*sd.tif", suf - mname, mname ); + sprintf( buf, "%.*sd.tif", suf - mname, mname ); - if( DskExists( buf ) ) { - printf( "Using drawing file '%s'.\n", buf ); - free( ii.fname ); - ii.fname = strdup( buf ); - } - } + if( DskExists( buf ) ) { + printf( "Using drawing file '%s'.\n", buf ); + free( ii.fname ); + ii.fname = strdup( buf ); + } + } - // Finally, add to collection - imap[string(tname)] = images.size(); - images.push_back( ii ); + // Finally, add to collection + imap[string(tname)] = images.size(); + images.push_back( ii ); - lowest = min( lowest, ii.layer ); - highest = max( highest, ii.layer ); - } - } - else if( !strncmp( ls->line, "TRANSFORM", 9 ) ) { + lowest = min( lowest, ii.layer ); + highest = max( highest, ii.layer ); + } + } + else if( !strncmp( ls->line, "TRANSFORM", 9 ) ) { - char name[2048]; - double a, b, c, d, e, f; - int nread; + char name[2048]; + double a, b, c, d, e, f; + int nread; - // newer format has '' delimited name - // older just space separated + // newer format has '' delimited name + // older just space separated - if( ls->line[10] == '\'' ) { - nread = sscanf( - ls->line + 10, "'%[^']' %lf %lf %lf %lf %lf %lf", - name, &a, &b, &c, &d, &e, &f ); - } - else { - nread = sscanf( - ls->line + 10, "%s %lf %lf %lf %lf %lf %lf", - name, &a, &b, &c, &d, &e, &f ); - } + if( ls->line[10] == '\'' ) { + nread = sscanf( + ls->line + 10, "'%[^']' %lf %lf %lf %lf %lf %lf", + name, &a, &b, &c, &d, &e, &f ); + } + else { + nread = sscanf( + ls->line + 10, "%s %lf %lf %lf %lf %lf %lf", + name, &a, &b, &c, &d, &e, &f ); + } - if( 7 != nread ) { - printf( "Bad TRANSFORM statement '%s'.", ls->line ); - exit( 42 ); - } + if( 7 != nread ) { + printf( "Bad TRANSFORM statement '%s'.", ls->line ); + exit( 42 ); + } - TAffine tf( a, b, c/scale, d, e, f/scale ); - char *fname = strtok( name, " ':" ); + TAffine tf( a, b, c/scale, d, e, f/scale ); + char *fname = strtok( name, " ':" ); - //printf("File '%s'\n", fname); + //printf("File '%s'\n", fname); - map::iterator imit = imap.find(string(fname)); + map::iterator imit = imap.find(string(fname)); - if( imit == imap.end() ) { + if( imit == imap.end() ) { - // This is normal with single layer image generation. + // This is normal with single layer image generation. - //printf( "File in TRANSFORM has no FOLDMAP - ignored.\n" ); - continue; - } + //printf( "File in TRANSFORM has no FOLDMAP - ignored.\n" ); + continue; + } - int k = imit->second; + int k = imit->second; - // get the rest of the string, now of the form ::123 - int patch = atoi( strtok( NULL, " :'\n" ) ); + // get the rest of the string, now of the form ::123 + int patch = atoi( strtok( NULL, " :'\n" ) ); - printf( "ImageIdx::patch = %d::%d\n", k, patch ); + printf( "ImageIdx::patch = %d::%d\n", k, patch ); - // Make new slot? - if( images[k].tf.size() <= patch ) { + // Make new slot? + if( images[k].tf.size() <= patch ) { - // initialize to an illegal transform - images[k].tf.resize( patch+1, TAffine(0,0,0,0,0,0) ); - images[k].inv.resize( patch+1 ); - } + // initialize to an illegal transform + images[k].tf.resize( patch+1, TAffine(0,0,0,0,0,0) ); + images[k].inv.resize( patch+1 ); + } - images[k].tf[patch] = tf; - } - else if( !strncmp( ls->line, "SPMAP", 5 ) ) { + images[k].tf[patch] = tf; + } + else if( !strncmp( ls->line, "SPMAP", 5 ) ) { - char name[2048], where[2048]; - int z, nprm; + char name[2048], where[2048]; + int z, nprm; - nprm = sscanf( ls->line + 5, "%s %s %d", name, where, &z ); + nprm = sscanf( ls->line + 5, "%s %s %d", name, where, &z ); - if( nprm < 2 ) { - printf( "Bad SPMAP statement '%s'.", ls->line ); - exit( 42 ); - } + if( nprm < 2 ) { + printf( "Bad SPMAP statement '%s'.", ls->line ); + exit( 42 ); + } - char *fname = strtok( name, " ':" ); + char *fname = strtok( name, " ':" ); - //printf("File '%s'\n", fname); + //printf("File '%s'\n", fname); - map::iterator imit = imap.find(string(fname)); + map::iterator imit = imap.find(string(fname)); - if( imit == imap.end() ) { + if( imit == imap.end() ) { - // This is normal with single layer image generation. - // If it's a layer we care about, print a message. - // Otherwise silently ignore. + // This is normal with single layer image generation. + // If it's a layer we care about, print a message. + // Otherwise silently ignore. - int layer; + int layer; - if( nprm > 2 ) - layer = z; - else - layer = FileNameToLayerNumber( dnames, lnums, fname ); + if( nprm > 2 ) + layer = z; + else + layer = FileNameToLayerNumber( dnames, lnums, fname ); - if( lspec1 < 0 || - (lspec1 <= layer && layer <= lspec2) ) { + if( lspec1 < 0 || + (lspec1 <= layer && layer <= lspec2) ) { - printf( - "File in SPMAP has no image - ignored.\n" ); - } + printf( + "File in SPMAP has no image - ignored.\n" ); + } - continue; - } + continue; + } - int k = imit->second; + int k = imit->second; - printf( "ImageIdx = %d\n", k ); - images[k].spname = strdup( where ); - } - else if( !strncmp( ls->line, "BOUNDARYMAP", 11 ) ) { + printf( "ImageIdx = %d\n", k ); + images[k].spname = strdup( where ); + } + else if( !strncmp( ls->line, "BOUNDARYMAP", 11 ) ) { - char name[2048], where[2048]; - int z, nprm; + char name[2048], where[2048]; + int z, nprm; - nprm = sscanf( ls->line + 11, "%s %s %d", name, where, &z ); + nprm = sscanf( ls->line + 11, "%s %s %d", name, where, &z ); - if( nprm < 2 ) { - printf( "Bad BOUNDARYMAP statement '%s'.", ls->line ); - exit( 42 ); - } + if( nprm < 2 ) { + printf( "Bad BOUNDARYMAP statement '%s'.", ls->line ); + exit( 42 ); + } - char *fname = strtok( name, " ':" ); + char *fname = strtok( name, " ':" ); - //printf("File '%s'\n", fname); + //printf("File '%s'\n", fname); - map::iterator imit = imap.find(string(fname)); + map::iterator imit = imap.find(string(fname)); - if( imit == imap.end() ) { + if( imit == imap.end() ) { - // This is normal with single layer image generation. - // If it's a layer we care about, print a message. - // Otherwise silently ignore. + // This is normal with single layer image generation. + // If it's a layer we care about, print a message. + // Otherwise silently ignore. - int layer; + int layer; - if( nprm > 2 ) - layer = z; - else - layer = FileNameToLayerNumber( dnames, lnums, fname ); + if( nprm > 2 ) + layer = z; + else + layer = FileNameToLayerNumber( dnames, lnums, fname ); - if( lspec1 < 0 || - (lspec1 <= layer && layer <= lspec2) ) { + if( lspec1 < 0 || + (lspec1 <= layer && layer <= lspec2) ) { - printf( - "File in BOUNDARYMAP has no image - ignored.\n" ); - } + printf( + "File in BOUNDARYMAP has no image - ignored.\n" ); + } - continue; - } + continue; + } - int k = imit->second; + int k = imit->second; - printf( "ImageIdx = %d\n", k ); - images[k].bname = strdup( where ); - } - else if( !strncmp( ls->line, "MPOINTS", 7 ) ) { + printf( "ImageIdx = %d\n", k ); + images[k].bname = strdup( where ); + } + else if( !strncmp( ls->line, "MPOINTS", 7 ) ) { - double a, b, c, d; - int za, zc; + double a, b, c, d; + int za, zc; - if( 6 != sscanf( ls->line + 7, - "%d %lf %lf %d %lf %lf", - &za, &a, &b, &zc, &c, &d ) ) { + if( 6 != sscanf( ls->line + 7, + "%d %lf %lf %d %lf %lf", + &za, &a, &b, &zc, &c, &d ) ) { - printf( "Bad MPOINTS statement '%s'.", ls->line ); - exit( 42 ); - } + printf( "Bad MPOINTS statement '%s'.", ls->line ); + exit( 42 ); + } - if( lspec1 < 0 || - (lspec1-1 <= za && za <= lspec2+1) || - (lspec1-1 <= zc && zc <= lspec2+1) ) { + if( lspec1 < 0 || + (lspec1-1 <= za && za <= lspec2+1) || + (lspec1-1 <= zc && zc <= lspec2+1) ) { - z1.push_back( za ); - x1.push_back( a/scale ); - y1.push_back( b/scale ); + z1.push_back( za ); + x1.push_back( a/scale ); + y1.push_back( b/scale ); - z2.push_back( zc ); - x2.push_back( c/scale ); - y2.push_back( d/scale ); - } - } - else if( !strncmp( ls->line, "BBOX", 4 ) ) { + z2.push_back( zc ); + x2.push_back( c/scale ); + y2.push_back( d/scale ); + } + } + else if( !strncmp( ls->line, "BBOX", 4 ) ) { - if( 4 != sscanf( ls->line + 4, - "%lf %lf %lf %lf", &xmin, &ymin, &xmax, &ymax ) ) { + if( 4 != sscanf( ls->line + 4, + "%lf %lf %lf %lf", &xmin, &ymin, &xmax, &ymax ) ) { - printf( "Bad BBOX statement '%s'.\n", ls->line ); - exit( 42 ); - } + printf( "Bad BBOX statement '%s'.\n", ls->line ); + exit( 42 ); + } - xmin /= scale; - ymin /= scale; - xmax /= scale; - ymax /= scale; - } - else if( !strncmp( ls->line, "IMAGESIZE", 9 ) ) { + xmin /= scale; + ymin /= scale; + xmax /= scale; + ymax /= scale; + } + else if( !strncmp( ls->line, "IMAGESIZE", 9 ) ) { - if( 2 != sscanf( ls->line + 10, "%d %d", &w, &h ) ) { - printf( "Bad IMAGESIZE line '%s'.\n", ls->line ); - exit( 42 ); - } + if( 2 != sscanf( ls->line + 10, "%d %d", &w, &h ) ) { + printf( "Bad IMAGESIZE line '%s'.\n", ls->line ); + exit( 42 ); + } - w /= scale; - h /= scale; - } - else { - printf( "Unknown line '%s'.", ls->line ); - exit( 42 ); - } - } + w /= scale; + h /= scale; + } + else { + printf( "Unknown line '%s'.", ls->line ); + exit( 42 ); + } + } - delete ls; - fclose( fp ); + delete ls; + fclose( fp ); //VMStats( stdout ); //exit( 11 ); - if( !images.size() ) { - printf( "No images in input.\n" ); - exit( 42 ); - } + if( !images.size() ) { + printf( "No images in input.\n" ); + exit( 42 ); + } - GlobalBounds( xmin, xmax, ymin, ymax, images, w, h ); + GlobalBounds( xmin, xmax, ymin, ymax, images, w, h ); - OffsetCoords( xmin, xmax, ymin, ymax, images, - x1, y1, x2, y2, x0, y0, xsize, ysize ); + OffsetCoords( xmin, xmax, ymin, ymax, images, + x1, y1, x2, y2, x0, y0, xsize, ysize ); @@ -2635,8 +2635,8 @@ if( lspec1 >= 0 ) { // layer numbers were specified double delta_image_space = 2.0; // implausibly high value for(int i=0; i relevant_images; // See if we find any boundary maps @@ -2704,86 +2704,86 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u int MaxSPUsed = 0; for(int i=0; iimap(nx*ny,0); if( relevant_images.size() > 0xFFFF ) { // since we hold this as 16 bits - printf("Too many images (%d) on layer %d\n", relevant_images.size(), out_layer); - exit( 42 ); - } + printf("Too many images (%d) on layer %d\n", relevant_images.size(), out_layer); + exit( 42 ); + } vectorPatchFrom(nx*ny,0); // Now the choice of fill-in methods if( matlab_order ) { - FillInMatlabOrder(imap, PatchFrom, nx, ny, - w, h, delta_image_space, images, relevant_images); + FillInMatlabOrder(imap, PatchFrom, nx, ny, + w, h, delta_image_space, images, relevant_images); } else { - FillInFromCenterOut(imap, PatchFrom, nx, ny, - w, h, delta_image_space, images, relevant_images); - } + FillInFromCenterOut(imap, PatchFrom, nx, ny, + w, h, delta_image_space, images, relevant_images); + } // Now compress the map/patch array. We assume less than 65536 combinations are used, so we can express // this as a 16 bit TIF. The combinations start at 1, and run sequentially. @@ -2822,22 +2822,22 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vectorhisto(10); // small histogram, for testing for(uint32 i=0; i::iterator it = temp.find(id); if( it == temp.end() ) { // add it - Triple t(imap[i], PatchFrom[i], 0); - temp.insert(pair(id, Triples.size())); + Triple t(imap[i], PatchFrom[i], 0); + temp.insert(pair(id, Triples.size())); printf("New combo %5d: %d %d at %d\n", Triples.size(), t.image, t.patch, i); Triples.push_back(t); - it = temp.find(id); // now should find it, since we just added it - } + it = temp.find(id); // now should find it, since we just added it + } imap[i] = it->second; if( it->second < 10 ) - histo[it->second]++; - } + histo[it->second]++; + } for(int i=0; i<10; i++) - printf("Entry %d used %d times.\n", i, histo[i]); + printf("Entry %d used %d times.\n", i, histo[i]); @@ -2853,7 +2853,7 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u printf("Writing 8 bit map in png format to %s\n", fname); vector copy(nx*ny, 0); // make an 8 bit copy for(int i=0; ibefore(nx*ny,0); for(int y=0; y < ny; y++) { if( (y & 0x3FF) == 0 ) { - printf("."); fflush(stdout); + printf("."); fflush(stdout); } - for(int x=0; x= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate - int ix = int(p.x); - int iy = int(p.y); - double alpha = p.x-ix; - double beta = p.y-iy; - int nn = ix + w*iy; // index into original image - uint8* pic = images[img].raster; - double pix = - (1-alpha)*(1-beta) * pic[nn] + - alpha *(1-beta) * pic[nn+1] + - (1-alpha)* beta * pic[nn+w] + - alpha * beta * pic[nn+w+1]; - before[bi] = ROUND(pix); - } - } // to aid debugging, draw lines at the image boundaries in the before image. + if( from == 0 ) + continue; // no image sets this pixel + int img = relevant_images[from-1]; + Point p(x, y); + images[img].inv[patch].Transform( p ); + // of course, this should be in the image, but let's double check + if( p.x >= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate + int ix = int(p.x); + int iy = int(p.y); + double alpha = p.x-ix; + double beta = p.y-iy; + int nn = ix + w*iy; // index into original image + uint8* pic = images[img].raster; + double pix = + (1-alpha)*(1-beta) * pic[nn] + + alpha *(1-beta) * pic[nn+1] + + (1-alpha)* beta * pic[nn+w] + + alpha * beta * pic[nn+w+1]; + before[bi] = ROUND(pix); + } + } // to aid debugging, draw lines at the image boundaries in the before image. } printf("Done creating before image; draw lines next\n"); if( Annotate ) { - vector edges; - for(int x=0; x edges; + for(int x=0; x 0 && p.x < nx-1 && p.y > 0 && p.y < ny-1 ) - DrawText(&before[0], nx, ny, fn, int(p.x), int(p.y)); - } - //also to aid in debugging, draw circles at correspondence points - for(int i=0; i 0x7FFFFFFFu ) { // is it *really* big? - printf("write half\n"); - sprintf(fname,"before.%05d.a.png", out_layer); - Raster8ToPng8( fname, &before[0], nx, ny/2 ); - printf("write the other half\n"); - sprintf(fname,"before.%05d.b.png", out_layer); - Raster8ToPng8( fname, &before[nx*ny/2], nx, ny/2 ); - printf("both written\n"); - } - else { // this is the usual case - sprintf(fname,"before.%05d.png", out_layer); - Raster8ToPng8( fname, &before[0], nx, ny ); - } - } + if( nx*ny > 0x7FFFFFFFu ) { // is it *really* big? + printf("write half\n"); + sprintf(fname,"before.%05d.a.png", out_layer); + Raster8ToPng8( fname, &before[0], nx, ny/2 ); + printf("write the other half\n"); + sprintf(fname,"before.%05d.b.png", out_layer); + Raster8ToPng8( fname, &before[nx*ny/2], nx, ny/2 ); + printf("both written\n"); + } + else { // this is the usual case + sprintf(fname,"before.%05d.png", out_layer); + Raster8ToPng8( fname, &before[0], nx, ny ); + } + } @@ -2971,29 +2971,29 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u sprintf(fname,"%s/%s/map.%05d.png", region_dir.c_str(), inv_dir.c_str(), out_layer); printf("write Pixel mapping file %s\n", fname); Raster16ToPng16( fname, &imap[0], nx, ny ); - // ------------------------------------------------ write the mapping text file -------------------- - // This is the text file that contains the transformations that describe how each pixel got there. - sprintf(fname,"%s/%s/mapping.%05d.txt", region_dir.c_str(), inv_dir.c_str(), out_layer); - FILE *ftxt = FileOpenOrDie( fname, "w" ); - //write the image names, and their indexes - for(int k=0; k gvtx; for(int m=0; m spots; const int delta = 40; for(int ty=0; ty 0 && image2 > 0 ) { // found a boundary + if( image1 != image2 && image1 > 0 && image2 > 0 ) { // found a boundary if (tx - prev_x < delta && // see if it's a duplicate of previous one (indx1 == prev_i1 && indx2 == prev_i2 || indx1 == prev_i2 && indx2 == prev_i1)) - printf("Same images, too close, at %d\n", tx); + printf("Same images, too close, at %d\n", tx); else { // it's Ok - Ntrans++; - int i1 = relevant_images[image1-1]; - int i2 = relevant_images[image2-1]; // point is on boundary of image i1 and i2 - //i2 = i1; // temp, just to make sure we get 0,0 - Point p1(tx,ty); - CommonPoint( spots, images, p1,i1, Triples[indx1].patch, out_layer ); - prev_x = tx; prev_i1 = indx1; prev_i2 = indx2; - } - } - } + Ntrans++; + int i1 = relevant_images[image1-1]; + int i2 = relevant_images[image2-1]; // point is on boundary of image i1 and i2 + //i2 = i1; // temp, just to make sure we get 0,0 + Point p1(tx,ty); + CommonPoint( spots, images, p1,i1, Triples[indx1].patch, out_layer ); + prev_x = tx; prev_i1 = indx1; prev_i2 = indx2; + } + } + } if( Ntrans > 100 ) { - printf("Too many transitions (%d) in map!\n", Ntrans); + printf("Too many transitions (%d) in map!\n", Ntrans); if( !Debug ) { - printf("Writing map as 'test.png'\n"); - Raster16ToPng16( "test.png", &imap[0], nx, ny ); - } + printf("Writing map as 'test.png'\n"); + Raster16ToPng16( "test.png", &imap[0], nx, ny ); + } exit( 42 ); - } - } + } + } for(int tx=0; tx 0 && image2 > 0 ) { // found a boundary + if( image1 != image2 && image1 > 0 && image2 > 0 ) { // found a boundary if (ty - prev_y < delta && // see if it's a duplicate of previous one (indx1 == prev_i1 && indx2 == prev_i2 || indx1 == prev_i2 && indx2 == prev_i1)) - printf("Same images, too close, at %d\n", ty); + printf("Same images, too close, at %d\n", ty); else { // it's Ok - Ntrans++; - int i1 = relevant_images[image1-1]; // -1 since 0 is reserved for 'no image maps here' - int i2 = relevant_images[image2-1]; // point is on boundary of image i1 and i2 - //i2 = i1; // temp, just to make sure we get 0,0 - Point p1(tx,ty); - CommonPoint( spots, images, p1,i1, Triples[indx1].patch, out_layer ); - prev_y = ty; prev_i1 = indx1; prev_i2 = indx2; - } - } - } + Ntrans++; + int i1 = relevant_images[image1-1]; // -1 since 0 is reserved for 'no image maps here' + int i2 = relevant_images[image2-1]; // point is on boundary of image i1 and i2 + //i2 = i1; // temp, just to make sure we get 0,0 + Point p1(tx,ty); + CommonPoint( spots, images, p1,i1, Triples[indx1].patch, out_layer ); + prev_y = ty; prev_i1 = indx1; prev_i2 = indx2; + } + } + } if( Ntrans > 100 ) { - printf("Too many transitions (%d) in map!\n", Ntrans); + printf("Too many transitions (%d) in map!\n", Ntrans); if( !Debug ) { - printf("Writing map as 'test.png'\n"); - Raster16ToPng16( "test.png", &imap[0], nx, ny ); - } + printf("Writing map as 'test.png'\n"); + Raster16ToPng16( "test.png", &imap[0], nx, ny ); + } exit( 42 ); - } - } + } + } printf("%d global control points; %d constraints\n", gvtx.size(), spots.size() ); int nvs = gvtx.size(); // number of control points @@ -3196,33 +3196,33 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vector RHS(2*nvs, 0.0); // // first, add the constraints that each should be near where they started... for(int i=0; i X(2*nvs); fflush(stdout); @@ -3248,7 +3248,7 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vector NewG(nvs); for(int i=0; iMoveThresh ? "<-----" : ""); + printf("Image %d, pt %d, was (%f,%f), now (%f,%f), moved %f %s\n", + i/(N+1), i%(N+1), gvtx[i].x, gvtx[i].y, NewG[i].x, NewG[i].y, move, move>MoveThresh ? "<-----" : ""); if( move > MoveThresh ) { - NewG[i] = gvtx[i]; - NTooFar++; - } - } + NewG[i] = gvtx[i]; + NTooFar++; + } + } // Now, for every patch of every image, compute a vector of N transforms, one corresponding // to each original triangle. for(int m=0; m empty; images[i].sectors.push_back(empty); // since there is no patch 0 images[i].sinvs .push_back(empty); - for(int j=1; j ltfs(N); // an N element vector of transforms - vector invs(N); // and the inverses to these + for(int j=1; j ltfs(N); // an N element vector of transforms + vector invs(N); // and the inverses to these printf("Image %d, patch %d\n", i, j); images[i].tf[j].TPrint(); - for(int k=0; k pts; - PointsInRing(pts, center, r, delta_image_space*0.9, w, h); + vector pts; + PointsInRing(pts, center, r, delta_image_space*0.9, w, h); // Now transform this by all relevant images - for(int k=0; k= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) - continue; - images[i].sectors[patch][sector].Transform( p ); // change to global coordinates - ix = ROUND(p.x); - iy = ROUND(p.y); + continue; + images[i].sectors[patch][sector].Transform( p ); // change to global coordinates + ix = ROUND(p.x); + iy = ROUND(p.y); if( ix == 8557 && iy == 431 ) { printf("Point %f %f in image %s\n", pts[j].x, pts[j].y, images[i].rname); - printf("Maps to pixel %d %d, image %d patch %d sector %d\n", ix, iy, i, patch, sector); + printf("Maps to pixel %d %d, image %d patch %d sector %d\n", ix, iy, i, patch, sector); images[i].sectors[patch][sector].TPrint( stdout, "Transform is " ); images[i]. sinvs[patch][sector].TPrint( stdout, " Inverse is " ); - } + } if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) - continue; // outside the image - //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); - bool dbg = (2642 <= ix && ix <= 2644 && 3398 <= iy && iy <= 3400); + continue; // outside the image + //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); + bool dbg = (2642 <= ix && ix <= 2644 && 3398 <= iy && iy <= 3400); if( dbg ) printf("\nDebugging point %d %d, r=%f, p= %f %f, pts[%d]= %f %f\n", ix, iy, r, p.x, p.y, j, pts[j].x, pts[j].y ); - uint32 nn = uint32(ix) + uint32(iy)*nx; // index into array - if( imap[nn] == 0 ) { - imap[nn] = k+1; // this pixel will be set by the kth relevant picture - PatchFrom[nn] = patch; // patch 'patch', sector 'sector' + uint32 nn = uint32(ix) + uint32(iy)*nx; // index into array + if( imap[nn] == 0 ) { + imap[nn] = k+1; // this pixel will be set by the kth relevant picture + PatchFrom[nn] = patch; // patch 'patch', sector 'sector' SectorFrom[nn]= sector; if( dbg ) printf("Not set, setting to %d %d %d %d\n", k, i, patch, sector); } - else { // already set, but we still might be better (because of finite - // grid in source, rounding to int, ordering ). - Point pt_us = Point(ix,iy); - Point pt_ot = pt_us; - // transform back into original frames. - int oi = relevant_images[imap[nn]-1]; // other image - int op = PatchFrom[nn]; // other patch + else { // already set, but we still might be better (because of finite + // grid in source, rounding to int, ordering ). + Point pt_us = Point(ix,iy); + Point pt_ot = pt_us; + // transform back into original frames. + int oi = relevant_images[imap[nn]-1]; // other image + int op = PatchFrom[nn]; // other patch int os = SectorFrom[nn]; // other sector - images[oi].sinvs[op][os].Transform( pt_ot ); - images[i].sinvs[patch][sector].Transform( pt_us ); - - double d_us = max(abs(pt_us.x-center.x), abs(pt_us.y-center.y)); // L-infinity norm - double d_ot = max(abs(pt_ot.x-center.x), abs(pt_ot.y-center.y)); // L-infinity norm - if( dbg ) printf("Already set to %d %d %d %d, d_us %f, d_ot %f\n", imap[nn]-1, oi, op, os, d_us, d_ot); - if( d_us < d_ot ) { - if( dbg ) printf("It CAN happen #2... d_us= %f, d_ot= %f\n", d_us, d_ot); - // Set it, even though it was previously set, since this is better - imap[nn] = k+1; // this pixel will be set by the ith picture - PatchFrom[nn] = patch; - SectorFrom[nn] = sector; - } - } - } - } - } + images[oi].sinvs[op][os].Transform( pt_ot ); + images[i].sinvs[patch][sector].Transform( pt_us ); + + double d_us = max(abs(pt_us.x-center.x), abs(pt_us.y-center.y)); // L-infinity norm + double d_ot = max(abs(pt_ot.x-center.x), abs(pt_ot.y-center.y)); // L-infinity norm + if( dbg ) printf("Already set to %d %d %d %d, d_us %f, d_ot %f\n", imap[nn]-1, oi, op, os, d_us, d_ot); + if( d_us < d_ot ) { + if( dbg ) printf("It CAN happen #2... d_us= %f, d_ot= %f\n", d_us, d_ot); + // Set it, even though it was previously set, since this is better + imap[nn] = k+1; // this pixel will be set by the ith picture + PatchFrom[nn] = patch; + SectorFrom[nn] = sector; + } + } + } + } + } // Now compress the map/patch/sector array. We assume less than 65536 combinations are used, so we can express // this as a 16 bit TIF. The combinations start at 1, and run sequentially. temp.clear(); // clear the mapping file Triples.resize(1); // and the triples; will fill up as they are found; first entry remains (0,0,0) for(uint32 i=0; i::iterator it = temp.find(id); if( it == temp.end() ) { // add it - Triple t(imap[i], PatchFrom[i], SectorFrom[i]); - temp.insert(pair(id, Triples.size())); + Triple t(imap[i], PatchFrom[i], SectorFrom[i]); + temp.insert(pair(id, Triples.size())); printf("New combo %5d: %3d %3d %3d\n", Triples.size(), t.image, t.patch, t.sector); Triples.push_back(t); - it = temp.find(id); // now should find it, since we just added it - } + it = temp.find(id); // now should find it, since we just added it + } uint32 iy = i/nx; uint32 ix = i - nx*iy; - if( ix == 8557 && iy == 431 ) { - printf("Compress map ix=%d iy=%d\n", ix, iy); + if( ix == 8557 && iy == 431 ) { + printf("Compress map ix=%d iy=%d\n", ix, iy); printf(" imap %d, patch %d, sector %d\n", imap[i], PatchFrom[i], SectorFrom[i]); if( imap[i] > 0 ) - printf("Image %d\n", relevant_images[imap[i]-1] ); - printf(" id = %d = %x\n", id, id); + printf("Image %d\n", relevant_images[imap[i]-1] ); + printf(" id = %d = %x\n", id, id); printf(" it->second = %d\n", it->second); - } + } imap[i] = it->second; - } + } // write the new map file, if requested if( make_map ) { sprintf(fname,"%s/%s/map.%05d.png", region_dir.c_str(), inv_dir.c_str(), out_layer); @@ -3466,79 +3466,79 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u } for(int x=0; x= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate - int ix = int(p.x); - int iy = int(p.y); - double alpha = p.x-ix; - double beta = p.y-iy; - int nn = ix + w*iy; // index into original image - uint8* pic = images[img].raster; - double pix = - (1-alpha)*(1-beta) * pic[nn] + - alpha *(1-beta) * pic[nn+1] + - (1-alpha)* beta * pic[nn+w] + - alpha * beta * pic[nn+w+1]; - before[bi] = ROUND(pix); + Point p(x, y); + images[img].sinvs[patch][sector].Transform( p ); + // of course, this should be in the image, but let's double check + if( p.x >= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate + int ix = int(p.x); + int iy = int(p.y); + double alpha = p.x-ix; + double beta = p.y-iy; + int nn = ix + w*iy; // index into original image + uint8* pic = images[img].raster; + double pix = + (1-alpha)*(1-beta) * pic[nn] + + alpha *(1-beta) * pic[nn+1] + + (1-alpha)* beta * pic[nn+w] + + alpha * beta * pic[nn+w+1]; + before[bi] = ROUND(pix); // for the super-pixel map we want nearest, not interpolation. if( p.x - ix >= 0.5 ) - ix++; + ix++; if( p.y - iy >= 0.5 ) - iy++; + iy++; int px = images[img].spmap[ix + w*iy]; if( px != 0 ) // 0 valued pixels are unassigned, and not translated px += images[img].spbase; spmap[bi] = px; //if( spmap[x+y*nx] == 65536 ) { // Just debugging //printf("w=%d h=%d nx=%d ny=%d patch=%d sector=%d\n", w, h, nx, ny, patch, sector); - //printf("Set to %d. x=%d y=%d ix=%d iy=%d img=%d images[img].spbase=%d images[img].spmap[ix + w*iy] = %d\n", + //printf("Set to %d. x=%d y=%d ix=%d iy=%d img=%d images[img].spbase=%d images[img].spmap[ix + w*iy] = %d\n", //px, x, y, ix, iy, img, images[img].spbase, images[img].spmap[ix + w*iy] ); //exit( 42 ); - //} + //} if( Debug && px == 0 ) - before[bi] = 255; - } - } // to aid debugging, draw lines at the image boundaries in the before image. + before[bi] = 255; + } + } // to aid debugging, draw lines at the image boundaries in the before image. } if( Annotate ) { - vector edges; - for(int x=0; x edges; + for(int x=0; x= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate - int ix = int(p.x); - int iy = int(p.y); - double alpha = p.x-ix; - double beta = p.y-iy; - int nn = ix + w*iy; // index into original image - uint8* pic = images[img].bmap; - double pix = - (1-alpha)*(1-beta) * pic[nn] + - alpha *(1-beta) * pic[nn+1] + - (1-alpha)* beta * pic[nn+w] + - alpha * beta * pic[nn+w+1]; - before[x+y*nx] = ROUND(pix); - } - } - } + Point p(x, y); + images[img].sinvs[patch][sector].Transform( p ); + // of course, this should be in the image, but let's double check + if( p.x >= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate + int ix = int(p.x); + int iy = int(p.y); + double alpha = p.x-ix; + double beta = p.y-iy; + int nn = ix + w*iy; // index into original image + uint8* pic = images[img].bmap; + double pix = + (1-alpha)*(1-beta) * pic[nn] + + alpha *(1-beta) * pic[nn+1] + + (1-alpha)* beta * pic[nn+w] + + alpha * beta * pic[nn+w+1]; + before[x+y*nx] = ROUND(pix); + } + } + } if( AnyBMap ) { sprintf(fname,"%s/%s/bmap.%05d.png", region_dir.c_str(), bmap_dir.c_str(), out_layer); - if( make_flat ) + if( make_flat ) Raster8ToPng8( fname, &before[0], nx, ny ); - } + } // ------------------------------------------------ write the mapping text file -------------------- // This is the text file that contains the transformations that describe how each pixel got there. @@ -3593,14 +3593,14 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u //write the image names, and their indexes for(int k=0; k volume(biggest+1,0); @@ -3639,24 +3639,24 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vector xmax(biggest+1,-1); vector ymax(biggest+1,-1); for(int y=0; y 0 ) - fprintf(fb,"%d %7d %8d %d %d %d %d\n", out_layer, i, xmin[i], ny-1-ymax[i], xmax[i]-xmin[i]+1, ymax[i]-ymin[i]+1, volume[i]); - } + fprintf(fb,"%d %7d %8d %d %d %d %d\n", out_layer, i, xmin[i], ny-1-ymax[i], xmax[i]-xmin[i]+1, ymax[i]-ymin[i]+1, volume[i]); + } fclose(fb); } @@ -3664,19 +3664,19 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u bool experiment = false; if( experiment ) { vector copy(nx*ny,0); - for(int i=0; i big(bigx*bigy); printf("try to fill the huge array\n"); fflush(stdout); int p1 = nx*ny; int p2 = bigx*bigy; for(int i=0; i not in the original image - else { - //printf("%6d maps to %d (global set of maps)\n", k, m); + for(int k=1; k not in the original image + else { + //printf("%6d maps to %d (global set of maps)\n", k, m); // this could go off the end of the Final Mapping array, if the biggest number // assigned is not used in the final image. Test for this: int n = (m < FinalMapping.size()) ? FinalMapping[m] : 0; - if( n == 0 ) - fprintf(fmap, "%d -2\n", k); // -2 => not used in final image - else - fprintf(fmap, "%d %d\n", k, n); - } - } - } - } + if( n == 0 ) + fprintf(fmap, "%d -2\n", k); // -2 => not used in final image + else + fprintf(fmap, "%d %d\n", k, n); + } + } + } + } fclose(fmap); // Now, for every image that was used, look and see if it had annotation. If so, transform @@ -3720,29 +3720,29 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vector tbars; vector bookmarks; for(int j=0; j which; // which picture - vector patch; // which patch - vector where; // local coords - Point gpt; // point in global coords spawning these - double moved; // distance it moved + vector which; // which picture + vector patch; // which patch + vector where; // local coords + Point gpt; // point in global coords spawning these + double moved; // distance it moved }; class image { public: - uint8* raster; // gray scale image - uint8* foldmap; // fold map - uint8* bmap; // boundary map - uint32 w, h; - int layer; // layer number - int FirstGlobalPoint; - int FirstTriangle; - int spbase; // should be added to all sp ids in this image, for uniqueness - char *rname; // raster filename - char *fname; // foldmap filename - char *spname; // super-pixel filename - char *bname; // boundary-map filename - uint16 *spmap; - vector SPmapping; // tells what original SP numbers are mapped to - vector tf; // image to global space, one for each patch (0 unused) - vector inv; // inverse transform - vector >sectors; // forward transform for each sector of each patch - vector >sinvs; // sector inverses - vector FoldmapRenumber; + uint8* raster; // gray scale image + uint8* foldmap; // fold map + uint8* bmap; // boundary map + uint32 w, h; + int layer; // layer number + int FirstGlobalPoint; + int FirstTriangle; + int spbase; // should be added to all sp ids in this image, for uniqueness + char *rname; // raster filename + char *fname; // foldmap filename + char *spname; // super-pixel filename + char *bname; // boundary-map filename + uint16 *spmap; + vector SPmapping; // tells what original SP numbers are mapped to + vector tf; // image to global space, one for each patch (0 unused) + vector inv; // inverse transform + vector >sectors; // forward transform for each sector of each patch + vector >sinvs; // sector inverses + vector FoldmapRenumber; }; // Class describing a triple of numbers that in turn describe @@ -74,15 +74,15 @@ class image { // class Triple { public: - uint16 image; - uint8 patch; - uint8 sector; + uint16 image; + uint8 patch; + uint8 sector; public: - Triple() - : image(0), patch(0), sector(0) {}; + Triple() + : image(0), patch(0), sector(0) {}; - Triple( uint16 i, uint8 p, uint8 s ) - : image(i), patch(p), sector(s) {}; + Triple( uint16 i, uint8 p, uint8 s ) + : image(i), patch(p), sector(s) {}; }; /* --------------------------------------------------------------- */ @@ -92,59 +92,59 @@ class Triple { class CArgs_mos { public: - double DontMoveStrength; - char *infile, - *fold_dir, - *region_dir, - *gray_dir, - *sp_dir, - *inv_dir, - *rav_dir, - *bmap_dir; - int scale, - x0, y0, xsize, ysize, - lspec1, lspec2; - bool Debug, - Warp, - FoldMasks, - Annotate, - make_tiles, - make_flat, - make_map, - matlab_order, - RenumberSuperPixels; + double DontMoveStrength; + char *infile, + *fold_dir, + *region_dir, + *gray_dir, + *sp_dir, + *inv_dir, + *rav_dir, + *bmap_dir; + int scale, + x0, y0, xsize, ysize, + lspec1, lspec2; + bool Debug, + Warp, + FoldMasks, + Annotate, + make_tiles, + make_flat, + make_map, + matlab_order, + RenumberSuperPixels; public: - CArgs_mos() - { - DontMoveStrength = 0.01; - infile = NULL; - fold_dir = "."; // prepended fm loc - region_dir = "."; // where results go - gray_dir = "."; // where gray img go - sp_dir = "."; // where super-pixel maps go - inv_dir = "."; // where inv-map data go - rav_dir = "."; // where raveler tiles go - bmap_dir = "."; // where bndry maps go - scale = 1; // scale down by this - x0 = 0; // user's output origin - y0 = 0; - xsize = -1; // user's output size - ysize = -1; - lspec1 = -1; // user's layer range - lspec2 = -1; - Debug = false; - Warp = false; // seam healing - FoldMasks = true; - Annotate = false; - make_tiles = false; // for raveler - make_flat = true; // 'before' montages - make_map = true; // how img generated - matlab_order = false; // matlab or closeness order - RenumberSuperPixels = true; - }; - - void SetCmdLine( int argc, char* argv[] ); + CArgs_mos() + { + DontMoveStrength = 0.01; + infile = NULL; + fold_dir = "."; // prepended fm loc + region_dir = "."; // where results go + gray_dir = "."; // where gray img go + sp_dir = "."; // where super-pixel maps go + inv_dir = "."; // where inv-map data go + rav_dir = "."; // where raveler tiles go + bmap_dir = "."; // where bndry maps go + scale = 1; // scale down by this + x0 = 0; // user's output origin + y0 = 0; + xsize = -1; // user's output size + ysize = -1; + lspec1 = -1; // user's layer range + lspec2 = -1; + Debug = false; + Warp = false; // seam healing + FoldMasks = true; + Annotate = false; + make_tiles = false; // for raveler + make_flat = true; // 'before' montages + make_map = true; // how img generated + matlab_order = false; // matlab or closeness order + RenumberSuperPixels = true; + }; + + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -176,125 +176,125 @@ void CArgs_mos::SetCmdLine( int argc, char* argv[] ) { // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - printf( "Start: %s ", atime ); + printf( "Start: %s ", atime ); // parse command line args - if( argc < 2 ) { - printf( "Usage: mos " - " [xmin,ymin,dx,dy] [minlayer,maxlayer] [options].\n" ); - exit( 42 ); - } - - vector noa; - - for( int i = 1; i < argc; ++i ) { - - // echo to log - printf( "%s ", argv[i] ); - - if( argv[i][0] != '-' ) { - - if( !infile ) - infile = argv[i]; - else - noa.push_back( argv[i] ); - } - else if( GetArg( &DontMoveStrength, "-dms=%lf", argv[i] ) ) - ; - else if( GetArgStr( fold_dir, "-fold_dir=", argv[i] ) ) - ; - else if( GetArgStr( region_dir, "-region_dir=", argv[i] ) ) - ; - else if( GetArgStr( gray_dir, "-gray_dir=", argv[i] ) ) - ; - else if( GetArgStr( gray_dir, "-grey_dir=", argv[i] ) ) - ; - else if( GetArgStr( sp_dir, "-sp_dir=", argv[i] ) ) - ; - else if( GetArgStr( inv_dir, "-inv_dir=", argv[i] ) ) - ; - else if( GetArgStr( rav_dir, "-rav_dir=", argv[i] ) ) - ; - else if( GetArgStr( bmap_dir, "-bmap_dir=", argv[i] ) ) - ; - else if( GetArg( &scale, "-s=%d", argv[i] ) ) - ; - else if( IsArg( "-d", argv[i] ) ) - Debug = true; - else if( IsArg( "-warp", argv[i] ) ) - Warp = true; - else if( IsArg( "-nf", argv[i] ) ) - FoldMasks = false; - else if( IsArg( "-a", argv[i] ) ) - Annotate = true; - else if( IsArg( "-tiles", argv[i] ) ) - make_tiles = true; - else if( IsArg( "-noflat", argv[i] ) ) - make_flat = false; - else if( IsArg( "-nomap", argv[i] ) ) - make_map = false; - else if( IsArg( "-matlab", argv[i] ) ) - matlab_order = true; - else if( IsArg( "-drn", argv[i] ) ) - RenumberSuperPixels = false; - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - exit( 42 ); - } - } - - printf( "\n" ); - - if( Warp ) - printf( "Don't move strength = %g\n", DontMoveStrength ); + if( argc < 2 ) { + printf( "Usage: mos " + " [xmin,ymin,dx,dy] [minlayer,maxlayer] [options].\n" ); + exit( 42 ); + } + + vector noa; + + for( int i = 1; i < argc; ++i ) { + + // echo to log + printf( "%s ", argv[i] ); + + if( argv[i][0] != '-' ) { + + if( !infile ) + infile = argv[i]; + else + noa.push_back( argv[i] ); + } + else if( GetArg( &DontMoveStrength, "-dms=%lf", argv[i] ) ) + ; + else if( GetArgStr( fold_dir, "-fold_dir=", argv[i] ) ) + ; + else if( GetArgStr( region_dir, "-region_dir=", argv[i] ) ) + ; + else if( GetArgStr( gray_dir, "-gray_dir=", argv[i] ) ) + ; + else if( GetArgStr( gray_dir, "-grey_dir=", argv[i] ) ) + ; + else if( GetArgStr( sp_dir, "-sp_dir=", argv[i] ) ) + ; + else if( GetArgStr( inv_dir, "-inv_dir=", argv[i] ) ) + ; + else if( GetArgStr( rav_dir, "-rav_dir=", argv[i] ) ) + ; + else if( GetArgStr( bmap_dir, "-bmap_dir=", argv[i] ) ) + ; + else if( GetArg( &scale, "-s=%d", argv[i] ) ) + ; + else if( IsArg( "-d", argv[i] ) ) + Debug = true; + else if( IsArg( "-warp", argv[i] ) ) + Warp = true; + else if( IsArg( "-nf", argv[i] ) ) + FoldMasks = false; + else if( IsArg( "-a", argv[i] ) ) + Annotate = true; + else if( IsArg( "-tiles", argv[i] ) ) + make_tiles = true; + else if( IsArg( "-noflat", argv[i] ) ) + make_flat = false; + else if( IsArg( "-nomap", argv[i] ) ) + make_map = false; + else if( IsArg( "-matlab", argv[i] ) ) + matlab_order = true; + else if( IsArg( "-drn", argv[i] ) ) + RenumberSuperPixels = false; + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + exit( 42 ); + } + } + + printf( "\n" ); + + if( Warp ) + printf( "Don't move strength = %g\n", DontMoveStrength ); // user region - if( noa.size() ) { + if( noa.size() ) { - if( 4 != sscanf( noa[0], "%d,%d,%d,%d", - &x0, &y0, &xsize, &ysize ) ) { + if( 4 != sscanf( noa[0], "%d,%d,%d,%d", + &x0, &y0, &xsize, &ysize ) ) { - printf( "Expected [xmin,ymin,dx,dy], got [%s]\n", noa[0] ); - exit( 42 ); - } + printf( "Expected [xmin,ymin,dx,dy], got [%s]\n", noa[0] ); + exit( 42 ); + } - printf( "[0,0,dx,dy] = [%d, %d, %d, %d].\n", - x0, y0, xsize, ysize ); - } + printf( "[0,0,dx,dy] = [%d, %d, %d, %d].\n", + x0, y0, xsize, ysize ); + } // layer range - if( noa.size() > 1 ) { + if( noa.size() > 1 ) { - if( 2 != sscanf( noa[1], "%d,%d", &lspec1, &lspec2 ) ) { + if( 2 != sscanf( noa[1], "%d,%d", &lspec1, &lspec2 ) ) { - printf( "Expected [minlyr,maxlyr], got [%s]\n", noa[1] ); - exit( 42 ); - } + printf( "Expected [minlyr,maxlyr], got [%s]\n", noa[1] ); + exit( 42 ); + } - printf( "Layer range = [%d, %d].\n", lspec1, lspec2 ); - } + printf( "Layer range = [%d, %d].\n", lspec1, lspec2 ); + } // directories - printf( "Fold mask directory = '%s'\n", fold_dir ); - printf( "Region directory = '%s'\n", region_dir ); - printf( "Gray scale directory = '%s'\n", gray_dir ); - printf( "Super-pixel directory = '%s'\n", sp_dir ); - printf( "Inverse-map directory = '%s'\n", inv_dir ); - printf( "Raveler directory = '%s'\n", rav_dir ); - printf( "Boundary directory = '%s'\n", bmap_dir ); + printf( "Fold mask directory = '%s'\n", fold_dir ); + printf( "Region directory = '%s'\n", region_dir ); + printf( "Gray scale directory = '%s'\n", gray_dir ); + printf( "Super-pixel directory = '%s'\n", sp_dir ); + printf( "Inverse-map directory = '%s'\n", inv_dir ); + printf( "Raveler directory = '%s'\n", rav_dir ); + printf( "Boundary directory = '%s'\n", bmap_dir ); - printf( "\n" ); - fflush( stdout ); + printf( "\n" ); + fflush( stdout ); } /* --------------------------------------------------------------- */ @@ -309,18 +309,18 @@ void CArgs_mos::SetCmdLine( int argc, char* argv[] ) // 'nmrc_z_tile.png' and we decode the z from that. // static int FileNameToLayerNumber( - const vector &dnames, - const vector &lnums, - const char *fname ) + const vector &dnames, + const vector &lnums, + const char *fname ) { /* ----- */ /* nmrc? */ /* ----- */ - const char *s = FileNamePtr( fname ); + const char *s = FileNamePtr( fname ); - if( !strncmp( s, "nmrc_", 5 ) ) - return atoi( s + 5 ); + if( !strncmp( s, "nmrc_", 5 ) ) + return atoi( s + 5 ); /* ------------------ */ /* Otherwise use ldir */ @@ -329,7 +329,7 @@ static int FileNameToLayerNumber( int k; for(k=0; k= dnames.size() ) { printf("Oops - '%s' not in layer directory.\n", fname); exit( 42 ); @@ -343,19 +343,19 @@ return lnums[k]; static void PrintTransAndInv( FILE *of, const TAffine &tr ) { - TAffine in; + TAffine in; - in.InverseOf( tr ); + in.InverseOf( tr ); - fprintf( of, - "Fwd:%11.8f %11.8f %10.4f %11.8f %11.8f %10.4f\n", - tr.t[0], tr.t[1], tr.t[2], - tr.t[3], tr.t[4], tr.t[5] ); + fprintf( of, + "Fwd:%11.8f %11.8f %10.4f %11.8f %11.8f %10.4f\n", + tr.t[0], tr.t[1], tr.t[2], + tr.t[3], tr.t[4], tr.t[5] ); - fprintf( of, - "Rev:%11.8f %11.8f %10.4f %11.8f %11.8f %10.4f\n", - in.t[0], in.t[1], in.t[2], - in.t[3], in.t[4], in.t[5] ); + fprintf( of, + "Rev:%11.8f %11.8f %10.4f %11.8f %11.8f %10.4f\n", + in.t[0], in.t[1], in.t[2], + in.t[3], in.t[4], in.t[5] ); } /* --------------------------------------------------------------- */ @@ -365,51 +365,51 @@ static void PrintTransAndInv( FILE *of, const TAffine &tr ) // Find bounding box in global space. // static void GlobalBounds( - double &xmin, - double &xmax, - double &ymin, - double &ymax, - const vector &images, - int w, - int h ) + double &xmin, + double &xmax, + double &ymin, + double &ymax, + const vector &images, + int w, + int h ) { - if( xmin > BIG/2 ) { + if( xmin > BIG/2 ) { - int ni = images.size(); + int ni = images.size(); - for( int i = 0; i < ni; ++i ) { + for( int i = 0; i < ni; ++i ) { - int nt = images[i].tf.size(); + int nt = images[i].tf.size(); - for( int k = 1; k < nt; ++k ) { + for( int k = 1; k < nt; ++k ) { - const TAffine& T = images[i].tf[k]; + const TAffine& T = images[i].tf[k]; - if( !T.det() ) - continue; + if( !T.det() ) + continue; - vector pts; + vector pts; - pts.push_back( Point( 0.0, 0.0 ) ); - pts.push_back( Point( w-1, 0.0 ) ); - pts.push_back( Point( w-1, h-1 ) ); - pts.push_back( Point( 0.0, h-1 ) ); + pts.push_back( Point( 0.0, 0.0 ) ); + pts.push_back( Point( w-1, 0.0 ) ); + pts.push_back( Point( w-1, h-1 ) ); + pts.push_back( Point( 0.0, h-1 ) ); - for( int j = 0; j < 4; ++j ) { + for( int j = 0; j < 4; ++j ) { - T.Transform( pts[j] ); + T.Transform( pts[j] ); - xmin = fmin( xmin, pts[j].x ); - xmax = fmax( xmax, pts[j].x ); - ymin = fmin( ymin, pts[j].y ); - ymax = fmax( ymax, pts[j].y ); - } - } - } - } + xmin = fmin( xmin, pts[j].x ); + xmax = fmax( xmax, pts[j].x ); + ymin = fmin( ymin, pts[j].y ); + ymax = fmax( ymax, pts[j].y ); + } + } + } + } - printf( "Bounds of global image: x=[%f %f] y=[%f %f].\n", - xmin, xmax, ymin, ymax ); + printf( "Bounds of global image: x=[%f %f] y=[%f %f].\n", + xmin, xmax, ymin, ymax ); } /* --------------------------------------------------------------- */ @@ -423,92 +423,92 @@ static void GlobalBounds( // alignment easier. // static void OffsetCoords( - double &xmin, - double &xmax, - double &ymin, - double &ymax, - vector &images, - vector &x1, - vector &x2, - vector &y1, - vector &y2 ) + double &xmin, + double &xmax, + double &ymin, + double &ymax, + vector &images, + vector &x1, + vector &x2, + vector &y1, + vector &y2 ) { - int xfl = int(floor( xmin )); - int yfl = int(floor( ymin )); + int xfl = int(floor( xmin )); + int yfl = int(floor( ymin )); // bounds - xmin -= xfl; - xmax -= xfl; - ymin -= yfl; - ymax -= yfl; + xmin -= xfl; + xmax -= xfl; + ymin -= yfl; + ymax -= yfl; - printf( "Bounds of global image: x=[%f %f] y=[%f %f].\n", - xmin, xmax, ymin, ymax ); + printf( "Bounds of global image: x=[%f %f] y=[%f %f].\n", + xmin, xmax, ymin, ymax ); - if( gArgs.xsize != -1 ) { - xmax = gArgs.xsize; - ymax = gArgs.ysize; - } + if( gArgs.xsize != -1 ) { + xmax = gArgs.xsize; + ymax = gArgs.ysize; + } // transforms - xfl = -(xfl + gArgs.x0); - yfl = -(yfl + gArgs.y0); + xfl = -(xfl + gArgs.x0); + yfl = -(yfl + gArgs.y0); - int ni = images.size(); + int ni = images.size(); - for( int i = 0; i < ni; ++i ) { + for( int i = 0; i < ni; ++i ) { - int nt = images[i].tf.size(); + int nt = images[i].tf.size(); - for( int k = 1; k < nt; ++k ) { + for( int k = 1; k < nt; ++k ) { - TAffine& T = images[i].tf[k]; + TAffine& T = images[i].tf[k]; - if( !T.det() ) - continue; + if( !T.det() ) + continue; - T.AddXY( xfl, yfl ); - images[i].inv[k].InverseOf( T ); - } - } + T.AddXY( xfl, yfl ); + images[i].inv[k].InverseOf( T ); + } + } // debugging - print transforms #if 0 - for( int i = 0; i < ni; ++i ) { + for( int i = 0; i < ni; ++i ) { - int nt = images[i].tf.size(); + int nt = images[i].tf.size(); - for( int k = 1; k < nt; ++k ) { + for( int k = 1; k < nt; ++k ) { - const TAffine& T = images[i].tf[k]; + const TAffine& T = images[i].tf[k]; - if( !T.det() ) - continue; + if( !T.det() ) + continue; - printf( - "Post offset: image %d, layer %d tf[%d]" - " = %f %f %f %f %f %f\n", - i, images[i].layer, k, - T.t[0], T.t[1], T.t[2], - T.t[3], T.t[4], T.t[5] ); - } - } + printf( + "Post offset: image %d, layer %d tf[%d]" + " = %f %f %f %f %f %f\n", + i, images[i].layer, k, + T.t[0], T.t[1], T.t[2], + T.t[3], T.t[4], T.t[5] ); + } + } #endif // correspondence points - int n = x1.size(); + int n = x1.size(); - for( int i = 0; i < n; ++i ) { + for( int i = 0; i < n; ++i ) { - x1[i] += xfl; - x2[i] += xfl; - y1[i] += yfl; - y2[i] += yfl; - } + x1[i] += xfl; + x2[i] += xfl; + y1[i] += yfl; + y2[i] += yfl; + } } /* --------------------------------------------------------------- */ @@ -517,31 +517,31 @@ static void OffsetCoords( static uint8* LoadNormImg( const char *name, uint32 &w, uint32 &h ) { - uint8* ras = Raster8FromAny( name, w, h ); + uint8* ras = Raster8FromAny( name, w, h ); - if( !strstr( name, ".mrc" ) ) { + if( !strstr( name, ".mrc" ) ) { - double mean, std; - int np = w * h; - MeanStd m; + double mean, std; + int np = w * h; + MeanStd m; - for( int i = 0; i < np; ++i ) - m.Element( double(ras[i]) ); + for( int i = 0; i < np; ++i ) + m.Element( double(ras[i]) ); - m.Stats( mean, std ); + m.Stats( mean, std ); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - int pix = RND( 127 + (ras[i] - mean) / std * 30.0 ); + int pix = RND( 127 + (ras[i] - mean) / std * 30.0 ); - if( pix > 255 ) - pix = 255; + if( pix > 255 ) + pix = 255; - ras[i] = pix; - } - } + ras[i] = pix; + } + } - return ras; + return ras; } /* --------------------------------------------------------------- */ @@ -550,14 +550,14 @@ static uint8* LoadNormImg( const char *name, uint32 &w, uint32 &h ) static void PrintMagnitude( const vector &X ) { - int k = X.size() - 6; + int k = X.size() - 6; - if( k >= 0 ) { + if( k >= 0 ) { - double mag = sqrt( X[k]*X[k] + X[k+1]*X[k+1] ); + double mag = sqrt( X[k]*X[k] + X[k+1]*X[k+1] ); - printf( "Final magnitude is %g\n", mag ); - } + printf( "Final magnitude is %g\n", mag ); + } } /* --------------------------------------------------------------- */ @@ -568,7 +568,7 @@ static void PrintMagnitude( const vector &X ) // static bool lr( int sx, int sy, void *arg ) { - return sx == 21 && sy == 21; + return sx == 21 && sy == 21; } /* --------------------------------------------------------------- */ @@ -579,7 +579,7 @@ static bool lr( int sx, int sy, void *arg ) // static bool lc( int c1, int c2, void *arg ) { - return true; + return true; } /* --------------------------------------------------------------- */ @@ -592,12 +592,12 @@ static bool lc( int c1, int c2, void *arg ) // is part of the image i1, patch patch1. // static void CommonPoint( - vector &spots, - const vector &images, - Point pt, - int i1, - int patch1, - int out_layer ) + vector &spots, + const vector &images, + Point pt, + int i1, + int patch1, + int out_layer ) { Point p1 = pt; printf("image %d, global x,y= %f %f\n", i1, p1.x, p1.y); @@ -637,12 +637,12 @@ glob_spot s; // this will contain all the detailed info s.gpt = pt; for(int i=0; i ftc; // cache for Fourier transform @@ -674,11 +674,11 @@ for(int i=0; i dx, dy= %f, %f, corr %f\n\n", pt.x, dx, dy, co); if( co < 0.7 ) { @@ -700,8 +700,8 @@ if( s.which.size() > 1 ) { printf("More than one image for global point (%f %f)\n", pt.x, pt.y); // and add all the matching spots to the list for each image for(int i=0; i 126 ) - continue; + if( ch < 32 || ch > 126 ) + continue; - // draw as N times original size - //printf("draw character '%c' at %d, %d\n", ch, x, y); + // draw as N times original size + //printf("draw character '%c' at %d, %d\n", ch, x, y); - ch -= 32; + ch -= 32; - int N = 3; + int N = 3; - for( int dy = 0; dy < 7; ++dy ) { + for( int dy = 0; dy < 7; ++dy ) { - for( int dx = 0; dx < 5; ++dx ) { + for( int dx = 0; dx < 5; ++dx ) { - bool bit = (font5x7[ch][dy] & (1 << (4-dx))); + bool bit = (font5x7[ch][dy] & (1 << (4-dx))); - if( !bit ) - continue; + if( !bit ) + continue; - int bx = x + dx*N; - int by = y + dy*N; + int bx = x + dx*N; + int by = y + dy*N; - // draw an N x N box at (bx, by) + // draw an N x N box at (bx, by) - for( int j = 0; j < N; ++j ) { + for( int j = 0; j < N; ++j ) { - for( int k = 0; k < N; ++k ) { + for( int k = 0; k < N; ++k ) { - int m = bx+j + w*(by+k); + int m = bx+j + w*(by+k); - if( m < w*h ) - raster[m] = 0xFF; - } - } - } - } + if( m < w*h ) + raster[m] = 0xFF; + } + } + } + } - x += 6*N; - } + x += 6*N; + } } /* --------------------------------------------------------------- */ @@ -877,10 +877,10 @@ static double PseudoAngle( double y, double x ) { bool xish = fabs(y) <= fabs(x); // closer to x than y axis if( x > 0 && xish ) - return y/x; + return y/x; if( y > 0 ) { if( xish ) - return 4 + y/x; + return 4 + y/x; else return 2 - x/y; } @@ -914,45 +914,45 @@ vector setback; // pixels we will set back to 0 when we are done int nholes = 0; for(int i=start; i < np; i++) { if( map[i] == 0 ) { - start = i; // so next time resume here - stack st; - st.push(i); - vector boundary( 257, 0 ); // histogram of what we hit. + start = i; // so next time resume here + stack st; + st.push(i); + vector boundary( 257, 0 ); // histogram of what we hit. vector pixels; // 0 valued pixels in this area - while( !st.empty() ) { - int j = st.top(); st.pop(); + while( !st.empty() ) { + int j = st.top(); st.pop(); if( map[j] == 0 ) { - map[j] = 255; // so we won't get it again + map[j] = 255; // so we won't get it again pixels.push_back(j); - int y = j / w; - int x = j - w * y; - if( x-1 >= 0 ) st.push(j-1); else boundary[256]++; + int y = j / w; + int x = j - w * y; + if( x-1 >= 0 ) st.push(j-1); else boundary[256]++; if( x+1 < w ) st.push(j+1); else boundary[256]++; if( y-1 >= 0 ) st.push(j-w); else boundary[256]++; if( y+1 < h ) st.push(j+w); else boundary[256]++; - } + } else {// map value is not 0, add what we ran into to the set of boundary values - if( map[j] != 255 ) boundary[map[j]]++; - } - } + if( map[j] != 255 ) boundary[map[j]]++; + } + } // how many different things did we hit? And what was one of them? int howmany = 0, what = 0; for( int k = 0; k < 256; ++k ) { - if( boundary[k] != 0 ) { - howmany++; + if( boundary[k] != 0 ) { + howmany++; what = k; - } - } + } + } if( howmany == 1 ) { // then we have a hole, or a gap starting at a boundary - for( int k = 0; k < pixels.size(); ++k ) - map[pixels[k]] = what; + for( int k = 0; k < pixels.size(); ++k ) + map[pixels[k]] = what; nholes++; - } - else { // not a pure hole. record pixel values to set back later + } + else { // not a pure hole. record pixel values to set back later for(int k=0; k &images, - int im, - int patch, - Point p1, - vector &tris, - vector &gvtx, - int N, - int *which, - double *amts ) + vector &images, + int im, + int patch, + Point p1, + vector &tris, + vector &gvtx, + int N, + int *which, + double *amts ) { Point p = p1; images[im].tf[patch].Transform( p ); int first_tri = images[im].FirstTriangle + (patch-1)*N; // since N triangle per patch, and - // first one is #1 + // first one is #1 for(int i=first_tri; i < first_tri+N; i++) { if( Inside(tris[i], gvtx, p) ) { - printf("Got one - Point %f %f inside triangle (%f %f) (%f %f) (%f %f)\n", - p.x, p.y, - gvtx[tris[i].v[0]].x, gvtx[tris[i].v[0]].y, - gvtx[tris[i].v[1]].x, gvtx[tris[i].v[1]].y, - gvtx[tris[i].v[2]].x, gvtx[tris[i].v[2]].y ); + printf("Got one - Point %f %f inside triangle (%f %f) (%f %f) (%f %f)\n", + p.x, p.y, + gvtx[tris[i].v[0]].x, gvtx[tris[i].v[0]].y, + gvtx[tris[i].v[1]].x, gvtx[tris[i].v[1]].y, + gvtx[tris[i].v[2]].x, gvtx[tris[i].v[2]].y ); // find barycentric coordinates (linear combo of the three vertices amts[0] = tris[i].a[0][0]*p.x + tris[i].a[0][1]*p.y + tris[i].a[0][2]*1.0; amts[1] = tris[i].a[1][0]*p.x + tris[i].a[1][1]*p.y + tris[i].a[1][2]*1.0; amts[2] = tris[i].a[2][0]*p.x + tris[i].a[2][1]*p.y + tris[i].a[2][2]*1.0; printf("Barycentric coords: %f %f %f\n", amts[0], amts[1], amts[2] ); for(int k=0; k<3; k++) - which[k] = tris[i].v[k]; - return; - } + which[k] = tris[i].v[k]; + return; + } } printf("Oops - no triangle for point (%f %f)\n", p.x, p.y); exit( 42 ); @@ -1033,18 +1033,18 @@ exit( 42 ); // Write triangles out to a text file in a format gnuplot can read. // static void WriteTriangles( - const char *name, - vector &tris, - vector &pts ) + const char *name, + vector &tris, + vector &pts ) { FILE *ft = FileOpenOrDie( name, "w" ); for(int i=0; i &SPmapping ) + uint16 *test, + int w, + int h, + int &MaxSPUsed, + vector &SPmapping ) { int biggest = -1; vector vals(65536,0); @@ -1120,10 +1120,10 @@ int base = MaxSPUsed; // will add this to all int n=0; for(int i=1; i<65536; i++) { // 0 always maps to 0 if( vals[i] != 0 ) { // this value was used - MaxSPUsed++; + MaxSPUsed++; SPmapping[i] = MaxSPUsed; - n++; - } + n++; + } } printf("--- %d different values were used\n", n); // Now do the remapping @@ -1139,11 +1139,11 @@ for(int i=0; i &SPmapping ) + uint32 *test, + int w, + int h, + int &MaxSPUsed, + vector &SPmapping ) { // First find the biggest int biggest = -1; @@ -1152,7 +1152,7 @@ for(int i=0; i &tfs, - int xmin, - int ymin, - int xmax, - int ymax ) + uint32 w, + uint32 h, + vector &tfs, + int xmin, + int ymin, + int xmax, + int ymax ) { // make the four corners vector corners; @@ -1213,7 +1213,7 @@ for(int j=1; j &pts, - const Point ¢er, - double r, - double delta, - uint32 w, - uint32 h ) + vector &pts, + const Point ¢er, + double r, + double delta, + uint32 w, + uint32 h ) { - double lx = center.x - r; - double rx = center.x + r; - double by = center.y - r; - double ty = center.y + r; - vector ppts; // potential points - - for( double d = -r; d <= r; d += delta ) { - - ppts.push_back( Point( lx, center.y + d ) ); - ppts.push_back( Point( rx, center.y + d ) ); - ppts.push_back( Point( center.x + d, by ) ); - ppts.push_back( Point( center.x + d, ty ) ); - } + double lx = center.x - r; + double rx = center.x + r; + double by = center.y - r; + double ty = center.y + r; + vector ppts; // potential points + + for( double d = -r; d <= r; d += delta ) { + + ppts.push_back( Point( lx, center.y + d ) ); + ppts.push_back( Point( rx, center.y + d ) ); + ppts.push_back( Point( center.x + d, by ) ); + ppts.push_back( Point( center.x + d, ty ) ); + } // Now push back upper right corner, which might not be covered. - ppts.push_back( Point( rx, ty ) ); + ppts.push_back( Point( rx, ty ) ); // Now keep only those within the image // (can happen if image is a rectangle, not a square) - int n = ppts.size(); + int n = ppts.size(); - for( int i = 0; i < n; ++i ) { + for( int i = 0; i < n; ++i ) { - if( ppts[i].x >= 0.0 && - ppts[i].x <= w-1 && - ppts[i].y >= 0.0 && - ppts[i].y <= h-1 ) { + if( ppts[i].x >= 0.0 && + ppts[i].x <= w-1 && + ppts[i].y >= 0.0 && + ppts[i].y <= h-1 ) { - pts.push_back( ppts[i] ); - } - } + pts.push_back( ppts[i] ); + } + } } /* --------------------------------------------------------------- */ @@ -1377,70 +1377,70 @@ static void PointsInRing( // distortions are. // static void FillInFromCenterOut( - vector &imap, - vector &PatchFrom, - int nx, - int ny, - int w, - int h, // size of images coming in - double delta_image_space, // smallest size that maps to each pixel on output - vector &images, // the images - vector &relevant_images ) // the ones that are used among them + vector &imap, + vector &PatchFrom, + int nx, + int ny, + int w, + int h, // size of images coming in + double delta_image_space, // smallest size that maps to each pixel on output + vector &images, // the images + vector &relevant_images ) // the ones that are used among them { // find the center of each picture. May not be integer Point center((w-1)/2.0, (h-1)/2.0); int report = 100; for(double r=0.0; r <= max(center.x,center.y)+0.0001; r += delta_image_space) { if( r >= report ) { - printf("Starting radius %f\n", r); - report += 100; - } + printf("Starting radius %f\n", r); + report += 100; + } //compute a ring of radius R vector pts; PointsInRing(pts, center, r, delta_image_space, w, h); // Now transform this by all relevant images for(int k=0; k= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) - continue; - images[i].tf[patch].Transform( p ); // change to global coordinates - ix = ROUND(p.x); - iy = ROUND(p.y); - if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) - continue; // outside the image - //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); - uint32 nn = ix + uint32(iy)*uint32(nx); // index into array - if( imap[nn] == 0 ) { - imap[nn] = k+1; // this pixel will be set by the kth relevant picture - PatchFrom[nn] = patch; - } - else { // already set, but we still might be better (because of finite - // grid in source, rounding to int, ordering ). - Point pt_us = Point(ix,iy); - Point pt_ot = pt_us; - // transform back into original frames. - int oi = relevant_images[imap[nn]-1]; // other image - int op = PatchFrom[nn]; // other patch - images[oi].inv[op].Transform( pt_ot ); - images[i].inv[patch].Transform( pt_us ); - - double d_us = max(abs(pt_us.x-center.x), abs(pt_us.y-center.y)); // L-infinity norm - double d_ot = max(abs(pt_ot.x-center.x), abs(pt_ot.y-center.y)); // L-infinity norm - if( d_us < d_ot ) { - //printf("It CAN happen... d_us= %f, d_ot= %f\n", d_us, d_ot); - imap[nn] = k+1; // this pixel will be set by the ith picture - PatchFrom[nn] = patch; - } - } - } - } + int i = relevant_images[k]; + for(int j=0; j= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) + continue; + images[i].tf[patch].Transform( p ); // change to global coordinates + ix = ROUND(p.x); + iy = ROUND(p.y); + if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) + continue; // outside the image + //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); + uint32 nn = ix + uint32(iy)*uint32(nx); // index into array + if( imap[nn] == 0 ) { + imap[nn] = k+1; // this pixel will be set by the kth relevant picture + PatchFrom[nn] = patch; + } + else { // already set, but we still might be better (because of finite + // grid in source, rounding to int, ordering ). + Point pt_us = Point(ix,iy); + Point pt_ot = pt_us; + // transform back into original frames. + int oi = relevant_images[imap[nn]-1]; // other image + int op = PatchFrom[nn]; // other patch + images[oi].inv[op].Transform( pt_ot ); + images[i].inv[patch].Transform( pt_us ); + + double d_us = max(abs(pt_us.x-center.x), abs(pt_us.y-center.y)); // L-infinity norm + double d_ot = max(abs(pt_ot.x-center.x), abs(pt_ot.y-center.y)); // L-infinity norm + if( d_us < d_ot ) { + //printf("It CAN happen... d_us= %f, d_ot= %f\n", d_us, d_ot); + imap[nn] = k+1; // this pixel will be set by the ith picture + PatchFrom[nn] = patch; + } + } + } + } } } @@ -1456,11 +1456,11 @@ for(double r=0.0; r <= max(center.x,center.y)+0.0001; r += delta_image_space) { // class NameSorter{ public: - char *name; - int num; + char *name; + int num; public: - bool operator < ( const NameSorter &rhs ) const - {return strcmp( name, rhs.name ) < 0;}; + bool operator < ( const NameSorter &rhs ) const + {return strcmp( name, rhs.name ) < 0;}; }; /* --------------------------------------------------------------- */ @@ -1469,7 +1469,7 @@ class NameSorter{ static bool NameSortFn( NameSorter a, NameSorter b ) { - return strcmp( a.name, b.name ) > 0; + return strcmp( a.name, b.name ) > 0; } /* --------------------------------------------------------------- */ @@ -1477,15 +1477,15 @@ static bool NameSortFn( NameSorter a, NameSorter b ) /* --------------------------------------------------------------- */ static void FillInMatlabOrder( - vector &imap, - vector &PatchFrom, - int nx, - int ny, - int w, - int h, // size of images coming in - double delta_image_space, // smallest size that maps to each pixel on output - vector &images, // the images - vector &relevant_images) // the ones that are used among them + vector &imap, + vector &PatchFrom, + int nx, + int ny, + int w, + int h, // size of images coming in + double delta_image_space, // smallest size that maps to each pixel on output + vector &images, // the images + vector &relevant_images) // the ones that are used among them { // find the center of each picture. May not be integer Point center((w-1)/2.0, (h-1)/2.0); @@ -1505,36 +1505,36 @@ for(int kk=0; kk= report ) { - printf("Starting radius %f\n", r); - report += 500; - } - //compute a ring of radius R - vector pts; - PointsInRing(pts, center, r, delta_image_space, w, h); - // Now transform this by all relevant images - for(int j=0; j= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) - continue; - images[i].tf[patch].Transform( p ); // change to global coordinates - ix = ROUND(p.x); - iy = ROUND(p.y); - if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) - continue; // outside the image - //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); - uint32 nn = ix + uint32(iy)*uint32(nx); // index into array - if( imap[nn] == 0 ) { - imap[nn] = k+1; // this pixel will be set by the kth relevant picture - PatchFrom[nn] = patch; - } - } - } + if( r >= report ) { + printf("Starting radius %f\n", r); + report += 500; + } + //compute a ring of radius R + vector pts; + PointsInRing(pts, center, r, delta_image_space, w, h); + // Now transform this by all relevant images + for(int j=0; j= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) + continue; + images[i].tf[patch].Transform( p ); // change to global coordinates + ix = ROUND(p.x); + iy = ROUND(p.y); + if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) + continue; // outside the image + //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); + uint32 nn = ix + uint32(iy)*uint32(nx); // index into array + if( imap[nn] == 0 ) { + imap[nn] = k+1; // this pixel will be set by the kth relevant picture + PatchFrom[nn] = patch; + } + } + } } } @@ -1564,18 +1564,18 @@ for(pass=1; pass<=MAX_PASS; pass++) { if( stat(name, &buf) ) { // error, assume directory does not exist if( mkdir(name,0775) ) - printf("mkdir('%s') failed.\n", name); + printf("mkdir('%s') failed.\n", name); else // it worked, stop trying - break; + break; } else { // was able to stat the file; see if it's a directory if( !S_ISDIR(buf.st_mode) ) { - printf("File '%s' exists, but is not a directory.\n", name); - exit( 42 ); - } + printf("File '%s' exists, but is not a directory.\n", name); + exit( 42 ); + } else - break; // file exists and is a directory - } + break; // file exists and is a directory + } } if( pass > MAX_PASS ) exit( 42 ); @@ -1597,14 +1597,14 @@ dir_cache.insert(string(name)); // so each pixel can get a contribution from 1, 2, or 4 pixels. // static void CopyRaster( - uint8 *dest, - int w, - int h, - int dx, - int dy, - uint8 *src, - int sw, - int sh ) + uint8 *dest, + int w, + int h, + int dx, + int dy, + uint8 *src, + int sw, + int sh ) { // Do this a brute force way. Go through all the src pixels, mapping each to dest, // and counting how many map to each. Then average. @@ -1618,17 +1618,17 @@ int swt = sw & (~1); // create copies that are rounded down to nearest even int sht = sh & (~1); // stands for "source height truncated" for(int y=0; y &dir_cache ) + const char* rav_name, + int section, + int level, + int row, + int col, + set &dir_cache ) { // open the 4 relevant tiles - (row,col), (row+1,col), (row,col+1), and (row+1,col+1) uint32 w1, h1, w2, h2, w3, h3, w4, h4; @@ -1760,12 +1760,12 @@ return 1; // Condenses 4 tiles into 1, for SuperPixels. // static int WriteSummaryTileSP( - const char* rav_name, - int section, - int level, - int row, - int col, - set &dir_cache ) + const char* rav_name, + int section, + int level, + int row, + int col, + set &dir_cache ) { // open the 4 relevant tiles - (row,col), (row+1,col), (row,col+1), and (row+1,col+1) uint32 w1, h1, w2, h2, w3, h3, w4, h4; @@ -1833,9 +1833,9 @@ return 1; //Create smaller tiles, for images. // static void CreateLevelNTiles( - const char* rav_name, - int section, - set &dir_cache ) + const char* rav_name, + int section, + set &dir_cache ) { int at_this_level = 1; // so we loop at least once for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for trillions of tiles @@ -1851,7 +1851,7 @@ for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for tril wrote += stat; } at_this_level += wrote; - } + } printf("At level %d, wrote %d tiles\n", level, at_this_level); } } @@ -1863,9 +1863,9 @@ for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for tril //Create smaller tiles, for SuperPixels. // void CreateLevelNTilesSP( - const char* rav_name, - int section, - set &dir_cache ) + const char* rav_name, + int section, + set &dir_cache ) { int at_this_level = 1; // so we loop at least once for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for trillions of tiles @@ -1881,7 +1881,7 @@ for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for tril wrote += stat; } at_this_level += wrote; - } + } printf("SP:At level %d, wrote %d tiles\n", level, at_this_level); } } @@ -1893,49 +1893,49 @@ for(int level=1; level < 20 && at_this_level > 0; level++) { // enough for tril // Updates the meta-data file. For now, just writes. // static void UpdateMetaData( - const char *name, - int section, - int w, - int h ) + const char *name, + int section, + int w, + int h ) { - int zmin, zmax; - FILE *fd = fopen( name, "r" ); + int zmin, zmax; + FILE *fd = fopen( name, "r" ); - if( fd ) { + if( fd ) { - CLineScan LS; - ssize_t read; + CLineScan LS; + ssize_t read; - while( (read = LS.Get( fd )) > 0 ) { + while( (read = LS.Get( fd )) > 0 ) { - //printf( "Retrieved line of length %zu :\n", read ); + //printf( "Retrieved line of length %zu :\n", read ); - if( !strncmp( LS.line, "zmin=", 5 ) ) - zmin = min( section, atoi(LS.line+5) ); - if( !strncmp( LS.line, "zmax=", 5 ) ) - zmax = max( section, atoi(LS.line+5) ); - } + if( !strncmp( LS.line, "zmin=", 5 ) ) + zmin = min( section, atoi(LS.line+5) ); + if( !strncmp( LS.line, "zmax=", 5 ) ) + zmax = max( section, atoi(LS.line+5) ); + } - fclose( fd ); - } - else { // no file yet; make one with one layer - zmin = section; - zmax = section; - } + fclose( fd ); + } + else { // no file yet; make one with one layer + zmin = section; + zmax = section; + } // Now write the new file - fd = FileOpenOrDie( name, "w" ); + fd = FileOpenOrDie( name, "w" ); - fprintf( fd, "version=1\n" ); - fprintf( fd, "width=%d\n", w ); - fprintf( fd, "height=%d\n", h ); - fprintf( fd, "zmin=%d\n", zmin ); - fprintf( fd, "zmax=%d\n", zmax ); - fprintf( fd, "superpixel-format=RGBA\n" ); - fprintf( fd, "channels=\"g;s\"\n" ); + fprintf( fd, "version=1\n" ); + fprintf( fd, "width=%d\n", w ); + fprintf( fd, "height=%d\n", h ); + fprintf( fd, "zmin=%d\n", zmin ); + fprintf( fd, "zmax=%d\n", zmax ); + fprintf( fd, "superpixel-format=RGBA\n" ); + fprintf( fd, "channels=\"g;s\"\n" ); - fclose( fd ); + fclose( fd ); } /* --------------------------------------------------------------- */ @@ -1945,11 +1945,11 @@ static void UpdateMetaData( // Writes the lowest level image tiles. // static int WriteImageTiles( - const char* rav_name, - int section, - const uint8 *image, - int w, - int h ) + const char* rav_name, + int section, + const uint8 *image, + int w, + int h ) { set dir_cache; // names of directories already created string base_name = rav_name; @@ -1969,30 +1969,30 @@ for(int row = 0; row*1024 < h; row++) { sprintf(fname, "%s/%d", base_name.c_str(), row); MakeDirExist(fname, dir_cache); for(int col = 0; col*1024 < w; col++) { - int xmin = col*1024; // bottom scan line - int xmax = min(xmin+1023, w-1); // top scan line + int xmin = col*1024; // bottom scan line + int xmax = min(xmin+1023, w-1); // top scan line sprintf(fname, "%s/%d/%d", base_name.c_str(), row, col); // make the dir for the column - MakeDirExist(fname, dir_cache); + MakeDirExist(fname, dir_cache); sprintf(fname, "%s/%d/%d/g", base_name.c_str(), row, col); // and the grey scale underneath - MakeDirExist(fname, dir_cache); + MakeDirExist(fname, dir_cache); // now, copy the portion of the image from xmin..xmax to ymin..ymax; int new_w = xmax - xmin + 1; int n = 0; - for(int y=ymin; y<=ymax; y++) { + for(int y=ymin; y<=ymax; y++) { uint32 m = uint32(xmin) + uint32(y)*uint32(w); // location of first byte on scan line y of 'image' - for(int x=0; x < new_w; x++) - raster[n++] = image[m++]; - } + for(int x=0; x < new_w; x++) + raster[n++] = image[m++]; + } int dir = section/1000; if( dir == 0 ) // first layers are written in the root directory - sprintf(fname,"%s/%d/%d/g/%03d.png", base_name.c_str(), row, col, section); + sprintf(fname,"%s/%d/%d/g/%03d.png", base_name.c_str(), row, col, section); else { // need another layer of directories - sprintf(fname,"%s/%d/%d/g/%d", base_name.c_str(), row, col, dir*1000); - MakeDirExist(fname, dir_cache); - sprintf(fname,"%s/%d/%d/g/%d/%03d.png", base_name.c_str(), row, col, dir*1000, section); - } + sprintf(fname,"%s/%d/%d/g/%d", base_name.c_str(), row, col, dir*1000); + MakeDirExist(fname, dir_cache); + sprintf(fname,"%s/%d/%d/g/%d/%03d.png", base_name.c_str(), row, col, dir*1000, section); + } Raster8ToPng8( fname, raster, new_w, ymax-ymin+1 ); - } + } } free(raster); @@ -2008,11 +2008,11 @@ return 0; // Writes the lowest level SP tiles. // static int WriteSPTiles( - const char* rav_name, - int section, - uint32 *image, - int w, - int h ) + const char* rav_name, + int section, + uint32 *image, + int w, + int h ) { set dir_cache; // names of directories already created string base_name = rav_name; @@ -2032,30 +2032,30 @@ for(int row = 0; row*1024 < h; row++) { sprintf(fname, "%s/%d", base_name.c_str(), row); MakeDirExist(fname, dir_cache); for(int col = 0; col*1024 < w; col++) { - int xmin = col*1024; // bottom scan line - int xmax = min(xmin+1023, w-1); // top scan line + int xmin = col*1024; // bottom scan line + int xmax = min(xmin+1023, w-1); // top scan line sprintf(fname, "%s/%d/%d", base_name.c_str(), row, col); // make the dir for the column - MakeDirExist(fname, dir_cache); + MakeDirExist(fname, dir_cache); sprintf(fname, "%s/%d/%d/s", base_name.c_str(), row, col); // and the sp map underneath - MakeDirExist(fname, dir_cache); + MakeDirExist(fname, dir_cache); // now, copy the portion of the image from xmin..xmax to ymin..ymax; int new_w = xmax - xmin + 1; int n = 0; - for(int y=ymin; y<=ymax; y++) { + for(int y=ymin; y<=ymax; y++) { uint32 m = uint32(xmin) + uint32(y)*uint32(w); // location of first byte on scan line y of 'image' - for(int x=0; x < new_w; x++) - raster[n++] = image[m++]; - } + for(int x=0; x < new_w; x++) + raster[n++] = image[m++]; + } int dir = section/1000; if (dir == 0) // first layers are written in the root directory - sprintf(fname,"%s/%d/%d/s/%03d.png", base_name.c_str(), row, col, section); + sprintf(fname,"%s/%d/%d/s/%03d.png", base_name.c_str(), row, col, section); else { // need another layer of directories - sprintf(fname,"%s/%d/%d/s/%d", base_name.c_str(), row, col, dir*1000); - MakeDirExist(fname, dir_cache); - sprintf(fname,"%s/%d/%d/s/%d/%03d.png", base_name.c_str(), row, col, dir*1000, section); - } + sprintf(fname,"%s/%d/%d/s/%d", base_name.c_str(), row, col, dir*1000); + MakeDirExist(fname, dir_cache); + sprintf(fname,"%s/%d/%d/s/%d/%03d.png", base_name.c_str(), row, col, dir*1000, section); + } Raster32ToPngRGBA( fname, raster, new_w, ymax-ymin+1 ); - } + } } free(raster); @@ -2072,38 +2072,38 @@ return 0; class Bookmark { public: - string text; - Point pt; - int z; - int body_id; - int image_number; + string text; + Point pt; + int z; + int body_id; + int image_number; public: - bool operator < ( const Bookmark &rhs ) const - {return image_number < rhs.image_number;}; + bool operator < ( const Bookmark &rhs ) const + {return image_number < rhs.image_number;}; }; class Partner { public: - double confidence; - Point pt; - int body_id; - int z; + double confidence; + Point pt; + int body_id; + int z; }; class TBar { public: - string status; - double confidence; - Point pt; - int z; - vector partners; - int body_id; - int image_number; + string status; + double confidence; + Point pt; + int z; + vector partners; + int body_id; + int image_number; public: - bool operator < ( const TBar &rhs ) const - {return image_number < rhs.image_number;}; + bool operator < ( const TBar &rhs ) const + {return image_number < rhs.image_number;}; }; /* --------------------------------------------------------------- */ @@ -2111,9 +2111,9 @@ class TBar { /* --------------------------------------------------------------- */ static bool ReadBookmarks( - char *fname, - int section, - vector &bookmarks ) + char *fname, + int section, + vector &bookmarks ) { Json::Value root; // will contains the root value after parsing. Json::Reader reader; @@ -2154,10 +2154,10 @@ for( unsigned int i = 0; i < nd; ++i ) { Json::Value lo = v["location"]; b.z = lo[2u].asInt(); if( b.z == section ) { - b.pt.x = lo[0u].asDouble(); - b.pt.y = lo[1u].asDouble(); + b.pt.x = lo[0u].asDouble(); + b.pt.y = lo[1u].asDouble(); bookmarks.push_back(b); - } + } } return true; } @@ -2167,9 +2167,9 @@ return true; /* --------------------------------------------------------------- */ static bool ReadSynAnnot( - char *fname, - int section, - vector &tbs ) + char *fname, + int section, + vector &tbs ) { Json::Value root; // will contains the root value after parsing. Json::Reader reader; @@ -2211,27 +2211,27 @@ for( unsigned int i = 0; i < nd; ++i ) { TBar tb; tb.z = lo[2u].asInt(); if( tb.z == section ) { - tb.status = t["status"].asString(); - tb.confidence = t["confidence"].asDouble(); - tb.body_id = t["body ID"].asInt(); - tb.pt.x = lo[0u].asDouble(); - tb.pt.y = lo[1u].asDouble(); - //printf("status is %s, confidence %f, loc %.1f,%lf,%d, %d partners\n", - //tb.status.c_str(), tb.confidence, tb.pt.x, tb.pt.y, tb.z, part.size() ); - for(int j=0; j &images, - bool Warp, - vector &tmap, - vector &result ) + const char *name, + char *root, + int section, + int image_no, + vector &images, + bool Warp, + vector &tmap, + vector &result ) { uint32 w = images[image_no].w; uint32 h = images[image_no].h; @@ -2274,11 +2274,11 @@ if( strstr(name, "annotations-synapse") != NULL ) { Point p = tbs[j].pt; int ix = int(p.x); int iy = int(p.y); - // make sure it's legal - if( ix < 0 || ix >= w || iy < 0 || iy >= h ) { - printf("Synapse outside diagram?? %d %d %d %d\n", ix, w, iy, h); - continue; - } + // make sure it's legal + if( ix < 0 || ix >= w || iy < 0 || iy >= h ) { + printf("Synapse outside diagram?? %d %d %d %d\n", ix, w, iy, h); + continue; + } int patch = images[image_no].foldmap[ix + w*iy]; // There can be small patches which were not used, so need to check for legality here // // No longer needed since we compress patches and foldmaps on input @@ -2290,13 +2290,13 @@ if( strstr(name, "annotations-synapse") != NULL ) { else { //we are warping int sector = tmap[ix + w*iy]; t = images[image_no].sectors[patch][sector]; - } + } t.Transform( p ); tbs[j].pt = p; - for(int m=0; m &images, - bool Warp, - vector &tmap, - vector &result ) + const char *name, + char *root, + int section, + int image_no, + vector &images, + bool Warp, + vector &tmap, + vector &result ) { uint32 w = images[image_no].w; uint32 h = images[image_no].h; @@ -2340,7 +2340,7 @@ if( strstr(name, "annotations-bookmarks") != NULL ) { // one, then look up the reverse transformation from global space, and find // the one that maps here. for(int j=0; j= images[i].tf.size() || images[i].tf[patch].det() == 0.0) continue; TAffine t; - if( !Warp ) // just one transform per image - t = images[image_no].tf[patch]; // change to global coordinates + if( !Warp ) // just one transform per image + t = images[image_no].tf[patch]; // change to global coordinates else { //we are warping - int sector = tmap[ix+iy*w]; + int sector = tmap[ix+iy*w]; t = images[image_no].sectors[patch][sector]; } t.Transform( p ); bookmarks[j].pt = p; - result.push_back(bookmarks[j]); - } + result.push_back(bookmarks[j]); + } } return true; } @@ -2383,7 +2383,7 @@ int main( int argc, char **argv ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); @@ -2406,309 +2406,309 @@ vector z1, z2; FILE *fp = FileOpenOrDie( gArgs.infile, "r" ); CLineScan *ls = new CLineScan; - for(;;) { + for(;;) { - if( ls->Get( fp ) <= 0 ) - break; + if( ls->Get( fp ) <= 0 ) + break; - if( !strncmp( ls->line, "DIR", 3 ) ) { + if( !strncmp( ls->line, "DIR", 3 ) ) { - // parallel vectors - char *z = strtok( ls->line + 4, " " ); - char *n = strtok( NULL, " \n" ); + // parallel vectors + char *z = strtok( ls->line + 4, " " ); + char *n = strtok( NULL, " \n" ); - lnums.push_back( atoi( z ) ); - dnames.push_back( strdup( n ) ); - } - else if( !strncmp( ls->line, "FOLDMAP", 7 ) ) { + lnums.push_back( atoi( z ) ); + dnames.push_back( strdup( n ) ); + } + else if( !strncmp( ls->line, "FOLDMAP", 7 ) ) { - char *tname = strtok( ls->line + 7, " '\n" ); - char *mname = strtok( NULL, " '\n" ); - int id_dum; + char *tname = strtok( ls->line + 7, " '\n" ); + char *mname = strtok( NULL, " '\n" ); + int id_dum; - if( !tname || !mname ) { - printf( "Bad FOLDMAP statement '%s'.", ls->line ); - exit( 42 ); - } + if( !tname || !mname ) { + printf( "Bad FOLDMAP statement '%s'.", ls->line ); + exit( 42 ); + } - map::iterator it = imap.find(string(tname)); + map::iterator it = imap.find(string(tname)); - if( it != imap.end() ) - continue; // already seen this one + if( it != imap.end() ) + continue; // already seen this one - // Get image dimensions - if( !w ) { - uint8 *r = Raster8FromAny( tname, w, h ); - RasterFree( r ); - w /= gArgs.scale; - h /= gArgs.scale; - } + // Get image dimensions + if( !w ) { + uint8 *r = Raster8FromAny( tname, w, h ); + RasterFree( r ); + w /= gArgs.scale; + h /= gArgs.scale; + } - image ii; + image ii; - ii.raster = NULL; - ii.foldmap = NULL; - ii.bmap = NULL; - ii.w = w; - ii.h = h; - ii.spbase = 0; - ii.rname = strdup( tname ); - ii.fname = strdup( mname ); - ii.spname = NULL; - ii.bname = NULL; - ii.spmap = NULL; + ii.raster = NULL; + ii.foldmap = NULL; + ii.bmap = NULL; + ii.w = w; + ii.h = h; + ii.spbase = 0; + ii.rname = strdup( tname ); + ii.fname = strdup( mname ); + ii.spname = NULL; + ii.bname = NULL; + ii.spmap = NULL; - ZIDFromFMPath( ii.layer, id_dum, mname ); + ZIDFromFMPath( ii.layer, id_dum, mname ); - if( gArgs.lspec1 < 0 || - (gArgs.lspec1 <= ii.layer && ii.layer <= gArgs.lspec2) ) { + if( gArgs.lspec1 < 0 || + (gArgs.lspec1 <= ii.layer && ii.layer <= gArgs.lspec2) ) { - // Point at drawing (d-suffixed) foldmap if exists + // Point at drawing (d-suffixed) foldmap if exists - char *suf = strstr( mname, ".tif" ); + char *suf = strstr( mname, ".tif" ); - if( suf ) { + if( suf ) { - char buf[2048]; + char buf[2048]; - sprintf( buf, "%.*sd.tif", suf - mname, mname ); + sprintf( buf, "%.*sd.tif", suf - mname, mname ); - if( DskExists( buf ) ) { - printf( "Using drawing file '%s'.\n", buf ); - free( ii.fname ); - ii.fname = strdup( buf ); - } - } + if( DskExists( buf ) ) { + printf( "Using drawing file '%s'.\n", buf ); + free( ii.fname ); + ii.fname = strdup( buf ); + } + } - // Finally, add to collection - imap[string(tname)] = images.size(); - images.push_back( ii ); + // Finally, add to collection + imap[string(tname)] = images.size(); + images.push_back( ii ); - lowest = min( lowest, ii.layer ); - highest = max( highest, ii.layer ); - } - } - else if( !strncmp( ls->line, "TRANSFORM", 9 ) ) { + lowest = min( lowest, ii.layer ); + highest = max( highest, ii.layer ); + } + } + else if( !strncmp( ls->line, "TRANSFORM", 9 ) ) { - char name[2048]; - double a, b, c, d, e, f; - int nread; + char name[2048]; + double a, b, c, d, e, f; + int nread; - // newer format has '' delimited name - // older just space separated + // newer format has '' delimited name + // older just space separated - if( ls->line[10] == '\'' ) { - nread = sscanf( - ls->line + 10, "'%[^']' %lf %lf %lf %lf %lf %lf", - name, &a, &b, &c, &d, &e, &f ); - } - else { - nread = sscanf( - ls->line + 10, "%s %lf %lf %lf %lf %lf %lf", - name, &a, &b, &c, &d, &e, &f ); - } + if( ls->line[10] == '\'' ) { + nread = sscanf( + ls->line + 10, "'%[^']' %lf %lf %lf %lf %lf %lf", + name, &a, &b, &c, &d, &e, &f ); + } + else { + nread = sscanf( + ls->line + 10, "%s %lf %lf %lf %lf %lf %lf", + name, &a, &b, &c, &d, &e, &f ); + } - if( 7 != nread ) { - printf( "Bad TRANSFORM statement '%s'.", ls->line ); - exit( 42 ); - } + if( 7 != nread ) { + printf( "Bad TRANSFORM statement '%s'.", ls->line ); + exit( 42 ); + } - TAffine tf( a, b, c/gArgs.scale, d, e, f/gArgs.scale ); - char *fname = strtok( name, " ':" ); + TAffine tf( a, b, c/gArgs.scale, d, e, f/gArgs.scale ); + char *fname = strtok( name, " ':" ); - //printf("File '%s'\n", fname); + //printf("File '%s'\n", fname); - map::iterator imit = imap.find(string(fname)); + map::iterator imit = imap.find(string(fname)); - if( imit == imap.end() ) { + if( imit == imap.end() ) { - // This is normal with single layer image generation. + // This is normal with single layer image generation. - //printf( "File in TRANSFORM has no FOLDMAP - ignored.\n" ); - continue; - } + //printf( "File in TRANSFORM has no FOLDMAP - ignored.\n" ); + continue; + } - int k = imit->second; + int k = imit->second; - // get the rest of the string, now of the form ::123 - int patch = atoi( strtok( NULL, " :'\n" ) ); + // get the rest of the string, now of the form ::123 + int patch = atoi( strtok( NULL, " :'\n" ) ); - printf( "ImageIdx::patch = %d::%d\n", k, patch ); + printf( "ImageIdx::patch = %d::%d\n", k, patch ); - // Make new slot? - if( images[k].tf.size() <= patch ) { + // Make new slot? + if( images[k].tf.size() <= patch ) { - // initialize to an illegal transform - images[k].tf.resize( patch+1, TAffine(0,0,0,0,0,0) ); - images[k].inv.resize( patch+1 ); - } + // initialize to an illegal transform + images[k].tf.resize( patch+1, TAffine(0,0,0,0,0,0) ); + images[k].inv.resize( patch+1 ); + } - images[k].tf[patch] = tf; - } - else if( !strncmp( ls->line, "SPMAP", 5 ) ) { + images[k].tf[patch] = tf; + } + else if( !strncmp( ls->line, "SPMAP", 5 ) ) { - char name[2048], where[2048]; - int z, nprm; + char name[2048], where[2048]; + int z, nprm; - nprm = sscanf( ls->line + 5, "%s %s %d", name, where, &z ); + nprm = sscanf( ls->line + 5, "%s %s %d", name, where, &z ); - if( nprm < 2 ) { - printf( "Bad SPMAP statement '%s'.", ls->line ); - exit( 42 ); - } + if( nprm < 2 ) { + printf( "Bad SPMAP statement '%s'.", ls->line ); + exit( 42 ); + } - char *fname = strtok( name, " ':" ); + char *fname = strtok( name, " ':" ); - //printf("File '%s'\n", fname); + //printf("File '%s'\n", fname); - map::iterator imit = imap.find(string(fname)); + map::iterator imit = imap.find(string(fname)); - if( imit == imap.end() ) { + if( imit == imap.end() ) { - // This is normal with single layer image generation. - // If it's a layer we care about, print a message. - // Otherwise silently ignore. + // This is normal with single layer image generation. + // If it's a layer we care about, print a message. + // Otherwise silently ignore. - int layer; + int layer; - if( nprm > 2 ) - layer = z; - else - layer = FileNameToLayerNumber( dnames, lnums, fname ); + if( nprm > 2 ) + layer = z; + else + layer = FileNameToLayerNumber( dnames, lnums, fname ); - if( gArgs.lspec1 < 0 || - (gArgs.lspec1 <= layer && layer <= gArgs.lspec2) ) { + if( gArgs.lspec1 < 0 || + (gArgs.lspec1 <= layer && layer <= gArgs.lspec2) ) { - printf( - "File in SPMAP has no image - ignored.\n" ); - } + printf( + "File in SPMAP has no image - ignored.\n" ); + } - continue; - } + continue; + } - int k = imit->second; + int k = imit->second; - printf( "ImageIdx = %d\n", k ); - images[k].spname = strdup( where ); - } - else if( !strncmp( ls->line, "BOUNDARYMAP", 11 ) ) { + printf( "ImageIdx = %d\n", k ); + images[k].spname = strdup( where ); + } + else if( !strncmp( ls->line, "BOUNDARYMAP", 11 ) ) { - char name[2048], where[2048]; - int z, nprm; + char name[2048], where[2048]; + int z, nprm; - nprm = sscanf( ls->line + 11, "%s %s %d", name, where, &z ); + nprm = sscanf( ls->line + 11, "%s %s %d", name, where, &z ); - if( nprm < 2 ) { - printf( "Bad BOUNDARYMAP statement '%s'.", ls->line ); - exit( 42 ); - } + if( nprm < 2 ) { + printf( "Bad BOUNDARYMAP statement '%s'.", ls->line ); + exit( 42 ); + } - char *fname = strtok( name, " ':" ); + char *fname = strtok( name, " ':" ); - //printf("File '%s'\n", fname); + //printf("File '%s'\n", fname); - map::iterator imit = imap.find(string(fname)); + map::iterator imit = imap.find(string(fname)); - if( imit == imap.end() ) { + if( imit == imap.end() ) { - // This is normal with single layer image generation. - // If it's a layer we care about, print a message. - // Otherwise silently ignore. + // This is normal with single layer image generation. + // If it's a layer we care about, print a message. + // Otherwise silently ignore. - int layer; + int layer; - if( nprm > 2 ) - layer = z; - else - layer = FileNameToLayerNumber( dnames, lnums, fname ); + if( nprm > 2 ) + layer = z; + else + layer = FileNameToLayerNumber( dnames, lnums, fname ); - if( gArgs.lspec1 < 0 || - (gArgs.lspec1 <= layer && layer <= gArgs.lspec2) ) { + if( gArgs.lspec1 < 0 || + (gArgs.lspec1 <= layer && layer <= gArgs.lspec2) ) { - printf( - "File in BOUNDARYMAP has no image - ignored.\n" ); - } + printf( + "File in BOUNDARYMAP has no image - ignored.\n" ); + } - continue; - } + continue; + } - int k = imit->second; + int k = imit->second; - printf( "ImageIdx = %d\n", k ); - images[k].bname = strdup( where ); - } - else if( !strncmp( ls->line, "MPOINTS", 7 ) ) { + printf( "ImageIdx = %d\n", k ); + images[k].bname = strdup( where ); + } + else if( !strncmp( ls->line, "MPOINTS", 7 ) ) { - double a, b, c, d; - int za, zc; + double a, b, c, d; + int za, zc; - if( 6 != sscanf( ls->line + 7, - "%d %lf %lf %d %lf %lf", - &za, &a, &b, &zc, &c, &d ) ) { + if( 6 != sscanf( ls->line + 7, + "%d %lf %lf %d %lf %lf", + &za, &a, &b, &zc, &c, &d ) ) { - printf( "Bad MPOINTS statement '%s'.", ls->line ); - exit( 42 ); - } + printf( "Bad MPOINTS statement '%s'.", ls->line ); + exit( 42 ); + } - if( gArgs.lspec1 < 0 || - (gArgs.lspec1-1 <= za && za <= gArgs.lspec2+1) || - (gArgs.lspec1-1 <= zc && zc <= gArgs.lspec2+1) ) { + if( gArgs.lspec1 < 0 || + (gArgs.lspec1-1 <= za && za <= gArgs.lspec2+1) || + (gArgs.lspec1-1 <= zc && zc <= gArgs.lspec2+1) ) { - z1.push_back( za ); - x1.push_back( a/gArgs.scale ); - y1.push_back( b/gArgs.scale ); + z1.push_back( za ); + x1.push_back( a/gArgs.scale ); + y1.push_back( b/gArgs.scale ); - z2.push_back( zc ); - x2.push_back( c/gArgs.scale ); - y2.push_back( d/gArgs.scale ); - } - } - else if( !strncmp( ls->line, "BBOX", 4 ) ) { + z2.push_back( zc ); + x2.push_back( c/gArgs.scale ); + y2.push_back( d/gArgs.scale ); + } + } + else if( !strncmp( ls->line, "BBOX", 4 ) ) { - if( 4 != sscanf( ls->line + 4, - "%lf %lf %lf %lf", &xmin, &ymin, &xmax, &ymax ) ) { + if( 4 != sscanf( ls->line + 4, + "%lf %lf %lf %lf", &xmin, &ymin, &xmax, &ymax ) ) { - printf( "Bad BBOX statement '%s'.\n", ls->line ); - exit( 42 ); - } + printf( "Bad BBOX statement '%s'.\n", ls->line ); + exit( 42 ); + } - xmin /= gArgs.scale; - ymin /= gArgs.scale; - xmax /= gArgs.scale; - ymax /= gArgs.scale; - } - else if( !strncmp( ls->line, "IMAGESIZE", 9 ) ) { + xmin /= gArgs.scale; + ymin /= gArgs.scale; + xmax /= gArgs.scale; + ymax /= gArgs.scale; + } + else if( !strncmp( ls->line, "IMAGESIZE", 9 ) ) { - if( 2 != sscanf( ls->line + 10, "%d %d", &w, &h ) ) { - printf( "Bad IMAGESIZE line '%s'.\n", ls->line ); - exit( 42 ); - } + if( 2 != sscanf( ls->line + 10, "%d %d", &w, &h ) ) { + printf( "Bad IMAGESIZE line '%s'.\n", ls->line ); + exit( 42 ); + } - w /= gArgs.scale; - h /= gArgs.scale; - } - else { - printf( "Unknown line '%s'.", ls->line ); - exit( 42 ); - } - } + w /= gArgs.scale; + h /= gArgs.scale; + } + else { + printf( "Unknown line '%s'.", ls->line ); + exit( 42 ); + } + } - delete ls; - fclose( fp ); + delete ls; + fclose( fp ); //VMStats( stdout ); //exit( 11 ); - if( !images.size() ) { - printf( "No images in input.\n" ); - exit( 42 ); - } + if( !images.size() ) { + printf( "No images in input.\n" ); + exit( 42 ); + } - GlobalBounds( xmin, xmax, ymin, ymax, images, w, h ); + GlobalBounds( xmin, xmax, ymin, ymax, images, w, h ); - OffsetCoords( xmin, xmax, ymin, ymax, images, x1, y1, x2, y2 ); + OffsetCoords( xmin, xmax, ymin, ymax, images, x1, y1, x2, y2 ); @@ -2738,8 +2738,8 @@ if( gArgs.lspec1 >= 0 ) { // layer numbers were specified double delta_image_space = 2.0; // implausibly high value for(int i=0; i relevant_images; // See if we find any boundary maps @@ -2807,86 +2807,86 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u int MaxSPUsed = 0; for(int i=0; iimap(nx*ny,0); if( relevant_images.size() > 0xFFFF ) { // since we hold this as 16 bits - printf("Too many images (%d) on layer %d\n", relevant_images.size(), out_layer); - exit( 42 ); - } + printf("Too many images (%d) on layer %d\n", relevant_images.size(), out_layer); + exit( 42 ); + } vectorPatchFrom(nx*ny,0); // Now the choice of fill-in methods if( gArgs.matlab_order ) { - FillInMatlabOrder( imap, PatchFrom, nx, ny, - w, h, delta_image_space, images, relevant_images ); + FillInMatlabOrder( imap, PatchFrom, nx, ny, + w, h, delta_image_space, images, relevant_images ); } else { - FillInFromCenterOut( imap, PatchFrom, nx, ny, - w, h, delta_image_space, images, relevant_images ); - } + FillInFromCenterOut( imap, PatchFrom, nx, ny, + w, h, delta_image_space, images, relevant_images ); + } // Now compress the map/patch array. We assume less than 65536 combinations are used, so we can express // this as a 16 bit TIF. The combinations start at 1, and run sequentially. @@ -2925,22 +2925,22 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vectorhisto(10); // small histogram, for testing for(uint32 i=0; i::iterator it = temp.find(id); if( it == temp.end() ) { // add it - Triple t(imap[i], PatchFrom[i], 0); - temp.insert(pair(id, Triples.size())); + Triple t(imap[i], PatchFrom[i], 0); + temp.insert(pair(id, Triples.size())); printf("New combo %5d: %d %d at %d\n", Triples.size(), t.image, t.patch, i); Triples.push_back(t); - it = temp.find(id); // now should find it, since we just added it - } + it = temp.find(id); // now should find it, since we just added it + } imap[i] = it->second; if( it->second < 10 ) - histo[it->second]++; - } + histo[it->second]++; + } for(int i=0; i<10; i++) - printf("Entry %d used %d times.\n", i, histo[i]); + printf("Entry %d used %d times.\n", i, histo[i]); @@ -2956,7 +2956,7 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u printf("Writing 8 bit map in png format to %s\n", fname); vector copy(nx*ny, 0); // make an 8 bit copy for(int i=0; ibefore(nx*ny,0); for(int y=0; y < ny; y++) { if( (y & 0x3FF) == 0 ) { - printf("."); fflush(stdout); + printf("."); fflush(stdout); } - for(int x=0; x= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate - int ix = int(p.x); - int iy = int(p.y); - double alpha = p.x-ix; - double beta = p.y-iy; - int nn = ix + w*iy; // index into original image - uint8* pic = images[img].raster; - double pix = - (1-alpha)*(1-beta) * pic[nn] + - alpha *(1-beta) * pic[nn+1] + - (1-alpha)* beta * pic[nn+w] + - alpha * beta * pic[nn+w+1]; - before[bi] = ROUND(pix); - } - } // to aid debugging, draw lines at the image boundaries in the before image. + if( from == 0 ) + continue; // no image sets this pixel + int img = relevant_images[from-1]; + Point p(x, y); + images[img].inv[patch].Transform( p ); + // of course, this should be in the image, but let's double check + if( p.x >= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate + int ix = int(p.x); + int iy = int(p.y); + double alpha = p.x-ix; + double beta = p.y-iy; + int nn = ix + w*iy; // index into original image + uint8* pic = images[img].raster; + double pix = + (1-alpha)*(1-beta) * pic[nn] + + alpha *(1-beta) * pic[nn+1] + + (1-alpha)* beta * pic[nn+w] + + alpha * beta * pic[nn+w+1]; + before[bi] = ROUND(pix); + } + } // to aid debugging, draw lines at the image boundaries in the before image. } printf("Done creating before image; draw lines next\n"); if( gArgs.Annotate ) { - vector edges; - for(int x=0; x edges; + for(int x=0; x 0 && p.x < nx-1 && p.y > 0 && p.y < ny-1 ) - DrawText(&before[0], nx, ny, fn, int(p.x), int(p.y)); - } - //also to aid in debugging, draw circles at correspondence points - for(int i=0; i 0x7FFFFFFFu ) { // is it *really* big? - printf( "write half\n" ); - sprintf( fname, "before.%05d.a.png", out_layer ); - Raster8ToPng8( fname, &before[0], nx, ny/2 ); - printf( "write the other half\n" ); - sprintf( fname, "before.%05d.b.png", out_layer ); - Raster8ToPng8( fname, &before[nx*ny/2], nx, ny/2 ); - printf( "both written\n" ); - } - else { // this is the usual case - sprintf( fname, "before.%05d.png", out_layer ); - Raster8ToPng8( fname, &before[0], nx, ny ); - } - } + if( nx*ny > 0x7FFFFFFFu ) { // is it *really* big? + printf( "write half\n" ); + sprintf( fname, "before.%05d.a.png", out_layer ); + Raster8ToPng8( fname, &before[0], nx, ny/2 ); + printf( "write the other half\n" ); + sprintf( fname, "before.%05d.b.png", out_layer ); + Raster8ToPng8( fname, &before[nx*ny/2], nx, ny/2 ); + printf( "both written\n" ); + } + else { // this is the usual case + sprintf( fname, "before.%05d.png", out_layer ); + Raster8ToPng8( fname, &before[0], nx, ny ); + } + } @@ -3074,29 +3074,29 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u sprintf( fname, "%s/%s/map.%05d.png", gArgs.region_dir, gArgs.inv_dir, out_layer ); printf( "write Pixel mapping file %s\n", fname ); Raster16ToPng16( fname, &imap[0], nx, ny ); - // ------------------------------------------------ write the mapping text file -------------------- - // This is the text file that contains the transformations that describe how each pixel got there. - sprintf( fname, "%s/%s/mapping.%05d.txt", gArgs.region_dir, gArgs.inv_dir, out_layer ); - FILE *ftxt = FileOpenOrDie( fname, "w" ); - //write the image names, and their indexes - for(int k=0; k gvtx; for(int m=0; m spots; const int delta = 40; for(int ty=0; ty 0 && image2 > 0 ) { // found a boundary + if( image1 != image2 && image1 > 0 && image2 > 0 ) { // found a boundary if (tx - prev_x < delta && // see if it's a duplicate of previous one (indx1 == prev_i1 && indx2 == prev_i2 || indx1 == prev_i2 && indx2 == prev_i1)) - printf("Same images, too close, at %d\n", tx); + printf("Same images, too close, at %d\n", tx); else { // it's Ok - Ntrans++; - int i1 = relevant_images[image1-1]; - int i2 = relevant_images[image2-1]; // point is on boundary of image i1 and i2 - //i2 = i1; // temp, just to make sure we get 0,0 - Point p1(tx,ty); - CommonPoint( spots, images, p1,i1, Triples[indx1].patch, out_layer ); - prev_x = tx; prev_i1 = indx1; prev_i2 = indx2; - } - } - } + Ntrans++; + int i1 = relevant_images[image1-1]; + int i2 = relevant_images[image2-1]; // point is on boundary of image i1 and i2 + //i2 = i1; // temp, just to make sure we get 0,0 + Point p1(tx,ty); + CommonPoint( spots, images, p1,i1, Triples[indx1].patch, out_layer ); + prev_x = tx; prev_i1 = indx1; prev_i2 = indx2; + } + } + } if( Ntrans > 100 ) { - printf("Too many transitions (%d) in map!\n", Ntrans); + printf("Too many transitions (%d) in map!\n", Ntrans); if( !gArgs.Debug ) { - printf("Writing map as 'test.png'\n"); - Raster16ToPng16( "test.png", &imap[0], nx, ny ); - } + printf("Writing map as 'test.png'\n"); + Raster16ToPng16( "test.png", &imap[0], nx, ny ); + } exit( 42 ); - } - } + } + } for(int tx=0; tx 0 && image2 > 0 ) { // found a boundary + if( image1 != image2 && image1 > 0 && image2 > 0 ) { // found a boundary if (ty - prev_y < delta && // see if it's a duplicate of previous one (indx1 == prev_i1 && indx2 == prev_i2 || indx1 == prev_i2 && indx2 == prev_i1)) - printf("Same images, too close, at %d\n", ty); + printf("Same images, too close, at %d\n", ty); else { // it's Ok - Ntrans++; - int i1 = relevant_images[image1-1]; // -1 since 0 is reserved for 'no image maps here' - int i2 = relevant_images[image2-1]; // point is on boundary of image i1 and i2 - //i2 = i1; // temp, just to make sure we get 0,0 - Point p1(tx,ty); - CommonPoint( spots, images, p1,i1, Triples[indx1].patch, out_layer ); - prev_y = ty; prev_i1 = indx1; prev_i2 = indx2; - } - } - } + Ntrans++; + int i1 = relevant_images[image1-1]; // -1 since 0 is reserved for 'no image maps here' + int i2 = relevant_images[image2-1]; // point is on boundary of image i1 and i2 + //i2 = i1; // temp, just to make sure we get 0,0 + Point p1(tx,ty); + CommonPoint( spots, images, p1,i1, Triples[indx1].patch, out_layer ); + prev_y = ty; prev_i1 = indx1; prev_i2 = indx2; + } + } + } if( Ntrans > 100 ) { - printf("Too many transitions (%d) in map!\n", Ntrans); + printf("Too many transitions (%d) in map!\n", Ntrans); if( !gArgs.Debug ) { - printf("Writing map as 'test.png'\n"); - Raster16ToPng16( "test.png", &imap[0], nx, ny ); - } + printf("Writing map as 'test.png'\n"); + Raster16ToPng16( "test.png", &imap[0], nx, ny ); + } exit( 42 ); - } - } + } + } printf("%d global control points; %d constraints\n", gvtx.size(), spots.size() ); int nvs = gvtx.size(); // number of control points @@ -3299,33 +3299,33 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vector RHS(2*nvs, 0.0); // // first, add the constraints that each should be near where they started... for(int i=0; i X(2*nvs); fflush(stdout); @@ -3351,7 +3351,7 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vector NewG(nvs); for(int i=0; iMoveThresh ? "<-----" : ""); + printf("Image %d, pt %d, was (%f,%f), now (%f,%f), moved %f %s\n", + i/(N+1), i%(N+1), gvtx[i].x, gvtx[i].y, NewG[i].x, NewG[i].y, move, move>MoveThresh ? "<-----" : ""); if( move > MoveThresh ) { - NewG[i] = gvtx[i]; - NTooFar++; - } - } + NewG[i] = gvtx[i]; + NTooFar++; + } + } // Now, for every patch of every image, compute a vector of N transforms, one corresponding // to each original triangle. for(int m=0; m empty; images[i].sectors.push_back(empty); // since there is no patch 0 images[i].sinvs .push_back(empty); - for(int j=1; j ltfs(N); // an N element vector of transforms - vector invs(N); // and the inverses to these + for(int j=1; j ltfs(N); // an N element vector of transforms + vector invs(N); // and the inverses to these printf("Image %d, patch %d\n", i, j); images[i].tf[j].TPrint(); - for(int k=0; k pts; - PointsInRing(pts, center, r, delta_image_space*0.9, w, h); + vector pts; + PointsInRing(pts, center, r, delta_image_space*0.9, w, h); // Now transform this by all relevant images - for(int k=0; k= images[i].tf.size() || images[i].tf[patch].det() == 0.0 ) - continue; - images[i].sectors[patch][sector].Transform( p ); // change to global coordinates - ix = ROUND(p.x); - iy = ROUND(p.y); + continue; + images[i].sectors[patch][sector].Transform( p ); // change to global coordinates + ix = ROUND(p.x); + iy = ROUND(p.y); if( ix == 8557 && iy == 431 ) { printf("Point %f %f in image %s\n", pts[j].x, pts[j].y, images[i].rname); - printf("Maps to pixel %d %d, image %d patch %d sector %d\n", ix, iy, i, patch, sector); + printf("Maps to pixel %d %d, image %d patch %d sector %d\n", ix, iy, i, patch, sector); images[i].sectors[patch][sector].TPrint( stdout, "Transform is " ); images[i]. sinvs[patch][sector].TPrint( stdout, " Inverse is " ); - } + } if( ix < 0 || ix >= nx || iy < 0 || iy >= ny ) - continue; // outside the image - //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); - bool dbg = (2642 <= ix && ix <= 2644 && 3398 <= iy && iy <= 3400); + continue; // outside the image + //printf("%f i=%d ix,iy=%d %d\n", r, i, ix, iy); + bool dbg = (2642 <= ix && ix <= 2644 && 3398 <= iy && iy <= 3400); if( dbg ) printf("\nDebugging point %d %d, r=%f, p= %f %f, pts[%d]= %f %f\n", ix, iy, r, p.x, p.y, j, pts[j].x, pts[j].y ); - uint32 nn = uint32(ix) + uint32(iy)*nx; // index into array - if( imap[nn] == 0 ) { - imap[nn] = k+1; // this pixel will be set by the kth relevant picture - PatchFrom[nn] = patch; // patch 'patch', sector 'sector' + uint32 nn = uint32(ix) + uint32(iy)*nx; // index into array + if( imap[nn] == 0 ) { + imap[nn] = k+1; // this pixel will be set by the kth relevant picture + PatchFrom[nn] = patch; // patch 'patch', sector 'sector' SectorFrom[nn]= sector; if( dbg ) printf("Not set, setting to %d %d %d %d\n", k, i, patch, sector); } - else { // already set, but we still might be better (because of finite - // grid in source, rounding to int, ordering ). - Point pt_us = Point(ix,iy); - Point pt_ot = pt_us; - // transform back into original frames. - int oi = relevant_images[imap[nn]-1]; // other image - int op = PatchFrom[nn]; // other patch + else { // already set, but we still might be better (because of finite + // grid in source, rounding to int, ordering ). + Point pt_us = Point(ix,iy); + Point pt_ot = pt_us; + // transform back into original frames. + int oi = relevant_images[imap[nn]-1]; // other image + int op = PatchFrom[nn]; // other patch int os = SectorFrom[nn]; // other sector - images[oi].sinvs[op][os].Transform( pt_ot ); - images[i].sinvs[patch][sector].Transform( pt_us ); - - double d_us = max(abs(pt_us.x-center.x), abs(pt_us.y-center.y)); // L-infinity norm - double d_ot = max(abs(pt_ot.x-center.x), abs(pt_ot.y-center.y)); // L-infinity norm - if( dbg ) printf("Already set to %d %d %d %d, d_us %f, d_ot %f\n", imap[nn]-1, oi, op, os, d_us, d_ot); - if( d_us < d_ot ) { - if( dbg ) printf("It CAN happen #2... d_us= %f, d_ot= %f\n", d_us, d_ot); - // Set it, even though it was previously set, since this is better - imap[nn] = k+1; // this pixel will be set by the ith picture - PatchFrom[nn] = patch; - SectorFrom[nn] = sector; - } - } - } - } - } + images[oi].sinvs[op][os].Transform( pt_ot ); + images[i].sinvs[patch][sector].Transform( pt_us ); + + double d_us = max(abs(pt_us.x-center.x), abs(pt_us.y-center.y)); // L-infinity norm + double d_ot = max(abs(pt_ot.x-center.x), abs(pt_ot.y-center.y)); // L-infinity norm + if( dbg ) printf("Already set to %d %d %d %d, d_us %f, d_ot %f\n", imap[nn]-1, oi, op, os, d_us, d_ot); + if( d_us < d_ot ) { + if( dbg ) printf("It CAN happen #2... d_us= %f, d_ot= %f\n", d_us, d_ot); + // Set it, even though it was previously set, since this is better + imap[nn] = k+1; // this pixel will be set by the ith picture + PatchFrom[nn] = patch; + SectorFrom[nn] = sector; + } + } + } + } + } // Now compress the map/patch/sector array. We assume less than 65536 combinations are used, so we can express // this as a 16 bit TIF. The combinations start at 1, and run sequentially. temp.clear(); // clear the mapping file Triples.resize(1); // and the triples; will fill up as they are found; first entry remains (0,0,0) for(uint32 i=0; i::iterator it = temp.find(id); if( it == temp.end() ) { // add it - Triple t(imap[i], PatchFrom[i], SectorFrom[i]); - temp.insert(pair(id, Triples.size())); + Triple t(imap[i], PatchFrom[i], SectorFrom[i]); + temp.insert(pair(id, Triples.size())); printf("New combo %5d: %3d %3d %3d\n", Triples.size(), t.image, t.patch, t.sector); Triples.push_back(t); - it = temp.find(id); // now should find it, since we just added it - } + it = temp.find(id); // now should find it, since we just added it + } uint32 iy = i/nx; uint32 ix = i - nx*iy; - if( ix == 8557 && iy == 431 ) { - printf("Compress map ix=%d iy=%d\n", ix, iy); + if( ix == 8557 && iy == 431 ) { + printf("Compress map ix=%d iy=%d\n", ix, iy); printf(" imap %d, patch %d, sector %d\n", imap[i], PatchFrom[i], SectorFrom[i]); if( imap[i] > 0 ) - printf("Image %d\n", relevant_images[imap[i]-1] ); - printf(" id = %d = %x\n", id, id); + printf("Image %d\n", relevant_images[imap[i]-1] ); + printf(" id = %d = %x\n", id, id); printf(" it->second = %d\n", it->second); - } + } imap[i] = it->second; - } + } // write the new map file, if requested if( gArgs.make_map ) { sprintf( fname, "%s/%s/map.%05d.png", gArgs.region_dir, gArgs.inv_dir, out_layer ); @@ -3569,79 +3569,79 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u } for(int x=0; x= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate - int ix = int(p.x); - int iy = int(p.y); - double alpha = p.x-ix; - double beta = p.y-iy; - int nn = ix + w*iy; // index into original image - uint8* pic = images[img].raster; - double pix = - (1-alpha)*(1-beta) * pic[nn] + - alpha *(1-beta) * pic[nn+1] + - (1-alpha)* beta * pic[nn+w] + - alpha * beta * pic[nn+w+1]; - before[bi] = ROUND(pix); + Point p(x, y); + images[img].sinvs[patch][sector].Transform( p ); + // of course, this should be in the image, but let's double check + if( p.x >= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate + int ix = int(p.x); + int iy = int(p.y); + double alpha = p.x-ix; + double beta = p.y-iy; + int nn = ix + w*iy; // index into original image + uint8* pic = images[img].raster; + double pix = + (1-alpha)*(1-beta) * pic[nn] + + alpha *(1-beta) * pic[nn+1] + + (1-alpha)* beta * pic[nn+w] + + alpha * beta * pic[nn+w+1]; + before[bi] = ROUND(pix); // for the super-pixel map we want nearest, not interpolation. if( p.x - ix >= 0.5 ) - ix++; + ix++; if( p.y - iy >= 0.5 ) - iy++; + iy++; int px = images[img].spmap[ix + w*iy]; if( px != 0 ) // 0 valued pixels are unassigned, and not translated px += images[img].spbase; spmap[bi] = px; //if( spmap[x+y*nx] == 65536 ) { // Just debugging //printf("w=%d h=%d nx=%d ny=%d patch=%d sector=%d\n", w, h, nx, ny, patch, sector); - //printf("Set to %d. x=%d y=%d ix=%d iy=%d img=%d images[img].spbase=%d images[img].spmap[ix + w*iy] = %d\n", + //printf("Set to %d. x=%d y=%d ix=%d iy=%d img=%d images[img].spbase=%d images[img].spmap[ix + w*iy] = %d\n", //px, x, y, ix, iy, img, images[img].spbase, images[img].spmap[ix + w*iy] ); //exit( 42 ); - //} + //} if( gArgs.Debug && px == 0 ) - before[bi] = 255; - } - } // to aid debugging, draw lines at the image boundaries in the before image. + before[bi] = 255; + } + } // to aid debugging, draw lines at the image boundaries in the before image. } if( gArgs.Annotate ) { - vector edges; - for(int x=0; x edges; + for(int x=0; x= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate - int ix = int(p.x); - int iy = int(p.y); - double alpha = p.x-ix; - double beta = p.y-iy; - int nn = ix + w*iy; // index into original image - uint8* pic = images[img].bmap; - double pix = - (1-alpha)*(1-beta) * pic[nn] + - alpha *(1-beta) * pic[nn+1] + - (1-alpha)* beta * pic[nn+w] + - alpha * beta * pic[nn+w+1]; - before[x+y*nx] = ROUND(pix); - } - } - } + Point p(x, y); + images[img].sinvs[patch][sector].Transform( p ); + // of course, this should be in the image, but let's double check + if( p.x >= 0.0 && p.x < w-1 && p.y >= 0.0 && p.y < h-1 ) { // then we can interpolate + int ix = int(p.x); + int iy = int(p.y); + double alpha = p.x-ix; + double beta = p.y-iy; + int nn = ix + w*iy; // index into original image + uint8* pic = images[img].bmap; + double pix = + (1-alpha)*(1-beta) * pic[nn] + + alpha *(1-beta) * pic[nn+1] + + (1-alpha)* beta * pic[nn+w] + + alpha * beta * pic[nn+w+1]; + before[x+y*nx] = ROUND(pix); + } + } + } if( AnyBMap ) { sprintf( fname, "%s/%s/bmap.%05d.png", gArgs.region_dir, gArgs.bmap_dir, out_layer ); - if( gArgs.make_flat ) + if( gArgs.make_flat ) Raster8ToPng8( fname, &before[0], nx, ny ); - } + } // ------------------------------------------------ write the mapping text file -------------------- // This is the text file that contains the transformations that describe how each pixel got there. @@ -3696,14 +3696,14 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u //write the image names, and their indexes for(int k=0; k volume(biggest+1,0); @@ -3742,24 +3742,24 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vector xmax(biggest+1,-1); vector ymax(biggest+1,-1); for(int y=0; y 0 ) - fprintf(fb,"%d %7d %8d %d %d %d %d\n", out_layer, i, xmin[i], ny-1-ymax[i], xmax[i]-xmin[i]+1, ymax[i]-ymin[i]+1, volume[i]); - } + fprintf(fb,"%d %7d %8d %d %d %d %d\n", out_layer, i, xmin[i], ny-1-ymax[i], xmax[i]-xmin[i]+1, ymax[i]-ymin[i]+1, volume[i]); + } fclose(fb); } @@ -3767,19 +3767,19 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u bool experiment = false; if( experiment ) { vector copy(nx*ny,0); - for(int i=0; i big(bigx*bigy); printf("try to fill the huge array\n"); fflush(stdout); int p1 = nx*ny; int p2 = bigx*bigy; for(int i=0; i not in the original image - else { - //printf("%6d maps to %d (global set of maps)\n", k, m); + for(int k=1; k not in the original image + else { + //printf("%6d maps to %d (global set of maps)\n", k, m); // this could go off the end of the Final Mapping array, if the biggest number // assigned is not used in the final image. Test for this: int n = (m < FinalMapping.size()) ? FinalMapping[m] : 0; - if( n == 0 ) - fprintf(fmap, "%d -2\n", k); // -2 => not used in final image - else - fprintf(fmap, "%d %d\n", k, n); - } - } - } - } + if( n == 0 ) + fprintf(fmap, "%d -2\n", k); // -2 => not used in final image + else + fprintf(fmap, "%d %d\n", k, n); + } + } + } + } fclose(fmap); // Now, for every image that was used, look and see if it had annotation. If so, transform @@ -3823,29 +3823,29 @@ for(int out_layer = lowest; out_layer <= highest; out_layer++) { //keep going u vector tbars; vector bookmarks; for(int j=0; j mos_$lyr.txt" - fi + echo $lyr + if [ -d "$lyr" ] + then + QSUB_1NODE.sht 10 "mos-$lyr" "" 8 "mos ../stack/simple 0,0,-1,-1 $lyr,$lyr -warp -nf > mos_$lyr.txt" + fi done diff --git a/1_Ptestx/makefile b/1_Ptestx/makefile index adfc394..80c6a28 100644 --- a/1_Ptestx/makefile +++ b/1_Ptestx/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_Ptestx/ptestx.cpp b/1_Ptestx/ptestx.cpp index 656be2b..7ad034f 100644 --- a/1_Ptestx/ptestx.cpp +++ b/1_Ptestx/ptestx.cpp @@ -52,32 +52,32 @@ class CArgs_ptx { public: - vector passon; - char im[2][2048], - fm[2][2048], - tmp[2048], - idb[2048], - prm[2048]; - int z[2], tile[2], - clrtmp; + vector passon; + char im[2][2048], + fm[2][2048], + tmp[2048], + idb[2048], + prm[2048]; + int z[2], tile[2], + clrtmp; public: - CArgs_ptx() - { - im[0][0] = 0; - im[1][0] = 0; - fm[0][0] = 0; - fm[1][0] = 0; - tmp[0] = 0; - idb[0] = 0; - prm[0] = 0; - clrtmp = false; - }; - - void SetCmdLine( int argc, char* argv[] ); - void TopLevel(); - void ALayer(); - void Call_ptest(); + CArgs_ptx() + { + im[0][0] = 0; + im[1][0] = 0; + fm[0][0] = 0; + fm[1][0] = 0; + tmp[0] = 0; + idb[0] = 0; + prm[0] = 0; + clrtmp = false; + }; + + void SetCmdLine( int argc, char* argv[] ); + void TopLevel(); + void ALayer(); + void Call_ptest(); }; /* --------------------------------------------------------------- */ @@ -100,81 +100,81 @@ void CArgs_ptx::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "ptestx.log", "w" ); + flog = FileOpenOrDie( "ptestx.log", "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Start: %s ", atime ); + fprintf( flog, "Start: %s ", atime ); // parse command line args - if( argc < 5 ) { + if( argc < 5 ) { usage: - printf( "Usage: ptestx -d=temp" - " -prm=matchparams.txt [-idb=xxx]" - " [-ima=xxx -imb=xxx -fma=zzz -fmb=xxx]" - " [options].\n" ); - exit( 42 ); - } - - const char *key, *_arg; - int ok = true; - - passon.push_back( argv[1] ); // key - - for( int i = 1; i < argc; ++i ) { - - // echo to log - fprintf( flog, "%s ", argv[i] ); - - if( argv[i][0] != '-' ) - key = argv[i]; - else if( GetArgStr( _arg, "-d=", argv[i] ) ) - ok = DskAbsPath( tmp, sizeof(tmp), _arg, flog ); - else if( GetArgStr( _arg, "-idb=", argv[i] ) ) - ok = DskAbsPath( idb, sizeof(idb), _arg, flog ); - else if( GetArgStr( _arg, "-prm=", argv[i] ) ) - ok = DskAbsPath( prm, sizeof(prm), _arg, flog ); - else if( GetArgStr( _arg, "-ima=", argv[i] ) ) - ok = DskAbsPath( im[0], sizeof(im[0]), _arg, flog ); - else if( GetArgStr( _arg, "-imb=", argv[i] ) ) - ok = DskAbsPath( im[1], sizeof(im[1]), _arg, flog ); - else if( GetArgStr( _arg, "-fma=", argv[i] ) ) - ok = DskAbsPath( fm[0], sizeof(fm[0]), _arg, flog ); - else if( GetArgStr( _arg, "-fmb=", argv[i] ) ) - ok = DskAbsPath( fm[1], sizeof(fm[1]), _arg, flog ); - else if( IsArg( "-clr", argv[i] ) ) - clrtmp = true; - else - passon.push_back( argv[i] ); - - if( !ok ) { - fprintf( flog, "\nBad arg path '%s'.\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n\n" ); - - if( !key || !tmp[0] || !prm[0] ) - goto usage; + printf( "Usage: ptestx -d=temp" + " -prm=matchparams.txt [-idb=xxx]" + " [-ima=xxx -imb=xxx -fma=zzz -fmb=xxx]" + " [options].\n" ); + exit( 42 ); + } + + const char *key, *_arg; + int ok = true; + + passon.push_back( argv[1] ); // key + + for( int i = 1; i < argc; ++i ) { + + // echo to log + fprintf( flog, "%s ", argv[i] ); + + if( argv[i][0] != '-' ) + key = argv[i]; + else if( GetArgStr( _arg, "-d=", argv[i] ) ) + ok = DskAbsPath( tmp, sizeof(tmp), _arg, flog ); + else if( GetArgStr( _arg, "-idb=", argv[i] ) ) + ok = DskAbsPath( idb, sizeof(idb), _arg, flog ); + else if( GetArgStr( _arg, "-prm=", argv[i] ) ) + ok = DskAbsPath( prm, sizeof(prm), _arg, flog ); + else if( GetArgStr( _arg, "-ima=", argv[i] ) ) + ok = DskAbsPath( im[0], sizeof(im[0]), _arg, flog ); + else if( GetArgStr( _arg, "-imb=", argv[i] ) ) + ok = DskAbsPath( im[1], sizeof(im[1]), _arg, flog ); + else if( GetArgStr( _arg, "-fma=", argv[i] ) ) + ok = DskAbsPath( fm[0], sizeof(fm[0]), _arg, flog ); + else if( GetArgStr( _arg, "-fmb=", argv[i] ) ) + ok = DskAbsPath( fm[1], sizeof(fm[1]), _arg, flog ); + else if( IsArg( "-clr", argv[i] ) ) + clrtmp = true; + else + passon.push_back( argv[i] ); + + if( !ok ) { + fprintf( flog, "\nBad arg path '%s'.\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n\n" ); + + if( !key || !tmp[0] || !prm[0] ) + goto usage; // Decode labels in key - if( 4 != sscanf( key, "%d.%d^%d.%d", - &z[0], &tile[0], &z[1], &tile[1] ) ) { + if( 4 != sscanf( key, "%d.%d^%d.%d", + &z[0], &tile[0], &z[1], &tile[1] ) ) { - fprintf( flog, "Bad label string '%s'.\n", key ); - exit( 42 ); - } + fprintf( flog, "Bad label string '%s'.\n", key ); + exit( 42 ); + } - fflush( flog ); + fflush( flog ); } /* --------------------------------------------------------------- */ @@ -183,25 +183,25 @@ void CArgs_ptx::SetCmdLine( int argc, char* argv[] ) void CArgs_ptx::TopLevel() { - char buf[2048]; + char buf[2048]; // preclear - if( clrtmp ) { - sprintf( buf, "rm -rf %s", tmp ); - system( buf ); - } + if( clrtmp ) { + sprintf( buf, "rm -rf %s", tmp ); + system( buf ); + } // create top directory - DskCreateDir( tmp, flog ); + DskCreateDir( tmp, flog ); // copy param files - if( idb[0] ) { - sprintf( buf, "cp %s/imageparams.txt %s", idb, tmp ); - system( buf ); - } + if( idb[0] ) { + sprintf( buf, "cp %s/imageparams.txt %s", idb, tmp ); + system( buf ); + } - sprintf( buf, "cp %s %s/matchparams.txt", prm, tmp ); - system( buf ); + sprintf( buf, "cp %s %s/matchparams.txt", prm, tmp ); + system( buf ); } /* --------------------------------------------------------------- */ @@ -210,24 +210,24 @@ void CArgs_ptx::TopLevel() void CArgs_ptx::ALayer() { - char buf[2048]; - int len; + char buf[2048]; + int len; /* ---------------------------- */ /* Create A layer and jobs dirs */ /* ---------------------------- */ - len = sprintf( buf, "%s/%d", tmp, z[0] ); - DskCreateDir( buf, flog ); + len = sprintf( buf, "%s/%d", tmp, z[0] ); + DskCreateDir( buf, flog ); - CreateJobsDir( buf, 0, 0, z[0], z[1], flog ); + CreateJobsDir( buf, 0, 0, z[0], z[1], flog ); /* --------------- */ /* Create tile dir */ /* --------------- */ - sprintf( buf + len, "/%d", tile[0] ); - DskCreateDir( buf, flog ); + sprintf( buf + len, "/%d", tile[0] ); + DskCreateDir( buf, flog ); } /* --------------------------------------------------------------- */ @@ -236,42 +236,42 @@ void CArgs_ptx::ALayer() void CArgs_ptx::Call_ptest() { - char buf[2048], - ptsbuf[32], - logbuf[32]; - int len, narg; + char buf[2048], + ptsbuf[32], + logbuf[32]; + int len, narg; // set jobs dir - sprintf( buf, "%s/%d/%c0_0", tmp, z[0], - (z[1] == z[0] ? 'S' : 'D') ); + sprintf( buf, "%s/%d/%c0_0", tmp, z[0], + (z[1] == z[0] ? 'S' : 'D') ); - chdir( buf ); + chdir( buf ); // build command line with any passon args - len = sprintf( buf, "ptest >>%s 2>%s", - NamePtsFile( ptsbuf, z[0], z[1] ), - NameLogFile( logbuf, z[0], tile[0], z[1], tile[1] ) ); - narg = passon.size(); + len = sprintf( buf, "ptest >>%s 2>%s", + NamePtsFile( ptsbuf, z[0], z[1] ), + NameLogFile( logbuf, z[0], tile[0], z[1], tile[1] ) ); + narg = passon.size(); - for( int i = 0; i < narg; ++i ) - len += sprintf( buf + len, " %s", passon[i] ); + for( int i = 0; i < narg; ++i ) + len += sprintf( buf + len, " %s", passon[i] ); // add optional image args - if( im[0][0] ) - len += sprintf( buf + len, " -ima=%s", im[0] ); + if( im[0][0] ) + len += sprintf( buf + len, " -ima=%s", im[0] ); - if( im[1][0] ) - len += sprintf( buf + len, " -imb=%s", im[1] ); + if( im[1][0] ) + len += sprintf( buf + len, " -imb=%s", im[1] ); - if( fm[0][0] ) - len += sprintf( buf + len, " -fma=%s", fm[0] ); + if( fm[0][0] ) + len += sprintf( buf + len, " -fma=%s", fm[0] ); - if( fm[1][0] ) - len += sprintf( buf + len, " -fmb=%s", fm[1] ); + if( fm[1][0] ) + len += sprintf( buf + len, " -fmb=%s", fm[1] ); // call ptest - fprintf( flog, "%s\n.", buf ); - system( buf ); + fprintf( flog, "%s\n.", buf ); + system( buf ); } /* --------------------------------------------------------------- */ @@ -284,34 +284,34 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* --------- */ /* Top level */ /* --------- */ - gArgs.TopLevel(); + gArgs.TopLevel(); /* ------- */ /* A layer */ /* ------- */ - gArgs.ALayer(); + gArgs.ALayer(); /* --------------------- */ /* Call through to ptest */ /* --------------------- */ - gArgs.Call_ptest(); + gArgs.Call_ptest(); /* ---- */ /* Done */ /* ---- */ - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_Reformat/makefile b/1_Reformat/makefile index 82487ee..5f8ebdb 100644 --- a/1_Reformat/makefile +++ b/1_Reformat/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_Reformat/reformat.cpp b/1_Reformat/reformat.cpp index e4b6665..69dd3c0 100644 --- a/1_Reformat/reformat.cpp +++ b/1_Reformat/reformat.cpp @@ -38,30 +38,30 @@ class CArgs_xml { private: - // re_id used to extract tile id from image name. - // "/N" used for EM projects, "_N_" for APIG images, - // "_Nex.mrc" typical for Leginon files. - CRegexID re_id; + // re_id used to extract tile id from image name. + // "/N" used for EM projects, "_N_" for APIG images, + // "_Nex.mrc" typical for Leginon files. + CRegexID re_id; public: - char *inpath; - int cmd, // {'x','r','d'} - zmin, - zmax; + char *inpath; + int cmd, // {'x','r','d'} + zmin, + zmax; public: - CArgs_xml() - { - inpath = NULL; - cmd = 0; - zmin = 0; - zmax = 32768; - }; - - void SetCmdLine( int argc, char* argv[] ); - - int IDFromName( const char *name ); - int IDFromPatch( TiXmlElement* p ); + CArgs_xml() + { + inpath = NULL; + cmd = 0; + zmin = 0; + zmax = 32768; + }; + + void SetCmdLine( int argc, char* argv[] ); + + int IDFromName( const char *name ); + int IDFromPatch( TiXmlElement* p ); }; /* --------------------------------------------------------------- */ @@ -84,60 +84,60 @@ void CArgs_xml::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "Reformat.log", "w" ); + flog = FileOpenOrDie( "Reformat.log", "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Start: %s ", atime ); + fprintf( flog, "Start: %s ", atime ); // parse command line args - const char *pat; - - re_id.Set( "_N_" ); - - if( argc < 4 ) { - printf( - "Usage: reformat path <-x,-r,-d> -p=_Nex.mrc -zmin=i -zmax=j.\n" ); - exit( 42 ); - } - - for( int i = 1; i < argc; ++i ) { - - // echo to log - fprintf( flog, "%s ", argv[i] ); - - if( argv[i][0] != '-' ) - inpath = argv[i]; - else if( IsArg( "-x", argv[i] ) ) - cmd = 'x'; - else if( IsArg( "-r", argv[i] ) ) - cmd = 'r'; - else if( IsArg( "-d", argv[i] ) ) - cmd = 'd'; - else if( GetArgStr( pat, "-p=", argv[i] ) ) - re_id.Set( pat ); - else if( GetArg( &zmin, "-zmin=%d", argv[i] ) ) - ; - else if( GetArg( &zmax, "-zmax=%d", argv[i] ) ) - ; - else { - printf( "Did not understand option [%s].\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n" ); - - re_id.Compile( flog ); - - fflush( flog ); + const char *pat; + + re_id.Set( "_N_" ); + + if( argc < 4 ) { + printf( + "Usage: reformat path <-x,-r,-d> -p=_Nex.mrc -zmin=i -zmax=j.\n" ); + exit( 42 ); + } + + for( int i = 1; i < argc; ++i ) { + + // echo to log + fprintf( flog, "%s ", argv[i] ); + + if( argv[i][0] != '-' ) + inpath = argv[i]; + else if( IsArg( "-x", argv[i] ) ) + cmd = 'x'; + else if( IsArg( "-r", argv[i] ) ) + cmd = 'r'; + else if( IsArg( "-d", argv[i] ) ) + cmd = 'd'; + else if( GetArgStr( pat, "-p=", argv[i] ) ) + re_id.Set( pat ); + else if( GetArg( &zmin, "-zmin=%d", argv[i] ) ) + ; + else if( GetArg( &zmax, "-zmax=%d", argv[i] ) ) + ; + else { + printf( "Did not understand option [%s].\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n" ); + + re_id.Compile( flog ); + + fflush( flog ); } /* -------------------------------------------------------------- */ @@ -146,14 +146,14 @@ void CArgs_xml::SetCmdLine( int argc, char* argv[] ) int CArgs_xml::IDFromName( const char *name ) { - int id; + int id; - if( !re_id.Decode( id, FileNamePtr( name ) ) ) { - fprintf( flog, "No tile-id found in '%s'.\n", name ); - exit( 42 ); - } + if( !re_id.Decode( id, FileNamePtr( name ) ) ) { + fprintf( flog, "No tile-id found in '%s'.\n", name ); + exit( 42 ); + } - return id; + return id; } /* -------------------------------------------------------------- */ @@ -162,7 +162,7 @@ int CArgs_xml::IDFromName( const char *name ) int CArgs_xml::IDFromPatch( TiXmlElement* p ) { - return IDFromName( p->Attribute( "title" ) ); + return IDFromName( p->Attribute( "title" ) ); } /* --------------------------------------------------------------- */ @@ -171,28 +171,28 @@ int CArgs_xml::IDFromPatch( TiXmlElement* p ) static void UpdateXMLLayer( TiXmlElement* layer, int z ) { - TiXmlElement* p = layer->FirstChildElement( "t2_patch" ); + TiXmlElement* p = layer->FirstChildElement( "t2_patch" ); - for( ; p; p = p->NextSiblingElement() ) { + for( ; p; p = p->NextSiblingElement() ) { - char title[128]; - int id = gArgs.IDFromPatch( p ); + char title[128]; + int id = gArgs.IDFromPatch( p ); - const char *c, *n = p->Attribute( "title" ); + const char *c, *n = p->Attribute( "title" ); - if( c = strstr( n, "col" ) ) { + if( c = strstr( n, "col" ) ) { - int col = -1, row = -1, cam = 0; - sscanf( c, "col%d_row%d_cam%d", &col, &row, &cam ); + int col = -1, row = -1, cam = 0; + sscanf( c, "col%d_row%d_cam%d", &col, &row, &cam ); - sprintf( title, "%d.%d-1_%d.%d.%d", - z, id, col, row, cam ); - } - else - sprintf( title, "%d.%d-1", z, id ); + sprintf( title, "%d.%d-1_%d.%d.%d", + z, id, col, row, cam ); + } + else + sprintf( title, "%d.%d-1", z, id ); - p->SetAttribute( "title", title ); - } + p->SetAttribute( "title", title ); + } } /* --------------------------------------------------------------- */ @@ -205,35 +205,35 @@ static void UpdateXML() /* Open */ /* ---- */ - XML_TKEM xml( gArgs.inpath, flog ); - TiXmlElement* layer = xml.GetFirstLayer(); + XML_TKEM xml( gArgs.inpath, flog ); + TiXmlElement* layer = xml.GetFirstLayer(); /* -------------- */ /* For each layer */ /* -------------- */ - for( ; layer; layer = layer->NextSiblingElement() ) { + for( ; layer; layer = layer->NextSiblingElement() ) { - /* ----------------- */ - /* Layer-level stuff */ - /* ----------------- */ + /* ----------------- */ + /* Layer-level stuff */ + /* ----------------- */ - int z = atoi( layer->Attribute( "z" ) ); + int z = atoi( layer->Attribute( "z" ) ); - if( z > gArgs.zmax ) - break; + if( z > gArgs.zmax ) + break; - if( z < gArgs.zmin ) - continue; + if( z < gArgs.zmin ) + continue; - UpdateXMLLayer( layer, z ); - } + UpdateXMLLayer( layer, z ); + } /* ---- */ /* Save */ /* ---- */ - xml.Save( "xmltmp.txt", true ); + xml.Save( "xmltmp.txt", true ); } /* --------------------------------------------------------------- */ @@ -242,50 +242,50 @@ static void UpdateXML() static void UpdateRick() { - FILE *in = FileOpenOrDie( gArgs.inpath, "r" ); + FILE *in = FileOpenOrDie( gArgs.inpath, "r" ); // name and open out file: path/name.ext -> path/name_v2.ext - char buf[2048]; - int len = sprintf( buf, "%s", gArgs.inpath ) - 4; - sprintf( buf + len, "_v2%s", gArgs.inpath + len ); + char buf[2048]; + int len = sprintf( buf, "%s", gArgs.inpath ) - 4; + sprintf( buf + len, "_v2%s", gArgs.inpath + len ); - FILE *out = FileOpenOrDie( buf, "w" ); + FILE *out = FileOpenOrDie( buf, "w" ); // process line by line - for( ;; ) { + for( ;; ) { - TAffine T; - int z, col = -999, row = -999, cam = 0; + TAffine T; + int z, col = -999, row = -999, cam = 0; - if( fscanf( in, "%s%lf%lf%d%*[^\r\n][\r\n]", - buf, &T.t[2], &T.t[5], &z ) != 4 ) { + if( fscanf( in, "%s%lf%lf%d%*[^\r\n][\r\n]", + buf, &T.t[2], &T.t[5], &z ) != 4 ) { - break; - } + break; + } - if( z > gArgs.zmax ) - break; + if( z > gArgs.zmax ) + break; - if( z < gArgs.zmin ) - continue; + if( z < gArgs.zmin ) + continue; - const char *c, *n = FileNamePtr( buf ); + const char *c, *n = FileNamePtr( buf ); - if( c = strstr( n, "col" ) ) - sscanf( c, "col%d_row%d_cam%d", &col, &row, &cam ); + if( c = strstr( n, "col" ) ) + sscanf( c, "col%d_row%d_cam%d", &col, &row, &cam ); - fprintf( out, "%d\t%d" - "\t%f\t%f\t%f\t%f\t%f\t%f" - "\t%d\t%d\t%d\t%s\n", - z, gArgs.IDFromName( n ), - T.t[0], T.t[1], T.t[2], T.t[3], T.t[4], T.t[5], - col, row, cam, buf ); - } + fprintf( out, "%d\t%d" + "\t%f\t%f\t%f\t%f\t%f\t%f" + "\t%d\t%d\t%d\t%s\n", + z, gArgs.IDFromName( n ), + T.t[0], T.t[1], T.t[2], T.t[3], T.t[4], T.t[5], + col, row, cam, buf ); + } - fclose( out ); - fclose( in ); + fclose( out ); + fclose( in ); } /* --------------------------------------------------------------- */ @@ -296,77 +296,77 @@ static void UpdateIDB() { // loop over dirs - for( int z = gArgs.zmin; z <= gArgs.zmax; ++z ) { + for( int z = gArgs.zmin; z <= gArgs.zmax; ++z ) { - // z exists? + // z exists? - char buf[4096]; - sprintf( buf, "%s/%d/TileToImage.txt", gArgs.inpath, z ); + char buf[4096]; + sprintf( buf, "%s/%d/TileToImage.txt", gArgs.inpath, z ); - if( !DskExists( buf ) ) - continue; + if( !DskExists( buf ) ) + continue; - // open input and skip header + // open input and skip header - FILE *in = FileOpenOrDie( buf, "r" ); - CLineScan LS; + FILE *in = FileOpenOrDie( buf, "r" ); + CLineScan LS; - if( LS.Get( in ) <= 0 ) { - fprintf( flog, "UpdateIDB: Empty file [%s].\n", buf ); - fclose( in ); - continue; - } + if( LS.Get( in ) <= 0 ) { + fprintf( flog, "UpdateIDB: Empty file [%s].\n", buf ); + fclose( in ); + continue; + } - // name and open out file: same.tmp + // name and open out file: same.tmp - sprintf( buf, "%s/%d/TileToImage.tmp", gArgs.inpath, z ); + sprintf( buf, "%s/%d/TileToImage.tmp", gArgs.inpath, z ); - FILE *out = FileOpenOrDie( buf, "w" ); + FILE *out = FileOpenOrDie( buf, "w" ); - // write header + // write header - fprintf( out, - "ID\tT0\tT1\tX\tT3\tT4\tY\tCol\tRow\tCam\tPath\n" ); + fprintf( out, + "ID\tT0\tT1\tX\tT3\tT4\tY\tCol\tRow\tCam\tPath\n" ); - // process line by line + // process line by line - while( LS.Get( in ) > 0 ) { + while( LS.Get( in ) > 0 ) { - TAffine T; - int id, col = -999, row = -999, cam = 0; + TAffine T; + int id, col = -999, row = -999, cam = 0; - sscanf( LS.line, - "%d\t%lf\t%lf\t%lf" - "\t%lf\t%lf\t%lf\t%[^\t\n]", - &id, - &T.t[0], &T.t[1], &T.t[2], - &T.t[3], &T.t[4], &T.t[5], - buf ); + sscanf( LS.line, + "%d\t%lf\t%lf\t%lf" + "\t%lf\t%lf\t%lf\t%[^\t\n]", + &id, + &T.t[0], &T.t[1], &T.t[2], + &T.t[3], &T.t[4], &T.t[5], + buf ); - const char *c, *n = FileNamePtr( buf ); + const char *c, *n = FileNamePtr( buf ); - if( c = strstr( n, "col" ) ) - sscanf( c, "col%d_row%d_cam%d", &col, &row, &cam ); + if( c = strstr( n, "col" ) ) + sscanf( c, "col%d_row%d_cam%d", &col, &row, &cam ); - fprintf( out, "%d" - "\t%f\t%f\t%f\t%f\t%f\t%f" - "\t%d\t%d\t%d\t%s\n", - id, - T.t[0], T.t[1], T.t[2], T.t[3], T.t[4], T.t[5], - col, row, cam, buf ); - } + fprintf( out, "%d" + "\t%f\t%f\t%f\t%f\t%f\t%f" + "\t%d\t%d\t%d\t%s\n", + id, + T.t[0], T.t[1], T.t[2], T.t[3], T.t[4], T.t[5], + col, row, cam, buf ); + } - fclose( out ); - fclose( in ); + fclose( out ); + fclose( in ); - // replace file + // replace file - sprintf( buf, - "mv %s/%d/TileToImage.tmp %s/%d/TileToImage.txt", - gArgs.inpath, z, gArgs.inpath, z ); + sprintf( buf, + "mv %s/%d/TileToImage.tmp %s/%d/TileToImage.txt", + gArgs.inpath, z, gArgs.inpath, z ); - system( buf ); - } + system( buf ); + } } /* --------------------------------------------------------------- */ @@ -379,35 +379,35 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* ------------- */ /* Write new xml */ /* ------------- */ - switch( gArgs.cmd ) { + switch( gArgs.cmd ) { - case 'x': - UpdateXML(); - break; + case 'x': + UpdateXML(); + break; - case 'r': - UpdateRick(); - break; + case 'r': + UpdateRick(); + break; - case 'd': - UpdateIDB(); - break; - } + case 'd': + UpdateIDB(); + break; + } /* ---- */ /* Done */ /* ---- */ - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_RemoveRefTiles/RemoveRefTiles.cpp b/1_RemoveRefTiles/RemoveRefTiles.cpp index 3efb209..b264515 100644 --- a/1_RemoveRefTiles/RemoveRefTiles.cpp +++ b/1_RemoveRefTiles/RemoveRefTiles.cpp @@ -11,42 +11,42 @@ using namespace std; class LineRec { public: - char line[2048]; - int id, x, y, z; + char line[2048]; + int id, x, y, z; public: - bool Get( FILE *f ); + bool Get( FILE *f ); }; bool LineRec::Get( FILE *f ) { - if( !fgets( line, sizeof(line), f ) ) - return false; + if( !fgets( line, sizeof(line), f ) ) + return false; - char *u = strrchr( line, '_' ); + char *u = strrchr( line, '_' ); - if( !u ) - return false; + if( !u ) + return false; - if( 4 != sscanf( u+1, "%dex.mrc\t%d\t%d\t%d", &id, &x, &y, &z ) ) - return false; + if( 4 != sscanf( u+1, "%dex.mrc\t%d\t%d\t%d", &id, &x, &y, &z ) ) + return false; - return true; + return true; } static void FlushPends( vector &pends, FILE *fou ) { - int np = pends.size(); + int np = pends.size(); - if( np ) { + if( np ) { - for( int i = 0; i < np; ++i ) - fprintf( fou, pends[i].line ); + for( int i = 0; i < np; ++i ) + fprintf( fou, pends[i].line ); - pends.clear(); - } + pends.clear(); + } } @@ -54,72 +54,72 @@ int main( int argc, char **argv ) { // open infile - char buf[2048]; - FILE *fin = FileOpenOrDie( argv[1], "r" ); + char buf[2048]; + FILE *fin = FileOpenOrDie( argv[1], "r" ); // set s to point at extension or trailing NULL - const char *s = FileDotPtr( argv[1] ); + const char *s = FileDotPtr( argv[1] ); // compose outname & open - sprintf( buf, "%.*s_v2%s", int(s - argv[1]), argv[1], s ); - FILE *fou = FileOpenOrDie( buf, "w" ); + sprintf( buf, "%.*s_v2%s", int(s - argv[1]), argv[1], s ); + FILE *fou = FileOpenOrDie( buf, "w" ); // read lines - ref tiles, if present, are at the start of // the list for that layer and their id's are much higher // than those of the real tiles that follow. - vector pends; - int zcur = -1; + vector pends; + int zcur = -1; - for(;;) { + for(;;) { - LineRec L; + LineRec L; - if( !L.Get( fin ) ) { + if( !L.Get( fin ) ) { - FlushPends( pends, fou ); - break; - } - else if( L.z != zcur ) { + FlushPends( pends, fou ); + break; + } + else if( L.z != zcur ) { - // new layer - don't yet know if has ref tiles or not + // new layer - don't yet know if has ref tiles or not - FlushPends( pends, fou ); - pends.push_back( L ); - zcur = L.z; - } - else if( !pends.size() ) { + FlushPends( pends, fou ); + pends.push_back( L ); + zcur = L.z; + } + else if( !pends.size() ) { - // resolved already - just output real tiles + // resolved already - just output real tiles - fprintf( fou, L.line ); - } - else if( L.id < pends[0].id ) { + fprintf( fou, L.line ); + } + else if( L.id < pends[0].id ) { - // found id step-down, so only real tiles hereafter + // found id step-down, so only real tiles hereafter - pends.clear(); - fprintf( fou, L.line ); - } - else if( L.id == pends[pends.size()-1].id ) { + pends.clear(); + fprintf( fou, L.line ); + } + else if( L.id == pends[pends.size()-1].id ) { - // repeated id also implies ref tile - } - else { + // repeated id also implies ref tile + } + else { - // not sure - could be real tiles, - // or, more than one ref tile id + // not sure - could be real tiles, + // or, more than one ref tile id - pends.push_back( L ); - } - } + pends.push_back( L ); + } + } // close files - fclose( fin ); - fclose( fou ); + fclose( fin ); + fclose( fou ); } diff --git a/1_RemoveRefTiles/makefile b/1_RemoveRefTiles/makefile index 8441520..8c96458 100644 --- a/1_RemoveRefTiles/makefile +++ b/1_RemoveRefTiles/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_Scapeops/makefile b/1_Scapeops/makefile index 025620f..1636462 100644 --- a/1_Scapeops/makefile +++ b/1_Scapeops/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_Scapeops/scapeops.cpp b/1_Scapeops/scapeops.cpp index 39cf505..ae84498 100644 --- a/1_Scapeops/scapeops.cpp +++ b/1_Scapeops/scapeops.cpp @@ -49,53 +49,53 @@ class CSuperscape { public: - DBox B; // oriented bounding box - Point Opts; // origin of aligned point list - double x0, y0; // scape corner in oriented system - uint8 *ras; // scape pixels - uint32 ws, hs; // scape dims - int is0, isN, // layer index range - Bxc, Byc, // oriented layer center - Bxw, Byh, // oriented layer span - deg; // rotate this much to orient + DBox B; // oriented bounding box + Point Opts; // origin of aligned point list + double x0, y0; // scape corner in oriented system + uint8 *ras; // scape pixels + uint32 ws, hs; // scape dims + int is0, isN, // layer index range + Bxc, Byc, // oriented layer center + Bxw, Byh, // oriented layer span + deg; // rotate this much to orient public: - CSuperscape() : ras(NULL) {}; - - virtual ~CSuperscape() - {KillRas();}; - - void KillRas() - { - if( ras ) { - RasterFree( ras ); - ras = NULL; - } - }; - - void DrawRas( const char *name ) - { - if( ras ) - Raster8ToPng8( name, ras, ws, hs ); - }; - - bool Load( const char *name, FILE* flog ) - { - x0 = y0 = 0.0; - ras = Raster8FromAny( name, ws, hs, flog ); - return (ras != NULL); - }; - - void FindLayerIndices( int z ); - void OrientLayer(); - - bool MakeWholeRaster(); - bool MakeRasV(); - bool MakeRasH(); - - void WriteMeta( char clbl, int z ); - - void MakePoints( vector &v, vector &p ); + CSuperscape() : ras(NULL) {}; + + virtual ~CSuperscape() + {KillRas();}; + + void KillRas() + { + if( ras ) { + RasterFree( ras ); + ras = NULL; + } + }; + + void DrawRas( const char *name ) + { + if( ras ) + Raster8ToPng8( name, ras, ws, hs ); + }; + + bool Load( const char *name, FILE* flog ) + { + x0 = y0 = 0.0; + ras = Raster8FromAny( name, ws, hs, flog ); + return (ras != NULL); + }; + + void FindLayerIndices( int z ); + void OrientLayer(); + + bool MakeWholeRaster(); + bool MakeRasV(); + bool MakeRasH(); + + void WriteMeta( char clbl, int z ); + + void MakePoints( vector &v, vector &p ); }; /* --------------------------------------------------------------- */ @@ -105,32 +105,32 @@ class CSuperscape { class CArgs_scp { public: - double abctr; - string idb; - const char *srcmons, - *script; - int za, - zb; - bool ismb, - isab, - abdbg, - abdbgfull; + double abctr; + string idb; + const char *srcmons, + *script; + int za, + zb; + bool ismb, + isab, + abdbg, + abdbgfull; public: - CArgs_scp() - { - abctr = 0.0; - srcmons = NULL; - script = NULL; - za = -1; - zb = -1; - ismb = false; - isab = false; - abdbg = false; - abdbgfull = false; - }; - - void SetCmdLine( int argc, char* argv[] ); + CArgs_scp() + { + abctr = 0.0; + srcmons = NULL; + script = NULL; + za = -1; + zb = -1; + ismb = false; + isab = false; + abdbg = false; + abdbgfull = false; + }; + + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -145,7 +145,7 @@ static CSuperscape *gA, *gB; static CThmScan *gS; static FILE* flog = NULL; static int gW = 0, // universal pic dims - gH = 0; + gH = 0; @@ -160,82 +160,82 @@ void CArgs_scp::SetCmdLine( int argc, char* argv[] ) { // label output by layer b - for( int i = 1; i < argc; ++i ) { + for( int i = 1; i < argc; ++i ) { - if( GetArg( &zb, "-zb=%d", argv[i] ) ) - break; - } + if( GetArg( &zb, "-zb=%d", argv[i] ) ) + break; + } - if( zb < 0 ) { - printf( "scapeops: Missing -zb option!!\n" ); - exit( 42 ); - } + if( zb < 0 ) { + printf( "scapeops: Missing -zb option!!\n" ); + exit( 42 ); + } // start log - char buf[256]; + char buf[256]; - sprintf( buf, "scplogs/scp_%d.log", zb ); - flog = FileOpenOrDie( buf, "w" ); + sprintf( buf, "scplogs/scp_%d.log", zb ); + flog = FileOpenOrDie( buf, "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Scapeops start: %s ", atime ); + fprintf( flog, "Scapeops start: %s ", atime ); // parse command line args - if( argc < 6 ) { - printf( - "Usage: See scapeops.cpp comments.\n" ); - exit( 42 ); - } - - const char *pchar; - - for( int i = 1; i < argc; ++i ) { - - // echo to log - fprintf( flog, "%s ", argv[i] ); - - if( argv[i][0] != '-' ) - srcmons = argv[i]; - else if( GetArgStr( script, "-script=", argv[i] ) ) - ; - else if( GetArgStr( pchar, "-idb=", argv[i] ) ) - idb = pchar; - else if( GetArg( &za, "-za=%d", argv[i] ) ) - ; - else if( GetArg( &zb, "-zb=%d", argv[i] ) ) - ; - else if( GetArg( &abctr, "-abctr=%lf", argv[i] ) ) - ; - else if( IsArg( "-mb", argv[i] ) ) - ismb = true; - else if( IsArg( "-ab", argv[i] ) ) - isab = true; - else if( IsArg( "-abdbg", argv[i] ) ) - abdbg = true; - else if( IsArg( "-abdbgfull", argv[i] ) ) - abdbgfull = true; - else { - printf( "Did not understand option [%s].\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n" ); - fflush( flog ); - - if( !ismb && !isab ) { - fprintf( flog, "No operations specified.\n" ); - exit( 0 ); - } + if( argc < 6 ) { + printf( + "Usage: See scapeops.cpp comments.\n" ); + exit( 42 ); + } + + const char *pchar; + + for( int i = 1; i < argc; ++i ) { + + // echo to log + fprintf( flog, "%s ", argv[i] ); + + if( argv[i][0] != '-' ) + srcmons = argv[i]; + else if( GetArgStr( script, "-script=", argv[i] ) ) + ; + else if( GetArgStr( pchar, "-idb=", argv[i] ) ) + idb = pchar; + else if( GetArg( &za, "-za=%d", argv[i] ) ) + ; + else if( GetArg( &zb, "-zb=%d", argv[i] ) ) + ; + else if( GetArg( &abctr, "-abctr=%lf", argv[i] ) ) + ; + else if( IsArg( "-mb", argv[i] ) ) + ismb = true; + else if( IsArg( "-ab", argv[i] ) ) + isab = true; + else if( IsArg( "-abdbg", argv[i] ) ) + abdbg = true; + else if( IsArg( "-abdbgfull", argv[i] ) ) + abdbgfull = true; + else { + printf( "Did not understand option [%s].\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n" ); + fflush( flog ); + + if( !ismb && !isab ) { + fprintf( flog, "No operations specified.\n" ); + exit( 0 ); + } } /* --------------------------------------------------------------- */ @@ -244,10 +244,10 @@ void CArgs_scp::SetCmdLine( int argc, char* argv[] ) void CSuperscape::FindLayerIndices( int z ) { - TS.GetLayerLimits( is0 = 0, isN ); + TS.GetLayerLimits( is0 = 0, isN ); - while( isN != -1 && TS.vtil[is0].z != z ) - TS.GetLayerLimits( is0 = isN, isN ); + while( isN != -1 && TS.vtil[is0].z != z ) + TS.GetLayerLimits( is0 = isN, isN ); } /* --------------------------------------------------------------- */ @@ -260,50 +260,50 @@ void CSuperscape::OrientLayer() { // Collect all tile corners in (C) - vector C, cnr; - Set4Corners( cnr, gW, gH ); + vector C, cnr; + Set4Corners( cnr, gW, gH ); - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - vector c( 4 ); - memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); - TS.vtil[i].T.Transform( c ); + vector c( 4 ); + memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); + TS.vtil[i].T.Transform( c ); - for( int i = 0; i < 4; ++i ) - C.push_back( c[i] ); - } + for( int i = 0; i < 4; ++i ) + C.push_back( c[i] ); + } // Rotate layer upright - TAffine R; + TAffine R; - deg = TightestBBox( B, C ); + deg = TightestBBox( B, C ); - if( scr.stripsweepspan >= 180 - && scr.stripsweepstep - && B.R - B.L > B.T - B.B ) { + if( scr.stripsweepspan >= 180 + && scr.stripsweepstep + && B.R - B.L > B.T - B.B ) { - // Make tall: rotate 90 degrees if wider than tall + // Make tall: rotate 90 degrees if wider than tall - deg = (deg < 0 ? deg + 90 : deg - 90); - R.NUSetRot( deg*PI/180 ); - R.Apply_R_Part( C ); - BBoxFromPoints( B, C ); - } + deg = (deg < 0 ? deg + 90 : deg - 90); + R.NUSetRot( deg*PI/180 ); + R.Apply_R_Part( C ); + BBoxFromPoints( B, C ); + } - R.NUSetRot( deg*PI/180 ); + R.NUSetRot( deg*PI/180 ); - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - TAffine& T = TS.vtil[i].T; + TAffine& T = TS.vtil[i].T; - T = R * T; - } + T = R * T; + } - Bxc = int((B.R + B.L)/2.0); - Byc = int((B.B + B.T)/2.0); - Bxw = int(B.R - B.L); - Byh = int(B.T - B.B); + Bxc = int((B.R + B.L)/2.0); + Byc = int((B.B + B.T)/2.0); + Bxw = int(B.R - B.L); + Byh = int(B.T - B.B); } /* --------------------------------------------------------------- */ @@ -312,17 +312,17 @@ void CSuperscape::OrientLayer() bool CSuperscape::MakeWholeRaster() { - vector vid( isN - is0 ); + vector vid( isN - is0 ); - for( int i = is0; i < isN; ++i ) - vid[i - is0] = i; + for( int i = is0; i < isN; ++i ) + vid[i - is0] = i; - ras = TS.Scape( ws, hs, x0, y0, - vid, inv_scl, 1, 0, - scr.legendremaxorder, scr.rendersdevcnts, - scr.maskoutresin, scr.stripslots ); + ras = TS.Scape( ws, hs, x0, y0, + vid, inv_scl, 1, 0, + scr.legendremaxorder, scr.rendersdevcnts, + scr.maskoutresin, scr.stripslots ); - return (ras != NULL); + return (ras != NULL); } /* --------------------------------------------------------------- */ @@ -333,34 +333,34 @@ bool CSuperscape::MakeRasV() { // Collect strip tiles - vector vid; - int w1, w2, h1, h2; + vector vid; + int w1, w2, h1, h2; - w1 = (scr.stripwidth * gW)/2; - w2 = Bxc + w1; - w1 = Bxc - w1; + w1 = (scr.stripwidth * gW)/2; + w2 = Bxc + w1; + w1 = Bxc - w1; - h1 = int(Byh * 0.45); - h2 = Byc + h1; - h1 = Byc - h1; + h1 = int(Byh * 0.45); + h2 = Byc + h1; + h1 = Byc - h1; - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - const CUTile& U = TS.vtil[i]; + const CUTile& U = TS.vtil[i]; - if( U.T.t[2] + gW > w1 && U.T.t[2] < w2 && - U.T.t[5] + gH > h1 && U.T.t[5] < h2 ) { + if( U.T.t[2] + gW > w1 && U.T.t[2] < w2 && + U.T.t[5] + gH > h1 && U.T.t[5] < h2 ) { - vid.push_back( i ); - } - } + vid.push_back( i ); + } + } - ras = TS.Scape( ws, hs, x0, y0, - vid, inv_scl, 1, 0, - scr.legendremaxorder, scr.rendersdevcnts, - scr.maskoutresin, scr.stripslots ); + ras = TS.Scape( ws, hs, x0, y0, + vid, inv_scl, 1, 0, + scr.legendremaxorder, scr.rendersdevcnts, + scr.maskoutresin, scr.stripslots ); - return (ras != NULL); + return (ras != NULL); } /* --------------------------------------------------------------- */ @@ -371,34 +371,34 @@ bool CSuperscape::MakeRasH() { // Collect strip tiles - vector vid; - int w1, w2, h1, h2; + vector vid; + int w1, w2, h1, h2; - w1 = int(Bxw * 0.45); - w2 = Bxc + w1; - w1 = Bxc - w1; + w1 = int(Bxw * 0.45); + w2 = Bxc + w1; + w1 = Bxc - w1; - h1 = (scr.stripwidth * gH)/2; - h2 = Byc + h1; - h1 = Byc - h1; + h1 = (scr.stripwidth * gH)/2; + h2 = Byc + h1; + h1 = Byc - h1; - for( int i = is0; i < isN; ++i ) { + for( int i = is0; i < isN; ++i ) { - const CUTile& U = TS.vtil[i]; + const CUTile& U = TS.vtil[i]; - if( U.T.t[2] + gW > w1 && U.T.t[2] < w2 && - U.T.t[5] + gH > h1 && U.T.t[5] < h2 ) { + if( U.T.t[2] + gW > w1 && U.T.t[2] < w2 && + U.T.t[5] + gH > h1 && U.T.t[5] < h2 ) { - vid.push_back( i ); - } - } + vid.push_back( i ); + } + } - ras = TS.Scape( ws, hs, x0, y0, - vid, inv_scl, 1, 0, - scr.legendremaxorder, scr.rendersdevcnts, - scr.maskoutresin, scr.stripslots ); + ras = TS.Scape( ws, hs, x0, y0, + vid, inv_scl, 1, 0, + scr.legendremaxorder, scr.rendersdevcnts, + scr.maskoutresin, scr.stripslots ); - return (ras != NULL); + return (ras != NULL); } /* --------------------------------------------------------------- */ @@ -407,12 +407,12 @@ bool CSuperscape::MakeRasH() void CSuperscape::WriteMeta( char clbl, int z ) { - fprintf( flog, - "*%c: z deg [l,r,b,t] scl [ws,hs] [x0,y0]\n", clbl ); + fprintf( flog, + "*%c: z deg [l,r,b,t] scl [ws,hs] [x0,y0]\n", clbl ); - fprintf( flog, - "%d %d [%g,%g,%g,%g] %d [%d,%d] [%g,%g]\n", - z, deg, B.L, B.R, B.B, B.T, scr.crossscale, ws, hs, x0, y0 ); + fprintf( flog, + "%d %d [%g,%g,%g,%g] %d [%d,%d] [%g,%g]\n", + z, deg, B.L, B.R, B.B, B.T, scr.crossscale, ws, hs, x0, y0 ); } /* --------------------------------------------------------------- */ @@ -423,46 +423,46 @@ void CSuperscape::MakePoints( vector &v, vector &p ) { // collect point and value lists - int np = ws * hs; + int np = ws * hs; - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( ras[i] ) { + if( ras[i] ) { - int iy = i / ws, - ix = i - ws * iy; + int iy = i / ws, + ix = i - ws * iy; - v.push_back( ras[i] ); - p.push_back( Point( ix, iy ) ); - } - } + v.push_back( ras[i] ); + p.push_back( Point( ix, iy ) ); + } + } - if( !(np = p.size()) ) { - fprintf( flog, "FAIL: Block has no non-zero pixels.\n" ); - exit( 42 ); - } + if( !(np = p.size()) ) { + fprintf( flog, "FAIL: Block has no non-zero pixels.\n" ); + exit( 42 ); + } // get points origin and translate to zero - DBox bb; + DBox bb; - BBoxFromPoints( bb, p ); - Opts = Point( bb.L, bb.B ); + BBoxFromPoints( bb, p ); + Opts = Point( bb.L, bb.B ); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - p[i].x -= Opts.x; - p[i].y -= Opts.y; - } + p[i].x -= Opts.x; + p[i].y -= Opts.y; + } // normalize values - if( !Normalize( v ) ) { - fprintf( flog, "FAIL: Scape stdev = 0.\n" ); - exit( 42 ); - } + if( !Normalize( v ) ) { + fprintf( flog, "FAIL: Scape stdev = 0.\n" ); + exit( 42 ); + } - KillRas(); + KillRas(); } /* --------------------------------------------------------------- */ @@ -474,20 +474,20 @@ void CSuperscape::MakePoints( vector &v, vector &p ) // coincident with center of B, so, Oxy = Bc - Rot(Ac). // static void StripAngProc( - int &Ox, - int &Oy, - int &Rx, - int &Ry, - double deg ) + int &Ox, + int &Oy, + int &Rx, + int &Ry, + double deg ) { - double r = deg*PI/180, - c = cos( r ), - s = sin( r ); - - Ox = int(gB->ws - (c*gA->ws - s*gA->hs))/2; - Oy = int(gB->hs - (s*gA->ws + c*gA->hs))/2; - Rx = int(gA->ws * 0.25); - Ry = int(gB->hs * 0.25); + double r = deg*PI/180, + c = cos( r ), + s = sin( r ); + + Ox = int(gB->ws - (c*gA->ws - s*gA->hs))/2; + Oy = int(gB->hs - (s*gA->ws + c*gA->hs))/2; + Rx = int(gA->ws * 0.25); + Ry = int(gB->hs * 0.25); } /* --------------------------------------------------------------- */ @@ -495,95 +495,95 @@ static void StripAngProc( /* --------------------------------------------------------------- */ static int AlignWithStrips( - CSuperscape &A, - CSuperscape &B, - clock_t &t0 ) + CSuperscape &A, + CSuperscape &B, + clock_t &t0 ) { - ThmRec thm; - CThmScan S; - CorRec best; - char buf[256]; - int ok = true; + ThmRec thm; + CThmScan S; + CorRec best; + char buf[256]; + int ok = true; - fprintf( flog, "\n---- Align strips ----\n" ); + fprintf( flog, "\n---- Align strips ----\n" ); - if( !A.MakeRasH() ) - return false; + if( !A.MakeRasH() ) + return false; - sprintf( buf, "strips/A_%d.png", gArgs.za ); - A.DrawRas( buf ); + sprintf( buf, "strips/A_%d.png", gArgs.za ); + A.DrawRas( buf ); - if( !B.MakeRasV() ) - return false; + if( !B.MakeRasV() ) + return false; - sprintf( buf, "strips/B_%d.png", gArgs.zb ); - B.DrawRas( buf ); + sprintf( buf, "strips/B_%d.png", gArgs.zb ); + B.DrawRas( buf ); - t0 = StopTiming( flog, "MakeStrips", t0 ); + t0 = StopTiming( flog, "MakeStrips", t0 ); - A.MakePoints( thm.av, thm.ap ); - A.WriteMeta( 'A', gArgs.za ); + A.MakePoints( thm.av, thm.ap ); + A.WriteMeta( 'A', gArgs.za ); - B.MakePoints( thm.bv, thm.bp ); - B.WriteMeta( 'B', gArgs.zb ); + B.MakePoints( thm.bv, thm.bp ); + B.WriteMeta( 'B', gArgs.zb ); - thm.ftc.clear(); - thm.reqArea = int(gW * gH * inv_scl * inv_scl); - thm.olap1D = int(gW * inv_scl * 0.5); - thm.scl = 1; + thm.ftc.clear(); + thm.reqArea = int(gW * gH * inv_scl * inv_scl); + thm.olap1D = int(gW * inv_scl * 0.5); + thm.scl = 1; - S.Initialize( flog, best ); - S.SetRThresh( scr.stripmincorr ); - S.SetNbMaxHt( 0.99 ); - S.SetSweepConstXY( false ); - S.SetSweepPretweak( true ); - S.SetSweepNThreads( scr.stripslots ); - S.SetUseCorrR( true ); - S.SetNewAngProc( StripAngProc ); + S.Initialize( flog, best ); + S.SetRThresh( scr.stripmincorr ); + S.SetNbMaxHt( 0.99 ); + S.SetSweepConstXY( false ); + S.SetSweepPretweak( true ); + S.SetSweepNThreads( scr.stripslots ); + S.SetUseCorrR( true ); + S.SetNewAngProc( StripAngProc ); - gA = &A; - gB = &B; - gS = &S; + gA = &A; + gB = &B; + gS = &S; - if( gArgs.abdbg ) { + if( gArgs.abdbg ) { - //S.RFromAngle( best, gArgs.abctr, thm ); - //S.Pretweaks( best.R, gArgs.abctr, thm ); - dbgCor = true; - S.RFromAngle( best, gArgs.abctr, thm ); - } - else { + //S.RFromAngle( best, gArgs.abctr, thm ); + //S.Pretweaks( best.R, gArgs.abctr, thm ); + dbgCor = true; + S.RFromAngle( best, gArgs.abctr, thm ); + } + else { - if( scr.stripsweepspan && scr.stripsweepstep ) { + if( scr.stripsweepspan && scr.stripsweepstep ) { - S.DenovoBestAngle( best, - 0, scr.stripsweepspan / 2, scr.stripsweepstep, - thm, true ); - } - else { - best.A = 0; - S.PeakHunt( best, 0, thm ); - } + S.DenovoBestAngle( best, + 0, scr.stripsweepspan / 2, scr.stripsweepstep, + thm, true ); + } + else { + best.A = 0; + S.PeakHunt( best, 0, thm ); + } - if( ok = best.R >= scr.stripmincorr ) { + if( ok = best.R >= scr.stripmincorr ) { - best.T.Apply_R_Part( A.Opts ); + best.T.Apply_R_Part( A.Opts ); - best.X += B.Opts.x - A.Opts.x; - best.Y += B.Opts.y - A.Opts.y; + best.X += B.Opts.x - A.Opts.x; + best.Y += B.Opts.y - A.Opts.y; - best.T.SetXY( best.X, best.Y ); + best.T.SetXY( best.X, best.Y ); - fprintf( flog, "*T: [0,1,2,3,4,5] (strip-strip)\n" ); - fprintf( flog, "[%f,%f,%f,%f,%f,%f]\n", - best.T.t[0], best.T.t[1], best.T.t[2], - best.T.t[3], best.T.t[4], best.T.t[5] ); - } - } + fprintf( flog, "*T: [0,1,2,3,4,5] (strip-strip)\n" ); + fprintf( flog, "[%f,%f,%f,%f,%f,%f]\n", + best.T.t[0], best.T.t[1], best.T.t[2], + best.T.t[3], best.T.t[4], best.T.t[5] ); + } + } - t0 = StopTiming( flog, "Strips", t0 ); + t0 = StopTiming( flog, "Strips", t0 ); - return ok; + return ok; } /* --------------------------------------------------------------- */ @@ -591,93 +591,93 @@ static int AlignWithStrips( /* --------------------------------------------------------------- */ static void AlignFull( - CSuperscape &A, - CSuperscape &B, - CSuperscape &M, - clock_t &t0 ) + CSuperscape &A, + CSuperscape &B, + CSuperscape &M, + clock_t &t0 ) { - ThmRec thm; - CThmScan S; - CorRec best; - char buf[256]; - - fprintf( flog, "\n---- Align full montages ----\n" ); - - A.MakeWholeRaster(); - sprintf( buf, "strips/AF_%d.png", gArgs.za ); - A.DrawRas( buf ); - - if( gArgs.ismb ) { - B = M; - sprintf( buf, "montages/M_%d_0.png", gArgs.zb ); - B.Load( buf, flog ); - } - else - B.MakeWholeRaster(); - - sprintf( buf, "strips/BF_%d.png", gArgs.zb ); - B.DrawRas( buf ); - - t0 = StopTiming( flog, "MakeFull", t0 ); - - A.MakePoints( thm.av, thm.ap ); - A.WriteMeta( 'A', gArgs.za ); - - B.MakePoints( thm.bv, thm.bp ); - B.WriteMeta( 'B', gArgs.zb ); - - thm.ftc.clear(); - thm.reqArea = int(gW * gH * inv_scl * inv_scl); - thm.olap1D = int(gW * inv_scl); - thm.scl = 1; - - S.Initialize( flog, best ); - S.SetRThresh( 0.02 ); - S.SetNbMaxHt( 0.99 ); - S.SetSweepConstXY( false ); - S.SetSweepPretweak( true ); - S.SetSweepNThreads( scr.stripslots ); - S.SetUseCorrR( true ); - S.SetDisc( 0, 0, -1, -1 ); - - gA = &A; - gB = &B; - gS = &S; - - if( gArgs.abdbgfull ) { - - //S.RFromAngle( best, gArgs.abctr, thm ); - //S.Pretweaks( best.R, gArgs.abctr, thm ); - dbgCor = true; - S.RFromAngle( best, gArgs.abctr, thm ); - } - else { - - if( scr.stripsweepspan && scr.stripsweepstep ) { - - S.DenovoBestAngle( best, - 0, scr.stripsweepspan / 2, scr.stripsweepstep, - thm, true ); - } - else { - best.A = 0; - S.PeakHunt( best, 0, thm ); - } - - best.T.Apply_R_Part( A.Opts ); - - best.X += B.Opts.x - A.Opts.x; - best.Y += B.Opts.y - A.Opts.y; - - best.T.SetXY( best.X, best.Y ); - - fprintf( flog, "*T: [0,1,2,3,4,5] (full-full)\n" ); - fprintf( flog, "[%f,%f,%f,%f,%f,%f]\n", - best.T.t[0], best.T.t[1], best.T.t[2], - best.T.t[3], best.T.t[4], best.T.t[5] ); - } - - t0 = StopTiming( flog, "Full", t0 ); + ThmRec thm; + CThmScan S; + CorRec best; + char buf[256]; + + fprintf( flog, "\n---- Align full montages ----\n" ); + + A.MakeWholeRaster(); + sprintf( buf, "strips/AF_%d.png", gArgs.za ); + A.DrawRas( buf ); + + if( gArgs.ismb ) { + B = M; + sprintf( buf, "montages/M_%d_0.png", gArgs.zb ); + B.Load( buf, flog ); + } + else + B.MakeWholeRaster(); + + sprintf( buf, "strips/BF_%d.png", gArgs.zb ); + B.DrawRas( buf ); + + t0 = StopTiming( flog, "MakeFull", t0 ); + + A.MakePoints( thm.av, thm.ap ); + A.WriteMeta( 'A', gArgs.za ); + + B.MakePoints( thm.bv, thm.bp ); + B.WriteMeta( 'B', gArgs.zb ); + + thm.ftc.clear(); + thm.reqArea = int(gW * gH * inv_scl * inv_scl); + thm.olap1D = int(gW * inv_scl); + thm.scl = 1; + + S.Initialize( flog, best ); + S.SetRThresh( 0.02 ); + S.SetNbMaxHt( 0.99 ); + S.SetSweepConstXY( false ); + S.SetSweepPretweak( true ); + S.SetSweepNThreads( scr.stripslots ); + S.SetUseCorrR( true ); + S.SetDisc( 0, 0, -1, -1 ); + + gA = &A; + gB = &B; + gS = &S; + + if( gArgs.abdbgfull ) { + + //S.RFromAngle( best, gArgs.abctr, thm ); + //S.Pretweaks( best.R, gArgs.abctr, thm ); + dbgCor = true; + S.RFromAngle( best, gArgs.abctr, thm ); + } + else { + + if( scr.stripsweepspan && scr.stripsweepstep ) { + + S.DenovoBestAngle( best, + 0, scr.stripsweepspan / 2, scr.stripsweepstep, + thm, true ); + } + else { + best.A = 0; + S.PeakHunt( best, 0, thm ); + } + + best.T.Apply_R_Part( A.Opts ); + + best.X += B.Opts.x - A.Opts.x; + best.Y += B.Opts.y - A.Opts.y; + + best.T.SetXY( best.X, best.Y ); + + fprintf( flog, "*T: [0,1,2,3,4,5] (full-full)\n" ); + fprintf( flog, "[%f,%f,%f,%f,%f,%f]\n", + best.T.t[0], best.T.t[1], best.T.t[2], + best.T.t[3], best.T.t[4], best.T.t[5] ); + } + + t0 = StopTiming( flog, "Full", t0 ); } /* --------------------------------------------------------------- */ @@ -717,39 +717,39 @@ static void AlignFull( // static void ScapeStuff() { - clock_t t0 = StartTiming(); - CSuperscape A, B, M; + clock_t t0 = StartTiming(); + CSuperscape A, B, M; - B.FindLayerIndices( gArgs.zb ); - B.OrientLayer(); + B.FindLayerIndices( gArgs.zb ); + B.OrientLayer(); - if( gArgs.ismb ) { + if( gArgs.ismb ) { - char buf[256]; + char buf[256]; - fprintf( flog, "\n---- Paint montage ----\n" ); + fprintf( flog, "\n---- Paint montage ----\n" ); - B.MakeWholeRaster(); - sprintf( buf, "montages/M_%d_0.png", gArgs.zb ); - B.DrawRas( buf ); - B.KillRas(); - B.WriteMeta( 'M', gArgs.zb ); - M = B; // reuse montage metadata in AlignFull - t0 = StopTiming( flog, "MakeMontage", t0 ); - } + B.MakeWholeRaster(); + sprintf( buf, "montages/M_%d_0.png", gArgs.zb ); + B.DrawRas( buf ); + B.KillRas(); + B.WriteMeta( 'M', gArgs.zb ); + M = B; // reuse montage metadata in AlignFull + t0 = StopTiming( flog, "MakeMontage", t0 ); + } - if( !gArgs.isab ) - return; + if( !gArgs.isab ) + return; - A.FindLayerIndices( gArgs.za ); - A.OrientLayer(); + A.FindLayerIndices( gArgs.za ); + A.OrientLayer(); - if( gArgs.abdbgfull || - scr.stripwidth <= 0 || - !AlignWithStrips( A, B, t0 ) ) { + if( gArgs.abdbgfull || + scr.stripwidth <= 0 || + !AlignWithStrips( A, B, t0 ) ) { - AlignFull( A, B, M, t0 ); - } + AlignFull( A, B, M, t0 ); + } } /* --------------------------------------------------------------- */ @@ -758,62 +758,62 @@ static void ScapeStuff() int main( int argc, char* argv[] ) { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); /* ------------------ */ /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); - TS.SetLogFile( flog ); + TS.SetLogFile( flog ); - if( !ReadScriptParams( scr, gArgs.script, flog ) ) - goto exit; + if( !ReadScriptParams( scr, gArgs.script, flog ) ) + goto exit; - inv_scl = 1.0 / scr.crossscale; + inv_scl = 1.0 / scr.crossscale; /* ---------------- */ /* Read source data */ /* ---------------- */ - if( gArgs.zb >= 0 && gArgs.za < 0 ) - gArgs.za = gArgs.zb; + if( gArgs.zb >= 0 && gArgs.za < 0 ) + gArgs.za = gArgs.zb; - TS.FillFromRgns( gArgs.srcmons, gArgs.idb, gArgs.zb, gArgs.za ); + TS.FillFromRgns( gArgs.srcmons, gArgs.idb, gArgs.zb, gArgs.za ); - fprintf( flog, "Got %d images.\n", (int)TS.vtil.size() ); + fprintf( flog, "Got %d images.\n", (int)TS.vtil.size() ); - if( !TS.vtil.size() ) - goto exit; + if( !TS.vtil.size() ) + goto exit; - TS.SetTileDimsFromImageFile(); - TS.GetTileDims( gW, gH ); + TS.SetTileDimsFromImageFile(); + TS.GetTileDims( gW, gH ); - t0 = StopTiming( flog, "ReadFile", t0 ); + t0 = StopTiming( flog, "ReadFile", t0 ); /* ------------- */ /* Sort by layer */ /* ------------- */ - TS.SortAll_z(); + TS.SortAll_z(); /* ----- */ /* Stuff */ /* ----- */ - ScapeStuff(); + ScapeStuff(); /* ---- */ /* Done */ /* ---- */ exit: - fprintf( flog, "\n" ); - VMStats( flog ); - fclose( flog ); + fprintf( flog, "\n" ); + VMStats( flog ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_ShtMaker/makefile b/1_ShtMaker/makefile index 5a890a1..afb5c5a 100644 --- a/1_ShtMaker/makefile +++ b/1_ShtMaker/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_ShtMaker/shtmaker.cpp b/1_ShtMaker/shtmaker.cpp index d611ca2..6e6de4e 100644 --- a/1_ShtMaker/shtmaker.cpp +++ b/1_ShtMaker/shtmaker.cpp @@ -12,47 +12,47 @@ // int main(int argc, char **argv) { - char *line; - size_t size = 0; + char *line; + size_t size = 0; - while( getline( &line, &size, stdin ) > 0 ) { + while( getline( &line, &size, stdin ) > 0 ) { - printf( "\tfprintf( f, \"" ); + printf( "\tfprintf( f, \"" ); - char *s = line, c; + char *s = line, c; - while( c = *s++ ) { + while( c = *s++ ) { - switch( c ) { + switch( c ) { - case '\n': - printf( "\\n\" );\n" ); - break; + case '\n': + printf( "\\n\" );\n" ); + break; - case '\t': - printf( "\\t" ); - break; + case '\t': + printf( "\\t" ); + break; - case '"': - printf( "\\\"" ); - break; + case '"': + printf( "\\\"" ); + break; - case '\\': - printf( "\\\\" ); - break; + case '\\': + printf( "\\\\" ); + break; - case '%': - printf( "%%%%" ); - break; + case '%': + printf( "%%%%" ); + break; - default: - printf( "%c", c ); - break; - } - } - } + default: + printf( "%c", c ); + break; + } + } + } - return 0; + return 0; } diff --git a/1_Thumbs/CGBL_Thumbs.cpp b/1_Thumbs/CGBL_Thumbs.cpp index 63d61c4..ce0b924 100644 --- a/1_Thumbs/CGBL_Thumbs.cpp +++ b/1_Thumbs/CGBL_Thumbs.cpp @@ -41,26 +41,26 @@ CGBL_Thumbs GBL; CGBL_Thumbs::CGBL_Thumbs() { - _arg.SCALE = 999.0; - _arg.XSCALE = 999.0; - _arg.YSCALE = 999.0; - _arg.SKEW = 999.0; - _arg.ima = NULL; - _arg.imb = NULL; - _arg.FLD = 0; - _arg.MODE = 0; - - arg.CTR = 999.0; - arg.fma = NULL; - arg.fmb = NULL; - arg.Transpose = false; - arg.SingleFold = false; - - A.z = 0; - A.id = 0; - - B.z = 0; - B.id = 0; + _arg.SCALE = 999.0; + _arg.XSCALE = 999.0; + _arg.YSCALE = 999.0; + _arg.SKEW = 999.0; + _arg.ima = NULL; + _arg.imb = NULL; + _arg.FLD = 0; + _arg.MODE = 0; + + arg.CTR = 999.0; + arg.fma = NULL; + arg.fmb = NULL; + arg.Transpose = false; + arg.SingleFold = false; + + A.z = 0; + A.id = 0; + + B.z = 0; + B.id = 0; } /* --------------------------------------------------------------- */ @@ -71,266 +71,266 @@ bool CGBL_Thumbs::SetCmdLine( int argc, char* argv[] ) { // Parse args - vector vD; - char *key; - - for( int i = 1; i < argc; ++i ) { - - if( argv[i][0] != '-' ) - key = argv[i]; - else if( GetArgList( vD, "-Tdfm=", argv[i] ) ) { - - if( 6 == vD.size() ) - _arg.Tdfm.push_back( TAffine( &vD[0] ) ); - else { - printf( - "main: WARNING: Bad format in -Tdfm [%s].\n", - argv[i] ); - } - } - else if( GetArgList( vD, "-Tab=", argv[i] ) ) { - - if( 6 == vD.size() ) - _arg.Tab.push_back( TAffine( &vD[0] ) ); - else { - printf( - "main: WARNING: Bad format in -Tab [%s].\n", - argv[i] ); - } - } - else if( GetArg( &_arg.SCALE, "-SCALE=%lf", argv[i] ) ) - ; - else if( GetArg( &_arg.XSCALE, "-XSCALE=%lf", argv[i] ) ) - ; - else if( GetArg( &_arg.YSCALE, "-YSCALE=%lf", argv[i] ) ) - ; - else if( GetArg( &_arg.SKEW, "-SKEW=%lf", argv[i] ) ) - ; - else if( GetArgStr( _arg.ima, "-ima=", argv[i] ) ) - ; - else if( GetArgStr( _arg.imb, "-imb=", argv[i] ) ) - ; - else if( GetArg( &_arg.FLD, "-FLD=%c", argv[i] ) ) - ; - else if( GetArg( &_arg.MODE, "-MODE=%c", argv[i] ) ) - ; - else if( GetArg( &arg.CTR, "-CTR=%lf", argv[i] ) ) - ; - else if( GetArgStr( arg.fma, "-fma=", argv[i] ) ) - ; - else if( GetArgStr( arg.fmb, "-fmb=", argv[i] ) ) - ; - else if( IsArg( "-tr", argv[i] ) ) - arg.Transpose = true; - else if( IsArg( "-nf", argv[i] ) ) - _arg.FLD = 'N'; - else if( IsArg( "-sf", argv[i] ) ) - arg.SingleFold = true; - else if( IsArg( "-dbgcor", argv[i] ) ) - dbgCor = true; - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - return false; - } - } + vector vD; + char *key; + + for( int i = 1; i < argc; ++i ) { + + if( argv[i][0] != '-' ) + key = argv[i]; + else if( GetArgList( vD, "-Tdfm=", argv[i] ) ) { + + if( 6 == vD.size() ) + _arg.Tdfm.push_back( TAffine( &vD[0] ) ); + else { + printf( + "main: WARNING: Bad format in -Tdfm [%s].\n", + argv[i] ); + } + } + else if( GetArgList( vD, "-Tab=", argv[i] ) ) { + + if( 6 == vD.size() ) + _arg.Tab.push_back( TAffine( &vD[0] ) ); + else { + printf( + "main: WARNING: Bad format in -Tab [%s].\n", + argv[i] ); + } + } + else if( GetArg( &_arg.SCALE, "-SCALE=%lf", argv[i] ) ) + ; + else if( GetArg( &_arg.XSCALE, "-XSCALE=%lf", argv[i] ) ) + ; + else if( GetArg( &_arg.YSCALE, "-YSCALE=%lf", argv[i] ) ) + ; + else if( GetArg( &_arg.SKEW, "-SKEW=%lf", argv[i] ) ) + ; + else if( GetArgStr( _arg.ima, "-ima=", argv[i] ) ) + ; + else if( GetArgStr( _arg.imb, "-imb=", argv[i] ) ) + ; + else if( GetArg( &_arg.FLD, "-FLD=%c", argv[i] ) ) + ; + else if( GetArg( &_arg.MODE, "-MODE=%c", argv[i] ) ) + ; + else if( GetArg( &arg.CTR, "-CTR=%lf", argv[i] ) ) + ; + else if( GetArgStr( arg.fma, "-fma=", argv[i] ) ) + ; + else if( GetArgStr( arg.fmb, "-fmb=", argv[i] ) ) + ; + else if( IsArg( "-tr", argv[i] ) ) + arg.Transpose = true; + else if( IsArg( "-nf", argv[i] ) ) + _arg.FLD = 'N'; + else if( IsArg( "-sf", argv[i] ) ) + arg.SingleFold = true; + else if( IsArg( "-dbgcor", argv[i] ) ) + dbgCor = true; + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + return false; + } + } // Decode labels in key - if( !key || - (4 != sscanf( key, "%d.%d^%d.%d", - &A.z, &A.id, - &B.z, &B.id )) ) { + if( !key || + (4 != sscanf( key, "%d.%d^%d.%d", + &A.z, &A.id, + &B.z, &B.id )) ) { - printf( "main: Usage: thumbs .\n" ); - return false; - } + printf( "main: Usage: thumbs .\n" ); + return false; + } // Rename stdout using image labels - OpenPairLog( A.z, A.id, B.z, B.id ); + OpenPairLog( A.z, A.id, B.z, B.id ); - printf( "\n---- Thumbnail matching ----\n" ); + printf( "\n---- Thumbnail matching ----\n" ); // Record start time - time_t t0 = time( NULL ); - printf( "main: Start: %s\n", ctime(&t0) ); + time_t t0 = time( NULL ); + printf( "main: Start: %s\n", ctime(&t0) ); // Get default parameters - if( !ReadMatchParams( mch, A.z, B.z ) ) - return false; + if( !ReadMatchParams( mch, A.z, B.z ) ) + return false; // Which file params to use according to (same,cross) layer - double cSCALE=1, cXSCALE=1, cYSCALE=1, cSKEW=0; - int cDfmFromTab; - - ctx.FLD = mch.FLD; - - if( A.z == B.z ) { - - cDfmFromTab = mch.TAB2DFM_SL; - - //ctx.Tdfm = identity (default) - ctx.XYCONF = mch.XYCONF_SL; - ctx.NBMXHT = mch.NBMXHT_SL; - ctx.HFANGDN = mch.HFANGDN_SL; - ctx.HFANGPR = mch.HFANGPR_SL; - ctx.RTRSH = mch.RTRSH_SL; - ctx.OLAP2D = mch.OLAP2D_SL; - ctx.MODE = mch.MODE_SL; - ctx.THMDEC = mch.THMDEC_SL; - ctx.OLAP1D = mch.OLAP1D_SL; - ctx.LIMXY = mch.LIMXY_SL; - } - else { - - cSCALE = mch.SCALE; - cXSCALE = mch.XSCALE; - cYSCALE = mch.YSCALE; - cSKEW = mch.SKEW; - - ctx.Tdfm.ComposeDfm( cSCALE, cXSCALE, cYSCALE, 0, cSKEW ); - - cDfmFromTab = mch.TAB2DFM_XL; - - ctx.XYCONF = mch.XYCONF_XL; - ctx.NBMXHT = mch.NBMXHT_XL; - ctx.HFANGDN = mch.HFANGDN_XL; - ctx.HFANGPR = mch.HFANGPR_XL; - ctx.RTRSH = mch.RTRSH_XL; - ctx.OLAP2D = mch.OLAP2D_XL; - ctx.MODE = mch.MODE_XL; - ctx.THMDEC = mch.THMDEC_XL; - ctx.OLAP1D = mch.OLAP1D_XL; - ctx.LIMXY = mch.LIMXY_XL; - } + double cSCALE=1, cXSCALE=1, cYSCALE=1, cSKEW=0; + int cDfmFromTab; + + ctx.FLD = mch.FLD; + + if( A.z == B.z ) { + + cDfmFromTab = mch.TAB2DFM_SL; + + //ctx.Tdfm = identity (default) + ctx.XYCONF = mch.XYCONF_SL; + ctx.NBMXHT = mch.NBMXHT_SL; + ctx.HFANGDN = mch.HFANGDN_SL; + ctx.HFANGPR = mch.HFANGPR_SL; + ctx.RTRSH = mch.RTRSH_SL; + ctx.OLAP2D = mch.OLAP2D_SL; + ctx.MODE = mch.MODE_SL; + ctx.THMDEC = mch.THMDEC_SL; + ctx.OLAP1D = mch.OLAP1D_SL; + ctx.LIMXY = mch.LIMXY_SL; + } + else { + + cSCALE = mch.SCALE; + cXSCALE = mch.XSCALE; + cYSCALE = mch.YSCALE; + cSKEW = mch.SKEW; + + ctx.Tdfm.ComposeDfm( cSCALE, cXSCALE, cYSCALE, 0, cSKEW ); + + cDfmFromTab = mch.TAB2DFM_XL; + + ctx.XYCONF = mch.XYCONF_XL; + ctx.NBMXHT = mch.NBMXHT_XL; + ctx.HFANGDN = mch.HFANGDN_XL; + ctx.HFANGPR = mch.HFANGPR_XL; + ctx.RTRSH = mch.RTRSH_XL; + ctx.OLAP2D = mch.OLAP2D_XL; + ctx.MODE = mch.MODE_XL; + ctx.THMDEC = mch.THMDEC_XL; + ctx.OLAP1D = mch.OLAP1D_XL; + ctx.LIMXY = mch.LIMXY_XL; + } // Fetch Til2Img entries - printf( "\n---- Input images ----\n" ); + printf( "\n---- Input images ----\n" ); - IDBFromTemp( idb, "../../" ); + IDBFromTemp( idb, "../../" ); - if( !IDBT2IGet1( A.t2i, idb, A.z, A.id, _arg.ima ) || - !IDBT2IGet1( B.t2i, idb, B.z, B.id, _arg.imb ) ) { + if( !IDBT2IGet1( A.t2i, idb, A.z, A.id, _arg.ima ) || + !IDBT2IGet1( B.t2i, idb, B.z, B.id, _arg.imb ) ) { - return false; - } + return false; + } - PrintTil2Img( stdout, 'A', A.t2i ); - PrintTil2Img( stdout, 'B', B.t2i ); + PrintTil2Img( stdout, 'A', A.t2i ); + PrintTil2Img( stdout, 'B', B.t2i ); - printf( "\n" ); + printf( "\n" ); // Commandline overrides - printf( "\n---- Command-line overrides ----\n" ); + printf( "\n---- Command-line overrides ----\n" ); - if( _arg.Tab.size() ) { + if( _arg.Tab.size() ) { - Tab = _arg.Tab[0]; + Tab = _arg.Tab[0]; - // remove lens parts of Tab coming from cross_thisblock + // remove lens parts of Tab coming from cross_thisblock - if( mch.PXLENS && A.z != B.z ) { + if( mch.PXLENS && A.z != B.z ) { - CAffineLens LN; + CAffineLens LN; - if( !LN.ReadIDB( idb ) ) - return false; + if( !LN.ReadIDB( idb ) ) + return false; - LN.UpdateTFormRHS( Tab, A.t2i.cam, true ); - LN.UpdateTFormLHS( Tab, B.t2i.cam, false ); - } + LN.UpdateTFormRHS( Tab, A.t2i.cam, true ); + LN.UpdateTFormLHS( Tab, B.t2i.cam, false ); + } - Tab.TPrint( stdout, "Tab= " ); - } - else - Tab.FromAToB( A.t2i.T, B.t2i.T ); + Tab.TPrint( stdout, "Tab= " ); + } + else + Tab.FromAToB( A.t2i.T, B.t2i.T ); - int altTdfm = false; + int altTdfm = false; - if( _arg.Tdfm.size() ) { + if( _arg.Tdfm.size() ) { - ctx.Tdfm = _arg.Tdfm[0]; - altTdfm = true; - } - else { + ctx.Tdfm = _arg.Tdfm[0]; + altTdfm = true; + } + else { - if( _arg.SCALE != 999.0 ) { - cSCALE = _arg.SCALE; - altTdfm = true; - printf( "SCALE=%g\n", _arg.SCALE ); - } + if( _arg.SCALE != 999.0 ) { + cSCALE = _arg.SCALE; + altTdfm = true; + printf( "SCALE=%g\n", _arg.SCALE ); + } - if( _arg.XSCALE != 999.0 ) { - cXSCALE = _arg.XSCALE; - altTdfm = true; - printf( "XSCALE=%g\n", _arg.XSCALE ); - } + if( _arg.XSCALE != 999.0 ) { + cXSCALE = _arg.XSCALE; + altTdfm = true; + printf( "XSCALE=%g\n", _arg.XSCALE ); + } - if( _arg.YSCALE != 999.0 ) { - cYSCALE = _arg.YSCALE; - altTdfm = true; - printf( "YSCALE=%g\n", _arg.YSCALE ); - } + if( _arg.YSCALE != 999.0 ) { + cYSCALE = _arg.YSCALE; + altTdfm = true; + printf( "YSCALE=%g\n", _arg.YSCALE ); + } - if( _arg.SKEW != 999.0 ) { - cSKEW = _arg.SKEW; - altTdfm = true; - printf( "SKEW=%g\n", _arg.SKEW ); - } + if( _arg.SKEW != 999.0 ) { + cSKEW = _arg.SKEW; + altTdfm = true; + printf( "SKEW=%g\n", _arg.SKEW ); + } - if( altTdfm ) - ctx.Tdfm.ComposeDfm( cSCALE, cXSCALE, cYSCALE, 0, cSKEW ); - } + if( altTdfm ) + ctx.Tdfm.ComposeDfm( cSCALE, cXSCALE, cYSCALE, 0, cSKEW ); + } - if( !altTdfm && cDfmFromTab ) { + if( !altTdfm && cDfmFromTab ) { - TAffine R; - R.NUSetRot( -Tab.GetRadians() ); + TAffine R; + R.NUSetRot( -Tab.GetRadians() ); - ctx.Tdfm = Tab; - ctx.Tdfm.SetXY( 0, 0 ); - ctx.Tdfm = R * ctx.Tdfm; - } + ctx.Tdfm = Tab; + ctx.Tdfm.SetXY( 0, 0 ); + ctx.Tdfm = R * ctx.Tdfm; + } - ctx.Tdfm.TPrint( stdout, "Tdfm=" ); + ctx.Tdfm.TPrint( stdout, "Tdfm=" ); - if( _arg.FLD ) { - ctx.FLD = _arg.FLD; - printf( "FLD=%c\n", _arg.FLD ); - } + if( _arg.FLD ) { + ctx.FLD = _arg.FLD; + printf( "FLD=%c\n", _arg.FLD ); + } - if( ctx.FLD == 'X' ) { - ctx.FLD = (GBL.A.z == GBL.B.z ? 'N' : 'Y'); - printf( "FLD=%c (was X)\n", ctx.FLD ); - } + if( ctx.FLD == 'X' ) { + ctx.FLD = (GBL.A.z == GBL.B.z ? 'N' : 'Y'); + printf( "FLD=%c (was X)\n", ctx.FLD ); + } - if( _arg.MODE ) { - ctx.MODE = _arg.MODE; - printf( "MODE=%c\n", _arg.MODE ); - } + if( _arg.MODE ) { + ctx.MODE = _arg.MODE; + printf( "MODE=%c\n", _arg.MODE ); + } - if( ctx.MODE == 'Z' ) { - ctx.MODE = 'C'; - arg.CTR = 0.0; - printf( "MODE=C (was Z)\n" ); - } - else if( ctx.MODE == 'M' ) { - ctx.MODE = 'N'; - arg.CTR = 0.0; - printf( "MODE=N (was M)\n" ); - } + if( ctx.MODE == 'Z' ) { + ctx.MODE = 'C'; + arg.CTR = 0.0; + printf( "MODE=C (was Z)\n" ); + } + else if( ctx.MODE == 'M' ) { + ctx.MODE = 'N'; + arg.CTR = 0.0; + printf( "MODE=N (was M)\n" ); + } - if( arg.CTR != 999.0 ) - printf( "CTR=%g\n", arg.CTR ); + if( arg.CTR != 999.0 ) + printf( "CTR=%g\n", arg.CTR ); - printf( "\n" ); + printf( "\n" ); - return true; + return true; } diff --git a/1_Thumbs/CGBL_Thumbs.h b/1_Thumbs/CGBL_Thumbs.h index 6649e97..a1b3718 100644 --- a/1_Thumbs/CGBL_Thumbs.h +++ b/1_Thumbs/CGBL_Thumbs.h @@ -17,71 +17,71 @@ class CGBL_Thumbs { // ===== private: - typedef struct { - vector Tdfm, - Tab; - double SCALE, - XSCALE, - YSCALE, - SKEW; - const char *ima, // override idb paths - *imb; - int FLD, - MODE; - } PrvDrvArgs; + typedef struct { + vector Tdfm, + Tab; + double SCALE, + XSCALE, + YSCALE, + SKEW; + const char *ima, // override idb paths + *imb; + int FLD, + MODE; + } PrvDrvArgs; public: - typedef struct { - double CTR; - const char *fma, // override idb paths - *fmb; - bool Transpose, // transpose all images - SingleFold; // assign id=1 to all non-fold rgns - } DriverArgs; - - typedef struct { - TAffine Tdfm; - double XYCONF, - NBMXHT, - HFANGDN, - HFANGPR, - RTRSH; - long OLAP2D; - int FLD, - MODE, - THMDEC, - OLAP1D, - LIMXY; - } CntxtDep; + typedef struct { + double CTR; + const char *fma, // override idb paths + *fmb; + bool Transpose, // transpose all images + SingleFold; // assign id=1 to all non-fold rgns + } DriverArgs; + + typedef struct { + TAffine Tdfm; + double XYCONF, + NBMXHT, + HFANGDN, + HFANGPR, + RTRSH; + long OLAP2D; + int FLD, + MODE, + THMDEC, + OLAP1D, + LIMXY; + } CntxtDep; // ============ // Data members // ============ private: - PrvDrvArgs _arg; + PrvDrvArgs _arg; public: - DriverArgs arg; - TAffine Tab; // start thumbs here - MatchParams mch; - CntxtDep ctx; - string idb; - PicSpec A, B; + DriverArgs arg; + TAffine Tab; // start thumbs here + MatchParams mch; + CntxtDep ctx; + string idb; + PicSpec A, B; // ================= // Object management // ================= public: - CGBL_Thumbs(); + CGBL_Thumbs(); // ========= // Interface // ========= public: - bool SetCmdLine( int argc, char* argv[] ); + bool SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ diff --git a/1_Thumbs/Thumbs.cpp b/1_Thumbs/Thumbs.cpp index 6e4a939..0ed400c 100644 --- a/1_Thumbs/Thumbs.cpp +++ b/1_Thumbs/Thumbs.cpp @@ -21,74 +21,74 @@ // See notes in ApproximateMatch.cpp. // bool Thumbs( - const PixPair &px, - const ConnRegion &acr, - const ConnRegion &bcr, - FILE* flog ) + const PixPair &px, + const ConnRegion &acr, + const ConnRegion &bcr, + FILE* flog ) { /* ------------------- */ /* Handle bypass modes */ /* ------------------- */ - if( GBL.ctx.MODE == 'E' || GBL.ctx.MODE == 'F' ) - return true; + if( GBL.ctx.MODE == 'E' || GBL.ctx.MODE == 'F' ) + return true; /* ------------------- */ /* Handle search modes */ /* ------------------- */ - CThmUtil U( GBL.A, acr.id, GBL.B, bcr.id, px, - GBL.Tab, GBL.ctx.OLAP2D, flog ); + CThmUtil U( GBL.A, acr.id, GBL.B, bcr.id, px, + GBL.Tab, GBL.ctx.OLAP2D, flog ); - U.SetParams( - GBL.ctx.HFANGDN, GBL.ctx.HFANGPR, GBL.ctx.RTRSH, - GBL.ctx.OLAP1D, GBL.ctx.MODE, GBL.ctx.LIMXY, - GBL.mch.WTHMPR ); + U.SetParams( + GBL.ctx.HFANGDN, GBL.ctx.HFANGPR, GBL.ctx.RTRSH, + GBL.ctx.OLAP1D, GBL.ctx.MODE, GBL.ctx.LIMXY, + GBL.mch.WTHMPR ); - CThmScan S; - CorRec best; + CThmScan S; + CorRec best; - S.Initialize( flog, best ); - S.SetTdfm( GBL.ctx.Tdfm ); - S.SetRThresh( GBL.ctx.RTRSH ); - S.SetNbMaxHt( GBL.ctx.NBMXHT ); - S.SetSweepConstXY( true ); - S.SetSweepPretweak( GBL.mch.PRETWEAK ); - S.SetUseCorrR( true ); - S.SetDisc( 0, 0, -1, -1 ); + S.Initialize( flog, best ); + S.SetTdfm( GBL.ctx.Tdfm ); + S.SetRThresh( GBL.ctx.RTRSH ); + S.SetNbMaxHt( GBL.ctx.NBMXHT ); + S.SetSweepConstXY( true ); + S.SetSweepPretweak( GBL.mch.PRETWEAK ); + S.SetUseCorrR( true ); + S.SetDisc( 0, 0, -1, -1 ); /* ----------------------- */ /* Create image thumbnails */ /* ----------------------- */ - OlapRec olp; - ThmRec thm; - int nPriorAngles = U.SetStartingAngle( - GBL.ctx.Tdfm, GBL.arg.CTR ); + OlapRec olp; + ThmRec thm; + int nPriorAngles = U.SetStartingAngle( + GBL.ctx.Tdfm, GBL.arg.CTR ); - if( !U.Crop( olp, acr, bcr, GBL.ctx.XYCONF ) ) - return false; + if( !U.Crop( olp, acr, bcr, GBL.ctx.XYCONF ) ) + return false; - if( !U.MakeThumbs( thm, olp, GBL.ctx.THMDEC ) ) - return false; + if( !U.MakeThumbs( thm, olp, GBL.ctx.THMDEC ) ) + return false; /* ------ */ /* Search */ /* ------ */ - if( GBL.ctx.MODE == 'N' ) { + if( GBL.ctx.MODE == 'N' ) { - if( !U.Disc( best, S, thm, olp, GBL.mch.PRETWEAK ) ) - return false; - } - else if( !U.Sweep( best, S, thm, nPriorAngles ) ) - return false; + if( !U.Disc( best, S, thm, olp, GBL.mch.PRETWEAK ) ) + return false; + } + else if( !U.Sweep( best, S, thm, nPriorAngles ) ) + return false; /* ------ */ /* Finish */ /* ------ */ - return U.Finish( best, S, thm, olp, GBL.mch.TWEAKS ); + return U.Finish( best, S, thm, olp, GBL.mch.TWEAKS ); } diff --git a/1_Thumbs/Thumbs.h b/1_Thumbs/Thumbs.h index 5ff68bb..6eee8a4 100644 --- a/1_Thumbs/Thumbs.h +++ b/1_Thumbs/Thumbs.h @@ -14,9 +14,9 @@ bool Thumbs_NoCR( const PixPair &px, FILE* flog ); bool Thumbs( - const PixPair &px, - const ConnRegion &acr, - const ConnRegion &bcr, - FILE* flog ); + const PixPair &px, + const ConnRegion &acr, + const ConnRegion &bcr, + FILE* flog ); diff --git a/1_Thumbs/ThumbsDriver.cpp b/1_Thumbs/ThumbsDriver.cpp index 5271d2c..26b145f 100644 --- a/1_Thumbs/ThumbsDriver.cpp +++ b/1_Thumbs/ThumbsDriver.cpp @@ -31,128 +31,128 @@ int main( int argc, char* argv[] ) { - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); /* ------------------ */ /* Parse command line */ /* ------------------ */ - if( !GBL.SetCmdLine( argc, argv ) ) - return 42; + if( !GBL.SetCmdLine( argc, argv ) ) + return 42; /* ---------- */ /* Get images */ /* ---------- */ - PixPair px; - CCropMask CM, *pCM = &CM; + PixPair px; + CCropMask CM, *pCM = &CM; - if( !px.Load( - GBL.A, GBL.B, GBL.idb, - GBL.mch.PXLENS, GBL.mch.PXRESMSK, GBL.mch.PXBRO, - GBL.mch.PXDOG, GBL.mch.PXDOG_R1, GBL.mch.PXDOG_R2, - stdout, GBL.arg.Transpose ) ) { + if( !px.Load( + GBL.A, GBL.B, GBL.idb, + GBL.mch.PXLENS, GBL.mch.PXRESMSK, GBL.mch.PXBRO, + GBL.mch.PXDOG, GBL.mch.PXDOG_R1, GBL.mch.PXDOG_R2, + stdout, GBL.arg.Transpose ) ) { - goto exit; - } + goto exit; + } /* ------------------- */ /* Scaling adjustments */ /* ------------------- */ - GBL.ctx.OLAP1D /= px.scl; - GBL.ctx.OLAP2D /= (px.scl * px.scl); + GBL.ctx.OLAP1D /= px.scl; + GBL.ctx.OLAP2D /= (px.scl * px.scl); /* ---------------------------------- */ /* Use foldmasks according to context */ /* ---------------------------------- */ - if( GBL.ctx.FLD == 'N' - && !GBL.mch.PXRESMSK - && !CM.IsFile( GBL.idb ) ) { + if( GBL.ctx.FLD == 'N' + && !GBL.mch.PXRESMSK + && !CM.IsFile( GBL.idb ) ) { - Thumbs_NoCR( px, stdout ); - } - else { + Thumbs_NoCR( px, stdout ); + } + else { - /* --------------- */ - /* Load fold masks */ - /* --------------- */ + /* --------------- */ + /* Load fold masks */ + /* --------------- */ - clock_t t1 = StartTiming(); - uint8 *fold_mask_a, *fold_mask_b; - vector Acr, Bcr; + clock_t t1 = StartTiming(); + uint8 *fold_mask_a, *fold_mask_b; + vector Acr, Bcr; - printf( "\n---- Foldmaps ----\n" ); + printf( "\n---- Foldmaps ----\n" ); - // Note that the foldmasks are always at full resolution. + // Note that the foldmasks are always at full resolution. - if( !CM.ReadIDB( GBL.idb ) ) - pCM = NULL; + if( !CM.ReadIDB( GBL.idb ) ) + pCM = NULL; - fold_mask_a = - GetFoldMask( - GBL.idb, GBL.A, GBL.arg.fma, - px.resmska, pCM, - px.wf, px.hf, - false, GBL.arg.Transpose, - GBL.arg.SingleFold ); + fold_mask_a = + GetFoldMask( + GBL.idb, GBL.A, GBL.arg.fma, + px.resmska, pCM, + px.wf, px.hf, + false, GBL.arg.Transpose, + GBL.arg.SingleFold ); - fold_mask_b = - GetFoldMask( - GBL.idb, GBL.B, GBL.arg.fmb, - px.resmskb, pCM, - px.wf, px.hf, - false, GBL.arg.Transpose, - GBL.arg.SingleFold ); + fold_mask_b = + GetFoldMask( + GBL.idb, GBL.B, GBL.arg.fmb, + px.resmskb, pCM, + px.wf, px.hf, + false, GBL.arg.Transpose, + GBL.arg.SingleFold ); - /* ----------------------- */ - /* Convert to Conn regions */ - /* ----------------------- */ + /* ----------------------- */ + /* Convert to Conn regions */ + /* ----------------------- */ - // Note that the connected region lists are always - // at the reduced resolution, if this is used. + // Note that the connected region lists are always + // at the reduced resolution, if this is used. - printf( "\n---- Connected regions ----\n" ); + printf( "\n---- Connected regions ----\n" ); - ConnRgnsFromFoldMask( Acr, fold_mask_a, - px.wf, px.hf, px.scl, - GBL.ctx.OLAP2D ); + ConnRgnsFromFoldMask( Acr, fold_mask_a, + px.wf, px.hf, px.scl, + GBL.ctx.OLAP2D ); - ConnRgnsFromFoldMask( Bcr, fold_mask_b, - px.wf, px.hf, px.scl, - GBL.ctx.OLAP2D ); + ConnRgnsFromFoldMask( Bcr, fold_mask_b, + px.wf, px.hf, px.scl, + GBL.ctx.OLAP2D ); - StopTiming( stdout, "Conn regions", t1 ); + StopTiming( stdout, "Conn regions", t1 ); - /* --------------------- */ - /* Run the pair mappings */ - /* --------------------- */ + /* --------------------- */ + /* Run the pair mappings */ + /* --------------------- */ - for( int i = 0; i < Acr.size(); ++i ) { + for( int i = 0; i < Acr.size(); ++i ) { - for( int j = 0; j < Bcr.size(); ++j ) { + for( int j = 0; j < Bcr.size(); ++j ) { - printf( "\n---- Begin A-%d to B-%d ----\n", - Acr[i].id, Bcr[j].id ); + printf( "\n---- Begin A-%d to B-%d ----\n", + Acr[i].id, Bcr[j].id ); - Thumbs( px, Acr[i], Bcr[j], stdout ); - } - } + Thumbs( px, Acr[i], Bcr[j], stdout ); + } + } - RasterFree( fold_mask_a ); - RasterFree( fold_mask_b ); - } + RasterFree( fold_mask_a ); + RasterFree( fold_mask_b ); + } /* ---- */ /* Done */ /* ---- */ exit: - StopTiming( stdout, "Total", t0 ); - VMStats( stdout ); + StopTiming( stdout, "Total", t0 ); + VMStats( stdout ); - return 0; + return 0; } diff --git a/1_Thumbs/Thumbs_NoCR.cpp b/1_Thumbs/Thumbs_NoCR.cpp index 642bc97..d60d3af 100644 --- a/1_Thumbs/Thumbs_NoCR.cpp +++ b/1_Thumbs/Thumbs_NoCR.cpp @@ -26,64 +26,64 @@ bool Thumbs_NoCR( const PixPair &px, FILE* flog ) /* Handle bypass modes */ /* ------------------- */ - if( GBL.ctx.MODE == 'E' || GBL.ctx.MODE == 'F' ) - return true; + if( GBL.ctx.MODE == 'E' || GBL.ctx.MODE == 'F' ) + return true; /* ------------------- */ /* Handle search modes */ /* ------------------- */ - CThmUtil U( GBL.A, 1, GBL.B, 1, px, - GBL.Tab, GBL.ctx.OLAP2D, flog ); + CThmUtil U( GBL.A, 1, GBL.B, 1, px, + GBL.Tab, GBL.ctx.OLAP2D, flog ); - U.SetParams( - GBL.ctx.HFANGDN, GBL.ctx.HFANGPR, GBL.ctx.RTRSH, - GBL.ctx.OLAP1D, GBL.ctx.MODE, GBL.ctx.LIMXY, - GBL.mch.WTHMPR ); + U.SetParams( + GBL.ctx.HFANGDN, GBL.ctx.HFANGPR, GBL.ctx.RTRSH, + GBL.ctx.OLAP1D, GBL.ctx.MODE, GBL.ctx.LIMXY, + GBL.mch.WTHMPR ); - CThmScan S; - CorRec best; + CThmScan S; + CorRec best; - S.Initialize( flog, best ); - S.SetTdfm( GBL.ctx.Tdfm ); - S.SetRThresh( GBL.ctx.RTRSH ); - S.SetNbMaxHt( GBL.ctx.NBMXHT ); - S.SetSweepConstXY( true ); - S.SetSweepPretweak( GBL.mch.PRETWEAK ); - S.SetUseCorrR( true ); - S.SetDisc( 0, 0, -1, -1 ); + S.Initialize( flog, best ); + S.SetTdfm( GBL.ctx.Tdfm ); + S.SetRThresh( GBL.ctx.RTRSH ); + S.SetNbMaxHt( GBL.ctx.NBMXHT ); + S.SetSweepConstXY( true ); + S.SetSweepPretweak( GBL.mch.PRETWEAK ); + S.SetUseCorrR( true ); + S.SetDisc( 0, 0, -1, -1 ); /* ----------------------- */ /* Create image thumbnails */ /* ----------------------- */ - OlapRec olp; - ThmRec thm; - int nPriorAngles = U.SetStartingAngle( - GBL.ctx.Tdfm, GBL.arg.CTR ); + OlapRec olp; + ThmRec thm; + int nPriorAngles = U.SetStartingAngle( + GBL.ctx.Tdfm, GBL.arg.CTR ); - U.Crop_NoCR( olp, GBL.ctx.XYCONF ); + U.Crop_NoCR( olp, GBL.ctx.XYCONF ); - if( !U.MakeThumbs( thm, olp, GBL.ctx.THMDEC ) ) - return false; + if( !U.MakeThumbs( thm, olp, GBL.ctx.THMDEC ) ) + return false; /* ------ */ /* Search */ /* ------ */ - if( GBL.ctx.MODE == 'N' ) { + if( GBL.ctx.MODE == 'N' ) { - if( !U.Disc( best, S, thm, olp, GBL.mch.PRETWEAK ) ) - return false; - } - else if( !U.Sweep( best, S, thm, nPriorAngles ) ) - return false; + if( !U.Disc( best, S, thm, olp, GBL.mch.PRETWEAK ) ) + return false; + } + else if( !U.Sweep( best, S, thm, nPriorAngles ) ) + return false; /* ------ */ /* Finish */ /* ------ */ - return U.Finish( best, S, thm, olp, GBL.mch.TWEAKS ); + return U.Finish( best, S, thm, olp, GBL.mch.TWEAKS ); } diff --git a/1_Thumbs/makefile b/1_Thumbs/makefile index 74d407e..8114726 100644 --- a/1_Thumbs/makefile +++ b/1_Thumbs/makefile @@ -15,8 +15,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_Tiny/makefile b/1_Tiny/makefile index b2fc722..d36eb86 100644 --- a/1_Tiny/makefile +++ b/1_Tiny/makefile @@ -21,8 +21,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_Tiny/tiny.cpp b/1_Tiny/tiny.cpp index 1fa2a45..0818e62 100644 --- a/1_Tiny/tiny.cpp +++ b/1_Tiny/tiny.cpp @@ -19,39 +19,39 @@ class CArgs_tiny { public: - double fmTOverride; - const char *infile, - *nmrc, - *fm, - *fmd; - int Z, - ID, - D, - minarea; - bool nomasks, - oneregion, - transpose, - dumphist; + double fmTOverride; + const char *infile, + *nmrc, + *fm, + *fmd; + int Z, + ID, + D, + minarea; + bool nomasks, + oneregion, + transpose, + dumphist; public: - CArgs_tiny() - { - fmTOverride = 0.0; - infile = NULL; - nmrc = NULL; - fm = NULL; - fmd = NULL; - Z = -1; - ID = -1; - D = -1; - minarea = 90000; - nomasks = false; - oneregion = false; - transpose = false; - dumphist = false; - }; - - void SetCmdLine( int argc, char* argv[] ); + CArgs_tiny() + { + fmTOverride = 0.0; + infile = NULL; + nmrc = NULL; + fm = NULL; + fmd = NULL; + Z = -1; + ID = -1; + D = -1; + minarea = 90000; + nomasks = false; + oneregion = false; + transpose = false; + dumphist = false; + }; + + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -73,83 +73,83 @@ void CArgs_tiny::SetCmdLine( int argc, char* argv[] ) { // parse command line args - if( argc < 5 ) { - printf( - "Usage: tiny [option]\n" ); - exit( 42 ); - } - - for( int i = 1; i < argc; ++i ) { - - if( argv[i][0] != '-' ) { - - if( Z == -1 ) - Z = atoi( argv[i] ); - else if( ID == -1 ) - ID = atoi( argv[i] ); - else - infile = argv[i]; - } - else if( GetArgStr( nmrc, "-nmrc=", argv[i] ) ) - ; - else if( GetArgStr( fm, "-fm=", argv[i] ) ) - ; - else if( GetArgStr( fmd, "-fmd=", argv[i] ) ) - ; - else if( GetArg( &fmTOverride, "-fmto=%lf", argv[i] ) ) { - - printf( "Fold Mask Threshold overridden, now %f.\n", - fmTOverride ); - } - else if( GetArg( &D, "-D=%d", argv[i] ) ) { - - printf( "Fold radius overridden, now %d.\n", D ); - } - else if( GetArg( &minarea, "-minarea=%d", argv[i] ) ) - ; - else if( IsArg( "-nf", argv[i] ) ) { - - nomasks = true; - printf( "Not generating mask files.\n" ); - } - else if( IsArg( "-one", argv[i] ) ) { - - oneregion = true; - printf( "Using just one region.\n" ); - } - else if( IsArg( "-h", argv[i] ) ) { - - dumphist = true; - printf( "Dumping a histogram.\n" ); - } - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - exit( 42 ); - } - } - - if( nomasks ) { - fm = NULL; - fmd = NULL; - } - else if( !fm && !fmd ) - nomasks = true; + if( argc < 5 ) { + printf( + "Usage: tiny [option]\n" ); + exit( 42 ); + } + + for( int i = 1; i < argc; ++i ) { + + if( argv[i][0] != '-' ) { + + if( Z == -1 ) + Z = atoi( argv[i] ); + else if( ID == -1 ) + ID = atoi( argv[i] ); + else + infile = argv[i]; + } + else if( GetArgStr( nmrc, "-nmrc=", argv[i] ) ) + ; + else if( GetArgStr( fm, "-fm=", argv[i] ) ) + ; + else if( GetArgStr( fmd, "-fmd=", argv[i] ) ) + ; + else if( GetArg( &fmTOverride, "-fmto=%lf", argv[i] ) ) { + + printf( "Fold Mask Threshold overridden, now %f.\n", + fmTOverride ); + } + else if( GetArg( &D, "-D=%d", argv[i] ) ) { + + printf( "Fold radius overridden, now %d.\n", D ); + } + else if( GetArg( &minarea, "-minarea=%d", argv[i] ) ) + ; + else if( IsArg( "-nf", argv[i] ) ) { + + nomasks = true; + printf( "Not generating mask files.\n" ); + } + else if( IsArg( "-one", argv[i] ) ) { + + oneregion = true; + printf( "Using just one region.\n" ); + } + else if( IsArg( "-h", argv[i] ) ) { + + dumphist = true; + printf( "Dumping a histogram.\n" ); + } + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + exit( 42 ); + } + } + + if( nomasks ) { + fm = NULL; + fmd = NULL; + } + else if( !fm && !fmd ) + nomasks = true; // For backwards compatibility, also accept the env. variable - const char *pe = getenv( "FoldMaskThreshold" ); + const char *pe = getenv( "FoldMaskThreshold" ); - if( pe ) { + if( pe ) { - fmTOverride = atof( pe ); + fmTOverride = atof( pe ); - printf( - "Environment variable over-ride of threshold to %f\n", - fmTOverride ); + printf( + "Environment variable over-ride of threshold to %f\n", + fmTOverride ); - printf( - "--- This is obsolete --- Use the -fmto option instead\n" ); - } + printf( + "--- This is obsolete --- Use the -fmto option instead\n" ); + } } /* --------------------------------------------------------------- */ @@ -158,25 +158,25 @@ void CArgs_tiny::SetCmdLine( int argc, char* argv[] ) static void WriteFOLDMAP2Entry( int ncr ) { - CMutex M; - char name[256]; + CMutex M; + char name[256]; - sprintf( name, "fm_%d", gArgs.Z ); + sprintf( name, "fm_%d", gArgs.Z ); - if( M.Get( name ) ) { + if( M.Get( name ) ) { - FILE *f = fopen( "fm.same", "a" ); + FILE *f = fopen( "fm.same", "a" ); - if( f ) { + if( f ) { - fprintf( f, - "FOLDMAP2 %d.%d %d\n", gArgs.Z, gArgs.ID, ncr ); - fflush( f ); - fclose( f ); - } - } + fprintf( f, + "FOLDMAP2 %d.%d %d\n", gArgs.Z, gArgs.ID, ncr ); + fflush( f ); + fclose( f ); + } + } - M.Release(); + M.Release(); } /* --------------------------------------------------------------- */ @@ -187,24 +187,24 @@ static void WriteFOLDMAP2Entry( int ncr ) // static bool SingleValueDominates( const vector &histo ) { - int total = 0, nh = histo.size(); + int total = 0, nh = histo.size(); - for( int i = 0; i < nh; ++i ) - total += histo[i]; + for( int i = 0; i < nh; ++i ) + total += histo[i]; - for( int i = 0; i < nh; ++i ) { + for( int i = 0; i < nh; ++i ) { - if( histo[i] > total/2 ) { + if( histo[i] > total/2 ) { - printf( - "Dominant value %d, %d occurences in %d pixels\n", - i, histo[i], total ); + printf( + "Dominant value %d, %d occurences in %d pixels\n", + i, histo[i], total ); - return true; - } - } + return true; + } + } - return false; + return false; } /* --------------------------------------------------------------- */ @@ -215,108 +215,108 @@ static bool SingleValueDominates( const vector &histo ) // static bool IsTooGaussian( const vector &histo ) { - int nhist = histo.size(); + int nhist = histo.size(); // Mean and std deviation. - MeanStd mh; - double mean, std; - int ndv = 0; // number of different values + MeanStd mh; + double mean, std; + int ndv = 0; // number of different values - for( int i = 0; i < nhist; ++i ) { + for( int i = 0; i < nhist; ++i ) { - mh.Run( i, histo[i] ); - ndv += (histo[i] > 0); - } + mh.Run( i, histo[i] ); + ndv += (histo[i] > 0); + } - mh.Stats( mean, std ); + mh.Stats( mean, std ); - printf( "\nMean %f, std %f, # different values %d\n", - mean, std, ndv ); + printf( "\nMean %f, std %f, # different values %d\n", + mean, std, ndv ); // Unusual case; print them - if( ndv <= 20 ) { + if( ndv <= 20 ) { - for( int i = 0; i < nhist; ++i ) { + for( int i = 0; i < nhist; ++i ) { - if( histo[i] > 0 ) - printf( "[%d %d] ", i, histo[i] ); - } + if( histo[i] > 0 ) + printf( "[%d %d] ", i, histo[i] ); + } - printf( "\n" ); - } + printf( "\n" ); + } // Now do a least squares fit. Should yield little diff, in theory. // Create y array (same data as double); s array (const std dev). - VecDoub x( nhist ), y( nhist ), s( nhist ); - MeanStd orig; + VecDoub x( nhist ), y( nhist ), s( nhist ); + MeanStd orig; - for( int i = 0; i < nhist; ++i ) { + for( int i = 0; i < nhist; ++i ) { - x[i] = i; - y[i] = histo[i]; - s[i] = 1.0; - orig.Element( histo[i] ); - } + x[i] = i; + y[i] = histo[i]; + s[i] = 1.0; + orig.Element( histo[i] ); + } - double omean, ostd; + double omean, ostd; - orig.Stats( omean, ostd ); + orig.Stats( omean, ostd ); - printf( "Histogram values: mean %f rms %f\n", omean, ostd ); + printf( "Histogram values: mean %f rms %f\n", omean, ostd ); // Now try a 1 gaussian fit - VecDoub a( 3 ); - double sum = 0.0; - double cnt = 0; - int ilo = max( 0, int(mean-std) ), - ihi = min( 255, int(mean+std) ); + VecDoub a( 3 ); + double sum = 0.0; + double cnt = 0; + int ilo = max( 0, int(mean-std) ), + ihi = min( 255, int(mean+std) ); - for( int i = ilo; i <= ihi; ++i ) { + for( int i = ilo; i <= ihi; ++i ) { - sum += histo[i]; - ++cnt; + sum += histo[i]; + ++cnt; - printf( "%d ", histo[i] ); - } + printf( "%d ", histo[i] ); + } - printf( "\n" ); - printf( "Boxcar average is %f\n", sum/cnt ); + printf( "\n" ); + printf( "Boxcar average is %f\n", sum/cnt ); - a[0] = 1.5 * sum/cnt; // estimated peak value - a[1] = mean; // where it is - a[2] = std * sqrt( 2 ); // and the divisor term + a[0] = 1.5 * sum/cnt; // estimated peak value + a[1] = mean; // where it is + a[2] = std * sqrt( 2 ); // and the divisor term - printf( "Before fit fit: height %f, loc %f, width %f\n", - a[0], mean, std ); + printf( "Before fit fit: height %f, loc %f, width %f\n", + a[0], mean, std ); - Fitmrq f( x, y, s, a, fgauss ); + Fitmrq f( x, y, s, a, fgauss ); - try { - f.fit(); - } - catch(int) { // if the fitting procedure blows up - return false; // it's safe to assume it's not very gaussian - } + try { + f.fit(); + } + catch(int) { // if the fitting procedure blows up + return false; // it's safe to assume it's not very gaussian + } - printf( "After fit: height %f, loc %f, width %f\n", - f.a[0], f.a[1], f.a[2]/sqrt(2) ); + printf( "After fit: height %f, loc %f, width %f\n", + f.a[0], f.a[1], f.a[2]/sqrt(2) ); // Now look at residuals - MeanStd m; + MeanStd m; - for( int i = 0; i < nhist; ++i ) - m.Element( y[i] - ygauss( x[i], f.a ) ); + for( int i = 0; i < nhist; ++i ) + m.Element( y[i] - ygauss( x[i], f.a ) ); - m.Stats( mean, std ); + m.Stats( mean, std ); - printf( "Residuals: mean %f, RMS about mean %f\n", mean, std ); + printf( "Residuals: mean %f, RMS about mean %f\n", mean, std ); - return std < ostd/8; // a guess + return std < ostd/8; // a guess } /* --------------------------------------------------------------- */ @@ -331,48 +331,48 @@ static bool IsTooGaussian( const vector &histo ) // distribution (narrow). // static void RemoveTooGaussian( - vector &goodp, - const uint8 *raster, - int w, - int h ) + vector &goodp, + const uint8 *raster, + int w, + int h ) { - vector histo( 256 ); + vector histo( 256 ); - const int D = 128; - const int S = 256; + const int D = 128; + const int S = 256; - int ymax = (int)ceil( (double(h) - S) / D ), - xmax = (int)ceil( (double(w) - S) / D ); + int ymax = (int)ceil( (double(h) - S) / D ), + xmax = (int)ceil( (double(w) - S) / D ); - for( int iy = 0; iy <= ymax; ++iy ) { + for( int iy = 0; iy <= ymax; ++iy ) { - int yhi = min( h, iy*D + S ), - ylo = yhi - S; + int yhi = min( h, iy*D + S ), + ylo = yhi - S; - for( int ix = 0; ix <= xmax; ++ix ) { + for( int ix = 0; ix <= xmax; ++ix ) { - int xhi = min( w, ix*D + S ), - xlo = xhi - S; + int xhi = min( w, ix*D + S ), + xlo = xhi - S; - memset( &histo[0], 0, 256*sizeof(int) ); + memset( &histo[0], 0, 256*sizeof(int) ); - for( int jy = ylo; jy < yhi; ++jy ) { + for( int jy = ylo; jy < yhi; ++jy ) { - for( int jx = xlo; jx < xhi; ++jx ) - ++histo[raster[jx + w*jy]]; - } + for( int jx = xlo; jx < xhi; ++jx ) + ++histo[raster[jx + w*jy]]; + } - if( SingleValueDominates( histo ) || - IsTooGaussian( histo ) ) { + if( SingleValueDominates( histo ) || + IsTooGaussian( histo ) ) { - for( int jy = ylo; jy < yhi; ++jy ) { + for( int jy = ylo; jy < yhi; ++jy ) { - for( int jx = xlo; jx < xhi; ++jx ) - goodp[jx + w*jy] = 0; - } - } - } - } + for( int jx = xlo; jx < xhi; ++jx ) + goodp[jx + w*jy] = 0; + } + } + } + } } /* --------------------------------------------------------------- */ @@ -380,36 +380,36 @@ static void RemoveTooGaussian( /* --------------------------------------------------------------- */ static double AccumNonSaturated( - MeanStd &m, - const vector &goodp, - const uint8 *raster, - int np, - int SAT ) + MeanStd &m, + const vector &goodp, + const uint8 *raster, + int np, + int SAT ) { - double fracReal; - int ngood = 0; + double fracReal; + int ngood = 0; - m.Reset(); + m.Reset(); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( goodp[i] ) { + if( goodp[i] ) { - int pix = raster[i]; + int pix = raster[i]; - ++ngood; + ++ngood; - if( pix >= SAT && pix <= 255-SAT ) - m.Element( pix ); - } - } + if( pix >= SAT && pix <= 255-SAT ) + m.Element( pix ); + } + } - fracReal = (double)m.HowMany() / ngood; + fracReal = (double)m.HowMany() / ngood; - printf( "SAT=%d: %d non-sat, %f percent non-sat\n", - SAT, m.HowMany(), fracReal * 100.0 ); + printf( "SAT=%d: %d non-sat, %f percent non-sat\n", + SAT, m.HowMany(), fracReal * 100.0 ); - return fracReal; + return fracReal; } /* --------------------------------------------------------------- */ @@ -419,28 +419,28 @@ static double AccumNonSaturated( // Get stats for pixels within SAT of 0, 255. // static int StatsForNonSaturated( - double &mean, - double &std, - const vector &goodp, - const uint8 *raster, - int w, - int h ) + double &mean, + double &std, + const vector &goodp, + const uint8 *raster, + int w, + int h ) { - MeanStd m; - double fracReal; - int np = w * h, SAT; + MeanStd m; + double fracReal; + int np = w * h, SAT; - fracReal = AccumNonSaturated( m, goodp, raster, np, SAT = 3 ); + fracReal = AccumNonSaturated( m, goodp, raster, np, SAT = 3 ); - if( fracReal < 0.9 ) { - printf( "Saturated image! Retrying with SAT = 1\n"); - AccumNonSaturated( m, goodp, raster, np, SAT = 1 ); - } + if( fracReal < 0.9 ) { + printf( "Saturated image! Retrying with SAT = 1\n"); + AccumNonSaturated( m, goodp, raster, np, SAT = 1 ); + } - m.Stats( mean, std ); - printf( "Non-sat pixels: mean = %f stddev = %f\n", mean, std ); + m.Stats( mean, std ); + printf( "Non-sat pixels: mean = %f stddev = %f\n", mean, std ); - return SAT; + return SAT; } /* --------------------------------------------------------------- */ @@ -455,17 +455,17 @@ static int StatsForNonSaturated( // - Value too close to saturation (within SAT of 0 or 255). // static int StatsForRealPixels ( - double &mean, - double &std, - const uint8 *raster, - int w, - int h ) + double &mean, + double &std, + const uint8 *raster, + int w, + int h ) { - vector goodp( w * h, 1 ); + vector goodp( w * h, 1 ); - RemoveTooGaussian( goodp, raster, w, h ); + RemoveTooGaussian( goodp, raster, w, h ); - return StatsForNonSaturated( mean, std, goodp, raster, w, h ); + return StatsForNonSaturated( mean, std, goodp, raster, w, h ); } /* --------------------------------------------------------------- */ @@ -477,22 +477,22 @@ static int StatsForRealPixels ( // from mean. // static void ZeroWhitePixels( - uint8 *raster, - int np, - double mean, - double std, - int SAT ) + uint8 *raster, + int np, + double mean, + double std, + int SAT ) { - if( mean + 2.5 * std < 255 ) { + if( mean + 2.5 * std < 255 ) { - printf( "Removing white pixels\n" ); + printf( "Removing white pixels\n" ); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( raster[i] > 255 - SAT ) - raster[i] = 0; - } - } + if( raster[i] > 255 - SAT ) + raster[i] = 0; + } + } } /* --------------------------------------------------------------- */ @@ -508,47 +508,47 @@ static void ZeroWhitePixels( // are ignored. // static void SelectThreshAndD( - double &thresh, - int &D, - double mean, - double std, - int SAT ) + double &thresh, + int &D, + double mean, + double std, + int SAT ) { - thresh = 4.0; // try 4 stddevs and shrink as needed - D = 10; + thresh = 4.0; // try 4 stddevs and shrink as needed + D = 10; - if( (SAT-1 - mean) / std > -thresh ) { + if( (SAT-1 - mean) / std > -thresh ) { - // 4 stddevs too wide... - // Set 95% of exact range. + // 4 stddevs too wide... + // Set 95% of exact range. - thresh = 0.95 * (mean - (SAT-1)) / std; + thresh = 0.95 * (mean - (SAT-1)) / std; - printf( "Thresh forced down to %g\n", thresh ); + printf( "Thresh forced down to %g\n", thresh ); - if( thresh < 2.0 ) { + if( thresh < 2.0 ) { - // Black area too expansive -> fragmentation... - // Set as wide as possible, out to value = 0.5 + // Black area too expansive -> fragmentation... + // Set as wide as possible, out to value = 0.5 - thresh = (mean - 0.5) / std; - D = 0; + thresh = (mean - 0.5) / std; + D = 0; - printf( - "Desparate action: Thresh = %g excluding only v = 0...\n" - "...And setting D = 0\n", thresh ); - } - } + printf( + "Desparate action: Thresh = %g excluding only v = 0...\n" + "...And setting D = 0\n", thresh ); + } + } - if( gArgs.fmTOverride != 0 ) { - thresh = gArgs.fmTOverride; - printf( "Explicit override of thresh %g\n", thresh ); - } + if( gArgs.fmTOverride != 0 ) { + thresh = gArgs.fmTOverride; + printf( "Explicit override of thresh %g\n", thresh ); + } - if( gArgs.D > -1 ) { - D = gArgs.D; - printf( "Explicit override of D %d\n", D ); - } + if( gArgs.D > -1 ) { + D = gArgs.D; + printf( "Explicit override of D %d\n", D ); + } } /* --------------------------------------------------------------- */ @@ -560,65 +560,65 @@ static void SelectThreshAndD( // contrast and if low, force those v-pixels below threshold. // static void RemoveLowContrast( - vector &v, - int w, - int h, - double std, - double thresh ) + vector &v, + int w, + int h, + double std, + double thresh ) { - const int D = 32; - const int S = 128; + const int D = 32; + const int S = 128; - vector window( S*S ); - vector remove; + vector window( S*S ); + vector remove; // Evaluate - int ymax = (int)ceil( (double(h) - S) / D ), - xmax = (int)ceil( (double(w) - S) / D ); + int ymax = (int)ceil( (double(h) - S) / D ), + xmax = (int)ceil( (double(w) - S) / D ); - for( int iy = 0; iy <= ymax; ++iy ) { + for( int iy = 0; iy <= ymax; ++iy ) { - int yhi = min( h, iy*D + S ), - ylo = yhi - S; + int yhi = min( h, iy*D + S ), + ylo = yhi - S; - for( int ix = 0; ix <= xmax; ++ix ) { + for( int ix = 0; ix <= xmax; ++ix ) { - int xhi = min( w, ix*D + S ), - xlo = xhi - S; + int xhi = min( w, ix*D + S ), + xlo = xhi - S; - for( int jy = ylo; jy < yhi; ++jy ) { + for( int jy = ylo; jy < yhi; ++jy ) { - memcpy( - &window[S*(jy-ylo)], - &v[xlo + w*jy], - S*sizeof(double) ); - } + memcpy( + &window[S*(jy-ylo)], + &v[xlo + w*jy], + S*sizeof(double) ); + } - if( IsLowContrast( window, std ) ) { + if( IsLowContrast( window, std ) ) { - for( int jy = ylo; jy < yhi; ++jy ) { + for( int jy = ylo; jy < yhi; ++jy ) { - for( int jx = xlo; jx < xhi; ++jx ) - remove.push_back( jx + w*jy ); - } - } - } - } + for( int jx = xlo; jx < xhi; ++jx ) + remove.push_back( jx + w*jy ); + } + } + } + } // Remove - int nr = remove.size(); + int nr = remove.size(); - printf( "Low contrast pixels = %d\n", nr ); + printf( "Low contrast pixels = %d\n", nr ); - if( nr ) { + if( nr ) { - thresh = -thresh - 1.0; + thresh = -thresh - 1.0; - for( int i = 0; i < nr; ++i ) - v[remove[i]] = thresh; - } + for( int i = 0; i < nr; ++i ) + v[remove[i]] = thresh; + } } /* --------------------------------------------------------------- */ @@ -628,45 +628,45 @@ static void RemoveLowContrast( // Remove pixels within radius D of any fold pixel. // static void Widen( - vector &v, - int w, - int h, - double thresh, - int D ) + vector &v, + int w, + int h, + double thresh, + int D ) { - int nr, np = w * h; + int nr, np = w * h; - vector remove; + vector remove; - thresh = -thresh; + thresh = -thresh; - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( v[i] <= thresh ) - remove.push_back( i ); - } + if( v[i] <= thresh ) + remove.push_back( i ); + } - if( nr = remove.size() ) { + if( nr = remove.size() ) { - thresh -= 1.0; + thresh -= 1.0; - for( int ir = 0; ir < nr; ++ir ) { + for( int ir = 0; ir < nr; ++ir ) { - int i = remove[ir], - y = i / w, - x = i - w * y, - ylo = max( 0, y - D ), - yhi = min( h-1, y + D ), - xlo = max( 0, x - D ), - xhi = min( w-1, x + D ); + int i = remove[ir], + y = i / w, + x = i - w * y, + ylo = max( 0, y - D ), + yhi = min( h-1, y + D ), + xlo = max( 0, x - D ), + xhi = min( w-1, x + D ); - for( y = ylo; y <= yhi; ++y ) { + for( y = ylo; y <= yhi; ++y ) { - for( x = xlo; x <= xhi; ++x ) - v[x + w*y] = thresh; - } - } - } + for( x = xlo; x <= xhi; ++x ) + v[x + w*y] = thresh; + } + } + } } /* --------------------------------------------------------------- */ @@ -679,64 +679,64 @@ static void Widen( // Return maximal region id. // static int ImageToFoldMap( - uint8* FoldMask, - const PicBase &pic, - bool remove_low_contrast = false ) + uint8* FoldMask, + const PicBase &pic, + bool remove_low_contrast = false ) { - double mean, std, thresh; - uint8 *raster = pic.raster; - int w = pic.w, - h = pic.h, - npixels = w * h, - SAT, D; + double mean, std, thresh; + uint8 *raster = pic.raster; + int w = pic.w, + h = pic.h, + npixels = w * h, + SAT, D; // Calc fold thresh and width extension D - SAT = StatsForRealPixels( mean, std, raster, w, h ); + SAT = StatsForRealPixels( mean, std, raster, w, h ); - ZeroWhitePixels( raster, npixels, mean, std, SAT ); + ZeroWhitePixels( raster, npixels, mean, std, SAT ); - SelectThreshAndD( thresh, D, mean, std, SAT ); + SelectThreshAndD( thresh, D, mean, std, SAT ); // Make normalized images - vector v(npixels); + vector v(npixels); - for( int i = 0; i < npixels; ++i ) - v[i] = (raster[i] - mean) / std; + for( int i = 0; i < npixels; ++i ) + v[i] = (raster[i] - mean) / std; - vector vorig = v; + vector vorig = v; // Remove low contrast - if( remove_low_contrast ) - RemoveLowContrast( v, w, h, std, thresh ); + if( remove_low_contrast ) + RemoveLowContrast( v, w, h, std, thresh ); // Widen folds - Widen( v, w, h, thresh, D ); + Widen( v, w, h, thresh, D ); // Propagate connected regions - vector cr; + vector cr; - for( int i = 0; i < npixels; ++i ) { + for( int i = 0; i < npixels; ++i ) { - if( v[i] > -thresh ) { + if( v[i] > -thresh ) { - ConnRegion c; - int npts; + ConnRegion c; + int npts; - npts = Propagate( c.pts, v, w, h, i, - -thresh, -thresh - 1.0 ); + npts = Propagate( c.pts, v, w, h, i, + -thresh, -thresh - 1.0 ); - printf( - "ImageToFoldMap: ConnRegion with %d pixels\n", npts ); + printf( + "ImageToFoldMap: ConnRegion with %d pixels\n", npts ); - if( npts > gArgs.minarea ) - cr.push_back( c ); - } - } + if( npts > gArgs.minarea ) + cr.push_back( c ); + } + } // Final accounting @@ -780,78 +780,78 @@ static int ImageToFoldMap( // low contrast cases are few. // static uint8* MakeDrawingMask( - PicBase &pic, - const uint8 *FoldMaskAlign, - int np ) + PicBase &pic, + const uint8 *FoldMaskAlign, + int np ) { // First we generate the drawing mask in pretty much the same way // as the alignment mask, except that low contrast regions are // not removed for the drawing version. - uint8 *FoldMaskDraw = (uint8*)malloc( np ); + uint8 *FoldMaskDraw = (uint8*)malloc( np ); - ImageToFoldMap( FoldMaskDraw, pic, false ); + ImageToFoldMap( FoldMaskDraw, pic, false ); // Next create the mapping from labels in the drawing map to // that label/region in the alignment map with which there is // greatest overlap. - vector map( 256, 0 ); + vector map( 256, 0 ); // Get a mapping for each label value used in the drawing map. // Since region labels are assigned consecutively, as soon as // we advance to a label that isn't used we are done. - int used = true; + int used = true; - for( int drawlabel = 1; drawlabel < 256 && used; ++drawlabel ) { + for( int drawlabel = 1; drawlabel < 256 && used; ++drawlabel ) { - vector alnarea( 256, 0 ); + vector alnarea( 256, 0 ); - used = false; + used = false; - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( FoldMaskDraw[i] == drawlabel ) { - ++alnarea[FoldMaskAlign[i]]; - used = true; - } - } + if( FoldMaskDraw[i] == drawlabel ) { + ++alnarea[FoldMaskAlign[i]]; + used = true; + } + } - if( used ) { + if( used ) { - // Find largest overlapped area, if any. + // Find largest overlapped area, if any. - int max_A = 0; - int max_j = 0; + int max_A = 0; + int max_j = 0; - for( int j = 1; j < 256; ++j ) { + for( int j = 1; j < 256; ++j ) { - if( alnarea[j] > max_A ) { - max_A = alnarea[j]; - max_j = j; - } - } + if( alnarea[j] > max_A ) { + max_A = alnarea[j]; + max_j = j; + } + } - printf( - "Mapping drawing region %d to alignment region %d\n", - drawlabel, max_j ); + printf( + "Mapping drawing region %d to alignment region %d\n", + drawlabel, max_j ); - map[drawlabel] = max_j; - } - } + map[drawlabel] = max_j; + } + } // Now relabel drawing map pixels - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( FoldMaskAlign[i] ) - FoldMaskDraw[i] = FoldMaskAlign[i]; - else if( FoldMaskDraw[i] ) - FoldMaskDraw[i] = map[FoldMaskDraw[i]]; - } + if( FoldMaskAlign[i] ) + FoldMaskDraw[i] = FoldMaskAlign[i]; + else if( FoldMaskDraw[i] ) + FoldMaskDraw[i] = map[FoldMaskDraw[i]]; + } - return FoldMaskDraw; + return FoldMaskDraw; } /* --------------------------------------------------------------- */ @@ -864,73 +864,73 @@ int main( int argc, char **argv ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* -------- */ /* Load src */ /* -------- */ - PicBase p; + PicBase p; - p.LoadOriginal( gArgs.infile, stdout, gArgs.transpose ); + p.LoadOriginal( gArgs.infile, stdout, gArgs.transpose ); /* ---------------- */ /* Save src as nmrc */ /* ---------------- */ - if( strstr( gArgs.infile, ".mrc" ) && gArgs.nmrc ) - Raster8ToPng8( gArgs.nmrc, p.original, p.w, p.h ); + if( strstr( gArgs.infile, ".mrc" ) && gArgs.nmrc ) + Raster8ToPng8( gArgs.nmrc, p.original, p.w, p.h ); /* ------------ */ /* Create masks */ /* ------------ */ - if( gArgs.nomasks ) { - WriteFOLDMAP2Entry( 1 ); - return 0; - } + if( gArgs.nomasks ) { + WriteFOLDMAP2Entry( 1 ); + return 0; + } // Create two different fold masks - one optimized for alignment, // with all low contrast regions removed, and one optimized for // drawing, with regions as big as possible. - int ncr, np = p.w * p.h; - uint8 *FoldMaskAlign = (uint8*)malloc( np ); - uint8 *FoldMaskDraw; + int ncr, np = p.w * p.h; + uint8 *FoldMaskAlign = (uint8*)malloc( np ); + uint8 *FoldMaskDraw; - if( gArgs.oneregion ) { + if( gArgs.oneregion ) { - // Efficiently handle the '-one' option. In this case - // the drawing and alignment masks are identical. + // Efficiently handle the '-one' option. In this case + // the drawing and alignment masks are identical. - ncr = 1; - FoldMaskDraw = FoldMaskAlign; - memset( FoldMaskAlign, 1, np ); - } - else { + ncr = 1; + FoldMaskDraw = FoldMaskAlign; + memset( FoldMaskAlign, 1, np ); + } + else { - // Otherwise, calculate real foldmasks + // Otherwise, calculate real foldmasks - ncr = ImageToFoldMap( FoldMaskAlign, p, true ); + ncr = ImageToFoldMap( FoldMaskAlign, p, true ); - if( gArgs.fmd ) - FoldMaskDraw = MakeDrawingMask( p, FoldMaskAlign, np ); - } + if( gArgs.fmd ) + FoldMaskDraw = MakeDrawingMask( p, FoldMaskAlign, np ); + } /* ------------------------------- */ /* Write masks and FOLDMAP entries */ /* ------------------------------- */ - if( gArgs.fm ) - Raster8ToPng8( gArgs.fm, FoldMaskAlign, p.w, p.h ); + if( gArgs.fm ) + Raster8ToPng8( gArgs.fm, FoldMaskAlign, p.w, p.h ); - if( gArgs.fmd ) - Raster8ToPng8( gArgs.fmd, FoldMaskDraw, p.w, p.h ); + if( gArgs.fmd ) + Raster8ToPng8( gArgs.fmd, FoldMaskDraw, p.w, p.h ); - WriteFOLDMAP2Entry( ncr ); + WriteFOLDMAP2Entry( ncr ); - VMStats( stdout ); - return 0; + VMStats( stdout ); + return 0; } diff --git a/1_Tiny/tiny_billnew.cpp b/1_Tiny/tiny_billnew.cpp index b43cfe8..443aa72 100644 --- a/1_Tiny/tiny_billnew.cpp +++ b/1_Tiny/tiny_billnew.cpp @@ -18,39 +18,39 @@ class CArgs_tiny { public: - double fmTOverride; - const char *infile, - *nmrc, - *fm, - *fmd; - int Z, - ID, - D, - minarea; - bool nomasks, - oneregion, - transpose, - dumphist; + double fmTOverride; + const char *infile, + *nmrc, + *fm, + *fmd; + int Z, + ID, + D, + minarea; + bool nomasks, + oneregion, + transpose, + dumphist; public: - CArgs_tiny() - { - fmTOverride = 0.0; - infile = NULL; - nmrc = NULL; - fm = NULL; - fmd = NULL; - Z = -1; - ID = -1; - D = -1; - minarea = 90000; - nomasks = false; - oneregion = false; - transpose = false; - dumphist = false; - }; - - void SetCmdLine( int argc, char* argv[] ); + CArgs_tiny() + { + fmTOverride = 0.0; + infile = NULL; + nmrc = NULL; + fm = NULL; + fmd = NULL; + Z = -1; + ID = -1; + D = -1; + minarea = 90000; + nomasks = false; + oneregion = false; + transpose = false; + dumphist = false; + }; + + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -72,83 +72,83 @@ void CArgs_tiny::SetCmdLine( int argc, char* argv[] ) { // parse command line args - if( argc < 5 ) { - printf( - "Usage: tiny [option]\n" ); - exit( 42 ); - } - - for( int i = 1; i < argc; ++i ) { - - if( argv[i][0] != '-' ) { - - if( Z == -1 ) - Z = atoi( argv[i] ); - else if( ID == -1 ) - ID = atoi( argv[i] ); - else - infile = argv[i]; - } - else if( GetArgStr( nmrc, "-nmrc=", argv[i] ) ) - ; - else if( GetArgStr( fm, "-fm=", argv[i] ) ) - ; - else if( GetArgStr( fmd, "-fmd=", argv[i] ) ) - ; - else if( GetArg( &fmTOverride, "-fmto=%lf", argv[i] ) ) { - - printf( "Fold Mask Threshold overridden, now %f.\n", - fmTOverride ); - } - else if( GetArg( &D, "-D=%d", argv[i] ) ) { - - printf( "Fold radius overridden, now %d.\n", D ); - } - else if( GetArg( &minarea, "-minarea=%d", argv[i] ) ) - ; - else if( IsArg( "-nf", argv[i] ) ) { - - nomasks = true; - printf( "Not generating mask files.\n" ); - } - else if( IsArg( "-one", argv[i] ) ) { - - oneregion = true; - printf( "Using just one region.\n" ); - } - else if( IsArg( "-h", argv[i] ) ) { - - dumphist = true; - printf( "Dumping a histogram.\n" ); - } - else { - printf( "Did not understand option '%s'.\n", argv[i] ); - exit( 42 ); - } - } - - if( nomasks ) { - fm = NULL; - fmd = NULL; - } - else if( !fm && !fmd ) - nomasks = true; + if( argc < 5 ) { + printf( + "Usage: tiny [option]\n" ); + exit( 42 ); + } + + for( int i = 1; i < argc; ++i ) { + + if( argv[i][0] != '-' ) { + + if( Z == -1 ) + Z = atoi( argv[i] ); + else if( ID == -1 ) + ID = atoi( argv[i] ); + else + infile = argv[i]; + } + else if( GetArgStr( nmrc, "-nmrc=", argv[i] ) ) + ; + else if( GetArgStr( fm, "-fm=", argv[i] ) ) + ; + else if( GetArgStr( fmd, "-fmd=", argv[i] ) ) + ; + else if( GetArg( &fmTOverride, "-fmto=%lf", argv[i] ) ) { + + printf( "Fold Mask Threshold overridden, now %f.\n", + fmTOverride ); + } + else if( GetArg( &D, "-D=%d", argv[i] ) ) { + + printf( "Fold radius overridden, now %d.\n", D ); + } + else if( GetArg( &minarea, "-minarea=%d", argv[i] ) ) + ; + else if( IsArg( "-nf", argv[i] ) ) { + + nomasks = true; + printf( "Not generating mask files.\n" ); + } + else if( IsArg( "-one", argv[i] ) ) { + + oneregion = true; + printf( "Using just one region.\n" ); + } + else if( IsArg( "-h", argv[i] ) ) { + + dumphist = true; + printf( "Dumping a histogram.\n" ); + } + else { + printf( "Did not understand option '%s'.\n", argv[i] ); + exit( 42 ); + } + } + + if( nomasks ) { + fm = NULL; + fmd = NULL; + } + else if( !fm && !fmd ) + nomasks = true; // For backwards compatibility, also accept the env. variable - const char *pe = getenv( "FoldMaskThreshold" ); + const char *pe = getenv( "FoldMaskThreshold" ); - if( pe ) { + if( pe ) { - fmTOverride = atof( pe ); + fmTOverride = atof( pe ); - printf( - "Environment variable over-ride of threshold to %f\n", - fmTOverride ); + printf( + "Environment variable over-ride of threshold to %f\n", + fmTOverride ); - printf( - "--- This is obsolete --- Use the -fmto option instead\n" ); - } + printf( + "--- This is obsolete --- Use the -fmto option instead\n" ); + } } /* --------------------------------------------------------------- */ @@ -157,25 +157,25 @@ void CArgs_tiny::SetCmdLine( int argc, char* argv[] ) static void WriteFOLDMAP2Entry( int ncr ) { - CMutex M; - char name[256]; + CMutex M; + char name[256]; - sprintf( name, "fm_%d", gArgs.Z ); + sprintf( name, "fm_%d", gArgs.Z ); - if( M.Get( name ) ) { + if( M.Get( name ) ) { - FILE *f = fopen( "fm.same", "a" ); + FILE *f = fopen( "fm.same", "a" ); - if( f ) { + if( f ) { - fprintf( f, - "FOLDMAP2 %d.%d %d\n", gArgs.Z, gArgs.ID, ncr ); - fflush( f ); - fclose( f ); - } - } + fprintf( f, + "FOLDMAP2 %d.%d %d\n", gArgs.Z, gArgs.ID, ncr ); + fflush( f ); + fclose( f ); + } + } - M.Release(); + M.Release(); } /* --------------------------------------------------------------- */ @@ -186,24 +186,24 @@ static void WriteFOLDMAP2Entry( int ncr ) // static bool SingleValueDominates( const vector &histo ) { - int total = 0, nh = histo.size(); + int total = 0, nh = histo.size(); - for( int i = 0; i < nh; ++i ) - total += histo[i]; + for( int i = 0; i < nh; ++i ) + total += histo[i]; - for( int i = 0; i < nh; ++i ) { + for( int i = 0; i < nh; ++i ) { - if( histo[i] > total/2 ) { + if( histo[i] > total/2 ) { - printf( - "Dominant value %d, %d occurences in %d pixels\n", - i, histo[i], total ); + printf( + "Dominant value %d, %d occurences in %d pixels\n", + i, histo[i], total ); - return true; - } - } + return true; + } + } - return false; + return false; } /* --------------------------------------------------------------- */ @@ -214,39 +214,39 @@ static bool SingleValueDominates( const vector &histo ) // static bool IsTooGaussian( const vector &histo ) { - int nh = histo.size(); + int nh = histo.size(); // Simple mean and standard deviation (std) - MeanStd mh; - double mean, std; - int ndv = 0; // number of different values + MeanStd mh; + double mean, std; + int ndv = 0; // number of different values - for( int i = 0; i < nh; ++i ) { + for( int i = 0; i < nh; ++i ) { - mh.Run( i, histo[i] ); - ndv += (histo[i] > 0); - } + mh.Run( i, histo[i] ); + ndv += (histo[i] > 0); + } - mh.Stats( mean, std ); + mh.Stats( mean, std ); - printf( "\nMean %f, std %f, # different values %d\n", - mean, std, ndv ); + printf( "\nMean %f, std %f, # different values %d\n", + mean, std, ndv ); // Unusual case; print them - if( ndv <= 20 ) { + if( ndv <= 20 ) { - printf( "Oddly few vals [v n]:" ); + printf( "Oddly few vals [v n]:" ); - for( int i = 0; i < nh; ++i ) { + for( int i = 0; i < nh; ++i ) { - if( histo[i] > 0 ) - printf( " [%d %d]", i, histo[i] ); - } + if( histo[i] > 0 ) + printf( " [%d %d]", i, histo[i] ); + } - printf( "\n" ); - } + printf( "\n" ); + } // Now try a 1 gaussian fit. Mean and std from fit should look // very much like those from the raw data. We'll actually just @@ -258,58 +258,58 @@ static bool IsTooGaussian( const vector &histo ) // (sum) over +- s encloses 68% of that. Therefore, // A ~ sum /[(0.68)*sqrt(2pi)*s] = sum / (1.7*s). - VecDoub x( nh ), y( nh ), s( nh ); - VecDoub a( 3 ); - double sum = 0.0; - int ilo = max( 0, int(mean - std) ), - ihi = min( 255, int(mean + std) ); + VecDoub x( nh ), y( nh ), s( nh ); + VecDoub a( 3 ); + double sum = 0.0; + int ilo = max( 0, int(mean - std) ), + ihi = min( 255, int(mean + std) ); - for( int i = 0; i < nh; ++i ) { - x[i] = i; - y[i] = histo[i]; - s[i] = 1.0; - } + for( int i = 0; i < nh; ++i ) { + x[i] = i; + y[i] = histo[i]; + s[i] = 1.0; + } - for( int i = ilo; i <= ihi; ++i ) - sum += histo[i]; + for( int i = ilo; i <= ihi; ++i ) + sum += histo[i]; - a[0] = sum / (1.7*std); // estimated peak value - a[1] = mean; // where it is - a[2] = std * sqrt( 2 ); // divisor term + a[0] = sum / (1.7*std); // estimated peak value + a[1] = mean; // where it is + a[2] = std * sqrt( 2 ); // divisor term - printf( "Before fit: height %10.4f, loc %f, width %f\n", - a[0], a[1], std ); + printf( "Before fit: height %10.4f, loc %f, width %f\n", + a[0], a[1], std ); - Fitmrq f( x, y, s, a, fgauss ); + Fitmrq f( x, y, s, a, fgauss ); - try { - f.fit(); - } - catch(int) { // if fit blows up - return false; // probably not gaussian - } + try { + f.fit(); + } + catch(int) { // if fit blows up + return false; // probably not gaussian + } - printf( "After fit: height %10.4f, loc %f, width %f\n", - f.a[0], f.a[1], f.a[2]/sqrt(2) ); + printf( "After fit: height %10.4f, loc %f, width %f\n", + f.a[0], f.a[1], f.a[2]/sqrt(2) ); #if 0 // Now look at residuals (what metric applies to these?) - MeanStd m; + MeanStd m; - for( int i = 0; i < nh; ++i ) - m.Element( y[i] - ygauss( x[i], f.a ) ); + for( int i = 0; i < nh; ++i ) + m.Element( y[i] - ygauss( x[i], f.a ) ); - m.Stats( mean, std ); + m.Stats( mean, std ); - printf( "Residuals: mean %f, RMS about mean %f\n", mean, std ); + printf( "Residuals: mean %f, RMS about mean %f\n", mean, std ); #endif // Evaluate std - const double T = 2; // similarity threshold (2) + const double T = 2; // similarity threshold (2) - return (f.a[2] >= a[2] ? f.a[2]/a[2] < T : a[2]/f.a[2] < T); + return (f.a[2] >= a[2] ? f.a[2]/a[2] < T : a[2]/f.a[2] < T); } /* --------------------------------------------------------------- */ @@ -324,48 +324,48 @@ static bool IsTooGaussian( const vector &histo ) // distribution (narrow). // static void RemoveTooGaussian( - vector &goodp, - const uint8 *raster, - int w, - int h ) + vector &goodp, + const uint8 *raster, + int w, + int h ) { - vector histo( 256 ); + vector histo( 256 ); - const int D = 128; - const int S = 256; + const int D = 128; + const int S = 256; - int ymax = (int)ceil( (double(h) - S) / D ), - xmax = (int)ceil( (double(w) - S) / D ); + int ymax = (int)ceil( (double(h) - S) / D ), + xmax = (int)ceil( (double(w) - S) / D ); - for( int iy = 0; iy <= ymax; ++iy ) { + for( int iy = 0; iy <= ymax; ++iy ) { - int yhi = min( h, iy*D + S ), - ylo = yhi - S; + int yhi = min( h, iy*D + S ), + ylo = yhi - S; - for( int ix = 0; ix <= xmax; ++ix ) { + for( int ix = 0; ix <= xmax; ++ix ) { - int xhi = min( w, ix*D + S ), - xlo = xhi - S; + int xhi = min( w, ix*D + S ), + xlo = xhi - S; - memset( &histo[0], 0, 256*sizeof(int) ); + memset( &histo[0], 0, 256*sizeof(int) ); - for( int jy = ylo; jy < yhi; ++jy ) { + for( int jy = ylo; jy < yhi; ++jy ) { - for( int jx = xlo; jx < xhi; ++jx ) - ++histo[raster[jx + w*jy]]; - } + for( int jx = xlo; jx < xhi; ++jx ) + ++histo[raster[jx + w*jy]]; + } - if( SingleValueDominates( histo ) || - IsTooGaussian( histo ) ) { + if( SingleValueDominates( histo ) || + IsTooGaussian( histo ) ) { - for( int jy = ylo; jy < yhi; ++jy ) { + for( int jy = ylo; jy < yhi; ++jy ) { - for( int jx = xlo; jx < xhi; ++jx ) - goodp[jx + w*jy] = 0; - } - } - } - } + for( int jx = xlo; jx < xhi; ++jx ) + goodp[jx + w*jy] = 0; + } + } + } + } } /* --------------------------------------------------------------- */ @@ -373,36 +373,36 @@ static void RemoveTooGaussian( /* --------------------------------------------------------------- */ static double AccumNonSaturated( - MeanStd &m, - const vector &goodp, - const uint8 *raster, - int np, - int SAT ) + MeanStd &m, + const vector &goodp, + const uint8 *raster, + int np, + int SAT ) { - double fracReal; - int ngood = 0; + double fracReal; + int ngood = 0; - m.Reset(); + m.Reset(); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( goodp[i] ) { + if( goodp[i] ) { - int pix = raster[i]; + int pix = raster[i]; - ++ngood; + ++ngood; - if( pix >= SAT && pix <= 255-SAT ) - m.Element( pix ); - } - } + if( pix >= SAT && pix <= 255-SAT ) + m.Element( pix ); + } + } - fracReal = (double)m.HowMany() / ngood; + fracReal = (double)m.HowMany() / ngood; - printf( "SAT=%d: %d non-sat, %f percent non-sat\n", - SAT, m.HowMany(), fracReal * 100.0 ); + printf( "SAT=%d: %d non-sat, %f percent non-sat\n", + SAT, m.HowMany(), fracReal * 100.0 ); - return fracReal; + return fracReal; } /* --------------------------------------------------------------- */ @@ -412,28 +412,28 @@ static double AccumNonSaturated( // Get stats for pixels within SAT of 0, 255. // static int StatsForNonSaturated( - double &mean, - double &std, - const vector &goodp, - const uint8 *raster, - int w, - int h ) + double &mean, + double &std, + const vector &goodp, + const uint8 *raster, + int w, + int h ) { - MeanStd m; - double fracReal; - int np = w * h, SAT; + MeanStd m; + double fracReal; + int np = w * h, SAT; - fracReal = AccumNonSaturated( m, goodp, raster, np, SAT = 3 ); + fracReal = AccumNonSaturated( m, goodp, raster, np, SAT = 3 ); - if( fracReal < 0.9 ) { - printf( "Saturated image! Retrying with SAT = 1\n"); - AccumNonSaturated( m, goodp, raster, np, SAT = 1 ); - } + if( fracReal < 0.9 ) { + printf( "Saturated image! Retrying with SAT = 1\n"); + AccumNonSaturated( m, goodp, raster, np, SAT = 1 ); + } - m.Stats( mean, std ); - printf( "Non-sat pixels: mean = %f stddev = %f\n", mean, std ); + m.Stats( mean, std ); + printf( "Non-sat pixels: mean = %f stddev = %f\n", mean, std ); - return SAT; + return SAT; } /* --------------------------------------------------------------- */ @@ -448,17 +448,17 @@ static int StatsForNonSaturated( // - Value too close to saturation (within SAT of 0 or 255). // static int StatsForRealPixels ( - double &mean, - double &std, - const uint8 *raster, - int w, - int h ) + double &mean, + double &std, + const uint8 *raster, + int w, + int h ) { - vector goodp( w * h, 1 ); + vector goodp( w * h, 1 ); - RemoveTooGaussian( goodp, raster, w, h ); + RemoveTooGaussian( goodp, raster, w, h ); - return StatsForNonSaturated( mean, std, goodp, raster, w, h ); + return StatsForNonSaturated( mean, std, goodp, raster, w, h ); } /* --------------------------------------------------------------- */ @@ -470,22 +470,22 @@ static int StatsForRealPixels ( // from mean. // static void ZeroWhitePixels( - uint8 *raster, - int np, - double mean, - double std, - int SAT ) + uint8 *raster, + int np, + double mean, + double std, + int SAT ) { - if( mean + 2.5 * std < 255 ) { + if( mean + 2.5 * std < 255 ) { - printf( "Removing white pixels\n" ); + printf( "Removing white pixels\n" ); - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( raster[i] > 255 - SAT ) - raster[i] = 0; - } - } + if( raster[i] > 255 - SAT ) + raster[i] = 0; + } + } } /* --------------------------------------------------------------- */ @@ -501,47 +501,47 @@ static void ZeroWhitePixels( // are ignored. // static void SelectThreshAndD( - double &thresh, - int &D, - double mean, - double std, - int SAT ) + double &thresh, + int &D, + double mean, + double std, + int SAT ) { - thresh = 4.0; // try 4 stddevs and shrink as needed - D = 10; + thresh = 4.0; // try 4 stddevs and shrink as needed + D = 10; - if( (SAT-1 - mean) / std > -thresh ) { + if( (SAT-1 - mean) / std > -thresh ) { - // 4 stddevs too wide... - // Set 95% of exact range. + // 4 stddevs too wide... + // Set 95% of exact range. - thresh = 0.95 * (mean - (SAT-1)) / std; + thresh = 0.95 * (mean - (SAT-1)) / std; - printf( "Thresh forced down to %g\n", thresh ); + printf( "Thresh forced down to %g\n", thresh ); - if( thresh < 2.0 ) { + if( thresh < 2.0 ) { - // Black area too expansive -> fragmentation... - // Set as wide as possible, out to value = 0.5 + // Black area too expansive -> fragmentation... + // Set as wide as possible, out to value = 0.5 - thresh = (mean - 0.5) / std; - D = 0; + thresh = (mean - 0.5) / std; + D = 0; - printf( - "Desparate action: Thresh = %g excluding only v = 0...\n" - "...And setting D = 0\n", thresh ); - } - } + printf( + "Desparate action: Thresh = %g excluding only v = 0...\n" + "...And setting D = 0\n", thresh ); + } + } - if( gArgs.fmTOverride != 0 ) { - thresh = gArgs.fmTOverride; - printf( "Explicit override of thresh %g\n", thresh ); - } + if( gArgs.fmTOverride != 0 ) { + thresh = gArgs.fmTOverride; + printf( "Explicit override of thresh %g\n", thresh ); + } - if( gArgs.D > -1 ) { - D = gArgs.D; - printf( "Explicit override of D %d\n", D ); - } + if( gArgs.D > -1 ) { + D = gArgs.D; + printf( "Explicit override of D %d\n", D ); + } } /* --------------------------------------------------------------- */ @@ -553,65 +553,65 @@ static void SelectThreshAndD( // contrast and if low, force those v-pixels below threshold. // static void RemoveLowContrast( - vector &v, - int w, - int h, - double std, - double thresh ) + vector &v, + int w, + int h, + double std, + double thresh ) { - const int D = 32; // 32 - const int S = 128; // 128 + const int D = 32; // 32 + const int S = 128; // 128 - vector window( S*S ); - vector remove; + vector window( S*S ); + vector remove; // Evaluate - int ymax = (int)ceil( (double(h) - S) / D ), - xmax = (int)ceil( (double(w) - S) / D ); + int ymax = (int)ceil( (double(h) - S) / D ), + xmax = (int)ceil( (double(w) - S) / D ); - for( int iy = 0; iy <= ymax; ++iy ) { + for( int iy = 0; iy <= ymax; ++iy ) { - int yhi = min( h, iy*D + S ), - ylo = yhi - S; + int yhi = min( h, iy*D + S ), + ylo = yhi - S; - for( int ix = 0; ix <= xmax; ++ix ) { + for( int ix = 0; ix <= xmax; ++ix ) { - int xhi = min( w, ix*D + S ), - xlo = xhi - S; + int xhi = min( w, ix*D + S ), + xlo = xhi - S; - for( int jy = ylo; jy < yhi; ++jy ) { + for( int jy = ylo; jy < yhi; ++jy ) { - memcpy( - &window[S*(jy-ylo)], - &v[xlo + w*jy], - S*sizeof(double) ); - } + memcpy( + &window[S*(jy-ylo)], + &v[xlo + w*jy], + S*sizeof(double) ); + } - if( IsLowContrast( window, std ) ) { + if( IsLowContrast( window, std ) ) { - for( int jy = ylo; jy < yhi; ++jy ) { + for( int jy = ylo; jy < yhi; ++jy ) { - for( int jx = xlo; jx < xhi; ++jx ) - remove.push_back( jx + w*jy ); - } - } - } - } + for( int jx = xlo; jx < xhi; ++jx ) + remove.push_back( jx + w*jy ); + } + } + } + } // Remove - int nr = remove.size(); + int nr = remove.size(); - printf( "Low contrast pixels = %d\n", nr ); + printf( "Low contrast pixels = %d\n", nr ); - if( nr ) { + if( nr ) { - thresh = -thresh - 1.0; + thresh = -thresh - 1.0; - for( int i = 0; i < nr; ++i ) - v[remove[i]] = thresh; - } + for( int i = 0; i < nr; ++i ) + v[remove[i]] = thresh; + } } /* --------------------------------------------------------------- */ @@ -621,45 +621,45 @@ static void RemoveLowContrast( // Remove pixels within radius D of any fold pixel. // static void Widen( - vector &v, - int w, - int h, - double thresh, - int D ) + vector &v, + int w, + int h, + double thresh, + int D ) { - int nr, np = w * h; + int nr, np = w * h; - vector remove; + vector remove; - thresh = -thresh; + thresh = -thresh; - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( v[i] <= thresh ) - remove.push_back( i ); - } + if( v[i] <= thresh ) + remove.push_back( i ); + } - if( nr = remove.size() ) { + if( nr = remove.size() ) { - thresh -= 1.0; + thresh -= 1.0; - for( int ir = 0; ir < nr; ++ir ) { + for( int ir = 0; ir < nr; ++ir ) { - int i = remove[ir], - y = i / w, - x = i - w * y, - ylo = max( 0, y - D ), - yhi = min( h-1, y + D ), - xlo = max( 0, x - D ), - xhi = min( w-1, x + D ); + int i = remove[ir], + y = i / w, + x = i - w * y, + ylo = max( 0, y - D ), + yhi = min( h-1, y + D ), + xlo = max( 0, x - D ), + xhi = min( w-1, x + D ); - for( y = ylo; y <= yhi; ++y ) { + for( y = ylo; y <= yhi; ++y ) { - for( x = xlo; x <= xhi; ++x ) - v[x + w*y] = thresh; - } - } - } + for( x = xlo; x <= xhi; ++x ) + v[x + w*y] = thresh; + } + } + } } /* --------------------------------------------------------------- */ @@ -672,64 +672,64 @@ static void Widen( // Return maximal region id. // static int ImageToFoldMap( - uint8* FoldMask, - const PicBase &pic, - bool remove_low_contrast = false ) + uint8* FoldMask, + const PicBase &pic, + bool remove_low_contrast = false ) { - double mean, std, thresh; - uint8 *raster = pic.raster; - int w = pic.w, - h = pic.h, - npixels = w * h, - SAT, D; + double mean, std, thresh; + uint8 *raster = pic.raster; + int w = pic.w, + h = pic.h, + npixels = w * h, + SAT, D; // Calc fold thresh and width extension D - SAT = StatsForRealPixels( mean, std, raster, w, h ); + SAT = StatsForRealPixels( mean, std, raster, w, h ); - ZeroWhitePixels( raster, npixels, mean, std, SAT ); + ZeroWhitePixels( raster, npixels, mean, std, SAT ); - SelectThreshAndD( thresh, D, mean, std, SAT ); + SelectThreshAndD( thresh, D, mean, std, SAT ); // Make normalized images - vector v(npixels); + vector v(npixels); - for( int i = 0; i < npixels; ++i ) - v[i] = (raster[i] - mean) / std; + for( int i = 0; i < npixels; ++i ) + v[i] = (raster[i] - mean) / std; - vector vorig = v; + vector vorig = v; // Remove low contrast - if( remove_low_contrast ) - RemoveLowContrast( v, w, h, std, thresh ); + if( remove_low_contrast ) + RemoveLowContrast( v, w, h, std, thresh ); // Widen folds - Widen( v, w, h, thresh, D ); + Widen( v, w, h, thresh, D ); // Propagate connected regions - vector cr; + vector cr; - for( int i = 0; i < npixels; ++i ) { + for( int i = 0; i < npixels; ++i ) { - if( v[i] > -thresh ) { + if( v[i] > -thresh ) { - ConnRegion c; - int npts; + ConnRegion c; + int npts; - npts = Propagate( c.pts, v, w, h, i, - -thresh, -thresh - 1.0 ); + npts = Propagate( c.pts, v, w, h, i, + -thresh, -thresh - 1.0 ); - printf( - "ImageToFoldMap: ConnRegion with %d pixels\n", npts ); + printf( + "ImageToFoldMap: ConnRegion with %d pixels\n", npts ); - if( npts > gArgs.minarea ) - cr.push_back( c ); - } - } + if( npts > gArgs.minarea ) + cr.push_back( c ); + } + } // Final accounting @@ -773,78 +773,78 @@ static int ImageToFoldMap( // low contrast cases are few. // static uint8* MakeDrawingMask( - PicBase &pic, - const uint8 *FoldMaskAlign, - int np ) + PicBase &pic, + const uint8 *FoldMaskAlign, + int np ) { // First we generate the drawing mask in pretty much the same way // as the alignment mask, except that low contrast regions are // not removed for the drawing version. - uint8 *FoldMaskDraw = (uint8*)malloc( np ); + uint8 *FoldMaskDraw = (uint8*)malloc( np ); - ImageToFoldMap( FoldMaskDraw, pic, false ); + ImageToFoldMap( FoldMaskDraw, pic, false ); // Next create the mapping from labels in the drawing map to // that label/region in the alignment map with which there is // greatest overlap. - vector map( 256, 0 ); + vector map( 256, 0 ); // Get a mapping for each label value used in the drawing map. // Since region labels are assigned consecutively, as soon as // we advance to a label that isn't used we are done. - int used = true; + int used = true; - for( int drawlabel = 1; drawlabel < 256 && used; ++drawlabel ) { + for( int drawlabel = 1; drawlabel < 256 && used; ++drawlabel ) { - vector alnarea( 256, 0 ); + vector alnarea( 256, 0 ); - used = false; + used = false; - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( FoldMaskDraw[i] == drawlabel ) { - ++alnarea[FoldMaskAlign[i]]; - used = true; - } - } + if( FoldMaskDraw[i] == drawlabel ) { + ++alnarea[FoldMaskAlign[i]]; + used = true; + } + } - if( used ) { + if( used ) { - // Find largest overlapped area, if any. + // Find largest overlapped area, if any. - int max_A = 0; - int max_j = 0; + int max_A = 0; + int max_j = 0; - for( int j = 1; j < 256; ++j ) { + for( int j = 1; j < 256; ++j ) { - if( alnarea[j] > max_A ) { - max_A = alnarea[j]; - max_j = j; - } - } + if( alnarea[j] > max_A ) { + max_A = alnarea[j]; + max_j = j; + } + } - printf( - "Mapping drawing region %d to alignment region %d\n", - drawlabel, max_j ); + printf( + "Mapping drawing region %d to alignment region %d\n", + drawlabel, max_j ); - map[drawlabel] = max_j; - } - } + map[drawlabel] = max_j; + } + } // Now relabel drawing map pixels - for( int i = 0; i < np; ++i ) { + for( int i = 0; i < np; ++i ) { - if( FoldMaskAlign[i] ) - FoldMaskDraw[i] = FoldMaskAlign[i]; - else if( FoldMaskDraw[i] ) - FoldMaskDraw[i] = map[FoldMaskDraw[i]]; - } + if( FoldMaskAlign[i] ) + FoldMaskDraw[i] = FoldMaskAlign[i]; + else if( FoldMaskDraw[i] ) + FoldMaskDraw[i] = map[FoldMaskDraw[i]]; + } - return FoldMaskDraw; + return FoldMaskDraw; } /* --------------------------------------------------------------- */ @@ -857,72 +857,72 @@ int main( int argc, char **argv ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* -------- */ /* Load src */ /* -------- */ - PicBase p; + PicBase p; - p.LoadOriginal( gArgs.infile, stdout, gArgs.transpose ); + p.LoadOriginal( gArgs.infile, stdout, gArgs.transpose ); /* ---------------- */ /* Save src as nmrc */ /* ---------------- */ - if( strstr( gArgs.infile, ".mrc" ) && gArgs.nmrc ) - Raster8ToPng8( gArgs.nmrc, p.original, p.w, p.h ); + if( strstr( gArgs.infile, ".mrc" ) && gArgs.nmrc ) + Raster8ToPng8( gArgs.nmrc, p.original, p.w, p.h ); /* ------------ */ /* Create masks */ /* ------------ */ - if( gArgs.nomasks ) { - WriteFOLDMAP2Entry( 1 ); - return 0; - } + if( gArgs.nomasks ) { + WriteFOLDMAP2Entry( 1 ); + return 0; + } // Create two different fold masks - one optimized for alignment, // with all low contrast regions removed, and one optimized for // drawing, with regions as big as possible. - int ncr, np = p.w * p.h; - uint8 *FoldMaskAlign = (uint8*)malloc( np ); - uint8 *FoldMaskDraw; + int ncr, np = p.w * p.h; + uint8 *FoldMaskAlign = (uint8*)malloc( np ); + uint8 *FoldMaskDraw; - if( gArgs.oneregion ) { + if( gArgs.oneregion ) { - // Efficiently handle the '-one' option. In this case - // the drawing and alignment masks are identical. + // Efficiently handle the '-one' option. In this case + // the drawing and alignment masks are identical. - ncr = 1; - FoldMaskDraw = FoldMaskAlign; - memset( FoldMaskAlign, 1, np ); - } - else { + ncr = 1; + FoldMaskDraw = FoldMaskAlign; + memset( FoldMaskAlign, 1, np ); + } + else { - // Otherwise, calculate real foldmasks + // Otherwise, calculate real foldmasks - ncr = ImageToFoldMap( FoldMaskAlign, p, true ); + ncr = ImageToFoldMap( FoldMaskAlign, p, true ); - if( gArgs.fmd ) - FoldMaskDraw = MakeDrawingMask( p, FoldMaskAlign, np ); - } + if( gArgs.fmd ) + FoldMaskDraw = MakeDrawingMask( p, FoldMaskAlign, np ); + } /* ------------------------------- */ /* Write masks and FOLDMAP entries */ /* ------------------------------- */ - if( gArgs.fm ) - Raster8ToPng8( gArgs.fm, FoldMaskAlign, p.w, p.h ); + if( gArgs.fm ) + Raster8ToPng8( gArgs.fm, FoldMaskAlign, p.w, p.h ); - if( gArgs.fmd ) - Raster8ToPng8( gArgs.fmd, FoldMaskDraw, p.w, p.h ); + if( gArgs.fmd ) + Raster8ToPng8( gArgs.fmd, FoldMaskDraw, p.w, p.h ); - WriteFOLDMAP2Entry( ncr ); + WriteFOLDMAP2Entry( ncr ); - return 0; + return 0; } diff --git a/1_TopScripts/makefile b/1_TopScripts/makefile index 2dd5c6a..5262db0 100644 --- a/1_TopScripts/makefile +++ b/1_TopScripts/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_TopScripts/topscripts.cpp b/1_TopScripts/topscripts.cpp index 5e721a6..ffa6417 100644 --- a/1_TopScripts/topscripts.cpp +++ b/1_TopScripts/topscripts.cpp @@ -26,23 +26,23 @@ class CArgs_scr { public: - char script[2048], - idb[2048]; - char *infile; - int zmin, - zmax; + char script[2048], + idb[2048]; + char *infile; + int zmin, + zmax; public: - CArgs_scr() - { - script[0] = 0; - idb[0] = 0; - infile = NULL; - zmin = 0; - zmax = 32768; - }; - - void SetCmdLine( int argc, char* argv[] ); + CArgs_scr() + { + script[0] = 0; + idb[0] = 0; + infile = NULL; + zmin = 0; + zmax = 32768; + }; + + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -65,61 +65,61 @@ void CArgs_scr::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "topscripts.log", "w" ); + flog = FileOpenOrDie( "topscripts.log", "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Create top-level scripts: %s ", atime ); + fprintf( flog, "Create top-level scripts: %s ", atime ); // parse command line args - if( argc < 5 ) { - printf( - "Usage: topscripts -script=scriptpath" - " -idb=idbpath -z=i,j.\n" ); - exit( 42 ); - } - - vector vi; - const char *pchar; - - for( int i = 1; i < argc; ++i ) { - - // echo to log - fprintf( flog, "%s ", argv[i] ); - - if( argv[i][0] != '-' ) - infile = argv[i]; - else if( GetArgStr( pchar, "-script=", argv[i] ) ) - DskAbsPath( script, sizeof(script), pchar, flog ); - else if( GetArgStr( pchar, "-idb=", argv[i] ) ) - DskAbsPath( idb, sizeof(idb), pchar, flog ); - else if( GetArgList( vi, "-z=", argv[i] ) ) { - - if( 2 == vi.size() ) { - zmin = vi[0]; - zmax = vi[1]; - } - else { - fprintf( flog, - "Bad format in -z [%s].\n", argv[i] ); - exit( 42 ); - } - } - else { - printf( "Did not understand option [%s].\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n" ); - fflush( flog ); + if( argc < 5 ) { + printf( + "Usage: topscripts -script=scriptpath" + " -idb=idbpath -z=i,j.\n" ); + exit( 42 ); + } + + vector vi; + const char *pchar; + + for( int i = 1; i < argc; ++i ) { + + // echo to log + fprintf( flog, "%s ", argv[i] ); + + if( argv[i][0] != '-' ) + infile = argv[i]; + else if( GetArgStr( pchar, "-script=", argv[i] ) ) + DskAbsPath( script, sizeof(script), pchar, flog ); + else if( GetArgStr( pchar, "-idb=", argv[i] ) ) + DskAbsPath( idb, sizeof(idb), pchar, flog ); + else if( GetArgList( vi, "-z=", argv[i] ) ) { + + if( 2 == vi.size() ) { + zmin = vi[0]; + zmax = vi[1]; + } + else { + fprintf( flog, + "Bad format in -z [%s].\n", argv[i] ); + exit( 42 ); + } + } + else { + printf( "Did not understand option [%s].\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n" ); + fflush( flog ); } /* --------------------------------------------------------------- */ @@ -128,37 +128,37 @@ void CArgs_scr::SetCmdLine( int argc, char* argv[] ) static void Write_dbgo() { - char buf[2048]; - FILE *f; - - sprintf( buf, "dbgo.sht" ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Make image database 'idb' from text 'billfile' or xml file...\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > makeidb inpath -script=scriptpath -idb=idbpath -z=i,j\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Required:\n" ); - fprintf( f, "# inPath\t\t\t\t;mylayout.txt or myxml.xml file\n" ); - fprintf( f, "# -script=scriptpath\t;alignment pipeline params file\n" ); - fprintf( f, "# -idb=idbpath\t\t\t;idb folder to create\n" ); - fprintf( f, "# -z=i,j\t\t\t\t;process layers in range z=[i..j]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# NOTE: Omit -idb parameter to generate RawData.xml.\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "export MRC_TRIM=12\n" ); - fprintf( f, "\n" ); - fprintf( f, "makeidb %s -script=%s -idb=%s -z=%d,%d\n", - gArgs.infile, gArgs.script, gArgs.idb, - gArgs.zmin, gArgs.zmax ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "dbgo.sht" ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Make image database 'idb' from text 'billfile' or xml file...\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > makeidb inpath -script=scriptpath -idb=idbpath -z=i,j\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Required:\n" ); + fprintf( f, "# inPath\t\t\t\t;mylayout.txt or myxml.xml file\n" ); + fprintf( f, "# -script=scriptpath\t;alignment pipeline params file\n" ); + fprintf( f, "# -idb=idbpath\t\t\t;idb folder to create\n" ); + fprintf( f, "# -z=i,j\t\t\t\t;process layers in range z=[i..j]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# NOTE: Omit -idb parameter to generate RawData.xml.\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "export MRC_TRIM=12\n" ); + fprintf( f, "\n" ); + fprintf( f, "makeidb %s -script=%s -idb=%s -z=%d,%d\n", + gArgs.infile, gArgs.script, gArgs.idb, + gArgs.zmin, gArgs.zmax ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -167,41 +167,41 @@ static void Write_dbgo() static void Write_mongo() { - char buf[2048]; - FILE *f; - - sprintf( buf, "mongo.sht" ); - f = FileOpenOrDie( buf, "w", flog ); - - fprintf( f, "#!/bin/sh\n" ); - fprintf( f, "\n" ); - fprintf( f, "# Purpose:\n" ); - fprintf( f, "# Make alignment workspace 'temp' and create scripts within\n" ); - fprintf( f, "# to drive montaging pipeline steps.\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# > makemontages temp -script=scriptpath -idb=idbpath -z=i,j\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Required:\n" ); - fprintf( f, "# temp\t\t\t\t\t;workspace directory to create\n" ); - fprintf( f, "# -script=scriptpath\t;alignment pipeline params file\n" ); - fprintf( f, "# -idb=idbpath\t\t\t;path to idb directory\n" ); - fprintf( f, "# -z=i,j\t\t\t\t;align layers in range z=[i..j]\n" ); - fprintf( f, "#\n" ); - fprintf( f, "# Options:\n" ); - fprintf( f, "# -exe=ptestalt\t\t\t;exe other than 'ptest'\n" ); - fprintf( f, "\n" ); - fprintf( f, "\n" ); - fprintf( f, "wrk=temp0\n" ); - fprintf( f, "\n" ); - fprintf( f, "makemontages $wrk -script=%s -idb=%s -z=%d,%d\n", - gArgs.script, gArgs.idb, - gArgs.zmin, gArgs.zmax ); - fprintf( f, "\n" ); - fprintf( f, "cp prms/* $wrk\n" ); - fprintf( f, "\n" ); - - fclose( f ); - FileScriptPerms( buf ); + char buf[2048]; + FILE *f; + + sprintf( buf, "mongo.sht" ); + f = FileOpenOrDie( buf, "w", flog ); + + fprintf( f, "#!/bin/sh\n" ); + fprintf( f, "\n" ); + fprintf( f, "# Purpose:\n" ); + fprintf( f, "# Make alignment workspace 'temp' and create scripts within\n" ); + fprintf( f, "# to drive montaging pipeline steps.\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# > makemontages temp -script=scriptpath -idb=idbpath -z=i,j\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Required:\n" ); + fprintf( f, "# temp\t\t\t\t\t;workspace directory to create\n" ); + fprintf( f, "# -script=scriptpath\t;alignment pipeline params file\n" ); + fprintf( f, "# -idb=idbpath\t\t\t;path to idb directory\n" ); + fprintf( f, "# -z=i,j\t\t\t\t;align layers in range z=[i..j]\n" ); + fprintf( f, "#\n" ); + fprintf( f, "# Options:\n" ); + fprintf( f, "# -exe=ptestalt\t\t\t;exe other than 'ptest'\n" ); + fprintf( f, "\n" ); + fprintf( f, "\n" ); + fprintf( f, "wrk=temp0\n" ); + fprintf( f, "\n" ); + fprintf( f, "makemontages $wrk -script=%s -idb=%s -z=%d,%d\n", + gArgs.script, gArgs.idb, + gArgs.zmin, gArgs.zmax ); + fprintf( f, "\n" ); + fprintf( f, "cp prms/* $wrk\n" ); + fprintf( f, "\n" ); + + fclose( f ); + FileScriptPerms( buf ); } /* --------------------------------------------------------------- */ @@ -214,23 +214,23 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* ------- */ /* Scripts */ /* ------- */ - Write_dbgo(); - Write_mongo(); + Write_dbgo(); + Write_mongo(); /* ---- */ /* Done */ /* ---- */ - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_ViewSD/ViewSD.cpp b/1_ViewSD/ViewSD.cpp index e410172..c8a19a4 100644 --- a/1_ViewSD/ViewSD.cpp +++ b/1_ViewSD/ViewSD.cpp @@ -30,25 +30,25 @@ using namespace std; class CArgs_xml { public: - char *xmlfile, - *sdfile; - int zmin, - zmax, - sdmin, - sdmax; + char *xmlfile, + *sdfile; + int zmin, + zmax, + sdmin, + sdmax; public: - CArgs_xml() - { - xmlfile = NULL; - sdfile = NULL; - zmin = 0; - zmax = 32768; - sdmin = 0; - sdmax = 0; - }; - - void SetCmdLine( int argc, char* argv[] ); + CArgs_xml() + { + xmlfile = NULL; + sdfile = NULL; + zmin = 0; + zmax = 32768; + sdmin = 0; + sdmax = 0; + }; + + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -73,41 +73,41 @@ void CArgs_xml::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "ViewSD.log", "w" ); + flog = FileOpenOrDie( "ViewSD.log", "w" ); // parse command line args - if( argc < 4 ) { - printf( - "Usage: ViewSD -sd= [options].\n" ); - exit( 42 ); - } - - for( int i = 1; i < argc; ++i ) { - - if( argv[i][0] != '-' ) { - - if( !xmlfile ) - xmlfile = argv[i]; - else - sdfile = argv[i]; - } - else if( GetArg( &zmin, "-zmin=%d", argv[i] ) ) - ; - else if( GetArg( &zmax, "-zmax=%d", argv[i] ) ) - ; - else if( GetArg( &sdmin, "-sdmin=%d", argv[i] ) ) - ; - else if( GetArg( &sdmax, "-sdmax=%d", argv[i] ) ) - ; - else { - printf( "Did not understand option [%s].\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n\n" ); - fflush( flog ); + if( argc < 4 ) { + printf( + "Usage: ViewSD -sd= [options].\n" ); + exit( 42 ); + } + + for( int i = 1; i < argc; ++i ) { + + if( argv[i][0] != '-' ) { + + if( !xmlfile ) + xmlfile = argv[i]; + else + sdfile = argv[i]; + } + else if( GetArg( &zmin, "-zmin=%d", argv[i] ) ) + ; + else if( GetArg( &zmax, "-zmax=%d", argv[i] ) ) + ; + else if( GetArg( &sdmin, "-sdmin=%d", argv[i] ) ) + ; + else if( GetArg( &sdmax, "-sdmax=%d", argv[i] ) ) + ; + else { + printf( "Did not understand option [%s].\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n\n" ); + fflush( flog ); } /* --------------------------------------------------------------- */ @@ -116,25 +116,25 @@ void CArgs_xml::SetCmdLine( int argc, char* argv[] ) static void LoadSD() { - FILE *f = FileOpenOrDie( gArgs.sdfile, "r", flog ); - CLineScan LS; + FILE *f = FileOpenOrDie( gArgs.sdfile, "r", flog ); + CLineScan LS; - for(;;) { + for(;;) { - if( LS.Get( f ) <= 0 ) - break; + if( LS.Get( f ) <= 0 ) + break; - MZID R; - int sd; + MZID R; + int sd; - sscanf( LS.line, "%d\t%d\t%d", &R.z, &R.id, &sd ); + sscanf( LS.line, "%d\t%d\t%d", &R.z, &R.id, &sd ); - Z.insert( R.z ); + Z.insert( R.z ); - M[R] = sd; - } + M[R] = sd; + } - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -143,29 +143,29 @@ static void LoadSD() static void TrimTiles( FILE* fres, TiXmlElement* layer, int z ) { - MZID key; - TiXmlElement* p = layer->FirstChildElement( "t2_patch" ); - TiXmlElement* nextT; + MZID key; + TiXmlElement* p = layer->FirstChildElement( "t2_patch" ); + TiXmlElement* nextT; - key.z = z; + key.z = z; - for( ; p; p = nextT ) { + for( ; p; p = nextT ) { - nextT = p->NextSiblingElement(); + nextT = p->NextSiblingElement(); - key.id = IDFromPatch( p ); + key.id = IDFromPatch( p ); - map::iterator it = M.find( key ); + map::iterator it = M.find( key ); - if( it == M.end() || - it->second < gArgs.sdmin || - it->second > gArgs.sdmax ) { + if( it == M.end() || + it->second < gArgs.sdmin || + it->second > gArgs.sdmax ) { - layer->RemoveChild( p ); - } - else - fprintf( fres, "%d\t%d\n", key.z, key.id ); - } + layer->RemoveChild( p ); + } + else + fprintf( fres, "%d\t%d\n", key.z, key.id ); + } } /* --------------------------------------------------------------- */ @@ -178,44 +178,44 @@ static void Edit() /* Open */ /* ---- */ - XML_TKEM xml( gArgs.xmlfile, flog ); - TiXmlNode* lyrset = xml.GetLayerset(); - TiXmlElement* layer = xml.GetFirstLayer(); + XML_TKEM xml( gArgs.xmlfile, flog ); + TiXmlNode* lyrset = xml.GetLayerset(); + TiXmlElement* layer = xml.GetFirstLayer(); /* --------- */ /* Do layers */ /* --------- */ - TiXmlElement* nextL; - FILE *fres = FileOpenOrDie( "Resin.txt", "w" ); + TiXmlElement* nextL; + FILE *fres = FileOpenOrDie( "Resin.txt", "w" ); - for( ; layer; layer = nextL ) { + for( ; layer; layer = nextL ) { - nextL = layer->NextSiblingElement(); + nextL = layer->NextSiblingElement(); - int z = atoi( layer->Attribute( "z" ) ); + int z = atoi( layer->Attribute( "z" ) ); - if( z > gArgs.zmax || - z < gArgs.zmin || - Z.find( z ) == Z.end() ) { + if( z > gArgs.zmax || + z < gArgs.zmin || + Z.find( z ) == Z.end() ) { - lyrset->RemoveChild( layer ); - continue; - } + lyrset->RemoveChild( layer ); + continue; + } - TrimTiles( fres, layer, z ); + TrimTiles( fres, layer, z ); - if( !layer->FirstChildElement( "t2_patch" ) ) - lyrset->RemoveChild( layer ); - } + if( !layer->FirstChildElement( "t2_patch" ) ) + lyrset->RemoveChild( layer ); + } - fclose( fres ); + fclose( fres ); /* ---- */ /* Save */ /* ---- */ - xml.Save( "xmltmp.txt", true ); + xml.Save( "xmltmp.txt", true ); } /* --------------------------------------------------------------- */ @@ -228,28 +228,28 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* ---------------- */ /* Map (z,id) to sd */ /* ---------------- */ - LoadSD(); + LoadSD(); /* ---- */ /* Edit */ /* ---- */ - Edit(); + Edit(); /* ---- */ /* Done */ /* ---- */ - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; } diff --git a/1_ViewSD/makefile b/1_ViewSD/makefile index afb3101..a1edd58 100644 --- a/1_ViewSD/makefile +++ b/1_ViewSD/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_XView/makefile b/1_XView/makefile index 28db764..89b5b9b 100644 --- a/1_XView/makefile +++ b/1_XView/makefile @@ -11,8 +11,8 @@ objs = ${files:.cpp=.o} all : $(appname) clean : - rm -f *.o + rm -f *.o $(appname) : .CHECK_GENLIB ${objs} - $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) + $(CC) $(LFLAGS) ${objs} $(LINKS_STD) $(OUTPUT) diff --git a/1_XView/xview.cpp b/1_XView/xview.cpp index 13cb7a8..3a5776a 100644 --- a/1_XView/xview.cpp +++ b/1_XView/xview.cpp @@ -27,38 +27,38 @@ using namespace ns_pipergns; class CArgs { public: - string idb; - const char *inpath, - *meta; - double forcew, - forceh, - degcw, - xml_trim; - int zilo, - zihi, - type, // {'T','M','X','B'} - xml_type, - xml_min, - xml_max; + string idb; + const char *inpath, + *meta; + double forcew, + forceh, + degcw, + xml_trim; + int zilo, + zihi, + type, // {'T','M','X','B'} + xml_type, + xml_min, + xml_max; public: - CArgs() - { - inpath = NULL; - meta = NULL; - forcew = 0.0; - forceh = 0.0; - degcw = 0.0; - xml_trim = 0.0; - zilo = 0; - zihi = 32768; - type = 'X'; - xml_type = 0; - xml_min = 0; - xml_max = 0; - }; - - void SetCmdLine( int argc, char* argv[] ); + CArgs() + { + inpath = NULL; + meta = NULL; + forcew = 0.0; + forceh = 0.0; + degcw = 0.0; + xml_trim = 0.0; + zilo = 0; + zihi = 32768; + type = 'X'; + xml_type = 0; + xml_min = 0; + xml_max = 0; + }; + + void SetCmdLine( int argc, char* argv[] ); }; /* --------------------------------------------------------------- */ @@ -69,15 +69,15 @@ class CMeta { // Tool to map paths from idb back to original mrc images. // This is known from the layout meta file we started with. private: - FILE *f; - CLineScan LS; - map mz; + FILE *f; + CLineScan LS; + map mz; public: - CMeta() : f(NULL) {}; - virtual ~CMeta(); - void Init( const char *meta ); - void MapZ( int z ); - const char* Path( const Til2Img* t2i ); + CMeta() : f(NULL) {}; + virtual ~CMeta(); + void Init( const char *meta ); + void MapZ( int z ); + const char* Path( const Til2Img* t2i ); }; /* --------------------------------------------------------------- */ @@ -104,89 +104,89 @@ void CArgs::SetCmdLine( int argc, char* argv[] ) { // start log - flog = FileOpenOrDie( "xview.log", "w" ); + flog = FileOpenOrDie( "xview.log", "w" ); // log start time - time_t t0 = time( NULL ); - char atime[32]; + time_t t0 = time( NULL ); + char atime[32]; - strcpy( atime, ctime( &t0 ) ); - atime[24] = '\0'; // remove the newline + strcpy( atime, ctime( &t0 ) ); + atime[24] = '\0'; // remove the newline - fprintf( flog, "Start: %s ", atime ); + fprintf( flog, "Start: %s ", atime ); // parse command line args - if( argc < 3 ) { - printf( - "Usage: xview inpath -idb=idbpath -z=i,j\n" ); - exit( 42 ); - } - - vector vd; - vector vi; - const char *pchar; - - for( int i = 1; i < argc; ++i ) { - - // echo to log - fprintf( flog, "%s ", argv[i] ); - - if( argv[i][0] != '-' ) { - inpath = argv[i]; - isAff = (NULL != strstr( FileNamePtr( inpath ), "X_A" )); - } - else if( GetArgStr( pchar, "-idb=", argv[i] ) ) - idb = pchar; - else if( GetArgStr( meta, "-meta=", argv[i] ) ) - ; - else if( GetArgList( vd, "-forceWH=", argv[i] ) ) { - - if( 2 == vd.size() ) { - forcew = vd[0]; - forceh = vd[1]; - fprintf( flog, "WH [%f %f]\n", forcew, forceh ); - } - else { - fprintf( flog, - "Bad format in -forceWH [%s].\n", argv[i] ); - exit( 42 ); - } - } - else if( GetArg( °cw, "-degcw=%lf", argv[i] ) ) - ; - else if( GetArg( &type, "-type=%c", argv[i] ) ) - ; - else if( GetArgList( vi, "-z=", argv[i] ) ) { - - if( 2 == vi.size() ) { - zilo = vi[0]; - zihi = vi[1]; - fprintf( flog, "z [%d %d]\n", zilo, zihi ); - } - else { - fprintf( flog, - "Bad format in -z [%s].\n", argv[i] ); - exit( 42 ); - } - } - else if( GetArg( &xml_trim, "-xmltrim=%lf", argv[i] ) ) - ; - else if( GetArg( &xml_type, "-xmltype=%d", argv[i] ) ) - ; - else if( GetArg( &xml_min, "-xmlmin=%d", argv[i] ) ) - ; - else if( GetArg( &xml_max, "-xmlmax=%d", argv[i] ) ) - ; - else { - printf( "Did not understand option [%s].\n", argv[i] ); - exit( 42 ); - } - } - - fprintf( flog, "\n\n" ); - fflush( flog ); + if( argc < 3 ) { + printf( + "Usage: xview inpath -idb=idbpath -z=i,j\n" ); + exit( 42 ); + } + + vector vd; + vector vi; + const char *pchar; + + for( int i = 1; i < argc; ++i ) { + + // echo to log + fprintf( flog, "%s ", argv[i] ); + + if( argv[i][0] != '-' ) { + inpath = argv[i]; + isAff = (NULL != strstr( FileNamePtr( inpath ), "X_A" )); + } + else if( GetArgStr( pchar, "-idb=", argv[i] ) ) + idb = pchar; + else if( GetArgStr( meta, "-meta=", argv[i] ) ) + ; + else if( GetArgList( vd, "-forceWH=", argv[i] ) ) { + + if( 2 == vd.size() ) { + forcew = vd[0]; + forceh = vd[1]; + fprintf( flog, "WH [%f %f]\n", forcew, forceh ); + } + else { + fprintf( flog, + "Bad format in -forceWH [%s].\n", argv[i] ); + exit( 42 ); + } + } + else if( GetArg( °cw, "-degcw=%lf", argv[i] ) ) + ; + else if( GetArg( &type, "-type=%c", argv[i] ) ) + ; + else if( GetArgList( vi, "-z=", argv[i] ) ) { + + if( 2 == vi.size() ) { + zilo = vi[0]; + zihi = vi[1]; + fprintf( flog, "z [%d %d]\n", zilo, zihi ); + } + else { + fprintf( flog, + "Bad format in -z [%s].\n", argv[i] ); + exit( 42 ); + } + } + else if( GetArg( &xml_trim, "-xmltrim=%lf", argv[i] ) ) + ; + else if( GetArg( &xml_type, "-xmltype=%d", argv[i] ) ) + ; + else if( GetArg( &xml_min, "-xmlmin=%d", argv[i] ) ) + ; + else if( GetArg( &xml_max, "-xmlmax=%d", argv[i] ) ) + ; + else { + printf( "Did not understand option [%s].\n", argv[i] ); + exit( 42 ); + } + } + + fprintf( flog, "\n\n" ); + fflush( flog ); } /* --------------------------------------------------------------- */ @@ -197,8 +197,8 @@ void CArgs::SetCmdLine( int argc, char* argv[] ) // CMeta::~CMeta() { - if( f ) - fclose( f ); + if( f ) + fclose( f ); } @@ -208,17 +208,17 @@ void CMeta::Init( const char *meta ) { // Open file - if( !meta ) - return; + if( !meta ) + return; - f = FileOpenOrDie( meta, "r" ); + f = FileOpenOrDie( meta, "r" ); // Cache first line - if( LS.Get( f ) <= 0 ) { - fprintf( flog, "Meta: Empty file [%s].\n", meta ); - exit( 42 ); - } + if( LS.Get( f ) <= 0 ) { + fprintf( flog, "Meta: Empty file [%s].\n", meta ); + exit( 42 ); + } } @@ -228,61 +228,61 @@ void CMeta::Init( const char *meta ) // void CMeta::MapZ( int z ) { - if( !f ) - return; + if( !f ) + return; - mz.clear(); + mz.clear(); // Gone too far? - int linez; + int linez; - sscanf( LS.line, "%d", &linez ); + sscanf( LS.line, "%d", &linez ); - if( linez > z ) { + if( linez > z ) { not_found:; - fprintf( flog, "Meta: Z [%d] not found.\n", z ); - exit( 42 ); - } + fprintf( flog, "Meta: Z [%d] not found.\n", z ); + exit( 42 ); + } // Move up to requested z - while( linez < z ) { + while( linez < z ) { - if( LS.Get( f ) <= 0 ) - goto not_found; + if( LS.Get( f ) <= 0 ) + goto not_found; - sscanf( LS.line, "%d", &linez ); + sscanf( LS.line, "%d", &linez ); - if( linez > z ) - goto not_found; - } + if( linez > z ) + goto not_found; + } // Map lines while this z - char path[2048]; - int id; + char path[2048]; + int id; - do { + do { - // map this line + // map this line - sscanf( LS.line, - "%d%d" - "%*lf%*lf%*lf%*lf%*lf%*lf" - "%*d%*d%*d%s\n", - &linez, &id, path ); + sscanf( LS.line, + "%d%d" + "%*lf%*lf%*lf%*lf%*lf%*lf" + "%*d%*d%*d%s\n", + &linez, &id, path ); - mz[id] = path; + mz[id] = path; - // get next one, or make fake one with huge z + // get next one, or make fake one with huge z - if ( LS.Get( f ) > 0 ) - sscanf( LS.line, "%d", &linez ); - else - sprintf( LS.line, "%d", linez = 0x7FFFFFFF ); + if ( LS.Get( f ) > 0 ) + sscanf( LS.line, "%d", &linez ); + else + sprintf( LS.line, "%d", linez = 0x7FFFFFFF ); - } while( linez == z ); + } while( linez == z ); } @@ -290,20 +290,20 @@ not_found:; // const char* CMeta::Path( const Til2Img* t2i ) { - if( f ) { - - map::iterator it = mz.find( t2i->id ); - - if( it != mz.end() ) - return it->second.c_str(); - else { - fprintf( flog, "Meta: missing line for [%s].\n", - FileNamePtr( t2i->path.c_str() ) ); - exit( 42 ); - } - } - else - return t2i->path.c_str(); + if( f ) { + + map::iterator it = mz.find( t2i->id ); + + if( it != mz.end() ) + return it->second.c_str(); + else { + fprintf( flog, "Meta: missing line for [%s].\n", + FileNamePtr( t2i->path.c_str() ) ); + exit( 42 ); + } + } + else + return t2i->path.c_str(); } /* --------------------------------------------------------------- */ @@ -312,44 +312,44 @@ const char* CMeta::Path( const Til2Img* t2i ) static void GetXY_Aff( DBox &B, const TAffine &Trot ) { - B.L = BIGD; - B.R = -BIGD; - B.B = BIGD; - B.T = -BIGD; + B.L = BIGD; + B.R = -BIGD; + B.B = BIGD; + B.T = -BIGD; - TAffine T; - vector cnr; - Set4Corners( cnr, gW, gH ); + TAffine T; + vector cnr; + Set4Corners( cnr, gW, gH ); - for( int z = gArgs.zilo; z <= gArgs.zihi; ++z ) { + for( int z = gArgs.zilo; z <= gArgs.zihi; ++z ) { - if( !R.Init( gArgs.idb, z, flog ) ) - continue; + if( !R.Init( gArgs.idb, z, flog ) ) + continue; - if( !R.Load( gArgs.inpath ) ) - continue; + if( !R.Load( gArgs.inpath ) ) + continue; - for( int j = 0; j < R.nr; ++j ) { + for( int j = 0; j < R.nr; ++j ) { - if( !FLAG_ISUSED( R.flag[j] ) ) - continue; + if( !FLAG_ISUSED( R.flag[j] ) ) + continue; - vector c( 4 ); - memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); - T = Trot * X_AS_AFF( R.x, j ); - T.Transform( c ); + vector c( 4 ); + memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); + T = Trot * X_AS_AFF( R.x, j ); + T.Transform( c ); - for( int k = 0; k < 4; ++k ) { - B.L = fmin( B.L, c[k].x ); - B.R = fmax( B.R, c[k].x ); - B.B = fmin( B.B, c[k].y ); - B.T = fmax( B.T, c[k].y ); - } - } - } + for( int k = 0; k < 4; ++k ) { + B.L = fmin( B.L, c[k].x ); + B.R = fmax( B.R, c[k].x ); + B.B = fmin( B.B, c[k].y ); + B.T = fmax( B.T, c[k].y ); + } + } + } - B.R = ceil( B.R - B.L + 1 ); - B.T = ceil( B.T - B.B + 1 ); + B.R = ceil( B.R - B.L + 1 ); + B.T = ceil( B.T - B.B + 1 ); } /* --------------------------------------------------------------- */ @@ -358,44 +358,44 @@ static void GetXY_Aff( DBox &B, const TAffine &Trot ) static void GetXY_Hmy( DBox &B, const THmgphy &Trot ) { - B.L = BIGD; - B.R = -BIGD; - B.B = BIGD; - B.T = -BIGD; + B.L = BIGD; + B.R = -BIGD; + B.B = BIGD; + B.T = -BIGD; - THmgphy T; - vector cnr; - Set4Corners( cnr, gW, gH ); + THmgphy T; + vector cnr; + Set4Corners( cnr, gW, gH ); - for( int z = gArgs.zilo; z <= gArgs.zihi; ++z ) { + for( int z = gArgs.zilo; z <= gArgs.zihi; ++z ) { - if( !R.Init( gArgs.idb, z, flog ) ) - continue; + if( !R.Init( gArgs.idb, z, flog ) ) + continue; - if( !R.Load( gArgs.inpath ) ) - continue; + if( !R.Load( gArgs.inpath ) ) + continue; - for( int j = 0; j < R.nr; ++j ) { + for( int j = 0; j < R.nr; ++j ) { - if( !FLAG_ISUSED( R.flag[j] ) ) - continue; + if( !FLAG_ISUSED( R.flag[j] ) ) + continue; - vector c( 4 ); - memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); - T = Trot * X_AS_HMY( R.x, j ); - T.Transform( c ); + vector c( 4 ); + memcpy( &c[0], &cnr[0], 4*sizeof(Point) ); + T = Trot * X_AS_HMY( R.x, j ); + T.Transform( c ); - for( int k = 0; k < 4; ++k ) { - B.L = fmin( B.L, c[k].x ); - B.R = fmax( B.R, c[k].x ); - B.B = fmin( B.B, c[k].y ); - B.T = fmax( B.T, c[k].y ); - } - } - } + for( int k = 0; k < 4; ++k ) { + B.L = fmin( B.L, c[k].x ); + B.R = fmax( B.R, c[k].x ); + B.B = fmin( B.B, c[k].y ); + B.T = fmax( B.T, c[k].y ); + } + } + } - B.R = ceil( B.R - B.L + 1 ); - B.T = ceil( B.T - B.B + 1 ); + B.R = ceil( B.R - B.L + 1 ); + B.T = ceil( B.T - B.B + 1 ); } /* --------------------------------------------------------------- */ @@ -404,16 +404,16 @@ static void GetXY_Hmy( DBox &B, const THmgphy &Trot ) static void Update_Aff( const TAffine &Trot, const DBox &B ) { - for( int j = 0; j < R.nr; ++j ) { + for( int j = 0; j < R.nr; ++j ) { - if( !FLAG_ISUSED( R.flag[j] ) ) - continue; + if( !FLAG_ISUSED( R.flag[j] ) ) + continue; - TAffine& T = X_AS_AFF( R.x, j ); + TAffine& T = X_AS_AFF( R.x, j ); - T = Trot * T; - T.AddXY( -B.L, -B.B ); - } + T = Trot * T; + T.AddXY( -B.L, -B.B ); + } } /* --------------------------------------------------------------- */ @@ -422,17 +422,17 @@ static void Update_Aff( const TAffine &Trot, const DBox &B ) static void Update_Hmy( const THmgphy &Trot, const DBox &B ) { - THmgphy M( 1,0,-B.L, 0,1,-B.B, 0,0 ); + THmgphy M( 1,0,-B.L, 0,1,-B.B, 0,0 ); - for( int j = 0; j < R.nr; ++j ) { + for( int j = 0; j < R.nr; ++j ) { - if( !FLAG_ISUSED( R.flag[j] ) ) - continue; + if( !FLAG_ISUSED( R.flag[j] ) ) + continue; - THmgphy& T = X_AS_HMY( R.x, j ); + THmgphy& T = X_AS_HMY( R.x, j ); - T = M * (Trot * T); - } + T = M * (Trot * T); + } } /* --------------------------------------------------------------- */ @@ -441,41 +441,41 @@ static void Update_Hmy( const THmgphy &Trot, const DBox &B ) static void WriteM_Aff() { - char buf[64]; - sprintf( buf, "X_A_MET/X_A_%d.txt", R.z ); - FILE *f = FileOpenOrDie( buf, "w", flog ); + char buf[64]; + sprintf( buf, "X_A_MET/X_A_%d.txt", R.z ); + FILE *f = FileOpenOrDie( buf, "w", flog ); - map::iterator mi, en = R.m.end(); + map::iterator mi, en = R.m.end(); - for( mi = R.m.begin(); mi != en; ) { + for( mi = R.m.begin(); mi != en; ) { - const Til2Img *t2i; + const Til2Img *t2i; - int id = mi->first, - j0 = mi->second, - jlim = (++mi == en ? R.nr : mi->second); + int id = mi->first, + j0 = mi->second, + jlim = (++mi == en ? R.nr : mi->second); - if( !IDBT2ICacheNGet1( t2i, gArgs.idb, R.z, id, flog ) ) - continue; + if( !IDBT2ICacheNGet1( t2i, gArgs.idb, R.z, id, flog ) ) + continue; - for( int j = j0; j < jlim; ++j ) { + for( int j = j0; j < jlim; ++j ) { - if( !FLAG_ISUSED( R.flag[j] ) ) - continue; + if( !FLAG_ISUSED( R.flag[j] ) ) + continue; - TAffine& T = X_AS_AFF( R.x, j ); + TAffine& T = X_AS_AFF( R.x, j ); - fprintf( f, - "%d\t%d" - "\t%f\t%f\t%f\t%f\t%f\t%f" - "\t%d\t%d\t%d\t%s\n", - id, j - j0 + 1, - T.t[0], T.t[1], T.t[2], T.t[3], T.t[4], T.t[5], - t2i->col, t2i->row, t2i->cam, gMeta.Path( t2i ) ); - } - } + fprintf( f, + "%d\t%d" + "\t%f\t%f\t%f\t%f\t%f\t%f" + "\t%d\t%d\t%d\t%s\n", + id, j - j0 + 1, + T.t[0], T.t[1], T.t[2], T.t[3], T.t[4], T.t[5], + t2i->col, t2i->row, t2i->cam, gMeta.Path( t2i ) ); + } + } - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -484,43 +484,43 @@ static void WriteM_Aff() static void WriteM_Hmy() { - char buf[64]; - sprintf( buf, "X_H_MET/X_H_%d.txt", R.z ); - FILE *f = FileOpenOrDie( buf, "w", flog ); + char buf[64]; + sprintf( buf, "X_H_MET/X_H_%d.txt", R.z ); + FILE *f = FileOpenOrDie( buf, "w", flog ); - map::iterator mi, en = R.m.end(); + map::iterator mi, en = R.m.end(); - for( mi = R.m.begin(); mi != en; ) { + for( mi = R.m.begin(); mi != en; ) { - const Til2Img *t2i; + const Til2Img *t2i; - int id = mi->first, - j0 = mi->second, - jlim = (++mi == en ? R.nr : mi->second); + int id = mi->first, + j0 = mi->second, + jlim = (++mi == en ? R.nr : mi->second); - if( !IDBT2ICacheNGet1( t2i, gArgs.idb, R.z, id, flog ) ) - continue; + if( !IDBT2ICacheNGet1( t2i, gArgs.idb, R.z, id, flog ) ) + continue; - for( int j = j0; j < jlim; ++j ) { + for( int j = j0; j < jlim; ++j ) { - if( !FLAG_ISUSED( R.flag[j] ) ) - continue; + if( !FLAG_ISUSED( R.flag[j] ) ) + continue; - THmgphy& T = X_AS_HMY( R.x, j ); + THmgphy& T = X_AS_HMY( R.x, j ); - fprintf( f, - "%d\t%d" - "\t%f\t%f\t%f\t%f\t%f\t%f\t%.12g\t%.12g" - "\t%d\t%d\t%d\t%s\n", - id, j - j0 + 1, - T.t[0], T.t[1], T.t[2], - T.t[3], T.t[4], T.t[5], - T.t[6], T.t[7], - t2i->col, t2i->row, t2i->cam, gMeta.Path( t2i ) ); - } - } + fprintf( f, + "%d\t%d" + "\t%f\t%f\t%f\t%f\t%f\t%f\t%.12g\t%.12g" + "\t%d\t%d\t%d\t%s\n", + id, j - j0 + 1, + T.t[0], T.t[1], T.t[2], + T.t[3], T.t[4], T.t[5], + T.t[6], T.t[7], + t2i->col, t2i->row, t2i->cam, gMeta.Path( t2i ) ); + } + } - fclose( f ); + fclose( f ); } /* --------------------------------------------------------------- */ @@ -529,37 +529,37 @@ static void WriteM_Hmy() static FILE* WriteXMLHead( int &oid, const DBox &B ) { - FILE *f = FileOpenOrDie( - (isAff ? "Affine.xml" : "Hmgphy.xml"), - "w", flog ); + FILE *f = FileOpenOrDie( + (isAff ? "Affine.xml" : "Hmgphy.xml"), + "w", flog ); - oid = 3; + oid = 3; - fprintf( f, "\n" ); + fprintf( f, "\n" ); - TrakEM2WriteDTD( f ); + TrakEM2WriteDTD( f ); - fprintf( f, "\n" ); + fprintf( f, "\n" ); - fprintf( f, - "\t\n" ); + fprintf( f, + "\t\n" ); - fprintf( f, - "\t\n", - oid++, B.R, B.T ); + fprintf( f, + "\t\n", + oid++, B.R, B.T ); - return f; + return f; } /* --------------------------------------------------------------- */ @@ -568,79 +568,79 @@ static FILE* WriteXMLHead( int &oid, const DBox &B ) static void WriteXMLLyr_Aff( FILE *f, int &oid ) { - map::iterator mi, en = R.m.end(); - int offset = int(2 * gArgs.xml_trim + 0.5); - - fprintf( f, - "\t\t\n", - oid++, R.z ); - - for( mi = R.m.begin(); mi != en; ) { - - const Til2Img *t2i; - - int id = mi->first, - j0 = mi->second, - jlim = (++mi == en ? R.nr : mi->second); - - if( !IDBT2ICacheNGet1( t2i, gArgs.idb, R.z, id, flog ) ) - continue; - - for( int j = j0; j < jlim; ++j ) { - - if( !FLAG_ISUSED( R.flag[j] ) ) - continue; - - char title[128]; - - if( t2i->col != -999 ) { - sprintf( title, "%d.%d-%d_%d.%d.%d", - R.z, id, j - j0 + 1, - t2i->col, t2i->row, t2i->cam ); - } - else - sprintf( title, "%d.%d-%d", R.z, id, j - j0 + 1 ); - - TAffine& T = X_AS_AFF( R.x, j ); - - // fix origin : undo trimming - Point o( gArgs.xml_trim, gArgs.xml_trim ); - T.Transform( o ); - - fprintf( f, - "\t\t\t\n", - gArgs.xml_min, gArgs.xml_max ); - } - else - fprintf( f, "\t\t\t/>\n" ); - } - } - - fprintf( f, "\t\t\n" ); + map::iterator mi, en = R.m.end(); + int offset = int(2 * gArgs.xml_trim + 0.5); + + fprintf( f, + "\t\t\n", + oid++, R.z ); + + for( mi = R.m.begin(); mi != en; ) { + + const Til2Img *t2i; + + int id = mi->first, + j0 = mi->second, + jlim = (++mi == en ? R.nr : mi->second); + + if( !IDBT2ICacheNGet1( t2i, gArgs.idb, R.z, id, flog ) ) + continue; + + for( int j = j0; j < jlim; ++j ) { + + if( !FLAG_ISUSED( R.flag[j] ) ) + continue; + + char title[128]; + + if( t2i->col != -999 ) { + sprintf( title, "%d.%d-%d_%d.%d.%d", + R.z, id, j - j0 + 1, + t2i->col, t2i->row, t2i->cam ); + } + else + sprintf( title, "%d.%d-%d", R.z, id, j - j0 + 1 ); + + TAffine& T = X_AS_AFF( R.x, j ); + + // fix origin : undo trimming + Point o( gArgs.xml_trim, gArgs.xml_trim ); + T.Transform( o ); + + fprintf( f, + "\t\t\t\n", + gArgs.xml_min, gArgs.xml_max ); + } + else + fprintf( f, "\t\t\t/>\n" ); + } + } + + fprintf( f, "\t\t\n" ); } /* --------------------------------------------------------------- */ @@ -649,22 +649,22 @@ static void WriteXMLLyr_Aff( FILE *f, int &oid ) static void TopLeft( Point &o, const THmgphy &T ) { - vector cnr( 4 ); + vector cnr( 4 ); - cnr[0] = Point( gArgs.xml_trim, gArgs.xml_trim ); - cnr[1] = Point( gW-1-gArgs.xml_trim, gArgs.xml_trim ); - cnr[2] = Point( gW-1-gArgs.xml_trim, gH-1-gArgs.xml_trim ); - cnr[3] = Point( gArgs.xml_trim, gH-1-gArgs.xml_trim ); + cnr[0] = Point( gArgs.xml_trim, gArgs.xml_trim ); + cnr[1] = Point( gW-1-gArgs.xml_trim, gArgs.xml_trim ); + cnr[2] = Point( gW-1-gArgs.xml_trim, gH-1-gArgs.xml_trim ); + cnr[3] = Point( gArgs.xml_trim, gH-1-gArgs.xml_trim ); - T.Transform( cnr ); + T.Transform( cnr ); - o.x = BIGD; - o.y = BIGD; + o.x = BIGD; + o.y = BIGD; - for( int k = 0; k < 4; ++k ) { - o.x = fmin( o.x, cnr[k].x ); - o.y = fmin( o.y, cnr[k].y ); - } + for( int k = 0; k < 4; ++k ) { + o.x = fmin( o.x, cnr[k].x ); + o.y = fmin( o.y, cnr[k].y ); + } } /* --------------------------------------------------------------- */ @@ -673,88 +673,88 @@ static void TopLeft( Point &o, const THmgphy &T ) static void WriteXMLLyr_Hmy( FILE *f, int &oid ) { - map::iterator mi, en = R.m.end(); - int offset = int(2 * gArgs.xml_trim + 0.5); - - fprintf( f, - "\t\t\n", - oid++, R.z ); - - for( mi = R.m.begin(); mi != en; ) { - - const Til2Img *t2i; - - int id = mi->first, - j0 = mi->second, - jlim = (++mi == en ? R.nr : mi->second); - - if( !IDBT2ICacheNGet1( t2i, gArgs.idb, R.z, id, flog ) ) - continue; - - for( int j = j0; j < jlim; ++j ) { - - if( !FLAG_ISUSED( R.flag[j] ) ) - continue; - - char title[128]; - - if( t2i->col != -999 ) { - sprintf( title, "%d.%d-%d_%d.%d.%d", - R.z, id, j - j0 + 1, - t2i->col, t2i->row, t2i->cam ); - } - else - sprintf( title, "%d.%d-%d", R.z, id, j - j0 + 1 ); - - THmgphy& T = X_AS_HMY( R.x, j ); - - // fix origin : undo trimming - Point o; - TopLeft( o, T ); - - fprintf( f, - "\t\t\t\n", - gArgs.xml_min, gArgs.xml_max ); - } - else - fprintf( f, "\t\t\t>\n" ); - - fprintf( f, - "\t\t\t\t\n" - "\t\t\t\n", - T.t[0], T.t[1], T.t[2], - T.t[3], T.t[4], T.t[5], - T.t[6], T.t[7] ); - } - } - - fprintf( f, "\t\t\n" ); + map::iterator mi, en = R.m.end(); + int offset = int(2 * gArgs.xml_trim + 0.5); + + fprintf( f, + "\t\t\n", + oid++, R.z ); + + for( mi = R.m.begin(); mi != en; ) { + + const Til2Img *t2i; + + int id = mi->first, + j0 = mi->second, + jlim = (++mi == en ? R.nr : mi->second); + + if( !IDBT2ICacheNGet1( t2i, gArgs.idb, R.z, id, flog ) ) + continue; + + for( int j = j0; j < jlim; ++j ) { + + if( !FLAG_ISUSED( R.flag[j] ) ) + continue; + + char title[128]; + + if( t2i->col != -999 ) { + sprintf( title, "%d.%d-%d_%d.%d.%d", + R.z, id, j - j0 + 1, + t2i->col, t2i->row, t2i->cam ); + } + else + sprintf( title, "%d.%d-%d", R.z, id, j - j0 + 1 ); + + THmgphy& T = X_AS_HMY( R.x, j ); + + // fix origin : undo trimming + Point o; + TopLeft( o, T ); + + fprintf( f, + "\t\t\t\n", + gArgs.xml_min, gArgs.xml_max ); + } + else + fprintf( f, "\t\t\t>\n" ); + + fprintf( f, + "\t\t\t\t\n" + "\t\t\t\n", + T.t[0], T.t[1], T.t[2], + T.t[3], T.t[4], T.t[5], + T.t[6], T.t[7] ); + } + } + + fprintf( f, "\t\t\n" ); } /* --------------------------------------------------------------- */ @@ -763,13 +763,13 @@ static void WriteXMLLyr_Hmy( FILE *f, int &oid ) static FILE* WriteXMLTail( FILE *f ) { - if( f ) { - fprintf( f, "\t\n" ); - fprintf( f, "\n" ); - fclose( f ); - } + if( f ) { + fprintf( f, "\t\n" ); + fprintf( f, "\n" ); + fclose( f ); + } - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -778,11 +778,11 @@ static FILE* WriteXMLTail( FILE *f ) static FILE* WriteBillHead() { - FILE *f = FileOpenOrDie( - (isAff ? "billfile_Affine.txt" : "billfile_Hmgphy.txt"), - "w", flog ); + FILE *f = FileOpenOrDie( + (isAff ? "billfile_Affine.txt" : "billfile_Hmgphy.txt"), + "w", flog ); - return f; + return f; } /* --------------------------------------------------------------- */ @@ -791,35 +791,35 @@ static FILE* WriteBillHead() static void WriteBillLyr_Aff( FILE *f ) { - map::iterator mi, en = R.m.end(); + map::iterator mi, en = R.m.end(); - for( mi = R.m.begin(); mi != en; ) { + for( mi = R.m.begin(); mi != en; ) { - const Til2Img *t2i; + const Til2Img *t2i; - int id = mi->first, - j0 = mi->second, - jlim = (++mi == en ? R.nr : mi->second); + int id = mi->first, + j0 = mi->second, + jlim = (++mi == en ? R.nr : mi->second); - if( !IDBT2ICacheNGet1( t2i, gArgs.idb, R.z, id, flog ) ) - continue; + if( !IDBT2ICacheNGet1( t2i, gArgs.idb, R.z, id, flog ) ) + continue; - for( int j = j0; j < jlim; ++j ) { + for( int j = j0; j < jlim; ++j ) { - if( !FLAG_ISUSED( R.flag[j] ) ) - continue; + if( !FLAG_ISUSED( R.flag[j] ) ) + continue; - TAffine& T = X_AS_AFF( R.x, j ); + TAffine& T = X_AS_AFF( R.x, j ); - fprintf( f, - "%d\t%d\t%d" - "\t%f\t%f\t%f\t%f\t%f\t%f" - "\t%d\t%d\t%d\t%s\n", - R.z, id, j - j0 + 1, - T.t[0], T.t[1], T.t[2], T.t[3], T.t[4], T.t[5], - t2i->col, t2i->row, t2i->cam, gMeta.Path( t2i ) ); - } - } + fprintf( f, + "%d\t%d\t%d" + "\t%f\t%f\t%f\t%f\t%f\t%f" + "\t%d\t%d\t%d\t%s\n", + R.z, id, j - j0 + 1, + T.t[0], T.t[1], T.t[2], T.t[3], T.t[4], T.t[5], + t2i->col, t2i->row, t2i->cam, gMeta.Path( t2i ) ); + } + } } /* --------------------------------------------------------------- */ @@ -828,37 +828,37 @@ static void WriteBillLyr_Aff( FILE *f ) static void WriteBillLyr_Hmy( FILE *f ) { - map::iterator mi, en = R.m.end(); + map::iterator mi, en = R.m.end(); - for( mi = R.m.begin(); mi != en; ) { + for( mi = R.m.begin(); mi != en; ) { - const Til2Img *t2i; + const Til2Img *t2i; - int id = mi->first, - j0 = mi->second, - jlim = (++mi == en ? R.nr : mi->second); + int id = mi->first, + j0 = mi->second, + jlim = (++mi == en ? R.nr : mi->second); - if( !IDBT2ICacheNGet1( t2i, gArgs.idb, R.z, id, flog ) ) - continue; + if( !IDBT2ICacheNGet1( t2i, gArgs.idb, R.z, id, flog ) ) + continue; - for( int j = j0; j < jlim; ++j ) { + for( int j = j0; j < jlim; ++j ) { - if( !FLAG_ISUSED( R.flag[j] ) ) - continue; + if( !FLAG_ISUSED( R.flag[j] ) ) + continue; - THmgphy& T = X_AS_HMY( R.x, j ); + THmgphy& T = X_AS_HMY( R.x, j ); - fprintf( f, - "%d\t%d\t%d" - "\t%f\t%f\t%f\t%f\t%f\t%f\t%.12g\t%.12g" - "\t%d\t%d\t%d\t%s\n", - R.z, id, j - j0 + 1, - T.t[0], T.t[1], T.t[2], - T.t[3], T.t[4], T.t[5], - T.t[6], T.t[7], - t2i->col, t2i->row, t2i->cam, gMeta.Path( t2i ) ); - } - } + fprintf( f, + "%d\t%d\t%d" + "\t%f\t%f\t%f\t%f\t%f\t%f\t%.12g\t%.12g" + "\t%d\t%d\t%d\t%s\n", + R.z, id, j - j0 + 1, + T.t[0], T.t[1], T.t[2], + T.t[3], T.t[4], T.t[5], + T.t[6], T.t[7], + t2i->col, t2i->row, t2i->cam, gMeta.Path( t2i ) ); + } + } } /* --------------------------------------------------------------- */ @@ -867,10 +867,10 @@ static void WriteBillLyr_Hmy( FILE *f ) static FILE* WriteBillTail( FILE *f ) { - if( f ) - fclose( f ); + if( f ) + fclose( f ); - return NULL; + return NULL; } /* --------------------------------------------------------------- */ @@ -879,60 +879,60 @@ static FILE* WriteBillTail( FILE *f ) static void ConvertA() { - TAffine Trot; - DBox B; - FILE *fout = NULL; - int oid; - - if( gArgs.forcew ) { - B.L = 0; - B.B = 0; - B.R = gArgs.forcew; - B.T = gArgs.forceh; - } - else if( gArgs.degcw || gArgs.type == 'X' ) { - Trot.NUSetRot( gArgs.degcw * PI/180.0 ); - GetXY_Aff( B, Trot ); - } - - if( gArgs.type == 'T' ) - DskCreateDir( "X_A_TXT", flog ); - else if( gArgs.type == 'M' ) - DskCreateDir( "X_A_MET", flog ); - else if( gArgs.type == 'X' ) - fout = WriteXMLHead( oid, B ); - else if( gArgs.type == 'B' ) - fout = WriteBillHead(); - - for( int z = gArgs.zilo; z <= gArgs.zihi; ++z ) { - - if( !R.Init( gArgs.idb, z, flog ) ) - continue; - - if( !R.Load( gArgs.inpath ) ) - continue; - - gMeta.MapZ( z ); - - if( gArgs.forcew ) - ; - else if( gArgs.degcw || gArgs.type == 'X' ) - Update_Aff( Trot, B ); - - if( gArgs.type == 'T' ) - R.SaveTXT( "X_A_TXT" ); - else if( gArgs.type == 'M' ) - WriteM_Aff(); - else if( gArgs.type == 'X' ) - WriteXMLLyr_Aff( fout, oid ); - else if( gArgs.type == 'B' ) - WriteBillLyr_Aff( fout ); - } - - if( gArgs.type == 'X' ) - fout = WriteXMLTail( fout ); - else if( gArgs.type == 'B' ) - fout = WriteBillTail( fout ); + TAffine Trot; + DBox B; + FILE *fout = NULL; + int oid; + + if( gArgs.forcew ) { + B.L = 0; + B.B = 0; + B.R = gArgs.forcew; + B.T = gArgs.forceh; + } + else if( gArgs.degcw || gArgs.type == 'X' ) { + Trot.NUSetRot( gArgs.degcw * PI/180.0 ); + GetXY_Aff( B, Trot ); + } + + if( gArgs.type == 'T' ) + DskCreateDir( "X_A_TXT", flog ); + else if( gArgs.type == 'M' ) + DskCreateDir( "X_A_MET", flog ); + else if( gArgs.type == 'X' ) + fout = WriteXMLHead( oid, B ); + else if( gArgs.type == 'B' ) + fout = WriteBillHead(); + + for( int z = gArgs.zilo; z <= gArgs.zihi; ++z ) { + + if( !R.Init( gArgs.idb, z, flog ) ) + continue; + + if( !R.Load( gArgs.inpath ) ) + continue; + + gMeta.MapZ( z ); + + if( gArgs.forcew ) + ; + else if( gArgs.degcw || gArgs.type == 'X' ) + Update_Aff( Trot, B ); + + if( gArgs.type == 'T' ) + R.SaveTXT( "X_A_TXT" ); + else if( gArgs.type == 'M' ) + WriteM_Aff(); + else if( gArgs.type == 'X' ) + WriteXMLLyr_Aff( fout, oid ); + else if( gArgs.type == 'B' ) + WriteBillLyr_Aff( fout ); + } + + if( gArgs.type == 'X' ) + fout = WriteXMLTail( fout ); + else if( gArgs.type == 'B' ) + fout = WriteBillTail( fout ); } /* --------------------------------------------------------------- */ @@ -941,60 +941,60 @@ static void ConvertA() static void ConvertH() { - THmgphy Trot; - DBox B; - FILE *fout = NULL; - int oid; - - if( gArgs.forcew ) { - B.L = 0; - B.B = 0; - B.R = gArgs.forcew; - B.T = gArgs.forceh; - } - else if( gArgs.degcw || gArgs.type == 'X' ) { - Trot.NUSetRot( gArgs.degcw * PI/180.0 ); - GetXY_Hmy( B, Trot ); - } - - if( gArgs.type == 'T' ) - DskCreateDir( "X_H_TXT", flog ); - else if( gArgs.type == 'M' ) - DskCreateDir( "X_H_MET", flog ); - else if( gArgs.type == 'X' ) - fout = WriteXMLHead( oid, B ); - else if( gArgs.type == 'B' ) - fout = WriteBillHead(); - - for( int z = gArgs.zilo; z <= gArgs.zihi; ++z ) { - - if( !R.Init( gArgs.idb, z, flog ) ) - continue; - - if( !R.Load( gArgs.inpath ) ) - continue; - - gMeta.MapZ( z ); - - if( gArgs.forcew ) - ; - else if( gArgs.degcw || gArgs.type == 'X' ) - Update_Hmy( Trot, B ); - - if( gArgs.type == 'T' ) - R.SaveTXT( "X_H_TXT" ); - else if( gArgs.type == 'M' ) - WriteM_Hmy(); - else if( gArgs.type == 'X' ) - WriteXMLLyr_Hmy( fout, oid ); - else if( gArgs.type == 'B' ) - WriteBillLyr_Hmy( fout ); - } - - if( gArgs.type == 'X' ) - fout = WriteXMLTail( fout ); - else if( gArgs.type == 'B' ) - fout = WriteBillTail( fout ); + THmgphy Trot; + DBox B; + FILE *fout = NULL; + int oid; + + if( gArgs.forcew ) { + B.L = 0; + B.B = 0; + B.R = gArgs.forcew; + B.T = gArgs.forceh; + } + else if( gArgs.degcw || gArgs.type == 'X' ) { + Trot.NUSetRot( gArgs.degcw * PI/180.0 ); + GetXY_Hmy( B, Trot ); + } + + if( gArgs.type == 'T' ) + DskCreateDir( "X_H_TXT", flog ); + else if( gArgs.type == 'M' ) + DskCreateDir( "X_H_MET", flog ); + else if( gArgs.type == 'X' ) + fout = WriteXMLHead( oid, B ); + else if( gArgs.type == 'B' ) + fout = WriteBillHead(); + + for( int z = gArgs.zilo; z <= gArgs.zihi; ++z ) { + + if( !R.Init( gArgs.idb, z, flog ) ) + continue; + + if( !R.Load( gArgs.inpath ) ) + continue; + + gMeta.MapZ( z ); + + if( gArgs.forcew ) + ; + else if( gArgs.degcw || gArgs.type == 'X' ) + Update_Hmy( Trot, B ); + + if( gArgs.type == 'T' ) + R.SaveTXT( "X_H_TXT" ); + else if( gArgs.type == 'M' ) + WriteM_Hmy(); + else if( gArgs.type == 'X' ) + WriteXMLLyr_Hmy( fout, oid ); + else if( gArgs.type == 'B' ) + WriteBillLyr_Hmy( fout ); + } + + if( gArgs.type == 'X' ) + fout = WriteXMLTail( fout ); + else if( gArgs.type == 'B' ) + fout = WriteBillTail( fout ); } /* --------------------------------------------------------------- */ @@ -1007,34 +1007,34 @@ int main( int argc, char* argv[] ) /* Parse command line */ /* ------------------ */ - gArgs.SetCmdLine( argc, argv ); + gArgs.SetCmdLine( argc, argv ); /* ------- */ /* Convert */ /* ------- */ - clock_t t0 = StartTiming(); + clock_t t0 = StartTiming(); - if( !IDBGetImageDims( gW, gH, gArgs.idb, flog ) ) - exit( 42 ); + if( !IDBGetImageDims( gW, gH, gArgs.idb, flog ) ) + exit( 42 ); - gMeta.Init( gArgs.meta ); + gMeta.Init( gArgs.meta ); - if( isAff ) - ConvertA(); - else - ConvertH(); + if( isAff ) + ConvertA(); + else + ConvertH(); - StopTiming( flog, "Convert", t0 ); + StopTiming( flog, "Convert", t0 ); /* ---- */ /* Done */ /* ---- */ - fprintf( flog, "\n" ); - fclose( flog ); + fprintf( flog, "\n" ); + fclose( flog ); - return 0; + return 0; }