Skip to content

Commit

Permalink
Add envelope radius slider
Browse files Browse the repository at this point in the history
Adding a slider to control the envelope radius. Also adding the forgotten
tooltips at the same time. Much like the show envelope checkbox, this
could be simplified with issue 13779.

Note: The maximum radius was set to 100 but it is very much arbitrary.

See Issue #13680
  • Loading branch information
vovythevov committed Jan 9, 2013
1 parent 1cde363 commit a61df61
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 61 deletions.
32 changes: 32 additions & 0 deletions Modules/Loadable/Armatures/MRML/Core/vtkMRMLArmatureNode.cxx
Expand Up @@ -29,6 +29,7 @@

// VTK includes
#include <vtkArmatureRepresentation.h>
#include <vtkBoneEnvelopeRepresentation.h>
#include <vtkBoneRepresentation.h>
#include <vtkBoneWidget.h>
#include <vtkCallbackCommand.h>
Expand Down Expand Up @@ -133,6 +134,8 @@ void vtkMRMLArmatureNode::WriteXML(ostream& of, int nIndent)
<< this->ArmatureProperties->GetShowParenthood() << "\"";
of << indent << " ShowEnvelopes=\""
<< this->GetShowEnvelopes() << "\"";
of << indent << " EnvelopesRadius=\""
<< this->GetEnvelopesRadius() << "\"";

of << indent << " Visibility=\"" << this->GetVisibility() << "\"";
of << indent << " Opacity=\"" << this->GetOpacity() << "\"";
Expand Down Expand Up @@ -198,6 +201,11 @@ void vtkMRMLArmatureNode::ReadXMLAttributes(const char** atts)
this->SetShowEnvelopes(
vtkMRMLNodeHelper::StringToInt(attValue));
}
else if (!strcmp(attName, "EnvelopesRadius"))
{
this->SetEnvelopesRadius(
vtkMRMLNodeHelper::StringToDouble(attValue));
}
}
this->EndModify(disabledModify);
}
Expand Down Expand Up @@ -411,6 +419,27 @@ int vtkMRMLArmatureNode::GetShowEnvelopes()
->GetShowEnvelope();
}

//---------------------------------------------------------------------------
void vtkMRMLArmatureNode::SetEnvelopesRadius(double radius)
{
double diff = fabs(radius) - fabs(this->GetEnvelopesRadius());
if (fabs(diff) < 1e-6)
{
return;
}

this->ArmatureProperties->GetBonesRepresentation()
->GetEnvelope()->SetRadius(radius);
this->Modified();
}

//---------------------------------------------------------------------------
double vtkMRMLArmatureNode::GetEnvelopesRadius()
{
return this->ArmatureProperties->GetBonesRepresentation()
->GetEnvelope()->GetRadius();
}

