Skip to content

Commit

Permalink
BUG: DrawerPrimitive's destructor is now responsible for emitting the…
Browse files Browse the repository at this point in the history
… "dying" signal instead of delegating this responsibility to the subclasses' destructor (at the same time, this fixes a bug with DrawerPoint, whose destructor did not include the signal). #3000

When applying this change, another bug has appeared: temporary primitives are not removed from Drawer, such as the polylines of the Polygonal ROI and the eraser's rectangle. To solve this problem, a new attribute is created for DrawerPrimitive (a vtkProp) which is returned by DrawerPrimitive::getAsVtkProp. The DrawerPrimitive's subclasses fill the parent's attribute and call the parent's DrawerPrimitive::getAsVtkProp to return the vtkProp.
  • Loading branch information
xiberta committed May 17, 2022
1 parent afd677a commit 334bc62
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 35 deletions.
2 changes: 1 addition & 1 deletion starviewer/src/core/drawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void Drawer::removeAllPrimitives()
if (!primitive->hasOwners())
{
m_2DViewer->getRenderer()->RemoveViewProp(primitive->getAsVtkProp());
delete primitive;
delete primitive; // automatically deleted from primitive containers by means of signals and slots
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions starviewer/src/core/drawerarrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ DrawerArrow::DrawerArrow(QObject *parent)
m_propAssembly->AddPart(m_tipBottomActor);
m_propAssembly->AddPart(m_tipTopActor);
m_propAssembly->AddPart(m_lineActor);
m_vtkProp = m_propAssembly;
}

DrawerArrow::~DrawerArrow()
{
emit dying(this);
}

const Vector3& DrawerArrow::getStartPoint() const
Expand Down Expand Up @@ -88,11 +88,6 @@ void DrawerArrow::setViewPlaneNormal(const Vector3 &normal)
emit changed();
}

vtkProp* DrawerArrow::getAsVtkProp()
{
return m_propAssembly;
}

double DrawerArrow::getDistanceToPoint(double *point3D, double closestPoint[3])
{
return MathTools::getPointToFiniteLineDistance(point3D, m_startPoint.toArray().data(), m_endPoint.toArray().data(), closestPoint);
Expand Down
1 change: 0 additions & 1 deletion starviewer/src/core/drawerarrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class DrawerArrow : public DrawerPrimitive
/// Sets the view plane normal needed to draw the tip lines with the correct orientation.
void setViewPlaneNormal(const Vector3 &normal);

vtkProp* getAsVtkProp() override;
double getDistanceToPoint(double *point3D, double closestPoint[3]) override;
void getBounds(double bounds[6]) override;

Expand Down
4 changes: 2 additions & 2 deletions starviewer/src/core/drawerbitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ DrawerBitmap::DrawerBitmap(QObject *parent)

DrawerBitmap::~DrawerBitmap()
{
emit dying(this);
}

void DrawerBitmap::setOrigin(double origin[3])
Expand Down Expand Up @@ -109,14 +108,15 @@ vtkProp* DrawerBitmap::getAsVtkProp()
m_imageActor->SetInputData(mapTransparency->GetOutput());
m_imageActor->SetDisplayExtent(0, m_width - 1, 0, m_height - 1, 0, 0);
m_imageActor->SetVisibility(this->isVisible());
m_vtkProp = m_imageActor;
}
else
{
DEBUG_LOG("Error al passar les dades del bitmap a format vtkImageActor o bé no hi ha dades");
}
}

return m_imageActor;
return DrawerPrimitive::getAsVtkProp();
}

double DrawerBitmap::getDistanceToPoint(double *point3D, double closestPoint[3])
Expand Down
11 changes: 3 additions & 8 deletions starviewer/src/core/drawercrosshair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ DrawerCrossHair::DrawerCrossHair(QObject *parent)

DrawerCrossHair::~DrawerCrossHair()
{
emit dying(this);

m_worldCoordinate->Delete();

if (m_vtkPropAssembly)
Expand Down Expand Up @@ -87,7 +85,7 @@ void DrawerCrossHair::setCentrePoint(double x, double y, double z)
emit changed();
}

vtkPropAssembly* DrawerCrossHair::getAsVtkPropAssembly()
vtkProp* DrawerCrossHair::getAsVtkProp()
{
if (!m_vtkPropAssembly)
{
Expand All @@ -100,13 +98,10 @@ vtkPropAssembly* DrawerCrossHair::getAsVtkPropAssembly()
m_vtkPropAssembly->AddPart(m_lineDown->getAsVtkProp());
m_vtkPropAssembly->AddPart(m_lineLeft->getAsVtkProp());
m_vtkPropAssembly->AddPart(m_lineRight->getAsVtkProp());
m_vtkProp = m_vtkPropAssembly;
}
return m_vtkPropAssembly;
}

vtkProp* DrawerCrossHair::getAsVtkProp()
{
return (vtkProp*)getAsVtkPropAssembly();
return DrawerPrimitive::getAsVtkProp();
}

void DrawerCrossHair::update()
Expand Down
2 changes: 0 additions & 2 deletions starviewer/src/core/drawercrosshair.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ Q_OBJECT
/// Afegim el primer punt de la línia
void setCentrePoint(double x, double y, double z);

vtkPropAssembly* getAsVtkPropAssembly();

vtkProp* getAsVtkProp();

double getDistanceToPoint(double *point3D, double closestPoint[3]);
Expand Down
5 changes: 2 additions & 3 deletions starviewer/src/core/drawerline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ DrawerLine::DrawerLine(QObject *parent)

