#include "DicomView.h"
#include <QGraphicsPixmapItem>
#include <QGraphicsWidget>
#include <QGraphicsLinearLayout>
#include <QGraphicsProxyWidget>
#include <QMessageBox>
DicomView::DicomView(QWidget *parent)
: QGraphicsView(parent)
{
_pScene = new QGraphicsScene(this);
_pPixmapItem = new QGraphicsPixmapItem;
_pWLValueItem = new QGraphicsSimpleTextItem;
_pCurFrameItem = new QGraphicsSimpleTextItem;
this->_seriesUID = "";
this->_pSeriesData = nullptr;
this->_currImageIndex = 0;
setFocusPolicy(Qt::StrongFocus);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setContextMenuPolicy(Qt::DefaultContextMenu);
setBackgroundBrush(QBrush(Qt::black));
setAcceptDrops(true);
setFrameShape(QFrame::Box);
setFrameShadow(QFrame::Plain);
setAlignment(Qt::AlignCenter);
setResizeAnchor(QGraphicsView::AnchorViewCenter);
_pScene->setSceneRect(-5000, -5000, 10000, 10000);
setScene(_pScene);
//图片切换风格
_pPixmapItem->setTransformationMode(Qt::SmoothTransformation);
_pPixmapItem->setAcceptHoverEvents(true);
_pWLValueItem->setBrush(Qt::white);
_pCurFrameItem->setBrush(Qt::white);
_pScene->addItem(_pPixmapItem);
_pScene->addItem(_pWLValueItem);
_pScene->addItem(_pCurFrameItem);
_pGraphicsSlider = new QGraphicsWidget;
QGraphicsLinearLayout *pVerticalLayout = new QGraphicsLinearLayout;
pVerticalLayout->setOrientation(Qt::Vertical);
pVerticalLayout->setSpacing(0);
_pGraphicsSlider->setLayout(pVerticalLayout);
_pScene->addItem(_pGraphicsSlider);
_pSlider = new QSlider;
_pSlider->setMinimum(0);
_pSlider->setOrientation(Qt::Vertical);
_pSlider->setAttribute(Qt::WA_StyledBackground, true);
_pSlider->setStyleSheet("background-color: rgba(200,200, 200,0)");
connect(_pSlider, SIGNAL(valueChanged(int)), this, SLOT(setCurFrameItem(int)));
_pProxyWidget = _pScene->addWidget(_pSlider);
QGraphicsLinearLayout *verticalLayout = (QGraphicsLinearLayout *)_pGraphicsSlider->layout();
verticalLayout->addItem(_pProxyWidget);
}
DicomView::~DicomView()
{
delete _pGraphicsSlider;
delete _pCurFrameItem;
delete _pWLValueItem;
delete _pPixmapItem;
delete _pScene;
}
void DicomView::loadSeries(QString &seriesUID)
{
SeriesData* pSeriesData = nullptr;
for (size_t i = 0; i < SeriesData::SeriesList.size(); i++)
{
if (SeriesData::SeriesList.at(i)->getSeriesUID() == seriesUID)
{
pSeriesData = SeriesData::SeriesList.at(i);
}
}
if (nullptr == pSeriesData)
{
QMessageBox::critical(this, QStringLiteral("加载错误"), QStringLiteral("序列不存在。"));
return;
}
if (pSeriesData->images.size() == 0)
{
return;
}
this->_seriesUID = seriesUID;
this->_pSeriesData = pSeriesData;
this->_currImageIndex = 0;
double xSpacing = 0, ySpacing = 0, zSpacing = 0;
if (pSeriesData->images.values().at(this->_currImageIndex)->getPixSpacing(xSpacing, ySpacing, zSpacing)) {
if (xSpacing > 0.000001 && ySpacing > 0.000001) {
double psX = xSpacing;
double psY = ySpacing;
_fixFactor = psY / psX;
}
}
_pSlider->setMaximum(_pSeriesData->images.size() - 1);
_pSlider->setValue(_currImageIndex);
double winWidth, winCenter;
_pSeriesData->getDefaultWindow(winCenter, winWidth);
_pWLValueItem->setText(tr("W:%1, L:%2").arg(winWidth).arg(winCenter));
_pPixmapItem->setPos(0, 0);
_pPixmapItem->setRotation(0);
_pPixmapItem->resetTransform();
updateView();
_pScene->update(_pScene->sceneRect());
}
void DicomView::updateView()
{
if (nullptr == _pSeriesData)
{
return;
}
QPixmap pixmap;
if (_pSeriesData->images.size() > this->_currImageIndex && _pSeriesData->images.values().at(this->_currImageIndex)->isNormal()) {
double winWidth, winCenter;
_pSeriesData->getDefaultWindow(winCenter, winWidth);
_pSeriesData->images.values().at(this->_currImageIndex)->setWindow(winCenter, winWidth);
_pSeriesData->images.values().at(this->_currImageIndex)->getPixmap(pixmap);
_pPixmapItem->setPixmap(pixmap);
_pPixmapItem->setTransformOriginPoint(_pPixmapItem->boundingRect().center());
_pCurFrameItem->setText(tr("%1 / %2").arg(_currImageIndex + 1).arg(_pSeriesData->images.size()));
}
else {
_pPixmapItem->setPixmap(pixmap);
_pCurFrameItem->setText("");
_pWLValueItem->setText("");
}
resizePixmapItem();
repositionAuxItems();
}
void DicomView::resizePixmapItem()
{
if (!_pPixmapItem->pixmap().isNull()) {
QRectF pixmapRect = _pPixmapItem->boundingRect();
QRectF viewRect = this->rect();
double factor;
if (pixmapRect.width()*viewRect.height() < pixmapRect.height()*_fixFactor*viewRect.width())
factor = viewRect.height() / (pixmapRect.height()*_fixFactor);
else
factor = viewRect.width() / pixmapRect.width();
_pPixmapItem->setTransform(QTransform(factor, 0, 0, factor*_fixFactor, 0, 0));
centerOn(_pPixmapItem);
}
}
void DicomView::repositionAuxItems()
{
QPointF sceneTL = mapToScene(rect().topLeft());
QPointF sceneBR = mapToScene(rect().bottomRight());
_pCurFrameItem->setPos(sceneBR.x() - 60, sceneTL.y() + 20);
_pGraphicsSlider->setPos(sceneBR.x() - 58, sceneTL.y() + 58);
QSizeF slider_size(58, sceneBR.y() - sceneTL.y() - 116);
_pGraphicsSlider->resize(slider_size);
_pWLValueItem->setPos(sceneTL.x() + 10, sceneBR.y() - 30);
}
void DicomView::resizeEvent(QResizeEvent *event)
{
resizePixmapItem();
repositionAuxItems();
}
void DicomView::wheelEvent(QWheelEvent *event)
{
QPoint delta = event->angleDelta();
if (_pSeriesData == nullptr || _pSeriesData->images.isEmpty()) return;
if (delta.y() > 0)
{
_currImageIndex -= 1;
if (_currImageIndex < 0)
{
//_currImageIndex = 0;
_currImageIndex = _pSeriesData->images.size() - 1;
}
}
else if (delta.y() < 0)
{
_currImageIndex += 1;
if (_currImageIndex >= _pSeriesData->images.size())
{
//_currImageIndex = _pSeriesData->images.size() - 1;
_currImageIndex = 0;
}
}
_pSlider->setValue(_currImageIndex);
}
void DicomView::setCurFrameItem(int value)
{
if (_pSeriesData == nullptr || _pSeriesData->images.size() == 0)
return;
_currImageIndex = value;
updateView();
}
没有合适的资源?快使用搜索试试~ 我知道了~
第一个 DCMTK 程序:显示 DICOM 图像(DCMTK 3.6.4 + Qt 5.14.2 + VS2015)源码
共68个文件
dll:28个
qm:22个
cpp:6个
5星 · 超过95%的资源 需积分: 44 76 下载量 48 浏览量
2020-11-25
21:18:47
上传
评论 2
收藏 21.41MB ZIP 举报
温馨提示
这是博文《第一个 DCMTK 程序:显示 DICOM 图像(DCMTK 3.6.4 + Qt 5.14.2 + VS2015)》的源码,详细内容见博客文章 https://blog.csdn.net/blackwoodcliff/article/details/109481195
资源详情
资源评论
资源推荐
收起资源包目录
DcmtkDemo.zip (68个子文件)
DcmtkDemo
DcmtkDemo
DicomView.h 1KB
SeriesData.cpp 481B
ImageData.cpp 6KB
DcmtkDemo.vcxproj 6KB
SeriesData.h 587B
DcmtkDemo.cpp 2KB
ImageData.h 1KB
DicomView.cpp 6KB
DcmtkDemo.h 554B
main.cpp 189B
ReadWorker.cpp 1KB
DcmtkDemo.vcxproj.filters 2KB
DcmtkDemo.vcxproj.user 165B
ReadWorker.h 446B
DcmtkDemo.ui 3KB
DcmtkDemo.qrc 69B
x64
Debug
Release
ofstd.dll 267KB
Qt5Svg.dll 328KB
Qt5Widgets.dll 5.3MB
libGLESv2.dll 3.44MB
iconengines
qsvgicon.dll 43KB
styles
qwindowsvistastyle.dll 139KB
Qt5Gui.dll 6.8MB
Qt5Core.dll 6.07MB
DcmtkDemo.exe 107KB
oflog.dll 378KB
dcmimgle.dll 1.77MB
dcmdata.dll 1.79MB
ijg8.dll 160KB
libEGL.dll 24KB
platforms
qwindows.dll 1.4MB
ijg12.dll 160KB
opengl32sw.dll 19.95MB
ijg16.dll 161KB
D3Dcompiler_47.dll 3.98MB
translations
qt_fi.qm 176KB
qt_cs.qm 171KB
qt_ca.qm 180KB
qt_es.qm 161KB
qt_gd.qm 185KB
qt_lv.qm 150KB
qt_uk.qm 155KB
qt_sk.qm 123KB
qt_pl.qm 159KB
qt_hu.qm 157KB
qt_zh_TW.qm 125KB
qt_ru.qm 194KB
qt_en.qm 23B
qt_it.qm 157KB
qt_da.qm 170KB
qt_ar.qm 156KB
qt_de.qm 209KB
qt_fr.qm 162KB
qt_he.qm 135KB
qt_bg.qm 161KB
qt_ja.qm 127KB
qt_ko.qm 128KB
dcmjpeg.dll 227KB
imageformats
qtga.dll 31KB
qgif.dll 37KB
qwebp.dll 505KB
qtiff.dll 377KB
qwbmp.dll 29KB
qsvg.dll 32KB
qicns.dll 44KB
qjpeg.dll 400KB
qico.dll 38KB
DcmtkDemo.sln 947B
共 68 条
- 1
blackwood-cliff
- 粉丝: 148
- 资源: 57
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1