remove multiple edges from 2D Arrangement

classic Classic list List threaded Threaded
2 messages Options
gp
Reply | Threaded
Open this post in threaded view
|

remove multiple edges from 2D Arrangement

gp
The context: a function that removes from an arrangement all faces whose data
don't pass a certain predicate. The approach: delete every edge that doesn't
border a passing face. Question: is there a better way to do this? I use the
double-while because of the general risk of deleting from a collection while
iterating over it, but I wonder if there's a more elegant way to obviate
that risk in this specific situation.

void removeFailingFaces(
    Arrangement& arr,
    std::function< bool( FaceData ) > facePredicate )
{
    while( true ) {
        bool deletedAnything = false;
        auto it = arr.halfedges_begin();
        while( it != arr.halfedges_end() ) {
            const Face_const_handle faceA = it->face();
            const Face_const_handle faceB = it->twin()->face();
            const bool aPasses = facePredicate( faceA->data() );
            const bool bPasses = facePredicate( faceB->data() );
            if( !aPasses && !bPasses ) {
                CGAL::remove_edge( arr, it );
                deletedAnything = true;
                break;
            }
            it++;
        }
        if( !deletedAnything ) {
            break;
        }
    }
}



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss


Reply | Threaded
Open this post in threaded view
|

Re: remove multiple edges from 2D Arrangement

CarstenT

Hi,

I'm not sure if an optimisation counts for adding to elegance.
If you keep track of the iter by a counter you can prevent starting
iteration from ->begin()
but from
it =arr->begin(),
it=+counter  //(don't increment counter on deletes)



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss