std::vector<int> getSamplesLine (pcl::PointCloud<pcl::PointXYZRGBNormalRSD>::Ptr cloud) { // srand (time(0)); // std::vector<int> random_idx(2); do { for (int i = 0; i < 2; i++) { random_idx[i] = (int) cloud->points.size () * (rand () / (RAND_MAX + 1.0)); } } while (random_idx[0] == random_idx[1]); return random_idx; }
/** \brief Get 2 random points as data samples and return them as point indices. * \param iterations the internal number of iterations used by SAC methods * \note assumes unique points! */ std::vector<int> SACModelLine::getSamples (int &iterations) { std::vector<int> random_idx (2); // Get a random number between 1 and max_indices int idx = (int)(indices_.size () * (rand () / (RAND_MAX + 1.0))); // Get the index random_idx[0] = indices_.at (idx); // Get a second point which is different than the first do { idx = (int)(indices_.size () * (rand () / (RAND_MAX + 1.0))); random_idx[1] = indices_.at (idx); iterations++; } while (random_idx[1] == random_idx[0]); iterations--; return (random_idx); }
void plat_freelist_process(int mnode) { page_t *page, **freelist; page_t *bdlist[STARFIRE_MAX_BOARDS]; page_t **sortlist[STARFIRE_MAX_BOARDS]; uint32_t idx, idy, size, color, max_color, lbn; uint32_t bd_flags, bd_cnt, result, bds; kmutex_t *pcm; int mtype; /* for each page size */ for (mtype = 0; mtype < MAX_MEM_TYPES; mtype++) { for (size = 0; size < mmu_page_sizes; size++) { /* * Compute the maximum # of phys colors based on * page size. */ max_color = page_get_pagecolors(size); /* for each color */ for (color = 0; color < max_color; color++) { bd_cnt = 0; bd_flags = 0; for (idx = 0; idx < STARFIRE_MAX_BOARDS; idx++) { bdlist[idx] = NULL; sortlist[idx] = NULL; } /* find freelist */ freelist = &PAGE_FREELISTS(mnode, size, color, mtype); if (*freelist == NULL) continue; /* acquire locks */ pcm = PC_BIN_MUTEX(mnode, color, PG_FREE_LIST); mutex_enter(pcm); /* * read freelist & sort pages by logical * board number */ /* grab pages till last one. */ while (*freelist) { page = *freelist; result = page_trylock(page, SE_EXCL); ASSERT(result); /* Delete from freelist */ if (size != 0) { page_vpsub(freelist, page); } else { mach_page_sub(freelist, page); } /* detect the lbn */ lbn = PFN_2_LBN(page->p_pagenum); /* add to bdlist[lbn] */ if (size != 0) { page_vpadd(&bdlist[lbn], page); } else { mach_page_add(&bdlist[lbn], page); } /* if lbn new */ if ((bd_flags & (1 << lbn)) == 0) { bd_flags |= (1 << lbn); bd_cnt++; } page_unlock(page); } /* * Make the sortlist so * bd_cnt choices show up */ bds = 0; for (idx = 0; idx < STARFIRE_MAX_BOARDS; idx++) { if (bdlist[idx]) sortlist[bds++] = &bdlist[idx]; } /* * Set random start. */ (void) random_idx(-color); /* * now rebuild the freelist by shuffling * pages from bd lists */ while (bd_cnt) { /* * get "random" index between 0 & * bd_cnt */ ASSERT(bd_cnt && (bd_cnt < STARFIRE_MAX_BOARDS+1)); idx = random_idx(bd_cnt); page = *sortlist[idx]; result = page_trylock(page, SE_EXCL); ASSERT(result); /* Delete from sort_list */ /* & Append to freelist */ /* Big pages use vp_add - 8k don't */ if (size != 0) { page_vpsub(sortlist[idx], page); page_vpadd(freelist, page); } else { mach_page_sub(sortlist[idx], page); mach_page_add(freelist, page); } /* needed for indexing tmp lists */ lbn = PFN_2_LBN(page->p_pagenum); /* * if this was the last page on this * list? */ if (*sortlist[idx] == NULL) { /* have to find brd list */ /* idx is lbn? -- No! */ /* sortlist, brdlist */ /* have diff indexs */ bd_flags &= ~(1 << lbn); --bd_cnt; /* * redo the sortlist so only * bd_cnt choices show up */ bds = 0; for (idy = 0; idy < STARFIRE_MAX_BOARDS; idy++) { if (bdlist[idy]) { sortlist[bds++] /* CSTYLED */ = &bdlist[idy]; } } } page_unlock(page); } mutex_exit(pcm); } } } }