Revision: 64331
http://sourceforge.net/p/brlcad/code/64331
Author: starseeker
Date: 2015-03-03 16:08:21 +0000 (Tue, 03 Mar 2015)
Log Message:
-----------
Prefix the libbn polygon routines that deal with 3d points.
Modified Paths:
--------------
brlcad/trunk/include/bn/polygon.h
brlcad/trunk/src/libbn/polygon.c
brlcad/trunk/src/libged/analyze.c
brlcad/trunk/src/librt/primitives/arbn/arbn.c
brlcad/trunk/src/librt/primitives/bot/bot.c
brlcad/trunk/src/librt/primitives/nmg/nmg.c
Modified: brlcad/trunk/include/bn/polygon.h
===================================================================
--- brlcad/trunk/include/bn/polygon.h 2015-03-03 15:22:21 UTC (rev 64330)
+++ brlcad/trunk/include/bn/polygon.h 2015-03-03 16:08:21 UTC (rev 64331)
@@ -37,60 +37,95 @@
__BEGIN_DECLS
+/*********************************************************
+ Operations on 2D point types
+ *********************************************************/
+
/**
* @brief
- * Calculate the interior area of a polygon.
+ * Test whether a point is inside a 2D polygon
*
+ * Franklin's test for point inclusion within a polygon - see
+ * http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
+ * for more details and the implementation file polygon.c for license info.
+ *
+ * @param[in] npts Number of points pts contains
+ * @param[in] pts Array of points, building a convex polygon. Duplicated points
+ * aren't allowed. The points in the array will be sorted counter-clockwise.
+ * @param[in] test_pt Point to test.
+ *
+ * @return 0 if point is outside polygon
+ * @return 1 if point is inside polygon
+ */
+BN_EXPORT extern int bn_pt_in_polygon(size_t npts, const point2d_t *pts, const
point2d_t *test_pt);
+
+/**
+ * @brief
+ * Triangulate a 2D polygon.
+ *
+ * This routine generates a triangulation of the input polygon using the method
+ * documented in David Eberly's Triangulation by Ear Clipping, section 2:
+ * http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
+ *
+ * The input polygon cannot have holes and must be provided as an array of
+ * counter-clockwise 2D points.
+ *
+ * No points are added as part of this triangulation process - the result uses
+ * only those points in the original polygon, and hence only the face
+ * information is created as output.
+ *
+ * @param[out] faces Set of faces in the triangulation, stored as integer
indices to the pts. The first three indices are the vertices of the first
face, the second three define the second face, and so forth.
+ * @param[out] num_faces Number of faces created
+ * @param[in] npts Number of points pts contains
+ * @param[in] pts Array of points defining a polygon. Duplicated points
+ * aren't allowed. The points in the array will be sorted counter-clockwise.
+ *
+ * @return 0 if triangulation is successful
+ * @return 1 if triangulation is unsuccessful
+ */
+BN_EXPORT extern int bn_polygon_triangulate(int **faces, int *num_faces, const
point2d_t *pts, size_t npts);
+
+
+/*********************************************************
+ Operations on 3D point types - these are assumed to be
+ polygons embedded in 3D planes in space
+ *********************************************************/
+
+/**
+ * @brief
+ * Calculate the interior area of a polygon in a 3D plane in space.
+ *
* If npts > 4, Greens Theorem is used. The polygon mustn't
* be self-intersecting.
*
* @param[out] area The interior area of the polygon
* @param[in] npts Number of point_ts, stored in pts
* @param[in] pts All points of the polygon, sorted counter-clockwise.
- * The array mustn't contain duplicated points.
+ * The array mustn't contain duplicated or non-coplanar points.
*
* @return 0 if calculation was successful
* @return 1 if calculation failed, e.g. because one parameter is a
NULL-pointer
*/
-BN_EXPORT extern int bn_polygon_area(fastf_t *area, size_t npts, const point_t
*pts);
+BN_EXPORT extern int bn_3d_polygon_area(fastf_t *area, size_t npts, const
point_t *pts);
/**
* @brief
- * Calculate the centroid of a non self-intersecting polygon
+ * Calculate the centroid of a non self-intersecting polygon in a 3D plane in
space.
*
* @param[out] cent The centroid of the polygon
* @param[in] npts Number of point_ts, stored in pts
* @param[in] pts all points of the polygon, sorted counter-clockwise.
- * The array mustn't contain duplicated points.
+ * The array mustn't contain duplicated points or non-coplanar points.
*
* @return 0 if calculation was successful
* @return 1 if calculation failed, e.g. because one in-parameter is a
NULL-pointer
*/
-BN_EXPORT extern int bn_polygon_centroid(point_t *cent, size_t npts, const
point_t *pts);
+BN_EXPORT extern int bn_3d_polygon_centroid(point_t *cent, size_t npts, const
point_t *pts);
/**
* @brief
- * Calculate for an array of plane_eqs, which build a polyhedron, the
- * point_t's for each face.
- *
- * @param[out] npts Array, which stores for every face the number of
- * point_ts, added to pts. Needs to be allocated with npts[neqs] already.
- * @param[out] pts 2D-array which stores the point_ts for every
- * face. The array needs to be allocated with pts[neqs][neqs-1] already.
- * @param[in] neqs Number of plane_ts, stored in eqs
- * @param[in] eqs Array, that contains the plane equations, which
- * build the polyhedron
- *
- * @return 0 if calculation was successful
- * @return 1 if calculation failed, e.g. because one parameter is a
NULL-Pointer
- */
-BN_EXPORT extern int bn_polygon_mk_pts_planes(size_t *npts, point_t **pts,
size_t neqs, const plane_t *eqs);
-
-
-/**
- * @brief
* Sort an array of point_ts, building a convex polygon, counter-clockwise
*
*@param[in] npts Number of points, pts contains
@@ -101,52 +136,29 @@
*@return 0 if calculation was successful
*@return 1 if calculation failed, e.g. because pts is a NULL-pointer
*/
-BN_EXPORT extern int bn_polygon_sort_ccw(size_t npts, point_t *pts, plane_t
cmp);
+BN_EXPORT extern int bn_3d_polygon_sort_ccw(size_t npts, point_t *pts, plane_t
cmp);
-/**
- * @brief
- * Test whether a point is inside a 2D polygon
- *
- * Franklin's test for point inclusion within a polygon - see
- * http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
- * for more details and the implementation file polygon.c for license info.
- *
- * @param[in] npts Number of points pts contains
- * @param[in] pts Array of points, building a convex polygon. Duplicated points
- * aren't allowed. The points in the array will be sorted counter-clockwise.
- * @param[in] test_pt Point to test.
- *
- * @return 0 if point is outside polygon
- * @return 1 if point is inside polygon
- */
-BN_EXPORT extern int bn_pt_in_polygon(size_t npts, const point2d_t *pts, const
point2d_t *test_pt);
/**
* @brief
- * Triangulate a 2D polygon.
+ * Calculate for an array of plane_eqs, which build a polyhedron, the
+ * point_t's for each face.
*
- * This routine generates a triangulation of the input polygon using the method
- * documented in David Eberly's Triangulation by Ear Clipping, section 2:
- * http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
+ * @param[out] npts Array, which stores for every face the number of
+ * point_ts, added to pts. Needs to be allocated with npts[neqs] already.
+ * @param[out] pts 2D-array which stores the point_ts for every
+ * face. The array needs to be allocated with pts[neqs][neqs-1] already.
+ * @param[in] neqs Number of plane_ts, stored in eqs
+ * @param[in] eqs Array, that contains the plane equations, which
+ * build the polyhedron
*
- * The input polygon cannot have holes and must be provided as an array of
- * counter-clockwise 2D points.
- *
- * No points are added as part of this triangulation process - the result uses
- * only those points in the original polygon, and hence only the face
- * information is created as output.
- *
- * @param[out] faces Set of faces in the triangulation, stored as integer
indices to the pts. The first three indices are the vertices of the first
face, the second three define the second face, and so forth.
- * @param[out] num_faces Number of faces created
- * @param[in] npts Number of points pts contains
- * @param[in] pts Array of points defining a polygon. Duplicated points
- * aren't allowed. The points in the array will be sorted counter-clockwise.
- *
- * @return 0 if triangulation is successful
- * @return 1 if triangulation is unsuccessful
+ * @return 0 if calculation was successful
+ * @return 1 if calculation failed, e.g. because one parameter is a
NULL-Pointer
*/
-BN_EXPORT extern int bn_polygon_triangulate(int **faces, int *num_faces, const
point2d_t *pts, size_t npts);
+BN_EXPORT extern int bn_3d_polygon_mk_pts_planes(size_t *npts, point_t **pts,
size_t neqs, const plane_t *eqs);
+
+
__END_DECLS
#endif /* BN_POLYGON_H */
Modified: brlcad/trunk/src/libbn/polygon.c
===================================================================
--- brlcad/trunk/src/libbn/polygon.c 2015-03-03 15:22:21 UTC (rev 64330)
+++ brlcad/trunk/src/libbn/polygon.c 2015-03-03 16:08:21 UTC (rev 64331)
@@ -28,7 +28,7 @@
int
-bn_polygon_area(fastf_t *area, size_t npts, const point_t *pts)
+bn_3d_polygon_area(fastf_t *area, size_t npts, const point_t *pts)
{
size_t i;
vect_t v1, v2, tmp, tot = VINIT_ZERO;
@@ -72,7 +72,7 @@
int
-bn_polygon_centroid(point_t *cent, size_t npts, const point_t *pts)
+bn_3d_polygon_centroid(point_t *cent, size_t npts, const point_t *pts)
{
size_t i;
fastf_t x_0 = 0.0;
@@ -137,7 +137,7 @@
int
-bn_polygon_mk_pts_planes(size_t *npts, point_t **pts, size_t neqs, const
plane_t *eqs)
+bn_3d_polygon_mk_pts_planes(size_t *npts, point_t **pts, size_t neqs, const
plane_t *eqs)
{
size_t i, j, k, l;
if (!npts || !pts || neqs < 4 || !eqs)
@@ -173,7 +173,7 @@
HIDDEN int
-sort_ccw(const void *x, const void *y, void *cmp)
+sort_ccw_3d(const void *x, const void *y, void *cmp)
{
vect_t tmp;
VCROSS(tmp, ((fastf_t *)x), ((fastf_t *)y));
@@ -182,11 +182,11 @@
int
-bn_polygon_sort_ccw(size_t npts, point_t *pts, plane_t cmp)
+bn_3d_polygon_sort_ccw(size_t npts, point_t *pts, plane_t cmp)
{
if (!pts || npts < 3)
return 1;
- bu_sort(pts, npts, sizeof(point_t), sort_ccw, &cmp);
+ bu_sort(pts, npts, sizeof(point_t), sort_ccw_3d, &cmp);
return 0;
}
Modified: brlcad/trunk/src/libged/analyze.c
===================================================================
--- brlcad/trunk/src/libged/analyze.c 2015-03-03 15:22:21 UTC (rev 64330)
+++ brlcad/trunk/src/libged/analyze.c 2015-03-03 16:08:21 UTC (rev 64331)
@@ -728,8 +728,8 @@
findang(angles, face->plane_eqn);
/* sort points */
- bn_polygon_sort_ccw(face->npts, face->pts, face->plane_eqn);
- bn_polygon_area(&face->area, face->npts, (const point_t *)face->pts);
+ bn_3d_polygon_sort_ccw(face->npts, face->pts, face->plane_eqn);
+ bn_3d_polygon_area(&face->area, face->npts, (const point_t *)face->pts);
/* store face information for pretty printing */
row->nfields = 8;
@@ -921,7 +921,7 @@
table.rows = (row_t *)bu_calloc(aip->neqn, sizeof(row_t), "analyze_arbn:
rows");
table.nrows = aip->neqn;
- bn_polygon_mk_pts_planes(npts, tmp_pts, aip->neqn, (const plane_t *)eqs);
+ bn_3d_polygon_mk_pts_planes(npts, tmp_pts, aip->neqn, (const plane_t
*)eqs);
for (i = 0; i < aip->neqn; i++) {
vect_t tmp;
Modified: brlcad/trunk/src/librt/primitives/arbn/arbn.c
===================================================================
--- brlcad/trunk/src/librt/primitives/arbn/arbn.c 2015-03-03 15:22:21 UTC
(rev 64330)
+++ brlcad/trunk/src/librt/primitives/arbn/arbn.c 2015-03-03 16:08:21 UTC
(rev 64331)
@@ -1305,11 +1305,11 @@
tmp_pts[i] = faces[i].pts;
HMOVE(eqs[i], faces[i].plane_eqn);
}
- bn_polygon_mk_pts_planes(npts, tmp_pts, aip->neqn, (const plane_t *)eqs);
+ bn_3d_polygon_mk_pts_planes(npts, tmp_pts, aip->neqn, (const plane_t
*)eqs);
for (i = 0; i < aip->neqn; i++) {
faces[i].npts = npts[i];
- bn_polygon_sort_ccw(faces[i].npts, faces[i].pts, faces[i].plane_eqn);
- bn_polygon_area(&faces[i].area, faces[i].npts, (const point_t
*)faces[i].pts);
+ bn_3d_polygon_sort_ccw(faces[i].npts, faces[i].pts, faces[i].plane_eqn);
+ bn_3d_polygon_area(&faces[i].area, faces[i].npts, (const point_t
*)faces[i].pts);
}
bu_free((char *)tmp_pts, "rt_arbn_faces_area: tmp_pts");
bu_free((char *)npts, "rt_arbn_faces_area: npts");
@@ -1363,7 +1363,7 @@
}
rt_arbn_faces_area(faces, aip);
for (i = 0; i < aip->neqn; i++) {
- bn_polygon_centroid(&faces[i].cent, faces[i].npts, (const point_t *)
faces[i].pts);
+ bn_3d_polygon_centroid(&faces[i].cent, faces[i].npts, (const point_t *)
faces[i].pts);
VADD2(arbit_point, arbit_point, faces[i].cent);
}
Modified: brlcad/trunk/src/librt/primitives/bot/bot.c
===================================================================
--- brlcad/trunk/src/librt/primitives/bot/bot.c 2015-03-03 15:22:21 UTC (rev
64330)
+++ brlcad/trunk/src/librt/primitives/bot/bot.c 2015-03-03 16:08:21 UTC (rev
64331)
@@ -5268,8 +5268,8 @@
/* SURFACE AREA */
/* sort points */
- bn_polygon_sort_ccw(face.npts, face.pts, face.plane_eqn);
- bn_polygon_area(&face.area, face.npts, (const point_t *)face.pts);
+ bn_3d_polygon_sort_ccw(face.npts, face.pts, face.plane_eqn);
+ bn_3d_polygon_area(&face.area, face.npts, (const point_t *)face.pts);
/* VOLUME */
VSCALE(tmp, face.plane_eqn, face.area);
Modified: brlcad/trunk/src/librt/primitives/nmg/nmg.c
===================================================================
--- brlcad/trunk/src/librt/primitives/nmg/nmg.c 2015-03-03 15:22:21 UTC (rev
64330)
+++ brlcad/trunk/src/librt/primitives/nmg/nmg.c 2015-03-03 16:08:21 UTC (rev
64331)
@@ -3083,11 +3083,11 @@
tmp_pts[i] = faces[i].pts;
HMOVE(eqs[i], faces[i].plane_eqn);
}
- bn_polygon_mk_pts_planes(npts, tmp_pts, num_faces, (const plane_t *)eqs);
+ bn_3d_polygon_mk_pts_planes(npts, tmp_pts, num_faces, (const plane_t
*)eqs);
for (i = 0; i < num_faces; i++) {
faces[i].npts = npts[i];
- bn_polygon_sort_ccw(faces[i].npts, faces[i].pts, faces[i].plane_eqn);
- bn_polygon_area(&faces[i].area, faces[i].npts, (const point_t
*)faces[i].pts);
+ bn_3d_polygon_sort_ccw(faces[i].npts, faces[i].pts, faces[i].plane_eqn);
+ bn_3d_polygon_area(&faces[i].area, faces[i].npts, (const point_t
*)faces[i].pts);
}
bu_free((char *)tmp_pts, "rt_nmg_faces_area: tmp_pts");
bu_free((char *)npts, "rt_nmg_faces_area: npts");
@@ -3163,7 +3163,7 @@
}
rt_nmg_faces_area(faces, s);
for (i = 0; i < num_faces; i++) {
- bn_polygon_centroid(&faces[i].cent, faces[i].npts, (const point_t *)
faces[i].pts);
+ bn_3d_polygon_centroid(&faces[i].cent, faces[i].npts, (const point_t *)
faces[i].pts);
VADD2(arbit_point, arbit_point, faces[i].cent);
}
VSCALE(arbit_point, arbit_point, (1/num_faces));
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits