Ejemplo n.º 1
0
///
/// Function used to compare geometries
/// FIXME
/// Since we do not have (yet) a real "equals" operator, we only compare points coordinates
bool operator == ( const Geometry& ga, const Geometry& gb )
{
    if ( ga.geometryTypeId() != gb.geometryTypeId() ) {
        return false;
    }

    detail::GetPointsVisitor get_points_a, get_points_b;
    ga.accept( get_points_a );
    gb.accept( get_points_b );

    if ( get_points_a.points.size() != get_points_b.points.size() ) {
        return false;
    }

    for ( size_t i = 0; i < get_points_a.points.size(); ++i ) {
        bool found = false;

        for ( size_t j = 0; j < get_points_b.points.size(); ++j ) {
            const Point& pta = *( get_points_a.points[i] );
            const Point& ptb = *( get_points_b.points[j] );

            if ( pta == ptb ) {
                found = true;
                break;
            }
        }

        if ( ! found ) {
            return false;
        }
    }

    return true;
}
Ejemplo n.º 2
0
void       translate( Geometry& g, const Kernel::Vector_3& v )
{
    transform::AffineTransform3 visitor(
        CGAL::Aff_transformation_3< Kernel >( CGAL::TRANSLATION, v )
    );
    g.accept( visitor ) ;
}
Ejemplo n.º 3
0
// Use of auto_ptr :
// If nothing has to be built, g will be moved to the result without copy and new allocation.
// Otherwise, a new geometry is built and the old one is deleted
std::auto_ptr<Geometry> collectionToMulti( std::auto_ptr<Geometry> g )
{
    if ( ! g->is<GeometryCollection>() ) {
        // not a collection, nothing to do
        return g;
    }

    const GeometryCollection& coll = g->as<GeometryCollection>();

    // if it is empty, do not do anything
    if ( coll.isEmpty() ) {
        return g;
    }

    bool has2d = false;
    bool has3d = false;

    for ( size_t i = 0; i < coll.numGeometries(); ++i ) {
        const Geometry& gi = coll.geometryN( i );

        if ( !has3d && gi.is3D() ) {
            has3d = true;
        }

        if ( !has2d && !gi.is3D() ) {
            has2d = true;
        }

        if ( !gi.isEmpty() && ( gi.geometryTypeId() != TYPE_POLYGON ) &&
                ( gi.geometryTypeId() != TYPE_TRIANGLE ) &&
                ( gi.geometryTypeId() != TYPE_POLYHEDRALSURFACE ) &&
                ( gi.geometryTypeId() != TYPE_TRIANGULATEDSURFACE ) ) {
            // it contains a bad type, abort
            return g;
        }
    }

    bool force3d = has2d && has3d;

    MultiPolygon* ret_geo = new MultiPolygon;

    // copy each geometry
    for ( size_t i = 0; i < coll.numGeometries(); ++i ) {

        Geometry* gi = coll.geometryN( i ).clone();

        if ( force3d && !gi->is3D() ) {
            transform::ForceZ forceZ;
            gi->accept( forceZ );
        }

        switch ( gi->geometryTypeId() ) {
        case TYPE_TRIANGLE:
            ret_geo->addGeometry( Polygon( gi->as<Triangle>() ) );
            break;

        case TYPE_TRIANGULATEDSURFACE: {
            for ( size_t j = 0; j < gi->numGeometries(); ++j ) {
                ret_geo->addGeometry( Polygon( gi->geometryN( j ).as<Triangle>() ) );
            }
        }
        break;

        case TYPE_POLYHEDRALSURFACE: {
            for ( size_t j = 0; j < gi->numGeometries(); ++j ) {
                ret_geo->addGeometry( gi->geometryN( j ) );
            }
        }
        break;

        case TYPE_GEOMETRYCOLLECTION:

            // do not include empty geometrycollection
            if ( gi->isEmpty() ) {
                continue;
            }

        default:
            ret_geo->addGeometry( *gi );
        }
    }

    return std::auto_ptr<Geometry>( ret_geo );
}
Ejemplo n.º 4
0
void force3D( Geometry& g, const Kernel::FT& defaultZ )
{
    transform::ForceZ t( defaultZ ) ;
    g.accept( t ) ;
}