#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 &#