Quantcast

Generating mesh with VTK marching cubes

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

Generating mesh with VTK marching cubes

mozendi
Dear VTK users,

I am trying to generate triangular mesh from point clouds obtained by Terrestrial Laser Scanners. I use marching cubes algorithm of VTK library. When I visualize the generated mesh it seems as a thick surface as shown in the image below:



However, I was expecting to see it as the figure shown below:



Could you please help me about this problem? I want to generate meshes as shown in the second figure.
I am looking forward to hearing from you

By the way my code is:

int main(int argc, char* argv[])
{
        vtkSmartPointer<vtkSimplePointsReader> reader = vtkSmartPointer<vtkSimplePointsReader>::New();
        reader->SetFileName("SIL_ARKA_ENTIRE.xyz");
        reader->Update();
        vtkPolyData* polydata = reader->GetOutput();

        double isoValue;
        double bounds[6];
        polydata->GetBounds(bounds);
        for (unsigned int i = 0; i < 6; i += 2)
        {
                double range = bounds[i + 1] - bounds[i];
                bounds[i] = bounds[i] - .1 * range;
                bounds[i + 1] = bounds[i + 1] + .1 * range;
        }
        vtkSmartPointer<vtkImageData> volume = vtkSmartPointer<vtkImageData>::New();
        vtkSmartPointer<vtkVoxelModeller> voxelModeller = vtkSmartPointer<vtkVoxelModeller>::New();
        voxelModeller->SetSampleDimensions(50, 50, 50);
        voxelModeller->SetModelBounds(bounds);
        voxelModeller->SetScalarTypeToFloat();
        voxelModeller->SetMaximumDistance(.1);
        voxelModeller->SetInputConnection(reader->GetOutputPort());
        voxelModeller->Update();
        isoValue = 0.0001;
        volume->DeepCopy(voxelModeller->GetOutput());
        vtkSmartPointer<vtkMarchingCubes> surface = vtkSmartPointer<vtkMarchingCubes>::New();
#if VTK_MAJOR_VERSION <= 5
        surface->SetInput(volume);
#else
        surface->SetInputData(volume);
#endif
        surface->ComputeNormalsOn();
        surface->SetValue(0, isoValue);
        vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
        renderer->SetBackground(.1, .2, .3);
        vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
        renderWindow->AddRenderer(renderer);
        vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
        interactor->SetRenderWindow(renderWindow);
        vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
        mapper->SetInputConnection(surface->GetOutputPort());
        mapper->ScalarVisibilityOff();

        std::string filename = "VTK_mesh_deneme.ply";
        vtkSmartPointer<vtkPLYWriter> plyWriter = vtkSmartPointer<vtkPLYWriter>::New();
        plyWriter->SetInputConnection(surface->GetOutputPort());
        plyWriter->SetFileName(filename.c_str());
        plyWriter->Write();

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

        renderer->AddActor(actor);

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

        return EXIT_SUCCESS;
}
Loading...