void maxAbsolute(const hoNDArray<T>& x, T& r, size_t& ind) { size_t N = x.get_number_of_elements(); const T* pX = x.begin(); ind = 0; if ( N == 0 ) return; long long n; typename realType<T>::Type v = abs(pX[0]); typename realType<T>::Type v2; ind = 0; for ( n=1; n<(long long)N; n++ ) { v2 = std::abs(pX[n]); if ( v2 > v ) { v = v2; ind = n; } } r = pX[ind]; }
void sort(const hoNDArray<T>& x, hoNDArray<T>& r, bool isascending) { if ( &r != &x ) { if ( r.get_number_of_elements()!=x.get_number_of_elements()) { r = x; } else { memcpy(r.begin(), x.begin(), x.get_number_of_bytes()); } } sort(x.get_number_of_elements(), x.begin(), r.begin(), isascending); }
hoNDArray<uint16_t> update_field_map(const hoNDArray<uint16_t> &field_map_index, const hoNDArray<uint16_t> &proposed_field_map_index, const hoNDArray<float> &residuals_map, const hoNDArray<float> &lambda_map) { hoNDArray<float> residual_diff_map(field_map_index.get_dimensions()); const auto X = field_map_index.get_size(0); const auto Y = field_map_index.get_size(1); const auto Z = field_map_index.get_size(2); for (size_t kz = 0; kz < Z; kz++) { for (size_t ky = 0; ky < Y; ky++) { for (size_t kx = 0; kx < X; kx++) { residual_diff_map(kx, ky,kz) = residuals_map(field_map_index(kx, ky,kz), kx, ky,kz) - residuals_map(proposed_field_map_index(kx, ky,kz), kx, ky,kz); } } } std::vector<boost::default_color_type> color_map; if (Z == 1) { color_map = graph_cut<2>(field_map_index, proposed_field_map_index, lambda_map, residual_diff_map); } else { color_map = graph_cut<3>(field_map_index, proposed_field_map_index, lambda_map, residual_diff_map); } auto result = field_map_index; size_t updated_voxels = 0; for (size_t i = 0; i < field_map_index.get_number_of_elements(); i++) { if (color_map[i] != boost::default_color_type::black_color) { updated_voxels++; result[i] = proposed_field_map_index[i]; } } return result; }
void maxValue(const hoNDArray<T>& a, T& v) { typedef T ValueType; try { const ValueType* pA = a.begin(); size_t n = a.get_number_of_elements(); v = pA[0]; size_t ii; for (ii=1; ii<n; ii++) { if (pA[ii]>v) v = pA[ii]; } } catch(...) { GADGET_THROW("Errors in maxValue(const hoNDArray<T>& a, T& v) ... "); } }
void dotu(const hoNDArray<T>& x, const hoNDArray<T>& y, T& r) { GADGET_DEBUG_CHECK_THROW(x.get_number_of_elements()==y.get_number_of_elements()); dotu(x.get_number_of_elements(), x.begin(), y.begin(), r); }
template<class T> size_t amax(const hoNDArray<T>& x) { return amax(x.get_number_of_elements(), x.begin()); }
void norm2(const hoNDArray<T>& x, typename realType<T>::Type& r) { norm2(x.get_number_of_elements(), x.begin(), r); }
template<class T> void asum(const hoNDArray<T>& x, typename realType<T>::Type& r) { asum(x.get_number_of_elements(), x.begin(), r); }
void correct_heart_beat_time_stamp_with_fitting(hoNDArray<float>& cpt_time_stamp, hoNDArray<int>& ind_hb, size_t startE1, size_t endE1, const std::vector<size_t>& start_e1_hb, const std::vector<size_t>& end_e1_hb, const std::vector<size_t>& start_n_hb, const std::vector<size_t>& end_n_hb ) { try { size_t E1 = cpt_time_stamp.get_size(0); size_t N = cpt_time_stamp.get_size(1); size_t rE1 = endE1-startE1+1; size_t e1, n, ind, ii; size_t num_acq_read_outs = 0; for ( n=0; n<N; n++ ) { for ( e1=0; e1<E1; e1++ ) { if ( cpt_time_stamp(e1, n) >= 0 ) { num_acq_read_outs++; } } } size_t numOfHB = start_e1_hb.size(); std::vector<size_t> ind_HB_start(numOfHB); std::vector<size_t> ind_HB_end(numOfHB); for ( ind=0; ind<numOfHB; ind++ ) { ind_HB_start[ind] = start_e1_hb[ind] + start_n_hb[ind] * E1; ind_HB_end[ind] = end_e1_hb[ind] + end_n_hb[ind] * E1; } // -------------------------------------------------------- // fit a line to every heart beat // -------------------------------------------------------- float a, b; std::vector<float> A(numOfHB, 0.0f), B(numOfHB, 0.0f); for ( ind=0; ind<numOfHB; ind++ ) { std::vector<float> x, y; size_t cpt; for ( cpt=ind_HB_start[ind]; cpt<=ind_HB_end[ind]; cpt++ ) { size_t n = cpt / E1; size_t e1 = cpt - n*E1; if(e1>=startE1 && e1<=endE1) { if ( cpt_time_stamp[cpt] > -1 ) { size_t x_ind = (e1-startE1) + n*rE1; x.push_back( (float)x_ind ); y.push_back(cpt_time_stamp[cpt]); } } } if ( !x.empty() ) { Gadgetron::simple_line_fit(x, y, a, b); A[ind] = a; B[ind] = b; } } // -------------------------------------------------------- // compute cpt time stamp for every line // -------------------------------------------------------- size_t num = cpt_time_stamp.get_number_of_elements(); for ( ind=0; ind<num; ind++ ) { n = ind / E1; e1 = ind - n*E1; if(e1>=startE1 && e1<=endE1) { // find to which heart beat this line belongs bool foundHB = false; for ( ii=0; ii<numOfHB; ii++ ) { size_t startHB = ind_HB_start[ii]; size_t endHB = ind_HB_end[ii]; if ( ii==0 && ind<=startHB ) { foundHB = true; break; } if ( ii==numOfHB-1 && ind>=endHB ) { foundHB = true; break; } if ( ind>=startHB && ind<=endHB ) { foundHB = true; break; } } // if cannot find a heart beat, this kspace line will not be used if ( foundHB && (std::abs(B[ii])>0) ) { ind_hb(e1, n) = ii; size_t x_ind = (e1-startE1) + n*rE1; cpt_time_stamp(e1, n) = (float)(A[ii] + B[ii]*x_ind); } else { ind_hb(e1, n) = -1; } } else { cpt_time_stamp(e1, n) = -1; ind_hb(e1, n) = -1; } } } catch(...) { GADGET_THROW("Exceptions happened in correct_heart_beat_time_stamp_with_fitting(...) ... "); } }