使用vtkPlaneSource创建一个vtkpolydata网格平面

网上说vtkPlaneSource不能创建网格平面,试了一下其实可以,写的比较糙,创建一个10*10的平面网格

void main() {


	//!!!!!!!!!!!!!!!!!!vtkPlaneSource创建一个网格平面然后往里面加点!!!!!!!!!!!!!!!!!!!!!!//
	vtkSmartPointer points = vtkSmartPointer::New();
	vtkSmartPointer cells = vtkSmartPointer::New();
	vtkSmartPointer polydata = vtkSmartPointer::New();
	vtkSmartPointer mapper = vtkSmartPointer::New();
	vtkSmartPointer writer = vtkSmartPointer::New();

	vtkSmartPointerplaneSource = vtkSmartPointer::New();
	//传统方式确定一个平面
	double Origin[3] = { -0.5, -0.5, 0};
	double Point1[3] = { 0.5, -0.5, 0 };
	double Point2[3] = { -0.5, 0.5, 0 };
	planeSource->SetOrigin(Origin);
	planeSource->SetPoint1(Point1);
	planeSource->SetPoint2(Point2);
	
	//点法法确定一个平面
	planeSource->SetCenter(0, 0, 0);//点
	planeSource->SetNormal(0, 0, 1);//法
	//planeSource->SetResolution();
	planeSource->SetXResolution(10);//x方向分割数
	planeSource->SetYResolution(10);//y方向分割数
	planeSource->Update();
	polydata = planeSource->GetOutput();
	

	//输出polydata模型的vtk文件
	writer->SetInputData(polydata);
	writer->SetFileName("G:/twogrid/vtkPlaneSource.vtk");
	writer->Update();

	mapper->SetInputData(polydata);
	vtkSmartPointer actor = vtkSmartPointer::New();
	actor->SetMapper(mapper);

	// Renderer
	vtkSmartPointer ren1 = vtkSmartPointer::New();
	ren1->AddActor(actor);
	ren1->SetBackground(0.1, 0.2, 0.4);

	// RenderWindow
	vtkSmartPointer renWin = vtkSmartPointer::New();
	renWin->AddRenderer(ren1);
	renWin->SetSize(300, 300);

	// RenderWindowInteractor
	vtkSmartPointer iren = vtkSmartPointer ::New();
	iren->SetRenderWindow(renWin);
	vtkSmartPointer style = vtkSmartPointer::New();
	iren->SetInteractorStyle(style);

	renWin->SetSize(600, 600);
	renWin->Render();
	iren->Start();




	cout << "[Message]vtp file has been writen" << endl;



}

使用vtkPlaneSource创建一个vtkpolydata网格平面_第1张图片

 

你可能感兴趣的:(平面,c++)