我寫了一個相當笨拙的python程式,它建立了一個特定幾何體的單元單元,并對其進行了複制,這樣我就得到了一個3x3x3的單元單元單元數組。結果儲存為.stl。目标是直接建立這些結構,而不是使用CAD。在
我的問題是計算時間很煩人(8x8x8x8需要大約2分鐘,這比我通常需要的要小)。最大的問題是,10x10x10甚至不可能。VTK立即抛出一個錯誤“無法配置設定[large number]個大小為8位元組的元素”。這使我認為我的記憶體管理不足(不存在)。在
我讀到了關于{{CD1>},但似乎隻能找到C++的解釋。如何在python中正确使用vtkSmartPointer?我應該補充說,我對C++沒有任何經驗。在
由于程式的大小,MWE是不可能的。以下是我的算法管道的一個簡短示例:import vtk
appendFilter = vtk.vtkAppendPolyData()
# create all 12 struts and combine them into one object
for i in range(1, 13, 1):
tf = create_strut(i, node_dist, amp, d, sides, mode, render=False) # method that creates my unit cell out of 12 struts, parameters are irrelevant
appendFilter.AddInputData(tf.GetOutput())
appendFilter.Update()
# clean up poly data
cleanFilter = vtk.vtkCleanPolyData()
cleanFilter.SetInputConnection(appendFilter.GetOutputPort())
cleanFilter.Update()
# cut the cell to its right size
planes = plane_collection(node_dist) # method that generates 6 planes
clip = vtk.vtkClipClosedSurface()
clip.SetInputData(cleanFilter.GetOutput())
clip.SetClippingPlanes(planes)
clip.Update()
# assemble an array from the unit cell
array = duplicate_cells(clip, xyz[0], xyz[1], xyz[2], node_dist)
# save as .stl
data = array.GetOutputPort()
stlwriter = vtk.vtkSTLWriter()
stlwriter.SetInputConnection(data)
stlwriter.SetFileName("Z:/example.stl")
stlwriter.Update()
stlwriter.Write()
這應該說明我使用了很多過濾器,從不關心删除它們或任何東西。清理記憶的正确/首選方法是什麼?在