Commit 38fc3976 authored by finetjul's avatar finetjul
Browse files

ENH: Add components (Interpolate, ColorNode, presets) into qSlicerScalar...

git-svn-id: http://svn.slicer.org/Slicer4/trunk@14735 3bd1e089-480b-0410-8dfb-8563597acbee
parent 63ee5375
......@@ -6,42 +6,128 @@
<rect>
<x>0</x>
<y>0</y>
<width>677</width>
<height>481</height>
<width>284</width>
<height>392</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="qMRMLVolumeThresholdWidget" name="MRMLVolumeThresholdWidget" native="true"/>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="LookupTableLabel">
<property name="text">
<string>Lookup Table:</string>
</property>
</widget>
</item>
<item>
<widget class="qMRMLWindowLevelWidget" name="MRMLWindowLevelWidget" native="true"/>
<item row="0" column="1">
<widget class="qMRMLColorTableComboBox" name="ColorTableComboBox">
<property name="addEnabled">
<bool>false</bool>
</property>
<property name="removeEnabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="ctkTransferFunctionView" name="TransferFunctionView">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>150</height>
</size>
<item row="1" column="0">
<widget class="QLabel" name="InterpolateLabel">
<property name="text">
<string>Interpolate:</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<item row="1" column="1">
<widget class="QCheckBox" name="InterpolateCheckbox">
<property name="text">
<string/>
</property>
<property name="sizeHint" stdset="0">
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Window Level editor presets:</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="PresetToolButton">
<property name="text">
<string>1</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="PresetToolButton3">
<property name="text">
<string>2</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="PresetToolButton6">
<property name="text">
<string>3</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="PresetToolButton5">
<property name="text">
<string>4</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="PresetToolButton4">
<property name="text">
<string>5</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="PresetToolButton2">
<property name="text">
<string>6</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0" colspan="2">
<widget class="qMRMLWindowLevelWidget" name="MRMLWindowLevelWidget"/>
</item>
<item row="5" column="0" colspan="2">
<widget class="qMRMLVolumeThresholdWidget" name="MRMLVolumeThresholdWidget"/>
</item>
<item row="6" column="0" colspan="2">
<widget class="ctkTransferFunctionView" name="TransferFunctionView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>20</width>
<height>40</height>
<width>0</width>
<height>150</height>
</size>
</property>
</spacer>
</widget>
</item>
</layout>
</widget>
......@@ -52,10 +138,14 @@
<header>ctkTransferFunctionView.h</header>
</customwidget>
<customwidget>
<class>qSlicerWidget</class>
<class>qMRMLColorTableComboBox</class>
<extends>qMRMLNodeComboBox</extends>
<header>qMRMLColorTableComboBox.h</header>
</customwidget>
<customwidget>
<class>qMRMLNodeComboBox</class>
<extends>QWidget</extends>
<header>qSlicerWidget.h</header>
<container>1</container>
<header>qMRMLNodeComboBox.h</header>
</customwidget>
<customwidget>
<class>qMRMLVolumeThresholdWidget</class>
......@@ -67,7 +157,30 @@
<extends>QWidget</extends>
<header>qMRMLWindowLevelWidget.h</header>
</customwidget>
<customwidget>
<class>qSlicerWidget</class>
<extends>QWidget</extends>
<header>qSlicerWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
<connections>
<connection>
<sender>qSlicerScalarVolumeDisplayWidget</sender>
<signal>mrmlSceneChanged(vtkMRMLScene*)</signal>
<receiver>ColorTableComboBox</receiver>
<slot>setMRMLScene(vtkMRMLScene*)</slot>
<hints>
<hint type="sourcelabel">
<x>299</x>
<y>273</y>
</hint>
<hint type="destinationlabel">
<x>271</x>
<y>17</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>525</width>
<height>319</height>
<width>249</width>
<height>103</height>
</rect>
</property>
<property name="windowTitle">
......@@ -18,6 +18,9 @@
<normaloff>:/Icons/Volumes.png</normaloff>:/Icons/Volumes.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="ActiveVolumeLabel">
<property name="text">
......@@ -52,6 +55,19 @@
</layout>
</widget>
</item>
<item row="2" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>208</width>
<height>15</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
......@@ -89,11 +105,11 @@
<slot>setMRMLScene(vtkMRMLScene*)</slot>
<hints>
<hint type="sourcelabel">
<x>424</x>
<x>248</x>
<y>1</y>
</hint>
<hint type="destinationlabel">
<x>422</x>
<x>230</x>
<y>19</y>
</hint>
</hints>
......@@ -105,12 +121,12 @@
<slot>setMRMLVolumeNode(vtkMRMLNode*)</slot>
<hints>
<hint type="sourcelabel">
<x>313</x>
<y>148</y>
<x>230</x>
<y>26</y>
</hint>
<hint type="destinationlabel">
<x>305</x>
<y>399</y>
<x>221</x>
<y>70</y>
</hint>
</hints>
</connection>
......
......@@ -27,7 +27,7 @@ public:
qSlicerScalarVolumeDisplayWidgetPrivate();
~qSlicerScalarVolumeDisplayWidgetPrivate();
void init();
void updateTransferFunction();
ctkVTKHistogram* Histogram;
vtkSmartPointer<vtkColorTransferFunction> ColorTransferFunction;
};
......@@ -66,6 +66,11 @@ void qSlicerScalarVolumeDisplayWidgetPrivate::init()
new ctkTransferFunctionBarsItem(this->Histogram);
barsItem->setBarWidth(1.);
scene->addItem(barsItem);
QObject::connect(this->InterpolateCheckbox, SIGNAL(toggled(bool)),
p, SLOT(setInterpolate(bool)));
QObject::connect(this->ColorTableComboBox, SIGNAL(currentNodeChanged(vtkMRMLNode*)),
p, SLOT(setColorNode(vtkMRMLNode*)));
}
// --------------------------------------------------------------------------
......@@ -79,6 +84,22 @@ qSlicerScalarVolumeDisplayWidget::qSlicerScalarVolumeDisplayWidget(QWidget* _par
this->setEnabled(false);
}
// --------------------------------------------------------------------------
vtkMRMLScalarVolumeNode* qSlicerScalarVolumeDisplayWidget::volumeNode()const
{
CTK_D(const qSlicerScalarVolumeDisplayWidget);
return vtkMRMLScalarVolumeNode::SafeDownCast(
d->MRMLWindowLevelWidget->mrmlVolumeNode());
}
// --------------------------------------------------------------------------
vtkMRMLScalarVolumeDisplayNode* qSlicerScalarVolumeDisplayWidget::volumeDisplayNode()const
{
vtkMRMLVolumeNode* volumeNode = this->volumeNode();
return volumeNode ? vtkMRMLScalarVolumeDisplayNode::SafeDownCast(
volumeNode->GetDisplayNode()) : 0;
}
// --------------------------------------------------------------------------
void qSlicerScalarVolumeDisplayWidget::setMRMLVolumeNode(vtkMRMLNode* node)
{
......@@ -89,23 +110,59 @@ void qSlicerScalarVolumeDisplayWidget::setMRMLVolumeNode(vtkMRMLNode* node)
void qSlicerScalarVolumeDisplayWidget::setMRMLVolumeNode(vtkMRMLScalarVolumeNode* volumeNode)
{
CTK_D(qSlicerScalarVolumeDisplayWidget);
vtkMRMLScalarVolumeDisplayNode* oldVolumeDisplayNode = this->volumeDisplayNode();
d->MRMLWindowLevelWidget->setMRMLVolumeNode(volumeNode);
d->MRMLVolumeThresholdWidget->setMRMLVolumeNode(volumeNode);
qvtkReconnect(oldVolumeDisplayNode, volumeNode->GetDisplayNode(), vtkCommand::ModifiedEvent,
this, SLOT(updateWidgetFromMRML()));
d->Histogram->setDataArray(volumeNode->GetImageData()->GetPointData()->GetScalars());
d->Histogram->build();
d->updateTransferFunction();
this->setEnabled(volumeNode != 0);
/*
disconnect(0, 0, this, SLOT(updateTransferFunction()));
connect(d->MRMLWindowLevelWidget, SIGNAL(windowLevelValuesChanged(double, double)),
this, SLOT(updateTransferFunction()));
connect(d->MRMLVolumeThresholdWidget, SIGNAL(thresholdValuesChanged(double, double)),
this, SLOT(updateTransferFunction()));
connect(d->MRMLVolumeThresholdWidget, SIGNAL(autoThresholdValueChanged(int)),
this, SLOT(updateTransferFunction()));
*/
this->updateWidgetFromMRML();
}
// --------------------------------------------------------------------------
void qSlicerScalarVolumeDisplayWidget::updateWidgetFromMRML()
{
CTK_D(qSlicerScalarVolumeDisplayWidget);
vtkMRMLScalarVolumeDisplayNode* displayNode =
this->volumeDisplayNode();
if (displayNode)
{
d->ColorTableComboBox->setCurrentNode(displayNode->GetColorNode());
d->InterpolateCheckbox->setChecked(displayNode->GetInterpolate());
}
this->updateTransferFunction();
}
//----------------------------------------------------------------------------
void qSlicerScalarVolumeDisplayWidgetPrivate::updateTransferFunction()
void qSlicerScalarVolumeDisplayWidget::updateTransferFunction()
{
vtkMRMLVolumeNode* volumeNode = this->MRMLWindowLevelWidget->mrmlVolumeNode();
Q_ASSERT(volumeNode == this->MRMLVolumeThresholdWidget->mrmlVolumeNode());
CTK_D(qSlicerScalarVolumeDisplayWidget);
// from vtkKWWindowLevelThresholdEditor::UpdateTransferFunction
if (!this->isVisible())
{
return;
}
vtkMRMLVolumeNode* volumeNode = d->MRMLWindowLevelWidget->mrmlVolumeNode();
Q_ASSERT(volumeNode == d->MRMLVolumeThresholdWidget->mrmlVolumeNode());
vtkImageData* imageData = volumeNode ? volumeNode->GetImageData() : 0;
if (imageData == 0)
{
this->ColorTransferFunction->RemoveAllPoints();
d->ColorTransferFunction->RemoveAllPoints();
return;
}
double range[2] = {0,255};
......@@ -113,22 +170,22 @@ void qSlicerScalarVolumeDisplayWidgetPrivate::updateTransferFunction()
// AdjustRange call will take out points that are outside of the new
// range, but it needs the points to be there in order to work, so call
// RemoveAllPoints after it's done
this->ColorTransferFunction->AdjustRange(range);
this->ColorTransferFunction->RemoveAllPoints();
d->ColorTransferFunction->AdjustRange(range);
d->ColorTransferFunction->RemoveAllPoints();
double low = this->MRMLVolumeThresholdWidget->lowerThreshold();
double upper = this->MRMLVolumeThresholdWidget->upperThreshold();
double min = this->MRMLWindowLevelWidget->level() - 0.5 * this->MRMLWindowLevelWidget->window();
double max = this->MRMLWindowLevelWidget->level() + 0.5 * this->MRMLWindowLevelWidget->window();
double min = d->MRMLWindowLevelWidget->level() - 0.5 * d->MRMLWindowLevelWidget->window();
double max = d->MRMLWindowLevelWidget->level() + 0.5 * d->MRMLWindowLevelWidget->window();
double minVal = 0;
double maxVal = 1;
double low = d->MRMLVolumeThresholdWidget->isOff() ? range[0] : d->MRMLVolumeThresholdWidget->lowerThreshold();
double upper = d->MRMLVolumeThresholdWidget->isOff() ? range[1] : d->MRMLVolumeThresholdWidget->upperThreshold();
this->ColorTransferFunction->SetColorSpaceToRGB();
d->ColorTransferFunction->SetColorSpaceToRGB();
if (low >= max || upper <= min)
{
this->ColorTransferFunction->AddRGBPoint(range[0], 0, 0, 0);
this->ColorTransferFunction->AddRGBPoint(range[1], 0, 0, 0);
d->ColorTransferFunction->AddRGBPoint(range[0], 0, 0, 0);
d->ColorTransferFunction->AddRGBPoint(range[1], 0, 0, 0);
}
else
{
......@@ -149,18 +206,50 @@ void qSlicerScalarVolumeDisplayWidgetPrivate::updateTransferFunction()
max = upper - 0.001;
}
this->ColorTransferFunction->AddRGBPoint(range[0], 0, 0, 0);
this->ColorTransferFunction->AddRGBPoint(low, 0, 0, 0);
this->ColorTransferFunction->AddRGBPoint(min, minVal, minVal, minVal);
this->ColorTransferFunction->AddRGBPoint(max, maxVal, maxVal, maxVal);
this->ColorTransferFunction->AddRGBPoint(upper, maxVal, maxVal, maxVal);
d->ColorTransferFunction->AddRGBPoint(range[0], 0, 0, 0);
d->ColorTransferFunction->AddRGBPoint(low, 0, 0, 0);
d->ColorTransferFunction->AddRGBPoint(min, minVal, minVal, minVal);
d->ColorTransferFunction->AddRGBPoint(max, maxVal, maxVal, maxVal);
d->ColorTransferFunction->AddRGBPoint(upper, maxVal, maxVal, maxVal);
if (upper+0.001 < range[1])
{
this->ColorTransferFunction->AddRGBPoint(upper+0.001, 0, 0, 0);
this->ColorTransferFunction->AddRGBPoint(range[1], 0, 0, 0);
d->ColorTransferFunction->AddRGBPoint(upper+0.001, 0, 0, 0);
d->ColorTransferFunction->AddRGBPoint(range[1], 0, 0, 0);
}
}
this->ColorTransferFunction->SetAlpha(1.0);
this->ColorTransferFunction->Build();
d->ColorTransferFunction->SetAlpha(1.0);
d->ColorTransferFunction->Build();
}
// -----------------------------------------------------------------------------
void qSlicerScalarVolumeDisplayWidget::showEvent( QShowEvent * event )
{
this->updateTransferFunction();
this->Superclass::showEvent(event);
}
// --------------------------------------------------------------------------
void qSlicerScalarVolumeDisplayWidget::setInterpolate(bool interpolate)
{
vtkMRMLScalarVolumeDisplayNode* displayNode =
this->volumeDisplayNode();
if (!displayNode)
{
return;
}
displayNode->SetInterpolate(interpolate);
}
// --------------------------------------------------------------------------
void qSlicerScalarVolumeDisplayWidget::setColorNode(vtkMRMLNode* colorNode)
{
vtkMRMLScalarVolumeDisplayNode* displayNode =
this->volumeDisplayNode();
if (!displayNode || !colorNode)
{
return;
}
Q_ASSERT(vtkMRMLColorNode::SafeDownCast(colorNode));
displayNode->SetAndObserveColorNodeID(colorNode->GetID());
}
......@@ -14,6 +14,7 @@
#include "qSlicerVolumesModuleExport.h"
class vtkMRMLNode;
class vtkMRMLScalarVolumeDisplayNode;
class vtkMRMLScalarVolumeNode;
class qSlicerScalarVolumeDisplayWidgetPrivate;
......@@ -27,7 +28,8 @@ public:
explicit qSlicerScalarVolumeDisplayWidget(QWidget* parent);
virtual ~qSlicerScalarVolumeDisplayWidget(){}
vtkMRMLScalarVolumeNode* volumeNode()const;
vtkMRMLScalarVolumeDisplayNode* volumeDisplayNode()const;
public slots:
///
......@@ -35,11 +37,15 @@ public slots:
void setMRMLVolumeNode(vtkMRMLScalarVolumeNode* volumeNode);
void setMRMLVolumeNode(vtkMRMLNode* node);
void setInterpolate(bool interpolate);
void setColorNode(vtkMRMLNode* colorNode);
protected slots:
void updateWidgetFromMRML();
void updateTransferFunction();
protected:
void showEvent(QShowEvent * event);
private:
CTK_DECLARE_PRIVATE(qSlicerScalarVolumeDisplayWidget);
};
......
......@@ -11,18 +11,18 @@ qSlicerVolumeDisplayWidget::qSlicerVolumeDisplayWidget(QWidget* _parent) : Super
this->ScalarVolumeDisplayWidget = new qSlicerScalarVolumeDisplayWidget(this);
this->addWidget(this->ScalarVolumeDisplayWidget);
}
// --------------------------------------------------------------------------
void qSlicerVolumeDisplayWidget::setMRMLVolumeNode(vtkMRMLNode* volumeNode)
{
if (volumeNode == 0)
{
if (volumeNode == 0)
{
return;
}
if (volumeNode->IsA("vtkMRMLScalarVolumeNode"))
{
this->ScalarVolumeDisplayWidget->setMRMLScene(volumeNode->GetScene());
this->ScalarVolumeDisplayWidget->setMRMLVolumeNode(volumeNode);
this->setCurrentWidget(this->ScalarVolumeDisplayWidget);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment