关于vtkActor有任何人在更多的" vtkRenderer"中添加同一个演员时遇到了麻烦。
我在三个vtkRenderWindow中有三个vtkRenderer。 我在三个vtkRenderer中添加一个actor,但是actor只处理第一个vtkRenderer。
示例:
void EstudoMaxilaMandibula::AddPointer(double* p)
{
vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(0.0, 0.0, 0.0);
sphereSource->SetRadius(2.0);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
listActor.push_back(actor);
actor->SetMapper(mapper);
actor->SetPosition(p);
for (int i = 0; i < 3; i++) {
corte->imageViwer[i]->GetRenderer()->AddActor(actor);
corte->imageViwer[i]->Render();
}
}
答案 0 :(得分:0)
我发现了问题。
VTK中的演员不能添加到多个vtkrenderwindow中。但是它们可以添加到几个vtkrenderer中。但是这些渲染它们必须在同一个vtkrenderwindow中。
在vtk组的这篇文章中有更多信息。
按照我上面所说的方式,我们有类似的东西:
int main(int, char* [])
{
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkInteractorStyleTrackballActor> style =
vtkSmartPointer<vtkInteractorStyleTrackballActor>::New();
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetInteractorStyle(style);
renderWindowInteractor->SetRenderWindow(renderWindow);
// Define viewport ranges
double xmins[4] = { 0, .5, 0, .5 };
double xmaxs[4] = { 0.5, 1, 0.5, 1 };
double ymins[4] = { 0, 0, .5, .5 };
double ymaxs[4] = { 0.5, 0.5, 1, 1 };
// Create a sphere
vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(0.0, 0.0, 0.0);
sphereSource->SetRadius(5);
sphereSource->Update();
// Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
for (unsigned i = 0; i < 4; i++)
{
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderWindow->AddRenderer(renderer);
renderer->SetViewport(xmins[i], ymins[i], xmaxs[i], ymaxs[i]);
renderer->AddActor(actor);
renderer->ResetCamera();
renderWindow->Render();
renderWindow->SetWindowName("Multiple ViewPorts");
}
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
这样一切正常。