From a53d3d395bbb62a3b64e8e846173e4a82a8eb86b Mon Sep 17 00:00:00 2001 From: Krad Date: Fri, 26 Aug 2022 13:15:46 +0800 Subject: [PATCH] Improve corner annotation display. --- src/src/Common/QGlobals.h | 2 +- .../Rendering/Core/MarginCornerAnnotation.cpp | 36 +++++++++++++++++++ .../Rendering/Core/MarginCornerAnnotation.h | 29 +++++++++++++++ src/src/Rendering/Viewer/DICOMImageViewer.cxx | 11 +++--- .../UI/Widget/ImageView/dicomimageview.cpp | 7 ++-- src/src/UI/Window/QDicomViewer.cpp | 1 + 6 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 src/src/Rendering/Core/MarginCornerAnnotation.cpp create mode 100644 src/src/Rendering/Core/MarginCornerAnnotation.h diff --git a/src/src/Common/QGlobals.h b/src/src/Common/QGlobals.h index b7c8163..7b5dd5e 100644 --- a/src/src/Common/QGlobals.h +++ b/src/src/Common/QGlobals.h @@ -244,7 +244,7 @@ public: static int getSize(QSize size) { double ratio = size.width()*1.0 / desktop_width; - int real = font_size - int(25.0*pow(1 - ratio, 2)); + int real = 20 - int(14.0*pow(1 - ratio, 2)); return real; } static int desktop_height; diff --git a/src/src/Rendering/Core/MarginCornerAnnotation.cpp b/src/src/Rendering/Core/MarginCornerAnnotation.cpp new file mode 100644 index 0000000..845616a --- /dev/null +++ b/src/src/Rendering/Core/MarginCornerAnnotation.cpp @@ -0,0 +1,36 @@ +// +// Created by Krad on 2022/8/26. +// + +#include "MarginCornerAnnotation.h" + +#include + +vtkStandardNewMacro(MarginCornerAnnotation); + +MarginCornerAnnotation::MarginCornerAnnotation():vtkCornerAnnotation() { + +} + +MarginCornerAnnotation::~MarginCornerAnnotation() { + +} + +void MarginCornerAnnotation::SetTextActorsPosition(int *vsize) { + this->TextActor[LowerLeft]->SetPosition ( margins[0], margins[3] ); + this->TextActor[LowerRight]->SetPosition ( vsize[0] - margins[3], margins[2] ); + this->TextActor[UpperLeft]->SetPosition ( margins[1], vsize[1] - margins[0] ); + this->TextActor[UpperRight]->SetPosition ( vsize[0] - margins[2], vsize[1] - margins[1] ); + + this->TextActor[LowerEdge]->SetPosition ( vsize[0]/2, margins[3] ); + this->TextActor[UpperEdge]->SetPosition ( vsize[0]/2, vsize[1] - margins[1] ); + this->TextActor[LeftEdge]->SetPosition ( margins[0], vsize[1]/2 ); + this->TextActor[RightEdge]->SetPosition ( vsize[0] - margins[2], vsize[1]/2 ); +} + +void MarginCornerAnnotation::SetMargin(int left, int top, int right, int bottom) { + margins[0]= left; + margins[1]= top; + margins[2]= right; + margins[3]= bottom; +} diff --git a/src/src/Rendering/Core/MarginCornerAnnotation.h b/src/src/Rendering/Core/MarginCornerAnnotation.h new file mode 100644 index 0000000..0441eba --- /dev/null +++ b/src/src/Rendering/Core/MarginCornerAnnotation.h @@ -0,0 +1,29 @@ +// +// Created by Krad on 2022/8/26. +// + +#ifndef OMEGAV_MARGINCORNERANNOTATION_H +#define OMEGAV_MARGINCORNERANNOTATION_H + +#include +class MarginCornerAnnotation: public vtkCornerAnnotation{ +public: + vtkTypeMacro(MarginCornerAnnotation,vtkCornerAnnotation); + static MarginCornerAnnotation *New(); + +protected: + MarginCornerAnnotation(); + ~MarginCornerAnnotation() override; + void SetTextActorsPosition(int vsize[2]) override ; + void SetMargin(int left, int top, int right, int bottom); + void SetMargin(int v){ + SetMargin(v, v, v, v); + } +private: + MarginCornerAnnotation(const MarginCornerAnnotation&) = delete; + void operator=(const MarginCornerAnnotation&) = delete; + int margins[4] = {8, 8, 8, 8}; +}; + + +#endif //OMEGAV_MARGINCORNERANNOTATION_H diff --git a/src/src/Rendering/Viewer/DICOMImageViewer.cxx b/src/src/Rendering/Viewer/DICOMImageViewer.cxx index 17eb22d..51cd6e9 100644 --- a/src/src/Rendering/Viewer/DICOMImageViewer.cxx +++ b/src/src/Rendering/Viewer/DICOMImageViewer.cxx @@ -19,13 +19,13 @@ #include #include #include -#include #include #include #include "Rendering/Measure/MeasureStore.h" #include "IO/General/ColorMapReader.h" #include "Interaction/ActorDraggableInteractorStyle.h" +#include "Rendering/Core/MarginCornerAnnotation.h" namespace { //扭转存在偏转的坐标轴 @@ -61,7 +61,7 @@ DICOMImageViewer::DICOMImageViewer() RenderWindow(nullptr), Renderer(nullptr), ImageStack(vtkImageStack::New()), ImageActor(vtkImageSlice::New()), ImageMapper(vtkImageSliceMapper::New()), FusionActor(nullptr), FusionMapper(nullptr), Interactor(nullptr), InteractorStyle(nullptr), OpacityActor(nullptr), - cornerAnnotation(vtkCornerAnnotation::New()), bar(nullptr), + cornerAnnotation(MarginCornerAnnotation::New()), bar(nullptr), SliceIJK(-1),SlicePlane(-1), FirstRender(1), Slice(0), loadedMeasureSlice(0), currentPresetIndex(1), Fusion(false), firstFusion(true), FusionOpacity(0.5), list(nullptr), measureStore(MeasureStore::Instance()), @@ -74,13 +74,14 @@ DICOMImageViewer::DICOMImageViewer() vtkNew prop; prop->SetFontFamilyToArial(); - prop->ShadowOn(); +// prop->ShadowOn(); this->cornerAnnotation->SetTextProperty(prop); - this->cornerAnnotation->GetTextProperty()->SetColor(1, 1, 0.5); + this->cornerAnnotation->GetTextProperty()->SetColor(0.0, 1, 1); // Annotate the image with window/level and mouse over pixel information cornerAnnotation->SetLinearFontScaleFactor(2); cornerAnnotation->SetNonlinearFontScaleFactor(1); - cornerAnnotation->SetMaximumFontSize(FontSizeHelper::font_size); + cornerAnnotation->SetMaximumFontSize(20); + cornerAnnotation->SetMinimumFontSize(8); vtkRenderWindow *renwin = vtkRenderWindow::New(); DICOMImageViewer::SetRenderWindow(renwin); diff --git a/src/src/UI/Widget/ImageView/dicomimageview.cpp b/src/src/UI/Widget/ImageView/dicomimageview.cpp index 9c85b9f..303f139 100644 --- a/src/src/UI/Widget/ImageView/dicomimageview.cpp +++ b/src/src/UI/Widget/ImageView/dicomimageview.cpp @@ -274,7 +274,6 @@ void DicomImageView::resizeEvent(QResizeEvent *event) { if (!mImageViewer) return; if (mImageViewer->GetvtkCornerAnnotation()) { mImageViewer->GetvtkCornerAnnotation()->SetMaximumFontSize(FontSizeHelper::getSize(frameGeometry().size())); - } // force update ReferenceLine data @@ -459,9 +458,9 @@ void DicomImageView::dispatchEvent(vtkObject *, unsigned long eid, void *callDat //Image render & operation about-------------------------------------------------------------------------------------- void DicomImageView::render() { if (hasSeries()) { - if (mImageViewer->GetvtkCornerAnnotation()) { - mImageViewer->GetvtkCornerAnnotation()->SetMaximumFontSize(FontSizeHelper::getSize(frameGeometry().size())); - } +// if (mImageViewer->GetvtkCornerAnnotation()) { +// mImageViewer->GetvtkCornerAnnotation()->SetMaximumFontSize(FontSizeHelper::getSize(frameGeometry().size())); +// } mImageViewer->Render(); } diff --git a/src/src/UI/Window/QDicomViewer.cpp b/src/src/UI/Window/QDicomViewer.cpp index ce3f154..54d2af6 100644 --- a/src/src/UI/Window/QDicomViewer.cpp +++ b/src/src/UI/Window/QDicomViewer.cpp @@ -272,6 +272,7 @@ void QDicomViewer::openDICOM(const std::string &dicomName, SeriesOpenMode openMo //必须首先重置成1个窗口的布局 ui->viewContainer->resetLayoutToSingle(); + //数据读取 DicomLoader *helper = DicomLoader::GetInstance(); helper->reset(); //load image and tag