extern "C" sfcgal_geometry_t* sfcgal_geometry_make_solid( const sfcgal_geometry_t* ga ) { const SFCGAL::Geometry* g = reinterpret_cast<const SFCGAL::Geometry*>(ga); if ( g->geometryTypeId() != SFCGAL::TYPE_POLYHEDRALSURFACE ) { SFCGAL_ERROR( "make_solid() only applies to polyhedral surfaces" ); return 0; } return static_cast<SFCGAL::Geometry*>(new SFCGAL::Solid( g->as<const SFCGAL::PolyhedralSurface>() )); }
extern "C" sfcgal_geometry_type_t sfcgal_geometry_type_id( const sfcgal_geometry_t* geom ) { try { return ( sfcgal_geometry_type_t )reinterpret_cast<const SFCGAL::Geometry*>( geom )->geometryTypeId(); } catch( std::exception& e ) { SFCGAL_ERROR( "%s", e.what() ); return SFCGAL_TYPE_POINT; // to avoid warning } }
/** * Get geometry orientation. * Returns: * -1 for a counter clock wise orientation, * 1 for a clock wise orientation, * 0 for invalid or undetermined orientation */ extern "C" int sfcgal_geometry_orientation( const sfcgal_geometry_t* ga ) { const SFCGAL::Geometry* g = reinterpret_cast<const SFCGAL::Geometry*>(ga); if ( g->geometryTypeId() != SFCGAL::TYPE_POLYGON ) { SFCGAL_ERROR( "orientation() only applies to polygons" ); return -1; } bool r; try { r = g->as<const SFCGAL::Polygon>().isCounterClockWiseOriented(); } catch ( std::exception& e ) { SFCGAL_WARNING( "During orientation(A) :" ); SFCGAL_WARNING( " with A: %s", ((const SFCGAL::Geometry*)(ga))->asText().c_str() ); SFCGAL_ERROR( "%s", e.what() ); return -1.0; } return r ? -1 : 1; }
extern "C" int sfcgal_geometry_is_planar( const sfcgal_geometry_t* ga ) { const SFCGAL::Geometry* g = reinterpret_cast<const SFCGAL::Geometry*>(ga); if ( g->geometryTypeId() != SFCGAL::TYPE_POLYGON ) { SFCGAL_ERROR( "is_planar() only applies to polygons" ); return -1; } bool r; try { r = SFCGAL::algorithm::hasPlane3D< SFCGAL::Kernel >( g->as< const SFCGAL::Polygon >() ); } catch ( std::exception& e ) { SFCGAL_WARNING( "During is_planar(A) :" ); SFCGAL_WARNING( " with A: %s", ((const SFCGAL::Geometry*)(ga))->asText().c_str() ); SFCGAL_ERROR( "%s", e.what() ); return -1.0; } return r ? 1 : 0; }
extern "C" sfcgal_geometry_t* sfcgal_io_read_wkt( const char* str, size_t len ) { std::auto_ptr<SFCGAL::Geometry> g; try { g = SFCGAL::io::readWkt( str, len ); } catch ( std::exception& e ) { SFCGAL_ERROR( "%s", e.what() ); return 0; } return g.release(); }
extern "C" sfcgal_prepared_geometry_t* sfcgal_io_read_ewkt( const char* str, size_t len ) { std::auto_ptr<SFCGAL::PreparedGeometry> g; try { g = SFCGAL::io::readEwkt( str, len ); } catch ( std::exception& e ) { SFCGAL_ERROR( "%s", e.what() ); return 0; } SFCGAL::PreparedGeometry* pg = g.release(); return pg; }
extern "C" sfcgal_geometry_t* sfcgal_geometry_minkowski_sum( const sfcgal_geometry_t* ga, const sfcgal_geometry_t* gb ) { const SFCGAL::Geometry* g1 = reinterpret_cast<const SFCGAL::Geometry*>(ga); const SFCGAL::Geometry* g2 = reinterpret_cast<const SFCGAL::Geometry*>(gb); if ( g2->geometryTypeId() != SFCGAL::TYPE_POLYGON ) { SFCGAL_ERROR( "minkowski_sum(): the second argument must be a polygon" ); return 0; } std::auto_ptr<SFCGAL::MultiPolygon> sum; try { sum = SFCGAL::algorithm::minkowskiSum( *g1, g2->as<const SFCGAL::Polygon>() ); } catch ( std::exception& e ) { SFCGAL_WARNING( "During minkowski_sum(A,B):" ); SFCGAL_WARNING( " with A: %s", ((const SFCGAL::Geometry*)(ga))->asText().c_str() ); SFCGAL_WARNING( " and B: %s", ((const SFCGAL::Geometry*)(gb))->asText().c_str() ); SFCGAL_ERROR( "%s", e.what() ); return 0; } return sum.release(); }
extern "C" sfcgal_prepared_geometry_t* sfcgal_io_read_binary_prepared( const char* str, size_t len ) { std::string sstr( str, len ); std::auto_ptr<SFCGAL::PreparedGeometry> g; try { g = SFCGAL::io::readBinaryPrepared( sstr ); } catch ( std::exception& e ) { SFCGAL_WARNING( "During read_binary_prepared" ); SFCGAL_ERROR( "%s", e.what() ); return 0; } return g.release(); }
extern "C" sfcgal_geometry_t* sfcgal_geometry_offset_polygon( const sfcgal_geometry_t* ga, double offset ) { const SFCGAL::Geometry* g1 = reinterpret_cast<const SFCGAL::Geometry*>(ga); std::auto_ptr<SFCGAL::MultiPolygon> mp; try { mp = SFCGAL::algorithm::offset( *g1, offset ); } catch ( std::exception& e ) { SFCGAL_WARNING( "During offset(A,%g):", offset ); SFCGAL_WARNING( " with A: %s", ((const SFCGAL::Geometry*)(ga))->asText().c_str() ); SFCGAL_ERROR( "%s", e.what() ); return 0; } return mp.release(); }
extern "C" sfcgal_geometry_t* sfcgal_geometry_force_rhr( const sfcgal_geometry_t* ga ) { const SFCGAL::Geometry* g = reinterpret_cast<const SFCGAL::Geometry*>(ga); SFCGAL::Geometry* gb = g->clone(); SFCGAL::transform::ForceOrderPoints force( /* ccw */ false ); try { gb->accept( force ); } catch ( std::exception& e ) { SFCGAL_WARNING( "During force_rhr(A) :" ); SFCGAL_WARNING( " with A: %s", ((const SFCGAL::Geometry*)(ga))->asText().c_str() ); SFCGAL_ERROR( "%s", e.what() ); return 0; } return gb; }
extern "C" sfcgal_geometry_t* sfcgal_geometry_triangulate_2dz( const sfcgal_geometry_t* ga ) { const SFCGAL::Geometry* g = reinterpret_cast<const SFCGAL::Geometry*>(ga); SFCGAL::TriangulatedSurface* surf = new SFCGAL::TriangulatedSurface; try { SFCGAL::triangulate::ConstraintDelaunayTriangulation cdt; SFCGAL::triangulate::triangulate2DZ( *g, cdt ); cdt.getTriangles( *surf ); } catch ( std::exception& e ) { SFCGAL_WARNING( "During triangulate_2d(A) :" ); SFCGAL_WARNING( " with A: %s", ((const SFCGAL::Geometry*)(ga))->asText().c_str() ); SFCGAL_ERROR( "%s", e.what() ); return 0; } return static_cast<SFCGAL::Geometry*>(surf); }
extern "C" sfcgal_geometry_t* sfcgal_geometry_extrude( const sfcgal_geometry_t* ga, double x, double y, double z ) { const SFCGAL::Geometry* g = reinterpret_cast<const SFCGAL::Geometry*>(ga); SFCGAL::Geometry* gb = g->clone(); SFCGAL::transform::ForceZOrderPoints forceZ; std::auto_ptr<SFCGAL::Geometry> result; try { gb->accept( forceZ ); result = SFCGAL::algorithm::extrude( *gb, x, y, z ); } catch ( std::exception& e ) { SFCGAL_WARNING( "During extrude(A, %g, %g, %g) :", x, y, z ); SFCGAL_WARNING( " with A: %s", ((const SFCGAL::Geometry*)(ga))->asText().c_str() ); SFCGAL_ERROR( "%s", e.what() ); return 0; } return result.release(); }
extern "C" sfcgal_geometry_t* sfcgal_geometry_round( const sfcgal_geometry_t* ga, int scale ) { const SFCGAL::Geometry* g = reinterpret_cast<const SFCGAL::Geometry*>(ga); SFCGAL::Geometry* gb = g->clone(); // SFCGAL_WARNING( "geom: %s %s", gb->asText().c_str(), typeid(g).name() ); SFCGAL::transform::RoundTransform roundT( scale ); try { gb->accept( roundT ); } catch ( std::exception& e ) { SFCGAL_WARNING( "During round(A):" ); SFCGAL_WARNING( " with A: %s", ((const SFCGAL::Geometry*)(ga))->asText().c_str() ); SFCGAL_ERROR( "%s", e.what() ); return 0; } // SFCGAL_WARNING( "processed geom: %s", gb->asText().c_str() ); return gb; }