/* Cause us to be subscribed to the given publisher (if any) and not to any other publisher. */ void reset(publisher_t *pub = NULL) { if (publisher) { mutex_assertion_t::acq_t acq(&publisher->mutex); publisher->subscriptions.remove(this); } publisher = pub; if (publisher) { mutex_assertion_t::acq_t acq(&publisher->mutex); publisher->subscriptions.push_back(this); } }
ZRef<Callable_PullSuggested> Searcher_DatonSet::GetCallable_PullSuggested() { ZAcqMtxR acq(fMtxR); if (not fCallable_PullSuggested_Self) fCallable_PullSuggested_Self = sCallable(sWeakRef(this), &Searcher_DatonSet::pPullSuggested); return fCallable_PullSuggested_Self; }
void push(const T &value) { write_message_t wm; // Despite that we are serializing this *to disk*, disk backed queues are not // intended to persist across restarts, so using // `cluster_version_t::LATEST_OVERALL` is safe. serialize<cluster_version_t::LATEST_OVERALL>(&wm, value); mutex_t::acq_t acq(&push_mutex); items_in_queue++; if (disk_queue.has()) { disk_queue->push(wm); // Check if we need to restart the copy coroutine that may have exited while we pushed if (restart_copy_coro) { restart_copy_coro = false; coro_t::spawn_sometime(std::bind( &disk_backed_queue_wrapper_t<T>::copy_from_disk_queue_to_memory_queue, this, auto_drainer_t::lock_t(&drainer))); } } else { if (memory_queue_free_space <= 0) { disk_queue.init(new internal_disk_backed_queue_t( io_backender, filename, stats_parent)); disk_queue->push(wm); coro_t::spawn_sometime(std::bind( &disk_backed_queue_wrapper_t<T>::copy_from_disk_queue_to_memory_queue, this, auto_drainer_t::lock_t(&drainer))); } else { memory_queue.emplace_back(std::move(wm)); available_control.set_available(true); } } }
void Searcher::SetCallable_SearcherResultsAvailable( ZRef<Callable_SearcherResultsAvailable> iCallable) { ZAcqMtx acq(fMtx); fCalled_SearcherResultsAvailable.Reset(); fCallable_SearcherResultsAvailable = iCallable; }
void Relater_Asyncify::ModifyRegistrations( const AddedQuery* iAdded, size_t iAddedCount, const int64* iRemoved, size_t iRemovedCount) { ZAcqMtxR acq(fMtxR); while (iAddedCount--) { if (ZLOGPF(s, eDebug + 1)) s << "Add: " << iAdded->GetRefcon(); sInsertMust(fPendingAdds, iAdded->GetRefcon(), iAdded->GetRel()); ++iAdded; } while (iRemovedCount--) { const int64 theRefcon = *iRemoved++; if (ZLOGPF(s, eDebug + 1)) s << "Remove: " << theRefcon; if (not sQErase(fPendingAdds, theRefcon)) sInsertMust(fPendingRemoves, theRefcon); if (sQErase(fPendingResults, theRefcon)) { // Not sure if this is actually an issue. ZLOGTRACE(eDebug); } } this->pTrigger_Update(); }
void ZServer::Start(ZRef<ZCaller> iCaller, ZRef<ZStreamerRWFactory> iFactory, ZRef<Callable_Connection> iCallable_Connection) { ZAssert(iCaller); ZAssert(iFactory); // Declared before the acq, so it goes out of scope after it, and any // callable on the roster is invoked with our mutex released. ZRef<ZRoster> priorRoster; ZAcqMtx acq(fMtx); ZAssert(not fWorker); ZAssert(not fFactory); ZAssert(not fCallable_Connection); priorRoster = fRoster; fRoster = new ZRoster; fFactory = iFactory; fCallable_Connection = iCallable_Connection; fWorker = new ZWorker( sCallable(sWeakRef(this), &ZServer::pWork), sCallable(sWeakRef(this), &ZServer::pWorkDetached)); fWorker->Attach(iCaller); fWorker->Wake(); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if(nrhs < 1) mexErrMsgTxt("At least one input argument is required."); if (nlhs > 1) mexErrMsgTxt("Too many output arguments."); btk::MergeAcquisitionFilter::Pointer merger = btk::MergeAcquisitionFilter::New(); std::vector<btk::Acquisition::Pointer> acq(nrhs); for (int i = 0 ; i < nrhs ; ++i) merger->SetInput(i, btk_MOH_get_object<btk::Acquisition>(prhs[i])); // Redirection of the btk::Logger::Warning stream. btk::MEXWarnLogToWarnMsgTxt warnRedir = btk::MEXWarnLogToWarnMsgTxt("btk:MergeAcquisitions"); merger->Update(); plhs[0] = btk_MOH_create_handle(merger->GetOutput()); #if defined(__APPLE__) || (defined(BTK_BUILD_SHARED_LIBS) && defined(__unix__)) // It seems to be related only to Linux with shared libraries // This fix was only tested with Matlab r2009a (7.8) // FIXME: This solution clear all the acquisitions and not only the ones // created from this function mexAtExit(btk::MEXHandleCollector<btk::Acquisition>::ManualClear); #endif };
void push(const T &value) { mutex_t::acq_t acq(&push_mutex); items_in_queue++; if (disk_queue.has()) { disk_queue->push(value); // Check if we need to restart the copy coroutine that may have exited while we pushed if (restart_copy_coro) { restart_copy_coro = false; coro_t::spawn_sometime(std::bind( &disk_backed_queue_wrapper_t<T>::copy_from_disk_queue_to_memory_queue, this, auto_drainer_t::lock_t(&drainer))); } } else { if (memory_queue.full()) { disk_queue.init(new disk_backed_queue_t<T>(io_backender, filename, stats_parent)); disk_queue->push(value); coro_t::spawn_sometime(std::bind( &disk_backed_queue_wrapper_t<T>::copy_from_disk_queue_to_memory_queue, this, auto_drainer_t::lock_t(&drainer))); } else { memory_queue.push_back(value); available_control.set_available(true); } } }
~StartOnNewThreadHandler() { ZAcqMtx acq(fMtx); fKeepRunning = false; fCnd.Broadcast(); while (fActiveThreads) fCnd.WaitFor(fMtx, 7); }
void publish(const callable_t &callable) { mutex_assertion_t::acq_t acq(&publisher.mutex); for (typename publisher_t<subscriber_t>::subscription_t *sub = publisher.subscriptions.head(); sub; sub = publisher.subscriptions.next(sub)) { /* `callable()` should not block */ ASSERT_FINITE_CORO_WAITING; callable(sub->subscriber); } }
void ZServer::Stop() { ZAcqMtx acq(fMtx); if (ZRef<ZStreamerRWFactory> theFactory = fFactory) { fFactory.Clear(); theFactory->Cancel(); } fCallable_Connection.Clear(); fCnd.Broadcast(); }
void Relater_Asyncify::CollectResults(vector<QueryResult>& oChanged) { ZAcqMtxR acq(fMtxR); Relater::pCalled_RelaterCollectResults(); oChanged.reserve(fPendingResults.size()); foreachi (iter, fPendingResults) { // May need to filter entries on our fPendingRemoves list. oChanged.push_back(iter->second); }
void reset(signal_t *s = nullptr) { if (s) { mutex_assertion_t::acq_t acq(&s->lock); if (s->is_pulsed()) { subs.subscriber->run(); } else { subs.reset(s->publisher_controller.get_publisher()); } } else { subs.reset(nullptr); } }
ZQ<void> Worker::QCall() { ZAcqMtx acq(fMtx); for (;;) { fWorking = ZThread::sID(); fNextWake = kDistantFuture; ZRelMtx rel(fMtx); ZQ<bool> result; try { result = fCallable_Work->QCall(this); } catch (...) {} ZAcqMtx acq(fMtx); fWorking = 0; if (result && *result) { if (fNextWake < kDistantFuture) { if (fNextWake <= Time::sSystem()) continue; sNextStartAt(fNextWake, Job(fStarter, this)); } return notnull; } fStarter.Clear(); fCnd.Broadcast(); ZRelMtx rel2(fMtx); try { sCall(fCallable_Detached, this); } catch (...) {} return null; } }
void RunLoop() { ZAcqMtx acq(fMtx); double expires = Time::sSystem() + 10; for (;;) { if (fQueue.empty()) { ZThread::sSetName("SONT idle"); if (not fKeepRunning) { fCnd.Broadcast(); break; } else if (Time::sSystem() > expires) { break; } ++fIdleThreads; fCnd.WaitFor(fMtx, 5); --fIdleThreads; } else { ZThread::sSetName("SONT call"); ZRef<Callable<void()>> theCallable = fQueue.front(); fQueue.pop_front(); try { ZRelMtx acq(fMtx); theCallable->QCall(); } catch (...) {} } } --fActiveThreads; }
void Worker::pWakeAt(double iSystemTime) { ZAcqMtx acq(fMtx); if (fStarter) { if (fWorking) { if (fNextWake > iSystemTime) fNextWake = iSystemTime; } else { sNextStartAt(iSystemTime, Job(fStarter, this)); } } }
void ZServer::StopWait() { ZAcqMtx acq(fMtx); if (ZRef<ZStreamerRWFactory> theFactory = fFactory) { fFactory.Clear(); theFactory->Cancel(); } if (fWorker) { fWorker->Wake(); while (fWorker) fCnd.Wait(fMtx); } }
void Start(const ZRef<Callable<void()>>& iCallable) { ZAcqMtx acq(fMtx); fQueue.push_back(iCallable); if (fIdleThreads < fQueue.size()) { ++fActiveThreads; for (int xx = 0; /*no test*/; ++xx) { try { ZThread::sStartRaw(0, (ZThread::ProcRaw_t)spRunLoop, this); if (xx != 0) { if (ZLOGF(w, eErr)) w << "ZThread::sStartRaw succeeded after " << xx << " additional tries."; } break; } catch (std::exception& ex) { if (xx == 0) { if (ZLOGF(w, eErr)) { w << "Exception: " << ex.what() << "\n"; Util_Debug::sWriteBacktrace(w); } } else { ZThread::sSleep(0.01); } } } } else { fCnd.Broadcast(); } }
void ZStreamRWCon_SSL_Win::Imp_SendDisconnect() { ZAcqMtx acq(fMtx_W); if (not fSendOpen) return; fSendOpen = false; SecBuffer outSB[1]; outSB[0].cbBuffer = 0; outSB[0].pvBuffer = nullptr; outSB[0].BufferType= SECBUFFER_TOKEN; SecBufferDesc outSBD; outSBD.cBuffers = 1; outSBD.pBuffers = outSB; outSBD.ulVersion = SECBUFFER_VERSION; DWORD attributes; SECURITY_STATUS scRet = spPSFT->InitializeSecurityContextA( &fCredHandle, &fCtxtHandle, nullptr, spRequirements, 0, // Reserved1 SECURITY_NATIVE_DREP, nullptr, 0, // Reserved2 nullptr, &outSBD, &attributes, nullptr); if (FAILED(scRet)) return; spWriteFreeFlush(outSB[0], fStreamW); }
bool Worker::Attach(ZRef<Starter> iStarter) { ZAcqMtx acq(fMtx); if (not fStarter) { fStarter = iStarter; try { ZRelMtx rel(fMtx); sCall(fCallable_Attached, this); return true; } catch (...) {} fStarter.Clear(); fCnd.Broadcast(); ZRelMtx rel(fMtx); try { sCall(fCallable_Detached, this); } catch (...) {} } return false; }
void GenericReconCartesianNonLinearSpirit2DTGadget::perform_nonlinear_spirit_unwrapping(hoNDArray< std::complex<float> >& kspace, hoNDArray< std::complex<float> >& kerIm, hoNDArray< std::complex<float> >& ref2DT, hoNDArray< std::complex<float> >& coilMap2DT, hoNDArray< std::complex<float> >& res, size_t e) { try { bool print_iter = this->spirit_print_iter.value(); size_t RO = kspace.get_size(0); size_t E1 = kspace.get_size(1); size_t E2 = kspace.get_size(2); size_t CHA = kspace.get_size(3); size_t N = kspace.get_size(4); size_t S = kspace.get_size(5); size_t SLC = kspace.get_size(6); size_t ref_N = kerIm.get_size(4); size_t ref_S = kerIm.get_size(5); hoNDArray< std::complex<float> > kspaceLinear(kspace); res = kspace; // detect whether random sampling is used bool use_random_sampling = false; std::vector<long long> sampled_step_size; long long n, e1; for (n=0; n<(long long)N; n++) { long long prev_sampled_line = -1; for (e1=0; e1<(long long)E1; e1++) { if(std::abs(kspace(RO/2, e1, 0, 0, 0, 0, 0))>0 && std::abs(kspace(RO/2, e1, 0, CHA-1, 0, 0, 0))>0) { if(prev_sampled_line>0) { sampled_step_size.push_back(e1 - prev_sampled_line); } prev_sampled_line = e1; } } } if(sampled_step_size.size()>4) { size_t s; for (s=2; s<sampled_step_size.size()-1; s++) { if(sampled_step_size[s]!=sampled_step_size[s-1]) { use_random_sampling = true; break; } } } if(use_random_sampling) { GDEBUG_STREAM("SPIRIT Non linear, random sampling is detected ... "); } Gadgetron::GadgetronTimer timer(false); boost::shared_ptr< hoNDArray< std::complex<float> > > coilMap; bool hasCoilMap = false; if (coilMap2DT.get_size(0) == RO && coilMap2DT.get_size(1) == E1 && coilMap2DT.get_size(3)==CHA) { if (ref_N < N) { coilMap = boost::shared_ptr< hoNDArray< std::complex<float> > >(new hoNDArray< std::complex<float> >(RO, E1, CHA, coilMap2DT.begin())); } else { coilMap = boost::shared_ptr< hoNDArray< std::complex<float> > >(new hoNDArray< std::complex<float> >(RO, E1, CHA, ref_N, coilMap2DT.begin())); } hasCoilMap = true; } hoNDArray<float> gFactor; float gfactorMedian = 0; float smallest_eigen_value(0); // ----------------------------------------------------- // estimate gfactor // ----------------------------------------------------- // mean over N hoNDArray< std::complex<float> > meanKSpace; if(calib_mode_[e]==ISMRMRD_interleaved) { Gadgetron::compute_averaged_data_N_S(kspace, true, true, true, meanKSpace); } else { Gadgetron::compute_averaged_data_N_S(ref2DT, true, true, true, meanKSpace); } if (!debug_folder_full_path_.empty()) { gt_exporter_.export_array_complex(meanKSpace, debug_folder_full_path_ + "spirit_nl_2DT_meanKSpace"); } hoNDArray< std::complex<float> > acsSrc(meanKSpace.get_size(0), meanKSpace.get_size(1), CHA, meanKSpace.begin()); hoNDArray< std::complex<float> > acsDst(meanKSpace.get_size(0), meanKSpace.get_size(1), CHA, meanKSpace.begin()); double grappa_reg_lamda = 0.0005; size_t kRO = 5; size_t kE1 = 4; hoNDArray< std::complex<float> > convKer; hoNDArray< std::complex<float> > kIm(RO, E1, CHA, CHA); Gadgetron::grappa2d_calib_convolution_kernel(acsSrc, acsDst, (size_t)this->acceFactorE1_[e], grappa_reg_lamda, kRO, kE1, convKer); Gadgetron::grappa2d_image_domain_kernel(convKer, RO, E1, kIm); hoNDArray< std::complex<float> > unmixC; if(hasCoilMap) { Gadgetron::grappa2d_unmixing_coeff(kIm, *coilMap, (size_t)acceFactorE1_[e], unmixC, gFactor); if (!debug_folder_full_path_.empty()) gt_exporter_.export_array(gFactor, debug_folder_full_path_ + "spirit_nl_2DT_gFactor"); hoNDArray<float> gfactorSorted(gFactor); std::sort(gfactorSorted.begin(), gfactorSorted.begin()+RO*E1); gfactorMedian = gFactor((RO*E1 / 2)); GDEBUG_STREAM("SPIRIT Non linear, the median gfactor is found to be : " << gfactorMedian); } if (!debug_folder_full_path_.empty()) gt_exporter_.export_array_complex(kIm, debug_folder_full_path_ + "spirit_nl_2DT_kIm"); hoNDArray< std::complex<float> > complexIm; // compute linear solution as the initialization if(use_random_sampling) { if (this->perform_timing.value()) timer.start("SPIRIT Non linear, perform linear spirit recon ... "); this->perform_spirit_unwrapping(kspace, kerIm, kspaceLinear); if (this->perform_timing.value()) timer.stop(); } else { if (this->perform_timing.value()) timer.start("SPIRIT Non linear, perform linear recon ... "); //size_t ref2DT_RO = ref2DT.get_size(0); //size_t ref2DT_E1 = ref2DT.get_size(1); //// mean over N //hoNDArray< std::complex<float> > meanKSpace; //Gadgetron::sum_over_dimension(ref2DT, meanKSpace, 4); //if (!debug_folder_full_path_.empty()) { gt_exporter_.export_array_complex(meanKSpace, debug_folder_full_path_ + "spirit_nl_2DT_meanKSpace"); } //hoNDArray< std::complex<float> > acsSrc(ref2DT_RO, ref2DT_E1, CHA, meanKSpace.begin()); //hoNDArray< std::complex<float> > acsDst(ref2DT_RO, ref2DT_E1, CHA, meanKSpace.begin()); //double grappa_reg_lamda = 0.0005; //size_t kRO = 5; //size_t kE1 = 4; //hoNDArray< std::complex<float> > convKer; //hoNDArray< std::complex<float> > kIm(RO, E1, CHA, CHA); //Gadgetron::grappa2d_calib_convolution_kernel(acsSrc, acsDst, (size_t)this->acceFactorE1_[e], grappa_reg_lamda, kRO, kE1, convKer); //Gadgetron::grappa2d_image_domain_kernel(convKer, RO, E1, kIm); //if (!debug_folder_full_path_.empty()) gt_exporter_.export_array_complex(kIm, debug_folder_full_path_ + "spirit_nl_2DT_kIm"); Gadgetron::hoNDFFT<float>::instance()->ifft2c(kspace, complex_im_recon_buf_); if (!debug_folder_full_path_.empty()) gt_exporter_.export_array_complex(complex_im_recon_buf_, debug_folder_full_path_ + "spirit_nl_2DT_aliasedImage"); hoNDArray< std::complex<float> > resKSpace(RO, E1, CHA, N); hoNDArray< std::complex<float> > aliasedImage(RO, E1, CHA, N, complex_im_recon_buf_.begin()); Gadgetron::grappa2d_image_domain_unwrapping_aliased_image(aliasedImage, kIm, resKSpace); if (!debug_folder_full_path_.empty()) gt_exporter_.export_array_complex(resKSpace, debug_folder_full_path_ + "spirit_nl_2DT_linearImage"); Gadgetron::hoNDFFT<float>::instance()->fft2c(resKSpace); memcpy(kspaceLinear.begin(), resKSpace.begin(), resKSpace.get_number_of_bytes()); Gadgetron::apply_unmix_coeff_aliased_image(aliasedImage, unmixC, complexIm); if (this->perform_timing.value()) timer.stop(); } if (!debug_folder_full_path_.empty()) gt_exporter_.export_array_complex(kspaceLinear, debug_folder_full_path_ + "spirit_nl_2DT_kspaceLinear"); if(hasCoilMap) { if(N>=spirit_reg_minimal_num_images_for_noise_floor.value()) { // estimate the noise level if(use_random_sampling) { Gadgetron::hoNDFFT<float>::instance()->ifft2c(kspaceLinear, complex_im_recon_buf_); hoNDArray< std::complex<float> > complexLinearImage(RO, E1, CHA, N, complex_im_recon_buf_.begin()); Gadgetron::coil_combine(complexLinearImage, *coilMap, 2, complexIm); } if (!debug_folder_full_path_.empty()) gt_exporter_.export_array_complex(complexIm, debug_folder_full_path_ + "spirit_nl_2DT_linearImage_complexIm"); // if N is sufficiently large, we can estimate the noise floor by the smallest eigen value hoMatrix< std::complex<float> > data; data.createMatrix(RO*E1, N, complexIm.begin(), false); hoNDArray< std::complex<float> > eigenVectors, eigenValues, eigenVectorsPruned; // compute eigen hoNDKLT< std::complex<float> > klt; klt.prepare(data, (size_t)1, (size_t)0); klt.eigen_value(eigenValues); if (this->verbose.value()) { GDEBUG_STREAM("SPIRIT Non linear, computes eigen values for all 2D kspaces ... "); eigenValues.print(std::cout); for (size_t i = 0; i<eigenValues.get_size(0); i++) { GDEBUG_STREAM(i << " = " << eigenValues(i)); } } smallest_eigen_value = std::sqrt( std::abs(eigenValues(N - 1).real()) / (RO*E1) ); GDEBUG_STREAM("SPIRIT Non linear, the smallest eigen value is : " << smallest_eigen_value); } } // perform nonlinear reconstruction { boost::shared_ptr<hoNDArray< std::complex<float> > > ker(new hoNDArray< std::complex<float> >(RO, E1, CHA, CHA, ref_N, kerIm.begin())); boost::shared_ptr<hoNDArray< std::complex<float> > > acq(new hoNDArray< std::complex<float> >(RO, E1, CHA, N, kspace.begin())); hoNDArray< std::complex<float> > kspaceInitial(RO, E1, CHA, N, kspaceLinear.begin()); hoNDArray< std::complex<float> > res2DT(RO, E1, CHA, N, res.begin()); if (this->spirit_data_fidelity_lamda.value() > 0) { GDEBUG_STREAM("Start the NL SPIRIT data fidelity iteration - regularization strength : " << this->spirit_image_reg_lamda.value() << " - number of iteration : " << this->spirit_nl_iter_max.value() << " - proximity across cha : " << this->spirit_reg_proximity_across_cha.value() << " - redundant dimension weighting ratio : " << this->spirit_reg_N_weighting_ratio.value() << " - using coil sen map : " << this->spirit_reg_use_coil_sen_map.value() << " - iter thres : " << this->spirit_nl_iter_thres.value() << " - wavelet name : " << this->spirit_reg_name.value() ); typedef hoGdSolver< hoNDArray< std::complex<float> >, hoWavelet2DTOperator< std::complex<float> > > SolverType; SolverType solver; solver.iterations_ = this->spirit_nl_iter_max.value(); solver.set_output_mode(this->spirit_print_iter.value() ? SolverType::OUTPUT_VERBOSE : SolverType::OUTPUT_SILENT); solver.grad_thres_ = this->spirit_nl_iter_thres.value(); if(spirit_reg_estimate_noise_floor.value() && std::abs(smallest_eigen_value)>0) { solver.scale_factor_ = smallest_eigen_value; solver.proximal_strength_ratio_ = this->spirit_image_reg_lamda.value() * gfactorMedian; GDEBUG_STREAM("SPIRIT Non linear, eigen value is used to derive the regularization strength : " << solver.proximal_strength_ratio_ << " - smallest eigen value : " << solver.scale_factor_); } else { solver.proximal_strength_ratio_ = this->spirit_image_reg_lamda.value(); } boost::shared_ptr< hoNDArray< std::complex<float> > > x0 = boost::make_shared< hoNDArray< std::complex<float> > >(kspaceInitial); solver.set_x0(x0); // parallel imaging term std::vector<size_t> dims; acq->get_dimensions(dims); hoSPIRIT2DTDataFidelityOperator< std::complex<float> > spirit(&dims); spirit.set_forward_kernel(*ker, false); spirit.set_acquired_points(*acq); // image reg term hoWavelet2DTOperator< std::complex<float> > wav3DOperator(&dims); wav3DOperator.set_acquired_points(*acq); wav3DOperator.scale_factor_first_dimension_ = this->spirit_reg_RO_weighting_ratio.value(); wav3DOperator.scale_factor_second_dimension_ = this->spirit_reg_E1_weighting_ratio.value(); wav3DOperator.scale_factor_third_dimension_ = this->spirit_reg_N_weighting_ratio.value(); wav3DOperator.with_approx_coeff_ = !this->spirit_reg_keep_approx_coeff.value(); wav3DOperator.change_coeffcients_third_dimension_boundary_ = !this->spirit_reg_keep_redundant_dimension_coeff.value(); wav3DOperator.proximity_across_cha_ = this->spirit_reg_proximity_across_cha.value(); wav3DOperator.no_null_space_ = true; wav3DOperator.input_in_kspace_ = true; wav3DOperator.select_wavelet(this->spirit_reg_name.value()); if (this->spirit_reg_use_coil_sen_map.value() && hasCoilMap) { wav3DOperator.coil_map_ = *coilMap; } // set operators solver.oper_system_ = &spirit; solver.oper_reg_ = &wav3DOperator; if (this->perform_timing.value()) timer.start("NonLinear SPIRIT solver for 2DT with data fidelity ... "); solver.solve(*acq, res2DT); if (this->perform_timing.value()) timer.stop(); if (!debug_folder_full_path_.empty()) gt_exporter_.export_array_complex(res2DT, debug_folder_full_path_ + "spirit_nl_2DT_data_fidelity_res"); } else { GDEBUG_STREAM("Start the NL SPIRIT iteration with regularization strength : "<< this->spirit_image_reg_lamda.value() << " - number of iteration : " << this->spirit_nl_iter_max.value() << " - proximity across cha : " << this->spirit_reg_proximity_across_cha.value() << " - redundant dimension weighting ratio : " << this->spirit_reg_N_weighting_ratio.value() << " - using coil sen map : " << this->spirit_reg_use_coil_sen_map.value() << " - iter thres : " << this->spirit_nl_iter_thres.value() << " - wavelet name : " << this->spirit_reg_name.value() ); typedef hoGdSolver< hoNDArray< std::complex<float> >, hoWavelet2DTOperator< std::complex<float> > > SolverType; SolverType solver; solver.iterations_ = this->spirit_nl_iter_max.value(); solver.set_output_mode(this->spirit_print_iter.value() ? SolverType::OUTPUT_VERBOSE : SolverType::OUTPUT_SILENT); solver.grad_thres_ = this->spirit_nl_iter_thres.value(); if(spirit_reg_estimate_noise_floor.value() && std::abs(smallest_eigen_value)>0) { solver.scale_factor_ = smallest_eigen_value; solver.proximal_strength_ratio_ = this->spirit_image_reg_lamda.value() * gfactorMedian; GDEBUG_STREAM("SPIRIT Non linear, eigen value is used to derive the regularization strength : " << solver.proximal_strength_ratio_ << " - smallest eigen value : " << solver.scale_factor_); } else { solver.proximal_strength_ratio_ = this->spirit_image_reg_lamda.value(); } boost::shared_ptr< hoNDArray< std::complex<float> > > x0 = boost::make_shared< hoNDArray< std::complex<float> > >(kspaceInitial); solver.set_x0(x0); // parallel imaging term std::vector<size_t> dims; acq->get_dimensions(dims); hoSPIRIT2DTOperator< std::complex<float> > spirit(&dims); spirit.set_forward_kernel(*ker, false); spirit.set_acquired_points(*acq); spirit.no_null_space_ = true; spirit.use_non_centered_fft_ = false; // image reg term std::vector<size_t> dim; acq->get_dimensions(dim); hoWavelet2DTOperator< std::complex<float> > wav3DOperator(&dim); wav3DOperator.set_acquired_points(*acq); wav3DOperator.scale_factor_first_dimension_ = this->spirit_reg_RO_weighting_ratio.value(); wav3DOperator.scale_factor_second_dimension_ = this->spirit_reg_E1_weighting_ratio.value(); wav3DOperator.scale_factor_third_dimension_ = this->spirit_reg_N_weighting_ratio.value(); wav3DOperator.with_approx_coeff_ = !this->spirit_reg_keep_approx_coeff.value(); wav3DOperator.change_coeffcients_third_dimension_boundary_ = !this->spirit_reg_keep_redundant_dimension_coeff.value(); wav3DOperator.proximity_across_cha_ = this->spirit_reg_proximity_across_cha.value(); wav3DOperator.no_null_space_ = true; wav3DOperator.input_in_kspace_ = true; wav3DOperator.select_wavelet(this->spirit_reg_name.value()); if (this->spirit_reg_use_coil_sen_map.value() && hasCoilMap) { wav3DOperator.coil_map_ = *coilMap; } // set operators solver.oper_system_ = &spirit; solver.oper_reg_ = &wav3DOperator; // set call back solverCallBack cb; cb.solver_ = &solver; solver.call_back_ = &cb; hoNDArray< std::complex<float> > b(kspaceInitial); Gadgetron::clear(b); if (this->perform_timing.value()) timer.start("NonLinear SPIRIT solver for 2DT ... "); solver.solve(b, res2DT); if (this->perform_timing.value()) timer.stop(); if (!debug_folder_full_path_.empty()) gt_exporter_.export_array_complex(res2DT, debug_folder_full_path_ + "spirit_nl_2DT_res"); spirit.restore_acquired_kspace(kspace, res2DT); if (!debug_folder_full_path_.empty()) gt_exporter_.export_array_complex(res2DT, debug_folder_full_path_ + "spirit_nl_2DT_res_restored"); } } } catch (...) { GADGET_THROW("Errors happened in GenericReconCartesianNonLinearSpirit2DTGadget::perform_nonlinear_spirit_unwrapping(...) ... "); } }
void Searcher::pCollectResultsCalled() { ZAcqMtx acq(fMtx); fCalled_SearcherResultsAvailable.Reset(); }
// <@$M_{t2}$@> module void foo () { acq(); f(); g(); rel(); }
void ZServer::pWorkDetached(ZRef<ZWorker> iWorker) { ZAcqMtx acq(fMtx); fWorker.Clear(); fCnd.Broadcast(); }
int main(void) { ArSerialConnection con; ArRobot robot; int ret; std::string str; ArActionLimiterForwards limiter("speed limiter near", 300, 600, 250); ArActionLimiterForwards limiterFar("speed limiter far", 300, 1100, 400); ArActionLimiterBackwards backwardsLimiter; ArActionConstantVelocity stop("stop", 0); ArActionConstantVelocity backup("backup", -200); ArSonarDevice sonar; ArACTS_1_2 acts; ArSonyPTZ sony(&robot); ArGripper gripper(&robot, ArGripper::GENIO); Acquire acq(&acts, &gripper); DriveTo driveTo(&acts, &gripper, &sony); PickUp pickUp(&acts, &gripper, &sony); TakeBlockToWall takeBlock(&robot, &gripper, &sony, &acq, &driveTo, &pickUp, &backup); Aria::init(); if (!acts.openPort(&robot)) { printf("Could not connect to acts\n"); exit(1); } robot.addRangeDevice(&sonar); //con.setBaud(38400); if ((ret = con.open()) != 0) { str = con.getOpenMessage(ret); printf("Open failed: %s\n", str.c_str()); Aria::shutdown(); return 1; } robot.setDeviceConnection(&con); if (!robot.blockingConnect()) { printf("Could not connect to robot... exiting\n"); Aria::shutdown(); return 1; } sony.init(); ArUtil::sleep(1000); //robot.setAbsoluteMaxTransVel(400); robot.setStateReflectionRefreshTime(250); robot.comInt(ArCommands::ENABLE, 1); robot.comInt(ArCommands::SOUNDTOG, 0); ArUtil::sleep(200); robot.addAction(&limiter, 100); robot.addAction(&limiterFar, 99); robot.addAction(&backwardsLimiter, 98); robot.addAction(&acq, 77); robot.addAction(&driveTo, 76); robot.addAction(&pickUp, 75); robot.addAction(&backup, 50); robot.addAction(&stop, 30); robot.run(true); Aria::shutdown(); return 0; }
ZRef<ZServer::Callable_Connection> ZServer::GetCallable_Connection() { ZAcqMtx acq(fMtx); return fCallable_Connection; }
ZRef<ZStreamerRWFactory> ZServer::GetFactory() { ZAcqMtx acq(fMtx); return fFactory; }
int main(void) { ArSerialConnection con; ArRobot robot; int ret; std::string str; ArActionLimiterForwards limiter("speed limiter near", 225, 600, 250); ArActionLimiterForwards limiterFar("speed limiter far", 225, 1100, 400); ArActionTableSensorLimiter tableLimiter; ArActionLimiterBackwards backwardsLimiter; ArActionConstantVelocity stop("stop", 0); ArSonarDevice sonar; ArACTS_1_2 acts; ArPTZ *ptz; ptz = new ArVCC4(&robot, true); ArGripper gripper(&robot); Acquire acq(&acts, &gripper); DriveTo driveTo(&acts, &gripper, ptz); DropOff dropOff(&acts, &gripper, ptz); PickUp pickUp(&acts, &gripper, ptz); TakeBlockToWall takeBlock(&robot, &gripper, ptz, &acq, &driveTo, &pickUp, &dropOff, &tableLimiter); if (!acts.openPort(&robot)) { printf("Could not connect to acts, exiting\n"); exit(0); } Aria::init(); robot.addRangeDevice(&sonar); //con.setBaud(38400); if ((ret = con.open()) != 0) { str = con.getOpenMessage(ret); printf("Open failed: %s\n", str.c_str()); Aria::shutdown(); return 1; } robot.setDeviceConnection(&con); if (!robot.blockingConnect()) { printf("Could not connect to robot... exiting\n"); Aria::shutdown(); return 1; } ptz->init(); ArUtil::sleep(8000); printf("### 2222\n"); ptz->panTilt(0, -40); printf("### whee\n"); ArUtil::sleep(8000); robot.setAbsoluteMaxTransVel(400); robot.setStateReflectionRefreshTime(250); robot.comInt(ArCommands::ENABLE, 1); robot.comInt(ArCommands::SOUNDTOG, 0); ArUtil::sleep(200); robot.addAction(&tableLimiter, 100); robot.addAction(&limiter, 99); robot.addAction(&limiterFar, 98); robot.addAction(&backwardsLimiter, 97); robot.addAction(&acq, 77); robot.addAction(&driveTo, 76); robot.addAction(&pickUp, 75); robot.addAction(&dropOff, 74); robot.addAction(&stop, 30); robot.run(true); Aria::shutdown(); return 0; }
bool ZSocketWatcher::QErase(const Pair_t& iPair) { ZAcqMtx acq(fMtx); return fSet.erase(iPair); }
int _tmain(int argc, _TCHAR* argv[]) { com_ptr<IDirectInput8> input(0); com_ptr<IDirectInputDevice8> device(0); HRESULT hr = 0; { IDirectInput8* ptr; hr = ::DirectInput8Create( ::GetModuleHandleA(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, reinterpret_cast<void**>(&ptr), 0); if (FAILED(hr)) { output("Failed to create DInput8 handle.\n"); return 0; } input = com_ptr<IDirectInput8>(ptr); } { IDirectInputDevice8* ptr; hr = input->CreateDevice(GUID_SysKeyboard, &ptr, 0); if (FAILED(hr)) { output("Failed to create keyboard device.\n"); return 0; } device = com_ptr<IDirectInputDevice8>(ptr); } hr = device->SetDataFormat(&c_dfDIKeyboard); if (FAILED(hr)) { output("Failed to set device data format.\n"); return 0; } hr = device->SetCooperativeLevel(GetConsoleHwnd(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); if (FAILED(hr)) { output("Failed to set device cooperative level.\n"); return 0; } { DIPROPDWORD dipdw = {0}; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = 8; // バッファのサイズ hr = device->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph); if (FAILED(hr)) { output("Failed to set device buffer size property.\n"); return 0; } } acquire_device acq(device.get()); keyboard kbd; while(!kbd.pressed(EscapeKey)) { kbd.reset(); HRESULT hr = device->GetDeviceState(KeyboardSize, kbd.data()); if (FAILED(hr)) { std::cout << "Failed to get keyboard device state\n"; break; } std::cout << std::hex; //for(byte_t i = 0; i != KeyboardSize; ++i) { byte_t i = 0; do { if (kbd.pressed(i)) std::cout << static_cast<size_t>(i) << " "; } while(i != KeyboardSize-1); //} std::cout << std::endl; ::Sleep(100); } return 0; }