Commit 4125c414 authored by jcfr's avatar jcfr
Browse files

ENH: Merge qSlicerMRMLSliceViewWidget and qMRMLSliceViewWidget classes

Since SlicerSliceLogic and SlicerSliceLayerLogic have been moved to MRMLLogic,
qMRMLWidgets library now depends on MRMLLogic

git-svn-id: http://svn.slicer.org/Slicer4/trunk@13979 3bd1e089-480b-0410-8dfb-8563597acbee
parent ea5f1df3
......@@ -43,9 +43,6 @@ SET(KIT_SRCS
qSlicerModuleSelectorWidget.h
qSlicerSaveDataDialog.cxx
qSlicerSaveDataDialog.h
qSlicerSliceViewWidget.cxx
qSlicerSliceViewWidget.h
qSlicerSliceViewWidget_p.h
qSlicerWidget.cxx
qSlicerWidget.h
)
......@@ -67,8 +64,6 @@ SET(KIT_MOC_SRCS
qSlicerModuleSelectorWidget_p.h
qSlicerSaveDataDialog.h
qSlicerSaveDataDialog_p.h
qSlicerSliceViewWidget.h
qSlicerSliceViewWidget_p.h
qSlicerWidget.h
)
......@@ -90,6 +85,7 @@ SET(KIT_target_libraries
MRMLDisplayableManager
qSlicerBaseQTCore
qMRMLWidgets
)
# Python wrap
......
......@@ -9,6 +9,7 @@
// qMRML includes
#include "qMRMLThreeDRenderView.h"
#include "qMRMLSliceViewWidget.h"
#include "qMRMLUtils.h"
#include "qMRMLNodeFactory.h"
......@@ -16,7 +17,6 @@
#include "qSlicerLayoutManager.h"
#include "qSlicerLayoutManager_p.h"
#include "qSlicerApplication.h"
#include "qSlicerSliceViewWidget.h"
// MRML includes
#include <vtkMRMLLayoutNode.h>
......@@ -47,7 +47,6 @@ qSlicerLayoutManagerPrivate::qSlicerLayoutManagerPrivate()
this->TargetWidget = 0;
this->CurrentViewArrangement = vtkMRMLLayoutNode::SlicerLayoutNone;
this->UpdatingMRMLLayoutNode = false;
logger.setTrace();
}
//------------------------------------------------------------------------------
......@@ -88,13 +87,14 @@ QWidget* qSlicerLayoutManagerPrivate::createSliceView(const QString& sliceViewNa
Q_ASSERT(this->MRMLScene);
Q_ASSERT(sliceNode);
qSlicerSliceViewWidget * sliceView = 0;
qMRMLSliceViewWidget * sliceView = 0;
//QString widgetId = QLatin1String(sliceNode->GetID());
if (this->SliceViewMap.contains(sliceViewName))
{
sliceView = this->SliceViewMap[sliceViewName];
if (sliceView->mrmlSliceNode() != sliceNode)
{
sliceView->setMRMLSliceNode(sliceNode);
......@@ -104,7 +104,7 @@ QWidget* qSlicerLayoutManagerPrivate::createSliceView(const QString& sliceViewNa
}
else
{
sliceView = new qSlicerSliceViewWidget(sliceViewName, this->TargetWidget);
sliceView = new qMRMLSliceViewWidget(sliceViewName, this->TargetWidget);
sliceView->setMRMLScene(this->MRMLScene);
sliceView->setMRMLSliceNode(sliceNode);
......@@ -193,7 +193,7 @@ void qSlicerLayoutManagerPrivate::onNodeAddedEvent(vtkObject* scene, vtkObject*
{
QString name = sliceNode->GetName();
logger.trace(QString("onSliceNodeAddedEvent - name: %1").arg(name));
Q_ASSERT(name == "red" || name == "yellow" || name == "green");
Q_ASSERT(name == "Red" || name == "Yellow" || name == "Green");
this->createSliceView(name, sliceNode);
}
}
......@@ -283,6 +283,22 @@ struct vtkMRMLSliceNodeInitializer : public vtkMRMLNodeInitializer
sliceNode->SetName(this->SliceLogicName.toLatin1());
sliceNode->SetLayoutName(this->SliceLogicName.toLatin1());
sliceNode->SetSingletonTag(this->SliceLogicName.toLatin1());
if (this->SliceLogicName == "Red")
{
sliceNode->SetOrientationToAxial();
}
else if(this->SliceLogicName == "Yellow")
{
sliceNode->SetOrientationToSagittal();
}
else if(this->SliceLogicName == "Green")
{
sliceNode->SetOrientationToCoronal();
}
else
{
sliceNode->SetOrientationToReformat();
}
}
QString SliceLogicName;
};
......@@ -314,12 +330,12 @@ void qSlicerLayoutManagerPrivate::initialize()
Q_UNUSED(node);
}
// Create "red", "yellow" and "green" vtkMRMLSliceNode if required
// Create "Red", "Yellow" and "Green" vtkMRMLSliceNode if required
int sliceNodeCount = this->MRMLScene->GetNumberOfNodesByClass("vtkMRMLSliceNode");
if (sliceNodeCount == 0)
{
QStringList sliceLogicNames;
sliceLogicNames << "red" << "yellow" << "green";
sliceLogicNames << "Red" << "Yellow" << "Green";
foreach(const QString& sliceLogicName, sliceLogicNames)
{
vtkMRMLSliceNodeInitializer sliceNodeInitializer(sliceLogicName);
......@@ -366,10 +382,10 @@ qMRMLThreeDRenderView* qSlicerLayoutManagerPrivate::threeDRenderView(const QStri
}
//------------------------------------------------------------------------------
qSlicerSliceViewWidget* qSlicerLayoutManagerPrivate::sliceView(const QString& name)
qMRMLSliceViewWidget* qSlicerLayoutManagerPrivate::sliceView(const QString& name)
{
Q_ASSERT(this->SliceViewMap.contains(name));
qSlicerSliceViewWidget* sliceView = this->SliceViewMap[name];
qMRMLSliceViewWidget* sliceView = this->SliceViewMap[name];
Q_ASSERT(sliceView);
return sliceView;
}
......@@ -453,19 +469,19 @@ void qSlicerLayoutManager::switchToConventionalView()
renderView->setVisible(true);
// Red Slice Viewer
qSlicerSliceViewWidget* redSliceView = d->sliceView("red");
qMRMLSliceViewWidget* redSliceView = d->sliceView("Red");
d->GridLayout->addWidget(redSliceView, 1, 0);
redSliceView->setVisible(true);
//redSliceView->setVisible(true);
// Yellow Slice Viewer
qSlicerSliceViewWidget* yellowSliceView = d->sliceView("yellow");
qMRMLSliceViewWidget* yellowSliceView = d->sliceView("Yellow");
d->GridLayout->addWidget(yellowSliceView, 1, 1);
yellowSliceView->setVisible(true);
//yellowSliceView->setVisible(true);
// Green Slice Viewer
qSlicerSliceViewWidget* greenSliceView = d->sliceView("green");
qMRMLSliceViewWidget* greenSliceView = d->sliceView("Green");
d->GridLayout->addWidget(greenSliceView, 1, 2);
greenSliceView->setVisible(true);
//greenSliceView->setVisible(true);
// Update LayoutNode
qSlicerLayoutManager_updateLayoutNode(ConventionalView);
......@@ -498,28 +514,28 @@ void qSlicerLayoutManager::switchToOneUp3DView()
void qSlicerLayoutManager::switchToOneUpRedSliceView()
{
qSlicerLayoutManager_returnIfMatchCurrentView(OneUpRedSliceView);
this->switchToOneUpSliceView("red");
this->switchToOneUpSliceView("Red");
}
//------------------------------------------------------------------------------
void qSlicerLayoutManager::switchToOneUpGreenSliceView()
{
qSlicerLayoutManager_returnIfMatchCurrentView(OneUpGreenSliceView);
this->switchToOneUpSliceView("green");
this->switchToOneUpSliceView("Green");
}
//------------------------------------------------------------------------------
void qSlicerLayoutManager::switchToOneUpYellowSliceView()
{
qSlicerLayoutManager_returnIfMatchCurrentView(OneUpYellowSliceView);
this->switchToOneUpSliceView("yellow");
this->switchToOneUpSliceView("Yellow");
}
//------------------------------------------------------------------------------
void qSlicerLayoutManager::switchToOneUpSliceView(const QString& sliceViewName)
{
// Sanity checks
Q_ASSERT(sliceViewName == "red" || sliceViewName == "yellow" || sliceViewName == "green");
if (sliceViewName != "red" && sliceViewName != "yellow" && sliceViewName != "green")
Q_ASSERT(sliceViewName == "Red" || sliceViewName == "Yellow" || sliceViewName == "Green");
if (sliceViewName != "Red" && sliceViewName != "Yellow" && sliceViewName != "Green")
{
qWarning() << "Slicer viewer name" << sliceViewName << "invalid !";
return;
......@@ -558,17 +574,17 @@ void qSlicerLayoutManager::switchToFourUpView()
renderView->setVisible(true);
// Red Slice Viewer
qMRMLSliceViewWidget* redSliceView = d->sliceView("red");
qMRMLSliceViewWidget* redSliceView = d->sliceView("Red");
d->GridLayout->addWidget(redSliceView, 0, 1);
redSliceView->setVisible(true);
// Yellow Slice Viewer
qMRMLSliceViewWidget* yellowSliceView = d->sliceView("yellow");
qMRMLSliceViewWidget* yellowSliceView = d->sliceView("Yellow");
d->GridLayout->addWidget(yellowSliceView, 1, 0);
yellowSliceView->setVisible(true);
// Green Slice Viewer
qMRMLSliceViewWidget* greenSliceView = d->sliceView("green");
qMRMLSliceViewWidget* greenSliceView = d->sliceView("Green");
d->GridLayout->addWidget(greenSliceView, 1, 1);
greenSliceView->setVisible(true);
......@@ -702,17 +718,17 @@ void qSlicerLayoutManager::switchToDual3DView()
renderView2->setVisible(true);
// Red Slice Viewer
qMRMLSliceViewWidget* redSliceView = d->sliceView("red");
qMRMLSliceViewWidget* redSliceView = d->sliceView("Red");
d->GridLayout->addWidget(redSliceView, 0, 1);
redSliceView->setVisible(true);
// Yellow Slice Viewer
qMRMLSliceViewWidget* yellowSliceView = d->sliceView("yellow");
qMRMLSliceViewWidget* yellowSliceView = d->sliceView("Yellow");
d->GridLayout->addWidget(yellowSliceView, 1, 0);
yellowSliceView->setVisible(true);
// Green Slice Viewer
qMRMLSliceViewWidget* greenSliceView = d->sliceView("green");
qMRMLSliceViewWidget* greenSliceView = d->sliceView("Green");
d->GridLayout->addWidget(greenSliceView, 1, 1);
greenSliceView->setVisible(true);
......
......@@ -15,7 +15,7 @@
#include <vtkSmartPointer.h>
class QGridLayout;
class qSlicerSliceViewWidget;
class qMRMLSliceViewWidget;
class qMRMLThreeDRenderView;
class vtkObject;
class vtkMRMLLayoutNode;
......@@ -56,7 +56,7 @@ public:
/// Convenient function allowing to get a reference to the sliceView widget
/// identified by \a sliceViewName
qSlicerSliceViewWidget* sliceView(const QString& sliceViewName);
qMRMLSliceViewWidget* sliceView(const QString& sliceViewName);
public slots:
/// Handle MRML scene event
......@@ -78,8 +78,8 @@ public:
/// the current MRML layout node is updated from one of the switchTo* slots.
bool UpdatingMRMLLayoutNode;
QHash<QString, qMRMLThreeDRenderView*> ThreeDRenderViewMap;
QHash<QString, qSlicerSliceViewWidget*> SliceViewMap;
QHash<QString, qMRMLThreeDRenderView*> ThreeDRenderViewMap;
QHash<QString, qMRMLSliceViewWidget*> SliceViewMap;
};
#endif
// Qt includes
#include <QDebug>
// CTK includes
#include <ctkLogger.h>
#include <ctkVTKSliceView.h>
// MRML includes
#include <vtkMRMLScene.h>
// VTK includes
#include <vtkIntArray.h>
// Slicer includes
#include "qSlicerSliceViewWidget.h"
#include "qSlicerSliceViewWidget_p.h"
// Convenient macro
#define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
//--------------------------------------------------------------------------
static ctkLogger logger("org.slicer.base.qtgui.qSlicerSliceView");
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// qSlicerSliceViewWidgetPrivate methods
//---------------------------------------------------------------------------
qSlicerSliceViewWidgetPrivate::qSlicerSliceViewWidgetPrivate()
{
logger.setTrace();
this->SliceLogic = vtkSmartPointer<vtkMRMLSliceLogic>::New();
this->qvtkConnect(this->SliceLogic,
vtkCommand::ModifiedEvent, this, SLOT(onSliceLogicModifiedEvent()));
}
//---------------------------------------------------------------------------
qSlicerSliceViewWidgetPrivate::~qSlicerSliceViewWidgetPrivate()
{
}
// --------------------------------------------------------------------------
void qSlicerSliceViewWidgetPrivate::onSliceLogicModifiedEvent()
{
CTK_P(qSlicerSliceViewWidget);
if (p->mrmlSliceCompositeNode() != this->SliceLogic->GetSliceCompositeNode())
{
p->setMRMLSliceCompositeNode(this->SliceLogic->GetSliceCompositeNode());
}
if (this->ImageData != this->SliceLogic->GetImageData())
{
logger.trace("onSliceLogicModifiedEvent - reconnect onImageDataModifiedEvent slot");
this->qvtkReconnect(this->ImageData, this->SliceLogic->GetImageData(),
vtkCommand::ModifiedEvent, this, SLOT(onImageDataModifiedEvent()));
this->ImageData = this->SliceLogic->GetImageData();
this->onImageDataModifiedEvent();
}
// Set the scale increments to match the z spacing (rotated into slice space)
const double * sliceSpacing = 0;
sliceSpacing = this->SliceLogic->GetLowestVolumeSliceSpacing();
Q_ASSERT(sliceSpacing);
double offsetResolution = sliceSpacing[2];
p->setSliceOffsetResolution(offsetResolution);
// Set slice offset range to match the field of view
// Calculate the number of slices in the current range
double sliceBounds[6] = {0, 0, 0, 0, 0, 0};
this->SliceLogic->GetLowestVolumeSliceBounds(sliceBounds);
p->setSliceOffsetRange(sliceBounds[4], sliceBounds[5]);
}
// --------------------------------------------------------------------------
void qSlicerSliceViewWidgetPrivate::onImageDataModifiedEvent()
{
CTK_P(qSlicerSliceViewWidget);
logger.trace("onImageDataModifiedEvent");
p->setImageData(this->ImageData);
p->scheduleRender();
}
// --------------------------------------------------------------------------
// qSlicerSliceView methods
// --------------------------------------------------------------------------
qSlicerSliceViewWidget::qSlicerSliceViewWidget(const QString& sliceViewName, QWidget* _parent) :
Superclass(sliceViewName, _parent)
{
CTK_INIT_PRIVATE(qSlicerSliceViewWidget);
//CTK_D(qSlicerSliceView);
}
//------------------------------------------------------------------------------
void qSlicerSliceViewWidget::setMRMLScene(vtkMRMLScene* scene)
{
if (scene == this->mrmlScene())
{
return;
}
this->qMRMLSliceViewWidget::setMRMLScene(scene);
}
//------------------------------------------------------------------------------
void qSlicerSliceViewWidget::setMRMLSliceNode(vtkMRMLSliceNode* sliceNode)
{
CTK_D(qSlicerSliceViewWidget);
Q_ASSERT(this->mrmlScene());
if (sliceNode == this->mrmlSliceNode())
{
return;
}
// List of events the slice logics should listen
VTK_CREATE(vtkIntArray, events);
events->InsertNextValue(vtkMRMLScene::NewSceneEvent);
events->InsertNextValue(vtkMRMLScene::SceneCloseEvent);
events->InsertNextValue(vtkMRMLScene::SceneClosingEvent);
events->InsertNextValue(vtkMRMLScene::SceneRestoredEvent);
events->InsertNextValue(vtkMRMLScene::NodeAddedEvent);
events->InsertNextValue(vtkMRMLScene::NodeRemovedEvent);
// Initialize logic
d->SliceLogic->SetMRMLScene(this->mrmlScene());
d->SliceLogic->SetSliceNode(sliceNode);
d->SliceLogic->ProcessLogicEvents();
d->SliceLogic->ProcessMRMLEvents(this->mrmlScene(), vtkCommand::ModifiedEvent, NULL);
d->SliceLogic->SetAndObserveMRMLSceneEvents(this->mrmlScene(), events);
this->qMRMLSliceViewWidget::setMRMLSliceNode(sliceNode);
}
// --------------------------------------------------------------------------
void qSlicerSliceViewWidget::onSliceOffsetValueChanged(double value)
{
logger.trace(QString("onSliceOffsetValueChanged: %1").arg(value));
ctk_d()->SliceLogic->SetSliceOffset(value);
}
/*
//------------------------------------------------------------------------------
void qSlicerSliceViewWidget::resizeEvent(QResizeEvent * event)
{
CTK_D(qSlicerSliceViewWidget);
this->qMRMLSliceViewWidget::resizeEvent(event);
}
*/
#ifndef __qSlicerSliceViewWidget_h
#define __qSlicerSliceViewWidget_h
// Qt includes
#include <QWidget>
// CTK includes
#include <ctkPimpl.h>
// qMRMLWidget includes
#include <qMRMLSliceViewWidget.h>
#include "qSlicerBaseQTGUIExport.h"
class qSlicerSliceViewWidgetPrivate;
class vtkMRMLScene;
class Q_SLICER_BASE_QTGUI_EXPORT qSlicerSliceViewWidget : public qMRMLSliceViewWidget
{
Q_OBJECT
public:
/// Superclass typedef
typedef qMRMLSliceViewWidget Superclass;
/// Constructors
explicit qSlicerSliceViewWidget(const QString& sliceViewName, QWidget* parent = 0);
virtual ~qSlicerSliceViewWidget(){}
//sgui->GetLogic()->FitSliceToAll ( w, h );
public slots:
///
/// Set the MRML \a scene that should be listened for events
virtual void setMRMLScene(vtkMRMLScene* scene);
///
/// Set \a sliceNode
virtual void setMRMLSliceNode(vtkMRMLSliceNode* sliceNode);
protected slots:
virtual void onSliceOffsetValueChanged(double value);
protected:
//void resizeEvent(QResizeEvent * event);
private:
CTK_DECLARE_PRIVATE(qSlicerSliceViewWidget);
};
#endif
#ifndef __qSlicerSliceViewWidget_p_h
#define __qSlicerSliceViewWidget_p_h
// Qt includes
// CTK includes
#include <ctkPimpl.h>
#include <ctkVTKObject.h>
// qMRML includes
#include "qSlicerSliceViewWidget.h"
// MRMLLogic includes
#include <vtkMRMLSliceLogic.h>
// VTK includes
#include <vtkSmartPointer.h>
#include <vtkWeakPointer.h>
//-----------------------------------------------------------------------------
class qSlicerSliceViewWidgetPrivate: public QObject,
public ctkPrivate<qSlicerSliceViewWidget>
{
Q_OBJECT
QVTK_OBJECT
public:
CTK_DECLARE_PUBLIC(qSlicerSliceViewWidget);
qSlicerSliceViewWidgetPrivate();
~qSlicerSliceViewWidgetPrivate();
public slots:
/// Triggered after the SliceLogic is modified
void onSliceLogicModifiedEvent();
/// Triggered after the ImageData associated with the SliceLogic is modified
void onImageDataModifiedEvent();
public:
vtkSmartPointer<vtkMRMLSliceLogic> SliceLogic;
vtkWeakPointer<vtkImageData> ImageData;
};
#endif
......@@ -120,6 +120,8 @@ QT4_ADD_RESOURCES(qMRMLWidgets_QRC_SRCS Resources/qMRMLWidgets.qrc)
SET(include_dirs
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${MRMLLogic_SOURCE_DIR}
${MRMLLogic_BINARY_DIR}
)
SET(QT_INCLUDE_DIRS
......@@ -174,6 +176,7 @@ SET(qMRMLWidgets_LIBRARIES
${CTK_LIBRARIES}
${CTK_EXTERNAL_LIBRARIES}
MRML
MRMLLogic
)
TARGET_LINK_LIBRARIES(${lib_name} ${qMRMLWidgets_LIBRARIES})
......
......@@ -59,7 +59,7 @@
</item>
<item>
<property name="text">
<string>Sagital</string>
<string>Sagittal</string>
</property>
</item>
<item>
......
......@@ -35,7 +35,12 @@ static ctkLogger logger("org.slicer.libs.qmrmlwidgets.qMRMLSliceViewWidget");
qMRMLSliceViewWidgetPrivate::qMRMLSliceViewWidgetPrivate()
{
logger.setTrace();
this->SliceLogic = vtkSmartPointer<vtkMRMLSliceLogic>::New();
this->qvtkConnect(this->SliceLogic,
vtkCommand::ModifiedEvent, this, SLOT(onSliceLogicModifiedEvent()));
this->MRMLSliceNode = 0;
this->MRMLSliceCompositeNode = 0;
......@@ -56,7 +61,7 @@ void qMRMLSliceViewWidgetPrivate::setupUi(qMRMLWidget* widget)
CTK_P(qMRMLSliceViewWidget);
this->Ui_qMRMLSliceViewWidget::setupUi(widget);
// Set LabelMapSelector attributes
this->LabelMapSelector->addAttribute("vtkMRMLVolumeNode", "LabelMap", "1");
......@@ -78,66 +83,111 @@ void qMRMLSliceViewWidgetPrivate::setupUi(qMRMLWidget* widget)
// Connect Slice offset slider
this->connect(this->SliceOffsetSlider, SIGNAL(valueIsChanging(double)),
p, SLOT(onSliceOffsetValueChanged(double)));
p, SLOT(setSliceOffsetValue(double)));
}
//---------------------------------------------------------------------------
void qMRMLSliceViewWidgetPrivate::setMRMLScene(vtkMRMLScene* scene)
void qMRMLSliceViewWidgetPrivate::setMRMLScene(vtkMRMLScene* newScene)
{
CTK_P(qMRMLSliceViewWidget);
if (scene == p->mrmlScene())
if (newScene == p->mrmlScene())
{
return;
}
this->qvtkReconnect(
p->mrmlScene(), scene,
p->mrmlScene(), newScene,
vtkMRMLScene::SceneClosingEvent, this, SLOT(onSceneClosingEvent()));
this->qvtkReconnect(
p->mrmlScene(), scene,
p->mrmlScene(), newScene,
vtkMRMLScene::SceneCloseEvent, this, SLOT(onSceneCloseEvent()));
this->qvtkReconnect(
p->mrmlScene(), scene,
p->mrmlScene(), newScene,
vtkMRMLScene::SceneLoadStartEvent, this, SLOT(onSceneLoadStartEvent()));
this->qvtkReconnect(
p->mrmlScene(), scene,
p->mrmlScene(), newScene,
vtkMRMLScene::SceneLoadEndEvent, this, SLOT(onSceneLoadEndEvent()));
this->qvtkReconnect(
p->mrmlScene(), scene,
p->mrmlScene(), newScene,
vtkMRMLScene::NodeAddedEvent, this,
SLOT(onNodeAddedEvent(vtkObject*, vtkObject*)));
this->qvtkReconnect(
p->mrmlScene(), scene,
p->mrmlScene(), newScene,