c++ - 如何设置正确的 vtkCamera 缩放系数?

标签 c++ qt vtk

我想将图像的大小增加到 50%、100%、200%、400% 和 800%。为了缩放 DICOM 图像。为此,我将在查看器中使用 QComboBox,并将其索引设置为 (50,100,200,400,800)。

从组合框中我得到了我需要增加多少百分比的索引。对于 (示例 - index(0)-50%,index(1)-100%...等等)。

我正在使用“vtk(getActiveCamera())”根据所选索引增加图像的大小。

我遇到的问题是,当我将尺寸设置为 200% 时,它会被正确设置。但是当我将大小增加到 400% 时,它将设置为 200%+400% =600%。显然,我只想将大小设置为 400%。

这是我的代码:

    void ViewerManager::vtkZoomCaller(int index)
    {
        int i;
        switch (index)
        {
        case 0:
            //qDebug() << "hello50";
            for (i = 0; i < NumberOfViewers; i++) {
                    viewerDerived[i]->GetRenderer()->GetActiveCamera()->Zoom(0.5);
                }
            break;
        case 1:
            //qDebug() << "hello100";
            for (i = 0; i < NumberOfViewers; i++) {
                viewerDerived[i]->GetRenderer()->GetActiveCamera()->Zoom(1);

            }
 break;
        case 2:
            //qDebug() << "hello200";
            for (i = 0; i < NumberOfViewers; i++) {
                viewerDerived[i]->GetRenderer()->GetActiveCamera()->Zoom(2);
                }

            break;
        case 3:
            //qDebug() << "hello400";
            for (i = 0; i < NumberOfViewers; i++) {
                viewerDerived[i]->GetRenderer()->GetActiveCamera()->Zoom(4);
                }
break;
        case 4:
            //qDebug() << "hello800";
            for (i = 0; i < NumberOfViewers; i++) {
                viewerDerived[i]->GetRenderer()->GetActiveCamera()->Zoom(8);
                }
            break;
        default:
            break;
        }
    }

当我想在 200% 之后选择 100% 或高于任何百分比时,它不会减小尺寸。 任何帮助对我都非常有用。 提前致谢

最佳答案

从您分享的内容中我看到两个问题:

  • vtkCamera::Zoom 接受 double 作为参数。

  • 代码中的冗余是不必要的。实际上,使用 QHash 有一种更优雅的方式来实现这一点。 .

考虑到这一点,我准备了您可以尝试的示例:

QHash<int, double> hash;
auto *comboZoom = new QComboBox(this);

hash.insert(0, 0.5);
hash.insert(1, 1.0);
hash.insert(2, 2.0);
hash.insert(3, 4.0);
hash.insert(4, 8.0);

comboZoom->addItems(QStringList{"50%", "100%", "200%", "400%", "800%"});

connect(comboZoom, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [hash](int index){
    for (int n = 0; n < numberOfViewers; n++) {
        viewerDerived[n]->GetRenderer()->GetActiveCamera()->Zoom(hash.value(index));
    }
});

关于c++ - 如何设置正确的 vtkCamera 缩放系数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52293729/

相关文章:

c# - 从 C++ 调用 C# 事件

python - 使用 Numpy 将 VTK 转换为 Matplotlib

c++ - 读/写 vtk 文件显示不正确

c++ - Qt QSound循环

qt - 如何将 mousePressEvent() 传播到一组 QGraphicsItem?

c++ - 将十六进制转换为 double 转换为十六进制?

android - NativeVTK 已停止

c++ - 如何处理OpenCV::Canny边缘检测的结果

c++ - OpenCV imshow 错误? - 像素颜色

c++ - 将一个类放在单独的文件中不起作用[C++]