使用 geomdl 3D 进行 NURBS/B 样条可视化不起作用(显示空图像)

问题描述 投票:0回答:2

我需要为项目创建 NURBS 曲面。为此我想使用 geomdl 包。我通过 conda 安装了它,并使用here给出的示例进行了尝试。它适用于 2d 示例,但不适用于 3d 示例。 这是 B 样条曲线的代码:

from geomdl import BSpline
from geomdl import utilities
from geomdl.visualization import VisMPL

ctrlpts = [[5.0, 5.0, 0.0], [5.0, 10.0, 0.0], [10.0, 10.0, 5.0], [10.0, 5.0, 5.0], [5.0, 5.0, 5.0], [5.0, 10.0, 10.0], [10.0, 10.0, 10.0], [10.0, 5.0, 10.0], [5.0, 5.0, 15.0], [5.0, 10.0, 15.0], [10.0, 10.0, 15.0], [10.0, 5.0, 20.0], [5.0, 5.0, 20.0]]

# Create a B-Spline curve instance
curve = BSpline.Curve()

# Set up curve
curve.degree = 3
curve.ctrlpts = ctrlpts

# Auto-generate knot vector
curve.knotvector = utilities.generate_knot_vector(curve.degree, curve.ctrlpts_size)

# Set evaluation delta
curve.delta = 0.01

# Plot the control point polygon and the evaluated curve
curve.vis = VisMPL.VisCurve3D()
curve.render()

The visual outcome looks like this: 没有轴,没有坐标,即使我告诉 curve.render 函数显示它们。 我还尝试删除 geomdl 并重新安装它。没有成功。

It should look like this

python spline nurbs
2个回答
0
投票

只需使用VisVTK模块代替VisMPL;它会正常工作,无需单独安装;它是“geomdl”包的一部分。

这是修改后的代码:

from geomdl import BSpline
from geomdl import utilities
from geomdl.visualization import VisVTK

ctrlpts = [[5.0, 5.0, 0.0], [5.0, 10.0, 0.0], [10.0, 10.0, 5.0], [10.0, 
5.0, 5.0], [5.0, 5.0, 5.0], [5.0, 10.0, 10.0], [10.0, 10.0, 10.0], [10.0, 
5.0, 10.0], [5.0, 5.0, 15.0], [5.0, 10.0, 15.0], [10.0, 10.0, 15.0], [10.0, 
5.0, 20.0], [5.0, 5.0, 20.0]]

# Create a B-Spline curve instance
curve = BSpline.Curve()

# Set up curve
curve.degree = 3
curve.ctrlpts = ctrlpts

# Auto-generate knot vector
curve.knotvector = utilities.generate_knot_vector(curve.degree, 
curve.ctrlpts_size)

# Set evaluation delta
curve.delta = 0.01

# Plot the control point polygon and the evaluated curve
curve.vis = VisVTK.VisCurve3D()
curve.render()


0
投票

我修复了它,用于曲面绘图,替换 VisMPL.py 的第 430 行

# Start plotting of the surface and the control points grid
fig = plt.figure(figsize=self.vconf.figure_size, dpi=self.vconf.figure_dpi)
ax = Axes3D(fig)

与:

# Start plotting of the surface and the control points grid
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})

我没有检查漏洞代码,也许你也需要在其他地方替换它。请注意,这些设置现在不再起作用。但这肯定可以解决。

© www.soinside.com 2019 - 2024. All rights reserved.