[vtkusers] How to change the points in a polydata

舞法舞天 278124177 at qq.com
Sat Jul 14 02:40:28 EDT 2018


Hello.       I read a ply file and want to change its' points' postion, but the code below doesn't work , how can i do?
      vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
	reader->SetFileName("d:\\plane.ply");
	reader->Update();
	vtkPolyData* data = reader->GetOutput();
	int n = data->GetNumberOfPoints();
	vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
	points->DeepCopy(data->GetPoints());
	for (int i = 0; i < n; i++)
	{
		double *p = points->GetPoint(i);
		p[2] = 0;
	}

       vtkSmartPointer<vtkSimplePointsWriter>writer = vtkSmartPointer<vtkSimplePointsWriter>::New();
	writer->SetInputData(data);
	writer->SetFileName("d:\\abc.txt");
	writer->Update();
	vtkSmartPointer<vtkPolyDataMapper> mapper =
		vtkSmartPointer<vtkPolyDataMapper>::New();
	mapper->SetInputData(data);
	mapper->Update();
	vtkSmartPointer<vtkActor> actor =
		vtkSmartPointer<vtkActor>::New();
	actor->SetMapper(mapper);
	//actor->GetProperty()->SetRepresentationToWireframe();
	vtkSmartPointer<vtkRenderer> renderer =
		vtkSmartPointer<vtkRenderer>::New();
	renderer->AddActor(actor);
	vtkSmartPointer<vtkRenderWindow> window =
		vtkSmartPointer<vtkRenderWindow>::New();
	window->AddRenderer(renderer);
	vtkSmartPointer<vtkRenderWindowInteractor> interactor =
		vtkSmartPointer<vtkRenderWindowInteractor>::New();
	interactor->SetRenderWindow(window);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180714/e409492d/attachment.html>


More information about the vtkusers mailing list