Example #1
0
    static inline bool are_holes_inside(RingIterator first,
                                        RingIterator beyond,
                                        ExteriorRing const& exterior_ring,
                                        IndexSet const& rings_with_turns)
    {
        int idx = 0;
        for (RingIterator it = first; it != beyond; ++it, ++idx)
        {
            // check only rings whose index is not associated to any turn
            if ( rings_with_turns.find(idx) == rings_with_turns.end()
                 && !geometry::within(range::front(*it), exterior_ring) )
            {
                return false;
            }
        }

        // for those rings that do not have any associated turns,
        // check if they lie inside another ring
        idx = 0;
        for (RingIterator it1 = first; it1 != beyond; ++it1, ++idx)
        {
            if ( rings_with_turns.find(idx) == rings_with_turns.end() )
            {
                for (RingIterator it2 = first; it2 != beyond; ++it2)
                {
                    if ( it1 != it2
                         && geometry::within(range::front(*it1), *it2) )
                    {
                        return false;
                    }
                }
            }
        }
        return true;
    }
bool isDup(const IndexSet& data, const BSONObj& key) {
    IndexSet::const_iterator it = data.find(IndexKeyEntry(key, RecordId()));
    if (it == data.end())
        return false;

    ++it;
    if (it == data.end())
        return false;

    return it->key.woCompare(key, BSONObj(), false) == 0;
}
bool isDup(const IndexSet& data, const BSONObj& key, RecordId loc) {
    const IndexSet::const_iterator it = data.find(IndexKeyEntry(key, RecordId()));
    if (it == data.end())
        return false;

    // Not a dup if the entry is for the same loc.
    return it->loc != loc;
}
Example #4
0
inline
void
VectorDBase<T>::assignT(T v, const IndexSet& is)
{
    for (typename IndexSet::Iter i = is.begin(); i != is.end(); ++i) {
        start[i] = v;
    } 
}
Example #5
0
inline
void
VectorDBase<T>::assign(const VectorDBase<T>& v1, const IndexSet& is)
{
    assert(v1.get_size() == is.get_size());
    assert(get_size() == is.count());
    T* i = start;
    for (typename IndexSet::Iter i1 = is.begin(); i1 != is.end(); ++i1) {
        *i = v1[i1]; ++i;
    } 
}
Example #6
0
void
LocalViewSelection::replaceViews(IndexSet const & toBeReplaced)
{
    IndexSet::const_iterator tbr = toBeReplaced.begin();
    while (tbr != toBeReplaced.end()) {
        available[*tbr] = false;
        selected.erase(*tbr);
        ++tbr;
    }
    success = false;
    performVS();
}
Example #7
0
void CombinedProfile::printDrift(const CombinedProfile& other,
                                 llvm::raw_ostream& stream) const
{

    // build union of non-zero histograms
    IndexSet I;

    for(unsigned i = 0, E = size(); i < E; ++i)
        if( (_histograms[i] != NULL) && _histograms[i]->nonZero() )
            I.insert(i);

    for(unsigned i = 0, E = other.size(); i < E; ++i)
        if( (other._histograms[i] != NULL) && other._histograms[i]->nonZero() )
            I.insert(i);

    if(I.size() == 0)
        errs() << "Warning: no histograms\n";

    // Compute and print drift
    stream << "#" << getNameStr() << "Index\t0-out\t0-in\n";
    for(IndexSet::iterator i = I.begin(), E = I.end(); i != E; ++i)
    {
        // check for 0-overlap (100% drift) cases
        if( (*i > size()) || (*i > other.size())
                || (_histograms[*i] == NULL) || (other._histograms[*i] == NULL)
                || !_histograms[*i]->nonZero() || !other._histograms[*i]->nonZero() )
        {
            errs() << "Warning: histogram " << *i << " only exists in one profile!\n";
            stream << *i << "\t1.0\t1.0\n";
            continue;
        }

        CPHistogram* h1 = _histograms[*i];
        CPHistogram* h2 = other._histograms[*i];

        if( h1->isPoint() && h2->isPoint() && (h1->min() != h2->min()))
        {
            errs() << "Warning: histogram " << *i << " has different point values\n";
            stream << *i << "\t1.0\t1.0\n";
            continue;
        }

        // finally, no exceptional situations!
        stream << *i << "\t" << 1-h1->overlap(*h2, false) << "\t"
               << 1-h1->overlap(*h2, true) << "\n";

    }
}
Example #8
0
MVS_NAMESPACE_BEGIN

LocalViewSelection::LocalViewSelection(
    SingleViewPtrList const& views,
    Settings const& settings,
    IndexSet const& globalViewIDs,
    IndexSet const& propagated,
    PatchSampler::Ptr sampler)
    :
    ViewSelection(settings),
    success(false),
    views(views),
    sampler(sampler)
{
    // inherited attribute
    this->selected = propagated;

    if (!sampler->success[settings.refViewNr]) {
        return;
    }
    if (selected.size() == settings.nrReconNeighbors)
        success = true;
    else if (selected.size() > settings.nrReconNeighbors) {
        std::cerr << "ERROR: Too many local neighbors propagated!" << std::endl;
        selected.clear();
    }

    available.clear();
    available.resize(views.size(), false);
    IndexSet::const_iterator id;
    for (id = globalViewIDs.begin(); id != globalViewIDs.end(); ++id) {
        available[*id] = true;
    }
    IndexSet::const_iterator sel;
    for (sel = selected.begin(); sel != selected.end(); ++sel) {
        available[*sel] = false;
    }
}
 Cursor(OperationContext* opCtx, const IndexSet& data, bool isForward, bool isUnique)
     : _opCtx(opCtx),
       _data(data),
       _forward(isForward),
       _isUnique(isUnique),
       _it(data.end()) {}
