From 2c4d70a166afa6df41d7c6e2c2d5338d105b20f8 Mon Sep 17 00:00:00 2001 From: kradchen Date: Tue, 29 Apr 2025 10:39:21 +0800 Subject: [PATCH] fix: fix measure delete bug when measure select by control point --- src/src/Rendering/Core/ControlPointActor.cpp | 3 ++- src/src/Rendering/Core/ControlPointActor.h | 4 ++++ .../Measure/AngleAnnotationActor.cpp | 4 ++++ .../Measure/ArrowAnnotationActor.cpp | 3 +++ .../Measure/EllipseAnnotationActor.cpp | 6 ++++++ .../Rendering/Measure/LineAnnotationActor.cpp | 2 ++ src/src/Rendering/Viewer/DICOMImageViewer.cxx | 20 ++++++++++++++++++- 7 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/src/Rendering/Core/ControlPointActor.cpp b/src/src/Rendering/Core/ControlPointActor.cpp index 63b49fd..d4784f6 100644 --- a/src/src/Rendering/Core/ControlPointActor.cpp +++ b/src/src/Rendering/Core/ControlPointActor.cpp @@ -15,7 +15,8 @@ vtkStandardNewMacro(ControlPointActor) ControlPointActor::ControlPointActor() - : shadowData(vtkPolyData::New()) { + : shadowData(vtkPolyData::New()) + , controlledActor(nullptr) { BaseDataPoints->SetNumberOfPoints(1); renderPoints->SetNumberOfPoints(1); renderPoints->SetPoint(0, 0, 0, 0); diff --git a/src/src/Rendering/Core/ControlPointActor.h b/src/src/Rendering/Core/ControlPointActor.h index b397aef..6ab9c2f 100644 --- a/src/src/Rendering/Core/ControlPointActor.h +++ b/src/src/Rendering/Core/ControlPointActor.h @@ -27,6 +27,9 @@ public: void SetWorldPosition(double *pos) { SetWorldPosition(pos[0], pos[1], pos[2]); } + vtkSetObjectMacro(controlledActor,DraggableActor); + vtkGetObjectMacro(controlledActor,DraggableActor); + protected: ControlPointActor(); @@ -34,6 +37,7 @@ protected: ~ControlPointActor() override; vtkPolyData *shadowData; + DraggableActor * controlledActor; }; diff --git a/src/src/Rendering/Measure/AngleAnnotationActor.cpp b/src/src/Rendering/Measure/AngleAnnotationActor.cpp index 8436445..e0150ea 100644 --- a/src/src/Rendering/Measure/AngleAnnotationActor.cpp +++ b/src/src/Rendering/Measure/AngleAnnotationActor.cpp @@ -47,6 +47,10 @@ AngleAnnotationActor::AngleAnnotationActor() controlP1->AddObserver(DraggableActorEvents::DragEvent, this, &AngleAnnotationActor::controlPointCb); controlP2->AddObserver(DraggableActorEvents::DragEvent, this, &AngleAnnotationActor::controlPointCb); controlP3->AddObserver(DraggableActorEvents::DragEvent, this, &AngleAnnotationActor::controlPointCb); + controlP1->SetcontrolledActor(this); + controlP2->SetcontrolledActor(this); + controlP3->SetcontrolledActor(this); + this->AddObserver(DraggableActorEvents::DragEvent, this, &AngleAnnotationActor::selfDragCb); } diff --git a/src/src/Rendering/Measure/ArrowAnnotationActor.cpp b/src/src/Rendering/Measure/ArrowAnnotationActor.cpp index c1b974b..dc73654 100644 --- a/src/src/Rendering/Measure/ArrowAnnotationActor.cpp +++ b/src/src/Rendering/Measure/ArrowAnnotationActor.cpp @@ -33,6 +33,9 @@ ArrowAnnotationActor::ArrowAnnotationActor() controlP2->AddObserver(DraggableActorEvents::DragEvent, this, &ArrowAnnotationActor::controlPointCb); controlP2->AddObserver(vtkCommand::EnterEvent, this, &ArrowAnnotationActor::HighlightOn); controlP2->AddObserver(vtkCommand::LeaveEvent, this, &ArrowAnnotationActor::HighlightOff); + controlP1->SetcontrolledActor(this); + controlP2->SetcontrolledActor(this); + this->AddObserver(DraggableActorEvents::DragEvent, this, &ArrowAnnotationActor::selfDragCb); } diff --git a/src/src/Rendering/Measure/EllipseAnnotationActor.cpp b/src/src/Rendering/Measure/EllipseAnnotationActor.cpp index 81bead3..de07096 100644 --- a/src/src/Rendering/Measure/EllipseAnnotationActor.cpp +++ b/src/src/Rendering/Measure/EllipseAnnotationActor.cpp @@ -80,6 +80,12 @@ EllipseAnnotationActor::EllipseAnnotationActor() { controlP_lb->AddObserver(DraggableActorEvents::DragEvent, this, &EllipseAnnotationActor::controlPointCb); controlP_rb->AddObserver(DraggableActorEvents::DragEvent, this, &EllipseAnnotationActor::controlPointCb); + controlP_lt->SetcontrolledActor(this); + controlP_rt->SetcontrolledActor(this); + controlP_lb->SetcontrolledActor(this); + controlP_rb->SetcontrolledActor(this); + + //this->AddObserver(DraggableActorEvents::DragEvent, this, &EllipseAnnotationActor::selfDragCb); diff --git a/src/src/Rendering/Measure/LineAnnotationActor.cpp b/src/src/Rendering/Measure/LineAnnotationActor.cpp index 51205a5..b90bce1 100644 --- a/src/src/Rendering/Measure/LineAnnotationActor.cpp +++ b/src/src/Rendering/Measure/LineAnnotationActor.cpp @@ -21,6 +21,8 @@ LineAnnotationActor::LineAnnotationActor() renderPoints->SetNumberOfPoints(2); controlP1->AddObserver(DraggableActorEvents::DragEvent, this, &LineAnnotationActor::controlPointCb); controlP2->AddObserver(DraggableActorEvents::DragEvent, this, &LineAnnotationActor::controlPointCb); + controlP1->SetcontrolledActor(this); + controlP2->SetcontrolledActor(this); this->AddObserver(DraggableActorEvents::DragEvent, this, &LineAnnotationActor::selfDragCb); } diff --git a/src/src/Rendering/Viewer/DICOMImageViewer.cxx b/src/src/Rendering/Viewer/DICOMImageViewer.cxx index 1532922..0bbf8b1 100644 --- a/src/src/Rendering/Viewer/DICOMImageViewer.cxx +++ b/src/src/Rendering/Viewer/DICOMImageViewer.cxx @@ -22,11 +22,12 @@ #include #include +#include "Rendering/Core/ControlPointActor.h" +#include "Rendering/Core/MarginCornerAnnotation.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" namespace { //扭转存在偏转的坐标轴 @@ -1022,12 +1023,29 @@ void DICOMImageViewer::AddMeasures(vtkObject *, unsigned long eventid, void *cal void DICOMImageViewer::RemoveMeasures(vtkObject *, unsigned long eventid, void *calldata) { auto p = static_cast(calldata); auto da = DraggableActor::SafeDownCast(p); + if (da->IsA("ControlPointActor")) + { + auto controlP = ControlPointActor::SafeDownCast(da); + if (nullptr == controlP) return; + if (nullptr == controlP->GetcontrolledActor()) return; + auto m = dynamic_cast(controlP->GetcontrolledActor()); + if (m == nullptr) return; + ClearCurrentSliceMeasure(); + measureStore->Remove(m); + this->InteractorStyle->ClearSelectedProp(); + ReloadCurrentSliceMeasure(); + this->Render(); + } + else{ auto m = dynamic_cast(da); + if (m == nullptr) return; ClearCurrentSliceMeasure(); measureStore->Remove(m); this->InteractorStyle->ClearSelectedProp(); ReloadCurrentSliceMeasure(); this->Render(); + } + } void DICOMImageViewer::DeleteSelectedMeasure() {