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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Summer Sun
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.


the image slices is as follow



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!
Loading...