void generate_random_points( Interface& mb, size_t num_points, std::vector<CartVect>& points, std::vector<EntityHandle>& point_elems ) { Range elems; ErrorCode rval; rval = mb.get_entities_by_dimension( 0, 3, elems ); CHK(rval); if (!elems.all_of_type(MBHEX)) { std::cerr << "Warning: ignoring non-hexahedral elements." << std::endl; std::pair< Range::iterator, Range::iterator > p = elems.equal_range(MBHEX); elems.erase( p.second, elems.end() ); elems.erase( elems.begin(), p.first ); } if (elems.empty()) { std::cerr << "Input file contains no hexahedral elements." << std::endl; exit(1); } points.resize( num_points ); point_elems.resize( num_points ); const size_t num_elem = elems.size(); for (size_t i = 0; i < num_points; ++i) { size_t offset = 0; for (size_t x = num_elem; x > 0; x /= RAND_MAX) offset += rand(); offset %= num_elem; point_elems[i] = elems[offset]; points[i] = random_point_in_hex( mb, point_elems[i] ); } }
ErrorCode BitTag::get_entities_with_bits( const Range &range, EntityType in_type, Range& entities, unsigned char bits ) const { if (MBMAXTYPE == in_type) { ErrorCode rval; for (--in_type; in_type >= MBVERTEX; --in_type) { rval = get_entities_with_bits( range, in_type, entities, bits ); if (MB_SUCCESS != rval) return rval; } return MB_SUCCESS; } EntityType type; EntityID count; size_t page; int offset, per_page = ents_per_page(); Range::const_iterator j, i, end; if (MBMAXTYPE == in_type) { i = range.begin(); end = range.end(); } else { std::pair<Range::iterator,Range::iterator> r = range.equal_range(in_type); i = r.first; end = r.second; } EntityHandle h; while (i != end) { h = *i; unpack( h, type, page, offset ); assert(MBMAXTYPE == in_type || type == in_type); i = i.end_of_block(); count = *i - h + 1; ++i; while (count > 0) { EntityID pcount = std::min( count, (EntityID)(per_page - offset) ); if (page < pageList[type].size() && pageList[type][page]) pageList[type][page]->search( bits, offset, pcount, storedBitsPerEntity, entities, h ); count -= pcount; h += pcount; assert(TYPE_FROM_HANDLE(h) == type); offset = 0; ++page; } } return MB_SUCCESS; }
void remove_type( Range& range, EntityType t ) { std::pair<Range::iterator,Range::iterator> p = range.equal_range(t); range.erase( p.first, p.second ); }