Открыть боковую панель
nikitronn
sverchok
Коммиты
164dc659
Коммит
164dc659
создал
Июн 27, 2021
по автору
Ilya Portnov
Просмотр файлов
Tuning.
владелец
92ced428
Изменения
2
Скрыть пробелы
Построчно
Рядом
utils/curve/nurbs_algorithms.py
Просмотр файла @
164dc659
...
...
@@ -32,39 +32,51 @@ def unify_degrees(curves):
curves
=
[
curve
.
elevate_degree
(
target
=
max_degree
)
for
curve
in
curves
]
return
curves
def
unify_curves
(
curves
):
def
unify_curves
(
curves
,
method
=
'UNIFY'
):
curves
=
[
curve
.
reparametrize
(
0.0
,
1.0
)
for
curve
in
curves
]
dst_knots
=
defaultdict
(
int
)
for
curve
in
curves
:
m
=
sv_knotvector
.
to_multiplicity
(
curve
.
get_knotvector
())
for
u
,
count
in
m
:
u
=
round
(
u
,
6
)
dst_knots
[
u
]
=
max
(
dst_knots
[
u
],
count
)
if
method
==
'UNIFY'
:
dst_knots
=
defaultdict
(
int
)
for
curve
in
curves
:
m
=
sv_knotvector
.
to_multiplicity
(
curve
.
get_knotvector
())
for
u
,
count
in
m
:
u
=
round
(
u
,
6
)
dst_knots
[
u
]
=
max
(
dst_knots
[
u
],
count
)
result
=
[]
result
=
[]
# for i, curve1 in enumerate(curves):
# for j, curve2 in enumerate(curves):
# if i != j:
# curve1 = curve1.to_knotvector(curve2)
# result.append(curve1)
for
curve
in
curves
:
diffs
=
[]
kv
=
np
.
round
(
curve
.
get_knotvector
(),
6
)
ms
=
dict
(
sv_knotvector
.
to_multiplicity
(
kv
))
for
dst_u
,
dst_multiplicity
in
dst_knots
.
items
():
src_multiplicity
=
ms
.
get
(
dst_u
,
0
)
diff
=
dst_multiplicity
-
src_multiplicity
diffs
.
append
((
dst_u
,
diff
))
#print(f"Src {ms}, dst {dst_knots} => diff {diffs}")
for
u
,
diff
in
diffs
:
if
diff
>
0
:
curve
=
curve
.
insert_knot
(
u
,
diff
)
result
.
append
(
curve
)
return
result
for
curve
in
curves
:
diffs
=
[]
kv
=
np
.
round
(
curve
.
get_knotvector
(),
6
)
ms
=
dict
(
sv_knotvector
.
to_multiplicity
(
kv
))
for
dst_u
,
dst_multiplicity
in
dst_knots
.
items
():
src_multiplicity
=
ms
.
get
(
dst_u
,
0
)
diff
=
dst_multiplicity
-
src_multiplicity
diffs
.
append
((
dst_u
,
diff
))
#print(f"Src {ms}, dst {dst_knots} => diff {diffs}")
for
u
,
diff
in
diffs
:
if
diff
>
0
:
curve
=
curve
.
insert_knot
(
u
,
diff
)
result
.
append
(
curve
)
return
result
elif
method
==
'AVERAGE'
:
kvs
=
[
len
(
curve
.
get_control_points
())
for
curve
in
curves
]
max_kv
,
min_kv
=
max
(
kvs
),
min
(
kvs
)
if
max_kv
!=
min_kv
:
raise
Exception
(
f
"Knotvector averaging is not applicable: Curves have different number of control points:
{
kvs
}
"
)
knotvectors
=
np
.
array
([
curve
.
get_knotvector
()
for
curve
in
curves
])
knotvector_u
=
knotvectors
.
mean
(
axis
=
0
)
result
=
[
curve
.
copy
(
knotvector
=
knotvector_u
)
for
curve
in
curves
]
return
result
def
interpolate_nurbs_curve
(
cls
,
degree
,
points
,
metric
=
'DISTANCE'
,
tknots
=
None
):
n
=
len
(
points
)
...
...
utils/surface/gordon.py
Просмотр файла @
164dc659
...
...
@@ -15,32 +15,36 @@ from sverchok.utils.surface.nurbs import SvNurbsSurface, simple_loft, interpolat
from
sverchok.utils.surface.algorithms
import
unify_nurbs_surfaces
from
sverchok.data_structure
import
repeat_last_for_length
def
gordon_surface
_impl
(
u_curves
,
v_curves
,
intersections
,
metric
=
'
DISTANCE
'
):
def
gordon_surface
(
u_curves
,
v_curves
,
intersections
,
metric
=
'
POINTS
'
):
#u_curves = [c.reparametrize(0.0, 1.0) for c in u_curves]
#v_curves = [c.reparametrize(0.0, 1.0) for c in v_curves]
u_curves
=
unify_curves_degree
(
u_curves
)
u_curves
=
unify_curves
(
u_curves
)
#, method='AVERAGE')
v_curves
=
unify_curves_degree
(
v_curves
)
v_curves
=
unify_curves
(
v_curves
)
#, method='AVERAGE')
intersections
=
np
.
asarray
(
intersections
)
u_curves_degree
=
u_curves
[
0
].
get_degree
()
v_curves_degree
=
v_curves
[
0
].
get_degree
()
intersections
=
np
.
array
(
intersections
)
n
=
len
(
intersections
)
m
=
len
(
intersections
[
0
])
knots
=
np
.
array
([
Spline
.
create_knots
(
intersections
[
i
,:],
metric
=
metric
)
for
i
in
range
(
n
)])
u_knots
=
knots
.
mean
(
axis
=
0
)
knots
=
np
.
array
([
Spline
.
create_knots
(
intersections
[:,
j
],
metric
=
metric
)
for
j
in
range
(
m
)])
v_knots
=
knots
.
mean
(
axis
=
0
)
loft_v_degree
=
len
(
u_curves
)
-
1
loft_u_degree
=
len
(
v_curves
)
-
1
loft_v_degree
=
min
(
len
(
u_curves
)
-
1
,
v_curves_degree
)
loft_u_degree
=
min
(
len
(
v_curves
)
-
1
,
u_curves_degree
)
_
,
_
,
lofted_v
=
simple_loft
(
u_curves
,
degree_v
=
loft_v_degree
,
tknots
=
u_knots
)
_
,
_
,
lofted_u
=
simple_loft
(
v_curves
,
degree_v
=
loft_u_degree
,
tknots
=
v_knots
)
_
,
_
,
lofted_v
=
simple_loft
(
u_curves
,
degree_v
=
loft_v_degree
,
metric
=
metric
)
#
tknots=u_knots)
_
,
_
,
lofted_u
=
simple_loft
(
v_curves
,
degree_v
=
loft_u_degree
,
metric
=
metric
)
#
tknots=v_knots)
lofted_u
=
lofted_u
.
swap_uv
()
int_degree_u
=
m
-
1
int_degree_v
=
n
-
1
interpolated
=
interpolate_nurbs_surface
(
int_degree_u
,
int_degree_v
,
intersections
,
uknots
=
u_knots
,
vknots
=
v_knots
)
int_degree_u
=
m
in
(
m
-
1
,
u_curves_degree
)
int_degree_v
=
min
(
n
-
1
,
v_curves_degree
)
interpolated
=
interpolate_nurbs_surface
(
int_degree_u
,
int_degree_v
,
intersections
,
metric
=
metric
)
#
uknots=u_knots, vknots=v_knots)
interpolated
=
interpolated
.
swap_uv
()
#print(f"Loft.U: {lofted_u}")
#print(f"Loft.V: {lofted_v}")
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать