From ad244f07b0f46bbbad3bd23d096097794ef0666e Mon Sep 17 00:00:00 2001 From: Bryan Marfito Date: Wed, 1 Sep 2021 07:36:17 +0800 Subject: [PATCH] Proposed changes to UnwrapComp CMakeLists.txt, unwrapComponents.py and relaxIVdriver.cpp (#324) * Updated CMakeLists.txt * Update relaxIVdriver.cpp * Update unwrapComponents.py * Fix the paths on lines 445 and 446 * Fixed paths on lines 445 and 446 --- contrib/UnwrapComp/CMakeLists.txt | 19 ++++++- contrib/UnwrapComp/src/relaxIVdriver.cpp | 71 +++++++++++++++++++++++- contrib/UnwrapComp/unwrapComponents.py | 6 +- 3 files changed, 87 insertions(+), 9 deletions(-) diff --git a/contrib/UnwrapComp/CMakeLists.txt b/contrib/UnwrapComp/CMakeLists.txt index a821300..c5e6458 100644 --- a/contrib/UnwrapComp/CMakeLists.txt +++ b/contrib/UnwrapComp/CMakeLists.txt @@ -1,7 +1,20 @@ -# TODO check for RelaxIV - -InstallSameDir( +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/RelaxIV) + Python_add_library(unwcomp MODULE + bindings/unwcompmodule.cpp + src/RelaxIV/RelaxIV.C + src/relaxIVdriver.cpp + ) + target_include_directories(unwcomp PUBLIC include) + InstallSameDir( + __init__.py + phaseUnwrap.py + unwrapComponents.py + unwcomp + ) +else() + InstallSameDir( __init__.py phaseUnwrap.py unwrapComponents.py ) +endif() diff --git a/contrib/UnwrapComp/src/relaxIVdriver.cpp b/contrib/UnwrapComp/src/relaxIVdriver.cpp index 9f9803b..a0821e8 100644 --- a/contrib/UnwrapComp/src/relaxIVdriver.cpp +++ b/contrib/UnwrapComp/src/relaxIVdriver.cpp @@ -2,7 +2,7 @@ #include #include #include -#include + using namespace MCFClass_di_unipi_it; @@ -13,7 +13,72 @@ inline T ABS( const T x ) } using namespace std; -extern void SetParam( MCFClass *mcf ); +//extern void SetParam( MCFClass *mcf ); + +template +static inline void str2val( const char* const str , T &sthg ) +{ + istringstream( str ) >> sthg; + } + +/*--------------------------------------------------------------------------*/ +// This function skips comment line in a input stream, where comment line is +// // marked by an initial '#' character +// +void SkipComments( ifstream &iParam , string &buf ) + { + do { + iParam >> ws; + getline( iParam , buf ); + } + while( buf[ 0 ] == '#' ); + } + + + + +void SetParam( MCFClass *mcf ) +{ + ifstream iParam( "config.txt" ); + if( ! iParam.is_open() ) + return; + + string buf; + int num; + SkipComments( iParam , buf ); + str2val( buf.c_str(), num ); // get number of int parameters + + for( int i = 0 ; i < num ; i++ ) { // read all int parameters + int param , val; + + SkipComments( iParam , buf ); + str2val( buf.c_str(), param ); // parameter name + + SkipComments( iParam , buf ); + str2val( buf.c_str(), val ); // parameter value + + mcf->SetPar( param , val ); + + } // end( for( i ) ) + + SkipComments( iParam , buf ); + str2val( buf.c_str() , num ); // get number of double parameters + + for( int i = 0 ; i < num ; i++ ) { // read all double parameters + int param; + double val; + SkipComments( iParam , buf ); + str2val( buf.c_str(), param ); // parameter name + + SkipComments( iParam , buf ); + str2val( buf.c_str() , val ); // parameter value + + mcf->SetPar( param , val ); + + } // end( for( i ) ) + } // end( SetParam ) + + vector driver(char *fileName) { ifstream iFile(fileName); @@ -30,7 +95,7 @@ vector driver(char *fileName) // load the network - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cout << "Loading Network :" << fileName << endl; + cout << "Loading Network: " << fileName << endl; mcf->LoadDMX( iFile ); // set "reasonable" values for the epsilons, if any - - - - - - - - - - - - diff --git a/contrib/UnwrapComp/unwrapComponents.py b/contrib/UnwrapComp/unwrapComponents.py index 272a7b5..a1bf967 100755 --- a/contrib/UnwrapComp/unwrapComponents.py +++ b/contrib/UnwrapComp/unwrapComponents.py @@ -327,7 +327,7 @@ band names = {{component (Band 1) }} dst_ds.SetGeoTransform( self.cc_ds.GetGeoTransform() ) dst_ds.SetProjection( self.cc_ds.GetProjectionRef() ) dstband = dst_ds.GetRasterBand(1) - print('Estimating neighbors of component : %d'%(compNumber)) + print('Estimating neighbors of component: %d'%(compNumber)) gdal.ComputeProximity(self.ccband, dstband, options, callback = gdal.TermProgress) width = self.cc_ds.RasterXSize @@ -442,6 +442,6 @@ if __name__ == "__main__": import isceobj unw = UnwrapComponents() - unw.setInpFile('/Users/subrahma/proj/isce/data/filt_topophase.unw.xml') - unw.setConnCompFile('/Users/subrahma/proj/isce/data/filt_topophase.unw.conncomp.xml') + unw.setInpFile(inpFile) + unw.setConnCompFile(ccFile) unw.unwrapComponents()