Skip to content

Commit

Permalink
Clean Up bone node - Display node first
Browse files Browse the repository at this point in the history
This starts by declaring the bone display node before the node itself.
This is necessary because otherwise the bone node does not have a proper
reference on its display node when loading a scene.

This implies that we can get rid of the initialization-hackish code in
the bone display node and the displayable manager.

See Issue #13668
  • Loading branch information
vovythevov committed Dec 12, 2012
1 parent 6509f6b commit 40e9747
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 30 deletions.
Expand Up @@ -38,7 +38,6 @@ vtkMRMLNodeNewMacro(vtkMRMLBoneDisplayNode);
vtkMRMLBoneDisplayNode::vtkMRMLBoneDisplayNode()
{
this->SetVisibility(1);
this->ShouldBeInitialized = true;
}

//----------------------------------------------------------------------------
Expand Down
5 changes: 0 additions & 5 deletions Modules/Loadable/Armatures/MRML/Core/vtkMRMLBoneDisplayNode.h
Expand Up @@ -78,10 +78,6 @@ class VTK_BENDER_ARMATURES_MRML_CORE_EXPORT vtkMRMLBoneDisplayNode
vtkSetVector3Macro(WidgetInteractionColor, double);
vtkGetVector3Macro(WidgetInteractionColor, double);

/// Set/Get if the widget should be initialized or not.
vtkSetMacro(ShouldBeInitialized, bool);
vtkGetMacro(ShouldBeInitialized, bool);

//--------------------------------------------------------------------------
// Bone methods
//--------------------------------------------------------------------------
Expand All @@ -99,7 +95,6 @@ class VTK_BENDER_ARMATURES_MRML_CORE_EXPORT vtkMRMLBoneDisplayNode
~vtkMRMLBoneDisplayNode();

double WidgetInteractionColor[3];
bool ShouldBeInitialized;

vtkMRMLBoneDisplayNode(const vtkMRMLBoneDisplayNode&); /// not implemented
void operator=(const vtkMRMLBoneDisplayNode&); /// not implemented
Expand Down
2 changes: 1 addition & 1 deletion Modules/Loadable/Armatures/MRML/Core/vtkMRMLBoneNode.cxx
Expand Up @@ -164,8 +164,8 @@ void vtkMRMLBoneNode::Initialize(vtkMRMLScene* mrmlScene)
}
// \tbd remove this SetScene call as it shouldn't be mandatory.
this->SetScene(mrmlScene);
this->Superclass::Initialize(mrmlScene);
this->CreateBoneDisplayNode();
this->Superclass::Initialize(mrmlScene);
}

//----------------------------------------------------------------------------
Expand Down
Expand Up @@ -211,15 +211,15 @@ ::AddBoneNode(vtkMRMLBoneNode* boneNode)
armatureWidget->UpdateBoneWithArmatureOptions(
boneWidget,
parentBoneWidget);
// For not armature widget properties HACKISH
if (boneWidget->GetBoneRepresentation())
vtkMRMLBoneDisplayNode* boneDisplayNode = boneNode->GetBoneDisplayNode();
if (boneDisplayNode)
{
boneWidget->GetBoneRepresentation()->SetOpacity(
armatureNode->GetOpacity());
boneDisplayNode->SetOpacity(armatureNode->GetOpacity());
double rgb[3];
armatureNode->GetColor(rgb);
boneWidget->GetBoneRepresentation()->GetLineProperty()->SetColor(rgb);
boneDisplayNode->SetColor(rgb);
}

boneWidget->SetShowParenthood(parentBoneWidget != 0);
boneNode->SetHasParent(parentBoneWidget != 0);

Expand Down Expand Up @@ -601,8 +601,6 @@ void vtkMRMLArmatureDisplayableManager::vtkInternal
::UpdateBoneWidgetFromNode(vtkMRMLBoneNode* boneNode,
vtkBoneWidget* boneWidget)
{
vtkMRMLBoneDisplayNode* boneDisplayNode =
boneNode ? boneNode->GetBoneDisplayNode() : 0;
if (!boneNode)
{
return;
Expand All @@ -616,6 +614,9 @@ ::UpdateBoneWidgetFromNode(vtkMRMLBoneNode* boneNode,
this->BoneNodes.find(boneNode)->second = boneWidget;
}

vtkMRMLBoneDisplayNode* boneDisplayNode =
boneNode ? boneNode->GetBoneDisplayNode() : 0;

// We need to stop listening to the boneWidget when changing its properties
// according to the node. Otherwise it will send ModifiedEvent() for the
// first property changed, thus updating the node.
Expand All @@ -627,22 +628,6 @@ ::UpdateBoneWidgetFromNode(vtkMRMLBoneNode* boneNode,
boneNode->PasteBoneNodeProperties(boneWidget);
if (boneDisplayNode)
{
if (boneDisplayNode->GetShouldBeInitialized())
{
// This hackish code is here to prevent the update of the widget
// by the display node before the display node was initialized.
int wasModifying = boneDisplayNode->StartModify();
double normalColor[3];
boneWidget->GetBoneRepresentation()->GetLineProperty()
->GetColor(normalColor);
boneDisplayNode->SetColor(normalColor);

boneDisplayNode->CopyBoneWidgetDisplayProperties(boneWidget);
boneDisplayNode->SetSelected(true);
boneDisplayNode->SetShouldBeInitialized(false);
boneDisplayNode->EndModify(wasModifying);
}

boneDisplayNode->PasteBoneDisplayNodeProperties(boneWidget);
}
boneWidget->AddObserver(vtkCommand::ModifiedEvent,
Expand Down

0 comments on commit 40e9747

Please sign in to comment.