利用vtkActorCollection实现对renderer中指定Actor的更新

//display
	vtkSmartPointer Kpolydata1 = vtkSmartPointer::New();
	Kpolydata1->SetPoints(featurePt1);
	//Kpolydata1->GetPointData()->SetScalars(clusterArray1);
	vtkSmartPointer Kpolydata2 = vtkSmartPointer::New();
	Kpolydata2->SetPoints(featurePt2);
	//Kpolydata2->GetPointData()->SetScalars(clusterArray2);
	vtkSmartPointer Kpolydata3 = vtkSmartPointer::New();
	Kpolydata3->SetPoints(featurePt3);
	vtkSmartPointer Kpolydata4 = vtkSmartPointer::New();
	Kpolydata4->SetPoints(featurePt4);

	vtkSmartPointer glyphFilter1 = vtkSmartPointer::New();
	glyphFilter1->SetInputData(Kpolydata1);
	glyphFilter1->Update();
	vtkSmartPointer glyphFilter2 = vtkSmartPointer::New();
	glyphFilter2->SetInputData(Kpolydata2);
	glyphFilter2->Update();
	vtkSmartPointer glyphFilter3 = vtkSmartPointer::New();
	glyphFilter3->SetInputData(Kpolydata3);
	glyphFilter3->Update();
	vtkSmartPointer glyphFilter4 = vtkSmartPointer::New();
	glyphFilter4->SetInputData(Kpolydata4);
	glyphFilter4->Update();

	// Create a mapper and actor
	vtkSmartPointer Kmapper1 = vtkSmartPointer::New();
	Kmapper1->SetInputConnection(glyphFilter1->GetOutputPort());
	vtkSmartPointer Kmapper2 = vtkSmartPointer::New();
	Kmapper2->SetInputConnection(glyphFilter2->GetOutputPort());
	vtkSmartPointer Kmapper3 = vtkSmartPointer::New();
	Kmapper3->SetInputConnection(glyphFilter3->GetOutputPort());
	vtkSmartPointer Kmapper4 = vtkSmartPointer::New();
	Kmapper4->SetInputConnection(glyphFilter4->GetOutputPort());

	vtkSmartPointer Kactor1 = vtkSmartPointer::New();
	Kactor1->SetMapper(Kmapper1);
	Kactor1->GetProperty()->SetPointSize(2);
	Kactor1->GetProperty()->SetColor(0, 0, 1.0);
	vtkSmartPointer Kactor2 = vtkSmartPointer::New();
	Kactor2->SetMapper(Kmapper2);
	Kactor2->GetProperty()->SetPointSize(2);
	Kactor2->GetProperty()->SetColor(0, 0, 1.0);
	vtkSmartPointer Kactor3 = vtkSmartPointer::New();
	Kactor3->SetMapper(Kmapper3);
	Kactor3->GetProperty()->SetPointSize(2);
	Kactor3->GetProperty()->SetColor(0, 0, 1.0);
	vtkSmartPointer Kactor4 = vtkSmartPointer::New();
	Kactor4->SetMapper(Kmapper4);
	Kactor4->GetProperty()->SetPointSize(2);
	Kactor4->GetProperty()->SetColor(0, 0, 1.0);

	vtkAxesActor* axes = vtkAxesActor::New();
	axes->SetTotalLength(50, 50, 50);

	Kactor1->SetUserMatrix(ConeMatrix1);
	Kactor2->SetUserMatrix(ConeMatrix2);
	Kactor3->SetUserMatrix(ConeMatrix3);
	Kactor4->SetUserMatrix(ConeMatrix4);

	vtkActorCollection* col = renderer1->GetActors();
	int num = col->GetNumberOfItems();
	col->InitTraversal();
	col->RemoveItem(num - 1);
	col->RemoveItem(num - 2);
	col->AddItem(Kactor1);
	col->AddItem(Kactor2);

	renderer1->RemoveAllViewProps();
	
	for (int i = 0; i < num; i++)
	{
		renderer1->AddActor(col->GetNextActor());
	}


	vtkActorCollection* col2 = renderer2->GetActors();
	int num2 = col2->GetNumberOfItems();
	col2->InitTraversal();
	col2->RemoveItem(num2 - 1);
	col2->RemoveItem(num2 - 2);
	col2->AddItem(Kactor3);
	col2->AddItem(Kactor4);

	renderer2->RemoveAllViewProps();

	for (int i = 0; i < num2; i++)
	{
		renderer2->AddActor(col2->GetNextActor());
	}

	//renderer1->AddActor(Kactor1);
	//renderer1->AddActor(Kactor2);
	//renderer1->AddActor(axes);

	//renderer2->AddActor(Kactor3);
	//renderer2->AddActor(Kactor4);
	//renderer2->AddActor(axes);


	renWin->AddRenderer(renderer1);
	renWin->AddRenderer(renderer2);
	renWin->Render();


你可能感兴趣的:(VTK手记)