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