bool Dynamic::get_seed (Point<float>& p, Point<float>& d) { uint64_t samples = 0; std::uniform_int_distribution<size_t> uniform_int (0, fixels.size()-2); while (1) { ++samples; const size_t fixel_index = 1 + uniform_int (rng.rng); const Fixel& fixel = fixels[fixel_index]; if (fixel.get_seed_prob (mu()) > rng()) { const Point<int>& v (fixel.get_voxel()); const Point<float> vp (v[0]+rng()-0.5, v[1]+rng()-0.5, v[2]+rng()-0.5); p = transform.voxel2scanner (vp); bool good_seed = !act; if (!good_seed) { if (act->check_seed (p)) { // Make sure that the seed point has not left the intended voxel const Point<float> new_v_float (transform.scanner2voxel (p)); const Point<int> new_v (std::round (new_v_float[0]), std::round (new_v_float[1]), std::round (new_v_float[2])); good_seed = (new_v == v); } } if (good_seed) { d = fixel.get_dir(); #ifdef DYNAMIC_SEED_DEBUGGING write_seed (p); #endif std::lock_guard<std::mutex> lock (mutex); total_samples += samples; ++total_seeds; return true; } } } return false; }
// ----- create/delete givens matrix ----- // givens_sequence_list *generate_givens(){ givens_sequence_list *gsl_r, *gsl_cur; givens_matrix_list *gml=NULL, *gml_cur; int *shfl; alloc_matrix_int(&shfl, MATRIX_SIZE); for(int i=0; i<MATRIX_SIZE; i++) shfl[i] = i; // Fisher-Yates shuffle for(int i=0; i<MATRIX_SIZE-1; i++){ int k = uniform_int(i,MATRIX_SIZE-1); int tmp = shfl[k]; shfl[k] = shfl[i]; shfl[i] = tmp; } gsl_r = create_givens_sequence_list(); gsl_cur = gsl_r; const int gm_num = MATRIX_SIZE/GS_NUM; for(int i=0; i<GS_NUM; i++){ gsl_cur = create_givens_sequence_list(); for(int j=0; j<gm_num/2; j++){ gml_cur = create_givens_matrix_list(); givens_matrix *gm = create_givens_matrix(shfl[gm_num*i + 2*j],shfl[gm_num*i+2*j+1], uniform()*2*MATH_PI); gml_cur->gm = gm; if(j == 0){ gsl_cur->gml = gml_cur; }else{ gml->next = gml_cur; } gml = gml_cur; } if(i == 0) gsl_r = gsl_cur; gsl_cur = gsl_cur->next; } free_matrix_int(&shfl); return gsl_r; }