Vtk多图绘制

std::vector > geometricObjectSources;

#include 
#include 
#include 
#include 
#include 
#include 
#include 
int main()
{
    std::vector > geometricObjectSources;


	geometricObjectSources.push_back(vtkSmartPointer::New());//箭头
	geometricObjectSources.push_back(vtkSmartPointer::New());//锥体
	geometricObjectSources.push_back(vtkSmartPointer::New());//立方体
	geometricObjectSources.push_back(vtkSmartPointer::New());//缸体
	geometricObjectSources.push_back(vtkSmartPointer::New());//转盘
	geometricObjectSources.push_back(vtkSmartPointer::New());//直线
	geometricObjectSources.push_back(vtkSmartPointer::New());//正多面体
	geometricObjectSources.push_back(vtkSmartPointer::New());//球体


	std::vector > renderers;
	std::vector > mappers;
	std::vector > actors;
	std::vector > textmappers;
	std::vector > textactors;


	for (unsigned int i = 0; i < geometricObjectSources.size(); i++)
	{
		geometricObjectSources[i]->Update();


		mappers.push_back(vtkSmartPointer::New());
		mappers[i]->SetInputConnection(geometricObjectSources[i]->GetOutputPort());


		actors.push_back(vtkSmartPointer::New());
		actors[i]->SetMapper(mappers[i]);


		textmappers.push_back(vtkSmartPointer::New());
		textmappers[i]->SetInput(geometricObjectSources[i]->GetClassName());


		textactors.push_back(vtkSmartPointer::New());
		textactors[i]->SetMapper(textmappers[i]);
		textactors[i]->SetPosition(10, 10);
	}


	// 设置格网承载形体
	int gridCols = 3;
	int gridRows = 3;
	// 定义渲染范围
	int rendererSize = 200;


	vtkSmartPointer renderWindow =
		vtkSmartPointer::New();
	renderWindow->SetSize(rendererSize*gridCols, rendererSize*gridRows);


	vtkSmartPointer renderWindowInteractor =
		vtkSmartPointer::New();


	for (double row = 0; row < gridRows; row++)
	{
		for (double col = 0; col < gridCols; col++)
		{
			double index = row*gridCols + col;


			//为每个cell定义渲染器
			vtkSmartPointer renderer = vtkSmartPointer::New();
			renderer->SetBackground(.1, .2, .3);
			double viewport[4] = {
				((col)* rendererSize) / (gridCols * rendererSize),
				((gridRows - (row + 1)) * rendererSize) / (gridRows * rendererSize),
				((col + 1)              * rendererSize) / (gridCols * rendererSize),
				((gridRows - (row)) * rendererSize) / (gridRows * rendererSize) };
			renderer->SetViewport(viewport);
			if (index < geometricObjectSources.size())
			{
				renderer->AddActor(actors[index]);
				renderer->AddActor(textactors[index]);
			}
			renderWindow->AddRenderer(renderer);
		}
	}


	vtkSmartPointer interactor =
		vtkSmartPointer::New();
	interactor->SetRenderWindow(renderWindow);
	renderWindow->Render();
	interactor->Start(); 
        return 0 ;

   
}



你可能感兴趣的:(C++)