mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
updated vnf_drop_unused_points
This commit is contained in:
parent
a12a258635
commit
315a1021df
1 changed files with 15 additions and 16 deletions
31
vnf.scad
31
vnf.scad
|
@ -496,34 +496,33 @@ function vnf_quantize(vnf,q=pow(2,-12)) =
|
||||||
[[for (pt = vnf[0]) quant(pt,q)], vnf[1]];
|
[[for (pt = vnf[0]) quant(pt,q)], vnf[1]];
|
||||||
|
|
||||||
|
|
||||||
// Function: vnf_drop_extra_points()
|
// Function: vnf_drop_unused_points()
|
||||||
// Usage:
|
// Usage:
|
||||||
// clean_vnf=vnf_drop_extra_points(vnf);
|
// clean_vnf=vnf_drop_unused_points(vnf);
|
||||||
// Description:
|
// Description:
|
||||||
// Remove all unreferenced vertices from a VNF. Note that in most
|
// Remove all unreferenced vertices from a VNF. Note that in most
|
||||||
// cases unreferenced vertices cause no harm, and this function may
|
// cases unreferenced vertices cause no harm, and this function may
|
||||||
// be slow on large VNFs.
|
// be slow on large VNFs.
|
||||||
function vnf_drop_extra_points(vnf) =
|
function vnf_drop_unused_points(vnf) =
|
||||||
let(
|
let(
|
||||||
flat = flatten(vnf[1]),
|
flat = flatten(vnf[1]),
|
||||||
ind = len(vnf[0])<800
|
ind = _link_indicator(flat,0,len(vnf[0])-1),
|
||||||
? [for(si = search(count(len(vnf[0])), flat,1) ) si!=[] ? 1: 0]
|
|
||||||
: _indicator_sort(flat,0,len(vnf[0])),
|
|
||||||
verts = [for(i=idx(vnf[0])) if(ind[i]==1) vnf[0][i] ],
|
verts = [for(i=idx(vnf[0])) if(ind[i]==1) vnf[0][i] ],
|
||||||
map = cumsum(ind)
|
map = cumsum(ind)
|
||||||
)
|
)
|
||||||
[ verts, [for(face=vnf[1]) [for(v=face) map[v]-1 ] ] ];
|
[ verts, [for(face=vnf[1]) [for(v=face) map[v]-1 ] ] ];
|
||||||
|
|
||||||
|
function _link_indicator(l,imin,imax) =
|
||||||
function _indicator_sort(l,imin,imax) =
|
len(l) == 0 ? repeat(imax-imin+1,0) :
|
||||||
len(l) == 0 ? [for(i=[imin:1:imax]) 0 ] :
|
imax-imin<100 || len(l)<400 ? [for(si=search(list([imin:1:imax]),l,1)) si!=[] ? 1: 0 ] :
|
||||||
let( pivot = floor((imax+imin)/2),
|
let(
|
||||||
lesser = [ for(li=l) if( li< pivot) li ],
|
pivot = floor((imax+imin)/2),
|
||||||
greater = [ for(li=l) if( li> pivot) li ] )
|
lesser = [ for(li=l) if( li< pivot) li ],
|
||||||
concat( _indicator_sort(lesser ,imin,pivot-1),
|
greater = [ for(li=l) if( li> pivot) li ]
|
||||||
|
)
|
||||||
|
concat( _link_indicator(lesser ,imin,pivot-1),
|
||||||
search(pivot,l,1) ? 1 : 0 ,
|
search(pivot,l,1) ? 1 : 0 ,
|
||||||
_indicator_sort(greater,pivot+1,imax) ) ;
|
_link_indicator(greater,pivot+1,imax) ) ;
|
||||||
|
|
||||||
|
|
||||||
// Function: vnf_triangulate()
|
// Function: vnf_triangulate()
|
||||||
// Usage:
|
// Usage:
|
||||||
|
|
Loading…
Reference in a new issue