BRL-CAD
chull.h
Go to the documentation of this file.
1/* C H U L L . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2023 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20
21/*----------------------------------------------------------------------*/
22/* @file chull.h */
23/** @addtogroup bg_chull */
24/** @{ */
25
26/**
27 * @brief Routines for the computation of convex and concave hulls in 2D and 3D
28 */
29
30#ifndef BG_CHULL_H
31#define BG_CHULL_H
32
33#include "common.h"
34#include "vmath.h"
35#include "bg/defines.h"
36
37__BEGIN_DECLS
38
39/**
40 * @brief
41 * Melkman's 2D simple polyline O(n) convex hull algorithm
42 *
43 * On-line construction of the convex hull of a simple polyline
44 * Melkman, Avraham A. Information Processing Letters 25.1 (1987): 11-12.
45 *
46 * See also <a href="http://geomalgorithms.com/a12-_hull-3.html">http://geomalgorithms.com/a12-_hull-3.html</a>
47 *
48 * @param[out] hull convex hull array vertices in ccw orientation (max is n)
49 * @param polyline The points defining the input polyline, stored with ccw orientation
50 * @param n the number of points in polyline
51 * @return the number of points in the output hull array
52 */
53BG_EXPORT int bg_polyline_2d_chull(point2d_t** hull, const point2d_t* polyline, int n);
54
55BG_EXPORT int bg_polyline_2d_chull2(int** hull, const int *polyline, int n, const point2d_t* pnts);
56
57
58/**
59 * @brief
60 * Return an array that contains just the set of 2D points active in the polyline.
61 *
62 * @param[out] opoly array containing just the active points in the polyline.
63 * @param[in] n number of points in polyline
64 * @param[in] polyline indices of polyline points in pnts array
65 * @param[in] pnts array that holds the points defining the polyline
66 *
67 * The output array will store the points in polyline order, avoiding the need
68 * for an explicit index array of point positions to define the polyline.
69 *
70 * @return number of points in opoly if calculation was successful
71 * @return -1 if error
72 */
73BG_EXPORT extern int bg_2d_polyline_gc(point2d_t **opoly, int n, int *polyline, const point2d_t *pnts);
74
75
76/**
77 * @brief
78 * Find 2D convex hull for unordered co-planar point sets
79 *
80 * The monotone chain algorithm's sorting approach is used to do
81 * the initial ordering of the points:
82 *
83 * Another efficient algorithm for convex hulls in two dimensions.
84 * Andrew, A. M. Information Processing Letters 9.5 (1979): 216-219.
85 *
86 * See also <a href="http://geomalgorithms.com/a10-_hull-1.html">http://geomalgorithms.com/a10-_hull-1.html</a>
87 *
88 * From there, instead of using the monotonic chain hull assembly
89 * step, recognize that the points thus ordered can be viewed as
90 * defining a simple polyline and use Melkman's algorithm for the
91 * hull building.
92 *
93 * @param[out] hull 2D convex hull array vertices in ccw orientation (max is n)
94 * @param points_2d The input 2d points for which a convex hull will be built
95 * @param n the number of points in the input set
96 * @return the number of points in the output hull array or zero if error.
97 */
98BG_EXPORT int bg_2d_chull(point2d_t** hull, const point2d_t* points_2d, int n);
99
100
101BG_EXPORT int bg_2d_chull2(int** hull, const point2d_t* points_2d, int n);
102
103/**
104 * @brief
105 * Find 3D coplanar point convex hull for unordered co-planar point sets
106 *
107 * This function assumes an input an array of 3D points which are coplanar
108 * in some arbitrary plane. This function:
109 *
110 * 1. Finds the plane that fits the points and picks an origin, x-axis and y-axis
111 * which allow 2D coordinates for all points to be calculated.
112 * 2. Calls 2D routines on the array found by step 1 to get a 2D convex hull
113 * 3. Translates the resultant 2D hull points back into 3D points so the hull array
114 * contains the bounding hull expressed in the 3D coordinate space of the
115 * original points.
116 *
117 * @param[out] hull convex hull array vertices using 3-space coordinates in ccw orientation (max is n)
118 * @param points_3d The input points for which a convex hull will be built
119 * @param n the number of points in the input set
120 * @return the number of points in the output hull array
121 */
122BG_EXPORT int bg_3d_coplanar_chull(point_t** hull, const point_t* points_3d, int n);
123
124
125BG_EXPORT int bg_3d_coplanar_chull2(int** hull, const point_t* points_3d, int n);
126
127/**
128 * @brief
129 * Find 3D point convex hull for unordered point sets
130 *
131 * This routine computes the convex hull of a three dimensional point set and
132 * returns the set of vertices and triangular faces that define that hull, as
133 * well as the numerical count of vertices and faces in the hull.
134 *
135 * @param[out] faces set of faces in the convex hull, stored as integer indices to the vertices. The first three indices are the vertices of the face, the second three define the second face, and so forth.
136 * @param[out] num_faces the number of faces in the faces array
137 * @param[out] vertices the set of vertices used by the convex hull.
138 * @param[out] num_vertices the number of vertices in the convex hull.
139 * @param input_points_3d The input points for which a convex hull will be built
140 * @param num_input_pnts the number of points in the input set
141 * @return dimension of output (3 is three dimensional faces and hulls, 2 is a polygon hull in a plane, etc.)
142 *
143 * This routine is based off of Antti Kuukka's implementation of the QuickHull
144 * algorithm: https://github.com/akuukka/quickhull implementation
145 */
146BG_EXPORT int bg_3d_chull(int **faces, int *num_faces, point_t **vertices, int *num_vertices,
147 const point_t *input_points_3d, int num_input_pnts);
148
149
150__END_DECLS
151
152#endif /* BG_CHULL_H */
153/** @} */
154/*
155 * Local Variables:
156 * mode: C
157 * tab-width: 8
158 * indent-tabs-mode: t
159 * c-file-style: "stroustrup"
160 * End:
161 * ex: shiftwidth=4 tabstop=8
162 */
Header file for the BRL-CAD common definitions.
int bg_3d_coplanar_chull(point_t **hull, const point_t *points_3d, int n)
Find 3D coplanar point convex hull for unordered co-planar point sets.
int bg_2d_polyline_gc(point2d_t **opoly, int n, int *polyline, const point2d_t *pnts)
Return an array that contains just the set of 2D points active in the polyline.
int bg_2d_chull(point2d_t **hull, const point2d_t *points_2d, int n)
Find 2D convex hull for unordered co-planar point sets.
int bg_3d_chull(int **faces, int *num_faces, point_t **vertices, int *num_vertices, const point_t *input_points_3d, int num_input_pnts)
Find 3D point convex hull for unordered point sets.
int bg_polyline_2d_chull2(int **hull, const int *polyline, int n, const point2d_t *pnts)
int bg_2d_chull2(int **hull, const point2d_t *points_2d, int n)
int bg_polyline_2d_chull(point2d_t **hull, const point2d_t *polyline, int n)
Routines for the computation of convex and concave hulls in 2D and 3D.
int bg_3d_coplanar_chull2(int **hull, const point_t *points_3d, int n)
void float float int * n
Definition: tig.h:74
fastf_t point2d_t[ELEMENTS_PER_POINT2D]
2-tuple point
Definition: vmath.h:339
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition: vmath.h:351
fundamental vector, matrix, quaternion math macros