赞
踩
def main():
# setup sphere
sphereSource = vtk.vtkSphereSource()
sphereSource.Update()
polydata = vtk.vtkPolyData()
#print(sphereSource.GetOutput())
polydata.ShallowCopy(sphereSource.GetOutput())
normals = polydata.GetPointData().GetNormals()
normal0 = normals.GetTuple3(3)
print("Normal0: {:3.1f} {:3.1f} {:3.1f}".format(normal0[0], normal0[1], normal0[2]))
print(normal0)
output
Normal0: 0.8 0.0 0.6
(0.7818315029144287, 0.0, 0.6234897971153259)
保存文件:”Test.vtp”
vtkxmlpolydatawriter()用来写入VTK XML polydata 格式的文件。
vtkcellarray()支持的列表结构形式:(n,id1,id2,…,idn, n,id1,id2,…,idn, …)其中n是在结构中点的数目,ID为偏移相关点列表。
读取文件:”Test.vtp”
#include <vtkXMLPolyDataReader.h> #include <vtkSmartPointer.h> #include <vtkPolyDataMapper.h> #include <vtkActor.h> #include <vtkRenderWindow.h> #include <vtkRenderer.h> #include <vtkRenderWindowInteractor.h> int main() { std::string filename = "cow.vtp"; vtkSmartPointer<vtkXMLPolyDataReader> reader = vtkSmartPointer<vtkXMLPolyDataReader>::New(); reader->SetFileName(filename.c_str()); reader->Update(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputConnection(reader->GetOutputPort()); vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New(); actor->SetMapper(mapper); vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New(); renderWindow->AddRenderer(renderer); vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); renderWindowInteractor->SetRenderWindow(renderWindow); renderer->AddActor(actor); renderer->SetBackground(.3, .6, .3); renderWindow->Render(); renderWindowInteractor->Start(); return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。