An update will be applied January 25th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

Commit f743ffbb authored by jcfr's avatar jcfr
Browse files

ENH: qMRMLThreeDViewsControllerWidget - Implement background buttons

git-svn-id: http://svn.slicer.org/Slicer4/trunk@14864 3bd1e089-480b-0410-8dfb-8563597acbee
parent d1ea74c8
......@@ -67,11 +67,14 @@ public:
void UpdateAxisVisibility();
void UpdateAxisLabelVisibility();
void SetAxisLabelColor(double newAxisLabelColor[3]);
void UpdateRenderMode();
void UpdateStereoType();
void UpdateBackgroundColor();
std::vector<vtkSmartPointer<vtkFollower> > AxisLabelActors;
vtkSmartPointer<vtkActor> BoxAxisActor;
vtkBoundingBox* BoxAxisBoundingBox;
......@@ -126,7 +129,7 @@ void vtkMRMLViewDisplayableManager::vtkInternal::CreateAxis()
axisActor->SetPickable(0);
this->AxisLabelActors.push_back(axisActor);
axisActor->GetProperty()->SetColor(1, 1, 1);
axisActor->GetProperty()->SetColor(1, 1, 1); // White
axisActor->GetProperty()->SetDiffuse(0.0);
axisActor->GetProperty()->SetAmbient(1.0);
axisActor->GetProperty()->SetSpecular(0.0);
......@@ -304,6 +307,17 @@ void vtkMRMLViewDisplayableManager::vtkInternal::UpdateAxisLabelVisibility()
this->External->RequestRender();
}
//---------------------------------------------------------------------------
void vtkMRMLViewDisplayableManager::vtkInternal::SetAxisLabelColor(double newAxisLabelColor[3])
{
for(std::size_t i = 0; i < this->AxisLabelActors.size(); ++i)
{
vtkFollower* actor = this->AxisLabelActors[i];
actor->GetProperty()->SetColor(newAxisLabelColor);
}
this->External->RequestRender();
}
//---------------------------------------------------------------------------
void vtkMRMLViewDisplayableManager::vtkInternal::UpdateRenderMode()
{
......@@ -355,6 +369,31 @@ void vtkMRMLViewDisplayableManager::vtkInternal::UpdateStereoType()
this->External->RequestRender();
}
//---------------------------------------------------------------------------
void vtkMRMLViewDisplayableManager::vtkInternal::UpdateBackgroundColor()
{
double backgroundColor[3] = {0.0, 0.0, 0.0};
this->External->GetMRMLViewNode()->GetBackgroundColor(backgroundColor);
vtkDebugWithObjectMacro(this->External, << "UpdateBackgroundColor (" <<
backgroundColor[0] << ", " << backgroundColor[1] << ", "
<< backgroundColor[2] << ")");
this->External->GetRenderer()->SetBackground(backgroundColor);
// If new background color is White, switch axis color label to black
if (backgroundColor[0] == 1.0 && backgroundColor[1] == 1.0 && backgroundColor[2] == 1.0)
{
double black[3] = {0.0, 0.0, 0.0};
this->SetAxisLabelColor(black);
}
else
{
double white[3] = {1.0, 1.0, 1.0};
this->SetAxisLabelColor(white);
}
this->External->RequestRender();
}
//---------------------------------------------------------------------------
// vtkMRMLViewDisplayableManager methods
......@@ -382,6 +421,7 @@ void vtkMRMLViewDisplayableManager::AdditionnalInitializeStep()
this->AddMRMLDisplayableManagerEvent(vtkMRMLViewNode::RenderModeEvent);
this->AddMRMLDisplayableManagerEvent(vtkMRMLViewNode::VisibilityEvent);
this->AddMRMLDisplayableManagerEvent(vtkMRMLViewNode::StereoModeEvent);
this->AddMRMLDisplayableManagerEvent(vtkMRMLViewNode::BackgroundColorEvent);
}
//---------------------------------------------------------------------------
......@@ -442,6 +482,11 @@ void vtkMRMLViewDisplayableManager::ProcessMRMLEvents(vtkObject * caller,
vtkDebugMacro(<< "ProcessMRMLEvents - StereoModeEvent");
this->Internal->UpdateStereoType();
}
else if (event == vtkMRMLViewNode::BackgroundColorEvent)
{
vtkDebugMacro(<< "ProcessMRMLEvents - BackgroundColorEvent");
this->Internal->UpdateBackgroundColor();
}
}
// Default MRML Event handler is NOT needed
// else
......
......@@ -349,6 +349,42 @@
<string>3D axis label</string>
</property>
</action>
<action name="actionSetLightBlueBackground">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Light blue background</string>
</property>
<property name="toolTip">
<string>Set light blue background</string>
</property>
</action>
<action name="actionSetBlackBackground">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Black background</string>
</property>
<property name="toolTip">
<string>Set black background</string>
</property>
</action>
<action name="actionSetWhiteBackground">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>White background</string>
</property>
<property name="toolTip">
<string>Set white background</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
......
......@@ -106,15 +106,29 @@ void qMRMLThreeDViewsControllerWidgetPrivate::setupUi(qMRMLWidget* widget)
connect(stereoTypesActions, SIGNAL(triggered(QAction*)),
this->StereoTypesMapper, SLOT(map(QAction*)));
// Show 3D Axis, 3D Axis label
QMenu* visibilityMenu = new QMenu("Visibility", widget);
this->VisibilityButton->setMenu(visibilityMenu);
// Show 3D Axis, 3D Axis label
visibilityMenu->addAction(this->actionSet3DAxisVisible);
visibilityMenu->addAction(this->actionSet3DAxisLabelVisible);
this->VisibilityButton->setMenu(visibilityMenu);
connect(this->actionSet3DAxisVisible, SIGNAL(triggered(bool)),
SLOT(set3DAxisVisible(bool)));
connect(this->actionSet3DAxisLabelVisible, SIGNAL(triggered(bool)),
SLOT(set3DAxisLabelVisible(bool)));
// Background color
QActionGroup* backgroundColorActions = new QActionGroup(widget);
backgroundColorActions->setExclusive(true);
visibilityMenu->addAction(this->actionSetLightBlueBackground);
visibilityMenu->addAction(this->actionSetBlackBackground);
visibilityMenu->addAction(this->actionSetWhiteBackground);
backgroundColorActions->addAction(this->actionSetLightBlueBackground);
backgroundColorActions->addAction(this->actionSetBlackBackground);
backgroundColorActions->addAction(this->actionSetWhiteBackground);
connect(this->actionSetLightBlueBackground, SIGNAL(triggered()), SLOT(setLightBlueBackground()));
connect(this->actionSetWhiteBackground, SIGNAL(triggered()), SLOT(setWhiteBackground()));
connect(this->actionSetBlackBackground, SIGNAL(triggered()), SLOT(setBlackBackground()));
}
// --------------------------------------------------------------------------
......@@ -205,6 +219,10 @@ void qMRMLThreeDViewsControllerWidgetPrivate::setStereoType(int newStereoType)
// --------------------------------------------------------------------------
void qMRMLThreeDViewsControllerWidgetPrivate::set3DAxisVisible(bool visible)
{
if (!this->ActiveMRMLThreeDViewNode)
{
return;
}
this->actionSet3DAxisVisible->setChecked(visible);
this->ActiveMRMLThreeDViewNode->SetBoxVisible(visible);
}
......@@ -212,10 +230,68 @@ void qMRMLThreeDViewsControllerWidgetPrivate::set3DAxisVisible(bool visible)
// --------------------------------------------------------------------------
void qMRMLThreeDViewsControllerWidgetPrivate::set3DAxisLabelVisible(bool visible)
{
if (!this->ActiveMRMLThreeDViewNode)
{
return;
}
this->actionSet3DAxisLabelVisible->setChecked(visible);
this->ActiveMRMLThreeDViewNode->SetAxisLabelsVisible(visible);
}
// --------------------------------------------------------------------------
namespace
{
//bool isLightBlueColor(double color[3])
//{
// return color[0] == 0.70196 && color[1] == 0.70196 && color[2] == 0.90588;
//}
bool isWhiteColor(double color[3])
{
return color[0] == 1.0 && color[1] == 1.0 && color[2] == 1.0;
}
bool isBlackColor(double color[3])
{
return color[0] == 0.0 && color[1] == 0.0 && color[2] == 0.0;
}
}
// --------------------------------------------------------------------------
void qMRMLThreeDViewsControllerWidgetPrivate::setLightBlueBackground()
{
double lightBlue[3] = {0.70196, 0.70196, 0.90588};
this->setBackgroundColor(lightBlue);
}
// --------------------------------------------------------------------------
void qMRMLThreeDViewsControllerWidgetPrivate::setBlackBackground()
{
double black[3] = {0.0, 0.0, 0.0};
this->setBackgroundColor(black);
}
// --------------------------------------------------------------------------
void qMRMLThreeDViewsControllerWidgetPrivate::setWhiteBackground()
{
double white[3] = {1.0, 1.0, 1.0};
this->setBackgroundColor(white);
}
// --------------------------------------------------------------------------
void qMRMLThreeDViewsControllerWidgetPrivate::setBackgroundColor(double newBackgroundColor[3])
{
if (!this->ActiveMRMLThreeDViewNode)
{
return;
}
this->actionSetLightBlueBackground->setChecked(!isWhiteColor(newBackgroundColor)
&& !isBlackColor(newBackgroundColor));
this->actionSetWhiteBackground->setChecked(isWhiteColor(newBackgroundColor));
this->actionSetBlackBackground->setChecked(isBlackColor(newBackgroundColor));
this->ActiveMRMLThreeDViewNode->SetBackgroundColor(newBackgroundColor);
}
// --------------------------------------------------------------------------
// qMRMLThreeDViewsControllerWidget methods
......
......@@ -69,6 +69,11 @@ public slots:
void set3DAxisVisible(bool visible);
void set3DAxisLabelVisible(bool visible);
void setLightBlueBackground();
void setBlackBackground();
void setWhiteBackground();
void setBackgroundColor(double newBackgroundColor[3]);
public:
vtkMRMLViewNode* ActiveMRMLThreeDViewNode;
......
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