/*
//---------------------------------------------------------------------------
void vtkMRMLArmatureNode
Expand Down Expand Up @@ -502,6 +531,8 @@ ::CopyArmatureWidgetProperties(vtkArmatureWidget* armatureWidget)

this->SetShowEnvelopes(
armatureWidget->GetBonesRepresentation()->GetShowEnvelope());
this->SetEnvelopesRadius(
armatureWidget->GetBonesRepresentation()->GetEnvelope()->GetRadius());
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -564,6 +595,7 @@ ::PasteArmatureNodeProperties(vtkArmatureWidget* armatureWidget)
boneDisplayNode->SetOpacity(this->GetOpacity());

boneDisplayNode->SetShowEnvelope(this->GetShowEnvelopes());
boneDisplayNode->SetEnvelopeRadius(this->GetEnvelopesRadius());
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Modules/Loadable/Armatures/MRML/Core/vtkMRMLArmatureNode.h
Expand Up @@ -195,6 +195,11 @@ class VTK_BENDER_ARMATURES_MRML_CORE_EXPORT vtkMRMLArmatureNode
void SetShowEnvelopes(int show);
int GetShowEnvelopes();

/// Set/Get the bone's envelopes radius.
/// \sa SetShowEnvelopes(), GetShowEnvelopes()
void SetEnvelopesRadius(double radius);
double GetEnvelopesRadius();

//--------------------------------------------------------------------------
// Bone methods
//--------------------------------------------------------------------------
Expand Down
16 changes: 14 additions & 2 deletions Modules/Loadable/Armatures/MRML/Core/vtkMRMLBoneDisplayNode.cxx
Expand Up @@ -27,10 +27,11 @@
#include <vtkProperty.h>

// Bender includes
#include <vtkCylinderBoneRepresentation.h>
#include <vtkDoubleConeBoneRepresentation.h>
#include <vtkBoneEnvelopeRepresentation.h>
#include <vtkBoneRepresentation.h>
#include <vtkBoneWidget.h>
#include <vtkCylinderBoneRepresentation.h>
#include <vtkDoubleConeBoneRepresentation.h>

//----------------------------------------------------------------------------
vtkMRMLNodeNewMacro(vtkMRMLBoneDisplayNode);
Expand All @@ -39,6 +40,7 @@ vtkMRMLNodeNewMacro(vtkMRMLBoneDisplayNode);
vtkMRMLBoneDisplayNode::vtkMRMLBoneDisplayNode()
{
this->ShowEnvelope = 0;
this->EnvelopeRadius = 10.0;
this->SetVisibility(1);
}

Expand All @@ -58,6 +60,7 @@ void vtkMRMLBoneDisplayNode::WriteXML(ostream& of, int nIndent)
<< this->InteractionColor[1] << " "
<< this->InteractionColor[2] << "\"";
of << indent << " ShowEnvelope=\"" << this->ShowEnvelope << "\"";
of << indent << " EnvelopeRadius=\"" << this->EnvelopeRadius << "\"";
}

//----------------------------------------------------------------------------
Expand All @@ -83,6 +86,11 @@ void vtkMRMLBoneDisplayNode::ReadXMLAttributes(const char** atts)
this->SetShowEnvelope(
vtkMRMLNodeHelper::StringToInt(attValue));
}
if (!strcmp(attName, "EnvelopeRadius"))
{
this->SetShowEnvelope(
vtkMRMLNodeHelper::StringToDouble(attValue));
}
}
this->EndModify(disabledModify);
}
Expand Down Expand Up @@ -154,6 +162,8 @@ ::CopyBoneWidgetDisplayProperties(vtkBoneWidget* boneWidget)

this->SetShowEnvelope(
boneWidget->GetBoneRepresentation()->GetShowEnvelope());
this->SetEnvelopeRadius(
boneWidget->GetBoneRepresentation()->GetEnvelope()->GetRadius());
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -211,4 +221,6 @@ ::PasteBoneDisplayNodeProperties(vtkBoneWidget* boneWidget)
// -- Envelope --
boneWidget->GetBoneRepresentation()->SetShowEnvelope(
this->GetShowEnvelope());
boneWidget->GetBoneRepresentation()->GetEnvelope()->SetRadius(
this->GetEnvelopeRadius());
}
5 changes: 5 additions & 0 deletions Modules/Loadable/Armatures/MRML/Core/vtkMRMLBoneDisplayNode.h
Expand Up @@ -82,6 +82,10 @@ class VTK_BENDER_ARMATURES_MRML_CORE_EXPORT vtkMRMLBoneDisplayNode
vtkGetMacro(ShowEnvelope,int);
vtkBooleanMacro(ShowEnvelope,int);

vtkSetMacro(EnvelopeRadius, double);
vtkGetMacro(EnvelopeRadius, double);


//--------------------------------------------------------------------------
// Bone methods
//--------------------------------------------------------------------------
Expand All @@ -100,6 +104,7 @@ class VTK_BENDER_ARMATURES_MRML_CORE_EXPORT vtkMRMLBoneDisplayNode

double InteractionColor[3];
int ShowEnvelope;
double EnvelopeRadius;

vtkMRMLBoneDisplayNode(const vtkMRMLBoneDisplayNode&); /// not implemented
void operator=(const vtkMRMLBoneDisplayNode&); /// not implemented
Expand Down
Expand Up @@ -218,6 +218,9 @@ ::AddBoneNode(vtkMRMLBoneNode* boneNode)
double rgb[3];
armatureNode->GetColor(rgb);
boneDisplayNode->SetColor(rgb);

boneDisplayNode->SetShowEnvelope(armatureNode->GetShowEnvelopes());
boneDisplayNode->SetEnvelopeRadius(armatureNode->GetEnvelopesRadius());
}

boneWidget->SetShowParenthood(parentBoneWidget != 0);
Expand Down
156 changes: 97 additions & 59 deletions Modules/Loadable/Armatures/Resources/UI/qSlicerArmaturesModule.ui
Expand Up @@ -134,6 +134,34 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="3">
<widget class="QComboBox" name="ArmatureRepresentationComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Change the bones representation.</string>
</property>
<property name="currentIndex">
<number>2</number>
</property>
<item>
<property name="text">
<string>Line</string>
</property>
</item>
<item>
<property name="text">
<string>Cylinder</string>
</property>
</item>
<item>
<property name="text">
<string>Octohedron</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="ArmatureColorLabel">
<property name="text">
Expand Down Expand Up @@ -190,6 +218,29 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="BonesAlwaysOnTopLabel">
<property name="text">
<string>X-Ray mode:</string>
</property>
<property name="buddy">
<cstring>BonesAlwaysOnTopCheckBox</cstring>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="QCheckBox" name="BonesAlwaysOnTopCheckBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>In x-ray mode, the bones are overlayed on top of every object of the scene.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="0" colspan="4">
<widget class="ctkCollapsibleGroupBox" name="ArmatureAdvancedDisplayCollapsibleGroupBox">
<property name="title">
Expand All @@ -198,10 +249,7 @@
<property name="collapsed">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout_7">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="ArmatureShowAxesLabel">
<property name="toolTip">
Expand All @@ -225,7 +273,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QLabel" name="ArmatureShowParenthoodLabel">
<property name="text">
<string>Show Parenthood:</string>
Expand All @@ -235,7 +283,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="1" column="1">
<widget class="QCheckBox" name="ArmatureShowParenthoodCheckBox">
<property name="enabled">
<bool>false</bool>
Expand All @@ -254,77 +302,67 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="2" column="0">
<widget class="QLabel" name="ArmatureShowEnvelopesLabel">
<property name="toolTip">
<string>Show/Hide the bone envelope</string>
</property>
<property name="text">
<string>Show Envelopes</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="2" column="1">
<widget class="QCheckBox" name="ArmatureShowEnvelopesCheckBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Show/Hide the bone envelope</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="ArmatureEnvelopeRadiusLabel">
<property name="toolTip">
<string>Change the envelope radius</string>
</property>
<property name="text">
<string>Envelope radius:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="ctkSliderWidget" name="ArmatureEnvelopeRadiusSlider">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Change the envelope radius</string>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="pageStep">
<double>0.100000000000000</double>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>100.000000000000000</double>
</property>
<property name="value">
<double>10.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="BonesAlwaysOnTopLabel">
<property name="text">
<string>X-Ray mode:</string>
</property>
<property name="buddy">
<cstring>BonesAlwaysOnTopCheckBox</cstring>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="QCheckBox" name="BonesAlwaysOnTopCheckBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>In x-ray mode, the bones are overlayed on top of every object of the scene.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1" colspan="3">
<widget class="QComboBox" name="ArmatureRepresentationComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Change the bones representation.</string>
</property>
<property name="currentIndex">
<number>2</number>
</property>
<item>
<property name="text">
<string>Line</string>
</property>
</item>
<item>
<property name="text">
<string>Cylinder</string>
</property>
</item>
<item>
<property name="text">
<string>Octohedron</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit a61df61

Please sign in to comment.