Object & ConstListItr<Object>::retrieve( ) const { assertIsValid( ); if( current->next == NULL ) throw IteratorOutOfBoundsException( "Cannot perform *end( ) in list" ); return current->data; }
void OctreeGrid::testSubdivideRandom(bool graded, bool paired) { bool bfs = false; std::vector<std::pair<int, int> > leaves, next; // Init: start with root cells leaves.reserve(m_Cells.size()); for (int i = 0; i < (int) m_Cells.size(); ++i) { leaves.emplace_back(0, i); } std::default_random_engine gen; std::uniform_real_distribution<double> distr(0, 1); assertIsValid(); int counter = 0; int nextCheck = (int) leaves.size(); while (!leaves.empty()) { std::uniform_int_distribution<int> take(0, (int) leaves.size() - 1); int i = take(gen); int depth = leaves[i].first; int id = leaves[i].second; std::swap(leaves[i], leaves.back()); leaves.pop_back(); if (depth < m_MaxDepth) { if (distr(gen) > 0.2 && cellIsLeaf(id)) { int newId = (int) m_Cells.size(); splitCell(id, graded, paired); for (int k = 0; k < 8; ++k) { if (bfs) { next.emplace_back(depth + 1, newId++); } else { leaves.emplace_back(depth + 1, newId++); } } } } ++counter; if (!bfs && counter == nextCheck) { assertIsValid(); nextCheck = (int) leaves.size(); counter = 0; } if (leaves.empty()) { assertIsValid(); std::swap(leaves, next); } } assertIsValid(); //std::shuffle(m_Cells.begin(), m_Cells.end(), std::default_random_engine()); // logger_debug("Octree", "Graded %s", is2to1Graded()); // logger_debug("Octree", "Build ok"); std::cout << "Graded: " << is2to1Graded() << std::endl; std::cout << "Paired: " << isPaired() << std::endl; // logger_debug("Octree", "Num nodes: %s", m_Nodes.size()); // logger_debug("Octree", "Num cells: %s", m_Cells.size()); if (graded) { oct_assert(is2to1Graded()); } if (paired) { oct_assert(isPaired()); } }
void ConstListItr<Object>::assertCanRetreat( ) const { assertIsValid( ); if( current->prev == head ) throw IteratorOutOfBoundsException( "Cannot perform --begin( ) in list" ); }