Открыть боковую панель
nikitronn
sverchok
Коммиты
058665de
Коммит
058665de
создал
Июн 26, 2021
по автору
Ilya Portnov
Просмотр файлов
Some debug.
владелец
263db215
Изменения
2
Скрыть пробелы
Построчно
Рядом
utils/surface/algorithms.py
Просмотр файла @
058665de
...
...
@@ -1073,7 +1073,7 @@ def nurbs_revolution_surface(curve, origin, axis, v_min=0, v_max=2*pi, global_or
curve
.
get_knotvector
(),
circle_knotvector
,
control_points
,
weights
)
def
unify_nurbs_surfaces
(
surfaces
):
def
unify_nurbs_surfaces
(
surfaces
,
knots_method
=
'UNIFY'
):
# Unify surface degrees
degrees_u
=
[
surface
.
get_degree_u
()
for
surface
in
surfaces
]
...
...
@@ -1088,47 +1088,78 @@ def unify_nurbs_surfaces(surfaces):
# Unify surface knotvectors
dst_knots_u
=
defaultdict
(
int
)
dst_knots_v
=
defaultdict
(
int
)
for
surface
in
surfaces
:
m_u
=
sv_knotvector
.
to_multiplicity
(
surface
.
get_knotvector_u
())
m_v
=
sv_knotvector
.
to_multiplicity
(
surface
.
get_knotvector_v
())
for
u
,
count
in
m_u
:
u
=
round
(
u
,
6
)
dst_knots_u
[
u
]
=
max
(
dst_knots_u
[
u
],
count
)
for
v
,
count
in
m_v
:
v
=
round
(
v
,
6
)
dst_knots_v
[
v
]
=
max
(
dst_knots_v
[
v
],
count
)
result
=
[]
for
surface
in
surfaces
:
diffs_u
=
[]
kv_u
=
np
.
round
(
surface
.
get_knotvector_u
(),
6
)
ms_u
=
dict
(
sv_knotvector
.
to_multiplicity
(
kv_u
))
for
dst_u
,
dst_multiplicity
in
dst_knots_u
.
items
():
src_multiplicity
=
ms_u
.
get
(
dst_u
,
0
)
diff
=
dst_multiplicity
-
src_multiplicity
diffs_u
.
append
((
dst_u
,
diff
))
for
u
,
diff
in
diffs_u
:
if
diff
>
0
:
surface
=
surface
.
insert_knot
(
SvNurbsSurface
.
U
,
u
,
diff
)
diffs_v
=
[]
kv_v
=
np
.
round
(
surface
.
get_knotvector_v
(),
6
)
ms_v
=
dict
(
sv_knotvector
.
to_multiplicity
(
kv_v
))
for
dst_v
,
dst_multiplicity
in
dst_knots_v
.
items
():
src_multiplicity
=
ms_v
.
get
(
dst_v
,
0
)
diff
=
dst_multiplicity
-
src_multiplicity
diffs_v
.
append
((
dst_v
,
diff
))
for
v
,
diff
in
diffs_v
:
if
diff
>
0
:
surface
=
surface
.
insert_knot
(
SvNurbsSurface
.
V
,
v
,
diff
)
result
.
append
(
surface
)
return
result
if
knots_method
==
'UNIFY'
:
dst_knots_u
=
defaultdict
(
int
)
dst_knots_v
=
defaultdict
(
int
)
for
surface
in
surfaces
:
m_u
=
sv_knotvector
.
to_multiplicity
(
surface
.
get_knotvector_u
())
m_v
=
sv_knotvector
.
to_multiplicity
(
surface
.
get_knotvector_v
())
for
u
,
count
in
m_u
:
u
=
round
(
u
,
6
)
dst_knots_u
[
u
]
=
max
(
dst_knots_u
[
u
],
count
)
for
v
,
count
in
m_v
:
v
=
round
(
v
,
6
)
dst_knots_v
[
v
]
=
max
(
dst_knots_v
[
v
],
count
)
result
=
[]
for
surface
in
surfaces
:
diffs_u
=
[]
kv_u
=
np
.
round
(
surface
.
get_knotvector_u
(),
6
)
ms_u
=
dict
(
sv_knotvector
.
to_multiplicity
(
kv_u
))
for
dst_u
,
dst_multiplicity
in
dst_knots_u
.
items
():
src_multiplicity
=
ms_u
.
get
(
dst_u
,
0
)
diff
=
dst_multiplicity
-
src_multiplicity
diffs_u
.
append
((
dst_u
,
diff
))
for
u
,
diff
in
diffs_u
:
if
diff
>
0
:
surface
=
surface
.
insert_knot
(
SvNurbsSurface
.
U
,
u
,
diff
)
diffs_v
=
[]
kv_v
=
np
.
round
(
surface
.
get_knotvector_v
(),
6
)
ms_v
=
dict
(
sv_knotvector
.
to_multiplicity
(
kv_v
))
for
dst_v
,
dst_multiplicity
in
dst_knots_v
.
items
():
src_multiplicity
=
ms_v
.
get
(
dst_v
,
0
)
diff
=
dst_multiplicity
-
src_multiplicity
diffs_v
.
append
((
dst_v
,
diff
))
for
v
,
diff
in
diffs_v
:
if
diff
>
0
:
surface
=
surface
.
insert_knot
(
SvNurbsSurface
.
V
,
v
,
diff
)
result
.
append
(
surface
)
return
result
elif
knots_method
==
'AVERAGE'
:
kvs
=
[
len
(
surface
.
get_control_points
())
for
surface
in
surfaces
]
max_kv
,
min_kv
=
max
(
kvs
),
min
(
kvs
)
if
max_kv
!=
min_kv
:
raise
Exception
(
f
"U knotvector averaging is not applicable: Surfaces have different number of control points:
{
kvs
}
"
)
kvs
=
[
len
(
surface
.
get_control_points
()[
0
])
for
surface
in
surfaces
]
max_kv
,
min_kv
=
max
(
kvs
),
min
(
kvs
)
if
max_kv
!=
min_kv
:
raise
Exception
(
f
"V knotvector averaging is not applicable: Surfaces have different number of control points:
{
kvs
}
"
)
knotvectors
=
np
.
array
([
surface
.
get_knotvector_u
()
for
surface
in
surfaces
])
knotvector_u
=
knotvectors
.
mean
(
axis
=
0
)
knotvectors
=
np
.
array
([
surface
.
get_knotvector_v
()
for
surface
in
surfaces
])
knotvector_u
=
knotvectors
.
mean
(
axis
=
0
)
result
=
[]
for
surface
in
surfaces
:
surface
=
SvNurbsSurface
.
build
(
surface
.
get_nurbs_implementation
(),
surface
.
get_degree_u
(),
surface
.
get_degree_v
(),
knotvector_u
,
knotvector_v
,
surface
.
get_control_points
(),
surface
.
get_weights
())
result
.
append
(
surface
)
return
result
else
:
raise
Exception
(
'Unsupported knotvector unification method'
)
utils/surface/gordon.py
Просмотр файла @
058665de
...
...
@@ -15,12 +15,7 @@ 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
,
degree_u
=
None
,
degree_v
=
None
,
metric
=
'DISTANCE'
):
if
degree_u
is
None
:
degree_u
=
u_curves
[
0
].
get_degree
()
if
degree_v
is
None
:
degree_v
=
v_curves
[
0
].
get_degree
()
def
gordon_surface_impl
(
u_curves
,
v_curves
,
intersections
,
metric
=
'DISTANCE'
):
#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]
...
...
@@ -36,25 +31,22 @@ def gordon_surface_impl(u_curves, v_curves, intersections, degree_u=None, degree
knots
=
np
.
array
([
Spline
.
create_knots
(
intersections
[:,
j
],
metric
=
metric
)
for
j
in
range
(
m
)])
v_knots
=
knots
.
mean
(
axis
=
0
)
_
,
_
,
lofted_v
=
simple_loft
(
u_curves
,
degree_v
=
degree_u
,
tknots
=
u_knots
)
_
,
_
,
lofted_u
=
simple_loft
(
v_curves
,
degree_v
=
degree_v
,
tknots
=
v_knots
)
loft_v_degree
=
len
(
u_curves
)
-
1
loft_u_degree
=
len
(
v_curves
)
-
1
_
,
_
,
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_u
=
lofted_u
.
swap_uv
()
# int_degree_u = lofted_u.get_degree_v()
# int_degree_v = lofted_v.get_degree_u()
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
)
interpolated
=
interpolated
.
swap_uv
()
print
(
f
"Loft.U:
{
lofted_u
.
get_degree_u
()
}
x
{
lofted_u
.
get_degree_v
()
}
"
)
print
(
f
"
{
lofted_u
.
get_knotvector_u
()
}
"
)
print
(
f
"
{
lofted_u
.
get_knotvector_v
()
}
"
)
print
(
f
"Loft.V:
{
lofted_v
.
get_degree_u
()
}
x
{
lofted_v
.
get_degree_v
()
}
"
)
print
(
f
"
{
lofted_v
.
get_knotvector_u
()
}
"
)
print
(
f
"
{
lofted_v
.
get_knotvector_v
()
}
"
)
print
(
f
"Interp:
{
interpolated
.
get_degree_u
()
}
x
{
interpolated
.
get_degree_v
()
}
"
)
print
(
f
"
{
interpolated
.
get_knotvector_u
()
}
"
)
print
(
f
"
{
interpolated
.
get_knotvector_v
()
}
"
)
#print(f"Loft.U: {lofted_u}")
#print(f"Loft.V: {lofted_v}")
#print(f"Interp: {interpolated}")
#print(f" {interpolated.get_knotvector_u()}")
#print(f" {interpolated.get_knotvector_v()}")
lofted_u
,
lofted_v
,
interpolated
=
unify_nurbs_surfaces
([
lofted_u
,
lofted_v
,
interpolated
])
...
...
@@ -66,5 +58,6 @@ def gordon_surface_impl(u_curves, v_curves, intersections, degree_u=None, degree
interpolated
.
get_degree_u
(),
interpolated
.
get_degree_v
(),
interpolated
.
get_knotvector_u
(),
interpolated
.
get_knotvector_v
(),
control_points
,
weights
=
None
)
#print(f"Result: {surface}")
return
lofted_u
,
lofted_v
,
interpolated
,
surface
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать