diff --git a/src/src/Common/QGlobals.h b/src/src/Common/QGlobals.h index 7145775..d71a96b 100644 --- a/src/src/Common/QGlobals.h +++ b/src/src/Common/QGlobals.h @@ -51,14 +51,14 @@ enum DicomModality enum CornerPos { + TOP_MIDDLE, + LEFT_MIDDLE, + BOTTOM_MIDDLE, + RIGHT_MIDDLE, + TOP_LEFT, BOTTOM_LEFT, + TOP_RIGHT, BOTTOM_RIGHT, - TOP_LEFT, - TOP_RIGHT, - BOTTOM_MIDDLE, - RIGHT_MIDDLE, - LEFT_MIDDLE, - TOP_MIDDLE, TOP_RIGHT_PRIVACY }; diff --git a/src/src/Deprecated/Export/dicomexporter.h b/src/src/Deprecated/Export/dicomexporter.h index 3efb0cf..2c23a63 100644 --- a/src/src/Deprecated/Export/dicomexporter.h +++ b/src/src/Deprecated/Export/dicomexporter.h @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include diff --git a/src/src/Interaction/ActorDraggableInteractorStyle.h b/src/src/Interaction/ActorDraggableInteractorStyle.h index bcd4cd8..0f5d355 100644 --- a/src/src/Interaction/ActorDraggableInteractorStyle.h +++ b/src/src/Interaction/ActorDraggableInteractorStyle.h @@ -8,14 +8,15 @@ #include #include #include +#include #include "vtkInteractorStyleImage.h" #include "vtkNew.h" // For ivars #include "functional" -#include "vtkCornerAnnotation.h" #include "vtkCommand.h" #include #include "Rendering/Core/RenderingDefines.h" +#include "Rendering/Legend/FastCornerAnnotationActor.h" class vtkProp; @@ -94,7 +95,7 @@ vtkTypeMacro(ActorDraggableInteractorStyle, vtkInteractorStyleImage); //} - vtkSetObjectMacro(CornerAnnotation, vtkCornerAnnotation); + vtkSetObjectMacro(CornerAnnotation, FastCornerAnnotationActor); vtkProp *GetSelectedProp() { return selectedProp; @@ -182,7 +183,7 @@ private: vtkProp *dragProp = nullptr; vtkProp *selectedProp = nullptr; int DragStartOrigin[2] = {0, 0}; - vtkCornerAnnotation *CornerAnnotation = nullptr; + FastCornerAnnotationActor *CornerAnnotation = nullptr; //bool isCornderAnno = true; Measure *measure = nullptr; double PanStartOrigin[3] = {0.0, 0.0, 0.0}; diff --git a/src/src/Rendering/Legend/FastCornerAnnotationActor.cpp b/src/src/Rendering/Legend/FastCornerAnnotationActor.cpp new file mode 100644 index 0000000..e834ce6 --- /dev/null +++ b/src/src/Rendering/Legend/FastCornerAnnotationActor.cpp @@ -0,0 +1,120 @@ +// +// Created by Krad on 2022/12/29. +// + +#include "FastCornerAnnotationActor.h" + +#include +#include +#include +#include +#include +#include + +vtkStandardNewMacro(FastCornerAnnotationActor); + +FastCornerAnnotationActor::FastCornerAnnotationActor() +: vtkProp(){ + for (int i = 0; i < 8; ++i) { + Actors[i] = vtkTextActor::New(); + Actors[i]->Register(this); + Actors[i]->SetTextScaleModeToNone(); + Actors[i]->SetUseBorderAlign(true); + Actors[i]->GetTextProperty()->SetFontFamilyToCourier(); + Actors[i]->GetTextProperty()->SetFontSize(13); + Actors[i]->GetTextProperty()->BoldOn(); + Actors[i]->GetTextProperty()->ShadowOn(); + Actors[i]->GetActualPositionCoordinate()->SetCoordinateSystemToDisplay(); + Actors[i]->SetPosition(5,5); + Actors[i]->Delete(); + } + + Actors[0]->GetTextProperty()->SetJustificationToCentered(); + Actors[0]->GetTextProperty()->SetVerticalJustificationToTop(); + Actors[1]->GetTextProperty()->SetJustificationToLeft(); + Actors[1]->GetTextProperty()->SetVerticalJustificationToCentered(); + Actors[2]->GetTextProperty()->SetJustificationToCentered(); + Actors[2]->GetTextProperty()->SetVerticalJustificationToBottom(); + Actors[3]->GetTextProperty()->SetJustificationToRight(); + Actors[3]->GetTextProperty()->SetVerticalJustificationToCentered(); + Actors[4]->GetTextProperty()->SetJustificationToLeft(); + Actors[4]->GetTextProperty()->SetVerticalJustificationToTop(); + Actors[4]->GetTextProperty()->SetVerticalJustificationToTop(); + Actors[5]->GetTextProperty()->SetJustificationToLeft(); + Actors[5]->GetTextProperty()->SetVerticalJustificationToBottom(); + Actors[6]->GetTextProperty()->SetJustificationToRight(); + Actors[6]->GetTextProperty()->SetVerticalJustificationToTop(); + Actors[7]->GetTextProperty()->SetJustificationToRight(); + Actors[7]->GetTextProperty()->SetVerticalJustificationToBottom(); +} + +FastCornerAnnotationActor::~FastCornerAnnotationActor() { + +} + + +/* + +---------+ + |4 0 6| + | | + |1 3| + | | + |5 2 7| + +---------+ +*/ +void FastCornerAnnotationActor::SetText(int index , const char* text) { + Actors[index]->SetInput(text); + this->Modified(); +} + +void FastCornerAnnotationActor::ReleaseGraphicsResources(vtkWindow * window) { + for (int i = 0; i < 8; ++i) { + Actors[i]->ReleaseGraphicsResources(window); + } +} + +int FastCornerAnnotationActor::RenderOverlay(vtkViewport *viewport) { + auto renderer = vtkRenderer::SafeDownCast(viewport); + bool ret = false; + for (int i = 0; i < 8; ++i) { + ret = Actors[i]->RenderOverlay(viewport); + } + return ret; +} + +int FastCornerAnnotationActor::RenderOpaqueGeometry(vtkViewport * viewport) { + int ret = 0; + auto renderer = vtkRenderer::SafeDownCast(viewport); + if (LoadTime.GetMTime()< renderer->GetRenderWindow()->GetMTime()) + { + ResetTextPosition(renderer); + LoadTime.Modified(); + } + for (int i = 0; i < 8; ++i) { + ret = Actors[i]->RenderOpaqueGeometry(viewport); + } + return ret; +} + +vtkTypeBool FastCornerAnnotationActor::HasTranslucentPolygonalGeometry() { + bool ret = true; + for (int i = 0; i < 8; ++i) { + ret = true && Actors[i]->HasTranslucentPolygonalGeometry(); + } + return ret; +} + +void FastCornerAnnotationActor::ResetTextPosition(vtkRenderer* renderer) { + double x = 1.0, y = 1.0; + renderer->NormalizedDisplayToDisplay(x, y); + for (int i = 0; i < 8; ++i) { + Actors[i]->GetActualPosition2Coordinate()->SetCoordinateSystemToDisplay(); + Actors[i]->SetPosition2(x - 5,y - 5); + } +} + +void FastCornerAnnotationActor::ClearAllTexts() { + for (int i = 0; i < 8; ++i) { + Actors[i]->SetInput(""); + } +} diff --git a/src/src/Rendering/Legend/FastCornerAnnotationActor.h b/src/src/Rendering/Legend/FastCornerAnnotationActor.h new file mode 100644 index 0000000..2395cb2 --- /dev/null +++ b/src/src/Rendering/Legend/FastCornerAnnotationActor.h @@ -0,0 +1,72 @@ +// +// Created by Krad on 2022/12/29. +// + +#ifndef OMEGAV_FASTCORNERANNOTATIONACTOR_H +#define OMEGAV_FASTCORNERANNOTATIONACTOR_H + +#include + +class vtkRenderer; +class vtkTextActor; + +class FastCornerAnnotationActor: public vtkProp { +public: + //@{ + /** + * Standard methods for instances of this class. + */ + static FastCornerAnnotationActor *New(); + + vtkTypeMacro(FastCornerAnnotationActor, vtkProp); + + //@{ + /** + * Methods to make this class behave as a vtkProp. + */ + double *GetBounds() VTK_SIZEHINT(6) override { return nullptr; } + + void GetActors(vtkPropCollection *) override {} + + void GetVolumes(vtkPropCollection *) override {} + + void ShallowCopy(vtkProp *prop) override {}; + + void ReleaseGraphicsResources(vtkWindow *) override; + + /** + * Method use to make this actor render in 2D scene; + * @param viewport + * @return render is success + */ + int RenderOverlay(vtkViewport *viewport) override; + + int RenderOpaqueGeometry(vtkViewport *vtkNotUsed(viewport)) override; + + int RenderTranslucentPolygonalGeometry(vtkViewport *vtkNotUsed(viewport)) override { return 0; } + + int RenderVolumetricGeometry(vtkViewport *vtkNotUsed(viewport)) override { return 0; } + + vtkTypeBool HasTranslucentPolygonalGeometry() override; + + void SetText(int index ,const char* text); + + void ClearAllTexts(); +protected: + FastCornerAnnotationActor(); + + ~FastCornerAnnotationActor() override; + +private: + FastCornerAnnotationActor(const FastCornerAnnotationActor &) = delete; + + void operator=(const FastCornerAnnotationActor &) = delete; + + void ResetTextPosition(vtkRenderer * renderer); + vtkTextActor* Actors[8]={nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr}; + bool FirstRender = true; + vtkTimeStamp LoadTime; +}; + + +#endif //OMEGAV_FASTCORNERANNOTATIONACTOR_H diff --git a/src/src/Rendering/Measure/RulerAnnotationActor.cpp b/src/src/Rendering/Measure/RulerAnnotationActor.cpp index 6b11c4e..8284878 100644 --- a/src/src/Rendering/Measure/RulerAnnotationActor.cpp +++ b/src/src/Rendering/Measure/RulerAnnotationActor.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/src/src/Rendering/Viewer/DICOMImageViewer.cxx b/src/src/Rendering/Viewer/DICOMImageViewer.cxx index dc619f1..a12b8de 100644 --- a/src/src/Rendering/Viewer/DICOMImageViewer.cxx +++ b/src/src/Rendering/Viewer/DICOMImageViewer.cxx @@ -23,6 +23,7 @@ #include #include "Rendering/Measure/MeasureStore.h" +#include "Rendering/Legend/FastCornerAnnotationActor.h" #include "IO/General/ColorMapReader.h" #include "Interaction/ActorDraggableInteractorStyle.h" #include "Rendering/Core/MarginCornerAnnotation.h" @@ -61,8 +62,8 @@ 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(MarginCornerAnnotation::New()), bar(nullptr), - SliceIJK(-1),SlicePlane(-1), FirstRender(1), Slice(0), loadedMeasureSlice(0), + cornerAnnotation(FastCornerAnnotationActor::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()), rulerActive(false){ @@ -72,16 +73,6 @@ DICOMImageViewer::DICOMImageViewer() this->ImageActor->SetMapper(this->ImageMapper); ImageStack->AddImage(ImageActor); - vtkNew prop; - prop->SetFontFamilyToArial(); - this->cornerAnnotation->SetTextProperty(prop); - 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(20); - cornerAnnotation->SetMinimumFontSize(8); - vtkRenderWindow *renwin = vtkRenderWindow::New(); DICOMImageViewer::SetRenderWindow(renwin); renwin->Delete(); diff --git a/src/src/Rendering/Viewer/DICOMImageViewer.h b/src/src/Rendering/Viewer/DICOMImageViewer.h index 654ae7f..37412ad 100644 --- a/src/src/Rendering/Viewer/DICOMImageViewer.h +++ b/src/src/Rendering/Viewer/DICOMImageViewer.h @@ -46,7 +46,7 @@ class MeasureStore; class vtkScalarBarActor; -class vtkCornerAnnotation; +class FastCornerAnnotationActor; class Measure; @@ -59,9 +59,6 @@ public: void PrintSelf(ostream &os, vtkIndent indent) override; //vtkGetMacro(m_cornerAnnotation, vtkCornerAnnotation); - vtkCornerAnnotation *GetvtkCornerAnnotation() { - return cornerAnnotation; - } void UpdateCornerInfo(int index); @@ -439,7 +436,7 @@ private: vtkRenderWindowInteractor *Interactor; ActorDraggableInteractorStyle *InteractorStyle = nullptr; vtkTextActor *OpacityActor; - vtkCornerAnnotation *cornerAnnotation; + FastCornerAnnotationActor *cornerAnnotation; vtkScalarBarActor *bar; vtkNew ruler; vtkNew referenceLine; diff --git a/src/src/Rendering/Viewer/ResliceImageViewer.cpp b/src/src/Rendering/Viewer/ResliceImageViewer.cpp index 9dddeba..cb7060c 100644 --- a/src/src/Rendering/Viewer/ResliceImageViewer.cpp +++ b/src/src/Rendering/Viewer/ResliceImageViewer.cpp @@ -19,7 +19,7 @@ #include "Rendering/Legend/ResliceCursorLegendActor.h" -#include "Rendering/Legend/FastOrientationLegendActor.h" +#include "Rendering/Legend/FastCornerAnnotationActor.h" #include "Rendering/Legend/ResliceSquareLegendActor.h" #include "Interaction/ResliceImageInteractorStyle.h" @@ -60,7 +60,7 @@ ResliceImageViewer::ResliceImageViewer() , cursor2(ResliceCursorLegendActor::New()) , Square(ResliceSquareLegendActor::New()) , Actor(vtkImageSlice::New()) - , annotation(vtkCornerAnnotation::New()) + , annotation(FastCornerAnnotationActor::New()) , OrientationMatrix(vtkMatrix4x4::New()) , DefaultOrientation(0) , FirstRender(true) @@ -77,13 +77,6 @@ ResliceImageViewer::ResliceImageViewer() vtkNew prop; prop->SetFontFamilyToArial(); - this->annotation->SetTextProperty(prop); - this->annotation->GetTextProperty()->SetColor(.0,1.,1.); - // Annotate the image with window/level and mouse over pixel information - this->annotation->SetLinearFontScaleFactor(2); - this->annotation->SetNonlinearFontScaleFactor(1); - this->annotation->SetMaximumFontSize(20); - this->annotation->SetMinimumFontSize(8); } ResliceImageViewer::~ResliceImageViewer() { @@ -191,7 +184,7 @@ void ResliceImageViewer::Render() { MeasureRenderer->SetLayer(1); MeasureRenderer->AddActor2D(cursor1); MeasureRenderer->AddActor2D(cursor2); - MeasureRenderer->AddActor(annotation); + cursor1->SetSlicePoint(MeasureRenderer->GetActiveCamera()->GetFocalPoint()); cursor2->SetSlicePoint(MeasureRenderer->GetActiveCamera()->GetFocalPoint()); cursor1->SetProjectDirectionVector(MeasureRenderer->GetActiveCamera()->GetDirectionOfProjection()); @@ -240,6 +233,7 @@ void ResliceImageViewer::Render() { cursor2->AddObserver(ResliceCursorLegendActor::ROLL,this, &ResliceImageViewer::handleRoll); cursor2->AddObserver(ResliceCursorLegendActor::MOVE,this, &ResliceImageViewer::handleMove); MeasureRenderer->AddActor2D(Square); + MeasureRenderer->AddActor(annotation); UpdateDirectionAnnotation(); Render(); return; @@ -380,13 +374,13 @@ void ResliceImageViewer::UpdateDirectionAnnotation() { double viewLeft[4] = {-viewRight[0], -viewRight[1], -viewRight[2], 1.}; std::string str; GetDirectionString(viewUp, str); - annotation->SetText(7,str.c_str() ); + annotation->SetText(0,str.c_str() ); GetDirectionString(viewRight, str); - annotation->SetText(5,str.c_str() ); + annotation->SetText(3,str.c_str() ); GetDirectionString(viewDown, str); - annotation->SetText(4,str.c_str() ); + annotation->SetText(2,str.c_str() ); GetDirectionString(viewLeft, str); - annotation->SetText(6,str.c_str() ); + annotation->SetText(1,str.c_str() ); } void ResliceImageViewer::ResetHandle() { diff --git a/src/src/Rendering/Viewer/ResliceImageViewer.h b/src/src/Rendering/Viewer/ResliceImageViewer.h index 95881f6..33aca68 100644 --- a/src/src/Rendering/Viewer/ResliceImageViewer.h +++ b/src/src/Rendering/Viewer/ResliceImageViewer.h @@ -27,7 +27,7 @@ class ResliceCursorLegendActor; class ResliceSquareLegendActor; -class vtkCornerAnnotation; +class FastCornerAnnotationActor; class ResliceImageViewer :public vtkObject { public: @@ -87,7 +87,7 @@ private: ResliceCursorLegendActor* cursor2; ResliceSquareLegendActor* Square; vtkImageSlice* Actor; - vtkCornerAnnotation* annotation; + FastCornerAnnotationActor* annotation; vtkMatrix4x4* OrientationMatrix; int DefaultOrientation; bool FirstRender; diff --git a/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp b/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp index 7b28edd..f6fdee1 100644 --- a/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp +++ b/src/src/Rendering/Viewer/VolumeRenderingViewer.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -29,6 +28,7 @@ #include "IO/DICOM/ExtendMedicalImageProperties.h" #include "Rendering/Measure/VolRulerAnnotationActor.h" #include "Rendering/Measure/VolArrowAnnotationActor.h" +#include "Rendering/Legend/FastCornerAnnotationActor.h" namespace { enum ViewDirection{ @@ -78,7 +78,7 @@ VolumeRenderingViewer::VolumeRenderingViewer() , RenderWindow(nullptr) , Renderer(nullptr) , VolumeActor(vtkVolume::New()) -, annotation(vtkCornerAnnotation::New()) +, annotation(FastCornerAnnotationActor::New()) , VolumeMapper(SmartFixedPointVolumeRayCastMapper::New()) , InteractorStyle(nullptr) , Interactor(nullptr) @@ -132,13 +132,6 @@ VolumeRenderingViewer::VolumeRenderingViewer() VolumeActor->SetMapper(VolumeMapper); vtkNew prop; prop->SetFontFamilyToArial(); - this->annotation->SetTextProperty(prop); - this->annotation->GetTextProperty()->SetColor(.0,1.,1.); - // Annotate the image with window/level and mouse over pixel information - this->annotation->SetLinearFontScaleFactor(2); - this->annotation->SetNonlinearFontScaleFactor(1); - this->annotation->SetMaximumFontSize(20); - this->annotation->SetMinimumFontSize(8); } VolumeRenderingViewer::~VolumeRenderingViewer() { @@ -342,7 +335,7 @@ void VolumeRenderingViewer::renderWindowAnnotation() { double wl = (range[0]+range[1])/2.0; double ww = (range[1] - range[0]); sprintf(buff,"WW:%.0f WL:%.0f", ww,wl); - annotation->SetText(0,buff ); + annotation->SetText(5,buff ); } void VolumeRenderingViewer::renderOrientationAnnotation() { @@ -361,13 +354,13 @@ void VolumeRenderingViewer::renderOrientationAnnotation() { double viewLeft[4] = {-viewRight[0], -viewRight[1], -viewRight[2], 1.}; std::string str; GetDirectionString(viewUp, str); - annotation->SetText(7,str.c_str() ); + annotation->SetText(0,str.c_str() ); GetDirectionString(viewRight, str); - annotation->SetText(5,str.c_str() ); + annotation->SetText(3,str.c_str() ); GetDirectionString(viewDown, str); - annotation->SetText(4,str.c_str() ); + annotation->SetText(2,str.c_str() ); GetDirectionString(viewLeft, str); - annotation->SetText(6,str.c_str() ); + annotation->SetText(1,str.c_str() ); } void VolumeRenderingViewer::GetDirectionString(const double *directionVector, std::string &str) const { diff --git a/src/src/Rendering/Viewer/VolumeRenderingViewer.h b/src/src/Rendering/Viewer/VolumeRenderingViewer.h index bedfdd3..bb53ed5 100644 --- a/src/src/Rendering/Viewer/VolumeRenderingViewer.h +++ b/src/src/Rendering/Viewer/VolumeRenderingViewer.h @@ -29,7 +29,7 @@ class vtkVolume; class vtkVolumeMapper; -class vtkCornerAnnotation; +class FastCornerAnnotationActor; class ExtendMedicalImageProperties; @@ -121,7 +121,7 @@ private: vtkVolumeMapper *VolumeMapper; vtkInteractorStyle *InteractorStyle; vtkRenderWindowInteractor *Interactor; - vtkCornerAnnotation* annotation; + FastCornerAnnotationActor* annotation; vtkOrientationMarkerWidget* OrientationMarker; vtkNew OrientationMatrix; bool gpuMode = false; diff --git a/src/src/UI/Widget/ImageView/dicomimageview.cpp b/src/src/UI/Widget/ImageView/dicomimageview.cpp index e876688..b1dfbad 100644 --- a/src/src/UI/Widget/ImageView/dicomimageview.cpp +++ b/src/src/UI/Widget/ImageView/dicomimageview.cpp @@ -277,9 +277,6 @@ void DicomImageView::mousePressEvent(QMouseEvent *event) { void DicomImageView::resizeEvent(QResizeEvent *event) { //auto size conner info if (!mImageViewer) return; - if (mImageViewer->GetvtkCornerAnnotation()) { - mImageViewer->GetvtkCornerAnnotation()->SetMaximumFontSize(FontSizeHelper::getSize(frameGeometry().size())); - } // force update ReferenceLine data mImageViewer->modifiedReferenceLine(); @@ -463,10 +460,6 @@ void DicomImageView::dispatchEvent(vtkObject *, unsigned long eid, void *callDat //Image render & operation about-------------------------------------------------------------------------------------- void DicomImageView::render() { if (hasSeries()) { - if (mIsFirstRenderAfterLoad && mImageViewer->GetvtkCornerAnnotation()) { - mImageViewer->GetvtkCornerAnnotation()->SetMaximumFontSize(FontSizeHelper::getSize(frameGeometry().size())); - mIsFirstRenderAfterLoad = false; - } mImageViewer->Render(); }