BRL-CAD
arb_edit.h
Go to the documentation of this file.
1 /* A R B _ E D I T . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2014 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 /** @addtogroup arb_edit */
21 /** @{ */
22 /** @file arb_edit.h
23  *
24  * @brief
25  * Editing operations for arb primitives.
26  *
27  */
28 
29 #ifndef ARB_EDIT_H
30 #define ARB_EDIT_H
31 
32 #include "common.h"
33 #include "bn.h"
34 #include "db.h"
35 #include "rtgeom.h"
36 
38 
39 #ifndef RT_EXPORT
40 # if defined(RT_DLL_EXPORTS) && defined(RT_DLL_IMPORTS)
41 # error "Only RT_DLL_EXPORTS or RT_DLL_IMPORTS can be defined, not both."
42 # elif defined(RT_DLL_EXPORTS)
43 # define RT_EXPORT __declspec(dllexport)
44 # elif defined(RT_DLL_IMPORTS)
45 # define RT_EXPORT __declspec(dllimport)
46 # else
47 # define RT_EXPORT
48 # endif
49 #endif
50 
51 /**
52  * face definitions for each arb type
53  *
54  * row 1: ARB4
55  * row 2: ARB5
56  * row 3: ARB6
57  * row 4: ARB7
58  * row 5: ARB8
59  *
60  * To use this array, define it as follows:
61  *
62  * const int arb_faces[5][24] = rt_arb_faces;
63  *
64  */
65 #define rt_arb_faces { \
66  {0,1,2,3, 0,1,4,5, 1,2,4,5, 0,2,4,5, -1,-1,-1,-1, -1,-1,-1,-1}, \
67  {0,1,2,3, 4,0,1,5, 4,1,2,5, 4,2,3,5, 4,3,0,5, -1,-1,-1,-1}, \
68  {0,1,2,3, 1,2,6,4, 0,4,6,3, 4,1,0,5, 6,2,3,7, -1,-1,-1,-1}, \
69  {0,1,2,3, 4,5,6,7, 0,3,4,7, 1,2,6,5, 0,1,5,4, 3,2,6,4}, \
70  {0,1,2,3, 4,5,6,7, 0,4,7,3, 1,2,6,5, 0,1,5,4, 3,2,6,7}, \
71 }
72 
73 /* The following arb editing arrays generally contain the following:
74  *
75  * location comments
76  *-------------------------------------------------------------------
77  * 0,1 edge end points
78  * 2,3 bounding planes 1 and 2
79  * 4, 5,6,7 plane 1 to recalculate, using next 3 points
80  * 8, 9,10,11 plane 2 to recalculate, using next 3 points
81  * 12, 13,14,15 plane 3 to recalculate, using next 3 points
82  * 16,17 points (vertices) to recalculate
83  *
84  * Each line is repeated for each edge (or point) to move.
85  * See g_arb.c for more details.
86  */
87 
88 /**
89  * edit array for arb8's
90  *
91  * row 1: edge 12
92  * row 2: edge 23
93  * row 3: edge 34
94  * row 4: edge 14
95  * row 5: edge 15
96  * row 6: edge 26
97  * row 7: edge 56
98  * row 8: edge 67
99  * row 9: edge 78
100  * row 10: edge 58
101  * row 11: edge 37
102  * row 12: edge 48
103  *
104  * To use this array, define it as follows:
105  *
106  * const short earb8[12][18] = earb8_edit_array;
107  */
108 #define earb8_edit_array { \
109  {0,1, 2,3, 0,0,1,2, 4,0,1,4, -1,0,0,0, 3,5}, \
110  {1,2, 4,5, 0,0,1,2, 3,1,2,5, -1,0,0,0, 3,6}, \
111  {2,3, 3,2, 0,0,2,3, 5,2,3,6, -1,0,0,0, 1,7}, \
112  {0,3, 4,5, 0,0,1,3, 2,0,3,4, -1,0,0,0, 2,7}, \
113  {0,4, 0,1, 2,0,4,3, 4,0,1,4, -1,0,0,0, 7,5}, \
114  {1,5, 0,1, 4,0,1,5, 3,1,2,5, -1,0,0,0, 4,6}, \
115  {4,5, 2,3, 4,0,5,4, 1,4,5,6, -1,0,0,0, 1,7}, \
116  {5,6, 4,5, 3,1,5,6, 1,4,5,6, -1,0,0,0, 2,7}, \
117  {6,7, 3,2, 5,2,7,6, 1,4,6,7, -1,0,0,0, 3,4}, \
118  {4,7, 4,5, 2,0,7,4, 1,4,5,7, -1,0,0,0, 3,6}, \
119  {2,6, 0,1, 3,1,2,6, 5,2,3,6, -1,0,0,0, 5,7}, \
120  {3,7, 0,1, 2,0,3,7, 5,2,3,7, -1,0,0,0, 4,6}, \
121 }
122 
123 /**
124  * edge/vertex mapping for arb8's
125  *
126  * row 1: edge 12
127  * row 2: edge 23
128  * row 3: edge 34
129  * row 4: edge 14
130  * row 5: edge 15
131  * row 6: edge 26
132  * row 7: edge 56
133  * row 8: edge 67
134  * row 9: edge 78
135  * row 10: edge 58
136  * row 11: edge 37
137  * row 12: edge 48
138  *
139  * To use this mapping , define it as follows:
140  * const short arb8_evm[12][2] = arb8_edge_vertex_mapping;
141  */
142 #define arb8_edge_vertex_mapping { \
143  {0,1}, \
144  {1,2}, \
145  {2,3}, \
146  {0,3}, \
147  {0,4}, \
148  {1,5}, \
149  {4,5}, \
150  {5,6}, \
151  {6,7}, \
152  {4,7}, \
153  {2,6}, \
154  {3,7}, \
155 }
156 
157 /**
158  * edit array for arb7's
159 
160  * row 1: edge 12
161  * row 2: edge 23
162  * row 3: edge 34
163  * row 4: edge 41
164  * row 5: edge 15
165  * row 6: edge 26
166  * row 7: edge 56
167  * row 8: edge 67
168  * row 9: edge 37
169  * row 10: edge 57
170  * row 11: edge 45
171  * row 12: point 5
172  *
173  * To use this array, define it as follows:
174  *
175  * const short earb7[12][18] = earb7_edit_array;
176  */
177 #define earb7_edit_array { \
178  {0,1, 2,3, 0,0,1,2, 4,0,1,4, -1,0,0,0, 3,5}, \
179  {1,2, 4,5, 0,0,1,2, 3,1,2,5, -1,0,0,0, 3,6}, \
180  {2,3, 3,2, 0,0,2,3, 5,2,3,6, -1,0,0,0, 1,4}, \
181  {0,3, 4,5, 0,0,1,3, 2,0,3,4, -1,0,0,0, 2,-1}, \
182  {0,4, 0,5, 4,0,5,4, 2,0,3,4, 1,4,5,6, 1,-1}, \
183  {1,5, 0,1, 4,0,1,5, 3,1,2,5, -1,0,0,0, 4,6}, \
184  {4,5, 5,3, 2,0,3,4, 4,0,5,4, 1,4,5,6, 1,-1}, \
185  {5,6, 4,5, 3,1,6,5, 1,4,5,6, -1,0,0,0, 2, -1}, \
186  {2,6, 0,1, 5,2,3,6, 3,1,2,6, -1,0,0,0, 4,5}, \
187  {4,6, 4,3, 2,0,3,4, 5,3,4,6, 1,4,5,6, 2,-1}, \
188  {3,4, 0,1, 4,0,1,4, 2,0,3,4, 5,2,3,4, 5,6}, \
189  {-1,-1, -1,-1, 5,2,3,4, 4,0,1,4, 8,2,1,-1, 6,5}, \
190 }
191 
192 /**
193  * edge/vertex mapping for arb7's
194  *
195  * row 1: edge 12
196  * row 2: edge 23
197  * row 3: edge 34
198  * row 4: edge 41
199  * row 5: edge 15
200  * row 6: edge 26
201  * row 7: edge 56
202  * row 8: edge 67
203  * row 9: edge 37
204  * row 10: edge 57
205  * row 11: edge 45
206  * row 12: point 5
207  *
208  * To use this mapping , define it as follows:
209  * const short arb7_evm[12][2] = arb7_edge_vertex_mapping;
210  */
211 #define arb7_edge_vertex_mapping { \
212  {0,1}, \
213  {1,2}, \
214  {2,3}, \
215  {0,3}, \
216  {0,4}, \
217  {1,5}, \
218  {4,5}, \
219  {5,6}, \
220  {2,6}, \
221  {4,6}, \
222  {3,4}, \
223  {4,4}, \
224 }
225 
226 /**
227  * edit array for arb6's
228  *
229  * row 1: edge 12
230  * row 2: edge 23
231  * row 3: edge 34
232  * row 4: edge 14
233  * row 5: edge 15
234  * row 6: edge 25
235  * row 7: edge 36
236  * row 8: edge 46
237  * row 9: point 5
238  * row 10: point 6
239  *
240  * To use this array, define it as follows:
241  *
242  * const short earb6[10][18] = earb6_edit_array;
243  */
244 #define earb6_edit_array { \
245  {0,1, 2,1, 3,0,1,4, 0,0,1,2, -1,0,0,0, 3,-1}, \
246  {1,2, 3,4, 1,1,2,5, 0,0,1,2, -1,0,0,0, 3,4}, \
247  {2,3, 1,2, 4,2,3,5, 0,0,2,3, -1,0,0,0, 1,-1}, \
248  {0,3, 3,4, 2,0,3,5, 0,0,1,3, -1,0,0,0, 4,2}, \
249  {0,4, 0,1, 3,0,1,4, 2,0,3,4, -1,0,0,0, 6,-1}, \
250  {1,4, 0,2, 3,0,1,4, 1,1,2,4, -1,0,0,0, 6,-1}, \
251  {2,6, 0,2, 4,6,2,3, 1,1,2,6, -1,0,0,0, 4,-1}, \
252  {3,6, 0,1, 4,6,2,3, 2,0,3,6, -1,0,0,0, 4,-1}, \
253  {-1,-1, -1,-1, 2,0,3,4, 1,1,2,4, 3,0,1,4, 6,-1}, \
254  {-1,-1, -1,-1, 2,0,3,6, 1,1,2,6, 4,2,3,6, 4,-1}, \
255 }
256 
257 /**
258  * edge/vertex mapping for arb6's
259  *
260  * row 1: edge 12
261  * row 2: edge 23
262  * row 3: edge 34
263  * row 4: edge 14
264  * row 5: edge 15
265  * row 6: edge 25
266  * row 7: edge 36
267  * row 8: edge 46
268  * row 9: point 5
269  * row 10: point 6
270  *
271  * To use this mapping , define it as follows:
272  *
273  * const short arb6_evm[10][2] = arb6_edge_vertex_mapping;
274  */
275 #define arb6_edge_vertex_mapping { \
276  {0,1}, \
277  {1,2}, \
278  {2,3}, \
279  {0,3}, \
280  {0,4}, \
281  {1,4}, \
282  {2,5}, \
283  {3,5}, \
284  {4,4}, \
285  {7,7}, \
286 }
287 
288 /**
289  * edit array for arb5's
290  *
291  * row 1: edge 12
292  * row 2: edge 23
293  * row 3: edge 34
294  * row 4: edge 14
295  * row 5: edge 15
296  * row 6: edge 25
297  * row 7: edge 35
298  * row 8: edge 45
299  * row 9: point 5
300  *
301  * To use this array, define it as follows:
302  *
303  * const short earb5[9][18] = earb5_edit_array;
304  */
305 #define earb5_edit_array { \
306  {0,1, 4,2, 0,0,1,2, 1,0,1,4, -1,0,0,0, 3,-1}, \
307  {1,2, 1,3, 0,0,1,2, 2,1,2,4, -1,0,0,0, 3,-1}, \
308  {2,3, 2,4, 0,0,2,3, 3,2,3,4, -1,0,0,0, 1,-1}, \
309  {0,3, 1,3, 0,0,1,3, 4,0,3,4, -1,0,0,0, 2,-1}, \
310  {0,4, 0,2, 9,0,0,0, 9,0,0,0, 9,0,0,0, -1,-1}, \
311  {1,4, 0,3, 9,0,0,0, 9,0,0,0, 9,0,0,0, -1,-1}, \
312  {2,4, 0,4, 9,0,0,0, 9,0,0,0, 9,0,0,0, -1,-1}, \
313  {3,4, 0,1, 9,0,0,0, 9,0,0,0, 9,0,0,0, -1,-1}, \
314  {-1,-1, -1,-1, 9,0,0,0, 9,0,0,0, 9,0,0,0, -1,-1}, \
315 }
316 
317 /**
318  * edge/vertex mapping for arb5's
319  *
320  * row 1: edge 12
321  * row 2: edge 23
322  * row 3: edge 34
323  * row 4: edge 14
324  * row 5: edge 15
325  * row 6: edge 25
326  * row 7: edge 35
327  * row 8: edge 45
328  * row 9: point 5
329  *
330  * To use this mapping , define it as follows:
331  *
332  * const short arb5_evm[9][2] = arb5_edge_vertex_mapping;
333  */
334 #define arb5_edge_vertex_mapping { \
335  {0,1}, \
336  {1,2}, \
337  {2,3}, \
338  {0,3}, \
339  {0,4}, \
340  {1,4}, \
341  {2,4}, \
342  {3,4}, \
343  {4,4}, \
344 }
345 
346 /**
347  * edit array for arb4's
348  *
349  * row 1: point 1
350  * row 2: point 2
351  * row 3: point 3
352  * row 4: dummy
353  * row 5: point 4
354  *
355  * To use this array, define it as follows:
356  *
357  * const short earb4[5][18] = earb4_edit_array;
358  */
359 #define earb4_edit_array { \
360  {-1,-1, -1,-1, 9,0,0,0, 9,0,0,0, 9,0,0,0, -1,-1}, \
361  {-1,-1, -1,-1, 9,0,0,0, 9,0,0,0, 9,0,0,0, -1,-1}, \
362  {-1,-1, -1,-1, 9,0,0,0, 9,0,0,0, 9,0,0,0, -1,-1}, \
363  {-1,-1, -1,-1, 9,0,0,0, 9,0,0,0, 9,0,0,0, -1,-1}, \
364  {-1,-1, -1,-1, 9,0,0,0, 9,0,0,0, 9,0,0,0, -1,-1}, \
365 }
366 
367 /**
368  * edge/vertex mapping for arb4's
369  *
370  * row 1: point 1
371  * row 2: point 2
372  * row 3: point 3
373  * row 4: dummy
374  * row 5: point 4
375  *
376  * To use this mapping , define it as follows:
377  *
378  * const short arb4_evm[5][2] = arb4_edge_vertex_mapping;
379  */
380 #define arb4_edge_vertex_mapping { \
381  {0,0}, \
382  {1,1}, \
383  {2,2}, \
384  {3,3}, \
385  {4,4}, \
386 }
387 
388 /**
389  * EXT4TO6(): extrudes face pt1 pt2 pt3 of an ARB4 "distance"
390  * to produce ARB6
391  */
392 RT_EXPORT extern void
393 ext4to6(int pt1, int pt2, int pt3, struct rt_arb_internal *arb, fastf_t peqn[7][4]);
394 
395 
396 /* MV_EDGE: Moves an arb edge (end1, end2) with bounding planes bp1
397  * and bp2 through point "thru". The edge has (non-unit) slope "dir".
398  * Note that the fact that the normals here point in rather than out
399  * makes no difference for computing the correct intercepts. After
400  * the intercepts are found, they should be checked against the other
401  * faces to make sure that they are always "inside".
402  */
403 RT_EXPORT extern int
404 mv_edge(struct rt_arb_internal *arb,
405  const vect_t thru,
406  const int bp1, const int bp2,
407  const int end1, const int end2,
408  const vect_t dir,
409  const struct bn_tol *tol,
410  fastf_t peqn[7][4]);
411 
412 /* Extrude an arb face */
413 RT_EXPORT extern int
414 arb_extrude(struct rt_arb_internal *arb,
415  int face, fastf_t dist,
416  const struct bn_tol *tol,
417  fastf_t peqn[7][4]);
418 
419 
420 /* Permute the vertex labels of an ARB
421  *
422  * Minimum and maximum tuple lengths
423  * ------------------------------------------------
424  * Solid # vertices needed # vertices
425  * type to disambiguate in THE face
426  * ------------------------------------------------
427  * ARB4 3 3
428  * ARB5 2 4
429  * ARB6 2 4
430  * ARB7 1 4
431  * ARB8 3 4
432  * ------------------------------------------------
433  */
434 RT_EXPORT extern int
435 arb_permute(struct rt_arb_internal *arb, const char *encoded_permutation, const struct bn_tol *tol);
436 
437 
438 /* Mirror an arb face about the x, y or z axis */
439 RT_EXPORT extern int
440 arb_mirror_face_axis(struct rt_arb_internal *arb, fastf_t peqn[7][4], const int face, const char *axis, const struct bn_tol *tol);
441 
442 /* An ARB edge is moved by finding the direction of the line
443  * containing the edge and the 2 "bounding" planes. The new edge is
444  * found by intersecting the new line location with the bounding
445  * planes. The two "new" planes thus defined are calculated and the
446  * affected points are calculated by intersecting planes. This keeps
447  * ALL faces planar.
448  */
449 RT_EXPORT extern int
450 arb_edit(struct rt_arb_internal *arb, fastf_t peqn[7][4], int edge, int newedge, vect_t pos_model, const struct bn_tol *tol);
451 
452 
454 
455 #endif /* ARB_EDIT_H */
456 
457 /** @} */
458 /*
459  * Local Variables:
460  * tab-width: 8
461  * mode: C
462  * indent-tabs-mode: t
463  * c-file-style: "stroustrup"
464  * End:
465  * ex: shiftwidth=4 tabstop=8
466  */
int mv_edge(struct rt_arb_internal *arb, const vect_t thru, const int bp1, const int bp2, const int end1, const int end2, const vect_t dir, const struct bn_tol *tol, fastf_t peqn[7][4])
Definition: arb_edit.c:61
Header file for the BRL-CAD common definitions.
int arb_extrude(struct rt_arb_internal *arb, int face, fastf_t dist, const struct bn_tol *tol, fastf_t peqn[7][4])
Definition: arb_edit.c:83
#define __BEGIN_DECLS
Definition: common.h:73
Support for uniform tolerances.
Definition: tol.h:71
int arb_permute(struct rt_arb_internal *arb, const char *encoded_permutation, const struct bn_tol *tol)
Definition: arb_edit.c:242
axis
Definition: color.c:48
#define __END_DECLS
Definition: common.h:74
void ext4to6(int pt1, int pt2, int pt3, struct rt_arb_internal *arb, fastf_t peqn[7][4])
Definition: arb_edit.c:39
int arb_mirror_face_axis(struct rt_arb_internal *arb, fastf_t peqn[7][4], const int face, const char *axis, const struct bn_tol *tol)
Definition: arb_edit.c:424
double fastf_t
Definition: defines.h:300
int arb_edit(struct rt_arb_internal *arb, fastf_t peqn[7][4], int edge, int newedge, vect_t pos_model, const struct bn_tol *tol)
Definition: arb_edit.c:568