0

nifti ラベル セットで vtkMarchingCubes を実行したいと考えています。サーフェスを生成したいボクセルの領域はすべて同じ値を共有します。2 つの問題があります。まず、結果の vtkPolyData には明らかに頂点がないため、アルゴリズムを正しく設定していないようです。次に、vtkOBJExporter のドキュメントから、vtkPolyData を wavefront .OBJ ファイルとしてエクスポートする方法がわかりません。以下のコードに問題がある場合、または vtkPolyData を OBJ としてエクスポートする方法を教えていただける場合は、よろしくお願いします。

//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();
4

1 に答える 1

0

このクラスhttps://github.com/daviddoria/vtkOBJWriterを使用して、(他のすべての VTK ライターと同様に) 期待どおりに obj ファイルを書き込むことができます。残念ながら、vtkOBJExporter は、私が持っていない追加情報も書き込もうとしています。

于 2012-11-14T00:46:22.833 に答える