# Qt显示 vtk cpr 序列

2023-11-03 13:40
文章标签 显示 qt 序列 vtk cpr

本文主要是介绍# Qt显示 vtk cpr 序列,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Qt显示 vtk cpr 序列

周末终于不忙了,正好实现一个cpr的常用功能,截面图序列浏览。

下边六个截面只是单纯的显示图片,想了想直接用qlabel吧,正好之前没做过可以学习下。记录下用到的东西

vtkImage 转 QImage

图片类型转换

vtkNew<vtkImageCast>cast;
cast->SetInputConnection(mpr_maker_->GetImageReslice(3)->GetOutputPort());
cast->SetOutputScalarTypeToUnsignedChar();
cast->Update();
QImage vtkImageDataToQImage(vtkSmartPointer<vtkImageData> imageData) {if (!imageData) {return QImage();}int width = imageData->GetDimensions()[0];int height = imageData->GetDimensions()[1];QImage image(width, height, QImage::Format_RGB32);QRgb *rgbPtr = reinterpret_cast<QRgb *>(image.bits()) + width * (height - 1);unsigned char *colorsPtr =reinterpret_cast<unsigned char *>(imageData->GetScalarPointer());for (int row = 0; row < height; row++) {for (int col = 0; col < width; col++) {*(rgbPtr++) = QColor(colorsPtr[0], colorsPtr[1], colorsPtr[2]).rgb();colorsPtr += imageData->GetNumberOfScalarComponents();}rgbPtr -= width * 2;}return image;
}

多条可拖动直线

需要自己实现一个Actor,
m_windowSize:窗口大小
m_windowOrigin:窗口原点
m_centerPointDisplayPosition:窗口中心点
m_cameraDistance:缩放倍率

