简体   繁体   English

将大量点写入vtk文件格式

[英]writing huge number of points to vtk file format

I'm writing script in python which is parsing about 500 images (slices of 3d object) of width 1810px and height 1808px. 我正在用python编写脚本,该脚本正在解析约500张宽度为1810px且高度为1808px的图像(3d对象的切片)。 I want to write points (with original color) from all these images and save them to vtk file format. 我想从所有这些图像中写入点(使用原始颜色)并将其保存为vtk文件格式。 For test purposes i've modified example from vtk: 为了测试目的,我从vtk修改了示例:

import vtk
from vtk import *

#setup points and vertices
Points = vtk.vtkPoints()
Vertices = vtk.vtkCellArray()

for x in xrange(0, 1808):
    for y in xrange(0, 1810):
        for z in xrange(0, 544):
            id = Points.InsertNextPoint(x, y, z)
            Vertices.InsertNextCell(1)
            Vertices.InsertCellPoint(id)


polydata = vtk.vtkPolyData()
polydata.SetPoints(Points)
polydata.SetVerts(Vertices)
polydata.Modified()
if vtk.VTK_MAJOR_VERSION <= 5:
    polydata.Update()

writer = vtk.vtkXMLPolyDataWriter()
writer.SetFileName("TriangleColoredPoints.vtp")
if vtk.VTK_MAJOR_VERSION <= 5:
    writer.SetInput(polydata)
else:
    writer.SetInputData(polydata)
writer.Write()

For now it's not even reading an image, but the problem is that when i add all these points, i'm going out of memory. 现在它甚至都没有读取图像,但是问题是当我添加所有这些点时,我的内存不足了。 Is there any way to save these points in chunks? 有什么办法可以将这些点保存为块吗?

Looks like you're attempting to write a polydata with 1800x1800x500 points approx (about 1.6 billion points). 看起来您正在尝试以大约1800x1800x500点(约16亿点)的大小写一个多数据。 Millions may be possible, but not billions, not yet anyway. 数以百万计的可能是有可能的,但数十亿美元是不可能的,无论如何还没有。 Looks like you will need to reduce your problem size. 看起来您将需要减少问题的大小。 If you do reduce the problem size, then use the vtkXMLPolyDataWriter. 如果确实减小了问题的大小,请使用vtkXMLPolyDataWriter。 It has 它有

writer->SetDataModeToBinary();
writer->SetCompressorTypeToZLib();

Which are useful in writing large models to a filesystem compactly. 这对于将大型模型紧凑地写入文件系统很有用。

Alternatively, you can store the images as a singe volume (1800x1800x500, vtkImageData) as the above comment mentions, there will be very large memory use still though. 或者,您可以将图像存储为上述注释中提到的单个卷(1800x1800x500,vtkImageData),但是仍然会占用非常大的内存。 Then you can do volume rendering or marching cubes to get a surface etc. But without more detail is to what you're trying to achieve, its difficult to answer any further. 然后,您可以进行体绘制或行进立方体以获取曲面等。但是,如果没有更多详细信息,您将尝试实现目标,那么就很难再回答了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM