Beispiel #1
0
/**
 * intersection post processing
 */
void post_intersection( const GeometrySet<2>& input, GeometrySet<2>& output )
{
    //
    // reverse orientation of polygons if needed
    for ( GeometrySet<2>::SurfaceCollection::const_iterator it = input.surfaces().begin();
            it != input.surfaces().end();
            ++it ) {
        const CGAL::Polygon_with_holes_2<Kernel>& p = it->primitive();
        CGAL::Polygon_2<Kernel> outer = p.outer_boundary();

        if ( outer.orientation() == CGAL::CLOCKWISE ) {
            outer.reverse_orientation();
        }

        std::list<CGAL::Polygon_2<Kernel> > rings;

        for ( CGAL::Polygon_with_holes_2<Kernel>::Hole_const_iterator hit = p.holes_begin();
                hit != p.holes_end();
                ++hit ) {
            rings.push_back( *hit );

            if ( hit->orientation() == CGAL::COUNTERCLOCKWISE ) {
                rings.back().reverse_orientation();
            }
        }

        output.surfaces().push_back( CGAL::Polygon_with_holes_2<Kernel>( outer, rings.begin(), rings.end() ) );
    }

    output.points() = input.points();
    output.segments() = input.segments();
    output.volumes() = input.volumes();
}
Beispiel #2
0
static void filter_self_intersection( const GeometrySet<Dim>& input, GeometrySet<Dim>& output )
{
    {
        typedef std::list< CollectionElement<typename Point_d<Dim>::Type> > PointList;
        PointList points;

        std::copy( input.points().begin(), input.points().end(), std::back_inserter( points ) );

        typename PointList::iterator it = points.begin();

        while ( it != points.end() ) {
            bool intersectsA = false;

            for ( typename PointList::iterator it2 = points.begin(); it2 != points.end(); ++it2 ) {
                if ( it == it2 ) {
                    continue;
                }

                PrimitiveHandle<Dim> pa1( &it->primitive() );
                PrimitiveHandle<Dim> pa2( &it2->primitive() );

                if ( CGAL::do_overlap( it->primitive().bbox(), it2->primitive().bbox() ) &&
                        algorithm::intersects( pa1, pa2 ) ) {
                    intersectsA = true;
                    GeometrySet<Dim> temp;
                    algorithm::intersection( pa1, pa2, temp );
                    std::copy( temp.points().begin(), temp.points().end(), std::back_inserter( points ) );
                    // erase it2
                    points.erase( it2 );
                    break;
                }
            }

            if ( ! intersectsA ) {
                output.addPrimitive( it->primitive() );
            }

            // suppress A
            it = points.erase( it );
        }
    }
    {
        typedef std::list< CollectionElement<typename Segment_d<Dim>::Type> > SegmentList;
        SegmentList segments;

        std::copy( input.segments().begin(), input.segments().end(), std::back_inserter( segments ) );

        typename SegmentList::iterator it = segments.begin();

        while ( it != segments.end() ) {
            bool intersectsA = false;

            for ( typename SegmentList::iterator it2 = segments.begin(); it2 != segments.end(); ++it2 ) {
                if ( it == it2 ) {
                    continue;
                }

                PrimitiveHandle<Dim> pa1( &it->primitive() );
                PrimitiveHandle<Dim> pa2( &it2->primitive() );

                if ( CGAL::do_overlap( it->primitive().bbox(), it2->primitive().bbox() ) &&
                        algorithm::intersects( pa1, pa2 ) ) {
                    intersectsA = true;
                    GeometrySet<Dim> temp;
                    algorithm::intersection( pa1, pa2, temp );
                    std::copy( temp.segments().begin(), temp.segments().end(), std::back_inserter( segments ) );
                    // erase it2
                    segments.erase( it2 );
                    break;
                }
            }

            if ( ! intersectsA ) {
                output.addPrimitive( it->primitive() );
            }

            // suppress A
            it = segments.erase( it );
        }
    }
}