Skip to content

Commit

Permalink
Enforce representation for armature's node
Browse files Browse the repository at this point in the history
A bone from an armature now always have a representation. This implies that
the BonesRepresentation can be declared and used for storing the
AlwaysOnTop property.

Also, make sure there are no memory leaks and actually register the
given BonesRepresentation (like said in the comments, but not in the code).

See Issue #13733
  • Loading branch information
vovythevov committed Nov 29, 2012
1 parent 53fe675 commit 5b2c67d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
54 changes: 28 additions & 26 deletions Libs/VTK/Widgets/vtkArmatureWidget.cxx
Expand Up @@ -182,12 +182,13 @@ vtkArmatureWidget::vtkArmatureWidget()
// Init map and root
this->Bones = new ArmatureTreeNodeVectorType;
// Init bones properties
this->BonesRepresentation = 0;
vtkBoneRepresentation* defaultRep = vtkBoneRepresentation::New();
defaultRep->SetAlwaysOnTop(0);

This comment has been minimized.

Copy link
@finetjul

finetjul Nov 29, 2012

Contributor

why do you need to set always on top differently than the default ?
This is very confusing if vtkBoneWidget is always on top by default, but vtkArmatureWidget is not.

This comment has been minimized.

Copy link
@vovythevov

vovythevov Nov 29, 2012

Author Owner

Do you mean the default for the armatures of the default in the vtkBoneRepresentation ?

This comment has been minimized.

Copy link
@finetjul

finetjul Nov 29, 2012

Contributor

I only meant that "default for the armatures" should be the same as the "default for the bone representation".

Now if you ask me, you got to pick, either they both are on or off.
Which one makes more sense to you ?

Probably off, (but keep in mind that Slicer wants them on by default)

This comment has been minimized.

Copy link
@vovythevov

vovythevov Nov 29, 2012

Author Owner

Agreed. I though that the default was off in the bone representation too.

This comment has been minimized.

Copy link
@finetjul

finetjul Nov 29, 2012

Contributor

if you thought it was off, then you shouldn't have set it to 0 again here :-P

This comment has been minimized.

Copy link
@vovythevov

vovythevov Nov 29, 2012

Author Owner

Just for the laugh, this is the answer I almost made to your first question:
"This is not really necessary for now. But I tend to be paranoid of this things; someone (i.e. me) may change the default for the bone representation and not change this. "

:)

This comment has been minimized.

Copy link
@finetjul

finetjul Nov 29, 2012

Contributor

:)

this->BonesRepresentation = defaultRep;
this->WidgetState = vtkArmatureWidget::Rest;
this->ShowAxes = vtkBoneWidget::Hidden;
this->ShowParenthood = true;
this->ShouldResetPoseToRest = true;
this->BonesAlwaysOnTop = 0;
}

//----------------------------------------------------------------------------
Expand All @@ -201,23 +202,18 @@ vtkArmatureWidget::~vtkArmatureWidget()
(*it)->Bone->Delete(); // Delete bone
}

if (this->BonesRepresentation)
{
this->BonesRepresentation->Delete();
}

this->BonesRepresentation->Delete();
this->ArmatureWidgetCallback->Delete();
}

//----------------------------------------------------------------------------
void vtkArmatureWidget::CreateDefaultRepresentation()
{
vtkArmatureRepresentation* armatureRepresentation =
this->GetArmatureRepresentation();
if (!armatureRepresentation)
if (! this->GetArmatureRepresentation())
{
armatureRepresentation = vtkArmatureRepresentation::New();
this->SetRepresentation(armatureRepresentation);
vtkSmartPointer<vtkArmatureRepresentation> rep =
vtkSmartPointer<vtkArmatureRepresentation>::New();
this->SetRepresentation(rep);
}
}

Expand Down Expand Up @@ -464,12 +460,12 @@ void vtkArmatureWidget::SetBonesRepresentation(vtkBoneRepresentation* newRep)
return;
}

if (this->BonesRepresentation)
{
this->BonesRepresentation->Delete();
}
newRep->SetAlwaysOnTop(this->BonesRepresentation->GetAlwaysOnTop());

this->BonesRepresentation->Delete();
this->BonesRepresentation = newRep;
this->BonesRepresentation->Register(this);

for (NodeIteratorType it = this->Bones->begin();
it != this->Bones->end(); ++it)
{
Expand All @@ -496,6 +492,10 @@ void vtkArmatureWidget::SetBoneRepresentation(vtkBoneWidget* bone)
}

bone->SetRepresentation(copiedRepresentation);
if (copiedRepresentation)
{
copiedRepresentation->Delete();
}
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -785,26 +785,28 @@ void vtkArmatureWidget::ResetPoseToRest()
//----------------------------------------------------------------------------
void vtkArmatureWidget::SetBonesAlwaysOnTop(int onTop)
{
if (onTop == this->BonesAlwaysOnTop)
if (this->BonesRepresentation->GetAlwaysOnTop() == onTop)
{
return;
}
this->BonesAlwaysOnTop = onTop;

if (this->GetBonesRepresentation())
this->BonesRepresentation->SetAlwaysOnTop(onTop);
for (NodeIteratorType it = this->Bones->begin();
it != this->Bones->end(); ++it)
{
this->BonesRepresentation->SetAlwaysOnTop(this->BonesAlwaysOnTop);

for (NodeIteratorType it = this->Bones->begin();
it != this->Bones->end(); ++it)
{
(*it)->Bone->GetBoneRepresentation()->SetAlwaysOnTop(this->BonesAlwaysOnTop);
}
(*it)->Bone->GetBoneRepresentation()->SetAlwaysOnTop(
this->BonesRepresentation->GetAlwaysOnTop());
}

this->Modified();
}

//----------------------------------------------------------------------------
int vtkArmatureWidget::GetBonesAlwaysOnTop()
{
return this->BonesRepresentation->GetAlwaysOnTop();
}

//----------------------------------------------------------------------------
void vtkArmatureWidget
::SetBoneWorldToParentTransform(vtkBoneWidget* bone, vtkBoneWidget* parent)
Expand Down
3 changes: 1 addition & 2 deletions Libs/VTK/Widgets/vtkArmatureWidget.h
Expand Up @@ -273,7 +273,7 @@ class VTK_BENDER_WIDGETS_EXPORT vtkArmatureWidget : public vtkAbstractWidget
// This can be set even if the bones do not have any representation.
// @sa vtkBoneRepresentation
void SetBonesAlwaysOnTop(int onTop);
vtkGetMacro(BonesAlwaysOnTop, int);
int GetBonesAlwaysOnTop();

protected:
vtkArmatureWidget();
Expand All @@ -299,7 +299,6 @@ class VTK_BENDER_WIDGETS_EXPORT vtkArmatureWidget : public vtkAbstractWidget
int ShowAxes;
int ShowParenthood;
bool ShouldResetPoseToRest;
int BonesAlwaysOnTop;

// Add/Remove all the necessaries observers to a bone
void AddBoneObservers(vtkBoneWidget* bone);
Expand Down

0 comments on commit 5b2c67d

Please sign in to comment.