2012-09-27 46 views
0

我想在nifti標籤集上運行vtkMarchingCubes。我想要生成曲面的體素區域都具有相同的值。我有兩個問題。首先,我似乎錯誤地設置了算法,因爲生成的vtkPolyData顯然沒有頂點。其次,從vtkOBJExporter文檔中我不清楚如何將vtkPolyData導出爲波前.OBJ文件。如果任何人看到下面的代碼的任何問題,或者可以告訴我如何將vtkPolyData作爲OBJ導出,我將不勝感激。vtkMarchingCubes將nifti曲面導出到波前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(); 

回答