diff --git a/.travis.yml b/.travis.yml index 31052a75d..94181484b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -228,7 +228,9 @@ before_install: # Use Travis' currently checked-out SIRF commit ID to build. # Also no point re-downloading SIRF - just use local URL. # N.B.: don't put into build matrix to allow caching. - - BUILD_FLAGS="$BUILD_FLAGS -DPYVER=$PYMVER -DSIRF_URL=$PWD -DSIRF_TAG=$TRAVIS_COMMIT" + # Force ALEXJAZZ008008 repo + # Force TOF branch + - BUILD_FLAGS="$BUILD_FLAGS -DPYVER=$PYMVER -DSIRF_URL=https://github.com/ALEXJAZZ008008/SIRF.git -DSIRF_TAG=tof" # get SuperBuild - cd .. - git clone https://github.com/CCPPETMR/SIRF-SuperBuild --recursive -b master diff --git a/data b/data index f3c4280ef..cd139a1c6 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit f3c4280ef5d9bfc864339848d6a3ef9f93c59267 +Subproject commit cd139a1c69fafb0b2126495d8716c0ee3e38c9dd diff --git a/src/xSTIR/cSTIR/cstir.cpp b/src/xSTIR/cSTIR/cstir.cpp index 92c91db13..b82a885ca 100644 --- a/src/xSTIR/cSTIR/cstir.cpp +++ b/src/xSTIR/cSTIR/cstir.cpp @@ -585,16 +585,20 @@ void* cSTIR_acquisitionDataFromScannerInfo extern "C" void* cSTIR_getAcquisitionDataDimensions(const void* ptr_acq, size_t ptr_dim) { - try { - int* dim = (int*)ptr_dim; - SPTR_FROM_HANDLE(PETAcquisitionData, sptr_ad, ptr_acq); - dim[0] = sptr_ad->get_num_tangential_poss(); - dim[1] = sptr_ad->get_num_views(); - dim[2] = sptr_ad->get_num_sinograms(); - dim[3] = sptr_ad->get_num_TOF_bins(); - return (void*)new DataHandle; - } - CATCH; + try + { + int* dim = (int*) ptr_dim; + + SPTR_FROM_HANDLE(PETAcquisitionData, sptr_ad, ptr_acq); + + dim[0] = sptr_ad->get_num_tangential_poss(); + dim[1] = sptr_ad->get_num_views(); + dim[2] = sptr_ad->get_num_sinograms(); + dim[3] = sptr_ad->get_num_TOF_bins(); + + return (void*) new DataHandle; + } + CATCH; } extern "C" @@ -1160,4 +1164,4 @@ extern "C" void* parameter(const void* ptr, const char* obj, const char* name) { return cSTIR_parameter(ptr, obj, name); -} \ No newline at end of file +} diff --git a/src/xSTIR/cSTIR/cstir_p.cpp b/src/xSTIR/cSTIR/cstir_p.cpp index 96541811f..10a69a699 100644 --- a/src/xSTIR/cSTIR/cstir_p.cpp +++ b/src/xSTIR/cSTIR/cstir_p.cpp @@ -587,6 +587,10 @@ sirf::cSTIR_setOSMAPOSLParameter objectFromHandle >(hp); if (boost::iequals(name, "MAP_model")) recon.set_MAP_model(charDataFromDataHandle(hv)); + if (boost::iequals(name, "set_maximum_relative_change")) + recon.set_maximum_relative_change(dataFromHandle((void*)hv)); + if (boost::iequals(name, "set_minimum_relative_change")) + recon.set_minimum_relative_change(dataFromHandle((void*)hv)); else return parameterNotFound(name, __FILE__, __LINE__); return new DataHandle; diff --git a/src/xSTIR/cSTIR/include/sirf/STIR/stir_data_containers.h b/src/xSTIR/cSTIR/include/sirf/STIR/stir_data_containers.h index b972c2c4a..c5105d103 100644 --- a/src/xSTIR/cSTIR/include/sirf/STIR/stir_data_containers.h +++ b/src/xSTIR/cSTIR/include/sirf/STIR/stir_data_containers.h @@ -241,7 +241,7 @@ namespace sirf { } int get_num_TOF_bins() { - return 1; + return data()->get_num_tof_poss(); } int get_max_segment_num() const { diff --git a/src/xSTIR/cSTIR/stir_data_containers.cpp b/src/xSTIR/cSTIR/stir_data_containers.cpp index d107099a8..24c2ab91e 100644 --- a/src/xSTIR/cSTIR/stir_data_containers.cpp +++ b/src/xSTIR/cSTIR/stir_data_containers.cpp @@ -33,26 +33,33 @@ using namespace sirf; std::string PETAcquisitionData::_storage_scheme; shared_ptr PETAcquisitionData::_template; -float -PETAcquisitionData::norm() const +float PETAcquisitionData::norm() const { double t = 0.0; + for (int s = 0; s <= get_max_segment_num(); ++s) { SegmentBySinogram seg = get_segment_by_sinogram(s); SegmentBySinogram::full_iterator seg_iter; - for (seg_iter = seg.begin_all(); seg_iter != seg.end_all();) { + + for (seg_iter = seg.begin_all(); seg_iter != seg.end_all();) + { double r = *seg_iter++; t += r*r; } - if (s != 0) { + + if (s != 0) + { seg = get_segment_by_sinogram(-s); - for (seg_iter = seg.begin_all(); seg_iter != seg.end_all();) { + + for (seg_iter = seg.begin_all(); seg_iter != seg.end_all();) + { double r = *seg_iter++; t += r*r; } } } + return sqrt((float)t); } diff --git a/src/xSTIR/pSTIR/STIR.py b/src/xSTIR/pSTIR/STIR.py index 2b2f19238..97d491341 100644 --- a/src/xSTIR/pSTIR/STIR.py +++ b/src/xSTIR/pSTIR/STIR.py @@ -785,18 +785,26 @@ def rebin(self, num_segments_to_combine, \ max_in_segment_num_to_process) check_status(ad.handle) return ad - def show(self, sino = None, title = None): + + + def show(self, sino = None, tof=0, title = None): '''Displays interactively selected sinograms.''' assert self.handle is not None + if not HAVE_PYLAB: print('pylab not found') + return + data = self.as_array() nz = data.shape[0] + if type(sino) == type(1): if sino < 0 or sino >= nz: return - show_2D_array('sinogram %d' % sino, data[0,sino,:,:]) + + show_2D_array('sinogram %d' % sino, data[tof,sino,:,:]) + return elif sino is None: ns = nz @@ -806,21 +814,28 @@ def show(self, sino = None, title = None): ns = len(sino) except: raise error('wrong sinograms list') + if title is None: title = 'Selected sinograms' - if ns >= 16: - tiles = (4, 4) - else: - tiles = None + + #if ns >= 16: + #tiles = (4, 4) + #else: + #tiles = None + f = 0 + while f < ns: t = min(f + 16, ns) - err = show_3D_array(data[0,:,:,:], \ - index = sino[f : t], tile_shape = tiles, \ - label = 'sinogram', \ - xlabel = 'tang.pos', ylabel = 'view', \ - suptitle = title, show = (t == ns)) + + #err = show_3D_array(data[0,:,:,:], \ + # index = sino[f : t], tile_shape = tiles, \ + # label = 'sinogram', \ + # xlabel = 'tang.pos', ylabel = 'view', \ + # suptitle = title, show = (t == ns)) + f = t + def allocate(self, value=0, **kwargs): '''Alias to get_uniform_copy @@ -840,6 +855,7 @@ def allocate(self, value=0, **kwargs): else: out = self.get_uniform_copy(value) return out + ## print('Please enter sinogram numbers (e.g.: 0, 3-5)') ## print('(a value outside the range 0 to %d will stop this loop)' % \ ## (nz - 1)) @@ -857,6 +873,7 @@ def allocate(self, value=0, **kwargs): ## ' the loop') ## break + DataContainer.register(AcquisitionData) class ListmodeToSinograms(object): @@ -1987,15 +2004,21 @@ def __init__(self, filename = ''): def __del__(self): if self.handle is not None: pyiutil.deleteDataHandle(self.handle) -## def set_MAP_model(self, model): -## parms.set_char_par\ -## (self.handle, self.name, 'MAP_model', model) -## def get_objective_function(self): -## obj_fun = PoissonLogLikelihoodWithLinearModelForMean() -## obj_fun.handle = pystir.cSTIR_parameter\ -## (self.handle, self.name, 'objective_function') -## check_status(obj_fun.handle) -## return obj_fun + def set_MAP_model(self, model): + parms.set_char_par\ + (self.handle, self.name, 'MAP_model', model) + def set_maximum_relative_change(self, value): + parms.set_float_par\ + (self.handle, self.name, 'set_maximum_relative_change', value) + def set_minimum_relative_change(self, value): + parms.set_float_par\ + (self.handle, self.name, 'set_minimum_relative_change', value) + def get_objective_function(self): + obj_fun = PoissonLogLikelihoodWithLinearModelForMean() + obj_fun.handle = pystir.cSTIR_parameter\ + (self.handle, self.name, 'objective_function') + check_status(obj_fun.handle) + return obj_fun class KOSMAPOSLReconstructor(IterativeReconstructor): '''