File sfcgal_c.h
File List > capi > sfcgal_c.h
Go to the documentation of this file
// Copyright (c) 2012-2013, IGN France.
// Copyright (c) 2012-2022, Oslandia.
// SPDX-License-Identifier: LGPL-2.0-or-later
#ifndef _SFCGAL_CAPI_H_
#define _SFCGAL_CAPI_H_
#include "SFCGAL/config.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
// TODO : return of errors ! => error handler
/*--------------------------------------------------------------------------------------*
*
* Support for SFCGAL::Geometry class hierarchy
*
*--------------------------------------------------------------------------------------*/
typedef void sfcgal_geometry_t;
typedef enum {
// TYPE_GEOMETRY = 0, //abstract
SFCGAL_TYPE_POINT = 1,
SFCGAL_TYPE_LINESTRING = 2,
SFCGAL_TYPE_POLYGON = 3,
SFCGAL_TYPE_MULTIPOINT = 4,
SFCGAL_TYPE_MULTILINESTRING = 5,
SFCGAL_TYPE_MULTIPOLYGON = 6,
SFCGAL_TYPE_GEOMETRYCOLLECTION = 7,
// TYPE_CIRCULARSTRING = 8,
// TYPE_COMPOUNDCURVE = 9,
// TYPE_CURVEPOLYGON = 10,
// TYPE_MULTICURVE = 11, //abstract
// TYPE_MULTISURFACE = 12, //abstract
// TYPE_CURVE = 13, //abstract
// TYPE_SURFACE = 14, //abstract
SFCGAL_TYPE_POLYHEDRALSURFACE = 15,
SFCGAL_TYPE_TRIANGULATEDSURFACE = 16,
SFCGAL_TYPE_TRIANGLE = 17,
//-- not official codes
SFCGAL_TYPE_SOLID = 101,
SFCGAL_TYPE_MULTISOLID = 102
} sfcgal_geometry_type_t;
SFCGAL_API void
sfcgal_set_geometry_validation(int enabled);
SFCGAL_API sfcgal_geometry_type_t
sfcgal_geometry_type_id(const sfcgal_geometry_t *);
SFCGAL_API int
sfcgal_geometry_is_valid(const sfcgal_geometry_t *);
SFCGAL_API int
sfcgal_geometry_is_valid_detail(const sfcgal_geometry_t *geom,
char **invalidity_reason,
sfcgal_geometry_t **invalidity_location);
SFCGAL_API int
sfcgal_geometry_is_3d(const sfcgal_geometry_t *);
SFCGAL_API int
sfcgal_geometry_is_measured(const sfcgal_geometry_t *);
SFCGAL_API int
sfcgal_geometry_is_empty(const sfcgal_geometry_t *);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_clone(const sfcgal_geometry_t *);
SFCGAL_API void
sfcgal_geometry_delete(sfcgal_geometry_t *);
SFCGAL_API void
sfcgal_geometry_as_text(const sfcgal_geometry_t *, char **buffer, size_t *len);
SFCGAL_API void
sfcgal_geometry_as_text_decim(const sfcgal_geometry_t *, int numDecimals,
char **buffer, size_t *len);
SFCGAL_API void
sfcgal_geometry_as_wkb(const sfcgal_geometry_t *, char **buffer, size_t *len);
SFCGAL_API void
sfcgal_geometry_as_hexwkb(const sfcgal_geometry_t *, char **buffer,
size_t *len);
SFCGAL_API void
sfcgal_geometry_as_vtk(const sfcgal_geometry_t *, char **buffer, size_t *len);
SFCGAL_API void
sfcgal_geometry_as_vtk_file(const sfcgal_geometry_t *, const char *filename);
SFCGAL_API void
sfcgal_geometry_as_obj_file(const sfcgal_geometry_t *, const char *filename);
SFCGAL_API void
sfcgal_geometry_as_obj(const sfcgal_geometry_t *, char **buffer, size_t *len);
SFCGAL_API sfcgal_geometry_t *
sfcgal_point_create();
SFCGAL_API sfcgal_geometry_t *
sfcgal_point_create_from_xy(double x, double y);
SFCGAL_API sfcgal_geometry_t *
sfcgal_point_create_from_xyz(double x, double y, double z);
SFCGAL_API sfcgal_geometry_t *
sfcgal_point_create_from_xym(double x, double y, double m);
SFCGAL_API sfcgal_geometry_t *
sfcgal_point_create_from_xyzm(double x, double y, double z, double m);
SFCGAL_API double
sfcgal_point_x(const sfcgal_geometry_t *);
SFCGAL_API double
sfcgal_point_y(const sfcgal_geometry_t *);
SFCGAL_API double
sfcgal_point_z(const sfcgal_geometry_t *);
SFCGAL_API double
sfcgal_point_m(const sfcgal_geometry_t *);
SFCGAL_API sfcgal_geometry_t *
sfcgal_linestring_create();
SFCGAL_API size_t
sfcgal_linestring_num_points(const sfcgal_geometry_t *linestring);
SFCGAL_API const sfcgal_geometry_t *
sfcgal_linestring_point_n(const sfcgal_geometry_t *linestring, size_t i);
SFCGAL_API void
sfcgal_linestring_add_point(sfcgal_geometry_t *linestring,
sfcgal_geometry_t *point);
SFCGAL_API sfcgal_geometry_t *
sfcgal_triangle_create();
SFCGAL_API sfcgal_geometry_t *
sfcgal_triangle_create_from_points(const sfcgal_geometry_t *pta,
const sfcgal_geometry_t *ptb,
const sfcgal_geometry_t *ptc);
SFCGAL_API const sfcgal_geometry_t *
sfcgal_triangle_vertex(const sfcgal_geometry_t *triangle, int i);
SFCGAL_API void
sfcgal_triangle_set_vertex(sfcgal_geometry_t *triangle, int i,
const sfcgal_geometry_t *vertex);
SFCGAL_API void
sfcgal_triangle_set_vertex_from_xy(sfcgal_geometry_t *triangle, int i, double x,
double y);
SFCGAL_API void
sfcgal_triangle_set_vertex_from_xyz(sfcgal_geometry_t *triangle, int i,
double x, double y, double z);
SFCGAL_API sfcgal_geometry_t *
sfcgal_polygon_create();
SFCGAL_API sfcgal_geometry_t *
sfcgal_polygon_create_from_exterior_ring(sfcgal_geometry_t *ring);
SFCGAL_API const sfcgal_geometry_t *
sfcgal_polygon_exterior_ring(const sfcgal_geometry_t *polygon);
SFCGAL_API size_t
sfcgal_polygon_num_interior_rings(const sfcgal_geometry_t *polygon);
SFCGAL_API const sfcgal_geometry_t *
sfcgal_polygon_interior_ring_n(const sfcgal_geometry_t *polygon, size_t i);
SFCGAL_API void
sfcgal_polygon_add_interior_ring(sfcgal_geometry_t *polygon,
sfcgal_geometry_t *ring);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_collection_create();
SFCGAL_API size_t
sfcgal_geometry_collection_num_geometries(const sfcgal_geometry_t *collection);
SFCGAL_API const sfcgal_geometry_t *
sfcgal_geometry_collection_geometry_n(const sfcgal_geometry_t *collection,
size_t i);
SFCGAL_API void
sfcgal_geometry_collection_add_geometry(sfcgal_geometry_t *collection,
sfcgal_geometry_t *geometry);
SFCGAL_API sfcgal_geometry_t *
sfcgal_multi_point_create();
SFCGAL_API sfcgal_geometry_t *
sfcgal_multi_linestring_create();
SFCGAL_API sfcgal_geometry_t *
sfcgal_multi_polygon_create();
SFCGAL_API sfcgal_geometry_t *
sfcgal_polyhedral_surface_create();
SFCGAL_API size_t
sfcgal_polyhedral_surface_num_polygons(const sfcgal_geometry_t *polyhedral);
SFCGAL_API const sfcgal_geometry_t *
sfcgal_polyhedral_surface_polygon_n(const sfcgal_geometry_t *polyhedral,
size_t i);
SFCGAL_API void
sfcgal_polyhedral_surface_add_polygon(sfcgal_geometry_t *polyhedral,
sfcgal_geometry_t *polygon);
SFCGAL_API sfcgal_geometry_t *
sfcgal_triangulated_surface_create();
SFCGAL_API size_t
sfcgal_triangulated_surface_num_triangles(const sfcgal_geometry_t *tin);
SFCGAL_API const sfcgal_geometry_t *
sfcgal_triangulated_surface_triangle_n(const sfcgal_geometry_t *tin, size_t i);
SFCGAL_API void
sfcgal_triangulated_surface_add_triangle(sfcgal_geometry_t *tin,
sfcgal_geometry_t *triangle);
SFCGAL_API sfcgal_geometry_t *
sfcgal_solid_create();
SFCGAL_API sfcgal_geometry_t *
sfcgal_solid_create_from_exterior_shell(sfcgal_geometry_t *shell);
SFCGAL_API size_t
sfcgal_solid_num_shells(const sfcgal_geometry_t *solid);
SFCGAL_API const sfcgal_geometry_t *
sfcgal_solid_shell_n(const sfcgal_geometry_t *solid, size_t i);
SFCGAL_API void
sfcgal_solid_add_interior_shell(sfcgal_geometry_t *solid,
sfcgal_geometry_t *shell);
SFCGAL_API int
sfcgal_geometry_has_validity_flag(const sfcgal_geometry_t *geom);
SFCGAL_API void
sfcgal_geometry_force_valid(sfcgal_geometry_t *geom, int valid);
/*--------------------------------------------------------------------------------------*
*
* Support for SFCGAL::PreparedGeometry
*
*--------------------------------------------------------------------------------------*/
typedef void sfcgal_prepared_geometry_t;
typedef uint32_t srid_t;
SFCGAL_API sfcgal_prepared_geometry_t *
sfcgal_prepared_geometry_create();
SFCGAL_API sfcgal_prepared_geometry_t *
sfcgal_prepared_geometry_create_from_geometry(sfcgal_geometry_t *geometry,
srid_t srid);
SFCGAL_API void
sfcgal_prepared_geometry_delete(sfcgal_prepared_geometry_t *prepared);
SFCGAL_API const sfcgal_geometry_t *
sfcgal_prepared_geometry_geometry(const sfcgal_prepared_geometry_t *prepared);
SFCGAL_API void
sfcgal_prepared_geometry_set_geometry(sfcgal_prepared_geometry_t *prepared,
sfcgal_geometry_t *geometry);
SFCGAL_API srid_t
sfcgal_prepared_geometry_srid(const sfcgal_prepared_geometry_t *prepared);
SFCGAL_API void
sfcgal_prepared_geometry_set_srid(sfcgal_prepared_geometry_t *prepared, srid_t);
SFCGAL_API void
sfcgal_prepared_geometry_as_ewkt(const sfcgal_prepared_geometry_t *prepared,
int num_decimals, char **buffer, size_t *len);
/*--------------------------------------------------------------------------------------*
*
* I/O functions
*
*--------------------------------------------------------------------------------------*/
SFCGAL_API sfcgal_geometry_t *
sfcgal_io_read_wkt(const char *, size_t len);
SFCGAL_API sfcgal_prepared_geometry_t *
sfcgal_io_read_ewkt(const char *, size_t len);
SFCGAL_API sfcgal_geometry_t *
sfcgal_io_read_wkb(const char *, size_t len);
/* allocates into char**, must be freed by the caller */
SFCGAL_API void
sfcgal_io_write_binary_prepared(const sfcgal_prepared_geometry_t *, char **,
size_t *);
SFCGAL_API sfcgal_prepared_geometry_t *
sfcgal_io_read_binary_prepared(const char *, size_t l);
/*--------------------------------------------------------------------------------------*
*
* Spatial processing
*
*--------------------------------------------------------------------------------------*/
SFCGAL_API int
sfcgal_geometry_intersects(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API int
sfcgal_geometry_intersects_3d(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_intersection(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_intersection_3d(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_difference(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_difference_3d(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_union(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_union_3d(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_convexhull(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_convexhull_3d(const sfcgal_geometry_t *geom);
SFCGAL_API double
sfcgal_geometry_volume(const sfcgal_geometry_t *geom);
SFCGAL_API double
sfcgal_geometry_area(const sfcgal_geometry_t *geom);
SFCGAL_API double
sfcgal_geometry_area_3d(const sfcgal_geometry_t *geom);
SFCGAL_API int
sfcgal_geometry_is_planar(const sfcgal_geometry_t *geom);
SFCGAL_API int
sfcgal_geometry_orientation(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_tesselate(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_triangulate_2dz(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_extrude(const sfcgal_geometry_t *geom, double ex, double ey,
double ez);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_make_solid(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_force_lhr(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_force_rhr(const sfcgal_geometry_t *geom);
SFCGAL_API double
sfcgal_geometry_distance(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API double
sfcgal_geometry_distance_3d(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_round(const sfcgal_geometry_t *geom, int r);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_minkowski_sum(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_offset_polygon(const sfcgal_geometry_t *geom, double radius);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_straight_skeleton(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_straight_skeleton_distance_in_m(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_extrude_straight_skeleton(const sfcgal_geometry_t *geom,
double height);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_extrude_polygon_straight_skeleton(const sfcgal_geometry_t *geom,
double building_height,
double roof_height);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_approximate_medial_axis(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_straight_skeleton_partition(const sfcgal_geometry_t *geom,
bool autoOrientation);
SFCGAL_API int
sfcgal_geometry_covers(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API int
sfcgal_geometry_covers_3d(const sfcgal_geometry_t *geom1,
const sfcgal_geometry_t *geom2);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_line_sub_string(const sfcgal_geometry_t *geom, double start,
double end);
#if !_MSC_VER
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_alpha_shapes(const sfcgal_geometry_t *geom, double alpha,
bool allow_holes);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_optimal_alpha_shapes(const sfcgal_geometry_t *geom,
bool allow_holes, size_t nb_components);
#endif
SFCGAL_API sfcgal_geometry_t *
sfcgal_y_monotone_partition_2(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_approx_convex_partition_2(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_greene_approx_convex_partition_2(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_optimal_convex_partition_2(const sfcgal_geometry_t *geom);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_visibility_point(const sfcgal_geometry_t *polygon,
const sfcgal_geometry_t *point);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_visibility_segment(const sfcgal_geometry_t *polygon,
const sfcgal_geometry_t *pointA,
const sfcgal_geometry_t *pointB);
typedef enum {
SFCGAL_BUFFER3D_ROUND,
SFCGAL_BUFFER3D_CYLSPHERE,
SFCGAL_BUFFER3D_FLAT
} sfcgal_buffer3d_type_t;
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_buffer3d(const sfcgal_geometry_t *geom, double radius,
int segments, sfcgal_buffer3d_type_t buffer_type);
/*--------------------------------------------------------------------------------------*
*
* Transformation
*
*--------------------------------------------------------------------------------------*/
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_rotate(const sfcgal_geometry_t *geom, double angle);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_rotate_2d(const sfcgal_geometry_t *geom, double angle,
double cx, double cy);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_rotate_3d(const sfcgal_geometry_t *geom, double angle,
double ax, double ay, double az);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_rotate_3d_around_center(const sfcgal_geometry_t *geom,
double angle, double ax, double ay,
double az, double cx, double cy,
double cz);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_rotate_x(const sfcgal_geometry_t *geom, double angle);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_rotate_y(const sfcgal_geometry_t *geom, double angle);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_rotate_z(const sfcgal_geometry_t *geom, double angle);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_scale(const sfcgal_geometry_t *geom, double s);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_scale_3d(const sfcgal_geometry_t *geom, double sx, double sy,
double sz);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_scale_3d_around_center(const sfcgal_geometry_t *geom, double sx,
double sy, double sz, double cx,
double cy, double cz);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_translate_3d(sfcgal_geometry_t *geom, double dx, double dy,
double dz);
SFCGAL_API sfcgal_geometry_t *
sfcgal_geometry_translate_2d(sfcgal_geometry_t *geom, double dx, double dy);
/*--------------------------------------------------------------------------------------*
*
* Error handling
*
*--------------------------------------------------------------------------------------*/
typedef int (*sfcgal_error_handler_t)(const char *, ...);
SFCGAL_API void
sfcgal_set_error_handlers(sfcgal_error_handler_t warning_handler,
sfcgal_error_handler_t error_handler);
/*--------------------------------------------------------------------------------------*
*
* Memory allocation
*
*--------------------------------------------------------------------------------------*/
typedef void *(*sfcgal_alloc_handler_t)(size_t);
typedef void (*sfcgal_free_handler_t)(void *);
SFCGAL_API void
sfcgal_set_alloc_handlers(sfcgal_alloc_handler_t malloc_handler,
sfcgal_free_handler_t free_handler);
/*--------------------------------------------------------------------------------------*
*
* Init
*
*--------------------------------------------------------------------------------------*/
SFCGAL_API void
sfcgal_init();
SFCGAL_API const char *
sfcgal_version();
SFCGAL_API const char *
sfcgal_full_version();
#ifdef __cplusplus
}
#endif
#endif