[vtkusers] Output lost in vtkPolyDataToPolyDataFilter !

Klaus Kesseler klaus.kesseler at rwth-aachen.de
Mon Nov 1 10:42:17 EST 2004


Hi Mailinglist,

i'm new to vtk and i have to questions:

----------------------------------------------------

1.)

I want to use the vtkDecimatePro class to reduce some meshes, but the 
problems i describe seem to happen with all childs of 
'vtkPolyDataToPolyDataFilter'.
The filter, used like in the following code seems to work if i use it in 
the built in vtk renderer. But if i try to export the (triangle) data, 
vtk tells me that after filtering my vtkPolyData Object (polydata) is empty:


this is the code fragment, where it happens:

	cout << polydata->GetNumberOfCells(); // e.g. == 4

	vtkDecimatePro * filter = vtkDecimatePro::New();
	filter->SetInput(polydata);
	filter->SetMaximumError(0);
	filter->SetTargetReduction(1);
	polydata = (vtkPolyData*) filter->GetOutput();

	cout << polydata->GetNumberOfCells(); // alway == 0;


------------------------------------------------------

2.) What is the easiest and most efficient way, to export the (triangle) 
mesh data out of a vtkPolyData Object, say in vertex based form:

vector<float*> vertices, list<int*> triangles ?


Thanks a lot,
Klaus
------------------------------------------------------


this is the (nearly) whole program file:






	int i;

	vtkFloatArray* pcoords = vtkFloatArray::New();

	pcoords->SetNumberOfComponents(3);
	pcoords->SetNumberOfTuples(6);
	float pts[6][3] = {	{0.0, 0.0, 0.0}, {0.0, 1.0, 0.0},
						{1.0, 0.0, 0.0}, {1.0, 1.0, 0.0},
						{2.0, 0.0, 0.0}, {2.0, 1.0, 0.0} };
	
	for (i=0; i<6; i++) { pcoords->SetTuple(i, pts[i]);	}

	vtkPoints* points = vtkPoints::New();
	points->SetData(pcoords);

	// Create the dataset. In this case, we create a vtkPolyData
	vtkPolyData* polydata = vtkPolyData::New();
	// Assign points and cells
	polydata->SetPoints(points);
	//polydata->SetPolys(strips);

	vtkTriangle *triangle;
	vtkCellArray*  tris = vtkCellArray::New();

	triangle=vtkTriangle::New();
	triangle->GetPointIds()->SetId(0,0);
	triangle->GetPointIds()->SetId(1,2);
	triangle->GetPointIds()->SetId(2,1);
	tris->InsertNextCell(triangle);
	triangle->Delete();


	 triangle=vtkTriangle::New();
	triangle->GetPointIds()->SetId(0,2);
	triangle->GetPointIds()->SetId(1,3);
	triangle->GetPointIds()->SetId(2,1);
	tris->InsertNextCell(triangle);
	triangle->Delete();


	triangle=vtkTriangle::New();
	triangle->GetPointIds()->SetId(0,2);
	triangle->GetPointIds()->SetId(1,4);
	triangle->GetPointIds()->SetId(2,3);
	tris->InsertNextCell(triangle);
	triangle->Delete();


	triangle=vtkTriangle::New();
	triangle->GetPointIds()->SetId(0,4);
	triangle->GetPointIds()->SetId(1,5);
	triangle->GetPointIds()->SetId(2,3);
	tris->InsertNextCell(triangle);
	triangle->Delete();

	polydata->SetPolys(tris);




	cout << polydata->GetNumberOfCells();

	vtkDecimatePro * filter = vtkDecimatePro::New();
	filter->SetInput(polydata);
	filter->SetMaximumError(0);
	filter->SetTargetReduction(1);
	polydata = (vtkPolyData*) filter->GetOutput();

	cout << polydata->GetNumberOfCells();


	// Create the mapper and set the appropriate scalar range
	// (default is (0,1)
	vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
	mapper->SetInput(polydata);
	mapper->SetScalarRange(0, 40);

	// Create an actor.
	vtkActor* actor = vtkActor::New();
	actor->SetMapper(mapper);

	actor->GetProperty()->SetRepresentationToWireframe ();



	// Create the rendering objects.
	vtkRenderer* ren = vtkRenderer::New();
	ren->AddActor(actor);


	vtkRenderWindow* renWin = vtkRenderWindow::New();
	renWin->AddRenderer(ren);

	vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
	iren->SetRenderWindow(renWin);
	iren->Initialize();
	iren->Start();




More information about the vtkusers mailing list