fix: fix a measure class memory leak bug

This commit is contained in:
kradchen
2025-07-22 14:41:56 +08:00
parent b0fc84756f
commit f718b2c919
16 changed files with 75 additions and 31 deletions

View File

@@ -15,8 +15,7 @@
vtkStandardNewMacro(ControlPointActor)
ControlPointActor::ControlPointActor()
: shadowData(vtkPolyData::New())
, controlledActor(nullptr) {
: shadowData(vtkPolyData::New()) {
BaseDataPoints->SetNumberOfPoints(1);
renderPoints->SetNumberOfPoints(1);
renderPoints->SetPoint(0, 0, 0, 0);

View File

@@ -29,8 +29,6 @@ public:
void SetWorldPosition(double *pos) {
SetWorldPosition(pos[0], pos[1], pos[2]);
}
vtkSetObjectMacro(controlledActor,DraggableActor);
vtkGetObjectMacro(controlledActor,DraggableActor);
protected:
@@ -39,7 +37,6 @@ protected:
~ControlPointActor() override;
vtkPolyData *shadowData;
DraggableActor * controlledActor;
};

View File

@@ -19,9 +19,11 @@
vtkStandardNewMacro(DraggableActor)
DraggableActor::DraggableActor()
: BaseDataPoints(vtkPoints::New()), renderPoints(vtkPoints::New()), tempStorePoints(nullptr),
renderData(vtkPolyData::New()), actor2D(vtkActor2D::New()), shadow2D(vtkActor2D::New()),
senseArea(vtkActor2D::New()), text(nullptr), Renderer(nullptr), OnDrag(nullptr), OnDragEnd(nullptr) {
: BaseDataPoints(vtkPoints::New()), renderPoints(vtkPoints::New()), tempStorePoints(nullptr),
renderData(vtkPolyData::New()), actor2D(vtkActor2D::New()), shadow2D(vtkActor2D::New()),
senseArea(vtkActor2D::New()), text(nullptr), Renderer(nullptr), OnDrag(nullptr), OnDragEnd(nullptr),
controlledActor(nullptr)
{
//if (Renderer) Renderer->RemoveViewProp(this);
vtkNew<vtkPolyDataMapper2D> mapper;
mapper->SetInputData(renderData);
@@ -251,3 +253,5 @@ void DraggableActor::Show() {

View File

@@ -135,6 +135,9 @@ public:
void Show();
vtkSetClampMacro(MapMode,PointMapMode,MapToSlice,MapToWorld);
vtkSetObjectMacro(controlledActor,DraggableActor);
vtkGetObjectMacro(controlledActor,DraggableActor);
protected:
DraggableActor();
@@ -168,6 +171,8 @@ private:
DragCallBack OnDrag = nullptr;
DragCallBack OnDragEnd = nullptr;
DraggableActor * controlledActor;
};

View File

@@ -14,16 +14,10 @@
#include "Rendering/Core/ControlPointActor.h"
vtkStandardNewMacro(AngleAnnotationActor)
AngleAnnotationActor::AngleAnnotationActor()
: DraggableActor()
, controlP1(ControlPointActor::New())
, controlP2(ControlPointActor::New())
, controlP3(ControlPointActor::New())
, textProperty(nullptr)
, placedPointCount(0)
: DraggableActor(), controlP1(ControlPointActor::New()), controlP2(ControlPointActor::New()), controlP3(ControlPointActor::New()), textProperty(nullptr), placedPointCount(0)
{
text = vtkActor2D::New();
@@ -227,3 +221,12 @@ void AngleAnnotationActor::selfDragCb(vtkObject *, unsigned long, void *data) {
MapScreenPointToWorld(pos[0], pos[1], this->Renderer, result);
controlP3->SetWorldPosition(result);
}
void AngleAnnotationActor::ForceDelete()
{
controlP1->SetcontrolledActor(nullptr);
controlP2->SetcontrolledActor(nullptr);
controlP3->SetcontrolledActor(nullptr);
this->SetRenderer(nullptr);
Delete();
}

View File

@@ -53,10 +53,7 @@ vtkTypeMacro(AngleAnnotationActor, DraggableActor);
NextMeasureMacro(AngleAnnotationActor);
void ForceDelete() override {
this->SetRenderer(nullptr);
DraggableActor::Delete();
}
void ForceDelete() override;
protected:
AngleAnnotationActor();

View File

@@ -21,7 +21,9 @@ ArrowAnnotationActor::ArrowAnnotationActor()
shadow2D->GetProperty()->SetLineWidth(5.0);
arrowRenderPoints->SetNumberOfPoints(2);
controlP1->SetcontrolledActor(nullptr);
controlP1->Delete();
controlP2->SetcontrolledActor(nullptr);
controlP2->Delete();
controlP1 = ControlPointRActor::New();
controlP2 = ControlPointRActor::New();

View File

@@ -293,7 +293,7 @@ void EllipseAnnotationActor::drawCircle(double *p1, double *p2) {
}
double angle = 0;
int id = 0;
while (angle <= 2.0 * vtkMath::Pi() + (2.0 * vtkMath::Pi() / (GRANULARITY * 1.0))) {
while (id<=GRANULARITY) {
double p[3]={0};
p[0] = p1[0];
p[1] = p1[1];
@@ -656,6 +656,16 @@ bool EllipseAnnotationActor::onMeasureLeftButtonUp(vtkRenderWindowInteractor *ir
return false;
}
void EllipseAnnotationActor::ForceDelete()
{
controlP_lt->SetcontrolledActor(nullptr);
controlP_rt->SetcontrolledActor(nullptr);
controlP_lb->SetcontrolledActor(nullptr);
controlP_rb->SetcontrolledActor(nullptr);
SetRenderer(nullptr);
Delete();
}
void EllipseAnnotationActor::Transform(float x, float y) {
DraggableActor::Transform(x, y);
this->controlPointsTransform(x, y);

View File

@@ -40,6 +40,8 @@ public:
bool onMeasureLeftButtonUp(vtkRenderWindowInteractor *) override;
void ForceDelete() override;
NextMeasureMacro(EllipseAnnotationActor);
protected:
EllipseAnnotationActor();

View File

@@ -12,7 +12,8 @@
vtkStandardNewMacro(LineAnnotationActor)
LineAnnotationActor::LineAnnotationActor()
: DraggableActor(), controlP1(ControlPointActor::New()), controlP2(ControlPointActor::New()) {
: DraggableActor(), controlP1(ControlPointActor::New()), controlP2(ControlPointActor::New())
{
BaseDataPoints->SetNumberOfPoints(2);
BaseDataPoints->SetPoint(0, 0, 0, 0);
BaseDataPoints->SetPoint(1, 512, 512, 0);
@@ -31,7 +32,6 @@ LineAnnotationActor::~LineAnnotationActor() {
controlP1 = nullptr;
controlP2->Delete();
controlP2 = nullptr;
}
void LineAnnotationActor::SetWorldPosition1(double x, double y, double z) {
@@ -120,3 +120,11 @@ bool LineAnnotationActor::onMeasureLeftButtonDown(vtkRenderWindowInteractor *ire
bool LineAnnotationActor::onMeasureLeftButtonUp(vtkRenderWindowInteractor *iren) {
return false;
}
void LineAnnotationActor::ForceDelete()
{
controlP1->SetcontrolledActor(nullptr);
controlP2->SetcontrolledActor(nullptr);
SetRenderer(nullptr);
Delete();
}

View File

@@ -42,10 +42,7 @@ public:
NextMeasureMacro(LineAnnotationActor);
void ForceDelete() override {
this->SetRenderer(nullptr);
DraggableActor::Delete();
}
void ForceDelete() override;
protected:
LineAnnotationActor();

View File

@@ -47,7 +47,6 @@ public:
void ForceDelete() override {
this->SetRenderer(nullptr);
printf("OpenPolyAnnotationActor delete \r\n");
Delete();
}

View File

@@ -76,7 +76,18 @@ void RoundAnnotationActor::BuildShape() {
}
}
RoundAnnotationActor::RoundAnnotationActor() {
void RoundAnnotationActor::ForceDelete()
{
controlP_lt->SetcontrolledActor(nullptr);
controlP_rt->SetcontrolledActor(nullptr);
controlP_lb->SetcontrolledActor(nullptr);
controlP_rb->SetcontrolledActor(nullptr);
SetRenderer(nullptr);
Delete();
}
RoundAnnotationActor::RoundAnnotationActor()
{
controlP_rt = ControlPointActor::New();
controlP_lb = ControlPointActor::New();
controlP_rb = ControlPointActor::New();
@@ -279,7 +290,7 @@ void RoundAnnotationActor::drawCircle(double *p1, double *p2) {
double angle = 0;
int id = 0;
while (angle <= 2.0 * vtkMath::Pi() + (2.0 * vtkMath::Pi() / (GRANULARITY * 1.0))) {
while (id<=GRANULARITY) {
double p[3]={0};
p[0] = p1[0];
p[1] = p1[1];

View File

@@ -38,6 +38,8 @@ public:
bool onMeasureLeftButtonUp(vtkRenderWindowInteractor *) override;
NextMeasureMacro(RoundAnnotationActor);
void ForceDelete() override;
protected:
RoundAnnotationActor();

View File

@@ -69,7 +69,14 @@ void TextAnnotationActor::ResetTextProp() {
mTextProperty->SetBackgroundOpacity(0.0);
}
TextAnnotationActor::TextAnnotationActor() {
void TextAnnotationActor::ForceDelete()
{
SetRenderer(nullptr);
Delete();
}
TextAnnotationActor::TextAnnotationActor()
{
BaseDataPoints->SetNumberOfPoints(2);
BaseDataPoints->SetPoint(0, 0, 0, 0);
BaseDataPoints->SetPoint(1, 512, 512, 0);
@@ -86,7 +93,6 @@ TextAnnotationActor::TextAnnotationActor() {
ResetTextProp();
}
TextAnnotationActor::~TextAnnotationActor() {
mTextProperty = nullptr;
text->Delete();

View File

@@ -59,6 +59,8 @@ vtkTypeMacro(TextAnnotationActor, DraggableActor);
bool onMeasureLeftButtonUp(vtkRenderWindowInteractor *) override;
NextMeasureMacro(TextAnnotationActor);
void ForceDelete() override;
protected:
TextAnnotationActor();