DrawerLine::~DrawerLine()
{
emit dying(this);

if (m_vtkActor)
{
m_vtkActor->Delete();
Expand Down Expand Up @@ -107,8 +105,9 @@ vtkProp* DrawerLine::getAsVtkProp()

m_vtkPropAssembly->AddPart(m_vtkBackgroundActor);
m_vtkPropAssembly->AddPart(m_vtkActor);
m_vtkProp = m_vtkPropAssembly;
}
return m_vtkPropAssembly;
return DrawerPrimitive::getAsVtkProp();
}

double* DrawerLine::getFirstPoint()
Expand Down
3 changes: 2 additions & 1 deletion starviewer/src/core/drawerpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ vtkProp* DrawerPoint::getAsVtkProp()
m_pointMapper = vtkPolyDataMapper::New();
m_pointMapper->SetInputConnection(m_pointSphere->GetOutputPort());
m_pointActor->SetMapper(m_pointMapper);
m_vtkProp = m_pointActor;
}

// Li donem els atributs
m_pointSphere->SetCenter(m_position);

updateVtkActorProperties();

return m_pointActor;
return DrawerPrimitive::getAsVtkProp();
}

void DrawerPoint::update()
Expand Down
5 changes: 2 additions & 3 deletions starviewer/src/core/drawerpolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ DrawerPolygon::DrawerPolygon(QObject *parent)

DrawerPolygon::~DrawerPolygon()
{
emit dying(this);

if (m_vtkPropAssembly)
{
m_vtkPolyData->Delete();
Expand Down Expand Up @@ -137,7 +135,7 @@ QList<Line3D> DrawerPolygon::getSegments()
vtkProp* DrawerPolygon::getAsVtkProp()
{
updateVtkProp();
return m_vtkPropAssembly;
return DrawerPrimitive::getAsVtkProp();
}

void DrawerPolygon::update()
Expand Down Expand Up @@ -190,6 +188,7 @@ void DrawerPolygon::buildVtkPipeline()
m_vtkPropAssembly = vtkPropAssembly::New();
m_vtkPropAssembly->AddPart(m_vtkBackgroundActor);
m_vtkPropAssembly->AddPart(m_vtkActor);
m_vtkProp = m_vtkPropAssembly;
}

void DrawerPolygon::buildVtkPoints()
Expand Down
5 changes: 2 additions & 3 deletions starviewer/src/core/drawerpolyline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ DrawerPolyline::DrawerPolyline(QObject *parent)

DrawerPolyline::~DrawerPolyline()
{
emit dying(this);

if (m_vtkPolydata)
{
m_vtkPolydata->Delete();
Expand Down Expand Up @@ -141,8 +139,9 @@ vtkProp* DrawerPolyline::getAsVtkProp()

m_vtkPropAssembly->AddPart(m_vtkBackgroundActor);
m_vtkPropAssembly->AddPart(m_vtkActor);
m_vtkProp = m_vtkPropAssembly;
}
return m_vtkPropAssembly;
return DrawerPrimitive::getAsVtkProp();
}

void DrawerPolyline::update()
Expand Down
7 changes: 5 additions & 2 deletions starviewer/src/core/drawerprimitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ namespace udg {

DrawerPrimitive::DrawerPrimitive(QObject *parent)
: QObject(parent), m_internalRepresentation(VTKRepresentation), m_isVisible(true), m_coordinateSystem(WorldCoordinateSystem), m_color(QColor(255, 165, 0)),
m_isFilled(false), m_linePattern(ContinuousLinePattern), m_lineWidth(2.0), m_opacity(1.0), m_modified(false), m_referenceCount(0), m_coordinate(0)
m_isFilled(false), m_linePattern(ContinuousLinePattern), m_lineWidth(2.0), m_opacity(1.0), m_modified(false), m_vtkProp(nullptr), m_referenceCount(0),
m_coordinate(0)
{
m_isErasable = true;
connect(this, SIGNAL(changed()), SLOT(setModified()));
}

DrawerPrimitive::~DrawerPrimitive()
{
emit dying(this);

if (m_coordinate)
{
m_coordinate->Delete();
Expand Down Expand Up @@ -133,7 +136,7 @@ bool DrawerPrimitive::isErasable() const

vtkProp* DrawerPrimitive::getAsVtkProp()
{
return 0;
return m_vtkProp;
}

bool DrawerPrimitive::isModified() const
Expand Down
3 changes: 3 additions & 0 deletions starviewer/src/core/drawerprimitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ protected slots:
/// Indica si alguna de les propietats s'han modificat
bool m_modified;

/// Stores the \c vtkProp representing this primitive.
vtkProp* m_vtkProp;

private:
/// Propietat d'esborrabilitat de la primitiva
bool m_isErasable;
Expand Down
6 changes: 3 additions & 3 deletions starviewer/src/core/drawertext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ DrawerText::DrawerText(QObject *parent)

DrawerText::~DrawerText()
{
emit dying(this);

if (m_vtkActor)
{
m_vtkActor->Delete();
Expand Down Expand Up @@ -87,8 +85,10 @@ vtkProp* DrawerText::getAsVtkProp()

// Li donem els atributs
updateVtkActorProperties();

m_vtkProp = m_vtkActor;
}
return m_vtkActor;
return DrawerPrimitive::getAsVtkProp();
}

void DrawerText::update()
Expand Down

0 comments on commit 334bc62

Please sign in to comment.