[vtkusers] Why is my marching cubes result not a surface but some strange sticks?

Summer Sun sunxiasx at foxmail.com
Thu Mar 30 06:49:17 EDT 2017


I read a dozen of bmp slices and try to use marching cubes to generate iso
surface.
But the result is some strange sticks like below.
<http://vtk.1045678.n5.nabble.com/file/n5742673/mc_result_1.png> 

the image slices is as follow
<http://vtk.1045678.n5.nabble.com/file/n5742673/slices_info.png> 


My code is here, I think there's no problem with my image data:
string segResultDir = ".\\images\\seg_result";

DIR *dir;
struct dirent *ent;
vtkSmartPointer<vtkImageAppend> appender =
vtkSmartPointer<vtkImageAppend>::New();
appender->SetAppendAxis(2);
vtkSmartPointer<vtkImageData> segModel =
vtkSmartPointer<vtkImageData>::New();
if ((dir = opendir(segResultDir.c_str())) != NULL) {
	// get all file under seg result directory
	while ((ent = readdir(dir)) != NULL) {
		string imageFileName = ent->d_name;
		// filter for file extension with .bmp
		if (imageFileName.substr(imageFileName.find_last_of(".") + 1) == "bmp") {
			//read the image
			vtkSmartPointer<vtkBMPReader> reader =
				vtkSmartPointer<vtkBMPReader>::New();
			reader->SetFileName((segResultDir + "\\" + imageFileName).c_str());
			reader->Update();
			appender->AddInputData(reader->GetOutput());
			appender->Update();
			/*vtkSmartPointer<vtkImageData> segSlice = reader->GetOutput();
		
segModel->GetPointData()->AddArray(segSlice->GetPointData()->GetScalars());*/
		}
	}
	closedir(dir);
}
segModel->DeepCopy(appender->GetOutput());

// marching cubes and render results
vtkSmartPointer<vtkMarchingCubes> surface =
	vtkSmartPointer<vtkMarchingCubes>::New();

surface->SetInputData(segModel);
surface->ComputeNormalsOn();
surface->SetValue(0, 0.5);
surface->Update();

vtkSmartPointer<vtkRenderer> modelRenderer =
	vtkSmartPointer<vtkRenderer>::New();
modelRenderer->SetBackground(.1, .2, .3);

vtkSmartPointer<vtkRenderWindow> modelRenderWindow =
	vtkSmartPointer<vtkRenderWindow>::New();
modelRenderWindow->AddRenderer(modelRenderer);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
	vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(modelRenderWindow);

vtkSmartPointer<vtkPolyDataMapper> mapper =
	vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(surface->GetOutputPort());
mapper->ScalarVisibilityOff();

vtkSmartPointer<vtkActor> actor =
	vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

modelRenderer->AddActor(actor);

modelRenderWindow->Render();
interactor->Start();

Thank you for your help!




--
View this message in context: http://vtk.1045678.n5.nabble.com/Why-is-my-marching-cubes-result-not-a-surface-but-some-strange-sticks-tp5742673.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list