vtkImageLogic和vtkImageMathmatic

本文深入探讨了VTK库中的vtkImageLogic和vtkImageMathmatic两个模块在图像处理中的功能和使用。vtkImageLogic主要用于进行二值逻辑运算,如与、或、非等操作,而vtkImageMathmatic则提供了更广泛的数学运算,如加、减、乘、除等,用于图像数据的算术处理。通过实例分析,阐述了这两个工具在实际项目中的重要性和灵活性。
摘要由CSDN通过智能技术生成
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
#include <vtkSmartPointer.h>
#include <vtkRenderer.h>
#include <vtkInteractorStyleImage.h>
#include <vtkImageActor.h>
#include <vtkImageCanvasSource2D.h>

namespace Ui {
    class MainWindow;
}

enum class ONE_OP_INDEX_TYPE : int
{
   ONE_OP_INDEX_NON = 0,
   ONE_OP_INDEX_INVERT ,
    ONE_OP_INDEX_SIN   ,
    ONE_OP_INDEX_COS   ,
    ONE_OP_INDEX_EXP   ,
    ONE_OP_INDEX_LOG   ,
    ONE_OP_INDEX_ABS   ,
    ONE_OP_INDEX_SQUARE,
    ONE_OP_INDEX_ROOT_SQUARE,
    ONE_OP_INDEX_ATAN  ,
    ONE_OP_INDEX_ATAN2 ,
    ONE_OP_INDEX_MUL_K ,
    ONE_OP_INDEX_ADD_K ,
    ONE_OP_INDEX_REPLACE_C_K,
    ONE_OP_INDEX_TOTAL ,
};

enum class TWO_OP_INDEX_TYPE : int
{
    TWO_OP_INDEX_NON = 0,
    TWO_OP_INDEX_ADD    ,
    TWO_OP_INDEX_SUB    ,
    TWO_OP_INDEX_MUL    ,
    TWO_OP_INDEX_DIV    ,
    TWO_OP_INDEX_CONJ   ,
    TWO_OP_INDEX_COM_MUL,
    TWO_OP_INDEX_MIN    ,
    TWO_OP_INDEX_MAX    ,
    TWO_OP_INDEX_TOTAL  ,
};

enum class LOGICAL_OP_INDEX_TYPE : int
{
    LOGICAL_OP_INDEX_NON = 0,
    LOGICAL_OP_INDEX_AND    ,
    LOGICAL_OP_INDEX_OR     ,
    LOGICAL_OP_INDEX_XOR    ,
    LOGICAL_OP_INDEX_N_AND  ,
    LOGICAL_OP_INDEX_N_OR   ,
    LOGICAL_OP_INDEX_NOT    ,
    LOGICAL_OP_INDEX_TOTAL  ,
};

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
private slots:
    void selectOpRadioSlot();
    void selectOpSlot();
private:
    void oneOperator(const ONE_OP_INDEX_TYPE indexType);
    void twoOperator(const TWO_OP_INDEX_TYPE indexType);
    void logicalOperator(const LOGICAL_OP_INDEX_TYPE indexType);
    void initInteractionStyle();
private:
    vtkSmartPointer<vtkRenderer>   src1Render; // 源图像1
    vtkSmartPointer<vtkRenderer>   src2Render; // 源图像2
    vtkSmartPointer<vtkRenderer>   dstRender;  // 生成图像
    vtkSmartPointer<vtkImageActor> src1ImageActor;
    vtkSmartPointer<vtkImageActor> src2ImageActor;
    vtkSmartPointer<vtkImageActor> dstImageActor;
    vtkSmartPointer<vtkInteractorStyleImage> style;
private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QFileDialog>
#include <vtkRenderWindow.h>
#include <vtkImageData.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleImage.h>
#include <vtkImageMathematics.h>
#include <vtkImageLogic.h>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 初始化Render
    src1Render =  vtkSmartPointer<vtkRenderer>::New();
    src2Render =  vtkSmartPointer<vtkRenderer>::New();
    dstRender  =  vtkSmartPointer<vtkRenderer>::New();
    src1Render->SetViewport(0, 0, 0.33, 1.0);
    src2Render->SetViewport(0.33, 0, 0.66, 1.0);
    dstRender->SetViewport(0.66, 0, 1.0, 1.0);
    src1Render->SetBackground(1.0, 0.0, 0.0);
    src2Render->SetBackground(0.0, 1.0, 0.0);
    dstRender->SetBackground(0.0, 0.0, 1.0);

    // ImageActor
    src1ImageActor = vtkSmartPointer<vtkImageActor>::New();
    src2ImageActor = vtkSmartPointer<vtkImageActor>::New();
    dstImageActor  = vtkSmartPointer<vtkImageActor>::New();
    src1Render->AddActor(src1ImageActor);
    src2Render->AddActor(src2ImageActor);
    dstRender->AddActor(dstImageActor);

    //    connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(openFileSlot()));
    connect(ui->oneOpRadioButton, SIGNAL(clicked(bool)), this, SLOT(selectOpRadioSlot()));
    connect(ui->twoOpRadioButton, SIGNAL(clicked(bool)), this, SLOT(selectOpRadioSlot()));
    connect(ui->logicalRadioButton, SIGNAL(clicked(bool)), this, SLOT(selectOpRadioSlot()));

    connect(ui->oneOpComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectOpSlot()));
    connect(ui->twoOpComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectOpSlot()));
    connect(ui->logicalComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectOpSlot()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::selectOpRadioSlot()
{
    QRadioButton* pRadioButton = qobject_cast<QRadioButton *>(sender());

    if(pRadioButton == nullptr)
    {
        return ;
    }

    bool enableOneOp = false;
    bool enableTwoOp = false;
    bool enableLogicalOp = false;
    if(pRadioButton == ui->oneOpRadioButton)
    {
        enableOneOp = true;
    }
    else if(pRadioButton == ui->twoOpRadioButton)
    {
        enableTwoOp = true;
    }
    else if(pRadioButton == ui->logicalRadioButton)
    {
        enableLogicalOp = true;
    }

    ui->oneOpComboBox->setEnabled(enableOneOp);
    ui->twoOpComboBox->setEnabled(enableTwoOp);
    ui->logicalComboBox->setEnabled(enableLogicalOp);
}

void MainWindow::selectOpSlot()
{
    QComboBox* pCombobox = qobject_cast<QComboBox *>(sender());

    int index = pCombobox->currentIndex();

    if(pCombobox == ui->oneOpComboBox)
    {
        oneOperator(static_cast<ONE_OP_INDEX_TYPE>(index));
    }
    else if(pCombobox == ui->twoOpComboBox)
    {
        twoOperator(static_cast<TWO_OP_INDEX_TYPE>(index));
    }
    else if(pCombobox == ui->logicalComboBox)
    {
        logicalOperator(static_cast<LOGICAL_OP_INDEX_TYPE>(index));
    }
}

void MainWindow::oneOperator(const ONE_OP_INDEX_TYPE indexType)
{
    vtkSmartPointer<vtkImageMathematics> imageMath = vtkSmartPointer<vtkImageMathematics>::New();

    vtkSmartPointer<vtkImageCanvasSource2D> src1 &#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值