Replace vtkCornerAnnotation with a FastCornerAnnotationActor.

This commit is contained in:
Krad
2023-01-04 09:11:53 +08:00
parent b4f98698c3
commit 8619723182
13 changed files with 227 additions and 66 deletions

View File

@@ -51,14 +51,14 @@ enum DicomModality
enum CornerPos
{
BOTTOM_LEFT,
BOTTOM_RIGHT,
TOP_LEFT,
TOP_RIGHT,
TOP_MIDDLE,
LEFT_MIDDLE,
BOTTOM_MIDDLE,
RIGHT_MIDDLE,
LEFT_MIDDLE,
TOP_MIDDLE,
TOP_LEFT,
BOTTOM_LEFT,
TOP_RIGHT,
BOTTOM_RIGHT,
TOP_RIGHT_PRIVACY
};

View File

@@ -6,7 +6,6 @@
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkRenderWindow.h>
#include <vtkCornerAnnotation.h>
#include <vtkWindowToImageFilter.h>
#include <vtkImageCast.h>
#include <vtkPNGWriter.h>

View File

@@ -8,14 +8,15 @@
#include <vtkPropPicker.h>
#include <vtkPointPicker.h>
#include <vtkImageSlice.h>
#include <vtkActor2D.h>
#include "vtkInteractorStyleImage.h"
#include "vtkNew.h" // For ivars
#include "functional"
#include "vtkCornerAnnotation.h"
#include "vtkCommand.h"
#include <vtkVersion.h>
#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};

View File

@@ -0,0 +1,120 @@
//
// Created by Krad on 2022/12/29.
//
#include "FastCornerAnnotationActor.h"
#include <vtkObjectFactory.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkTextActor.h>
#include <vtkTextProperty.h>
#include <vtkCoordinate.h>
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("");
}
}

View File

@@ -0,0 +1,72 @@
//
// Created by Krad on 2022/12/29.
//
#ifndef OMEGAV_FASTCORNERANNOTATIONACTOR_H
#define OMEGAV_FASTCORNERANNOTATIONACTOR_H
#include <vtkProp.h>
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

View File

@@ -7,6 +7,7 @@
#include <vtkObjectFactory.h>
#include <vtkPolyData.h>
#include <vtkProperty2D.h>
#include <vtkActor2D.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>

View File

@@ -23,6 +23,7 @@
#include <vtkTextProperty.h>
#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<vtkTextProperty> 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();

View File

@@ -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<RulerLegendActor> ruler;
vtkNew<ReferenceLineLegendActor> referenceLine;

View File

@@ -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<vtkTextProperty> 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() {

View File

@@ -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;

View File

@@ -17,7 +17,6 @@
#include <vtkGPUVolumeRayCastMapper.h>
#include <vtkPiecewiseFunction.h>
#include <vtkColorTransferFunction.h>
#include <vtkCornerAnnotation.h>
#include <vtkTextProperty.h>
#include <vtkPlane.h>
#include <vtkBoundingBox.h>
@@ -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<vtkTextProperty> 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 {

View File

@@ -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<vtkMatrix4x4> OrientationMatrix;
bool gpuMode = false;

View File

@@ -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();
}