Example #10
0
 ForwardCursor(const IndexSet& data, OperationContext* txn)
     : _txn(txn),
       _data(data),
       _it(data.end())
 {}
 Cursor(OperationContext* txn, const IndexSet& data, bool isForward)
     : _txn(txn), _data(data), _forward(isForward), _it(data.end()) {}
bool keyExists(const IndexSet& data, const BSONObj& key) {
    IndexSet::const_iterator it = data.find(IndexKeyEntry(key, RecordId()));
    return it != data.end();
}
Example #13
0
void
TopologyGraph::createBoundary(unsigned graphNum, TopologyGraph::IndexVector& output) const
{
    // nothing to do - bail
    if (_verts.empty() || graphNum+1 > _maxGraphID)
        return;

    // graph ID is one more than the graph number passed in:
    unsigned graphID = graphNum + 1u;

    // Find the starting point (vertex with minimum Y) for this graph ID.
    // By the nature of disconnected graphs, that start point is all we need
    // to ensure we are walking a single connected mesh.
    Index vstart = _verts.end();
    for (VertexSet::const_iterator vert = _verts.begin(); vert != _verts.end(); ++vert)
    {
        if (vert->_graphID == graphID) 
        {
            if (vstart == _verts.end() || vert->y() < vstart->y())
            {
                vstart = vert;
            }
        }
    }

    // couldn't find a start point - bail (should never happen)
    if (vstart == _verts.end())
        return;

    // starting with the minimum-Y vertex (which is guaranteed to be in the boundary)
    // traverse the outside of the point set. Do this by sorting all the edges by
    // their angle relative to the vector from the previous point. The "leftest" turn
    // represents the edge connecting the current point to the next boundary point.
    // Thusly we walk the boundary counterclockwise until we return to the start point.
    Index vptr = vstart;
    Index vptr_prev = _verts.end();

    IndexSet visited;

    while( true )
    {
        // store this vertex in the result set:
        output.push_back( vptr );

        // pull up the next 2D vertex (XY plane):
        osg::Vec2d vert ( vptr->x(), vptr->y() );

        // construct the "base" vector that points from the previous 
        // point to the current point; or to +X in the initial case
        osg::Vec2d base;
        if ( vptr_prev == _verts.end() )
        {
            base.set(1, 0);
        }
        else
        {
            base = vert - osg::Vec2d( vptr_prev->x(), vptr_prev->y() );
            base.normalize();
        }
            
        // pull up the edge set for this vertex:
        EdgeMap::const_iterator ei = _edgeMap.find(vptr);
        if (ei == _edgeMap.end())
            continue; // should be impossible

        const IndexSet& edges = ei->second;

        // find the edge with the minimum delta angle to the base vector
        double bestScore = -DBL_MAX;
        Index  bestEdge  = _verts.end();
        
        //OE_NOTICE << "VERTEX (" << 
        //    vptr->x() << ", " << vptr->y() << ", "
        //    << ") has " << edges.size() << " edges..."
        //    << std::endl;

        unsigned possibleEdges = 0u;

        for( IndexSet::iterator e = edges.begin(); e != edges.end(); ++e )
        {
            // don't go back from whence we just came
            if ( *e == vptr_prev )
                continue;

            // never return to a vert we've already visited
            if ( visited.find(*e) != visited.end() )
                continue;

            ++possibleEdges;

            // calculate the angle between the base vector and the current edge:
            osg::Vec2d edgeVert( (*e)->x(), (*e)->y() );
            osg::Vec2d edge = edgeVert - vert;
            edge.normalize();

            double cross = base.x()*edge.y() - base.y()*edge.x();
            double dot   = base * edge;

            double score;
            if (cross <= 0.0)
                score = 1.0-dot; // [0..2]
            else
                score = dot-1.0; // [-2..0]

            //OE_NOTICE << "   check: " << (*e)->x() << ", " << (*e)->y() << std::endl;
            //OE_NOTICE << "   base = " << base.x() << ", " << base.y() << std::endl;
            //OE_NOTICE << "   edge = " << edge.x() << ", " << edge.y() << std::endl;
            //OE_NOTICE << "   crs = " << cross << ", dot = " << dot << ", score = " << score << std::endl;
            
            if (score > bestScore)
            {
                bestScore = score;
                bestEdge = *e;
            }
        }

        if ( bestEdge == _verts.end() )
        {
            // this should never happen
            // but sometimes does anyway
            OE_WARN << LC << getName() << " - Illegal state - reached a dead end during boundary detection. Vertex (" 
                << vptr->x() << ", " << vptr->y() << ") has " << possibleEdges << " possible edges.\n"
                << std::endl;
            break;
        }

        // store the previous:
        vptr_prev = vptr;

        // follow the chosen edge around the outside of the geometry:
        //OE_DEBUG << "   BEST SCORE = " << bestScore << std::endl;
        vptr = bestEdge;

        // record this vert so we don't visit it again.
        visited.insert( vptr );

        // once we make it all the way around, we're done:
        if ( vptr == vstart )
            break;
    }
}