首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >vtkMarchingCubes将nifti曲面导出为wavefront OBJ

vtkMarchingCubes将nifti曲面导出为wavefront OBJ
EN

Stack Overflow用户
提问于 2012-09-28 03:33:19
回答 1查看 1.3K关注 0票数 0

我想在nifti标签集上运行vtkMarchingCubes。我想为其生成曲面的体素区域共享相同的值。我有两个问题。首先,我似乎错误地设置了算法,因为生成的vtkPolyData显然没有顶点。其次,在vtkOBJExporter文档中,我不清楚如何将vtkPolyData导出为wavefront .OBJ文件。如果有人发现下面的代码有任何问题,或者可以告诉我如何将vtkPolyData导出为OBJ,我将不胜感激。

代码语言:javascript
复制
//Read The Nifti Label File
string input_path = "/MyPath/labels.nii";
nifti_image *im = nifti_image_read(input_path.c_str(),true);
cout<<im->nx<<","<<im->ny<<","<<im->nz<<endl; //Confirms Read Works

// Set up vtk image data
vtkImageImport* importer = vtkImageImport::New();
importer->SetImportVoidPointer((void*)im->data);
importer->SetDataScalarTypeToFloat();
importer->SetDataExtent(0, im->nx-1, 0, im->ny-1, 0, im->nz-1);
importer->SetWholeExtent(0, im->nx-1, 0, im->ny-1, 0, im->nz-1);
vtkImageData* point_cloud = importer->GetOutput();
point_cloud->SetScalarTypeToFloat();
point_cloud->SetExtent(0, im->nx-1, 0, im->ny-1, 0, im->nz-1);
point_cloud->SetSpacing(im->dx, im->dy, im->dz);

//Apply Threshold To Cut Out Other Data 
//Is this needed or will Marching Cubes properly identify the region
vtkImageThreshold* threshold = vtkImageThreshold::New();
threshold->ThresholdBetween(label_number,label_number);
threshold->SetInValue(255);
threshold->SetOutValue(0);
threshold->SetInput(point_cloud);

//Apply the Marching Cubes algorithm
vtkMarchingCubes* marching_cubes = vtkMarchingCubes::New();
marching_cubes->SetValue(0, 127.0f);
marching_cubes->SetInput(threshold->GetOutput()); //(vtkDataObject*)point_cloud);

vtkPolyData* surface = marching_cubes->GetOutput();
marching_cubes->Update(); 

//See That Marching Cubes Worked
cout<<"# Vertices: "<< surface->GetNumberOfVerts()<<endl;
cout<<"# Cells: "<< surface->GetNumberOfCells()<<endl;


//Export (How is this done properly?)
vtkOBJExporter* exporter = vtkOBJExporter::New();
exporter->SetInput(vtkRenderWindow *renWin); //I don't want a render window, I want at file
exporter->SetFilePrefix("/MyPath/surface");
exporter->Write();
EN

回答 1

Stack Overflow用户

发布于 2012-11-14 08:46:23

您可以使用此类https://github.com/daviddoria/vtkOBJWriter以您期望的方式编写obj文件(就像其他所有VTK编写器一样)。不幸的是,vtkOBJExporter还想写入我从未拥有过的附加信息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12628786

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档