Skip to content

Commit

Permalink
ENH: Creating and registering VR segment editor widget
Browse files Browse the repository at this point in the history
Creates and registers the VR segment editor widget (which can be switched to from the VR home widget)

KitwareMedical#43
  • Loading branch information
mohammadrashid0917 authored and cpinter committed Sep 19, 2021
1 parent 5146142 commit 034d838
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 2 deletions.
8 changes: 8 additions & 0 deletions VirtualReality/Widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set(${KIT}_INCLUDE_DIRECTORIES
${vtkSlicerVirtualRealityModuleMRML_INCLUDE_DIRS}
${VTK_INCLUDE_DIRS}
${qSlicerSubjectHierarchyModuleWidgets_INCLUDE_DIRS}
${qSlicerSegmentationsModuleWidgets_INCLUDE_DIRS}
${qSlicerSegmentationsEditorEffects_INCLUDE_DIRS}
)

set(${KIT}_SRCS
Expand All @@ -21,6 +23,8 @@ set(${KIT}_SRCS
qMRMLVirtualRealityHomeWidget.h
qMRMLVirtualRealityDataModuleWidget.cxx
qMRMLVirtualRealityDataModuleWidget.h
qMRMLVirtualRealitySegmentEditorWidget.cxx
qMRMLVirtualRealitySegmentEditorWidget.h
)

set(${KIT}_MOC_SRCS
Expand All @@ -29,11 +33,13 @@ set(${KIT}_MOC_SRCS
qMRML${MODULE_NAME}View_p.h
qMRMLVirtualRealityHomeWidget.h
qMRMLVirtualRealityDataModuleWidget.h
qMRMLVirtualRealitySegmentEditorWidget.h
)

set(${KIT}_UI_SRCS
Resources/UI/qMRMLVirtualRealityHomeWidget.ui
Resources/UI/qMRMLVirtualRealityDataModuleWidget.ui
Resources/UI/qMRMLVirtualRealitySegmentEditorWidget.ui
Resources/UI/qMRML${MODULE_NAME}TransformWidget.ui
)

Expand All @@ -47,6 +53,8 @@ set(${KIT}_TARGET_LIBRARIES
vtkSlicerCamerasModuleLogic
${VTK_LIBRARIES}
qSlicerSubjectHierarchyModuleWidgets
qSlicerSegmentationsModuleWidgets

)

#-----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>qMRMLVirtualRealitySegmentEditorWidget</class>
<widget class="qMRMLWidget" name="qMRMLVirtualRealitySegmentEditorWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>589</width>
<height>590</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>qMRMLSegmentEditorWidget</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="qMRMLSegmentEditorWidget" name="SegmentEditorWidget" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>qMRMLWidget</class>
<extends>QWidget</extends>
<header>qMRMLWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>qMRMLSegmentEditorWidget</class>
<extends>qMRMLWidget</extends>
<header>qMRMLSegmentEditorWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../../Resources/qSlicerSegmentationsModule.qrc"/>
<include location="../../../../../../Base/QTGUI/Resources/qSlicerBaseQTGUI.qrc"/>
</resources>
<connections>
<connection>
<sender>qMRMLVirtualRealitySegmentEditorWidget</sender>
<signal>mrmlSceneChanged(vtkMRMLScene*)</signal>
<receiver>SegmentEditorWidget</receiver>
<slot>setMRMLScene(vtkMRMLScene*)</slot>
<hints>
<hint type="sourcelabel">
<x>189</x>
<y>581</y>
</hint>
<hint type="destinationlabel">
<x>189</x>
<y>533</y>
</hint>
</hints>
</connection>
</connections>
</ui>
16 changes: 16 additions & 0 deletions VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
#include "qMRMLVirtualRealityHomeWidget.h"
#include "ui_qMRMLVirtualRealityHomeWidget.h"
#include "qMRMLVirtualRealityDataModuleWidget.h"
#include "qMRMLVirtualRealitySegmentEditorWidget.h"

// VirtualReality MRML includes
#include "vtkMRMLVirtualRealityViewNode.h"

// Segmentations includes
#include "vtkMRMLSegmentEditorNode.h"

// VTK includes
#include <vtkWeakPointer.h>

Expand Down Expand Up @@ -55,6 +59,7 @@ class qMRMLVirtualRealityHomeWidgetPrivate : public Ui_qMRMLVirtualRealityHomeWi
/// Virtual reality view MRML node
vtkWeakPointer<vtkMRMLVirtualRealityViewNode> VirtualRealityViewNode;
qMRMLVirtualRealityDataModuleWidget* DataModuleWidget;
qMRMLVirtualRealitySegmentEditorWidget* SegmentEditorWidget;
};

//-----------------------------------------------------------------------------
Expand All @@ -63,6 +68,7 @@ qMRMLVirtualRealityHomeWidgetPrivate::qMRMLVirtualRealityHomeWidgetPrivate(qMRML
{
this->VirtualRealityViewNode = nullptr;
this->DataModuleWidget = nullptr;
this->SegmentEditorWidget = nullptr;
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -400,8 +406,18 @@ void qMRMLVirtualRealityHomeWidget::registerDefaultModules()

d->DataModuleWidget = new qMRMLVirtualRealityDataModuleWidget(this);
d->DataModuleWidget->setMRMLScene(this->mrmlScene());
d->SegmentEditorWidget = new qMRMLVirtualRealitySegmentEditorWidget(this);
d->SegmentEditorWidget->setMRMLScene(this->mrmlScene());

QIcon dataIcon(QPixmap(":/Icons/SubjectHierarchy.png"));
QIcon segmentEditorIcon(QPixmap(":/Icons/SegmentEditor.png"));

this->addModuleButton(d->DataModuleWidget, dataIcon);
this->addModuleButton(d->SegmentEditorWidget, segmentEditorIcon);
}

void qMRMLVirtualRealityHomeWidget::setMRMLSegmentEditorNode(vtkMRMLSegmentEditorNode* newSegmentEditorNode)
{
Q_D(qMRMLVirtualRealityHomeWidget);
d->SegmentEditorWidget->setMRMLSegmentEditorNode(newSegmentEditorNode);
}
8 changes: 6 additions & 2 deletions VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

class vtkMRMLVirtualRealityViewNode;
class qMRMLVirtualRealityHomeWidgetPrivate;
class vtkMRMLSegmentEditorNode;

/// \ingroup SlicerVirtualReality_Widgets
class Q_SLICER_QTMODULES_VIRTUALREALITY_WIDGETS_EXPORT qMRMLVirtualRealityHomeWidget : public qMRMLWidget
Expand All @@ -62,8 +63,11 @@ class Q_SLICER_QTMODULES_VIRTUALREALITY_WIDGETS_EXPORT qMRMLVirtualRealityHomeWi
/// \param icon The icon that appears on the button in the home widget
Q_INVOKABLE void addModuleButton(QWidget* moduleWidget, QIcon& icon);

/// Register default modules: Data
Q_INVOKABLE void registerDefaultModules();
/// Register default modules: Data, Segment Editor
Q_INVOKABLE void registerDefaultModules();

/// Set the segment editor node for the segment editor widget
Q_INVOKABLE void setMRMLSegmentEditorNode(vtkMRMLSegmentEditorNode* newSegmentEditorNode);

public slots:
/// Set virtual reality view MRML node
Expand Down
118 changes: 118 additions & 0 deletions VirtualReality/Widgets/qMRMLVirtualRealitySegmentEditorWidget.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*==============================================================================
Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
Queen's University, Kingston, ON, Canada. All Rights Reserved.
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This file was originally developed by Csaba Pinter, PerkLab, Queen's University
and was supported through the Applied Cancer Research Unit program of Cancer Care
Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
and CANARIE.
==============================================================================*/

// VirtualReality Widgets includes
#include "qMRMLVirtualRealitySegmentEditorWidget.h"
#include "ui_qMRMLVirtualRealitySegmentEditorWidget.h"

// VirtualReality MRML includes
#include "vtkMRMLVirtualRealityViewNode.h"

// Segmentations includes
#include "vtkMRMLSegmentEditorNode.h"

// Qt includes
#include <QDebug>
#include "qpushbutton.h"
#include "ctkMenuButton.h"
#include "qtoolbutton.h"

//-----------------------------------------------------------------------------
class qMRMLVirtualRealitySegmentEditorWidgetPrivate : public Ui_qMRMLVirtualRealitySegmentEditorWidget
{
Q_DECLARE_PUBLIC(qMRMLVirtualRealitySegmentEditorWidget);

protected:
qMRMLVirtualRealitySegmentEditorWidget* const q_ptr;

public:
qMRMLVirtualRealitySegmentEditorWidgetPrivate(qMRMLVirtualRealitySegmentEditorWidget& object);
virtual ~qMRMLVirtualRealitySegmentEditorWidgetPrivate();

void init();
};

//-----------------------------------------------------------------------------
qMRMLVirtualRealitySegmentEditorWidgetPrivate::qMRMLVirtualRealitySegmentEditorWidgetPrivate(qMRMLVirtualRealitySegmentEditorWidget& object)
: q_ptr(&object)
{
}

//-----------------------------------------------------------------------------
qMRMLVirtualRealitySegmentEditorWidgetPrivate::~qMRMLVirtualRealitySegmentEditorWidgetPrivate()
{
}

//-----------------------------------------------------------------------------
void qMRMLVirtualRealitySegmentEditorWidgetPrivate::init()
{
Q_Q(qMRMLVirtualRealitySegmentEditorWidget);
this->setupUi(q);

//List of effects to be used in VR; effects not listed here are not shown in the widget
QStringList effectNameOrder;
effectNameOrder.append("None");
effectNameOrder.append("Paint");
effectNameOrder.append("Erase");
effectNameOrder.append("Level tracing");
effectNameOrder.append("Grow from seeds");
effectNameOrder.append("Smoothing");
effectNameOrder.append("Scissors");
effectNameOrder.append("Logical Operators");
this->SegmentEditorWidget->setEffectNameOrder(effectNameOrder);

//Hide unneeded effects and buttons
this->SegmentEditorWidget->setUnorderedEffectsVisible(false);
this->SegmentEditorWidget->setSwitchToSegmentationsButtonVisible(false);
this->SegmentEditorWidget->findChild<QToolButton*>("SpecifyGeometryButton")->setVisible(false);
this->SegmentEditorWidget->findChild<QToolButton*>("SliceRotateWarningButton")->setVisible(false);
this->SegmentEditorWidget->findChild<ctkMenuButton*>("Show3DButton")->setVisible(false);
}

//-----------------------------------------------------------------------------
// qMRMLVirtualRealitySegmentEditorWidget methods

//-----------------------------------------------------------------------------
qMRMLVirtualRealitySegmentEditorWidget::qMRMLVirtualRealitySegmentEditorWidget(QWidget* _parent)
: qMRMLWidget(_parent)
, d_ptr(new qMRMLVirtualRealitySegmentEditorWidgetPrivate(*this))
{
Q_D(qMRMLVirtualRealitySegmentEditorWidget);
d->init();

this->updateWidgetFromMRML();
}

//-----------------------------------------------------------------------------
qMRMLVirtualRealitySegmentEditorWidget::~qMRMLVirtualRealitySegmentEditorWidget()
= default;

//-----------------------------------------------------------------------------
void qMRMLVirtualRealitySegmentEditorWidget::updateWidgetFromMRML()
{
//Q_D(qMRMLVirtualRealitySegmentEditorWidget);
}

void qMRMLVirtualRealitySegmentEditorWidget::setMRMLSegmentEditorNode(vtkMRMLSegmentEditorNode* newSegmentEditorNode)
{
Q_D(qMRMLVirtualRealitySegmentEditorWidget);
d->SegmentEditorWidget->setMRMLSegmentEditorNode(newSegmentEditorNode);
}
67 changes: 67 additions & 0 deletions VirtualReality/Widgets/qMRMLVirtualRealitySegmentEditorWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*==============================================================================
Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
Queen's University, Kingston, ON, Canada. All Rights Reserved.
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This file was originally developed by Csaba Pinter, PerkLab, Queen's University
and was supported through the Applied Cancer Research Unit program of Cancer Care
Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
and CANARIE.
==============================================================================*/

#ifndef __qMRMLVirtualRealitySegmentEditorWidget_h
#define __qMRMLVirtualRealitySegmentEditorWidget_h

// VirtualReality Widgets includes
#include "qSlicerVirtualRealityModuleWidgetsExport.h"

// MRMLWidgets includes
#include "qMRMLWidget.h"

// CTK includes
#include <ctkPimpl.h>
#include <ctkVTKObject.h>

class qMRMLVirtualRealitySegmentEditorWidgetPrivate;
class vtkMRMLSegmentEditorNode;

/// \ingroup SlicerVirtualReality_Widgets
class Q_SLICER_QTMODULES_VIRTUALREALITY_WIDGETS_EXPORT qMRMLVirtualRealitySegmentEditorWidget : public qMRMLWidget
{
Q_OBJECT
QVTK_OBJECT

public:
typedef qMRMLWidget Superclass;
/// Constructor
explicit qMRMLVirtualRealitySegmentEditorWidget(QWidget* parent = nullptr);
/// Destructor
~qMRMLVirtualRealitySegmentEditorWidget() override;

void setMRMLSegmentEditorNode(vtkMRMLSegmentEditorNode* newSegmentEditorNode);

public slots:

protected slots:
/// Update widgets from the MRML node
void updateWidgetFromMRML();

protected:
QScopedPointer<qMRMLVirtualRealitySegmentEditorWidgetPrivate> d_ptr;

private:
Q_DECLARE_PRIVATE(qMRMLVirtualRealitySegmentEditorWidget);
Q_DISABLE_COPY(qMRMLVirtualRealitySegmentEditorWidget);
};

#endif

0 comments on commit 034d838

Please sign in to comment.