[vtkusers] Generating mesh with VTK marching cubes

mozendi mozendi at gmail.com
Fri Apr 28 08:44:51 EDT 2017


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:

<http://vtk.1045678.n5.nabble.com/file/n5743010/mesh_from_top_1.png> 

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

<http://vtk.1045678.n5.nabble.com/file/n5743010/mesh_from_top_gmc.png> 

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;
}




--
View this message in context: http://vtk.1045678.n5.nabble.com/Generating-mesh-with-VTK-marching-cubes-tp5743010.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list