This commit is contained in:
watrabi
2025-09-18 17:55:52 -04:00
commit 977f1ff4b8
15030 changed files with 17324420 additions and 0 deletions
+613
View File
@@ -0,0 +1,613 @@
#include "../sg.h"
typedef int (*fptr)(const void*, const void*);
static OSCAN_COD bo_scan(hOBJ hobj,lpSCAN_CONTROL lpsc);
hINDEX b_index_np(lpNP_STR_LIST list, lpREGION_3D gab);
static int sort_function( const short *a, const short *b);
BOOL b_list_del(lpNP_STR_LIST list, hOBJ hobj);
BOOL b_list_lable(lpNP_STR_LIST list, hOBJ hobj);
static short b_np_label(NP_TYPE_POINT met);
static WORD app_idn_a;
static lpNP_STR_LIST list_str = NULL;
short key, object_number, ident_c;
lpNPW npa = NULL, npb = NULL;
VADR hbo_mem = NULL;
hINDEX hindex_a = NULL, hindex_b = NULL;
NP_STR_LIST lista,listb;
VLD vld_c;
int num_index_a, num_index_b;
REGION_3D gab_c = {{1.e35,1.e35,1.e35},{-1.e35,-1.e35,-1.e35}};
BOOL brept1 = TRUE;
BOOL Bo_Put_Message = TRUE;
lpLISTH bo_line_listh;
OSCAN_COD boolean_operation(hOBJ hobj_a, hOBJ hobj_b, CODE_OPERATION code_operation,
lpLISTH listh)
{
int i, ii;
int num_proc = -1;
NP_STR str1 , str2;
REGION_3D gab_a = {{1.e35,1.e35,1.e35},{-1.e35,-1.e35,-1.e35}};
REGION_3D gab_b = {{1.e35,1.e35,1.e35},{-1.e35,-1.e35,-1.e35}};
hOBJ hobj_c = NULL;
lpOBJ obj_a, obj_b;
lpGEO_BREP lpgeobrep_a, lpgeobrep_b;
WORD app_idn_b;
int* b;
BOOL line_inter = FALSE;
SCAN_CONTROL sc;
OSCAN_COD rt = OSTRUE;
NP_TYPE_POINT answer;
flg_exist = 1;
if (hobj_a == NULL || hobj_b == NULL ||
code_operation < UNION || code_operation > LINE_INTER /*PENETRATE*/) {
put_message(EMPTY_MSG,GetIDS(IDS_SG028),0);
return OSBREAK;
}
// if (code_operation == PENETRATE) point.met=0;
obj_a = (lpOBJ)hobj_a;
obj_b = (lpOBJ)hobj_b;
lpgeobrep_a = (lpGEO_BREP)obj_a->geo_data;
lpgeobrep_b = (lpGEO_BREP)obj_b->geo_data;
if ( lpgeobrep_a->type == SURF ) brept1 = FALSE;
else brept1 = TRUE;
if ( code_operation == LINE_INTER ) {
if ( lpgeobrep_a->type == FRAME || lpgeobrep_b->type == FRAME ) {
put_message(EMPTY_MSG,GetIDS(IDS_SG029),0);
return OSBREAK;
}
goto bo;
}
/* if ( lpgeobrep_b->type != BODY ) {
put_message(EMPTY_MSG,GetIDS(IDS_SG030),0);
return OSFALSE;
}
*/
if ( code_operation == UNION && lpgeobrep_a->type != BODY ) {
put_message(EMPTY_MSG,GetIDS(IDS_SG031),0);
return OSBREAK;
}
bo:
// init_listh(&line_listh);
bo_line_listh = listh;
gab_a.min = lpgeobrep_a->min;
gab_a.max = lpgeobrep_a->max;
gab_b.min = lpgeobrep_b->min;
gab_b.max = lpgeobrep_b->max;
f3d_gabar_project1(lpgeobrep_a->matr,&gab_a.min,&gab_a.max,
&gab_a.min,&gab_a.max);
f3d_gabar_project1(lpgeobrep_b->matr,&gab_b.min,&gab_b.max,
&gab_b.min,&gab_b.max);
np_gab_un(&gab_a, &gab_b, &gab_c);
define_eps(&(gab_c.min), &(gab_c.max));
if ((np_gab_inter(&gab_a,&gab_b)) == TRUE) {
if ( Bo_Put_Message )
put_message(EMPTY_MSG,GetIDS(IDS_SG032),1);
if (code_operation == UNION) return OSFALSE;
if (code_operation == SUB) {
if ( !o_copy_obj(hobj_a, &hobj_c,"") ) return OSFALSE;
obj_a = (lpOBJ)hobj_c;
obj_a->status &= (~(ST_SELECT|ST_BLINK));
attach_item_tail(listh, hobj_c);
}
return rt;
}
key = code_operation;
app_idn_b = lpgeobrep_b->ident_np + 32767;
app_idn_a = 32767 - lpgeobrep_a->ident_np;
if (app_idn_a < app_idn_b) {
put_message(IDENT_OVER,NULL,0);
return OSBREAK;
}
app_idn_a = lpgeobrep_a->ident_np + 32767;
ident_c = lpgeobrep_a->ident_np + app_idn_b;
init_scan(&sc);
sc.user_geo_scan = bo_scan;
read_user_data_buf = bo_read_user_data_buf;
write_user_data_buf = bo_write_user_data_buf;
read_user_data_mem = bo_read_user_data_mem;
add_user_data_mem = bo_add_user_data_mem;
size_user_data = bo_size_user_data;
expand_user_data = bo_expand_user_data;
init_vld(&vld_c);
/* if (npwg->maxnov < 2*MAXNOV) nov = 2*MAXNOV - npwg->maxnov;
else nov = 0;
if (npwg->maxnoe < 2*MAXNOE) noe = 2*MAXNOE - npwg->maxnoe;
else noe = 0;
if (npwg->maxnof < 2*MAXNOF) nof = 2*MAXNOF - npwg->maxnof;
else nof = 0;
if (npwg->maxnoc < 2*MAXNOC) noc = 2*MAXNOC - npwg->maxnoc;
else noc = 0;
if ( !(o_expand_np(npwg, nov, noe, nof, noc)) ) return NULL;
*/
npwg->type = TNPW;
np_init(npwg);
object_number = 1;
if ( !np_init_list(&lista) )
{
rt = OSBREAK; goto norm;
}
list_str = &lista;
if ( (rt = o_scan(hobj_a,&sc)) != OSTRUE ) goto norm;
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
rt = OSBREAK;
goto norm;
}
if ((hindex_a = b_index_np(&lista,&gab_b)) == NULL)
{
rt = OSBREAK; goto norm;
}
num_index_a = lista.number_all;
object_number = 2;
if ( !np_init_list(&listb) )
{
rt = OSBREAK; goto norm;
}
list_str = &listb;
if ( (rt = o_scan(hobj_b,&sc)) != OSTRUE ) goto norm;
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
rt = OSBREAK;
goto norm;
}
if ((hindex_b = b_index_np(&listb,&gab_a)) == NULL)
{
rt = OSBREAK; goto norm;
}
num_index_b = listb.number_all;
if ((rt = (OSCAN_COD)np_str_form(np_gab_inter, &lista, &listb)) != OSTRUE)
goto norm;
np_gab_init(&gab_c);
npa = npwg;
npwg->type = TNPW;
if ( !(bo_new_user_data(npa)) )
{
rt = OSBREAK; goto norm;
}
if ( (npb = creat_np_mem(TNPW,MAXNOV,MAXNOE,MAXNOF,MAXNOF,MAXNOE))
== NULL )
{
rt = OSBREAK; goto norm;
}
np_init(npb);
if ( !(bo_new_user_data(npb)) )
{
rt = OSBREAK; goto norm;
}
// if ( !tb_setcolor(IDXRED) ) { rt = OSFALSE; goto norm; }
// num_proc = start_grad(GetIDS(IDS_SG033), lista.number_all);
for (ii=0; ii<lista.number_all; ii++) {
// step_grad (num_proc , ii);
read_elem(&lista.vdim,ii,&str1);
if ( str1.len == 0 || abs(str1.lab) == 1 ) continue;
if (!(read_np(&lista.bnp,str1.hnp,npa)))
{
rt = OSBREAK; goto norm;
}
begin_rw(&lista.nb, str1.b);
for (i=0 ; i < str1.len ; i++) {
b = (int*)get_next_elem(&lista.nb);
read_elem(&listb.vdim,*b,&str2);
if (!(read_np(&listb.bnp,str2.hnp,npb)))
{
rt = OSBREAK; goto norm;
}
if ( !(b_lnp(&str1,&str2)) ) {
end_rw(&lista.nb); ;//nb b = NULL;
rt = OSSKIP;
goto norm;
}
if (str2.lab == 2) {
line_inter = TRUE;
if ( !(overwrite_np(&listb.bnp,str2.hnp,npb,TNPW)) )
{
rt = OSBREAK; goto norm;
}
}
write_elem(&listb.vdim,*b,&str2);
}
end_rw(&lista.nb); //nb b = NULL;
if (str1.lab == 2) {
if ( !(overwrite_np(&lista.bnp,str1.hnp,npa,TNPW)) )
{
rt = OSBREAK; goto norm;
}
line_inter = TRUE;
}
write_elem(&lista.vdim,ii,&str1);
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
rt = OSBREAK;
goto norm;
}
}
read_user_data_mem = NULL;
add_user_data_mem = NULL;
// end_grad (num_proc , ii);
num_proc = -1;
if ( code_operation == LINE_INTER ) {
if ( listh->num ) {
hobj_c = make_group(listh, TRUE);
init_listh(listh);
attach_item_tail(listh, hobj_c);
}
goto norm;
}
if ( line_inter == FALSE ) {
if ( code_operation == UNION ) {
// object_number = 2;
read_elem(&listb.vdim,0, &str1);
if (!(read_np(&listb.bnp, str1.hnp, npa)))
{
rt = OSBREAK; goto norm;
}
if ( !check_point_object(&npa->v[1], hobj_a, &answer) )
{
rt = OSBREAK; goto norm;
}
if ( answer == NP_IN ) goto fr;
// object_number = 1;
read_elem(&lista.vdim,0, &str1);
if (!(read_np(&lista.bnp, str1.hnp, npa)))
{
rt = OSBREAK; goto norm;
}
if ( !check_point_object(&npa->v[1], hobj_b, &answer) )
{
rt = OSBREAK; goto norm;
}
if ( answer == NP_IN ) {
if ( !o_copy_obj(hobj_b, &hobj_c,"") )
{
rt = OSBREAK; goto norm;
}
obj_a = (lpOBJ)hobj_c;
obj_a->status &= (~(ST_SELECT|ST_BLINK));
attach_item_tail(listh, hobj_c);
goto norm;
} else {
rt = OSSKIP;
if ( Bo_Put_Message )
put_message(EMPTY_MSG,GetIDS(IDS_SG034),1);
goto norm;
}
} else {
// object_number = 1;
read_elem(&lista.vdim,0, &str1);
if (!(read_np(&lista.bnp, str1.hnp, npa)))
{
rt = OSBREAK; goto norm;
}
if ( !check_point_object(&npa->v[1], hobj_b, &answer) )
{
rt = OSBREAK; goto norm;
}
}
if (answer==NP_IN && (code_operation==SUB || code_operation==INTER))
{
rt = OSCONTAINS;
goto norm;
}
if ( answer == NP_IN )
goto norm;
if (answer==NP_OUT && (code_operation==SUB || code_operation==INTER))
{
goto norm;
}
fr:
if ( !o_copy_obj(hobj_a, &hobj_c,"") )
{
rt = OSBREAK; goto norm;
}
obj_a = (lpOBJ)hobj_c;
obj_a->status &= (~(ST_SELECT|ST_BLINK));
attach_item_tail(listh, hobj_c);
goto norm;
}
object_number = 1;
if ( !(b_list_del(&lista, hobj_a)) )
{
rt = OSBREAK; goto norm;
}
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
rt = OSBREAK;
goto norm;
}
if ( brept1 ) {
object_number = 2;
if ( !(b_list_del(&listb, hobj_b)) ) { rt = OSBREAK; goto norm; }
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
rt = OSBREAK;
goto norm;
}
}
//
object_number = 1;
for (ii=0; ii<lista.number_all; ii++) {
read_elem(&lista.vdim,ii,&str1);
if ((str1.ort & ST_SV) || (str1.ort & ST_MAX)) {
if ( !(b_del_sv(&lista, &str1)) )
{
rt = OSBREAK; goto norm;
}
str1.ort = 0;
write_elem(&lista.vdim,ii,&str1);
}
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
rt = OSBREAK;
goto norm;
}
}
if ( brept1 ) {
object_number = 2;
for (ii=0; ii<listb.number_all; ii++) {
read_elem(&listb.vdim,ii,&str2);
if ( (str2.ort & ST_SV) || (str2.ort & ST_MAX) ) {
if ( !(b_del_sv(&listb, &str2)) )
{
rt = OSBREAK; goto norm;
}
str2.ort = 0;
write_elem(&listb.vdim,ii,&str2);
}
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
rt = OSBREAK;
goto norm;
}
}
}
rt = (OSCAN_COD)b_form_model_list(listh, hobj_a);
norm:
// tb_clear();
// if (num_proc != -1 ) end_grad (num_proc ,ii);
bo_free_user_data(npwg);
bo_free_user_data(npb);
free_np_mem(&npb);
if (hindex_a != NULL) { SGFree(hindex_a); hindex_a = NULL; }
if (hindex_b != NULL) { SGFree(hindex_b); hindex_b = NULL; }
if ( lista.number_all > 0) np_end_of_put(&lista,NP_CANCEL,0,NULL);
if ( listb.number_all > 0) np_end_of_put(&listb,NP_CANCEL,0,NULL);
read_user_data_buf = NULL;
write_user_data_buf = NULL;
size_user_data = NULL;
expand_user_data = NULL;
read_user_data_mem = NULL;
add_user_data_mem = NULL;
np_free_stack();
return rt;
}
#pragma argsused
static OSCAN_COD bo_scan(hOBJ hobj,lpSCAN_CONTROL lpsc)
{
register short i;
lpD_POINT v;
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
return OSBREAK;
}
if (lpsc->type != OBREP) return OSTRUE;
npwg->type = TNPW;
v = npwg->v;
for (i = 1; i <= npwg->nov ; i++) {
if ( !o_hcncrd(lpsc->m,&v[i],&v[i])) goto err;
}
if ( !np_cplane(npwg) ) goto err;
if (object_number == 2) {
npwg->ident += app_idn_a;
for (i=1 ; i <= npwg->noe ; i++) {
if (npwg->efc[i].fp < 0) { npwg->efc[i].ep += app_idn_a; continue; }
if (npwg->efc[i].fm < 0) { npwg->efc[i].em += app_idn_a; continue; }
}
}
if ( np_put(npwg,list_str) ) return OSTRUE;
err:
return OSFALSE;
}
hINDEX b_index_np(lpNP_STR_LIST list, lpREGION_3D gab)
{
short number_np,i;
lpNP_STR str;
hINDEX hindex;//nb = NULL;
lpINDEX index;
number_np = list->number_all;
if ( (hindex = SGMalloc(sizeof(INDEX)*number_np)) == NULL) return NULL;
index = (lpINDEX)hindex;
begin_rw(&list->vdim,0);
for (i=0; i<list->number_all; i++) {
str = (NP_STR*)get_next_elem(&list->vdim);
index[i].ident = str->ident;
index[i].hnp = str->hnp;
if ((np_gab_inter(&str->gab,gab)) == TRUE) {
str->lab = -2;
}
write_elem(&list->vdim,i,str);
}
end_rw(&list->vdim);
qsort((void*)index,i,sizeof(index[0]),(fptr)sort_function);
return hindex;
}
int sort_function( const short *a, const short *b)
{
if ( (*(INDEX*)a).ident < (*(INDEX*)b).ident ) return -1;
if ( (*(INDEX*)a).ident == (*(INDEX*)b).ident ) return 0;
return 1;
}
VNP b_get_hnp(hINDEX hindex, short num, short ident)
{
VNP hnp;
lpINDEX index, p;
index = (lpINDEX)hindex;
p = (lpINDEX)bsearch(&ident,index,num,sizeof(index[0]),(fptr)sort_function);
if ( !p ) return 0;
hnp = p->hnp;
return hnp;
}
BOOL b_list_del(lpNP_STR_LIST list, hOBJ hobj)
{
short ii, pr = 0;
NP_STR str;
// num_proc = start_grad(GetIDS(IDS_SG035), lista.number_all);
for (ii=0; ii<list->number_all; ii++) {
// step_grad (num_proc , ii);
read_elem(&list->vdim,ii,&str);
if ( str.lab == 2 ) {
if (!(read_np(&list->bnp,str.hnp,npa))) goto err;
if ( !(b_del(list,npa, &str)) ) goto err;
if (npa->nof == 0) str.lab = -1;
else { str.lab = 1;
if ( !(overwrite_np(&list->bnp,str.hnp,npa,TNPW)) ) goto err;
}
write_elem(&list->vdim,ii,&str);
} else pr = 1;
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
goto err;
}
}
// end_grad (num_proc , ii);
if ( pr == 0 ) return TRUE;
if ( b_list_lable(list, hobj) ) return TRUE;
err:
// end_grad (num_proc , ii);
return FALSE;
}
BOOL b_list_lable(lpNP_STR_LIST list, hOBJ hobj)
{
short ii;
NP_STR str;
short count_old, count_np;
NP_TYPE_POINT answer;
/*nb count_old = */count_np = 0;
list->number_np = list->number_all;
do {
count_old = count_np; count_np = 0;
for (ii=0; ii<list->number_all; ii++) {
read_elem(&list->vdim,ii,&str);
if (abs(str.lab) == 1) {
count_np++ ;
continue;
}
str.lab = 0;
if (!(read_np(&list->bnp,str.hnp,npa))) return FALSE;
if ( !(b_np_lab(list,&str,npa)) ) return FALSE;
if (str.lab != 0) {
if (str.lab == 1 && object_number == 2 && key == SUB)
if ( !(overwrite_np(&list->bnp,str.hnp,npa,TNPW)) ) return FALSE;
write_elem(&list->vdim,ii,&str);
count_np++;
}
}
} while (count_np != list->number_all && count_np != count_old);
if (count_np != list->number_all) {
for (ii=0; ii<list->number_all; ii++) {
read_elem(&list->vdim,ii,&str);
if (abs(str.lab) == 1) {
continue;
}
if (!(read_np(&list->bnp,str.hnp,npa))) return FALSE;
if ( !check_point_object(&npa->v[1], hobj, &answer) ) return FALSE;
str.lab = b_np_label(answer);
if (str.lab != 0) {
if (str.lab == 1 && object_number == 2 && key == SUB)
if ( !(overwrite_np(&list->bnp,str.hnp,npa,TNPW)) ) return FALSE;
write_elem(&list->vdim,ii,&str);
//nb count_np++;
}
}
}
return TRUE;
}
static short b_np_label(NP_TYPE_POINT met)
{
switch (key) {
case UNION:
switch (met) {
case NP_OUT:
return 1;
case NP_IN:
return -1;
default:
return 0;
}
case INTER:
switch (met) {
case NP_OUT:
return -1;
case NP_IN:
return 1;
default:
return 0;
}
case SUB:
if (object_number == 1) {
if (met == NP_OUT) return 1;
else return -1;
} else if (met == NP_OUT) return -1;
else return 1;
default:
return 0;
}
}
+145
View File
@@ -0,0 +1,145 @@
#include "../sg.h"
static OSCAN_COD arc_scan(hOBJ hobj, lpSCAN_CONTROL lpsc);
static BOOL b_arc_np(lpNPW np, lpGEO_ARC arc, BOOL flag_arc, lpVDIM vdim);
static sgFloat def_angle_point_on_arc(lpD_POINT p, lpGEO_ARC a);
BOOL bo_arc_object(lpGEO_ARC arc, lpREGION_3D gab_arc, hOBJ hbody, lpVDIM vdim)
{
lpOBJ obj;//nb = NULL;
SCAN_CONTROL sc;
OSCAN_COD cod;
BO_ARC_DATA cd;
obj = (lpOBJ)hbody;
if ( obj->type != OBREP ) {
put_message(EMPTY_MSG,GetIDS(IDS_SG029),0);
return FALSE;
}
cd.arc = *arc;
cd.flag_arc = TRUE;
cd.gab = *gab_arc;
init_scan(&sc);
cd.vdim = vdim;
sc.user_geo_scan = arc_scan;
sc.data = &cd;
cod = o_scan(hbody, &sc);
if ( cod != OSTRUE ) return FALSE;
return TRUE;
}
#pragma argsused
static OSCAN_COD arc_scan(hOBJ hobj, lpSCAN_CONTROL lpsc)
{
int i;
lpBO_ARC_DATA data;
lpD_POINT v;
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
return OSFALSE;
}
data = (lpBO_ARC_DATA)(lpsc->data);
npwg->type = TNPW;
v = npwg->v;
for (i = 1; i <= npwg->nov ; i++) {
if ( !o_hcncrd(lpsc->m,&v[i],&v[i])) return OSFALSE;
}
dpoint_minmax(&npwg->v[1], npwg->nov, &npwg->gab.min, &npwg->gab.max);
if ( np_gab_inter(&npwg->gab, &data->gab) ) return OSTRUE;
if ( !np_cplane(npwg) ) return OSFALSE;
if ( !b_arc_np(npwg, &data->arc, data->flag_arc, data->vdim) ) return OSFALSE;
return OSTRUE;
}
static BOOL b_arc_np(lpNPW np, lpGEO_ARC arc, BOOL flag_arc, lpVDIM vdim)
{
#define DIST(v) ((v)->x*ka + (v)->y*kb + (v)->z*kc + kd)
short i, v, edge, kp;
short face;
D_PLANE pl;
GEO_LINE line;
BO_INTER_POINT ip;
NP_TYPE_POINT type;
NP_VERTEX_LIST ver = {0,0,NULL,NULL};
BOOL rt;//nb = TRUE;
D_POINT p[2];
pl.v = arc->n;
pl.d = dcoef_pl(&arc->vc, &pl.v);
if ( !(rt = np_ver_alloc(&ver)) ) return FALSE;
for (face = 1; face <= np->nof; face++) {
if (fabs(np->p[face].v.x - pl.v.x) <= eps_n &&
fabs(np->p[face].v.y - pl.v.y) <= eps_n &&
fabs(np->p[face].v.z - pl.v.z) <= eps_n ||
fabs(np->p[face].v.x + pl.v.x) <= eps_n &&
fabs(np->p[face].v.y + pl.v.y) <= eps_n &&
fabs(np->p[face].v.z + pl.v.z) <= eps_n ) continue;
ver.uk = 0;
np->nov_tmp = np->maxnov;
if ( !(rt=np_pl(np, face, &ver, &pl)) ) { rt = FALSE; goto end; }
if (ver.uk == 0) continue;
line.v1 = np->v[ver.v[0].v];
line.v2 = np->v[ver.v[1].v];
if ( !intersect_3d_la(&line, FALSE, arc, flag_arc, p, &kp) ) {
rt = FALSE;
goto end;
}
if ( !kp ) continue;
for (i = 0; i < kp; i++) {
type = np_point_belog_to_face1(np, &p[i], face, &edge, &v);
if ( type == NP_OUT ) continue;
ip.p = p[i];
if ( flag_arc && (fabs(dpoint_distance(&p[i], &arc->vb)) < eps_d ||
fabs(dpoint_distance(&p[i], &arc->ve)) < eps_d) ) {
if ( type == NP_IN ) ip.type = B_IN_ON;
else ip.type = B_ON_ON;
} else {
if ( type == NP_IN ) ip.type = B_IN_IN;
else ip.type = B_ON_IN;
}
ip.t = fabs(def_angle_point_on_arc(&ip.p, arc));
if ( !add_elem(vdim,&ip) ) { rt = FALSE; goto end; }
continue;
}
}
end:
np_free_ver(&ver);
return rt;
}
static sgFloat def_angle_point_on_arc(lpD_POINT p, lpGEO_ARC a)
{
D_POINT w;
sgFloat an;
if ( dpoint_distance(p, &a->vb) < eps_d ) return 0;
if ( dpoint_distance(p, &a->ve) < eps_d ) return a->angle;
// memcpy(a1, a, sizeof(GEO_ARC));
// memcpy(a2, a, sizeof(GEO_ARC));
// dpoint_copy(&a1->ve, p);
// dpoint_copy(&a2->vb, p);
get_c_matr((lpGEO_CIRCLE)a, el_g_e, el_e_g);
o_hcncrd(el_g_e, p, &w);
an = v_angle(w.x, w.y);
if(a->angle > 0.)
while(an < a->ab)
an += 2.*M_PI;
else
while(an > a->ab)
an -= 2.*M_PI;
an = an - a->ab;
return an;
}
+115
View File
@@ -0,0 +1,115 @@
#include "../sg.h"
//static BOOL b_def_angle(lpNPW np, short v3, short r1, short r2, short face);
//short b_def_loop(lpNPW np, short face, short r, short *rl);
BOOL b_as(lpNPW np)
{
short face;
short r,rt;
short cl,cnt,cnt1,cnt2;
short l,new_c;
short rl1=0,rl2=0;
for (face=1 ; face <= np->nof ; face++) {
cnt = np->f[face].fc;
do {
cl = cnt;
cnt = np->c[cnt].nc;
} while (cnt > 0);
if (cnt == 0) continue;
cnt = -cnt;
np->c[cl].nc = 0;
r = np->c[cnt].fe;
for(;;) {
rt = r;
if (rt == 0) break;
r = np->efc[r].ep;
np->c[cnt].fe = r;
np->efc[rt].ep = -rt;
np->efc[rt].em = rt;
l = 0;
cnt1 = np_def_loop(np, face, rt, &rl1);
cnt2 = np_def_loop(np, face,(short)(-rt), &rl2);
if (cnt1 != 0) {
l = l + 1;
np_insert_edge(np,rt,rl1);
}
if (cnt2 != 0) {
l = l + 1;
np_insert_edge(np,(short)(-rt),rl2);
}
if (l == 1) continue;
if (l == 0) {
if ((new_c = np_new_loop(np,rt)) == 0) return FALSE;
np->c[new_c].nc = np->f[face].fc;
np->f[face].fc = new_c;
continue;
}
np_an_loops(np,face,cnt1,cnt2,rt);
}
}
return TRUE;
}
/*
short b_def_loop(lpNPW np, short face, short r, short *rl)
{
short vn,vk,vt;
short rt,rn,rf;
short cnt;
vn = BE(r,np);
vk = EE(r,np);
cnt = np->f[face].fc;
do {
rt = rf = np->c[cnt].fe;
vt = EE(rt,np);
do {
if (vt == vn) {
rn = SL(rt,np);
if (rn == -rt) goto norm;
if (b_def_angle(np,vk,rt,rn,face)) goto norm;
}
rt = SL(rt,np);
vt = EE(rt,np);
} while (rt != rf);
cnt = np->c[cnt].nc;
} while (cnt != 0);
return 0;
norm: *rl = rt;
return cnt;
}
*/
/*
static BOOL b_def_angle(lpNPW np, short v3, short r1, short r2, short face)
{
short v,v1,v2;
D_POINT a1, a2, a3, c,d1,d2;
sgFloat cr, cr1, cr2;
v1 = BE(r1,np); v2 = EE(r2,np); v = EE(r1,np);
dpoint_sub(&(np->v[v]),&(np->v[v1]), &a1);
dpoint_sub(&(np->v[v]),&(np->v[v2]), &a2);
dpoint_sub(&(np->v[v]),&(np->v[v3]), &a3);
dvector_product(&a1, &a2, &c);
cr = dskalar_product(&c, &(np->p[face].v));
if ((fabs(cr)) <= eps_d) {
dvector_product(&a1, &a3, &c);
cr = dskalar_product(&c, &(np->p[face].v));
if (cr < 0) return TRUE;
return FALSE;
}
dvector_product(&a1, &a3, &d1);
dvector_product(&a3, &a2, &d2);
cr1 = dskalar_product(&d1, &c);
cr2 = dskalar_product(&d2, &c);
if (cr < eps_d) {
if(cr1 > 0 && cr2 > 0) return TRUE;
return FALSE;
}
if (cr1 > 0 && cr2 >0) return FALSE;
return TRUE;
}
*/
+33
View File
@@ -0,0 +1,33 @@
#include "../sg.h"
void b_av(short mt, short *p,short *pr,short *pt, BOOL *le)
{
if (abs(mt) == 1) {
*p=-*p;
return;
}
if (abs(mt) == 4) return;
if (mt == 2) {
if (*pr < 0) {
*pt=*p; *p=1; *pr=1;
*le = TRUE;
return;
} else {
*p=*pt; *pr=-1;
*le = FALSE;
return;
}
} else { /* mt=3 */
if (*pr < 0) {
*pt=*p; *p=1; *pr=1;
*le = TRUE;
return;
} else {
*p=-*pt; *pr=-1;
*le = FALSE;
return;
}
}
}
+448
View File
@@ -0,0 +1,448 @@
#include "../sg.h"
//static lpNPW np_cut = NULL;
static OSCAN_COD cut_geo_scan(hOBJ hobj,lpSCAN_CONTROL lpsc);
static BOOL cut_pl(lpNPW np, lpD_PLANE pl, lpNPW np_cut);
static BOOL cut_up(lpNPW np, lpNP_VERTEX_LIST ver, lpD_PLANE pl, lpNPW np_cut);
static BOOL cut_zav(lpNPW np_cut);
typedef struct {
D_PLANE pl;
lpNPW np_cut;
lpLISTH listh_cut;
} CUT_DATA;
typedef CUT_DATA * lpCUT_DATA;
#define EDIT_EDGE_LABLE 0x1000
#pragma argsused
BOOL cut(lpLISTH list, NUM_LIST num_list, lpD_PLANE pl, lpLISTH listh_cut)
{
// short num_proc;
OBJTYPE type;
SCAN_CONTROL sc;
OSCAN_COD cod;
REGION_3D gab_obj = {{1.e35,1.e35,1.e35},{-1.e35,-1.e35,-1.e35}};
CUT_DATA cd={{{0.,0.,-1.},0}/*,{1.e35,1.e35,1.e35},{-1.e35,-1.e35,-1.e35}*/, NULL};
hOBJ hobj, hnext; //, hobj_c = NULL;
lpOBJ obj;
ODRAWSTATUS dstatus;
lpNPW np_cut;
// VMM_Clear_Ram();
init_listh(listh_cut);
if ( (cd.np_cut = creat_np_mem(TNPW,MAXNOV*2,MAXNOV*2,10,10,MAXNOV*2))
== NULL ) return FALSE;
np_cut = cd.np_cut;
cd.pl = *pl;
cd.listh_cut = listh_cut;
init_scan(&sc);
sc.data = &cd;
sc.user_geo_scan = cut_geo_scan;
hobj = list->hhead;
while (hobj != NULL) {
// step_grad (num_proc , j++);
get_next_item_z(num_list,hobj,&hnext);
obj = (lpOBJ)hobj;
dstatus = obj->drawstatus;
type = obj->type;
if (dstatus == ST_HIDE) goto met;
if ( type != OBREP && type != OGROUP ) goto met;
if ( !get_object_limits(hobj, &gab_obj.min, &gab_obj.max) ) goto err;
define_eps(&gab_obj.min, &gab_obj.max);
if (np_gab_pl(&gab_obj, &cd.pl, eps_d)) goto met;
cod = o_scan(hobj,&sc);
switch ( cod ) {
case OSSKIP:
break;
case OSBREAK:
cod = OSTRUE;
goto br;
case OSTRUE:
// tb_clear();
/* if ( np_cut->nov ) {
// tb_setcolor(IDXYELLOW);
if ( !cut_zav(np_cut) ) goto err;
dpoint_minmax(&np_cut->v[1],np_cut->nov,&(np_cut->gab.min),
&(np_cut->gab.max));
np_gab_un(&gab_cut, &(np_cut->gab), &gab_cut);
init_listh(&listh_path);
loop = 1;
do {
if((hobj_path = o_alloc(OPATH)) == NULL) goto err;
obj_path = (lpOBJ)hobj_path;
geo_path = (lpGEO_PATH)obj_path->geo_data;
o_hcunit(geo_path->matr);
init_listh(&geo_path->listh);
first_edge = edge = np_cut->c[loop].fe;
vertex = BE(edge, np_cut);
vn = np_cut->v[vertex];
min = vn;
max = vn;
do {
vertex = EE(edge, np_cut);
vk = np_cut->v[vertex];
modify_limits_by_point(&vk, &min, &max);
// if ( !tb_put_otr(vn,vk) ) goto err;
if((hobj_line = o_alloc(OLINE)) == NULL) goto err;
obj_line = (lpOBJ)hobj_line;
obj_line->hhold = hobj_path;
geo_line = (lpGEO_LINE)(obj_line->geo_data);
geo_line->v1 = vn;
geo_line->v2 = vk;
attach_item_tail(&geo_path->listh, hobj_line);
vn = vk;
edge = SL(edge, np_cut);
} while ( edge != first_edge && edge != 0);
geo_path->min = min;
geo_path->max = max;
obj_path->status |= ST_FLAT;
if ( edge == first_edge ) obj_path->status |= ST_CLOSE;
if ((cod1 = test_self_cross_path(hobj_path,NULL)) == OSFALSE) goto err;
if (cod1 == OSTRUE) {
obj_path = (lpOBJ)hobj_path;
obj_path->status |= ST_SIMPLE;
}
attach_item_tail(&listh_path, hobj_path);
loop = np_cut->c[loop].nc;
} while (loop != 0);
if ( listh_path.num > 0) {
if ( (hobj_c = make_group(&listh_path)) == NULL ) goto err;
attach_item_tail(listh_cut, hobj_c);
}
}
*/
// tb_clear();
goto met;
case OSFALSE:
default:
goto err;
}
met:hobj = hnext;
}
// end_grad(num_proc, i);
// num_proc = -1;
cod = OSTRUE;
goto end;
err:
cod = OSFALSE;
br:
end:
// tb_clear();
np_free_stack();
free_np_mem(&np_cut);
return cod;
}
static OSCAN_COD cut_geo_scan(hOBJ hobj, lpSCAN_CONTROL lpsc)
{
register short i;
lpGEO_BREP lpgeobrep;
REGION_3D gab = {{1.e35,1.e35,1.e35},{-1.e35,-1.e35,-1.e35}};
lpD_POINT v;//, vn, vk;
lpNPW np_cut;
D_POINT vn, vk, min, max;
int loop, edge, vertex, first_edge;
OSCAN_COD cod;
hOBJ hobj_c;//nb = NULL;
hOBJ hobj_line, hobj_path;
lpOBJ obj, obj_line, obj_path;
lpGEO_LINE geo_line;
lpGEO_PATH geo_path;
LISTH listh_path = {NULL,NULL,0};
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
return OSBREAK;
}
// step_grad (num_proc , i);
if ( lpsc->type != OBREP) return OSSKIP;
if ( lpsc->breptype != BODY && lpsc->breptype != SURF) return OSSKIP;
np_cut = ((lpCUT_DATA)(lpsc->data))->np_cut;
if ( scan_flg_np_begin ) {
// tb_setcolor(IDXYELLOW);
// breptype = lpsc->breptype;
obj = (lpOBJ)hobj;
lpgeobrep = (lpGEO_BREP)obj->geo_data;
gab.min = lpgeobrep->min;
gab.max = lpgeobrep->max;
f3d_gabar_project1(lpgeobrep->matr,&gab.min,&gab.max,&gab.min,&gab.max);
if (np_gab_pl(&gab, &((lpCUT_DATA)(lpsc->data))->pl, eps_d)) return OSSKIP;
np_init(np_cut);
}
npwg->type = TNPW;
v = npwg->v;
for (i = 1; i <= npwg->nov ; i++) {
if ( !o_hcncrd(lpsc->m,&v[i],&v[i])) return OSFALSE;
}
dpoint_minmax(&npwg->v[1], npwg->nov, &npwg->gab.min,&npwg->gab.max);
if ( !np_gab_pl(&npwg->gab, &((lpCUT_DATA)lpsc->data)->pl, eps_d)) {
if ( !np_cplane(npwg) ) return OSFALSE;
if ( cut_pl(npwg, &((lpCUT_DATA)lpsc->data)->pl,
np_cut) == FALSE ) return OSFALSE;
}
if ( scan_flg_np_end ) {
if ( np_cut->nov ) {
if ( !cut_zav(np_cut) ) return OSFALSE;
init_listh(&listh_path);
loop = 1;
do {
if((hobj_path = o_alloc(OPATH)) == NULL) return OSFALSE;
obj_path = (lpOBJ)hobj_path;
geo_path = (lpGEO_PATH)obj_path->geo_data;
o_hcunit(geo_path->matr);
init_listh(&geo_path->listh);
first_edge = edge = np_cut->c[loop].fe;
vertex = BE(edge, np_cut);
vn = np_cut->v[vertex];
min = vn;
max = vn;
do {
vertex = EE(edge, np_cut);
vk = np_cut->v[vertex];
if (!dpoint_eq(&vn, &vk, eps_d)) {
modify_limits_by_point(&vk, &min, &max);
// if ( !tb_put_otr(vn,vk) ) goto err;
if((hobj_line = o_alloc(OLINE)) == NULL) return OSFALSE;
obj_line = (lpOBJ)hobj_line;
obj_line->hhold = hobj_path;
geo_line = (lpGEO_LINE)(obj_line->geo_data);
geo_line->v1 = vn;
geo_line->v2 = vk;
attach_item_tail(&geo_path->listh, hobj_line);
vn = vk;
}
edge = SL(edge, np_cut);
} while ( edge != first_edge && edge != 0);
if (geo_path->listh.num == 0) {
o_free(hobj_path, NULL);
} else {
geo_path->min = min;
geo_path->max = max;
obj_path->status |= ST_FLAT;
if ( edge == first_edge ) obj_path->status |= ST_CLOSE;
if ((cod = test_self_cross_path(hobj_path,NULL)) == OSFALSE) return OSFALSE;
if (cod == OSTRUE) {
obj_path = (lpOBJ)hobj_path;
obj_path->status |= ST_SIMPLE;
}
attach_item_tail(&listh_path, hobj_path);
}
loop = np_cut->c[loop].nc;
} while (loop != 0);
if ( listh_path.num > 0) {
if ( (hobj_c = make_group(&listh_path, TRUE)) == NULL ) return OSFALSE;
attach_item_tail(((lpCUT_DATA)(lpsc->data))->listh_cut, hobj_c);
}
// tb_clear();
}
}
return OSTRUE;
}
static BOOL cut_pl(lpNPW np, lpD_PLANE pl, lpNPW np_cut)
{
short face;
NP_VERTEX_LIST ver = {0,0,NULL,NULL};
BOOL rt;//nb = FALSE;
if ( !(rt = np_ver_alloc(&ver)) ) goto end;
for (face = 1 ; face <= np->nof ; face++) {
if (fabs(np->p[face].v.x - pl->v.x) <= eps_n &&
fabs(np->p[face].v.y - pl->v.y) <= eps_n &&
fabs(np->p[face].v.z - pl->v.z) <= eps_n ||
fabs(np->p[face].v.x + pl->v.x) <= eps_n &&
fabs(np->p[face].v.y + pl->v.y) <= eps_n &&
fabs(np->p[face].v.z + pl->v.z) <= eps_n ) continue;
ver.uk = 0;
np->nov_tmp = np->maxnov;
if ( !(rt=np_pl(np, face, &ver, pl)) ) goto end;
if (ver.uk == 0) continue;
np_axis = np_defc( &np->p[face].v, &pl->v);
np_sort_ver(np->v,&ver,np_axis);
if ( !(rt=cut_up(np, &ver, pl, np_cut)) ) goto end;
}
rt = TRUE;
end:
np_free_ver(&ver);
return rt;
}
/************************************************
* --- BOOL cut_up ---
*
************************************************/
static BOOL cut_up(lpNPW np, lpNP_VERTEX_LIST ver, lpD_PLANE pl, lpNPW np_cut)
{
short p = -1, pr = -1, pt = -1;
short p1, p2, face1, face2;
short ukt = 0;
short w1, w2;
short edge, r;
float gru;
D_POINT vvn, vvk;
lpD_POINT vn, vk;
BOOL le = FALSE;
while (ukt < ver->uk) {
np_av(ver->v[ukt].m,&p,&pr,&pt,&le);
ukt++;
if (p == 1) {
r = b_vran(np, ver, ukt);
if ( le ) {
face1 = EF( r,np);
face2 = EF(-r,np);
if (face2 < 0) face2 = np_calc_gru(np, (short)(abs(r)));
p1 = b_pv(np, r, pl);
p2 = b_pv(np,(short)(-r), pl);
if (p1 == p2) continue;
if (p1 == 0 || p2 == 0) {
if ( face2 == 0) gru = np->gru[(int)abs(r)];
else
if (face1 > 0 && face2 > 0)
if ( (gru=np_gru(np,r,&np->p[face1].v,&np->p[face2].v)) == 0 )
return FALSE;
if (gru > M_PI) continue;
}
}
face1 = EF(r,np);
vvn = np->v[ver->v[ukt-1].v];
vvk = np->v[ver->v[ukt].v];
vn = &vvn; vk = &vvk;
if ( !b_ort(&vn,&vk,&(np->p[face1].v),&pl->v) ) return FALSE;
if ( (w1 = np_new_vertex(np_cut, vn)) == 0) return FALSE;
if ( (w2 = np_new_vertex(np_cut, vk)) == 0) return FALSE;
if ( w1 != w2 ) {
if ( !(edge=np_new_edge(np_cut,w1,w2)) ) return FALSE;
if (edge < 0) continue;
np_cut->efc[edge].fp = 1;
}
}
}
return TRUE;
}
static BOOL cut_zav(lpNPW np_cut)
{
short i, ii;
short loop1, loop2;
short first_edge, edge;
short v;
BOOL rt = TRUE;
ii = 0;
loop2 = 0;
while ( 1 ) {
for (i=1 ; i <= np_cut->noe ; i++) {
// if (np_cut->efc[i].ep == 0) break;
if (np_cut->efr[i].el & EDIT_EDGE_LABLE) continue;
break;
}
if (i > np_cut->noe) break;
ii++;
if ( !(loop1=np_new_loop(np_cut, i)) ) return FALSE;
if ( loop2 != 0 ) np_cut->c[loop2].nc = loop1;
loop2 = loop1;
first_edge = edge = i;
np_cut->efr[edge].el |= EDIT_EDGE_LABLE;
while ( 1 ) {
v = np_cut->efr[edge].ev;
for (i=1 ; i <= np_cut->noe ; i++) {
if (np_cut->efr[i].bv == v) {
if ( np_cut->efc[i].ep ) continue;
np_cut->efc[edge].ep = i;
np_cut->efr[i].el |= EDIT_EDGE_LABLE;
edge = i;
ii++;
break;
}
}
if (i > np_cut->noe) {
// last_edge = edge;
edge = first_edge;
while ( 1 ) {
v = np_cut->efr[edge].bv;
for (i=1 ; i <= np_cut->noe ; i++) {
if (np_cut->efr[i].ev == v) {
if (np_cut->efr[i].el & EDIT_EDGE_LABLE) continue;
np_cut->efc[i].ep = edge;
edge = i;
np_cut->efr[i].el |= EDIT_EDGE_LABLE;
ii++;
break;
}
}
if (i > np_cut->noe) {
np_cut->c[loop1].fe = edge;
goto met;
}
}
}
if (np_cut->efr[edge].ev == np_cut->efr[first_edge].bv) {
np_cut->efc[edge].ep = first_edge;
break;
}
}
met: if (ii >= np_cut->noe) break;
}
for (i=1; i<=np_cut->noe; i++) {
if ( !(np_cut->efr[i].el & EDIT_EDGE_LABLE) ) continue;
np_cut->efr[i].el &= (~EDIT_EDGE_LABLE);
}
return rt;
}
/*
void cut_ort_loop(lpNPW np)
{
short loop; //, lc;
int to, from, nxt;
sgFloat sq;
// lc = 0;
loop = np->f[1].fc;
do {
np_ort_loop(np,1,loop,&sq);
if (sq < 0) {
to = np->c[loop].fe;
from = SL(to,np);
do {
if (from > 0) {
nxt = np->efc[abs(from)].ep;
np->efc[abs(from)].em = -to;
} else {
nxt = np->efc[abs(from)].em;
np->efc[abs(from)].ep = -to;
}
to = from;
from = nxt;
} while (to != np->c[loop].fe);
np->c[loop].fe = - np->c[loop].fe;
}
// lc = loop;
loop = np->c[loop].nc;
} while (loop != 0);
}
*/
+21
View File
@@ -0,0 +1,21 @@
#include "../sg.h"
/************************************************
* --- short b_defc ---
* ************************************************/
short b_defc(void)
{
D_POINT c;
dvector_product(&(npa->p[facea].v), &(npb->p[faceb].v),&c);
c.x = fabs(c.x);
c.y = fabs(c.y);
c.z = fabs(c.z);
if (c.x <= c.y)
if (c.y <= c.z) return 2;
else return 1;
else
if (c.x <= c.z) return 2;
else return 0;
}
+144
View File
@@ -0,0 +1,144 @@
#include "../sg.h"
/************************************************
* --- void b_del ---
*
************************************************/
BOOL b_del(lpNP_STR_LIST list_str, lpNPW np, lpNP_STR str)
{
short i,k,met,max=0;
BO_BIT_EDGE *bo;
NP_BIT_FACE *bf;
NP_STR str_n;
short ident,edge,face,index;
short *mem_ident;//nb = NULL;
if ( !(b_as(np)) ) return FALSE;
if ( !(b_fa(np)) ) return FALSE;
if ( (mem_ident = (short*)SGMalloc(sizeof(np->ident)*(np->noe))) == NULL )
return FALSE;
for (i = 1 ; i <= np->noe ; i++) {
if (np->efc[i].fp >= 0 && np->efc[i].fm >= 0) continue;
if (np->efc[i].fp < 0) {
ident = np->efc[i].ep;
face = np->efc[i].fm;
edge = i;
} else {
ident = np->efc[i].em;
face = np->efc[i].fp;
edge = -i;
}
bo = (BO_BIT_EDGE*)&np->efr[(int)abs(i)].el;
if (bo->flg != 0) {
if (edge > 0) met = bo->ep;
else met = bo->em;
met = b_face_label(met);
} else {
bf = (NP_BIT_FACE*)&np->f[face].fl;
met = bf->met;
}
k = 0;
while (k < max) {
if (mem_ident[k] == ident) break;
k++;
}
if (k < max) continue;
mem_ident[max] = ident;
max++;
if (met == 0) met = -1;
if ( !(np_get_str(list_str,ident,&str_n,&index)) ) goto err;
if (str_n.lab == 0 || str_n.lab == -2) {
str_n.lab = met;
write_elem(&list_str->vdim,index,&str_n);
if (object_number == 2 && key == SUB) {
if (!(read_np(&list_str->bnp,str_n.hnp,npb))) goto err;
np_inv(npb,NP_ALL);
if ( !(overwrite_np(&list_str->bnp,str_n.hnp,npb,TNPW)) ) goto err;
}
}
continue;
}
SGFree(mem_ident);
if (object_number == 2 && key == SUB) np_inv(np,NP_ALL);
if ( !(np_del_face(np)) ) return FALSE;
if (np->nof == 0) {
str->lab = -1;
return TRUE;
}
// if ( brept1 ) b_move_gru(np);
b_move_gru(np);
if ( !(np_del_edge(np)) ) return FALSE;
np_del_vertex(np);
np_del_loop(np);
for (i=1 ; i <= np->noe ; i++) {
bo = (BO_BIT_EDGE*)&np->efr[i].el;
bo->flg = 0;
bo->em = 0;
bo->ep = 0;
}
if ( !b_sv(np) ) str->ort |= ST_SV;
else if (np->nov > MAXNOV || np->noe > MAXNOE ||
np->nof > MAXNOF || np->noc > MAXNOC) {
str->ort |= ST_MAX;
}
return TRUE;
err:
SGFree(mem_ident);
return FALSE;
}
void b_move_gru(lpNPW np)
{
short i;
lpBO_USER us;
sgFloat con = c_smooth_angle;
// sgFloat con = d_radian(c_smooth_angle);
us = (lpBO_USER)np->user;
for (i = 1 ; i <= np->noe ; i++) {
if (np->efc[i].fp > 0 && np->efc[i].fm <= 0 && us[i].bnd > 0) {
np->gru[i] = us[i].bnd;
np->efc[i].em = us[i].ind;
np->efc[i].fm = -i;
if (fabs(us[i].bnd - M_PI) < eps_n) {
np->efr[i].el = ST_TD_DUMMY;
continue;
}
if (fabs(us[i].bnd - M_PI) < con) {
np->efr[i].el = ST_TD_APPROCH | ST_TD_COND;
}
continue;
}
if (np->efc[i].fm > 0 && np->efc[i].fp <= 0 && us[i].bnd > 0) {
np->gru[i] = us[i].bnd;
np->efc[i].ep = us[i].ind;
np->efc[i].fp = - i;
if (fabs(us[i].bnd - M_PI) < eps_n) {
np->efr[i].el = ST_TD_DUMMY;
continue;
}
if (fabs(us[i].bnd - M_PI) < con) {
np->efr[i].el = ST_TD_APPROCH | ST_TD_COND;
}
continue;
}
if (np->efc[i].fm > 0 && np->efc[i].fp > 0) {
if (np->efr[i].el & ST_TD_APPROCH) continue;
facea = np->efc[i].fp;
faceb = np->efc[i].fm;
if (fabs(np->p[facea].v.x - np->p[faceb].v.x) <= eps_n &&
fabs(np->p[facea].v.y - np->p[faceb].v.y) <= eps_n &&
fabs(np->p[facea].v.z - np->p[faceb].v.z) <= eps_n ) {
np->efr[i].el = ST_TD_DUMMY;
}
}
}
}
+227
View File
@@ -0,0 +1,227 @@
#include "../sg.h"
//int b_np_max(lpNPW np);
static BOOL b_big_face(lpNPW np);
static BOOL b_put_index(hINDEX *hindex, short *num_index,lpNP_STR_LIST list_str,
lpNPW np, lpNP_STR str);
BOOL b_del_sv(lpNP_STR_LIST list_str, lpNP_STR str)
{
short i,j,jjj;
short bv_npw, ev_npw, bv_npd, ev_npd;
short num_index, num_index2;
short old_ident,ident;
short max,k;
VNP vnpd;
lpNPW npw, npd;
hINDEX hindex, hindex2;
// SVTYPE status = BO_FIRST;
lpNP_STR_LIST list, list2, listd;
lpNP_BIT_FACE b;
BOOL rt = TRUE;
short* mem_ident;
NP_STR str_new;
if (object_number == 1) {
hindex = hindex_a; num_index = num_index_a;
hindex2 = hindex_b; num_index2 = num_index_b;
list = &lista; list2 = &listb;
} else {
hindex = hindex_b; num_index = num_index_b;
hindex2 = hindex_a; num_index2 = num_index_a;
list = &listb; list2 = &lista;
}
if (!(read_np(&list_str->bnp,str->hnp,npa))) return FALSE;
if ( !b_big_face(npa) ) return FALSE;
mem_ident = (short*)SGMalloc(sizeof(npa->ident)*(npa->noe));
str_new = *str;
npw = npa;
for (;;) {
if ( np_max(npw) == npa->nof )
break;
if ( !np_write_np_tmp(npw) ) { rt = FALSE; goto end; }
if ( !(np_del_face(npw)) ) { rt = FALSE; goto end; }
b_move_gru(npw);
if ( !(np_del_edge(npw)) ) { rt = FALSE; goto end; }
np_del_vertex(npw);
np_del_loop(npw);
if ( !(overwrite_np(&list_str->bnp,str_new.hnp,npw,TNPW)) )
{ rt = FALSE; goto end; }
if ( !np_read_np_tmp(npw) ) { rt = FALSE; goto end; }
for (i=1 ; i <= npw->nof ; i++) {
b = (NP_BIT_FACE*)&npw->f[i].fl;
if (b->met == 1) b->met=0;
else b->met=1;
}
if ( !(np_del_face(npw)) ) { rt = FALSE; goto end; }
b_move_gru(npw);
if ( !(np_del_edge(npw)) ) { rt = FALSE; goto end; }
np_del_vertex(npw);
np_del_loop(npw);
old_ident = npw->ident;
npw->ident = ident_c++;
if ( !b_put_index(&hindex,&num_index,list,npw,&str_new) ) { rt = FALSE; goto end;}
// met:
max = 0;
for (i=1 ; i <= npw->noe ; i++) {
if (npw->efc[i].fp >= 0 && npw->efc[i].fm >= 0) continue;
if (npw->efc[i].fp < 0) ident = npw->efc[i].ep;
else ident = npw->efc[i].em;
k = 0;
while (k < max) {
if (mem_ident[k] == ident) break;
k++;
}
if (k < max) continue;
mem_ident[max] = ident;
max++;
listd = list;
vnpd = b_get_hnp(hindex, num_index, ident);
if (vnpd == 0) {
listd = list2;
if ( !(vnpd=b_get_hnp(hindex2,num_index2,ident)) ) {
put_message(INTERNAL_ERROR,GetIDS(IDS_SG019),0);
rt = FALSE;
goto end;
}
}
if (!(read_np(&listd->bnp,vnpd,npb))) { rt = FALSE;goto end; }
npd = npb;
for (j=1 ; j <= npd->noe ; j++) {
if (npd->efc[j].ep == old_ident || npd->efc[j].em == old_ident) {
for (jjj=i ; jjj <= npw->noe ; jjj++) {
if (npw->efc[jjj].ep == npd->ident ||
npw->efc[jjj].em == npd->ident) {
bv_npw = npw->efr[jjj].bv;
ev_npw = npw->efr[jjj].ev;
bv_npd = npd->efr[j].bv;
ev_npd = npd->efr[j].ev;
if ( !(dpoint_eq(&npw->v[bv_npw],&npd->v[bv_npd],eps_d)) &&
!(dpoint_eq(&npw->v[bv_npw],&npd->v[ev_npd],eps_d))) continue;
if ( !(dpoint_eq(&npw->v[ev_npw],&npd->v[bv_npd],eps_d)) &&
!(dpoint_eq(&npw->v[ev_npw],&npd->v[ev_npd],eps_d))) continue;
if (npd->efc[j].ep == old_ident) {
npd->efc[j].ep = npw->ident;
break;
}
if (npd->efc[j].em == old_ident) {
npd->efc[j].em = npw->ident;
break;
}
}
}
}
}
if ( !(overwrite_np(&listd->bnp,vnpd,npb,TNPW)) )
{ rt = FALSE; goto end; }
}
if ( !(overwrite_np(&list_str->bnp,str_new.hnp,npw,TNPW)) ) { rt = FALSE; goto end;}
}
end:
if (object_number == 1) { hindex_a = hindex; num_index_a = num_index; }
else { hindex_b = hindex; num_index_b = num_index; }
if ( mem_ident ) SGFree(mem_ident);
np_free_np_tmp();
return rt;
}
static BOOL b_big_face(lpNPW np)
{
short noe, nov, noc;
short edge, fedge, iedge, v, face, loop;
BO_BIT_EDGE *bo;
NP_BIT_FACE *bfp;
char *lv, *lc;
BOOL rt = TRUE;
noe = nov = noc =0;
lv = (char*)SGMalloc(sizeof(char)*(np->maxnov+1));
lc = (char*)SGMalloc(sizeof(char)*(np->maxnoc+1));
for (face = 1; face <= np->nof; face++) {
bfp = (NP_BIT_FACE*)&np->f[face].fl;
bfp->met = 0;
loop = np->f[face].fc;
lc[loop] = 1;
noc++;
do {
if (lc[loop] == 0 ) { lc[loop] = 1; noc++; }
edge = fedge = np->c[loop].fe; v = BE(edge,np);
do {
if ( lv[v] == 0 ) { lv[v] = 1; nov++; }
iedge = abs(edge);
bo = (BO_BIT_EDGE*)&np->efr[iedge].el;
if (bo->flg == 0) { bo->flg = 1; noe++; }
edge = SL(edge,np); v = BE(edge,np);
} while (edge != fedge);
loop = np->c[loop].nc;
} while (loop > 0);
if (nov >= MAXNOV || noe > MAXNOE || noc >= MAXNOC ) {
if ( !b_divide_face(np, face) ) { rt = FALSE; goto end; }
face--;
}
noe = nov = noc = 0;
memset(lv,0,sizeof(char)*(np->maxnov+1));
memset(lc,0,sizeof(char)*(np->maxnoc+1));
}
end:
for (edge=1 ; edge <= np->noe ; edge++) {
bo = (BO_BIT_EDGE*)&np->efr[edge].el;
bo->flg = 0;
}
SGFree(lc);
SGFree(lv);
return rt;
}
static BOOL b_put_index(hINDEX *hindex, short *num_index,
lpNP_STR_LIST list_str, lpNPW np, lpNP_STR str)
{
short i, number;
// NP_STR str;
VNP vnp;
hINDEX hindex_new;
lpINDEX index, index_new;
dpoint_minmax(&np->v[1], np->nov, &np->gab.min, &np->gab.max);
memset(str,0,sizeof(NP_STR));
str->ident = np->ident;
str->lab = 1;
memcpy(&str->gab,&np->gab,sizeof(REGION_3D));
if ( !(vnp = write_np(&list_str->bnp,np,TNPW)) ) return FALSE;
str->hnp = vnp;
if ( !( add_elem(&list_str->vdim,str)) ) return FALSE;
list_str->number_all++;
number = list_str->number_all - 1;
if ( *num_index == number) {
hindex_new = SGMalloc(sizeof(INDEX)*(number+10));
index_new = (lpINDEX)hindex_new;
index = (lpINDEX)(*hindex);
memcpy(index_new,index,sizeof(INDEX)*(*num_index));
for (i=*num_index ; i < *num_index+10 ; i++)
index_new[i].ident = MAXSHORT;
SGFree(*hindex);
*num_index += 10;
index = index_new;
*hindex = hindex_new;
} else index = (lpINDEX)(*hindex);
index[number].ident = np->ident;
index[number].hnp = vnp;
return TRUE;
}
+130
View File
@@ -0,0 +1,130 @@
#include "../sg.h"
short b_diver(lpNPW np, lpNP_VERTEX_LIST ver, short ukt, short r,
lpD_POINT vn,lpD_POINT vk)
{
short ir,r_old,r1,r2,edge;
short v1,v2,w1,w2,wn,bv;
if ( (w1 = np_new_vertex(np, vn)) == 0) return 0;
if ( (w2 = np_new_vertex(np, vk)) == 0) return 0;
r_old = r;
r1 = ver->v[ukt-1].r;
r2 = ver->v[ukt ].r;
v1 = ver->v[ukt-1].v;
v2 = ver->v[ukt ].v;
ir = abs(r);
bv = np->efr[ir].bv;
if ((v1 == w1) && (v2 == w2)) return (r);
if (w2 == v2) {
if ( !(edge = b_dive(np, ir, w1)) ) return 0;
if (bv == v1) r = edge*isg(r);
return (r);
}
ver->v[ukt-1].v = w2;
if (w1 == v1) {
if ( !(edge = b_dive(np,ir,w2)) ) return 0;
if (bv == v2) r = edge*isg(r);
} else {
if (bv == v2) {
wn=w2; w2=w1; w1=wn;
}
if ( !(b_dive(np,ir,w2)) ) return 0;
if ( !(edge = b_dive(np,ir,w1)) ) return 0;
r = edge*isg(r);
}
if (r_old == r1) ver->v[ukt-1].r = SL(r2,np);
else {
ver->v[ukt-1].r = r;
ver->v[ukt ].r = SL(r,np);
}
return r;
}
short b_dive(lpNPW np, short edge, short v)
{
short bv, ev, vv;
short iedge, edged, ident;
lpNPW npd;
hINDEX hindex, hindex2;
short num_index, num_index2;
VNP vnp;
lpBO_USER user;
lpNP_STR_LIST listd, listdd;
iedge = abs(edge);
bv = np->efr[iedge].bv;
ev = np->efr[iedge].ev;
if (np->efc[iedge].fp < 0 || np->efc[iedge].fm < 0) {
if (np->efc[iedge].fp < 0) ident = np->efc[iedge].ep;
else ident = np->efc[iedge].em;
if (np == npa) npd = npb;
else npd = npa;
if ( object_number == 1) {
listd = &lista; listdd = &listb;
hindex = hindex_a; num_index = num_index_a;
hindex2 = hindex_b; num_index2 = num_index_b;
} else {
listd = &listb; listdd = &lista;
hindex = hindex_b; num_index = num_index_b;
hindex2 = hindex_a; num_index2 = num_index_a;
}
if ( !np_write_np_tmp(npd) ) return 0;
if ( !(vnp=b_get_hnp(hindex,num_index,ident)) ) {
listd = listdd;
if ( !(vnp=b_get_hnp(hindex2,num_index2,ident)) ) {
put_message(INTERNAL_ERROR,GetIDS(IDS_SG020),0);
goto err;
}
}
if ( !read_np(&listd->bnp,vnp,npd) ) goto err;
if ( (edged=b_search_edge(npd,&np->v[bv],&np->v[ev],
np->ident)) == 0) {
put_message(INTERNAL_ERROR,GetIDS(IDS_SG021),0);
goto err;
}
npd->nov_tmp = npd->maxnov;
if ( (vv=np_new_vertex(npd,&np->v[v])) == 0) goto err;
if ( (edged=np_divide_edge(npd,edged,vv)) == 0) goto err;
user = (lpBO_USER)npd->user;
user[edged].bnd = 0;
user[edged].ind = 0;
if ( !overwrite_np(&listd->bnp,vnp,npd,TNPW) ) goto err;
if ( !np_read_np_tmp(npd) ) return 0;
}
if ( (edged=np_divide_edge(np,edge,v)) == 0) return 0;
user = (lpBO_USER)np->user;
user[edged].bnd = 0;
user[edged].ind = 0;
return edged;
err:
np_free_np_tmp();
return 0;
}
short b_search_edge(lpNPW npw, lpD_POINT bv, lpD_POINT ev, short ident)
{
short edge;
short bv_npw, ev_npw;
for (edge=1 ; edge <= npw->noe ; edge++) {
if (npw->efc[edge].fp > 0 && npw->efc[edge].fm > 0) continue;
if (npw->efc[edge].ep == ident || npw->efc[edge].em == ident) {
bv_npw = npw->efr[edge].bv;
ev_npw = npw->efr[edge].ev;
if ( !(dpoint_eq(&npw->v[bv_npw],bv,eps_d)) &&
!(dpoint_eq(&npw->v[bv_npw],ev,eps_d))) continue;
if ( !(dpoint_eq(&npw->v[ev_npw],bv,eps_d)) &&
!(dpoint_eq(&npw->v[ev_npw],ev,eps_d))) continue;
break;
}
}
if (edge > npw->noe) return 0;
return edge;
}
+113
View File
@@ -0,0 +1,113 @@
#include "../sg.h"
static void b_def_pl(lpNPW np, short face, lpD_PLANE pl);
static BOOL b_cut_face_pl(lpNPW np, short face, lpD_PLANE pl, lpNP_VERTEX_LIST ver);
static BOOL b_up(lpNPW np, short face, lpNP_VERTEX_LIST ver);
BOOL b_divide_face(lpNPW np, short face)
{
NP_VERTEX_LIST ver = {0,0,NULL,NULL};
D_PLANE pl;
BOOL rt = TRUE;
if ( !np_ver_alloc(&ver) ) return FALSE;
b_def_pl(np, face, &pl);
if ( !b_cut_face_pl(np,face,&pl,&ver) ) { rt = FALSE; goto end; }
if ( !np_fa(np,face) ) rt = FALSE;
end:
np_free_ver(&ver);
np_free_stack();
return rt;
}
static void b_def_pl(lpNPW np, short face, lpD_PLANE pl)
{
short loop, edge, fedge, vn;
sgFloat dx, dy, dz;
REGION_3D g = {{1.e35,1.e35,1.e35},{-1.e35,-1.e35,-1.e35}};
pl->v.x = pl->v.y = pl->v.z = 0;
loop = np->f[face].fc;
do {
fedge = np->c[loop].fe;
edge = fedge;
//nb vn = BE(edge,np);
do {
vn = BE(edge,np);
if (g.min.x > np->v[vn].x) g.min.x = np->v[vn].x;
if (g.min.y > np->v[vn].y) g.min.y = np->v[vn].y;
if (g.min.z > np->v[vn].z) g.min.z = np->v[vn].z;
if (g.max.x < np->v[vn].x) g.max.x = np->v[vn].x;
if (g.max.y < np->v[vn].y) g.max.y = np->v[vn].y;
if (g.max.z < np->v[vn].z) g.max.z = np->v[vn].z;
edge = SL(edge,np);
} while(edge != fedge);
loop = np->c[loop].nc;
} while (loop != 0);
dx = fabs(g.max.x - g.min.x);
dy = fabs(g.max.y - g.min.y);
dz = fabs(g.max.z - g.min.z);
if (dx > dy) {
if (dx > dz) { pl->v.x = 1; pl->d = - (g.min.x + dx/2); }
else { pl->v.z = 1; pl->d = - (g.min.z + dz/2); }
} else {
if (dy > dz) { pl->v.y = 1; pl->d = - (g.min.y + dy/2); }
else { pl->v.z = 1; pl->d = - (g.min.z + dz/2); }
}
}
static BOOL b_cut_face_pl(lpNPW np, short face, lpD_PLANE pl, lpNP_VERTEX_LIST ver)
{
ver->uk = 0;
np->nov_tmp = np->maxnov;
if ( !np_pl(np, face, ver, pl) ) return FALSE;
if (ver->uk == 0) return TRUE;
np_axis = np_defc(&np->p[face].v,&pl->v);
np_sort_ver(np->v, ver, np_axis);
if ( !b_up(np,face,ver) ) return FALSE;
return TRUE;
}
static BOOL b_up(lpNPW np, short face, lpNP_VERTEX_LIST ver)
{
short p = -1, pr = -1, pt = -1;
short ukt = 0;
short loop1, loop2;
short w1, w2;
short edge, last_edge1, last_edge2;
D_POINT v1, v2;
BOOL le = FALSE;
while (ukt < ver->uk) {
np_av(ver->v[ukt].m,&p,&pr,&pt,&le);
ukt++;
if (p == 1) {
if (ver->v[ukt-1].v > np->nov) {
v1 = np->v[ver->v[ukt-1].v];
if ( (w1 = np_new_vertex(np, &v1)) == 0) return FALSE;
} else w1 = ver->v[ukt-1].v;
if (ver->v[ukt-1].m == 1)
if ((edge=b_dive(np,ver->v[ukt-1].r,w1)) == 0) return FALSE;
if (ver->v[ukt].v > np->nov) {
v2 = np->v[ver->v[ukt].v];
if ( (w2 = np_new_vertex(np, &v2)) == 0) return FALSE;
} else w2 = ver->v[ukt].v;
if (ver->v[ukt].m == 1)
if ((edge=b_dive(np,ver->v[ukt].r,w2)) == 0) return FALSE;
if ( !(edge = np_new_edge(np,w1,w2)) ) return FALSE;
if ( edge < 0 ) continue;
np->efc[edge].fp = np->efc[edge].fm = face;
loop1 = np_def_loop(np, face, edge, &last_edge1);
loop2 = np_def_loop(np, face, (short)(-edge), &last_edge2);
np_insert_edge(np, edge, last_edge1);
np_insert_edge(np, (short)(-edge), last_edge2);
if (loop1 == 0 || loop2 == 0) continue;
if ( !np_an_loops(np, face, loop1, loop2, edge) ) return FALSE;
}
}
return TRUE;
}
+27
View File
@@ -0,0 +1,27 @@
#include "../sg.h"
BOOL b_fa(lpNPW np)
{
short mf;
short face;
lpNP_LOOPS l = NULL;
short loops = 0;
BOOL rt = TRUE, msg = TRUE;
if ( (l = np_realloc_loops(l,&loops)) == NULL ) return FALSE;
mf = np->nof;
for (face = 1 ; face <= mf ; face++) {
if ( !np_fa_one(np, face, &l, &loops, msg) ) {
rt = FALSE;
goto end;
}
}
if (np->nof > mf) np_fa_ef(np,mf);
mf = b_fa_lab1(np);
if (mf == 0) { rt = FALSE; goto end; }
if (mf != np->nof)
if ( !(b_fa_lab2(np)) ) rt = FALSE;
end:
SGFree(l);
return rt;
}
+126
View File
@@ -0,0 +1,126 @@
#include "../sg.h"
short b_fa_lab1(lpNPW np)
{
NP_BIT_FACE *bf;
BO_BIT_EDGE *be;
short pr,mt,i;
short fedge,edge;
short loop,face;
i=0;
for (face=1 ; face <= np->nof ; face++) {
bf = (NP_BIT_FACE*)&np->f[face].fl;
bf->flg = 0;
pr = 0;
loop = np->f[face].fc;
do {
edge = fedge = np->c[loop].fe;
do {
be = (BO_BIT_EDGE*)&np->efr[(int)abs(edge)].el;
if (be->flg != 0) {
if (edge > 0) mt = be->ep;
else mt = be->em;
if (pr == 0) {
pr = 1;
bf->met = b_face_label(mt);
bf->flg = 1;
i++;
}
else {
mt = b_face_label(mt);
if (mt != bf->met) {
put_message(LAB_ERR,NULL,0);
return (0);
}
}
}
edge = SL(edge,np);
} while (fedge != edge);
loop = np->c[loop].nc;
} while (loop > 0);
}
return (i);
}
BOOL b_fa_lab2(lpNPW np)
{
NP_BIT_FACE *bf,*bt;
short edge,fedge,loop;
short face,sface;
short i,ipr;
ipr = 0;
do {
i = 0;
for (face = 1 ; face <= np->nof ; face++) {
bf = (NP_BIT_FACE*)&np->f[face].fl;
if (bf->flg == 1) {
i++; continue;
}
loop = np->f[face].fc;
do {
edge = fedge = np->c[loop].fe;
do {
sface = SF(edge,np);
if (sface > 0) {
bt = (NP_BIT_FACE*)&np->f[sface].fl;
if (bt->flg == 1) {
bf->met = bt->met;
bf->flg = 1;
i++;
goto alab;
}
}
edge = SL(edge,np);
} while (fedge != edge);
loop = np->c[loop].nc;
} while (loop > 0);
alab:
;
}
if (ipr == i) {
put_message(INTERNAL_ERROR,GetIDS(IDS_SG022),0);
return FALSE;
}
ipr = i;
} while (i != np->nof);
return TRUE;
}
short b_face_label(short met)
{
switch (key) {
case UNION:
switch (met) {
case 0:
return 1;
case 3:
if (object_number == 1)
return 1;
else
return 0;
default:
return 0;
}
case INTER:
switch (met) {
case 1:
return 1;
case 3:
if (object_number == 1)
return 1;
else
return 0;
default:
return 0;
}
case SUB:
if (object_number == 1) {
if (met == 0 || met == 2) return 1;
else return 0;
} else if (met == 1) return 1;
else return 0;
}
return 0;
}
+219
View File
@@ -0,0 +1,219 @@
#include "../sg.h"
static BOOL b_grup(lpNP_STR_LIST list, lpLISTH list_brep, hOBJ hobj);
static BOOL b_put_new(lpNPW np, lpNP_STR_LIST list);
short * mem_ident = NULL;
BOOL b_form_model_list(lpLISTH list_brep, hOBJ hobj)
{
int i; //, j, gru;
NP_STR_LIST list_new;
lpNP_STR str;
if ( (mem_ident = (short*)SGMalloc(sizeof(npwg->ident)*(lista.number_all +
listb.number_all))) == NULL ) return FALSE;
if ( !np_init_list(&list_new) ) goto err;
begin_rw(&lista.vdim,0);
for (i = 0; i < lista.number_all; i++) {
str = (NP_STR*)get_next_elem(&lista.vdim);
if (str->lab != 1) continue;
if ( !read_np(&lista.bnp,str->hnp,npwg) ) {
end_rw(&lista.vdim);
goto err;
}
if ( !b_put_new(npwg,&list_new) ) {
end_rw(&lista.vdim);
goto err;
}
}
end_rw(&lista.vdim);
np_end_of_put(&lista,NP_CANCEL,0,NULL);
if ( brept1 && flg_exist ) {
begin_rw(&listb.vdim,0);
for (i = 0; i < listb.number_all; i++) {
str = (NP_STR*)get_next_elem(&listb.vdim);
if (str->lab != 1) continue;
if ( !read_np(&listb.bnp,str->hnp,npwg) ) {
end_rw(&listb.vdim);
goto err;
}
if ( !b_put_new(npwg,&list_new) ) {
end_rw(&listb.vdim);
goto err;
}
}
end_rw(&listb.vdim);
np_end_of_put(&listb,NP_CANCEL,0,NULL);
}
SGFree(mem_ident);
if ( !list_new.number_all ) {
np_end_of_put(&list_new,NP_CANCEL,0,NULL);
return TRUE;
}
if ( !b_grup(&list_new, list_brep, hobj) ) return FALSE;
return TRUE;
err:
SGFree(mem_ident);
np_end_of_put(&lista,NP_CANCEL,0,NULL);
np_end_of_put(&listb,NP_CANCEL,0,NULL);
np_end_of_put(&list_new,NP_CANCEL,0,NULL);
return FALSE;
}
BOOL b_grup(lpNP_STR_LIST list, lpLISTH list_brep, hOBJ hobj)
{
short i,fi,index;
short ident_np;
int number, number_old, istr;
lpNP_STR str_t1;
NP_STR str_t,str;
int * b = NULL;
hOBJ hbrep = NULL;
lpOBJ brep, obj;
lpGEO_BREP lpgeobrep;
VLD vld;
REGION_3D g = {{1.e35,1.e35,1.e35},{-1.e35,-1.e35,-1.e35}};
LNP lnp;
// init_listh(list_brep);
do {
list->number_np = list->number_all;
begin_rw(&list->vdim,0);
fi = 0;
while (1) {
str_t1 = (lpNP_STR)get_next_elem(&list->vdim);
if ( str_t1->lab == 0 ) break;
fi++;
}
str_t1->lab = 1;
end_rw(&list->vdim);
//nb number_old = number = 0;
ident_np = -32767;
number = 0;
init_vld(&vld);
do {
number_old = number;
number = 0;
for (istr = fi; istr < list->number_all; istr++) {
read_elem(&list->vdim,istr,&str);
if (str.lab == 2) continue;
if (str.lab == 0) continue;
number++;
if (str.ort == 1) continue;
str.ort = 1;
write_elem(&list->vdim,istr,&str);
if (str.len == 0) goto mod;
begin_rw(&list->nb, str.b);
for (i=0 ; i < str.len ; i++) {
b = (int*)get_next_elem(&list->nb);
if ( !(np_get_str(list,(short)(*b),&str_t,&index)) ) goto err;
if (str_t.lab == 1) continue;
str_t.lab = 1; str_t.ort = 0;
write_elem(&list->vdim,index,&str_t);
}
end_rw(&list->nb); b = NULL;
}
} while (number != list->number_np && number != number_old);
mod:
if ( ( hbrep = o_alloc(OBREP)) == NULL) goto err;
brep = (lpOBJ)hbrep;
obj = (lpOBJ)hobj;
brep->color = obj->color;
brep->ltype = obj->ltype;
brep->lthickness = obj->lthickness;
lpgeobrep = (lpGEO_BREP)brep->geo_data;
o_hcunit(lpgeobrep->matr);
number = 0;
list->number_np = 0;
for (istr = 0; istr < list->number_all; istr++) {
read_elem(&list->vdim,istr,&str);
if (str.lab == 2) continue;
if ( str.lab == 0 ) { list->number_np++; continue; }
number++;
if (ident_np <= str.ident) ident_np = str.ident;
if (!(read_np(&list->bnp,str.hnp,npwg))) goto err;
np_gab_init(&npwg->gab);
dpoint_minmax(&npwg->v[1], npwg->nov, &npwg->gab.min, &npwg->gab.max);
np_gab_un(&g, &npwg->gab, &g);
add_np_mem(&vld,npwg,TNPB);
str.lab = 2;
write_elem(&list->vdim,istr,&str);
}
lpgeobrep->min = g.min;
lpgeobrep->max = g.max;
lpgeobrep->ident_np = ident_np + 1;
if ( brept1 ) lpgeobrep->type = BODY;
else lpgeobrep->type = SURF;
memset(&lnp,0,sizeof(lnp));
lnp.kind = COMMON;
lnp.listh = vld.listh;
lnp.num_np = number;
if ( !put_np_brep(&lnp,&lpgeobrep->num)) {
// if ( !put_np_brep(&lpgeobrep->npd,&vld.listh,number,COMMON,NULL)) {
goto err;
}
copy_obj_attrib(hobj, hbrep);
attach_item_tail(list_brep, hbrep);
} while (list->number_np != 0);
number = (short)list_brep->num;
goto cancel;
err:
number = 0;
if (b != NULL) end_rw(&list->nb);
if (hbrep != NULL) o_free(hbrep,NULL);
cancel:
np_str_free(list);
return number;
}
BOOL b_put_new(lpNPW np, lpNP_STR_LIST list)
{
short k, edge;
int * b;
int ident;
NP_STR str;
VNP vnp;
dpoint_minmax(&np->v[1], np->nov, &np->gab.min, &np->gab.max);
memset(&str,0,sizeof(str));
str.ident = np->ident;
str.gab = np->gab;
str.b = list->nb.num_elem;
str.len = 0;
for (edge = 1 ; edge <= np->noe ; edge++) {
if (np->efc[edge].fp >= 0 && np->efc[edge].fm >= 0) continue;
if (np->efc[edge].fp < 0) ident = np->efc[edge].ep;
else ident = np->efc[edge].em;
if ( str.len ) {
begin_rw(&list->nb,str.b);
k = 0;
while (k < str.len) {
b = (int*)get_next_elem(&list->nb);
if ( *b == ident ) break;
k++;
}
end_rw(&list->nb);
if (k < str.len) continue;
}
add_elem(&list->nb, &ident);
str.len++;
}
if ( !(vnp = write_np(&list->bnp,np,TNPW)) ) return FALSE;
str.hnp = vnp;
list->number_all++;
return ( add_elem(&list->vdim,&str) );
}
+200
View File
@@ -0,0 +1,200 @@
#include "../sg.h"
typedef struct {
lpVDIM vdim;
D_POINT p1;
D_POINT p2;
REGION_3D gab;
} LINE_DATA;
typedef LINE_DATA * lpLINE_DATA;
//static void bo_def_axis(lpD_POINT p1, lpD_POINT p2);
static OSCAN_COD line_scan(hOBJ hobj, lpSCAN_CONTROL lpsc);
static BOOL b_line_np(lpNPW np, lpD_POINT pb, lpD_POINT pe, lpVDIM vdim);
BOOL bo_line_object(lpD_POINT pb, lpD_POINT pe, hOBJ hobj,
lpVDIM point)
{
short i;
lpOBJ obj;//nb = NULL;
lpGEO_BREP lpgeobrep;
MATR matr, matr_inv;
REGION_3D gab_obj;
SCAN_CONTROL sc;
OSCAN_COD cod;
LINE_DATA cd;
lpBO_INTER_POINT v;
obj = (lpOBJ)hobj;
if ( obj->type != OBREP ) {
put_message(EMPTY_MSG,GetIDS(IDS_SG029),0);
return FALSE;
}
lpgeobrep = (lpGEO_BREP)obj->geo_data;
gab_obj.min = lpgeobrep->min;
gab_obj.max = lpgeobrep->max;
memcpy(matr, lpgeobrep->matr, sizeof(matr));
if ( !o_minv(lpgeobrep->matr,matr_inv) ) {
return FALSE;
}
if ( !o_hcncrd(matr_inv,pb,&cd.p1) ) return FALSE;
if ( !o_hcncrd(matr_inv,pe,&cd.p2) ) return FALSE;
cd.vdim = point;
if (cd.p1.x < cd.p2.x) cd.gab.min.x = cd.p1.x;
else cd.gab.min.x = cd.p2.x;
if (cd.p1.y < cd.p2.y) cd.gab.min.y = cd.p1.y;
else cd.gab.min.y = cd.p2.y;
if (cd.p1.z < cd.p2.z) cd.gab.min.z = cd.p1.z;
else cd.gab.min.z = cd.p2.z;
if (cd.p1.x > cd.p2.x) cd.gab.max.x = cd.p1.x;
else cd.gab.max.x = cd.p2.x;
if (cd.p1.y > cd.p2.y) cd.gab.max.y = cd.p1.y;
else cd.gab.max.y = cd.p2.y;
if (cd.p1.z > cd.p2.z) cd.gab.max.z = cd.p1.z;
else cd.gab.max.z = cd.p2.z;
define_eps(&gab_obj.min, &gab_obj.max);
if ( np_gab_inter(&gab_obj, &cd.gab) ) return TRUE;
init_scan(&sc);
sc.user_geo_scan = line_scan;
sc.data = &cd;
cod = o_scan(hobj, &sc);
if ( !begin_rw(point, 0) ) return FALSE;
for (i=0; i < point->num_elem; i++) {
v = (lpBO_INTER_POINT)get_next_elem(point);
if ( !o_hcncrd(matr,&(v->p),&(v->p)) ) {
end_rw(point);
return FALSE;
}
if ( !o_hcncrd(matr,&(v->p1),&(v->p1)) ) {
end_rw(point);
return FALSE;
}
if ( !o_hcncrd(matr,&(v->p2),&(v->p2)) ) {
end_rw(point);
return FALSE;
}
}
end_rw(point);
if ( cod != OSTRUE ) return FALSE;
return TRUE;
}
#pragma argsused
static OSCAN_COD line_scan(hOBJ hobj, lpSCAN_CONTROL lpsc)
{
lpLINE_DATA data;
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
return OSFALSE;
}
data = (lpLINE_DATA)(lpsc->data);
npwg->type = TNPW;
dpoint_minmax(&npwg->v[1], npwg->nov, &npwg->gab.min, &npwg->gab.max);
if ( np_gab_inter(&npwg->gab, &data->gab) ) return OSTRUE;
if ( !np_cplane(npwg) ) return OSFALSE;
if ( !b_line_np(npwg, &data->p1, &data->p2, data->vdim) ) return OSFALSE;
return OSTRUE;
}
static BOOL b_line_np(lpNPW np, lpD_POINT pb, lpD_POINT pe, lpVDIM vdim)
{
#define DIST(v) ((v)->x*ka + (v)->y*kb + (v)->z*kc + kd)
short v, edge, f_edge;
short face, loop;
short p1, p2;
sgFloat ka, kb, kc, kd, cs;
sgFloat r, f1, f2;
D_POINT v1, v2;
BO_INTER_POINT ip;
NP_TYPE_POINT type;
for (face = 1; face <= np->nof; face++) {
ka = np->p[face].v.x; kb = np->p[face].v.y;
kc = np->p[face].v.z; kd = np->p[face].d;
f1 = DIST(pb); p1 = sg(f1,eps_d);
f2 = DIST(pe); p2 = sg(f2,eps_d);
if (p1 == 0 && p2 == 0) continue;
if (p1 == 0) {
type = np_point_belog_to_face1(np, pb, face, &edge, &v);
if ( type == NP_OUT ) continue;
ip.p = *pb;
ip.t = 0.;
if ( type == NP_IN ) ip.type = B_IN_ON;
else ip.type = B_ON_ON;
loop = np->f[face].fc;
f_edge = np->c[loop].fe;
ip.p1 = np->v[np->efr[(int)abs(f_edge)].bv];
ip.p2 = np->v[np->efr[(int)abs(f_edge)].ev];
cs = dskalar_product(&ip.p1, &ip.p2);
if ( fabs(cs) -eps_d > 1 ) {
dvector_product(dpoint_sub(&ip.p1,&ip.p, &v1), &np->p[face].v, &v2);
dpoint_add(&ip.p, &v2, &ip.p2);
}
if ( !add_elem(vdim,&ip) ) return FALSE;
continue;
}
if (p2 == 0) {
type = np_point_belog_to_face1(np, pe, face, &edge, &v);
if ( type == NP_OUT ) continue;
ip.p = *pe;
ip.t = dpoint_distance(pb, pe);
if ( type == NP_IN ) ip.type = B_IN_ON;
else ip.type = B_ON_ON;
loop = np->f[face].fc;
f_edge = np->c[loop].fe;
ip.p1 = np->v[np->efr[(int)abs(f_edge)].bv];
ip.p2 = np->v[np->efr[(int)abs(f_edge)].ev];
cs = dskalar_product(&ip.p1, &ip.p2);
if ( fabs(cs) -eps_d > 1 ) {
dvector_product(dpoint_sub(&ip.p1,&ip.p, &v1), &np->p[face].v, &v2);
dpoint_add(&ip.p, &v2, &ip.p2);
}
if ( !add_elem(vdim,&ip) ) return FALSE;
continue;
}
if (p1 == p2) continue;
r = fabs(f1)/(fabs(f2) + fabs(f1));
ip.p.x = pb->x + (pe->x - pb->x)*r;
ip.p.y = pb->y + (pe->y - pb->y)*r;
ip.p.z = pb->z + (pe->z - pb->z)*r;
ip.t = dpoint_distance(pb, &ip.p);
type = np_point_belog_to_face1(np, &ip.p, face, &edge, &v);
if ( type == NP_OUT ) continue;
if ( type == NP_IN ) ip.type = B_IN_IN;
else ip.type = B_ON_IN;
loop = np->f[face].fc;
f_edge = np->c[loop].fe;
ip.p1 = np->v[np->efr[(int)abs(f_edge)].bv];
ip.p2 = np->v[np->efr[(int)abs(f_edge)].ev];
cs = dskalar_product(&ip.p1, &ip.p2);
if ( fabs(cs) -eps_d > 1 ) {
dvector_product(dpoint_sub(&ip.p1,&ip.p, &v1), &np->p[face].v, &v2);
dpoint_add(&ip.p, &v2, &ip.p2);
}
if ( !add_elem(vdim,&ip) ) return FALSE;
}
return TRUE;
}
+252
View File
@@ -0,0 +1,252 @@
#include "../sg.h"
#include <vector>
static BOOL b_up(void);
static int is_faces_equals(lpNPW np1, short face1, lpNPW np2, short face2,
short& edge_on_1, short& edge_on_2);
static bool is_faces_on_one_plane(lpNPW np1, short face1, lpNPW np2, short face2);
short facea,faceb;
NP_VERTEX_LIST vera = {0,0,NULL,NULL};
NP_VERTEX_LIST verb = {0,0,NULL,NULL};
BOOL b_lnp(lpNP_STR str1,lpNP_STR str2)
{
short i;
NP_BIT_FACE *b;
BO_BIT_EDGE *be;
lpDA_POINT w1, w2;
BOOL rt=FALSE;//nb = TRUE;
if ( !(rt = np_ver_alloc(&vera)) ) goto end;
if ( !(rt = np_ver_alloc(&verb)) ) goto end;
i=0;
for (faceb = 1 ; faceb <= npb->nof ; faceb++) {
b = (NP_BIT_FACE*)&npb->f[faceb].fl;
if (np_gab_pl(&npa->gab,&npb->p[faceb],eps_d)) {
b->flg = 1;
i++;
} else
b->flg = 0;
}
if (i == npb->nof) goto end;
for (facea = 1 ; facea <= npa->nof ; facea++) {
if (np_gab_pl(&npb->gab,&npa->p[facea],eps_d))
continue;
for (faceb = 1 ; faceb <= npb->nof ; faceb++) {
b = (NP_BIT_FACE*)&npb->f[faceb].fl;
if (b->flg == 1) continue;
if (is_faces_on_one_plane(npa,facea,npb,faceb))
{
continue;
}
vera.uk = 0; verb.uk = 0;
npa->nov_tmp = npa->maxnov;
npb->nov_tmp = npb->maxnov;
if ( !(rt=np_pl(npa,facea,&vera,&npb->p[faceb])) ) goto end;
if (vera.uk == 0) continue; /* */
if ( !(rt=np_pl(npb,faceb,&verb,&npa->p[facea])) ) goto end;
if (verb.uk == 0) continue; /* */
np_axis = np_defc(&npa->p[facea].v,&npb->p[faceb].v);
np_sort_ver(npa->v,&vera,np_axis);
// qsort((void*)vera.v,vera.uk,sizeof(VERTEX),(fptr)sort_function);
np_sort_ver(npb->v,&verb,np_axis);
// qsort((void*)verb.v,verb.uk,sizeof(VERTEX),(fptr)sort_function);
w1 = (lpDA_POINT)npa->v;
w2 = (lpDA_POINT)npb->v;
if (w1[vera.v[0].v][np_axis] > w2[verb.v[verb.uk-1].v][np_axis] ||
w2[verb.v[0].v][np_axis] > w1[vera.v[vera.uk-1].v][np_axis] ) continue;
if ( !(rt=b_up()) )
{
rt=FALSE;
goto end;
}
}
}
if (str1->lab != 2) {
for (i = 1 ; i <= npa->noe ; i++) {
be = (BO_BIT_EDGE*)&npa->efr[i].el;
if (be->flg == 0) continue;
str1->lab = 2;
break;
}
}
if (str2->lab != 2) {
for (i = 1 ; i <= npb->noe ; i++) {
be = (BO_BIT_EDGE*)&npb->efr[i].el;
if (be->flg == 0) continue;
str2->lab = 2;
break;
}
}
end:
np_free_ver(&vera);
np_free_ver(&verb);
return rt;
}
BOOL b_up(void)
{
short pa = -1, pb = -1;
short pra = -1,prb = -1;
short pta = -1,ptb = -1;
short uka = 0, ukb = 0;
short maxnova, maxnovb, nova, novb, i;
lpDA_POINT w1, w2;
BOOL lea=FALSE,leb=FALSE;
maxnova = npa->maxnov; nova = npa->nov;
maxnovb = npb->maxnov; novb = npb->nov;
// w1 = (lpDA_POINT)npa->v;
// w2 = (lpDA_POINT)npb->v;
do {
w1 = (lpDA_POINT)npa->v;
w2 = (lpDA_POINT)npb->v;
if (maxnova < npa->maxnov) {
w1 = (lpDA_POINT)npa->v;
for (i = uka ; i < vera.uk ; i++) {
if ( vera.v[i].v > nova ) vera.v[i].v += MAXNOV/4;
}
maxnova = npa->maxnov; nova = npa->nov;
}
if (maxnovb < npb->maxnov) {
w2 = (lpDA_POINT)npb->v;
for (i = ukb ; i < verb.uk ; i++) {
if ( verb.v[i].v > novb ) verb.v[i].v += MAXNOV/4;
}
maxnovb = npb->maxnov; novb = npb->nov;
}
if (w1[vera.v[uka].v][np_axis] < w2[verb.v[ukb].v][np_axis]) {
np_av(vera.v[uka].m,&pa,&pra,&pta,&lea);
uka++;
} else {
np_av(verb.v[ukb].m,&pb,&prb,&ptb,&leb);
ukb++;
}
if ((pa + pb) == 2 &&
fabs(w1[vera.v[uka].v][np_axis] - w2[verb.v[ukb-1].v][np_axis]) > eps_d &&
fabs(w1[vera.v[uka-1].v][np_axis] - w2[verb.v[ukb].v][np_axis]) > eps_d)
if ( !(b_vr(uka,ukb,lea,leb)) )
return FALSE;
} while (uka < vera.uk && ukb < verb.uk);
return TRUE;
}
static int is_faces_equals(lpNPW np1, short face1, lpNPW np2, short face2,
short& edge_on_1, short& edge_on_2)
{
D_POINT* face1_vert, *face1_vert_2;
D_POINT* face2_vert/*, *face2_vert_2*/;
int check_res = 0;
short loop_1 = np1->f[face1].fc;
short fedge_1 = np1->c[loop_1].fe;
short v_1 = BE(fedge_1,np1);
short edge_1 = fedge_1;
D_POINT* eq_pnts[2];
face1_vert = &(np1->v[v_1]);
do {
short loop_2 = np2->f[face2].fc;
short fedge_2 = np2->c[loop_2].fe;
short v_2 = BE(fedge_2,np2);
short edge_2 = fedge_2;
face2_vert = &(np2->v[v_2]);
do {
if (dpoint_eq(face1_vert,face2_vert,eps_d))
{
check_res++;
if (check_res==1)
{
eq_pnts[0] = face1_vert;
}
else
{
if (check_res==2)
{
eq_pnts[1] = face1_vert;
}
}
break;
}
if (check_res>2)
return 3;
edge_2 = SL(edge_2,np2);
v_2 = BE(edge_2,np2);
face2_vert = &(np2->v[v_2]);
} while (edge_2 != fedge_2);
edge_1 = SL(edge_1,np1);
v_1 = BE(edge_1,np1);
face1_vert = &(np1->v[v_1]);
} while (edge_1 != fedge_1);
if (check_res==2)
{
loop_1 = np1->f[face1].fc;
fedge_1 = np1->c[loop_1].fe;
edge_1 = fedge_1;
do {
face1_vert = &(np1->v[BE(edge_1,np1)]);
face1_vert_2 = &(np1->v[EE(edge_1,np1)]);
if ((dpoint_eq(face1_vert,eq_pnts[0],eps_d) && dpoint_eq(face1_vert_2,eq_pnts[1],eps_d))||
(dpoint_eq(face1_vert,eq_pnts[1],eps_d) && dpoint_eq(face1_vert_2,eq_pnts[0],eps_d)))
{
edge_on_1 = edge_1;
break;
}
edge_1 = SL(edge_1,np1);
} while (edge_1 != fedge_1);
loop_1 = np2->f[face2].fc;
fedge_1 = np2->c[loop_1].fe;
edge_1 = fedge_1;
do {
face1_vert = &(np2->v[BE(edge_1,np2)]);
face1_vert_2 = &(np2->v[EE(edge_1,np2)]);
if ((dpoint_eq(face1_vert,eq_pnts[0],eps_d) && dpoint_eq(face1_vert_2,eq_pnts[1],eps_d))||
(dpoint_eq(face1_vert,eq_pnts[1],eps_d) && dpoint_eq(face1_vert_2,eq_pnts[0],eps_d)))
{
edge_on_2 = edge_1;
break;
}
edge_1 = SL(edge_1,np2);
} while (edge_1 != fedge_1);
}
return (check_res);
}
static bool is_faces_on_one_plane(lpNPW np1, short face1, lpNPW np2, short face2)
{
return ((fabs(npa->p[facea].v.x - npb->p[faceb].v.x) <= eps_n &&
fabs(npa->p[facea].v.y - npb->p[faceb].v.y) <= eps_n &&
fabs(npa->p[facea].v.z - npb->p[faceb].v.z) <= eps_n) ||
(fabs(npa->p[facea].v.x + npb->p[faceb].v.x) <= eps_n &&
fabs(npa->p[facea].v.y + npb->p[faceb].v.y) <= eps_n &&
fabs(npa->p[facea].v.z + npb->p[faceb].v.z) <= eps_n)/* ||
fabs(dskalar_product(&npa->p[facea].v,&npb->p[faceb].v))>1.0-0.0001*/);
}
+38
View File
@@ -0,0 +1,38 @@
#include "../sg.h"
BOOL b_np_lab(lpNP_STR_LIST list_str, lpNP_STR str, lpNPW np)
{
short index;
short i, k, max=0, ident;
NP_STR str_n;
BOOL rt = TRUE;
short * mem_ident;
if ( (mem_ident = (short*)SGMalloc(sizeof(np->ident)*(np->noe))) == NULL ) return FALSE;
for (i=1 ; i <= np->noe ; i++) {
if (np->efc[i].fp >= 0 && np->efc[i].fm >= 0) continue;
if (np->efc[i].fp < 0) ident = np->efc[i].ep;
else ident = np->efc[i].em;
k = 0;
while (k < max) {
if (mem_ident[k] == ident) break;
k++;
}
if (k < max) continue;
mem_ident[max] = ident;
max++;
if ( !(np_get_str(list_str,ident,&str_n,&index)) ) { rt = FALSE; goto end; }
if (abs(str_n.lab) == 1) {
str->lab = str_n.lab;
if (str->lab == 1 && object_number == 2 && key == SUB)
np_inv(np,NP_ALL);
goto end;
}
}
end:
SGFree(mem_ident);
return rt;
}
+672
View File
@@ -0,0 +1,672 @@
#include "../sg.h"
typedef struct {
hOBJ hobj;
lpVDIM p;
CODE_OPERATION key;
lpLISTH listh;
} POINT_DATA;
typedef POINT_DATA * lpPOINT_DATA;
static OSCAN_COD b_sub_spline(lpGEO_SPLINE spline, lpSCAN_CONTROL lpsc);
static int sort_founction1(const void *a, const void *b);
static OSCAN_COD b_sub_line(lpGEO_LINE geo_line, lpSCAN_CONTROL lpsc);
static OSCAN_COD b_sub_arc(lpGEO_ARC arc, lpREGION_3D gab_arc, lpSCAN_CONTROL lpsc);
static OSCAN_COD point_scan(hOBJ hobj, lpSCAN_CONTROL lpsc);
static int sort_function( const void *a, const void *b);
static void b_get_point_on_arc(lpGEO_ARC arc, sgFloat alfa, lpD_POINT p);
static void o_modify_limits_by_point(lpD_POINT p, lpREGION_3D reg);
static BOOL get_ends_point(hOBJ hobj, lpD_POINT p1, lpD_POINT p2);
BOOL bo_points(hOBJ hobj_l, hOBJ hobj_b, lpVDIM points, CODE_OPERATION code_operation,
lpLISTH listh)
{
REGION_3D gabb, gabl, gab;
hOBJ hobj1 = NULL;
SCAN_CONTROL sc;
POINT_DATA cd;
OSCAN_COD cod;
NP_TYPE_POINT answer;
D_POINT p1, p2;
lpOBJ obj;
if ( !(code_operation == SUB || code_operation == INTER ||
code_operation == INTER_POINT) ) return FALSE;
if (!get_object_limits(hobj_b, &gabb.min, &gabb.max)) return FALSE;
if (!get_object_limits(hobj_l, &gabl.min, &gabl.max)) return FALSE;
if ( np_gab_inter(&gabl, &gabb) ) {
if ( code_operation == INTER_POINT ) return TRUE;
if ( !get_ends_point(hobj_l, &p1, &p2) ) return FALSE;
if ( !check_point_object(&p1, hobj_b, &answer) ) return FALSE;
if ( answer == NP_OUT && code_operation == SUB ||
(answer == NP_IN || answer == NP_ON) && code_operation == INTER ) {
if ( !o_copy_obj(hobj_l, &hobj1,"") ) return FALSE;
obj = (lpOBJ)hobj1;
obj->status &= (~(ST_SELECT|ST_BLINK|ST_DIRECT));
attach_item_tail(listh, hobj1);
}
return TRUE;
}
np_gab_un(&gabb, &gabl, &gab);
define_eps(&gab.min, &gab.max);
init_scan(&sc);
cd.p = points;
cd.listh = listh;
cd.hobj = hobj_b;
cd.key = code_operation;
sc.data = &cd;
sc.user_geo_scan = point_scan;
cod = o_scan(hobj_l, &sc);
return cod;
}
#pragma argsused
static OSCAN_COD point_scan(hOBJ hobj, lpSCAN_CONTROL lpsc)
{
short count, color;
SCAN_CONTROL tmp;
lpOBJ obj, obj1;
hOBJ hobj_new, hnext, hobj1, h_first, h_last;
GEO_SPLINE geo_spline;
GEO_ARC geo_arc;
lpGEO_ARC lpgeo_arc, lpgeo_arc1;
GEO_LINE geo_line;
GEO_OBJ geo;
VLD vld;
REGION_3D gab;
OSCAN_COD ret;
LISTH listh;
lpPOINT_DATA data;
D_POINT min, max, p;
D_POINT p11, p12, p21, p22;
ARC_DATA ad;
short num, i;
if ( ctrl_c_press ) return OSBREAK;
init_listh(&listh);
data = (lpPOINT_DATA)(lpsc->data);
switch (lpsc->type) {
case OPOINT:
break;
case OARC:
obj = (lpOBJ)lpsc->hobj;
geo_arc = *(lpGEO_ARC)obj->geo_data;
if (!get_object_limits(lpsc->hobj, &gab.min, &gab.max)) return OSFALSE;
ret = b_sub_arc(&geo_arc, &gab, lpsc);
break;
case OCIRCLE:
obj = (lpOBJ)lpsc->hobj;
memcpy(&geo_arc, obj->geo_data, sizeof(GEO_CIRCLE));
get_c_matr((lpGEO_CIRCLE)obj->geo_data, el_g_e, el_e_g);
if (!get_object_limits(lpsc->hobj, &gab.min, &gab.max)) return OSFALSE;
p.x = geo_arc.r;
p.y = p.z = 0.;
o_hcncrd(el_e_g, &p, &p);
geo_arc.angle = 2.*M_PI;
geo_arc.vb = p;
geo_arc.ve = p;
calc_arc_ab(&geo_arc);
ret = b_sub_arc(&geo_arc, &gab, lpsc);
if ( !data->listh ) break;
if ( data->listh->num > 1 ) {
h_first = data->listh->hhead;
h_last = data->listh->htail;
if ( !get_ends_point(h_first, &p11, &p12) ) {
ret = OSFALSE;
break;
}
if ( !get_ends_point(h_last, &p21, &p22) ) {
ret = OSFALSE;
break;
}
if ( dpoint_eq(&p11, &p22, eps_d) ) {
detach_item(data->listh, h_first);
obj = (lpOBJ)h_first;
obj1 = (lpOBJ)h_last;
lpgeo_arc = (lpGEO_ARC)(obj->geo_data);
lpgeo_arc1 = (lpGEO_ARC)(obj1->geo_data);
lpgeo_arc1->ve = lpgeo_arc->ve;
lpgeo_arc1->angle += lpgeo_arc->angle;
calc_arc_ab(lpgeo_arc1);
o_free(h_first, NULL);
}
}
break;
case OLINE:
obj = (lpOBJ)lpsc->hobj;
geo_line = *(lpGEO_LINE)obj->geo_data;
ret = b_sub_line(&geo_line, lpsc);
break;
case OSPLINE:
obj = (lpOBJ)lpsc->hobj;
geo_spline = *(lpGEO_SPLINE)obj->geo_data;
ret=b_sub_spline(&geo_spline, lpsc);
break;
case OFRAME:
init_vld(&vld);
count = 0;
tmp = *lpsc;
obj = (lpOBJ)lpsc->hobj;
frame_read_begin((lpGEO_FRAME)obj->geo_data);
while ( frame_read_next(&(tmp.type), (short *)&(tmp.color), &(tmp.ltype),
&(tmp.lthickness), &geo)) {
switch (tmp.type) {
case OCIRCLE:
np_gab_init(&gab);
memcpy(&geo_arc, &geo.circle, sizeof(GEO_CIRCLE));
if ( lpsc->m ) o_trans_arc((lpGEO_ARC)&geo_arc, lpsc->m, OECS_CIRCLE);
get_c_matr((lpGEO_CIRCLE)&geo_arc, el_g_e, el_e_g);
p.x = geo_arc.r;
p.y = p.z = 0.;
o_hcncrd(el_e_g, &p, &p);
geo_arc.angle = 2.*M_PI;
geo_arc.vb = p;
geo_arc.ve = p;
calc_arc_ab(&geo_arc);
num = o_init_ecs_arc(&ad,&geo_arc, OECS_ARC, vi_h_tolerance);
for (i = 0; i <= num; i++) {
o_get_point_on_arc(&ad,(sgFloat)i / num, &p);
o_modify_limits_by_point(&p, &gab);
}
ret = b_sub_arc(&geo_arc, &gab, lpsc);
break;
case OARC:
np_gab_init(&gab);
if ( lpsc->m ) o_trans_arc(&geo.arc, lpsc->m, OECS_ARC);
if ( lpsc->status & ST_ORIENT ) geo.arc.angle = -geo.arc.angle;
num = o_init_ecs_arc(&ad,&geo.arc, OECS_ARC, vi_h_tolerance);
for (i = 0; i <= num; i++) {
o_get_point_on_arc(&ad,(sgFloat)i / num, &p);
o_modify_limits_by_point(&p, &gab);
}
ret = b_sub_arc(&geo.arc, &gab, &tmp);
break;
case OLINE:
if ( lpsc->m ) {
o_hcncrd(lpsc->m,&geo_line.v1,&geo_line.v1);
o_hcncrd(lpsc->m,&geo_line.v2,&geo_line.v2);
}
ret = b_sub_line(&geo.line, &tmp);
break;
default:
continue;
}
hobj_new = data->listh->hhead;
while (hobj_new) {
get_next_item(hobj_new, &hnext);
detach_item(data->listh, hobj_new);
obj = (lpOBJ)hobj_new;
if (count == 32000) {
if ((hobj1 = o_alloc(OFRAME)) == NULL) {
return OSFALSE;
}
obj1 = (lpOBJ)hobj1;
obj1->color = lpsc->color;
obj1->ltype = lpsc->ltype;
obj1->lthickness = lpsc->lthickness;
((lpGEO_FRAME)obj1->geo_data)->num = count;
((lpGEO_FRAME)obj1->geo_data)->vld = vld;
o_hcunit(((lpGEO_FRAME)obj1->geo_data)->matr);
if (!get_object_limits(hobj1, &min, &max) ) {
o_free(hobj1,NULL);
return OSFALSE;
}
obj1 = (lpOBJ)hobj1;
((lpGEO_FRAME)obj1->geo_data)->min = min;
((lpGEO_FRAME)obj1->geo_data)->max = max;
copy_obj_attrib(lpsc->hobj, hobj1);
attach_item_tail(&listh, hobj1);
init_vld(&vld);
count = 0;
}
if ( !add_vld_data(&vld, sizeof(obj->type),&obj->type)) goto err;
color = obj->color;
if ( !add_vld_data(&vld, sizeof(color),&color)) goto err;
if ( !add_vld_data(&vld, sizeof(obj->ltype),&obj->ltype)) goto err;
if ( !add_vld_data(&vld, sizeof(obj->lthickness),&obj->lthickness)) goto err;
if ( !add_vld_data(&vld, geo_size[obj->type],obj->geo_data)) goto err;
count++;
o_free(hobj_new, NULL);
hobj_new = hnext;
}
}
if ((hobj1 = o_alloc(OFRAME)) == NULL) return OSFALSE;
obj1 = (lpOBJ)hobj1;
obj1->color = lpsc->color;
obj1->ltype = lpsc->ltype;
obj1->lthickness = lpsc->lthickness;
((lpGEO_FRAME)obj1->geo_data)->num = count;
((lpGEO_FRAME)obj1->geo_data)->vld = vld;
o_hcunit(((lpGEO_FRAME)obj1->geo_data)->matr);
if (!get_object_limits(hobj1, &min, &max) ) {
o_free(hobj1,NULL);
return OSFALSE;
}
obj1 = (lpOBJ)hobj1;
((lpGEO_FRAME)obj1->geo_data)->min = min;
((lpGEO_FRAME)obj1->geo_data)->max = max;
copy_obj_attrib(lpsc->hobj, hobj1);
attach_item_tail(&listh, hobj1);
*data->listh = listh;
break;
default: // OTEXT .
ret = OSTRUE;
}
return ret;
err:
return OSFALSE;
}
static int sort_function( const void *a, const void *b)
{
if ( ((lpBO_INTER_POINT)a)->t > ((lpBO_INTER_POINT)b)->t) return 1;
return -1;
}
static void b_get_point_on_arc(lpGEO_ARC arc, sgFloat alfa, lpD_POINT p)
{
ARC_DATA ad;
o_init_ecs_arc(&ad, arc, OECS_ARC, vi_h_tolerance);
o_get_point_on_arc(&ad, alfa, p);
}
OSCAN_COD b_sub_line(lpGEO_LINE line, lpSCAN_CONTROL lpsc)
{
short j, jj;
VDIM points;
D_POINT v1, v2, p1, p2, p3;
lpPOINT_DATA data;
lpBO_INTER_POINT v, vv;
lpGEO_LINE geo_line;
BO_INTER_POINT ip;
OSCAN_COD rt = OSTRUE;
NP_TYPE_POINT answer;
lpOBJ obj;
hOBJ hline;
data = (lpPOINT_DATA)(lpsc->data);
if (!init_vdim(&points,sizeof(BO_INTER_POINT))) return OSFALSE;
v1 = line->v1;
v2 = line->v2;
if ( !bo_line_object(&v1, &v2, data->hobj, &points) ) {
rt = OSFALSE;
goto end;
}
if ( !data->listh ) {
if ( points.num_elem == 0 ) goto end;
if ( !begin_rw(&points, 0) ) { rt = OSFALSE; goto end; }
for (j=0; j < points.num_elem; j++) {
v = (lpBO_INTER_POINT)get_next_elem(&points);
if ( !begin_rw(data->p,0) ) {
rt = OSFALSE;
end_rw(&points);
goto end;
}
for (jj=0; jj < (data->p)->num_elem; jj++) {
vv = (lpBO_INTER_POINT)get_next_elem(data->p);
if ( dpoint_eq(&v->p, &vv->p, eps_d) ) break;
}
end_rw(data->p);
if (jj < (data->p)->num_elem) continue;
if ( !add_elem(data->p,v) ) {
rt = OSFALSE;
end_rw(&points);
goto end;
}
}
end_rw(&points);
goto end;
}
if ( !sort_vdim(&points, sort_function) ) { rt = OSFALSE; goto end; }
ip.p = v2;
ip.type = B_IN_ON;
if ( !add_elem(&points, &ip) ) { rt = OSFALSE; goto end; }
if ( !begin_rw(&points, 0) ) { rt = OSFALSE; goto end; }
p1 = v1;
for (j=0; j < points.num_elem; j++) {
v = (lpBO_INTER_POINT)get_next_elem(&points);
p2 = v->p;
if ( fabs(dpoint_distance(&p1, &p2)) < eps_d) {
p1 = p2;
continue;
}
dpoint_parametr(&p1, &p2, .5, &p3);
if ( !check_point_object(&p3, data->hobj, &answer) ) {
end_rw(&points);
rt = OSFALSE;
goto end;
}
if ( answer == NP_OUT && data->key == SUB ||
(answer == NP_IN || answer == NP_ON) && data->key == INTER ) {
if((hline = o_alloc(OLINE)) == NULL) {
end_rw(&points);
rt = OSFALSE;
goto end;
}
obj = (lpOBJ)hline;
obj->color = lpsc->color;
obj->ltype = lpsc->ltype;
obj->lthickness = lpsc->lthickness;
geo_line = (lpGEO_LINE)(obj->geo_data);
geo_line->v1 = p1;
geo_line->v2 = p2;
copy_obj_attrib(lpsc->hobj, hline);
attach_item_tail(data->listh, hline);
}
p1 = p2;
}
end_rw(&points);
end:
free_vdim(&points);
return rt;
}
OSCAN_COD b_sub_arc(lpGEO_ARC arc, lpREGION_3D gab_arc, lpSCAN_CONTROL lpsc)
{
short j, jj;
sgFloat t1, t2;
VDIM points;
D_POINT p1, p2, p3;
lpPOINT_DATA data;
lpBO_INTER_POINT v, vv;
lpGEO_ARC geo_arc;
BO_INTER_POINT ip;
OSCAN_COD rt = OSTRUE;
NP_TYPE_POINT answer;
lpOBJ obj;
hOBJ harc;//nb = NULL;
data = (lpPOINT_DATA)(lpsc->data);
if (!init_vdim(&points,sizeof(BO_INTER_POINT))) { rt=OSFALSE; goto end;}
if ( !bo_arc_object(arc, gab_arc, data->hobj, &points) ) return OSFALSE;
if ( !data->listh ) {
if ( points.num_elem == 0 ) goto end;
if ( !begin_rw(&points, 0) ) { rt = OSFALSE; goto end; }
for (j=0; j < points.num_elem; j++) {
v = (lpBO_INTER_POINT)get_next_elem(&points);
if ( !begin_rw(data->p,0) ) {
rt = OSFALSE;
end_rw(&points);
goto end;
}
for (jj=0; jj < (data->p)->num_elem; jj++) {
vv = (lpBO_INTER_POINT)get_next_elem(data->p);
if ( dpoint_eq(&v->p, &vv->p, eps_d) ) break;
}
end_rw(data->p);
if (jj < (data->p)->num_elem) continue;
if ( !add_elem(data->p,v) ) {
rt = OSFALSE;
end_rw(&points);
goto end;
}
}
end_rw(&points);
goto end;
}
if ( !sort_vdim(&points, sort_function) ) { rt = OSFALSE; goto end; }
ip.p = arc->ve;
ip.type = B_IN_ON;
ip.t = fabs(arc->angle);
if ( !add_elem(&points, &ip) ) { rt = OSFALSE; goto end; }
if ( !begin_rw(&points, 0) ) { rt = OSFALSE; goto end; }
p1 = arc->vb; t1 = 0;
for (j=0; j < points.num_elem; j++) {
v = (lpBO_INTER_POINT)get_next_elem(&points);
p2 = v->p; t2 = v->t;
b_get_point_on_arc(arc, (t2-(t2-t1)/2)/fabs(arc->angle), &p3);
if ( !check_point_object(&p3, data->hobj, &answer) ) {
end_rw(&points);
rt = OSFALSE;
goto end;
}
if ( answer == NP_OUT && data->key == SUB ||
(answer == NP_IN || answer == NP_ON) && data->key == INTER ) {
if((harc = o_alloc(OARC)) == NULL) {
end_rw(&points);
rt = OSFALSE;
goto end;
}
obj = (lpOBJ)harc;
obj->color = lpsc->color;
obj->ltype = lpsc->ltype;
obj->lthickness = lpsc->lthickness;
geo_arc = (lpGEO_ARC)(obj->geo_data);
*geo_arc = *arc;
geo_arc->vb = p1;
geo_arc->ve = p2;
geo_arc->angle = (t2 - t1)*sg(arc->angle,eps_d);
calc_arc_ab(geo_arc);
copy_obj_attrib(lpsc->hobj, harc);
attach_item_tail(data->listh, harc);
}
p1 = p2; t1 = t2;
}
end_rw(&points);
end:
free_vdim(&points);
return rt;
}
static void o_modify_limits_by_point(lpD_POINT p, lpREGION_3D reg)
{
if (p->x < reg->min.x) reg->min.x = p->x;
if (p->y < reg->min.y) reg->min.y = p->y;
if (p->z < reg->min.z) reg->min.z = p->z;
if (p->x > reg->max.x) reg->max.x = p->x;
if (p->y > reg->max.y) reg->max.y = p->y;
if (p->z > reg->max.z) reg->max.z = p->z;
}
static BOOL get_ends_point(hOBJ hobj, lpD_POINT p1, lpD_POINT p2)
{
lpOBJ obj;
D_POINT tmp;
sgFloat ln;
obj = (lpOBJ)hobj;
switch (obj->type) {
case OLINE:
*p1 = ((lpGEO_LINE)(obj->geo_data))->v1;
*p2 = ((lpGEO_LINE)(obj->geo_data))->v2;
break;
case OARC:
*p1 = ((lpGEO_ARC)(obj->geo_data))->vb;
*p2 = ((lpGEO_ARC)(obj->geo_data))->ve;
break;
case OPATH:
if ( !init_get_point_on_path(hobj, &ln) ) return FALSE;
if ( !get_point_on_path(0, p1) ) {
term_get_point_on_path();
return FALSE;
}
if ( !get_point_on_path(ln, p2) ) {
term_get_point_on_path();
return FALSE;
}
term_get_point_on_path();
return TRUE;
default:
return FALSE;
}
if (obj->status & ST_DIRECT) {
tmp = *p1;
*p1 = *p2;
*p2 = tmp;
}
return TRUE;
}
static OSCAN_COD b_sub_spline(lpGEO_SPLINE spline, lpSCAN_CONTROL lpsc){
short i, j, j1, k, l, num_elem, ipp, span, span_base=60;
short tes1, tes2, span_base1=10;
sgFloat t, t1, t_beg, dist, bound[2], tmp_bound, t_sply;
sgFloat *t_intersec/*=NULL*/;
SPLY_DAT sply_dat;
lpPOINT_DATA data;
VDIM points, points1;
D_POINT p, v1, v2, vv2, plane[3];
BO_INTER_POINT vv1;
OSCAN_COD rt = OSFALSE;
lpGEO_SPLINE geo_spline;
NP_TYPE_POINT answer;
lpOBJ obj;
hOBJ hspline = NULL;
data = (lpPOINT_DATA)(lpsc->data);
if((t_intersec=(sgFloat*)SGMalloc(100*sizeof(sgFloat))) == NULL ) return rt;
l=0;
//found beginning point for intersection
tes1=0;
if( !begin_use_sply( spline, &sply_dat) ) goto end1;
for(i=0; i<sply_dat.numk-1; i++ ){
t = sply_dat.u[i+1] - sply_dat.u[i];
span = span_base + (short)(t*100);
t = t/span;
memcpy(&v1, &sply_dat.knots[i], sizeof(DA_POINT));
bound[0]=sply_dat.u[i];
for( j=1; j<=span; j++ ){
if( !tes1 ) {
if( !init_vdim(&points,sizeof(BO_INTER_POINT))) goto end2;
tes1=1;
}
t_beg = sply_dat.u[i]+t*j;
bound[1] = tmp_bound = t_beg;
if( j==span ) memcpy(&v2, &sply_dat.knots[i+1], sizeof(DA_POINT));
else get_point_on_sply(&sply_dat, t_beg, &v2, 0);
if( (rt = (OSCAN_COD)bo_line_object(&v1, &v2, data->hobj, &points) ) != OSTRUE )
goto end3;
tes2=0;
if ( points.num_elem != 0 ){ // there are points of intersection
tes1=0;
t_beg = bound[0];
t1 = t/span_base1;
for( j1=1; j1<=span_base1; j1++ ){
if( !tes2 ){
if (!init_vdim(&points1,sizeof(BO_INTER_POINT))) goto end3;
tes2=1;
}
t_beg += t1;
bound[1]=t_beg;
if( j1==span_base1 ) memcpy(&vv2, &v2, sizeof(DA_POINT));
else get_point_on_sply(&sply_dat, t_beg, &vv2, 0);
if( (rt = (OSCAN_COD)bo_line_object(&v1, &v2, data->hobj, &points1) ) != OSTRUE )
goto end4;
if ( points1.num_elem != 0 ){ // there are points of intersection
tes2=0;
num_elem=0;
while( read_elem( &points, num_elem++, &vv1 )){
t_sply=bound[0];
p=vv1.p;
if(!Spline_By_Point( &sply_dat, (void *)&p, &t_sply, &dist )) return OSFALSE;
//call function for calculate real point of intersection
//create plane to intersect
plane[0]=vv1.p;
plane[1]=vv1.p1;
plane[2]=vv1.p2;
if( !Spline_By_Plane( &sply_dat, (void *)plane, &t_sply, bound, &dist ) ) goto end4;
// if( dist >= eps_d || t_beg < 0. ) continue; // tested point is out of the spline
if( t_sply < 0. ) continue; //tested point out of span
for( ipp=0, k=0; k<l; k++ )
if( fabs( t_intersec[k] - t_beg ) < eps_n ){// this point already exists
ipp=1; break;}
if( !ipp ){
t_intersec[l++] = t_beg;
if( !data->listh ){ // found only points of intersection
get_point_on_sply(&sply_dat, t_beg, &vv1.p, 0);
if( !add_elem( data->p, &vv1 ) ) goto end4;
}
}
}
}
v1=vv2;
bound[0]=bound[1];
if( !tes2 ) free_vdim(&points1);
}
}
v1=v2;
bound[0]=tmp_bound;
if( !tes1 ) free_vdim(&points);
}
}
if( !data->listh ){ // found only points of intersection
rt = OSTRUE;
goto end2;
}
// sorting points of intersection by parameter
qsort( (void *)t_intersec, l, sizeof(sgFloat), sort_founction1 );
if( fabs( t_intersec[0] ) > eps_n ){
for( i=l-1; i>=0; i-- ) t_intersec[i+1]= t_intersec[i];
t_intersec[0]=0.;
l++;
}
if( fabs( t_intersec[l-1]-1. ) > eps_n ) t_intersec[l++]=1.;
//detect spline part lieing in/out of the body
for( i=0; i<l-1; i++ ){
get_point_on_sply(&sply_dat,
t_intersec[i]+(t_intersec[i+1]-t_intersec[i])/2., &v1, 0);
if ( !check_point_object(&v1, data->hobj, &answer) ) goto end2;
if ( answer == NP_OUT && data->key == SUB ||
(answer == NP_IN || answer == NP_ON) && data->key == INTER
){ // create new sply
if((hspline = o_alloc(OSPLINE)) == NULL) goto end2;
obj = (lpOBJ)hspline;
obj->color = lpsc->color; // Color
obj->ltype = lpsc->ltype; // Line Type
obj->lthickness = lpsc->lthickness; // Thickness
geo_spline = (lpGEO_SPLINE)(obj->geo_data);
if( !(Get_Part_Spline_Geo( &sply_dat,
t_intersec[i], t_intersec[i+1], geo_spline ))) goto end2;
copy_obj_attrib(lpsc->hobj, hspline);
attach_item_tail(data->listh, hspline);
}
}
rt=OSTRUE;
end4:
free_vdim(&points1);
end3:
free_vdim(&points);
end2:
end_use_sply( spline, &sply_dat);
end1:
if( t_intersec ) SGFree( t_intersec );
return rt;
}
static int sort_founction1(const void *a, const void *b){
if( ( *(sgFloat*)a - *(sgFloat*)b ) > eps_n ) return 1;
if( ( *(sgFloat*)a - *(sgFloat*)b ) < -eps_n ) return -1;
return 0;
}
+64
View File
@@ -0,0 +1,64 @@
#include "../sg.h"
short b_pv(lpNPW np1, short r, lpD_PLANE pl)
{
short v1,v2;
short gr,p;
D_POINT x2,x3;
sgFloat dl,f;
v1 = BE(r,np1); v2 = EE(r,np1);
if (r > 0) gr = np1->efc[ r].fp;
else gr = np1->efc[-r].fm;
if (gr < 0) gr = 0;
dpoint_sub(&(np1->v[v2]), &(np1->v[v1]), &x2);
dnormal_vector (&x2);
dl = 1; //eps_d*1.e7;
dvector_product(&(np1->p[gr].v),&x2, &x3);
x3.x *= dl; x3.y *= dl; x3.z *= dl;
x3.x += np1->v[v1].x;
x3.y += np1->v[v1].y;
x3.z += np1->v[v1].z;
f = (pl->v.x*x3.x + pl->v.y*x3.y + pl->v.z*x3.z + pl->d);
p = sg(f,eps_d);
return p;
}
short b_face_angle(lpNPW np1, short r, lpNPW np2, short f1, short f2, short pe)
{
short p1,p2,p,f;
short mvy[3][3]={
{ 1, 3, 0},
{ 2, 2, 0},
{ 0, 0, 0}
};
short mvo[3][3]={
{ 1, 1, 1},
{ 1, 2, 2},
{ 1, 3, 0}
};
if (r > 0) f = np1->efc[ r].fp;
else f = np1->efc[-r].fm;
if (f < 0) f = 0;
p1 = b_pv(np1, r, &np2->p[f1]);
p1 = p1 + 1;
p2 = b_pv(np1, r, &np2->p[f2]);
p2 = p2 + 1;
if (pe < 0) p = mvy[p1][p2];
else p = mvo[p1][p2];
if (p == 2) {
if (fabs(np1->p[f].v.x - np2->p[f1].v.x) < eps_n &&
fabs(np1->p[f].v.y - np2->p[f1].v.y) < eps_n &&
fabs(np1->p[f].v.z - np2->p[f1].v.z) < eps_n ) return (3);
else return (2);
}
if (p == 3) {
if (fabs(np1->p[f].v.x - np2->p[f2].v.x) < eps_n &&
fabs(np1->p[f].v.y - np2->p[f2].v.y) < eps_n &&
fabs(np1->p[f].v.z - np2->p[f2].v.z) < eps_n ) return (3);
else return (2);
}
return p;
}
+39
View File
@@ -0,0 +1,39 @@
#include "../sg.h"
BOOL b_sv(lpNPW np)
{
short i,j;
short edge,fedge,face,loop;
NP_BIT_FACE *bf,*b;
b = (NP_BIT_FACE*)&np->f[1].fl;
b->met = 1;
i = 1;
do {
j = i;
i = 0;
for (face=1 ; face <= np->nof ; face++) {
b = (NP_BIT_FACE*)&np->f[face].fl;
if (b->met == 1) { i++; continue; }
loop = np->f[face].fc;
do {
edge = fedge = np->c[loop].fe;
do {
facea = SF(edge,np);
if (facea > 0) {
bf = (NP_BIT_FACE*)&np->f[facea].fl;
if (bf->met == 1) {
b->met = 1;
i++;
break;
}
}
edge = SL(edge,np);
} while (edge != fedge);
loop = np->c[loop].nc;
} while(loop != 0 && b->met == 0);
}
} while (i != j && i != np->nof);
if (i == np->nof) return TRUE;
return FALSE;
}
+98
View File
@@ -0,0 +1,98 @@
#include "../sg.h"
BOOL bo_new_user_data(lpNPW np)
{
if ( (np->user = SGMalloc(sizeof(BO_USER)*(np->maxnoe+1))) == NULL) return FALSE;
return TRUE;
}
void bo_free_user_data(lpNPW np)
{
if ( np ) {
if ( np->user ) SGFree(np->user);
np->user = NULL;
}
}
BOOL bo_copy_user_data(lpNPW dist, lpNPW source)
{
BO_USER *us_dist, *us_source;
us_dist = (BO_USER*)dist->user;
us_source = (BO_USER*)source->user;
if (us_source == NULL || us_dist == NULL) return TRUE;
// if (us_dist == NULL) return FALSE;
memcpy(us_dist,us_source,sizeof(us_source)*source->noe);
return TRUE;
}
#pragma argsused
BOOL bo_expand_user_data(lpNPW np, short nov, short noe, short nof, short noc)
{
lpBO_USER user_new;
if (noe == 0 || np->user == NULL) return TRUE;
if ( (user_new = (BO_USER*)SGMalloc(sizeof(BO_USER)*(np->maxnoe+noe+1))) == NULL) return FALSE;
memcpy(user_new,np->user,sizeof(BO_USER)*(np->noe+1));
SGFree(np->user);
np->user = user_new;
return TRUE;
}
BOOL bo_write_user_data_buf(lpNP_BUF np_buf,lpNPW npw)
{
lpBO_USER user = (BO_USER*)npw->user;
lpBUFFER_DAT bd = &np_buf->bd;
char flg = 0;
if (npw->user == NULL) {
if ( !story_data(bd,sizeof(char),&flg) ) return FALSE;
return TRUE;
}
flg = 1;
if ( !story_data(bd,sizeof(char),&flg) ) return FALSE;
if ( !story_data(bd,sizeof(BO_USER)*(npw->noe+1),user) ) return FALSE;
return TRUE;
}
BOOL bo_read_user_data_buf(lpNP_BUF np_buf,lpNPW npw)
{
lpBO_USER user = (BO_USER*)npw->user;
WORD size;
lpBUFFER_DAT bd = &np_buf->bd;
char flg;
if ( load_data(bd,sizeof(flg),&flg) != sizeof(flg)) return FALSE;
if ( !flg ) {
memset(user,0,sizeof(BO_USER)*(npw->maxnoe+1));
return TRUE;
}
size = sizeof(BO_USER)*(npw->noe+1);
if ( load_data(bd,sizeof(BO_USER)*(npw->noe+1),user) != size) return FALSE;
return TRUE;
}
BOOL bo_add_user_data_mem(lpVLD vld,lpNPW npw)
{
lpBO_USER user = (BO_USER*)npw->user;
if ( !add_vld_data(vld,sizeof(BO_USER)*(npw->noe+1),user) ) return FALSE;
return TRUE;
}
#pragma argsused
BOOL bo_read_user_data_mem(lpNPW npw)
{
lpBO_USER user = (BO_USER*)npw->user;
WORD size;
size = sizeof(BO_USER)*(npw->noe+1);
read_vld_data(size,user);
return TRUE;
}
WORD bo_size_user_data(lpNPW npw)
{
WORD size;
if (npw->user == NULL)
size = sizeof(char);
else
size = sizeof(char) + sizeof(BO_USER)*(npw->noe+1);
return size;
}
+453
View File
@@ -0,0 +1,453 @@
#include "../sg.h"
static BOOL b_vr_ee(lpD_POINT * vn,lpD_POINT * vk);
static BOOL b_vr_ff(lpD_POINT * vn, lpD_POINT * vk);
static BOOL b_vr_on(short nm,lpD_POINT * vn,lpD_POINT * vk);
short uk1,uk2;
BOOL b_vr(short uka, short ukb, BOOL lea, BOOL leb)
{
lpNP_VERTEX vn1,vk1,vn2,vk2;
short nm = 0;
D_POINT vvn,vvk;
lpD_POINT vn,vk;
lpDA_POINT w1, w2;
uk1 = uka; uk2 = ukb;
w1 = (lpDA_POINT)npa->v;
w2 = (lpDA_POINT)npb->v;
vn1 = &(vera.v[uk1-1]); vk1 = &(vera.v[uk1]);
vn2 = &(verb.v[uk2-1]); vk2 = &(verb.v[uk2]);
if (w1[vn1->v][np_axis] < w2[vn2->v][np_axis])
memcpy(&vvn,&(npb->v[vn2->v]),sizeof(vvn));
else memcpy(&vvn,&(npa->v[vn1->v]),sizeof(vvn));
vn = &vvn;
if (w1[vk1->v][np_axis] < w2[vk2->v][np_axis])
memcpy(&vvk,&(npa->v[vk1->v]),sizeof(vvk));
else memcpy(&vvk,&(npb->v[vk2->v]),sizeof(vvk));
vk = &vvk;
// if ( !tb_put_otr(vn,vk) ) return FALSE;
// f3d_line(&vport[curr_vp].wind3d,vn,vk);
/*
if (key == PENETRATE) {
t_vr_pnt(&vn);
return;
}
*/
if (key == LINE_INTER) {
if ( !(b_vr_line(vn,vk)) ) return FALSE;
return TRUE;
}
if (lea == FALSE && leb == FALSE) {
if ( b_vr_ff(&vn,&vk) ) return TRUE;
return FALSE;
}
if ( lea == FALSE ) {
nm = 1;
object_number = 2;
}
if ( leb == FALSE ) {
nm = 2;
object_number = 1;
}
if (nm != 0) {
if ( b_vr_on(nm,&vn,&vk) ) return TRUE;
return FALSE;
}
// -
if ( b_vr_ee(&vn,&vk) ) return TRUE;
return FALSE;
}
static BOOL b_vr_ff(lpD_POINT * vn, lpD_POINT * vk)
{
BO_BIT_EDGE *b;
lpBO_USER usa,usb;
D_POINT f;
float gu;
short edgea, edgeb;
object_number = 1;
if ( !b_ort(vn,vk,&(npa->p[facea].v),&(npb->p[faceb].v)) ) return FALSE;
if ( !(edgea = b_vrr(npa,*vn,*vk,&vera,uk1,facea)) ) return FALSE;
b = (BO_BIT_EDGE*)&npa->efr[(int)abs(edgea)].el;
b->ep = 1;
b->em = 0;
b->flg = 1;
object_number = 2;
if ( !b_ort(vn,vk,&(npb->p[faceb].v),&(npa->p[facea].v)) ) return FALSE;
if ( !(edgeb = b_vrr(npb,*vn,*vk,&verb,uk2,faceb)) ) return FALSE;
b = (BO_BIT_EDGE*)&npb->efr[(int)abs(edgeb)].el;
b->ep = 1;
b->em = 0;
b->flg = 1;
if ( !brept1 ) {
usa = (lpBO_USER)npa->user;
usa[(int)abs(edgea)].bnd = 0.;
usa[(int)abs(edgea)].ind = 0;
return TRUE;
}
f.x = npb->p[faceb].v.x;
f.y = npb->p[faceb].v.y;
f.z = npb->p[faceb].v.z;
if (key == SUB) { edgea = -edgea; f.x = - f.x; f.y = - f.y; f.z = - f.z; }
if (key == UNION) edgea = -edgea;
if ( (gu = np_gru(npa,edgea,&npa->p[facea].v,&f)) == 0 ) return FALSE;
usa = (lpBO_USER)npa->user;
usb = (lpBO_USER)npb->user;
usa[(int)abs(edgea)].bnd = gu;
usb[edgeb].bnd = gu;
usa[(int)abs(edgea)].ind = npb->ident;
usb[edgeb].ind = npa->ident;
return TRUE;
}
static BOOL b_vr_on(short nm,lpD_POINT * vn,lpD_POINT * vk)
{
short r,edge,ir,edgea;
short fs,fs1,fs2,face;
short p1,p2,pe1,met_p,met_o;
short i,ident,num_index;
short ukr,ukf;
float gu;
lpNPW npr,npf;
D_POINT ff,fr;
BO_BIT_EDGE *b;
lpBO_USER usr,usf,usa;
lpNP_VERTEX_LIST spr,spf;
lpNP_STR_LIST listd;
hINDEX hindex;
VNP vnp;
if (nm == 1) {
npr = npb; usr = (lpBO_USER)npb->user;
npf = npa; usf = (lpBO_USER)npa->user;
spr = &verb; ukr = uk2;
spf = &vera; ukf = uk1;
face = facea;
listd = &listb; hindex = hindex_b; num_index = num_index_b;
} else {
npr = npa; usr = (lpBO_USER)npa->user;
npf = npb; usf = (lpBO_USER)npb->user;
spr = &vera; ukr = uk1;
spf = &verb; ukf = uk2;
face = faceb;
listd = &lista; hindex = hindex_a; num_index = num_index_a;
}
r = b_vran(npr,spr,ukr);
if (r > 0) {
fs1 = npr->efc[r].fp;
fs2 = npr->efc[r].fm;
ident = npr->efc[r].em;
} else {
fs1 = npr->efc[-r].fm;
fs2 = npr->efc[-r].fp;
ident = npr->efc[-r].ep;
}
ir = abs(r);
if (fs2 == 0) {
if ( !brept1 && object_number == 1) {
npr->p[0] = npr->p[fs1];
} else {
put_message(NO_LIMIT_COND,NULL,0);
return FALSE;
}
} else { if (fs2 < 0) fs2 = np_calc_gru(npr, ir); }
if ( !(r = b_diver(npr,spr,ukr,r,*vn,*vk)) ) return FALSE;
if ( object_number == 1) object_number = 2;
else object_number = 1;
p1 = b_pv(npr, r, &npf->p[face]);
p2 = b_pv(npr,(short)(-r), &npf->p[face]);
if (p1 == p2) {
b = (BO_BIT_EDGE*)&npr->efr[(int)abs(r)].el;
b->flg = 1;
pe1 = b_pv(npr,r,&npr->p[fs2]);
if (p1 == 1) {
b->ep = 0;
b->em = 0;
if (pe1 == -1) {
if (key != UNION) return TRUE;
} else
if (!(key == SUB && object_number == 2)) return TRUE;
} else {
b->ep = 1;
b->em = 1;
if (pe1 == -1) {
if (!(key == SUB && nm == 1)) return TRUE;
} else
if (key != INTER) return TRUE;
}
put_message(TOO_MANY_FACES,NULL,0);
return FALSE;
}
if (p1 == -p2) {
b = (BO_BIT_EDGE*)&npr->efr[(int)abs(r)].el;
b->flg = 1;
if (r > 0 && p1 == -1 || r < 0 && p1 == 1) {
b->ep = 1;
b->em = 0;
} else {
b->ep = 0;
b->em = 1;
}
if ( !b_ort(vn,vk,&(npf->p[face].v),&(npr->p[fs1].v)) ) return FALSE;
edge = abs(b_vrr(npf,*vn,*vk,spf,ukf,face));
if (edge == 0) return FALSE;
b = (BO_BIT_EDGE*)&npf->efr[(int)abs(edge)].el;
b->ep = 1;
b->em = 0;
b->flg = 1;
} else {
if ((fabs(npf->p[face].v.x - npr->p[fs2].v.x) < eps_n) &&
(fabs(npf->p[face].v.y - npr->p[fs2].v.y) < eps_n) &&
(fabs(npf->p[face].v.z - npr->p[fs2].v.z) < eps_n) ) {
if ( !b_ort_on(npr, (short)(-r), vn, vk) ) return FALSE;
edge = abs(b_vrr(npf,*vn,*vk,spf,ukf,face));
if ( edge == 0 ) return FALSE;
b = (BO_BIT_EDGE*)&npr->efr[(int)abs(r)].el;
b->flg = 1;
if (r > 0) {
b->em = 3;
if (p1 > 0) b->ep = 0;
else b->ep = 1;
} else {
b->ep = 3;
if (p1 > 0) b->em = 0;
else b->em = 1;
}
b = (BO_BIT_EDGE*)&npf->efr[edge].el;
b->flg = 1;
b->ep = 3;
if (p1 > 0) b->em = 1;
else b->em = 0;
} else {
if ( !b_ort_on(npr, r, vn, vk) ) return FALSE;
edge = abs(b_vrr(npf,*vn,*vk,spf,ukf,face));
if ( edge == 0 ) return FALSE;
b = (BO_BIT_EDGE*)&npr->efr[(int)abs(r)].el;
b->flg = 1;
if (r > 0) {
b->em = 2;
if (p1 > 0) b->ep = 0;
else b->ep = 1;
} else {
b->ep = 2;
if (p1 > 0) b->em = 0;
else b->em = 1;
}
b = (BO_BIT_EDGE*)&npf->efr[edge].el;
b->flg = 1;
b->ep = 2;
if (p1 > 0) b->em = 0;
else b->em = 1;
}
}
if ( !brept1 ) {
if (nm == 1) edgea = r;
else edgea = edge;
usa = (lpBO_USER)npa->user;
usa[(int)abs(edgea)].bnd = 0.;
usa[(int)abs(edgea)].ind = 0;
return TRUE;
}
ir = abs(r);
b = (BO_BIT_EDGE*)&npr->efr[ir].el;
if (r > 0) { met_p = b->ep; met_o = b->em;}
else { met_p = b->em; met_o = b->ep;}
if (nm == 1) object_number = 2;
else object_number = 1;
i = 0;
if ((b_face_label(met_p)) == 1) { fs = fs1; i++;}
if ((b_face_label(met_o)) == 1) { fs = fs2; r = -r; i++;}
if (i == 0 || i == 2) return TRUE;
memcpy(&fr,&npr->p[fs].v,sizeof(fr));
memcpy(&ff,&npf->p[face].v,sizeof(ff));
if (key == SUB) {
if (nm == 2) { ff.x = - ff.x; ff.y = - ff.y; ff.z = - ff.z; }
else { fr.x = - fr.x; fr.y = - fr.y; fr.z = - fr.z; r = -r;}
}
if ( (gu = np_gru(npr,r,&fr,&ff)) == 0 ) return FALSE;
usf[(int)abs(edge)].bnd = gu;
if (fs == 0) {
usf[(int)abs(edge)].ind = ident;
usr[ir].bnd = gu;
usr[ir].ind = npf->ident;
if (p1 == 0 || p2 == 0) {
if ( !np_write_np_tmp(npf) ) return FALSE;
if ( !(vnp=b_get_hnp(hindex,num_index,ident)) ) {
put_message(INTERNAL_ERROR,GetIDS(IDS_SG023),0);
goto err;
}
if ( !read_np(&listd->bnp,vnp,npf) ) goto err;
if ( !b_vr_idn(npf,*vn,*vk,npr,ir) ) goto err;
if ( !overwrite_np(&listd->bnp,vnp,npf,TNPW) ) goto err;
if ( !np_read_np_tmp(npf) ) return FALSE;
}
} else {
usf[(int)abs(edge)].ind = npr->ident;
usr[ir].bnd = gu;
usr[ir].ind = npf->ident;
}
return TRUE;
err:
np_free_np_tmp();
return FALSE;
}
static BOOL b_vr_ee(lpD_POINT * vn,lpD_POINT * vk)
{
short edgea, edgeb, ir, jr, r;
short pe1, met, i1, i2, pra, prb;
short fma, fpa, fmb, fpb;
short identa, identb;
short fs1, fs2;
float gu;
D_POINT f1, f2;
BO_BIT_EDGE *ba, *bb;
lpBO_USER usa, usb;
VNP vnp;
usa = (lpBO_USER)npa->user;
usb = (lpBO_USER)npb->user;
object_number = 1;
edgea = b_vran(npa,&vera,uk1);
if ( !(edgea = b_diver(npa,&vera,uk1,edgea,*vn,*vk)) ) return FALSE;
ir = abs(edgea);
object_number = 2;
edgeb = b_vran(npb,&verb,uk2);
if ( !(edgeb = b_diver(npb,&verb,uk2,edgeb,*vn,*vk)) ) return FALSE;
jr = abs(edgeb);
ba = (BO_BIT_EDGE*)&npa->efr[ir].el;
bb = (BO_BIT_EDGE*)&npb->efr[jr].el;
if (ba->flg == 1 && bb->flg == 1) return TRUE;
fpa = npa->efc[ir].fp; fpb = npb->efc[jr].fp;
fma = npa->efc[ir].fm; fmb = npb->efc[jr].fm;
if (fpa == 0 || fma == 0 ) {
if ( !brept1 ) {
if (fpa == 0) npa->p[0] = npa->p[fma];
else npa->p[0] = npa->p[fpa];
} else {
put_message(NO_LIMIT_COND,NULL,0);
return FALSE;
}
} else {
if (fpa < 0 || fma < 0) {
if (fpa < 0) { fpa = np_calc_gru(npa, ir); identa = npa->efc[ir].ep; }
else { fma = np_calc_gru(npa, ir); identa = npa->efc[ir].em; }
}
}
if ( fpb == 0 || fmb == 0 ) {
put_message(NO_LIMIT_COND,NULL,0);
return FALSE;
}
if (fpb < 0 || fmb < 0) {
if (fpb < 0) { fpb = np_calc_gru(npb, jr); identb = npb->efc[jr].ep; }
else { fmb = np_calc_gru(npb, jr); identb = npb->efc[jr].em; }
}
pra = 0;
if (ba->flg == 0) {
pe1 = b_pv(npb,jr,&npb->p[fmb]);
ba->ep = b_face_angle(npa, ir, npb, fpb, fmb, pe1);
ba->em = b_face_angle(npa,(short)(-ir),npb, fpb, fmb, pe1);
ba->flg = 1;
} else pra = 1;
prb = 0;
if (bb->flg == 0) {
pe1 = b_pv(npa,ir,&npa->p[fma]);
bb->ep = b_face_angle(npb, jr, npa, fpa, fma, pe1);
bb->em = b_face_angle(npb,(short)(-jr),npa, fpa, fma, pe1);
bb->flg = 1;
} else prb = 1;
if ( !brept1 ) {
usa = (lpBO_USER)npa->user;
usa[(int)abs(edgea)].bnd = 0.;
usa[(int)abs(edgea)].ind = 0;
return TRUE;
}
i1 = 0; i2 = 0;
met = ba->ep;
object_number = 1;
if ((b_face_label(met)) == 1) { fs1 = fpa; r = ir; i1++; }
met = ba->em;
if ((b_face_label(met)) == 1) { fs1 = fma; r = -ir; i1++; }
met = bb->ep;
object_number = 2;
if ((b_face_label(met)) == 1) { fs2 = fpb; i2++; }
met = bb->em;
if ((b_face_label(met)) == 1) { fs2 = fmb; i2++; }
if (i1 == 2 && i2 == 0 || i1 == 0 && i2 == 2 ||
i1 == 0 && i2 == 0) return TRUE;
if (i1 == 1 && i2 == 1) {
memcpy(&f1,&npa->p[fs1].v,sizeof(f1));
memcpy(&f2,&npb->p[fs2].v,sizeof(f2));
if (key == SUB) {
f2.x = - f2.x; f2.y = - f2.y; f2.z = - f2.z;
}
if ( (gu = np_gru(npa,r,&f1,&f2)) == 0 ) return FALSE;
if (pra == 0) {
usa[ir].bnd = gu;
if (fs2 == 0) usa[ir].ind = identb;
else usa[ir].ind = npb->ident;
if (fs1 == 0) {
if (ba->ep == 2 || ba->ep == 3 ||
ba->em == 2 || ba->em == 3) {
if ( !np_write_np_tmp(npb) ) return FALSE;
if ( !(vnp = b_get_hnp(hindex_a, (short)num_index_a, identa)) ) {
put_message(INTERNAL_ERROR,GetIDS(IDS_SG024),0);
goto err;
}
if ( !read_np(&lista.bnp,vnp,npb) ) goto err;
if ( !b_vr_idn(npb,*vn,*vk,npa,ir) ) goto err;
if ( !overwrite_np(&lista.bnp,vnp,npb,TNPW) ) goto err;
if ( !np_read_np_tmp(npb) ) return FALSE;
}
}
}
if (prb == 0) {
usb[jr].bnd = gu;
if (fs1 == 0) usb[jr].ind = identa;
else usb[jr].ind = npa->ident;
if (fs2 == 0) {
if (bb->ep == 2 || bb->ep == 3 ||
bb->em == 2 || bb->em == 3 ) {
if ( !np_write_np_tmp(npa) ) return FALSE;
if ( !(vnp=b_get_hnp(hindex_b, (short)num_index_b, identb)) ) {
put_message(INTERNAL_ERROR,GetIDS(IDS_SG025),0);
goto err;
}
if ( !read_np(&listb.bnp,vnp,npa) ) goto err;
if ( !b_vr_idn(npa,*vn,*vk,npb,jr) ) goto err;
if ( !overwrite_np(&listb.bnp,vnp,npa,TNPW) ) goto err;
if ( !np_read_np_tmp(npa) ) return FALSE;
}
}
}
return TRUE;
}
if (i1 == 2 && i2 == 2)
put_message(TOO_MANY_FACES,NULL,0);
else
put_message(INTERNAL_ERROR,GetIDS(IDS_SG026),0);
return FALSE;
err:
np_free_np_tmp();
return FALSE;
}
+115
View File
@@ -0,0 +1,115 @@
#include "../sg.h"
BOOL b_ort(lpD_POINT * vn,lpD_POINT * vk,
lpD_POINT n1, lpD_POINT n2)
{
lpD_POINT v;
sgFloat sp;
D_POINT a3, a4;
dvector_product(n1, n2, &a3);
dpoint_sub(*vk, *vn, &a4);
if ( !dnormal_vector (&a3) ) goto err;
if ( !dnormal_vector (&a4) ) goto err;
sp = dskalar_product(&a3, &a4);
if ( sg(sp,eps_d) < 0 ) {
v = *vn;
*vn = *vk;
*vk = v;
}
return TRUE;
err:
return FALSE;
}
BOOL b_ort_on(lpNPW np, short r, lpD_POINT * vn, lpD_POINT * vk)
{
short v1,v2;
sgFloat sp;
D_POINT a3, a4;
lpD_POINT v;
v1 = BE(r,np);
v2 = EE(r,np);
dpoint_sub(*vk, *vn, &a3);
dpoint_sub(&(np->v[v2]), &(np->v[v1]), &a4);
if ( !dnormal_vector (&a3) ) goto err;
if ( !dnormal_vector (&a4) ) goto err;
sp = dskalar_product(&a3, &a4);
if ((sg(sp,eps_d)) < 0) {
v = *vn;
*vn = *vk;
*vk = v;
}
return TRUE;
err:
return FALSE;
}
short b_vrr(lpNPW np,lpD_POINT vn,lpD_POINT vk,lpNP_VERTEX_LIST ver,
short ukt, short face)
{
short v1, v2, v;
short edge, cnt, loop;
DA_POINT wn,wk;
lpDA_POINT w;
wn[0] = np->v[ver->v[ukt-1].v].x;
wn[1] = np->v[ver->v[ukt-1].v].y;
wn[2] = np->v[ver->v[ukt-1].v].z;
wk[0] = np->v[ver->v[ukt].v].x;
wk[1] = np->v[ver->v[ukt].v].y;
wk[2] = np->v[ver->v[ukt].v].z;
// memcpy(wn,&(np->v[ver->v[ukt-1].v]),sizeof(D_POINT));
// memcpy(wk,&(np->v[ver->v[ukt].v]),sizeof(D_POINT));
if ( (v1 = np_new_vertex(np, vn)) == 0) return 0;
if ( (v2 = np_new_vertex(np, vk)) == 0) return 0;
if ( (edge = np_new_edge(np,v1,v2)) <= 0) return edge;
np->efc[edge].fm = np->efc[edge].fp = face;
np->efr[edge].el = ST_TD_CONSTR;
w = (lpDA_POINT)np->v;
if (w[v1][np_axis] > w[v2][np_axis]) {
v = v1; v1 = v2; v2 = v;
}
if ((fabs(w[v1][np_axis] - wn[np_axis])) < eps_d &&
ver->v[ukt-1].m == 1) {
if (b_dive(np,ver->v[ukt-1].r,v1) == 0) return (0);
}
w = (lpDA_POINT)np->v;
if ((fabs(w[v2][np_axis] - wk[np_axis])) < eps_d &&
ver->v[ukt].m == 1) {
if (b_dive(np,ver->v[ukt].r,v2) == 0) return (0);
}
cnt = np->f[face].fc;
while (cnt > 0) {
loop = cnt;
cnt = np->c[cnt].nc;
}
if (cnt != 0) {
cnt = abs(cnt);
np->efc[edge].ep = np->c[cnt].fe;
np->c[cnt].fe = edge;
} else {
cnt = np_new_loop(np,edge);
np->c[loop].nc = -cnt;
}
return (edge);
}
short b_vran(lpNPW np, lpNP_VERTEX_LIST sp, short ukt)
{
short r1,r2;
short v1,v2,vn,vk;
r1 = sp->v[ukt].r;
r2 = sp->v[ukt-1].r;
v1 = sp->v[ukt].v;
v2 = sp->v[ukt-1].v;
vn = np->efr[(int)abs(r1)].bv;
vk = np->efr[(int)abs(r1)].ev;
if ((v1 == vn) & (v2 == vk) || (v1 == vk) & (v2 == vn)) return (r1);
return (r2);
}
+86
View File
@@ -0,0 +1,86 @@
#include "../sg.h"
BOOL b_vr_idn(lpNPW np,lpD_POINT vn,lpD_POINT vk,lpNPW npr,short edge)
{
/*
#define DIST(v1,f) (fabs(np->v[v1].x*npr->p[f].v.x + \
np->v[v1].y*npr->p[f].v.y + np->v[v1].z*npr->p[f].v.z + \
npr->p[f].d))
DA_POINT *w;
short v1,v2,vv,f1,f2,i,r;
BO_BIT_EDGE *b, *br;
NP_STR str;
lpNP_STR_LIST list_str;
short old_ident,index;
if (npr == npa) {
list_str = &lista;
} else {
list_str = &listb;
}
old_ident = npr->ident;
f1 = npr->efc[edge].fp; if (f1 < 0) f1 = 0;
f2 = npr->efc[edge].fm; if (f2 < 0) f2 = 0;
for (i=1 ; i <= np->noe ; i++) {
if (np->efc[i].ep == old_ident || np->efc[i].em == old_ident) {
v1 = np->efr[i].bv;
if ( (DIST(v1,f1)) > eps_d ) continue;
v2 = np->efr[i].ev;
if ( (DIST(v2,f1)) > eps_d ) continue;
if ( (DIST(v1,f2)) > eps_d ) continue;
if ( (DIST(v2,f2)) > eps_d ) continue;
w = (void*)np->v;
if (w[v1][np_axis] > w[v2][np_axis]) {
vv = v2; v2 = v1; v1 = vv;
}
switch (np_axis) {
case 0:
if (!(np->v[v1].x-eps_d < vn->x && np->v[v2].x+eps_d > vn->x &&
np->v[v1].x-eps_d < vk->x && np->v[v2].x+eps_d > vk->x)) continue;
break;
case 1:
if (!(np->v[v1].y-eps_d < vn->y && np->v[v2].y+eps_d > vn->y &&
np->v[v1].y-eps_d < vk->y && np->v[v2].y+eps_d > vk->y)) continue;
break;
case 2:
if (!(np->v[v1].z-eps_d < vn->z && np->v[v2].z+eps_d > vn->z &&
np->v[v1].z-eps_d < vk->z && np->v[v2].z+eps_d > vk->z)) continue;
break;
}
if ((r = b_diver_ident(np,i,vn,vk)) == 0) return FALSE;
*/
short r,index;
BO_BIT_EDGE *b, *br;
NP_STR str;
lpNP_STR_LIST list_str;
if (npr == npa) {
list_str = &lista;
} else {
list_str = &listb;
}
if ( (r=b_search_edge(np,vn,vk,npr->ident)) == 0) {
put_message(INTERNAL_ERROR,GetIDS(IDS_SG027),0);
return FALSE;
}
((BO_USER*)(np->user))[r].bnd = ((BO_USER*)(npr->user))[edge].bnd;
((BO_USER*)(np->user))[r].ind = ((BO_USER*)(npr->user))[edge].ind;
b = (BO_BIT_EDGE*)&np->efr[r].el;
br = (BO_BIT_EDGE*)&npr->efr[edge].el;
b->flg = 1;
if (dpoint_eq(&npr->v[npr->efr[edge].bv],
&np->v[np->efr[r].bv],eps_d)) {
b->em = br->em;
b->ep = br->ep;
} else {
b->em = br->ep;
b->ep = br->em;
}
if ( !(np_get_str(list_str,np->ident,&str,&index)) ) return FALSE;
str.lab = 2;
write_elem(&list_str->vdim,index,&str);
return TRUE;
}
+18
View File
@@ -0,0 +1,18 @@
#include "../sg.h"
BOOL b_vr_line(lpD_POINT vn,lpD_POINT vk)
{
lpGEO_LINE geo_line;
hOBJ hobj;
lpOBJ obj;
if((hobj = o_alloc(OLINE)) == NULL)
return FALSE;
obj = (lpOBJ)hobj;
geo_line = (lpGEO_LINE)(obj->geo_data);
geo_line->v1 = *vn;
geo_line->v2 = *vk;
attach_item_tail(bo_line_listh, hobj);
return TRUE;
}
+312
View File
@@ -0,0 +1,312 @@
#include "../sg.h"
typedef int (*fptr)(const void*, const void*);
static OSCAN_COD check_scan(hOBJ hobj,lpSCAN_CONTROL lpsc);
static hINDEX check_index_np(void);
static int sort_function( const short *a, const short *b);
static BOOL check_list_del(void);
static BOOL check_list_lable(lpNP_STR_LIST list);
static int ii, num_proc = -1;
BOOL check = TRUE;
BOOL check_and_edit_model(hOBJ hobj, hOBJ *hnew_obj, BOOL * pr)
{
int i, num_np;
int * b;//nb = NULL;
lpOBJ obj;//nb = NULL;
lpGEO_BREP lpgeobrep;
SCAN_CONTROL sc;
NP_STR str1, str2;
REGION_3D gab;
BOOL rt = TRUE;
lpLNP lnp;
LISTH list_brep = {NULL,NULL,0};
GS_CODE ret;
BOOL value = TRUE;
check = TRUE;
*hnew_obj = NULL;
flg_exist = 0;
obj = (lpOBJ)hobj;
lpgeobrep = (lpGEO_BREP)obj->geo_data;
if (lpgeobrep->type != BODY) {
put_message(MSG_CHECK_002,NULL,0);
return FALSE;
}
key = UNION;
lnp = (LNP*)get_elem(&vd_brep,lpgeobrep->num);
num_np = lnp->num_np;
gab.min = lpgeobrep->min;
gab.max = lpgeobrep->max;
f3d_gabar_project1(lpgeobrep->matr,&gab.min,&gab.max,&gab.min,&gab.max);
define_eps(&(gab.min), &(gab.max));
init_scan(&sc);
sc.user_geo_scan = check_scan;
read_user_data_buf = bo_read_user_data_buf;
write_user_data_buf = bo_write_user_data_buf;
read_user_data_mem = bo_read_user_data_mem;
add_user_data_mem = bo_add_user_data_mem;
size_user_data = bo_size_user_data;
expand_user_data = bo_expand_user_data;
npwg->type = TNPW;
np_init(npwg);
if ( !(bo_new_user_data(npwg)) ) goto err;
// num_proc = start_grad(GetIDS(IDS_SG170), num_np);
ii = 0;
if ( !np_init_list(&lista) ) goto err;
if ( (o_scan(hobj,&sc)) != OSTRUE ) goto err;
// end_grad (num_proc ,ii);
if ((hindex_a = check_index_np()) == NULL) goto err;
num_index_a = lista.number_all;
hindex_b = hindex_a;
num_index_b = lista.number_all;
listb = lista;
if (!(np_str_form(np_gab_inter, &lista, &lista))) goto err;
npa = npwg;
npwg->type = TNPW;
if ( (npb = creat_np_mem(TNPW,MAXNOV,MAXNOE,MAXNOF,MAXNOF,MAXNOE))
== NULL ) goto err;
np_init(npb);
if ( !(bo_new_user_data(npb)) ) goto err;
// num_proc = start_grad(GetIDS(IDS_SG171), lista.number_all);
for (ii=0; ii<lista.number_all; ii++) {
// step_grad (num_proc , ii);
read_elem(&lista.vdim,ii,&str1);
if ( str1.len == 0 ) continue; //
if (!(read_np(&lista.bnp,str1.hnp,npa))) goto err;
if ( !check_np(npa, npa, &str1, &str1) ) goto err;
begin_rw(&lista.nb, str1.b);
for (i=0 ; i < str1.len ; i++) {
b = (int*)get_next_elem(&lista.nb);
read_elem(&lista.vdim,*b,&str2);
if ( npa->ident > str2.ident ) continue;
if (!(read_np(&lista.bnp,str2.hnp,npb))) goto err;
if ( !(check_np(npa, npb, &str1, &str2)) ) {
end_rw(&lista.nb); //nb b = NULL;
goto end;
}
if (str2.lab == 2) {
if ( !(overwrite_np(&lista.bnp,str2.hnp,npb,TNPW)) ) goto err;
}
write_elem(&lista.vdim,*b,&str2);
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
end_rw(&lista.nb); //nb b = NULL;
goto err;
}
}
end_rw(&lista.nb); //nb b = NULL;
if (str1.lab == 2) {
if ( !(overwrite_np(&lista.bnp,str1.hnp,npa,TNPW)) ) goto err;
}
write_elem(&lista.vdim,ii,&str1);
}
read_user_data_mem = NULL;
add_user_data_mem = NULL;
// end_grad (num_proc , ii);
num_proc = -1;
if ( check ) goto end;
// ret = get_bool_value(&value, get_prompt(PRO_CHECK_001)->str);
ret = G_OK;
if (ret != G_OK || !value) goto end;
if ( !(check_list_del()) ) goto err;
object_number = 1;
for (ii=0; ii<lista.number_all; ii++) {
read_elem(&lista.vdim,ii,&str1);
if ((str1.ort & ST_SV) || (str1.ort & ST_MAX)) {
if ( !(b_del_sv(&lista, &str1)) ) goto err;
str1.ort = 0;
write_elem(&lista.vdim,ii,&str1);
}
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
goto end;
}
}
if ( !b_form_model_list(&list_brep, hobj) ) goto err;
*hnew_obj = list_brep.hhead;
goto end;
err:
put_message(MSG_CHECK_001,NULL,0);
rt = FALSE;
end:
*pr = check;
flg_exist = 1;
// if (num_proc != -1 ) end_grad (num_proc ,ii);
bo_free_user_data(npwg);
bo_free_user_data(npb);
if ( npb ) free_np_mem(&npb);
if (hindex_a != NULL) { SGFree(hindex_a); hindex_a = NULL; hindex_b = NULL; }
np_free_stack();
np_end_of_put(&lista,NP_CANCEL,0,NULL);
read_user_data_buf = NULL;
write_user_data_buf = NULL;
size_user_data = NULL;
expand_user_data = NULL;
read_user_data_mem = NULL;
add_user_data_mem = NULL;
return rt;
}
#pragma argsused
static OSCAN_COD check_scan(hOBJ hobj,lpSCAN_CONTROL lpsc)
{
register short i;
lpD_POINT v;
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
return OSFALSE;
}
// step_grad (num_proc , ii++);
npwg->type = TNPW;
v = npwg->v;
for (i = 1; i <= npwg->nov ; i++) {
if ( !o_hcncrd(lpsc->m,&v[i],&v[i])) goto err;
}
for (i = 1; i <= npwg->noe ; i++) {
npwg->efr[i].el &= ST_TD_CLEAR;
}
if ( !np_cplane(npwg) ) goto err;
if ( np_put(npwg,&lista) ) return OSTRUE;
err:
return OSFALSE;
}
static hINDEX check_index_np(void)
{
short number_np,i;
lpNP_STR str;
hINDEX hindex;//nb = NULL;
lpINDEX index;
number_np = lista.number_all;
if ( (hindex = SGMalloc(sizeof(INDEX)*number_np)) == NULL) return NULL;
index = (lpINDEX)hindex;
begin_rw(&lista.vdim,0);
for (i=0; i<lista.number_all; i++) {
str = (NP_STR*)get_next_elem(&lista.vdim);
index[i].ident = str->ident;
index[i].hnp = str->hnp;
write_elem(&lista.vdim,i,str);
}
end_rw(&lista.vdim);
qsort((void*)index,i,sizeof(index[0]),(fptr)sort_function);
return hindex;
}
static int sort_function( const short *a, const short *b)
{
if ( (*(INDEX*)a).ident < (*(INDEX*)b).ident ) return -1;
if ( (*(INDEX*)a).ident == (*(INDEX*)b).ident ) return 0;
return 1;
}
static BOOL check_list_del(void)
{
short pr = 0;
int ii;
NP_STR str;
// num_proc = start_grad(GetIDS(IDS_SG035), lista.number_all);
for (ii=0; ii<lista.number_all; ii++) {
// step_grad (num_proc , ii);
read_elem(&lista.vdim,ii,&str);
if (abs(str.lab) == 2) {
if (!(read_np(&lista.bnp,str.hnp,npa))) goto err;
if ( !(check_del(&str)) ) goto err;
if (npa->nof == 0) str.lab = -1;
else { str.lab = 1;
if ( !(overwrite_np(&lista.bnp,str.hnp,npa,TNPW)) ) goto err;
}
write_elem(&lista.vdim,ii,&str);
} else pr = 1;
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
goto err;
}
}
// end_grad (num_proc , ii);
if ( pr == 0 ) return TRUE;
if ( check_list_lable(&lista) ) return TRUE;
err:
// end_grad (num_proc , ii);
return FALSE;
}
static BOOL check_list_lable(lpNP_STR_LIST list)
{
int ii;
NP_STR str;
int count_old, count_np;
/*nb count_old = */count_np = 0;
list->number_np = list->number_all;
do {
count_old = count_np; count_np = 0;
for (ii=0; ii<list->number_all; ii++) {
read_elem(&list->vdim,ii,&str);
if (abs(str.lab) == 1) {
count_np++ ;
continue;
}
if (!(read_np(&list->bnp,str.hnp,npa))) return FALSE;
if ( !(b_np_lab(list,&str,npa)) ) return FALSE;
if (str.lab != 0) {
if (str.lab == 1 && object_number == 2 && key == SUB)
if ( !(overwrite_np(&list->bnp,str.hnp,npa,TNPW)) ) return FALSE;
write_elem(&list->vdim,ii,&str);
count_np++;
}
}
if (ctrl_c_press) {
put_message(CTRL_C_PRESS, NULL, 0);
return FALSE;
}
} while (count_np != list->number_all && count_np != count_old);
if (count_np == 0) {
put_message(MSG_CHECK_003,NULL,1);
return FALSE;
}
if (count_np != list->number_all) {
put_message(MSG_CHECK_004,NULL,0);
return FALSE;
}
return TRUE;
}
+220
View File
@@ -0,0 +1,220 @@
#include "../sg.h"
#define FF(r,m) ((r) > 0 ? m->efc[r].fm : m->efc[-r].fp)
static BOOL check_up(lpNPW np1, lpNPW np2);
static BOOL check_ff1(lpNPW np);
static BOOL check_ff2(lpNPW np1, lpNPW np2);
BOOL check_np(lpNPW np1, lpNPW np2, lpNP_STR str1,lpNP_STR str2)
{
short i;
NP_BIT_FACE *b;
BO_BIT_EDGE *be;
lpDA_POINT w1, w2;
BOOL rt;//nb = TRUE;
if ( !(rt=np_ver_alloc(&vera)) ) goto end;
if ( !(rt=np_ver_alloc(&verb)) ) goto end;
if (np1 != np2) {
i=0;
for (faceb = 1 ; faceb <= np2->nof ; faceb++) {
b = (NP_BIT_FACE*)&np2->f[faceb].fl;
if (np_gab_pl(&np1->gab,&np2->p[faceb],eps_d) == TRUE) {
b->flg = 1;
i++;
} else b->flg = 0;
}
if (i == np2->nof) return TRUE;
}
for (facea = 1 ; facea <= np1->nof ; facea++) {
if (np_gab_pl(&np2->gab,&np1->p[facea],eps_d) == TRUE) continue;
for (faceb = 1 ; faceb <= np2->nof ; faceb++) {
if (np1 == np2) {
// if (facea == faceb) continue;
if (facea >= faceb) continue;
if ( check_ff1(np1) ) continue;
} else {
b = (NP_BIT_FACE*)&np2->f[faceb].fl;
if (b->flg == 1) continue;
if ( check_ff2(np1,np2) ) continue;
}
if (fabs(np1->p[facea].v.x - np2->p[faceb].v.x) <= eps_n &&
fabs(np1->p[facea].v.y - np2->p[faceb].v.y) <= eps_n &&
fabs(np1->p[facea].v.z - np2->p[faceb].v.z) <= eps_n ||
fabs(np1->p[facea].v.x + np2->p[faceb].v.x) <= eps_n &&
fabs(np1->p[facea].v.y + np2->p[faceb].v.y) <= eps_n &&
fabs(np1->p[facea].v.z + np2->p[faceb].v.z) <= eps_n ) continue;
vera.uk = 0; verb.uk = 0;
np1->nov_tmp = np1->maxnov;
np2->nov_tmp = np2->maxnov;
if ( !(rt=np_pl(np1,facea,&vera,&np2->p[faceb])) ) goto end;
if (vera.uk == 0) continue;
if ( !(rt=np_pl(np2,faceb,&verb,&np1->p[facea])) ) goto end;
if (verb.uk == 0) continue;
np_axis = np_defc(&np1->p[facea].v,&np2->p[faceb].v);
np_sort_ver(np1->v,&vera,np_axis);
np_sort_ver(np2->v,&verb,np_axis);
w1 = (lpDA_POINT)np1->v;
w2 = (lpDA_POINT)np2->v;
if (w1[vera.v[0].v][np_axis] > w2[verb.v[verb.uk-1].v][np_axis] ||
w2[verb.v[0].v][np_axis] > w1[vera.v[vera.uk-1].v][np_axis] ) continue;
//
if ( !(rt=check_up(np1, np2)) ) goto end;
}
}
if (str1->lab != 2) {
for (i = 1 ; i <= np1->noe ; i++) {
be = (BO_BIT_EDGE*)&np1->efr[i].el;
if (be->flg == 0) continue;
str1->lab = 2;
break;
}
}
if ( np1 != np2 ) {
if (str2->lab != 2) {
for (i = 1 ; i <= np2->noe ; i++) {
be = (BO_BIT_EDGE*)&np2->efr[i].el;
if (be->flg == 0) continue;
str2->lab = 2;
break;
}
}
}
end:
np_free_ver(&vera);
np_free_ver(&verb);
return rt;
}
static BOOL check_ff1(lpNPW np)
{
short loop, edge, fedge;
loop = np->f[facea].fc;
do {
fedge = edge = np->c[loop].fe;
do {
if (faceb == FF(edge,np)) return TRUE;
edge = SL(edge,np);
} while (edge != fedge);
loop = np->c[loop].nc;
} while (loop > 0);
return FALSE;
}
static BOOL check_ff2(lpNPW np1, lpNPW np2)
{
short v1, v2, w1, w2, ident;
short loop1, edge1, fedge1;
short loop2, edge2, fedge2;
loop1 = np1->f[facea].fc;
do {
fedge1 = edge1 = np1->c[loop1].fe;
do {
if ( FF(edge1,np1) < 0 ) {
if (edge1 < 0) ident = np1->efc[-edge1].ep;
else ident = np1->efc[ edge1].em;
if (ident == np2->ident) {
loop2 = np2->f[faceb].fc;
do {
fedge2 = edge2 = np2->c[loop2].fe;
do {
if ( (ident=FF(edge2,np2)) < 0 ) {
if (edge2 < 0) ident = np2->efc[-edge2].em;
else ident = np2->efc[ edge2].ep;
if (ident == np1->ident) {
v1 = np1->efr[edge1].bv;
v2 = np1->efr[edge1].ev;
w1 = np2->efr[edge2].bv;
w2 = np2->efr[edge2].ev;
if (dpoint_eq(&np1->v[v1],&np2->v[w1],eps_d) &&
dpoint_eq(&np1->v[v2],&np2->v[w2],eps_d) ||
dpoint_eq(&np1->v[v2],&np2->v[w1],eps_d) &&
dpoint_eq(&np1->v[v1],&np2->v[w2],eps_d))
return TRUE;
}
}
edge2 = SL(edge2,np2);
} while (edge2 != fedge2);
loop2 = np2->c[loop2].nc;
} while (loop2 > 0);
return TRUE;
}
}
edge1 = SL(edge1,np1);
} while (edge1 != fedge1);
loop1 = np1->c[loop1].nc;
} while (loop1 > 0);
return FALSE;
}
static BOOL check_up(lpNPW np1, lpNPW np2)
{
short pa = -1, pb = -1;
short pra = -1,prb = -1;
short pta = -1,ptb = -1;
short uka = 0, ukb = 0;
short maxnov1, maxnov2, nov1, nov2, i;
lpDA_POINT w1, w2;
BOOL lea=FALSE,leb=FALSE;
lpNP_VERTEX vn1,vk1,vn2,vk2;
D_POINT vn, vk;
maxnov1 = np1->maxnov; nov1 = np1->nov;
maxnov2 = np2->maxnov; nov2 = np2->nov;
w1 = (lpDA_POINT)np1->v;
w2 = (lpDA_POINT)np2->v;
do {
if (maxnov1 < np1->maxnov) {
w1 = (lpDA_POINT)np1->v;
for (i = uka ; i < vera.uk ; i++) {
if ( vera.v[i].v > nov1 ) vera.v[i].v += MAXNOV/4;
}
maxnov1 = np1->maxnov; nov1 = np1->nov;
if ( np1 == np2 ) {
for (i = ukb ; i < verb.uk ; i++) {
if ( verb.v[i].v > nov2 ) verb.v[i].v += MAXNOV/4;
}
maxnov2 = np2->maxnov; nov2 = np2->nov;
}
}
if (maxnov2 < np2->maxnov) {
w2 = (lpDA_POINT)np2->v;
for (i = ukb ; i < verb.uk ; i++) {
if ( verb.v[i].v > nov2 ) verb.v[i].v += MAXNOV/4;
}
maxnov2 = np2->maxnov; nov2 = np2->nov;
}
if (w1[vera.v[uka].v][np_axis] < w2[verb.v[ukb].v][np_axis]) {
np_av(vera.v[uka].m,&pa,&pra,&pta,&lea);
uka++;
} else {
np_av(verb.v[ukb].m,&pb,&prb,&ptb,&leb);
ukb++;
}
if ((pa + pb) == 2 &&
fabs(w1[vera.v[uka].v][np_axis] - w2[verb.v[ukb-1].v][np_axis]) > eps_d &&
fabs(w1[vera.v[uka-1].v][np_axis] - w2[verb.v[ukb].v][np_axis]) > eps_d) {
vn1 = &(vera.v[uka-1]); vk1 = &(vera.v[uka]);
vn2 = &(verb.v[ukb-1]); vk2 = &(verb.v[ukb]);
if (w1[vn1->v][np_axis] < w2[vn2->v][np_axis])
vn = np2->v[vn2->v];
else vn = np1->v[vn1->v];
if (w1[vk1->v][np_axis] < w2[vk2->v][np_axis])
vk = np1->v[vk1->v];
else vk = np2->v[vk2->v];
// tb_put_otr(&vn,&vk);
check = FALSE;
if ( !check_vr(np1,np2, &vn, &vk, uka,ukb,lea,leb) ) return FALSE;
}
} while (uka < vera.uk && ukb < verb.uk);
return TRUE;
}
+236
View File
@@ -0,0 +1,236 @@
#include "../sg.h"
static BOOL check_move_gru(lpNPW np);
BOOL check_del(lpNP_STR str)
{
short i,k,met,max=0;
BO_BIT_EDGE *bo;
NP_BIT_FACE *bf;
NP_STR str_n;
short ident,edge,face,index;
short * mem_ident;//nb = NULL;
if ( !(b_as(npa)) ) return FALSE;
if ( !(b_fa(npa)) ) return FALSE;
if ( (mem_ident = (short*)SGMalloc(sizeof(npa->ident)*(npa->noe))) == NULL)
return FALSE;
for (i = 1 ; i <= npa->noe ; i++) {
if (npa->efc[i].fp >= 0 && npa->efc[i].fm >= 0) continue;
if (npa->efc[i].fp < 0) {
ident = npa->efc[i].ep;
face = npa->efc[i].fm;
edge = i;
} else {
ident = npa->efc[i].em;
face = npa->efc[i].fp;
edge = -i;
}
bo = (BO_BIT_EDGE*)&npa->efr[(int)abs(i)].el;
if (bo->flg != 0) {
if (edge > 0) met = bo->ep;
else met = bo->em;
met = b_face_label(met);
} else {
bf = (NP_BIT_FACE*)&npa->f[face].fl;
met = bf->met;
}
k = 0;
while (k < max) {
if (mem_ident[k] == ident) break;
k++;
}
if (k < max) continue;
mem_ident[max] = ident;
max++;
if (met == 0) met = -1;
if ( !(np_get_str(&lista, ident, &str_n, &index)) ) goto err;
if (str_n.lab == 0 || str_n.lab == -2) {
str_n.lab = met;
write_elem(&lista.vdim, index, &str_n);
}
continue;
}
SGFree(mem_ident);
if ( !(np_del_face(npa)) ) return FALSE;
if (npa->nof == 0) {
str->lab = -1;
return TRUE;
}
if ( !check_move_gru(npa) ) return FALSE;
if ( !(np_del_edge(npa)) ) return FALSE;
np_del_vertex(npa);
np_del_loop(npa);
for (i=1 ; i <= npa->noe ; i++) {
bo = (BO_BIT_EDGE*)&npa->efr[i].el;
bo->flg = 0;
bo->em = 0;
bo->ep = 0;
}
if ( !b_sv(npa) ) str->ort |= ST_SV;
else if (npa->nov > MAXNOV || npa->noe > MAXNOE ||
npa->nof > MAXNOF || npa->noc > MAXNOC) {
str->ort |= ST_MAX; // > max
}
return TRUE;
err:
SGFree(mem_ident);
return FALSE;
}
static BOOL check_move_gru(lpNPW np)
{
short i, j, edge, loop;
// short noe, last_edge;
lpBO_USER us;
sgFloat con = c_smooth_angle;
us = (lpBO_USER)np->user;
for (i = 1 ; i <= np->noe ; i++) {
if (np->efc[i].fp > 0 && np->efc[i].fm <= 0 && us[i].bnd > 0) {
// -
if ( np->ident != us[i].ind ) {
np->gru[i] = us[i].bnd;
np->efc[i].em = us[i].ind;
np->efc[i].fm = -i;
if (fabs(us[i].bnd - M_PI) < eps_n) {
np->efr[i].el = ST_TD_DUMMY;
continue;
}
if (fabs(us[i].bnd - M_PI) < con) {
np->efr[i].el = ST_TD_APPROCH | ST_TD_COND;
}
continue;
} else {
j = (short)us[i].bnd;
if ( np->efr[i].bv == np->efr[j].bv && np->efr[i].ev == np->efr[j].ev ) {
if (np->efc[j].fm == 0) {
put_message(EMPTY_MSG,GetIDS(IDS_SG357),1);
return FALSE;
}
np->efc[i].fm = np->efc[j].fm;
np->efc[i].em = np->efc[j].em;
j = -j;
} else {
if ( np->efr[i].bv == np->efr[j].ev && np->efr[i].ev == np->efr[j].bv ) {
if (np->efc[j].fp == 0) {
put_message(EMPTY_MSG,GetIDS(IDS_SG358),1);
return FALSE;
}
np->efc[i].fm = np->efc[j].fp;
np->efc[i].em = np->efc[j].ep;
} else {
put_message(EMPTY_MSG,GetIDS(IDS_SG359),1);
return FALSE;
}
}
for( edge = 1; edge <= np->noe ; edge++ ) {
if ( abs(np->efc[edge].ep) == abs(j) ) {
np->efc[edge].ep = i*isg(np->efc[edge].ep)*isg(j);
continue;
}
if ( abs(np->efc[edge].em) == abs(j) ) {
np->efc[edge].em = i*isg(np->efc[edge].em)*isg(j);
continue;
}
}
np->efc[(int)abs(j)].fp = np->efc[(int)abs(j)].ep = 0;
np->efc[(int)abs(j)].fm = np->efc[(int)abs(j)].em = 0;
for( loop = 1; loop <= np->noc ; loop++ ) {
if (np->c[loop].fe == j) {
np->c[loop].fe = -i;
break;
}
}
continue;
}
}
if (np->efc[i].fm > 0 && np->efc[i].fp <= 0 && us[i].bnd > 0) {
if ( np->ident != us[i].ind ) {
np->gru[i] = us[i].bnd;
np->efc[i].ep = us[i].ind;
np->efc[i].fp = - i;
if (fabs(us[i].bnd - M_PI) < eps_n) {
np->efr[i].el = ST_TD_DUMMY;
continue;
}
if (fabs(us[i].bnd - M_PI) < con) {
np->efr[i].el = ST_TD_APPROCH | ST_TD_COND;
}
continue;
} else {
j = (short)us[i].bnd;
if ( np->efr[i].bv == np->efr[j].bv && np->efr[i].ev == np->efr[j].ev ) {
if (np->efc[j].fp == 0) {
put_message(EMPTY_MSG,GetIDS(IDS_SG314),1);
return FALSE;
}
np->efc[i].fp = np->efc[j].fp;
np->efc[i].ep = np->efc[j].ep;
} else {
if ( np->efr[i].bv == np->efr[j].ev && np->efr[i].ev == np->efr[j].bv ) {
if (np->efc[j].fm == 0) {
put_message(EMPTY_MSG,GetIDS(IDS_SG314),1);
return FALSE;
}
np->efc[i].fp = np->efc[j].fm;
np->efc[i].ep = np->efc[j].em;
j = -j;
} else {
put_message(EMPTY_MSG,GetIDS(IDS_SG315),1);
return FALSE;
}
}
for( edge = 1; edge <= np->noe ; edge++ ) {
if ( abs(np->efc[edge].ep) == abs(j) ) {
np->efc[edge].ep = i*isg(np->efc[edge].ep)*isg(j);
continue;
}
if ( abs(np->efc[edge].em) == abs(j) ) {
np->efc[edge].em = i*isg(np->efc[edge].em)*isg(j);
continue;
}
}
np->efc[(int)abs(j)].fp = np->efc[(int)abs(j)].ep = 0;
np->efc[(int)abs(j)].fm = np->efc[(int)abs(j)].em = 0;
for( loop = 1; loop <= np->noc ; loop++ ) {
if (np->c[loop].fe == j) {
np->c[loop].fe = i;
// break;
}
}
continue;
}
}
if (np->efc[i].fm > 0 && np->efc[i].fp > 0) {
if (np->efr[i].el & ST_TD_APPROCH) continue;
facea = np->efc[i].fp;
faceb = np->efc[i].fm;
if (fabs(np->p[facea].v.x - np->p[faceb].v.x) <= eps_n &&
fabs(np->p[facea].v.y - np->p[faceb].v.y) <= eps_n &&
fabs(np->p[facea].v.z - np->p[faceb].v.z) <= eps_n ) {
np->efr[i].el = ST_TD_DUMMY;
}
}
}
return TRUE;
}
+659
View File
@@ -0,0 +1,659 @@
#include "../sg.h"
static BOOL check_vr_ee(lpD_POINT * vn,lpD_POINT * vk);
static BOOL check_vr_ff(lpD_POINT * vn, lpD_POINT * vk);
static BOOL check_vrr2(lpD_POINT vn, lpD_POINT vk);
static BOOL check_vr_on(short nm,lpD_POINT * vn,lpD_POINT * vk);
static short uk1,uk2;
static lpNPW np1, np2;
BOOL check_vr(lpNPW _npa, lpNPW _npb, lpD_POINT vn, lpD_POINT vk,
short uka, short ukb, BOOL lea, BOOL leb)
{
// lpNP_VERTEX vn1,vk1,vn2,vk2;
short nm = 0;
uk1 = uka; uk2 = ukb;
np1 = _npa; np2 = _npb;
if (lea == FALSE && leb == FALSE) {
if ( check_vr_ff(&vn,&vk) ) return TRUE;
return FALSE;
}
if ( lea == FALSE ) {
nm = 1;
// object_number = 2;
}
if ( leb == FALSE ) {
nm = 2;
// object_number = 1;
}
object_number = 1;
if (nm != 0) {
if ( check_vr_on(nm,&vn,&vk) ) return TRUE;
return FALSE;
}
if ( check_vr_ee(&vn,&vk) ) return TRUE;
return FALSE;
}
static BOOL check_vr_ff(lpD_POINT * vn, lpD_POINT * vk)
{
BO_BIT_EDGE *b;
lpBO_USER usa,usb;
D_POINT f;
float gu;
short edgea, edgeb;
if (np1->ident != np2->ident) {
object_number = 1;
if ( !b_ort(vn,vk,&(np1->p[facea].v),&(np2->p[faceb].v)) ) return FALSE;
if ( !(edgea = b_vrr(np1,*vn,*vk,&vera,uk1,facea)) ) return FALSE;
b = (BO_BIT_EDGE*)&np1->efr[edgea].el;
b->ep = 1;
b->em = 0;
b->flg = 1;
// object_number = 2;
if ( !b_ort(vn,vk,&(np2->p[faceb].v),&(np1->p[facea].v)) ) return FALSE;
if ( !(edgeb = b_vrr(np2,*vn,*vk,&verb,uk2,faceb)) ) return FALSE;
b = (BO_BIT_EDGE*)&np2->efr[edgeb].el;
b->ep = 1;
b->em = 0;
b->flg = 1;
f.x = np2->p[faceb].v.x;
f.y = np2->p[faceb].v.y;
f.z = np2->p[faceb].v.z;
/*if (key == UNION) */
edgea = -edgea;
if ( (gu = np_gru(np1,edgea,&np1->p[facea].v,&f)) == 0) return FALSE;
usa = (lpBO_USER)np1->user;
usb = (lpBO_USER)np2->user;
int indxxx = abs(edgea);
usa[indxxx].bnd = gu;
usb[edgeb].bnd = gu;
indxxx = abs(edgea);
usa[indxxx].ind = np2->ident;
usb[edgeb].ind = np1->ident;
} else {
if ( !check_vrr2( *vn, *vk ) ) return FALSE;
}
return TRUE;
}
static BOOL check_vr_on(short nm,lpD_POINT * vn,lpD_POINT * vk)
{
short r, edge, ir; //, v1, v2, v;
short fs, fs1, fs2, face; //, cnt, loop;
short p1, p2, pe1, met_p, met_o;
short i, ident, num_index;
short ukr, ukf;
float gu;
lpNPW npr, npf;
D_POINT ff, fr;
// DA_POINT wn, wk;
// lpDA_POINT w;
BO_BIT_EDGE *b;
lpBO_USER usr, usf, usa;
lpNP_VERTEX_LIST spr, spf;
lpNP_STR_LIST listd;
hINDEX hindex;
VNP vnp;
if (nm == 1) {
npr = np2; usr = (lpBO_USER)np2->user;
npf = np1; usf = (lpBO_USER)np1->user;
spr = &verb; ukr = uk2;
spf = &vera; ukf = uk1;
face = facea;
listd = &listb; hindex = hindex_b; num_index = num_index_b;
} else {
npr = np1; usr = (lpBO_USER)np1->user;
npf = np2; usf = (lpBO_USER)np2->user;
spr = &vera; ukr = uk1;
spf = &verb; ukf = uk2;
face = faceb;
listd = &lista; hindex = hindex_a; num_index = num_index_a;
}
r = b_vran(npr,spr,ukr);
if (r > 0) {
fs1 = npr->efc[r].fp;
fs2 = npr->efc[r].fm;
ident = npr->efc[r].em;
} else {
fs1 = npr->efc[-r].fm;
fs2 = npr->efc[-r].fp;
ident = npr->efc[-r].ep;
}
ir = abs(r);
if (fs2 < 0) fs2 = np_calc_gru(npr, ir);
if ( !(r = b_diver(npr,spr,ukr,r,*vn,*vk)) ) return FALSE;
/* if ( object_number == 1) object_number = 2;
else object_number = 1;
*/
p1 = b_pv(npr, r, &npf->p[face]);
p2 = b_pv(npr,(short)(-r), &npf->p[face]);
if (p1 == p2) {
int indx1 = abs(r);
b = (BO_BIT_EDGE*)&npr->efr[indx1].el;
b->flg = 1;
pe1 = b_pv(npr,r,&npr->p[fs2]);
if (p1 == 1) {
b->ep = 0;
b->em = 0;
if (pe1 == 1) return TRUE;
} else {
b->ep = 1;
b->em = 1;
if (pe1 == -1) return TRUE;
}
put_message(EMPTY_MSG, GetIDS(IDS_SG313), 0);
return FALSE;
}
if (p1 == -p2) {
int indx2 = abs(r);
b = (BO_BIT_EDGE*)&npr->efr[indx2].el;
if ( b->flg == 1 ) return TRUE;
b->flg = 1;
if (r > 0 && p1 == -1 || r < 0 && p1 == 1) {
b->ep = 1;
b->em = 0;
} else {
b->ep = 0;
b->em = 1;
}
if ( !b_ort(vn,vk,&(npf->p[face].v),&(npr->p[fs1].v)) ) return FALSE;
edge = abs(b_vrr(npf,*vn,*vk,spf,ukf,face));
if (edge == 0) return FALSE;
b = (BO_BIT_EDGE*)&npf->efr[edge].el;
b->ep = 1;
b->em = 0;
b->flg = 1;
} else {
if ((fabs(npf->p[face].v.x - npr->p[fs2].v.x) < eps_n) &&
(fabs(npf->p[face].v.y - npr->p[fs2].v.y) < eps_n) &&
(fabs(npf->p[face].v.z - npr->p[fs2].v.z) < eps_n) ) {
if ( !b_ort_on(npr, (short)(-r), vn, vk) ) return FALSE;
// if ( npr->ident != npf->ident ) {
edge = abs(b_vrr(npf,*vn,*vk,spf,ukf,face));
if ( edge == 0 ) return FALSE;
/* } else {
// if ( !b_ort(vn,vk,&(np1->p[fs1].v),&(np1->p[fs2].v)) ) return FALSE;
wn[0] = np1->v[spr->v[uk1-1].v].x;
wn[1] = np1->v[spr->v[uk1-1].v].y;
wn[2] = np1->v[spr->v[uk1-1].v].z;
wk[0] = np1->v[spr->v[uk1].v].x;
wk[1] = np1->v[spr->v[uk1].v].y;
wk[2] = np1->v[spr->v[uk1].v].z;
if ( (v1 = np_new_vertex(np1, *vn)) == 0) return FALSE;
if ( (v2 = np_new_vertex(np1, *vk)) == 0) return FALSE;
if (np1->noe+2 > np1->maxnoe)
if ( !(o_expand_np(np1, 0, MAXNOE/4, 0, 0)) ) return FALSE;
edge = ++np1->noe;
np1->efr[edge].bv = v1;
np1->efr[edge].ev = v2;
np1->efc[edge].ep = 0;
np1->efc[edge].em = 0;
np1->gru[edge] = 0;
np1->efc[edge].fm = np1->efc[edge].fp = face;
np1->efr[edge].el = ST_TD_CONSTR;
w = (lpDA_POINT)np1->v;
if (w[v1][np_axis] > w[v2][np_axis]) {
v = v1; v1 = v2; v2 = v;
}
if ((fabs(w[v1][np_axis] - wn[np_axis])) < eps_d &&
spr->v[uk1-1].m == 1) {
if (b_dive(np1,spr->v[uk1-1].r,v1) == 0) return FALSE;
}
w = (lpDA_POINT)np1->v;
if ((fabs(w[v2][np_axis] - wk[np_axis])) < eps_d &&
spr->v[uk1].m == 1) {
if (b_dive(np1,spr->v[uk1].r,v2) == 0) return FALSE;
}
cnt = np1->f[face].fc;
while (cnt > 0) {
loop = cnt;
cnt = np1->c[cnt].nc;
}
if (cnt != 0) {
cnt = abs(cnt);
np1->efc[edge].ep = np1->c[cnt].fe;
np1->c[cnt].fe = edge;
} else {
cnt = np_new_loop(np1,edge);
np1->c[loop].nc = -cnt;
}
}
*/
int indx3 = abs(r);
b = (BO_BIT_EDGE*)&npr->efr[indx3].el;
b->flg = 1;
if (r > 0) {
b->em = 3;
if (p1 > 0) b->ep = 0;
else b->ep = 1;
} else {
b->ep = 3;
if (p1 > 0) b->em = 0;
else b->em = 1;
}
b = (BO_BIT_EDGE*)&npf->efr[edge].el;
b->flg = 1;
b->ep = 3;
if (p1 > 0) b->em = 1;
else b->em = 0;
} else {
if ( !b_ort_on(npr, r, vn, vk) ) return FALSE;
// if ( npr->ident != npf->ident ) {
edge = abs(b_vrr(npf,*vn,*vk,spf,ukf,face));
if ( edge == 0 ) return FALSE;
/* } else {
// if ( !b_ort(vn,vk,&(np1->p[fs1].v),&(np1->p[fs2].v)) ) return FALSE;
wn[0] = np1->v[spr->v[uk1-1].v].x;
wn[1] = np1->v[spr->v[uk1-1].v].y;
wn[2] = np1->v[spr->v[uk1-1].v].z;
wk[0] = np1->v[spr->v[uk1].v].x;
wk[1] = np1->v[spr->v[uk1].v].y;
wk[2] = np1->v[spr->v[uk1].v].z;
if ( (v1 = np_new_vertex(np1, *vn)) == 0) return FALSE;
if ( (v2 = np_new_vertex(np1, *vk)) == 0) return FALSE;
if (np1->noe+2 > np1->maxnoe)
if ( !(o_expand_np(np1, 0, MAXNOE/4, 0, 0)) ) return FALSE;
edge = ++np1->noe;
np1->efr[edge].bv = v1;
np1->efr[edge].ev = v2;
np1->efc[edge].ep = 0;
np1->efc[edge].em = 0;
np1->gru[edge] = 0;
np1->efc[edge].fm = np1->efc[edge].fp = face;
np1->efr[edge].el = ST_TD_CONSTR;
w = (lpDA_POINT)np1->v;
if (w[v1][np_axis] > w[v2][np_axis]) {
v = v1; v1 = v2; v2 = v;
}
if ((fabs(w[v1][np_axis] - wn[np_axis])) < eps_d &&
spr->v[uk1-1].m == 1) {
if (b_dive(np1,spr->v[uk1-1].r,v1) == 0) return FALSE;
}
w = (lpDA_POINT)np1->v;
if ((fabs(w[v2][np_axis] - wk[np_axis])) < eps_d &&
spr->v[uk1].m == 1) {
if (b_dive(np1,spr->v[uk1].r,v2) == 0) return FALSE;
}
cnt = np1->f[face].fc;
while (cnt > 0) {
loop = cnt;
cnt = np1->c[cnt].nc;
}
if (cnt != 0) {
cnt = abs(cnt);
np1->efc[edge].ep = np1->c[cnt].fe;
np1->c[cnt].fe = edge;
} else {
cnt = np_new_loop(np1,edge);
np1->c[loop].nc = -cnt;
}
}
*/
int indx4 = abs(r);
b = (BO_BIT_EDGE*)&npr->efr[indx4].el;
b->flg = 1;
if (r > 0) {
b->em = 2;
if (p1 > 0) b->ep = 0;
else b->ep = 1;
} else {
b->ep = 2;
if (p1 > 0) b->em = 0;
else b->em = 1;
}
b = (BO_BIT_EDGE*)&npf->efr[edge].el;
b->flg = 1;
b->ep = 2;
if (p1 > 0) b->em = 0;
else b->em = 1;
}
}
ir = abs(r);
if ( npr->ident == npf->ident ) {
usa = (lpBO_USER)npf->user;
usa[edge].bnd = ir;
usa[ir].bnd = edge;
usa[edge].ind = npf->ident;
usa[ir].ind = npf->ident;
return TRUE;
}
b = (BO_BIT_EDGE*)&npr->efr[ir].el;
if (r > 0) { met_p = b->ep; met_o = b->em;}
else { met_p = b->em; met_o = b->ep;}
if (nm == 1) object_number = 2;
else object_number = 1;
i = 0;
if ((b_face_label(met_p)) == 1) { fs = fs1; i++;}
if ((b_face_label(met_o)) == 1) { fs = fs2; r = -r; i++;}
if (i == 0 || i == 2) return TRUE;
memcpy(&fr,&npr->p[fs].v,sizeof(fr));
memcpy(&ff,&npf->p[face].v,sizeof(ff));
if ( (gu = np_gru(npr,r,&fr,&ff)) == 0 ) return FALSE;
int indxxx = abs(edge);
usf[indxxx].bnd = gu;
if (fs == 0) {
int indxx2 = abs(edge);
usf[indxx2].ind = ident;
usr[ir].bnd = gu;
usr[ir].ind = npf->ident;
if (p1 == 0 || p2 == 0) {
if ( !np_write_np_tmp(npf) ) return FALSE;
if ( !(vnp=b_get_hnp(hindex,num_index,ident)) ) {
put_message(INTERNAL_ERROR,"no_index",0);
goto err;
}
if ( !read_np(&listd->bnp,vnp,npf) ) goto err;
if ( !b_vr_idn(npf,*vn,*vk,npr,ir) ) goto err;
if ( !overwrite_np(&listd->bnp,vnp,npf,TNPW) ) goto err;
if ( !np_read_np_tmp(npf) ) return FALSE;
}
} else {
usf[edge].ind = npr->ident;
usf[edge].bnd = gu;
usr[ir].ind = npf->ident;
usr[ir].bnd = gu;
}
return TRUE;
err:
np_free_np_tmp();
return FALSE;
}
static BOOL check_vr_ee(lpD_POINT * vn,lpD_POINT * vk)
{
short edgea,edgeb,ir,jr,r;
short pe1,met,i1,i2,pra,prb;
short fma,fpa,fmb,fpb;
short identa,identb;
short fs1,fs2;
float gu;
D_POINT f1,f2;
BO_BIT_EDGE *ba,*bb;
lpBO_USER usa,usb;
VNP vnp;
usa = (lpBO_USER)np1->user;
usb = (lpBO_USER)np2->user;
object_number = 1;
edgea = b_vran(np1,&vera,uk1);
if ( !(edgea = b_diver(np1,&vera,uk1,edgea,*vn,*vk)) ) return FALSE;
ir = abs(edgea);
// object_number = 2;
edgeb = b_vran(np2,&verb,uk2);
if ( !(edgeb = b_diver(np2,&verb,uk2,edgeb,*vn,*vk)) ) return FALSE;
jr = abs(edgeb);
ba = (BO_BIT_EDGE*)&np1->efr[ir].el;
bb = (BO_BIT_EDGE*)&np2->efr[jr].el;
if (ba->flg == 1 && bb->flg == 1) return TRUE;
fpa = np1->efc[ir].fp; fpb = np2->efc[jr].fp;
fma = np1->efc[ir].fm; fmb = np2->efc[jr].fm;
if (fpa < 0 || fma < 0) {
if (fpa < 0) { fpa = np_calc_gru(np1, ir); identa = np1->efc[ir].ep; }
else { fma = np_calc_gru(np1, ir); identa = np1->efc[ir].em; }
}
if ( fpb == 0 || fmb == 0 ) {
put_message(NO_LIMIT_COND,NULL,0);
return FALSE;
}
if (fpb < 0 || fmb < 0) {
if (fpb < 0) { fpb = np_calc_gru(np2, jr); identb = np2->efc[jr].ep; }
else { fmb = np_calc_gru(np2, jr); identb = np2->efc[jr].em; }
}
pra = 0;
if (ba->flg == 0) {
pe1 = b_pv(np2,jr,&np2->p[fmb]);
ba->ep = b_face_angle(np1, ir,np2,fpb,fmb,pe1);
ba->em = b_face_angle(np1,(short)(-ir),np2,fpb,fmb,pe1);
ba->flg = 1;
} else pra = 1;
prb = 0;
if (bb->flg == 0) {
pe1 = b_pv(np1,ir,&np1->p[fma]);
bb->ep = b_face_angle(np2, jr, np1, fpa, fma, pe1);
bb->em = b_face_angle(np2,(short)(-jr), np1, fpa, fma, pe1);
bb->flg = 1;
} else prb = 1;
if ( np1->ident == np2->ident ) {
usa = (lpBO_USER)np1->user;
usa[ir].bnd = jr;
usa[jr].bnd = ir;
usa[ir].ind = np1->ident;
usa[jr].ind = np1->ident;
return TRUE;
}
i1 = 0; i2 = 0;
met = ba->ep;
object_number = 1;
if ((b_face_label(met)) == 1) { fs1 = fpa; r = ir; i1++; }
met = ba->em;
if ((b_face_label(met)) == 1) { fs1 = fma; r = -ir; i1++; }
met = bb->ep;
object_number = 2;
if ((b_face_label(met)) == 1) { fs2 = fpb; i2++; }
met = bb->em;
if ((b_face_label(met)) == 1) { fs2 = fmb; i2++; }
if (i1 == 2 && i2 == 0 || i1 == 0 && i2 == 2 ||
i1 == 0 && i2 == 0) return TRUE;
if (i1 == 1 && i2 == 1) {
memcpy(&f1,&np1->p[fs1].v,sizeof(f1));
memcpy(&f2,&np2->p[fs2].v,sizeof(f2));
if ( (gu = np_gru(np1,r,&f1,&f2)) == 0 ) return FALSE;
if (pra == 0) {
usa[ir].bnd = gu;
if (fs2 == 0) usa[ir].ind = identb;
else usa[ir].ind = np2->ident;
if (fs1 == 0) {
if (ba->ep == 2 || ba->ep == 3 ||
ba->em == 2 || ba->em == 3) {
if ( !np_write_np_tmp(np2) ) return FALSE;
if ( !(vnp = b_get_hnp(hindex_a, (short)num_index_a, identa)) ) {
put_message(INTERNAL_ERROR,"no_index",0);
goto err;
}
if ( !read_np(&lista.bnp,vnp,np2) ) goto err;
if ( !b_vr_idn(np2,*vn,*vk,np1,ir) ) goto err;
if ( !overwrite_np(&lista.bnp,vnp,np2,TNPW) ) goto err;
if ( !np_read_np_tmp(np2) ) return FALSE;
}
}
}
if (prb == 0) {
usb[jr].bnd = gu;
if (fs1 == 0) usb[jr].ind = identa;
else usb[jr].ind = np1->ident;
if (fs2 == 0) {
if (bb->ep == 2 || bb->ep == 3 ||
bb->em == 2 || bb->em == 3 ) {
if ( !np_write_np_tmp(np1) ) return FALSE;
if ( !(vnp = b_get_hnp(hindex_b, (short)num_index_b, identb)) ) {
put_message(INTERNAL_ERROR,"no_index",0);
goto err;
}
if ( !read_np(&listb.bnp,vnp,np1) ) goto err;
if ( !b_vr_idn(np1,*vn,*vk,np2,jr) ) goto err;
if ( !overwrite_np(&listb.bnp,vnp,np1,TNPW) ) goto err;
if ( !np_read_np_tmp(np1) ) return FALSE;
}
}
}
return TRUE;
}
if (i1 == 2 && i2 == 2)
put_message(TOO_MANY_FACES,NULL,0);
else
put_message(INTERNAL_ERROR,"err_b_vr_ee",0);
return FALSE;
err:
np_free_np_tmp();
return FALSE;
}
static BOOL check_vrr2(lpD_POINT vn, lpD_POINT vk)
{
// short v1, v2, v;
short edge1, edge2; //, cnt, loop;
// DA_POINT wn,wk;
lpBO_USER usa;
BO_BIT_EDGE *b;
// lpDA_POINT w;
object_number = 1;
if ( !b_ort(&vn,&vk,&(npa->p[facea].v),&(npa->p[faceb].v)) ) return FALSE;
if ( !(edge1 = b_vrr(npa,vn,vk,&vera,uk1,facea)) ) return FALSE;
b = (BO_BIT_EDGE*)&npa->efr[edge1].el;
b->ep = 1;
b->em = 0;
b->flg = 1;
// object_number = 2;
// if ( !b_ort(&vn,&vk,&(npa->p[faceb].v),&(npa->p[facea].v)) ) return FALSE;
if ( !(edge2 = b_vrr(npa,vn,vk,&verb,uk2,faceb)) ) return FALSE;
b = (BO_BIT_EDGE*)&np2->efr[edge2].el;
b->ep = 0;
b->em = 1;
b->flg = 1;
/*
if ( !b_ort(&vn,&vk,&(npa->p[facea].v),&(npa->p[faceb].v)) ) return FALSE;
wn[0] = npa->v[vera.v[uk1-1].v].x;
wn[1] = npa->v[vera.v[uk1-1].v].y;
wn[2] = npa->v[vera.v[uk1-1].v].z;
wk[0] = npa->v[vera.v[uk1].v].x;
wk[1] = npa->v[vera.v[uk1].v].y;
wk[2] = npa->v[vera.v[uk1].v].z;
if ( (v1 = np_new_vertex(npa, vn)) == 0) return FALSE;
if ( (v2 = np_new_vertex(npa, vk)) == 0) return FALSE;
if (npa->noe+2 > npa->maxnoe)
if ( !(o_expand_np(npa, 0, MAXNOE/4, 0, 0)) ) return FALSE;
edge1 = ++npa->noe;
npa->efr[edge1].bv = v1;
npa->efr[edge1].ev = v2;
npa->efc[edge1].ep = 0;
npa->efc[edge1].em = 0;
npa->gru[edge1] = 0;
npa->efc[edge1].fm = npa->efc[edge1].fp = facea;
npa->efr[edge1].el = ST_TD_CONSTR;
edge2 = ++npa->noe;
npa->efr[edge2].bv = v1;
npa->efr[edge2].ev = v2;
npa->efc[edge2].ep = 0;
npa->efc[edge2].em = 0;
npa->gru[edge2] = 0;
npa->efc[edge2].fm = npa->efc[edge2].fp = faceb;
npa->efr[edge2].el = ST_TD_CONSTR;
w = (lpDA_POINT)npa->v;
if (w[v1][np_axis] > w[v2][np_axis]) {
v = v1; v1 = v2; v2 = v;
}
if ((fabs(w[v1][np_axis] - wn[np_axis])) < eps_d &&
vera.v[uk1-1].m == 1) {
if (b_dive(npa,vera.v[uk1-1].r,v1) == 0) return FALSE;
}
w = (lpDA_POINT)npa->v;
if ((fabs(w[v2][np_axis] - wk[np_axis])) < eps_d &&
vera.v[uk1].m == 1) {
if (b_dive(npa,vera.v[uk1].r,v2) == 0) return FALSE;
}
b = (BO_BIT_EDGE*)&npa->efr[edge1].el;
b->ep = 1;
b->em = 0;
b->flg = 1;
wn[0] = npa->v[verb.v[uk2-1].v].x;
wn[1] = npa->v[verb.v[uk2-1].v].y;
wn[2] = npa->v[verb.v[uk2-1].v].z;
wk[0] = npa->v[verb.v[uk2].v].x;
wk[1] = npa->v[verb.v[uk2].v].y;
wk[2] = npa->v[verb.v[uk2].v].z;
w = (lpDA_POINT)npa->v;
if ((fabs(w[v1][np_axis] - wn[np_axis])) < eps_d &&
verb.v[uk2-1].m == 1) {
if (b_dive(npa,verb.v[uk2-1].r,v1) == 0) return FALSE;
}
w = (lpDA_POINT)npa->v;
if ((fabs(w[v2][np_axis] - wk[np_axis])) < eps_d &&
verb.v[uk2].m == 1) {
if (b_dive(npa,verb.v[uk2].r,v2) == 0) return FALSE;
}
b = (BO_BIT_EDGE*)&npa->efr[edge2].el;
b->ep = 0;
b->em = 1;
b->flg = 1;
cnt = npa->f[facea].fc;
while (cnt > 0) {
loop = cnt;
cnt = npa->c[cnt].nc;
}
if (cnt != 0) {
cnt = abs(cnt);
npa->efc[edge1].ep = npa->c[cnt].fe;
npa->c[cnt].fe = edge1;
} else {
cnt = np_new_loop(npa,edge1);
npa->c[loop].nc = -cnt;
}
cnt = npa->f[faceb].fc;
while (cnt > 0) {
loop = cnt;
cnt = npa->c[cnt].nc;
}
if (cnt != 0) {
cnt = abs(cnt);
npa->efc[edge2].ep = npa->c[cnt].fe;
npa->c[cnt].fe = edge2;
} else {
cnt = np_new_loop(npa,edge2);
npa->c[loop].nc = -cnt;
}
*/
usa = (lpBO_USER)npa->user;
usa[edge1].bnd = edge2;
usa[edge2].bnd = edge1;
usa[edge1].ind = npa->ident;
usa[edge2].ind = npa->ident;
return TRUE;
}