BRL-CAD
Loading...
Searching...
No Matches
polygon.h
Go to the documentation of this file.
1/* P O L Y G O N . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2025 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/** @addtogroup bv_polygon
23 *
24 * @brief Functions for working with polygons
25 */
26/* @file polygon.h */
27/** @{ */
28
29#ifndef BV_POLYGON_H
30#define BV_POLYGON_H
31
32#include "common.h"
33#include "vmath.h"
34#include "bu/color.h"
35#include "bv/defines.h"
36#include "bg/polygon.h"
37#include "bg/polygon_types.h"
38
39__BEGIN_DECLS
40
41/* View polygon logic and types */
42
43#define BV_POLYGON_GENERAL 0
44#define BV_POLYGON_CIRCLE 1
45#define BV_POLYGON_ELLIPSE 2
46#define BV_POLYGON_RECTANGLE 3
47#define BV_POLYGON_SQUARE 4
48
49struct bv_polygon {
50 int type;
51 int fill_flag; /* set to shade the interior */
57 point_t origin_point; /* For non-general polygons */
58
59 /* We stash the view plane creation, so we know how to return
60 * to it for future 2D alterations */
62
63 /* Offset of polygon plane from the view plane. Allows for moving
64 * the polygon "towards" and "away from" the viewer. */
66
67 /* Actual polygon info */
69
70 /* Arbitrary data */
71 void *u_data;
72};
73
74// Given a polygon, create a scene object
75BV_EXPORT extern struct bv_scene_obj *bv_create_polygon_obj(struct bview *v, int flags, struct bv_polygon *p);
76
77// Creates a scene object with a default polygon
78BV_EXPORT extern struct bv_scene_obj *bv_create_polygon(struct bview *v, int flags, int type, point_t *fp);
79
80// Various update modes have similar logic - we pass in the flags to the update
81// routine to enable/disable specific portions of the overall flow.
82#define BV_POLYGON_UPDATE_DEFAULT 0
83#define BV_POLYGON_UPDATE_PROPS_ONLY 1
84#define BV_POLYGON_UPDATE_PT_SELECT 2
85#define BV_POLYGON_UPDATE_PT_SELECT_CLEAR 3
86#define BV_POLYGON_UPDATE_PT_MOVE 4
87#define BV_POLYGON_UPDATE_PT_APPEND 5
88BV_EXPORT extern int bv_update_polygon(struct bv_scene_obj *s, struct bview *v, int utype);
89
90// Update just the scene obj vlist, without altering the source polygon
91BV_EXPORT extern void bv_polygon_vlist(struct bv_scene_obj *s);
92
93// Find the closest polygon obj to a point
94BV_EXPORT extern struct bv_scene_obj *bv_select_polygon(struct bu_ptbl *objs, point_t *cp);
95
96BV_EXPORT extern int bv_move_polygon(struct bv_scene_obj *s, point_t *cp, point_t *pp);
97BV_EXPORT extern struct bv_scene_obj *bv_dup_view_polygon(const char *nname, struct bv_scene_obj *s);
98
99// Copy a bv polygon. Note that this also performs a
100// view sync - if the user is copying the polygon into
101// another view, they will have to update the output's
102// bview to match their target view.
103BV_EXPORT extern void bv_polygon_cpy(struct bv_polygon *dest , struct bv_polygon *src);
104
105// Calculate a suggested default fill delta based on the polygon structure. The
106// idea is to try and strike a balance between line count and having enough fill
107// lines to highlight interior holes.
108BV_EXPORT extern int bv_polygon_calc_fdelta(struct bv_polygon *p);
109
110BV_EXPORT extern struct bg_polygon *
111bv_polygon_fill_segments(struct bg_polygon *poly, plane_t *vp, vect2d_t line_slope, fastf_t line_spacing);
112
113// For all polygon bv_scene_objs in the objs table, apply the specified boolean
114// op using p and replace the original polygon geometry in objs with the
115// results (NOTE: p will not act on itself if it is in objs):
116//
117// u : objs[i] u p (unions p with objs[i])
118// - : objs[i] - p (removes p from objs[i])
119// + : objs[i] + p (intersects p with objs[i])
120//
121// At a data structure level, what happens is the bv_polygon geometry stored in
122// the bv_polygon stored as the data entry for a bv_scene_obj is replaced. The
123// bv_scene_obj and bv_polygon pointers should remain valid, but the bv_polygon
124// contained in bv_polygon is replaced - calling code should not rely on the
125// bv_polygon pointer remaining the same after a boolean operation.
126BV_EXPORT extern int bv_polygon_csg(struct bv_scene_obj *target, struct bv_scene_obj *stencil, bg_clip_t op);
127
128__END_DECLS
129
130#endif /* BV_POLYGON_H */
131/** @} */
132/*
133 * Local Variables:
134 * mode: C
135 * tab-width: 8
136 * indent-tabs-mode: t
137 * c-file-style: "stroustrup"
138 * End:
139 * ex: shiftwidth=4 tabstop=8
140 */
Header file for the BRL-CAD common definitions.
bg_clip_t
Functions for working with polygons.
int bv_polygon_csg(struct bv_scene_obj *target, struct bv_scene_obj *stencil, bg_clip_t op)
struct bv_scene_obj * bv_create_polygon_obj(struct bview *v, int flags, struct bv_polygon *p)
void bv_polygon_cpy(struct bv_polygon *dest, struct bv_polygon *src)
struct bv_scene_obj * bv_create_polygon(struct bview *v, int flags, int type, point_t *fp)
void bv_polygon_vlist(struct bv_scene_obj *s)
int bv_move_polygon(struct bv_scene_obj *s, point_t *cp, point_t *pp)
int bv_update_polygon(struct bv_scene_obj *s, struct bview *v, int utype)
int bv_polygon_calc_fdelta(struct bv_polygon *p)
struct bv_scene_obj * bv_select_polygon(struct bu_ptbl *objs, point_t *cp)
struct bg_polygon * bv_polygon_fill_segments(struct bg_polygon *poly, plane_t *vp, vect2d_t line_slope, fastf_t line_spacing)
struct bv_scene_obj * bv_dup_view_polygon(const char *nname, struct bv_scene_obj *s)
double fastf_t
fastest 64-bit (or larger) floating point type
Definition vmath.h:334
fastf_t plane_t[ELEMENTS_PER_PLANE]
Definition of a plane equation.
Definition vmath.h:397
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:355
fastf_t vect2d_t[ELEMENTS_PER_VECT2D]
2-tuple vector
Definition vmath.h:337
Definition ptbl.h:53
vect2d_t fill_dir
Definition polygon.h:52
plane_t vp
Definition polygon.h:61
struct bg_polygon polygon
Definition polygon.h:68
fastf_t fill_delta
Definition polygon.h:53
int fill_flag
Definition polygon.h:51
fastf_t vZ
Definition polygon.h:65
long curr_point_i
Definition polygon.h:56
void * u_data
Definition polygon.h:71
int type
Definition polygon.h:50
long curr_contour_i
Definition polygon.h:55
point_t origin_point
Definition polygon.h:57
struct bu_color fill_color
Definition polygon.h:54
fundamental vector, matrix, quaternion math macros