Esempio n. 1
0
std::vector<geo::Bounds::Ptr> Quad::retrieve_all_bounds( Quad::Ptr& quadptr, bool leaf_only, bool fuzzy )
{
    std::vector<geo::Bounds::Ptr> ret;
    PtrStack quadstack;
    quadstack.push(quadptr);

    while (!quadstack.empty()) {
        Ptr currquad = quadstack.top();
        quadstack.pop();
        
        if (currquad->haschildren()) {
            for (auto& child : currquad->children_) {
                quadstack.push(child);
            }

            if (!leaf_only) {
                if (fuzzy) {
                    ret.push_back(std::make_shared<geo::Bounds>(currquad->fuzzybounds_));
                } else {
                    ret.push_back(std::make_shared<geo::Bounds>(*currquad));
                }
            }
        } else {
            if (fuzzy) {
                ret.push_back(std::make_shared<geo::Bounds>(currquad->fuzzybounds_));
            } else {
                ret.push_back(std::make_shared<geo::Bounds>(*currquad));
            }
        }
    }

    return ret;
}
Esempio n. 2
0
bool Quad::insert( Quad::Ptr& quadptr, geo::Entity::CPtr entity_ptr )
{
    if ( !entity_ptr->touches(quadptr->fuzzybounds_) ) return false;

    PtrStack quadstack;
    quadstack.push(quadptr);

    while (!quadstack.empty()) {
        // attempt to insert this element (edge) in the quad at the top of
        // the stack.
        Ptr currquad = quadstack.top();
        quadstack.pop();

        // Create a list of entities to process.
        if (currquad->haschildren()) {
            // this quad has children (implies no elements in this quad)
            for ( auto& quad : currquad->children_ ) {
                // attempt to insert into all child quads that contain the edge.
                if (entity_ptr->touches(quad->fuzzybounds_)) {
                    quadstack.push( quad );
                } 
            }

            continue;

        } 
        
        // This is a leaf node. Try to insert.
        currquad->element_list_.push_back(entity_ptr);

        // Try to split the quad if its full.
        if (currquad->full() && currquad->split()) {
            // quad is saturated with elements; split and redistribute.
            // add it first so we redistribute everything including this
            // element.
            for ( auto& e : currquad->element_list_ ) {
                for ( auto& quad : currquad->children_ ) {
                    insert(quad, e);
                }
            }

            currquad->element_list_.clear();
        } 
    }

    return true;
}