class CBvtkResliceActor final : public vtkObject {public:static CBvtkResliceActor *New();vtkTypeMacro(CBvtkResliceActor, vtkObject);CBvtkResliceActor() {createActor();}~CBvtkResliceActor() = default;vtkActor *getActor() const {return m_actor;}vtkMTimeType getLineTime() const {return m_cursorLines[0]->GetMTime();}void setCameraDistance(const double t_distance) {m_cameraDistance = t_distance;}void setDisplaySize(const double *t_size);void setDisplayOriginPoint(const double *t_point);void setCenterPosition(const double *t_center);void createActor();void update();void reset() const;void createColors(double *t_color1, double *t_color2);void setCPRLines();bool cpr_lines_ = false;private:vtkSmartPointer<vtkAppendPolyData> m_appender = {};vtkSmartPointer<vtkActor> m_actor = {};vtkSmartPointer<vtkTransformFilter> m_filter = {};vtkSmartPointer<vtkLineSource> m_cursorLines[11] = {};vtkSmartPointer<vtkUnsignedCharArray> m_colors[3] = {};vtkSmartPointer<vtkPolyDataMapper> m_mapper = {};double m_windowSize[3] = {};double m_windowOrigin[3] = {};double m_centerPointDisplayPosition[3] = {};double m_cameraDistance = 0;int m_start = 0;
};
void CBvtkResliceActor::update() {if (m_start == 0) {if(cpr_lines_) {for (auto i = -3; i < 4; ++i) {if(0 == i) {continue;}m_cursorLines[7 + i]->SetPoint1(m_centerPointDisplayPosition[0] + i * 1.6,m_centerPointDisplayPosition[1] - 5, 0.01);m_cursorLines[7 + i]->SetPoint2(m_centerPointDisplayPosition[0] + i * 1.6,m_centerPointDisplayPosition[1] + 5, 0.01);m_cursorLines[7 + i]->Update();m_cursorLines[7 + i]->GetOutput()->GetPointData()->AddArray(m_colors[0]);}} else {// 中间连起来m_cursorLines[0]->SetPoint1(m_windowOrigin[0], m_centerPointDisplayPosition[1], 0.01);m_cursorLines[0]->SetPoint2(m_windowSize[0], m_centerPointDisplayPosition[1], 0.01);m_cursorLines[0]->Update();m_cursorLines[0]->GetOutput()->GetPointData()->AddArray(m_colors[1]);m_cursorLines[2]->SetPoint1(m_centerPointDisplayPosition[0], m_windowOrigin[1], 0.01);m_cursorLines[2]->SetPoint2(m_centerPointDisplayPosition[0], m_windowSize[1], 0.01);m_cursorLines[2]->Update();m_cursorLines[2]->GetOutput()->GetPointData()->AddArray(m_colors[0]);// 中间空一个centerHide距离if(false) {m_cursorLines[0]->SetPoint1(m_windowOrigin[0], m_centerPointDisplayPosition[1], 0.01);m_cursorLines[0]->SetPoint2(m_centerPointDisplayPosition[0] - centerHide, m_centerPointDisplayPosition[1], 0.01);m_cursorLines[0]->Update();m_cursorLines[0]->GetOutput()->GetPointData()->AddArray(m_colors[1]);m_cursorLines[1]->SetPoint1(m_centerPointDisplayPosition[0] + centerHide, m_centerPointDisplayPosition[1], 0.01);m_cursorLines[1]->SetPoint2(m_windowSize[0], m_centerPointDisplayPosition[1], 0.01);m_cursorLines[1]->Update();m_cursorLines[1]->GetOutput()->GetPointData()->AddArray(m_colors[1]);m_cursorLines[2]->SetPoint1(m_centerPointDisplayPosition[0], m_windowOrigin[1], 0.01);m_cursorLines[2]->SetPoint2(m_centerPointDisplayPosition[0], m_centerPointDisplayPosition[1] - centerHide, 0.01);m_cursorLines[2]->Update();m_cursorLines[2]->GetOutput()->GetPointData()->AddArray(m_colors[0]);m_cursorLines[3]->SetPoint1(m_centerPointDisplayPosition[0], m_centerPointDisplayPosition[1] + centerHide, 0.01);m_cursorLines[3]->SetPoint2(m_centerPointDisplayPosition[0], m_windowSize[1], 0.01);m_cursorLines[3]->Update();m_cursorLines[3]->GetOutput()->GetPointData()->AddArray(m_colors[0]);}}m_actor->SetScale(5);m_start = 1;} else {m_actor->SetPosition(m_centerPointDisplayPosition[0],m_centerPointDisplayPosition[1],0.01);}
}

绑定鼠标滚轮和拖动事件的槽函数


enum vtkCustomEvents : unsigned long {changeScrollValue = vtkCommand::UserEvent + 1,defaultCursor = changeScrollValue + 1,cursorMove = defaultCursor + 1,cursorFinishMovement = cursorMove + 1,cursorRotate = cursorFinishMovement + 1,imageChanged = cursorRotate + 1,qualityLow = imageChanged + 1,qualityHigh = qualityLow + 1,
};for (auto i = 0; i < 3; ++i) {if (!m_cursor[i]) {m_cursor[i] = vtkSmartPointer<CBvtkReslicePlaneCursorWidget>::New();m_cursor[i]->cpr_type_ = cpr_type_;m_cbk[i] = vtkSmartPointer<CBvtkResliceCallback>::New();m_cbk[i]->setHandleNumber(i);m_cbk[i]->setWidget(this);m_cbk[i]->planeWidget_[0] = this->m_planeWidget[0];m_cbk[i]->planeWidget_[1] = this->m_planeWidget[1];m_cbk[i]->planeWidget_[2] = this->m_planeWidget[2];m_cursor[i]->setWidget(this);m_cursor[i]->AddObserver(cursorRotate, m_cbk[i]);m_cursor[i]->AddObserver(cursorMove, m_cbk[i]);m_cursor[i]->AddObserver(qualityLow, m_cbk[i]);m_cursor[i]->AddObserver(qualityHigh, m_cbk[i]);m_cursor[i]->AddObserver(vtkCommand::LeftButtonReleaseEvent, m_cbk[i]);m_cursor[i]->AddObserver(cursorFinishMovement, m_cbk[i]);m_cursor[i]->AddObserver(imageChanged, m_cbk[i]);m_windows[i]->GetInteractor()->GetInteractorStyle()->AddObserver(imageChanged, m_cbk[i]);}
}if(reslice_widget_->cpr_type_) {for(int i = 0; i < 3; i++) {connection_->Connect(reslice_widget_->GetReslicePlaneCursorWidget()[i],cursorMove, this,SLOT(SlotUpdataCPR(vtkObject *, unsigned long, void *, void *)));connection_->Connect(reslice_widget_->GetReslicePlaneCursorWidget()[i],imageChanged, this,SLOT(SlotUpdataCPR(vtkObject *, unsigned long, void *, void *)));}
}

生成多张切片

要保证几个窗口的床位窗宽一致,我是选择四组vtkImageResliceToColors + vtkImageReslice,几个窗口公用一个vtkScalarsToColors来实现。
三组用来切割实现cpr切割,另外一组用来切割下面几张用QLabel显示的图片。每次切割平移8个毫米。
QList<QImage>把几张需要显示的图片传出去。

QList<QImage> list;
vtkNew<vtkMatrix4x4>reslice_axes;
for(int i = -24; i < 25; i = i + 8) {if(0 == i) {continue;}reslice_axes->DeepCopy(reslice_widget_->GetImageReslicers()[0]->GetResliceAxes());reslice_axes->SetElement(0, 3, reslice_axes->GetElement(0, 3) + i);reslice_axes->SetElement(1, 3, cpr_center_[1]);reslice_axes->SetElement(2, 3, cpr_center_[2]);mpr_maker_->GetImageReslice(3)->SetResliceAxes(reslice_axes);vtkNew<vtkImageCast>cast;cast->SetInputConnection(mpr_maker_->GetImageReslice(3)->GetOutputPort());cast->SetOutputScalarTypeToUnsignedChar();cast->Update();list <<  vtkImageDataToQImage(cast->GetOutput()).mirrored(false, true);
}
emit SgnUpdataCPR(list);

这篇关于# Qt显示 vtk cpr 序列的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/338554

相关文章

Qt QCustomPlot库简介(最新推荐)

《QtQCustomPlot库简介(最新推荐)》QCustomPlot是一款基于Qt的高性能C++绘图库,专为二维数据可视化设计,它具有轻量级、实时处理百万级数据和多图层支持等特点,适用于科学计算、... 目录核心特性概览核心组件解析1.绘图核心 (QCustomPlot类)2.数据容器 (QCPDataC

Qt如何实现文本编辑器光标高亮技术

《Qt如何实现文本编辑器光标高亮技术》这篇文章主要为大家详细介绍了Qt如何实现文本编辑器光标高亮技术,文中的示例代码讲解详细,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录实现代码函数作用概述代码详解 + 注释使用 QTextEdit 的高亮技术(重点)总结用到的关键技术点应用场景举例示例优化建议

SpringSecurity显示用户账号已被锁定的原因及解决方案

《SpringSecurity显示用户账号已被锁定的原因及解决方案》SpringSecurity中用户账号被锁定问题源于UserDetails接口方法返回值错误,解决方案是修正isAccountNon... 目录SpringSecurity显示用户账号已被锁定的解决方案1.问题出现前的工作2.问题出现原因各

Qt 设置软件版本信息的实现

《Qt设置软件版本信息的实现》本文介绍了Qt项目中设置版本信息的三种常用方法,包括.pro文件和version.rc配置、CMakeLists.txt与version.h.in结合,具有一定的参考... 目录在运行程序期间设置版本信息可以参考VS在 QT 中设置软件版本信息的几种方法方法一:通过 .pro

RedisTemplate默认序列化方式显示中文乱码的解决

《RedisTemplate默认序列化方式显示中文乱码的解决》本文主要介绍了SpringDataRedis默认使用JdkSerializationRedisSerializer导致数据乱码,文中通过示... 目录1. 问题原因2. 解决方案3. 配置类示例4. 配置说明5. 使用示例6. 验证存储结果7.

VS配置好Qt环境之后但无法打开ui界面的问题解决

《VS配置好Qt环境之后但无法打开ui界面的问题解决》本文主要介绍了VS配置好Qt环境之后但无法打开ui界面的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目UKeLvb录找到Qt安装目录中designer.UKeLvBexe的路径找到vs中的解决方案资源

利用Python实现时间序列动量策略

《利用Python实现时间序列动量策略》时间序列动量策略作为量化交易领域中最为持久且被深入研究的策略类型之一,其核心理念相对简明:对于显示上升趋势的资产建立多头头寸,对于呈现下降趋势的资产建立空头头寸... 目录引言传统策略面临的风险管理挑战波动率调整机制:实现风险标准化策略实施的技术细节波动率调整的战略价

idea中project的显示问题及解决

《idea中project的显示问题及解决》:本文主要介绍idea中project的显示问题及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录idea中project的显示问题清除配置重China编程新生成配置总结idea中project的显示问题新建空的pr

Qt之QMessageBox的具体使用

《Qt之QMessageBox的具体使用》本文介绍Qt中QMessageBox类的使用,用于弹出提示、警告、错误等模态对话框,具有一定的参考价值,感兴趣的可以了解一下... 目录1.引言2.简单介绍3.常见函数4.按钮类型(QMessage::StandardButton)5.分步骤实现弹窗6.总结1.引言

Qt中Qfile类的使用

《Qt中Qfile类的使用》很多应用程序都具备操作文件的能力,包括对文件进行写入和读取,创建和删除文件,本文主要介绍了Qt中Qfile类的使用,具有一定的参考价值,感兴趣的可以了解一下... 目录1.引言2.QFile文件操作3.演示示例3.1实验一3.2实验二【演示 QFile 读写二进制文件的过程】4.