求面的公共边
案例1
高亮面的公共边(求公共边)
Date: 5-JAN-1998
Subject: Sample API program to highlight common edges
/*HEAD HIGHLIGHT_COMMON_EDGES CCC UFUN */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_object_types.h>
#include <uf_disp.h>
#include <uf_modl.h>
#include <uf_assem.h>
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
static int report_error( char *file, int line, char *call, int irc)
{
if (irc)
{
char
err[133],
messg[300];
UF_get_fail_message(irc, err);
sprintf(messg, "\n%s\nerror %d at line %d in %s\n%s",
err, irc, line, file, call);
printf("%s\n", messg);
strcpy(&messg[129], "...");
uc1601(messg, TRUE); /* Internal only - remove for external */
}
return(irc);
}
static tag_t select_a_face(char *prompt)
{
double
cp[3];
int
irc;
tag_t
face,
view;
UF_UI_selection_options_t
opts;
UF_UI_mask_t
mask;
opts.num_mask_triples = 1;
opts.mask_triples = &mask;
opts.scope = UF_UI_SEL_SCOPE_WORK_PART;
mask.object_type = UF_solid_type;
mask.object_subtype = 0;
mask.solid_type = UF_UI_SEL_FEATURE_ANY_FACE;
UF_CALL(UF_UI_select_single(prompt, &opts, &irc, &face, cp, &view));
if (irc == 4 || irc == 5)
{
UF_CALL(UF_DISP_set_highlight(face, FALSE));
return face;
}
else return NULL_TAG;
}
static int ask_common_edges(tag_t face1, tag_t face2, tag_p_t *edges)
{
int
ii,
n = 0;
uf_list_p_t
edge_list;
UF_CALL(UF_MODL_ask_shared_edges(face1, face2, &edge_list));
if (edge_list) UF_CALL(UF_MODL_ask_list_count(edge_list, &n));
*edges = (tag_t *)malloc(n * sizeof(tag_t));
for (ii = 0; ii < n; ii++)
{
UF_CALL(UF_MODL_ask_list_item(edge_list, ii, *edges+ii));
if (UF_ASSEM_is_occurrence(face1) && UF_ASSEM_is_occurrence(face2))
*(*edges+ii) = UF_ASSEM_find_occurrence(
UF_ASSEM_ask_part_occurrence(face1), *(*edges+ii));
}
UF_CALL(UF_MODL_delete_list(&edge_list));
return n;
}
static void do_it(void)
{
int
ii,
n;
tag_t
face1,
face2,
*edges;
char
messg[30];
while (((face1 = select_a_face("Select first face")) != NULL_TAG) &&
((face2 = select_a_face("Select second face")) != NULL_TAG))
{
n = ask_common_edges(face1, face2, &edges);
sprintf(messg, "%d common edge(s)", n);
if (n)
{
for (ii = 0; ii < n; ii++)
UF_DISP_set_highlight(edges[ii], TRUE);
uc1601(messg, TRUE);
for (ii = 0; ii < n; ii++)
UF_DISP_set_highlight(edges[ii], FALSE);
free(edges);
}
else
uc1601(messg, TRUE);
}
}
void ufusr(char *param, int *retcode, int paramLen)
{
if (UF_CALL(UF_initialize())) return;
do_it();
UF_terminate();
}
int ufusr_ask_unload(void)
{
return (UF_UNLOAD_IMMEDIATELY);
}
案例2
面的封闭环
Date: 10-MAR-1999
Subject: Sample API function to report face loops
static void report_face_loops(tag_t face)
{
char
*types[4] = { "", "Peripheral", "Hole", "Other" };
int
ii,
jj,
n_edges,
n_loops,
type;
tag_t
edge;
uf_list_p_t
edge_list;
uf_loop_p_t
loop_list;
if (!UF_CALL(UF_MODL_ask_face_loops(face, &loop_list)) && loop_list)
{
UF_CALL(UF_MODL_ask_loop_list_count(loop_list, &n_loops));
printf("\nface %d has %d loops\n", face, n_loops);
for (ii = 0; ii < n_loops; ii++)
{
UF_CALL(UF_MODL_ask_loop_list_item(loop_list,ii,&type,&edge_list));
UF_CALL(UF_MODL_ask_list_count(edge_list, &n_edges));
printf(" %d. %s loop has %d edges\n", ii+1, types[type], n_edges);
for (jj = 0; jj < n_edges; jj++)
{
UF_CALL(UF_MODL_ask_list_item(edge_list, jj, &edge));
printf(" %d. edge %d\n", jj+1, edge);
}
}
UF_CALL(UF_MODL_delete_loop_list(&loop_list));
}
}
案例3
获取面的公共边
Date: 10-AUG-1999
Subject: Sample API function to ask common edges
static int ask_common_edges(tag_t face1, tag_t face2, tag_p_t *common_edges)
{
int
err,
ii,
n = 0;
tag_t
*edges;
uf_list_p_t
edge_list;
UF_CALL(UF_MODL_ask_shared_edges(face1, face2, &edge_list));
if (edge_list) UF_CALL(UF_MODL_ask_list_count(edge_list, &n));
*common_edges = (edges = (tag_t *)UF_allocate_memory(n*sizeof(tag_t),&err));
if (UF_CALL(err)) return 0;
for (ii = 0; ii < n; ii++)
{
UF_CALL(UF_MODL_ask_list_item(edge_list, ii, &edges[ii]));
if (UF_ASSEM_is_occurrence(face1) && UF_ASSEM_is_occurrence(face2))
edges[ii] = UF_ASSEM_find_occurrence(
UF_ASSEM_ask_part_occurrence(face1), edges[ii]);
}
UF_CALL(UF_MODL_delete_list(&edge_list));
return n;
}
评论区