多个渲染器上的vtkWidget位置

时间:2015-03-11 09:42:53

标签: vtk

我遇到了一个相对简单的问题好几天了,我没有找到任何解决方法:我有一个vtkRenderWindow,我在那里散布了4个渲染器,但在运行时我隐藏其中的3个,所以我可以有1个或4个当时的渲染器......

在渲染器1上,我打算放一个vtkSliderWidget来实现它,我写道:

        vtkSliderRepresentation2D* pSliderRep = vtkSliderRepresentation2D::New();
......
......
        pSliderRep->GetPoint1Coordinate()->SetCoordinateSystemToNormalizedViewport();
        pSliderRep->GetPoint1Coordinate()->SetValue(0.1, 0.1);
        pSliderRep->GetPoint2Coordinate()->SetCoordinateSystemToNormalizedViewport();
        pSliderRep->GetPoint2Coordinate()->SetValue(0.9, 0.1);
        m_pSlider->SetInteractor(m_pInteractor);
        m_pSlider->SetRepresentation(pSliderRep);

其中 m_pSlider vtkSliderWidget 对象......

问题变成了我有4个渲染器的地方:

Renderer 1    Renderer 2
Renderer 3    Renderer 4

在这个阶段,我在渲染器3上找到了一个小部件,而不是渲染器1在哪里属于......为什么?

我做错了吗?我为这个问题挖了好几天!!你能救我吗?

稍后编辑:

我使用this test project进行了简单的测试:

int main(int, char *[])
{
vtkSmartPointer<vtkRenderWindow> renderWindow = 
    vtkSmartPointer<vtkRenderWindow>::New();

vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
    vtkSmartPointer<vtkRenderWindowInteractor>::New();

renderWindowInteractor->SetRenderWindow(renderWindow);

vtkRenderer* renderer[4];

// 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};
for(unsigned i = 0; i < 4; i++)
{
    renderer[i] = vtkRenderer::New();
    renderWindow->AddRenderer(renderer[i]);
    CString sTemp;
    sTemp.Format("%.1f, %.1f, %.1f, %.1f\n", xmins[i], ymins[i], xmaxs[i], ymaxs[i]);
    renderer[i]->SetViewport(xmins[i], ymins[i], xmaxs[i], ymaxs[i]);
    // 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);
    renderer[i]->AddActor(actor);
    renderer[i]->ResetCamera();
    renderWindow->Render();
    renderWindow->SetWindowName(_T("Multiple ViewPorts"));
}

vtkSliderRepresentation2D* pSliderRep = vtkSliderRepresentation2D::New();
pSliderRep->SetMinimumValue(3.0);
pSliderRep->SetMaximumValue(20.0);
pSliderRep->SetPlaceFactor(1);
pSliderRep->GetSliderProperty()->SetColor(0.65, 0.75, 0.90);
pSliderRep->GetTitleProperty()->SetColor(1, 0, 0);
pSliderRep->SetLabelFormat(_T("%.2g"));
pSliderRep->GetLabelProperty()->SetColor(1, 0, 0);
pSliderRep->GetSelectedProperty()->SetColor(0, 1, 0);
pSliderRep->GetTubeProperty()->SetColor(0.36, 0.5, 0.66);
pSliderRep->GetTubeProperty()->SetDisplayLocationToForeground();
pSliderRep->GetCapProperty()->SetColor(0.36, 0.5, 0.66);
pSliderRep->SetEndCapLength(0);
pSliderRep->SetEndCapWidth(0.025);
pSliderRep->SetSliderWidth(0.025);
pSliderRep->SetSliderLength(0.045);
pSliderRep->SetHandleSize(6);
pSliderRep->SetTubeWidth(0.032);

pSliderRep->GetPoint1Coordinate()->SetCoordinateSystemToNormalizedDisplay();
pSliderRep->GetPoint1Coordinate()->SetValue(0.01, 0.99);
pSliderRep->GetPoint2Coordinate()->SetCoordinateSystemToNormalizedDisplay();
pSliderRep->GetPoint2Coordinate()->SetValue(0.99, 0.99);

vtkSliderWidget* pSlider = vtkSliderWidget::New();
pSlider->SetInteractor(renderWindowInteractor);
pSlider->SetCurrentRenderer(renderer[0]);
pSlider->SetRepresentation(pSliderRep);
pSlider->EnabledOn();
pSlider->SetDefaultRenderer(renderer[0]);
pSlider->SetAnimationModeToAnimate();

renderWindowInteractor->Start();

pSliderRep->Delete();
pSlider->Delete();

for(unsigned i = 0; i < 4; i++)
    renderer[i]->Delete();

return EXIT_SUCCESS;
}

但是我看到没有滑块......我做错了什么?

[新数据]实际上,在渲染器上设置滑块时,问题会减少,而不是渲染器0:

int main(int, char *[])
{
vtkSmartPointer<vtkRenderWindow> renderWindow = 
    vtkSmartPointer<vtkRenderWindow>::New();

vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
    vtkSmartPointer<vtkRenderWindowInteractor>::New();

renderWindowInteractor->SetRenderWindow(renderWindow);

vtkRenderer* renderer[4];

// 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};
for(unsigned i = 0; i < 4; i++)
{
    renderer[i] = vtkRenderer::New();
    renderWindow->AddRenderer(renderer[i]);
    CString sTemp;
    sTemp.Format("%.1f, %.1f, %.1f, %.1f\n", xmins[i], ymins[i], xmaxs[i], ymaxs[i]);
    renderer[i]->SetViewport(xmins[i], ymins[i], xmaxs[i], ymaxs[i]);
    // 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);
    renderer[i]->AddActor(actor);
    renderer[i]->ResetCamera();
    renderWindow->Render();
    renderWindow->SetWindowName(_T("Multiple ViewPorts"));
}

vtkSliderRepresentation2D* pSliderRep = vtkSliderRepresentation2D::New();
pSliderRep->SetMinimumValue(3.0);
pSliderRep->SetMaximumValue(20.0);

pSliderRep->GetPoint1Coordinate()->SetCoordinateSystemToNormalizedViewport();
pSliderRep->GetPoint1Coordinate()->SetValue(0.1, 0.9);
pSliderRep->GetPoint2Coordinate()->SetCoordinateSystemToNormalizedViewport();
pSliderRep->GetPoint2Coordinate()->SetValue(0.9, 0.9);

vtkSliderWidget* pSlider = vtkSliderWidget::New();
pSlider->SetInteractor(renderWindowInteractor);
pSlider->SetCurrentRenderer(renderer[1]);    // <-- not working !!!
pSlider->SetDefaultRenderer(renderer[1]);    // <-- not working !!!
pSlider->SetAnimationModeToAnimate();

pSlider->SetRepresentation(pSliderRep);
pSlider->EnabledOn();

pSliderRep->Modified();

renderWindowInteractor->Start();

pSliderRep->Delete();
pSlider->Delete();

for(int i = 0; i < 4; i++)
    renderer[i]->Delete();

return EXIT_SUCCESS;
}

问题是,如何在渲染器1(或2或3)上显示滑块,但在渲染器0上?

可能是简单的......

1 个答案:

答案 0 :(得分:1)

在应用表示和所有内容调用CreateDefaultRepresentation()之后 - 这应该会发生很大变化。

pSlider->SetRepresentation(pSliderRep);
pSlider->EnabledOn();
pSlider->CreateDefaultRepresentation();