Quellcode durchsuchen

ENH: Add ctkVTKScalarBarWidget that represents a vtkScalarBarWidget

Julien Finet vor 15 Jahren
Ursprung
Commit
d84be20650

+ 5 - 0
Libs/Visualization/VTK/Widgets/CMakeLists.txt

@@ -31,6 +31,8 @@ SET(KIT_SRCS
   ctkVTKRenderView.cpp
   ctkVTKRenderView.h
   ctkVTKRenderView_p.h
+  ctkVTKScalarBarWidget.cpp
+  ctkVTKScalarBarWidget.h
   ctkVTKSliceView.cpp
   ctkVTKSliceView.h
   ctkVTKSliceView_p.h
@@ -44,6 +46,7 @@ SET(KIT_MOC_SRCS
   ctkVTKMatrixWidget.h
   ctkVTKRenderView.h
   ctkVTKRenderView_p.h
+  ctkVTKScalarBarWidget.h
   ctkVTKSliceView.h
   ctkVTKSliceView_p.h
   ctkVTKTextPropertyWidget.h
@@ -51,11 +54,13 @@ SET(KIT_MOC_SRCS
 
 # UI files
 SET(KIT_UI_FORMS
+  Resources/UI/ctkVTKScalarBarWidget.ui
   Resources/UI/ctkVTKTextPropertyWidget.ui
 )
 
 # Resources
 SET(KIT_resources
+
 )
 
 # Set VTK_LIBRARIES variable

+ 3 - 0
Libs/Visualization/VTK/Widgets/Plugins/CMakeLists.txt

@@ -15,6 +15,8 @@ SET(PLUGIN_SRCS
 
   ctkVTKRenderViewPlugin.cpp
   ctkVTKRenderViewPlugin.h
+  ctkVTKScalarBarWidgetPlugin.cpp
+  ctkVTKScalarBarWidgetPlugin.h
   ctkVTKSliceViewPlugin.cpp
   ctkVTKSliceViewPlugin.h
   ctkVTKTextPropertyWidgetPlugin.cpp
@@ -26,6 +28,7 @@ SET(PLUGIN_MOC_SRCS
   ctkVTKWidgetsPlugins.h
 
   ctkVTKRenderViewPlugin.h
+  ctkVTKScalarBarWidgetPlugin.h
   ctkVTKSliceViewPlugin.h
   ctkVTKTextPropertyWidgetPlugin.h
   )

+ 61 - 0
Libs/Visualization/VTK/Widgets/Plugins/ctkVTKScalarBarWidgetPlugin.cpp

@@ -0,0 +1,61 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  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.
+
+=========================================================================*/
+
+// CTK includes
+#include "ctkVTKScalarBarWidget.h"
+#include "ctkVTKScalarBarWidgetPlugin.h"
+
+//-----------------------------------------------------------------------------
+ctkVTKScalarBarWidgetPlugin::ctkVTKScalarBarWidgetPlugin(QObject *_parent):QObject(_parent)
+{
+}
+
+//-----------------------------------------------------------------------------
+QWidget *ctkVTKScalarBarWidgetPlugin::createWidget(QWidget *parentWidget)
+{
+  ctkVTKScalarBarWidget* newWidget = new ctkVTKScalarBarWidget(parentWidget);
+  return newWidget;
+}
+
+//-----------------------------------------------------------------------------
+QString ctkVTKScalarBarWidgetPlugin::domXml() const
+{
+  return "<widget class=\"ctkVTKScalarBarWidget\" \
+          name=\"VTKScalarBar\">\n"
+          "</widget>\n";
+}
+
+//-----------------------------------------------------------------------------
+QString ctkVTKScalarBarWidgetPlugin::includeFile() const
+{
+  return "ctkVTKScalarBarWidget.h";
+}
+
+//-----------------------------------------------------------------------------
+bool ctkVTKScalarBarWidgetPlugin::isContainer() const
+{
+  return false;
+}
+
+//-----------------------------------------------------------------------------
+QString ctkVTKScalarBarWidgetPlugin::name() const
+{
+  return "ctkVTKScalarBarWidget";
+}

+ 43 - 0
Libs/Visualization/VTK/Widgets/Plugins/ctkVTKScalarBarWidgetPlugin.h

@@ -0,0 +1,43 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  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.
+
+=========================================================================*/
+
+#ifndef __ctkVTKScalarBarWidgetPlugin_h
+#define __ctkVTKScalarBarWidgetPlugin_h
+
+// CTK includes
+#include "ctkVTKWidgetsAbstractPlugin.h"
+
+class CTK_VISUALIZATION_VTK_WIDGETS_PLUGINS_EXPORT ctkVTKScalarBarWidgetPlugin :
+  public QObject,
+  public ctkVTKWidgetsAbstractPlugin
+{
+  Q_OBJECT
+
+public:
+  ctkVTKScalarBarWidgetPlugin(QObject *_parent = 0);
+
+  QWidget *createWidget(QWidget *_parent);
+  QString domXml() const;
+  QString includeFile() const;
+  bool isContainer() const;
+  QString name() const;
+};
+
+#endif

+ 2 - 0
Libs/Visualization/VTK/Widgets/Plugins/ctkVTKWidgetsPlugins.h

@@ -27,6 +27,7 @@
 // CTK includes
 #include "CTKVisualizationVTKWidgetsPluginsExport.h"
 #include "ctkVTKRenderViewPlugin.h"
+#include "ctkVTKScalarBarWidgetPlugin.h"
 #include "ctkVTKSliceViewPlugin.h"
 #include "ctkVTKTextPropertyWidgetPlugin.h"
 
@@ -43,6 +44,7 @@ public:
     {
     QList<QDesignerCustomWidgetInterface *> plugins;
     plugins << new ctkVTKRenderViewPlugin;
+    plugins << new ctkVTKScalarBarWidgetPlugin;
     plugins << new ctkVTKSliceViewPlugin;
     plugins << new ctkVTKTextPropertyWidgetPlugin;
     return plugins;

+ 103 - 0
Libs/Visualization/VTK/Widgets/Resources/UI/ctkVTKScalarBarWidget.ui

@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkVTKScalarBarWidget</class>
+ <widget class="QWidget" name="ctkVTKScalarBarWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>311</width>
+    <height>535</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>vtkScalarBarWidget</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout_3">
+   <property name="margin">
+    <number>0</number>
+   </property>
+   <item row="0" column="0" colspan="2">
+    <widget class="QCheckBox" name="DisplayScalarBarCheckBox">
+     <property name="text">
+      <string>Display scalar bar</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0" colspan="2">
+    <widget class="QGroupBox" name="TitleGroupBox">
+     <property name="title">
+      <string>Title properties:</string>
+     </property>
+     <property name="flat">
+      <bool>true</bool>
+     </property>
+     <layout class="QGridLayout" name="gridLayout">
+      <item row="0" column="0">
+       <widget class="ctkVTKTextPropertyWidget" name="TitleTextPropertyWidget"/>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item row="2" column="0" colspan="2">
+    <widget class="QGroupBox" name="LabelsGroupBox">
+     <property name="title">
+      <string>Labels properties:</string>
+     </property>
+     <property name="flat">
+      <bool>true</bool>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_2">
+      <item row="0" column="0">
+       <widget class="ctkVTKTextPropertyWidget" name="LabelsTextPropertyWidget">
+        <property name="textLabel">
+         <string>Format:</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item row="3" column="0">
+    <widget class="QLabel" name="MaxNumberOfColorsLabel">
+     <property name="text">
+      <string>Maximum number of colors:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="1">
+    <widget class="QSpinBox" name="MaxNumberOfColorsSpinBox">
+     <property name="minimum">
+      <number>2</number>
+     </property>
+     <property name="maximum">
+      <number>9999</number>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="0">
+    <widget class="QLabel" name="NumberOfLabelsLabel">
+     <property name="text">
+      <string>Number of labels:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="1">
+    <widget class="QSpinBox" name="NumberOfLabelsSpinBox">
+     <property name="maximum">
+      <number>64</number>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>ctkVTKTextPropertyWidget</class>
+   <extends>QWidget</extends>
+   <header>ctkVTKTextPropertyWidget.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>

+ 195 - 0
Libs/Visualization/VTK/Widgets/ctkVTKScalarBarWidget.cpp

@@ -0,0 +1,195 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  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.
+
+=========================================================================*/
+
+// Qt includes
+
+// CTK includes
+#include "ctkVTKScalarBarWidget.h"
+#include "ui_ctkVTKScalarBarWidget.h"
+
+// VTK includes
+#include <vtkScalarBarActor.h>
+#include <vtkScalarBarWidget.h>
+
+//-----------------------------------------------------------------------------
+class ctkVTKScalarBarWidgetPrivate
+  : public ctkPrivate<ctkVTKScalarBarWidget>
+  , public Ui_ctkVTKScalarBarWidget
+{
+public:
+  ctkVTKScalarBarWidgetPrivate();
+  void init();
+  vtkScalarBarWidget* ScalarBarWidget;
+};
+
+//-----------------------------------------------------------------------------
+ctkVTKScalarBarWidgetPrivate::ctkVTKScalarBarWidgetPrivate()
+{
+  this->ScalarBarWidget = 0;
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKScalarBarWidgetPrivate::init()
+{
+  CTK_P(ctkVTKScalarBarWidget);
+  this->setupUi(p);
+  p->setEnabled(this->ScalarBarWidget != 0);
+  QObject::connect(this->DisplayScalarBarCheckBox, SIGNAL(toggled(bool)),
+                   p, SLOT(setDisplay(bool)));
+  QObject::connect(this->MaxNumberOfColorsSpinBox, SIGNAL(valueChanged(int)),
+                   p, SLOT(setMaxNumberOfColors(int)));
+  QObject::connect(this->NumberOfLabelsSpinBox, SIGNAL(valueChanged(int)),
+                   p, SLOT(setNumberOfLabels(int)));
+  QObject::connect(this->TitleTextPropertyWidget, SIGNAL(textChanged(const QString&)),
+                   p, SLOT(setTitle(const QString&)));
+  QObject::connect(this->LabelsTextPropertyWidget, SIGNAL(textChanged(const QString&)),
+                   p, SLOT(setLabelsFormat(const QString&)));
+}
+
+//-----------------------------------------------------------------------------
+ctkVTKScalarBarWidget::ctkVTKScalarBarWidget(QWidget* parentWidget)
+  :QWidget(parentWidget)
+{
+  CTK_INIT_PRIVATE(ctkVTKScalarBarWidget);
+  CTK_D(ctkVTKScalarBarWidget);
+  d->init();
+}
+
+//-----------------------------------------------------------------------------
+ctkVTKScalarBarWidget::ctkVTKScalarBarWidget(vtkScalarBarWidget* scalarBarWidget, QWidget* parentWidget)
+  :QWidget(parentWidget)
+{
+  CTK_INIT_PRIVATE(ctkVTKScalarBarWidget);
+  CTK_D(ctkVTKScalarBarWidget);
+  d->init();
+  this->setScalarBarWidget(scalarBarWidget);
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKScalarBarWidget::setScalarBarWidget(vtkScalarBarWidget* scalarBarWidget)
+{
+  CTK_D(ctkVTKScalarBarWidget);
+  if (scalarBarWidget == d->ScalarBarWidget)
+    {
+    return;
+    }
+  vtkScalarBarActor* oldActor =
+    d->ScalarBarWidget ? d->ScalarBarWidget->GetScalarBarActor() : 0;
+  vtkScalarBarActor* newActor =
+    scalarBarWidget ? scalarBarWidget->GetScalarBarActor() : 0;
+  qvtkReconnect(oldActor, newActor, vtkCommand::ModifiedEvent,
+                this, SLOT(updateFromScalarBarWidget()));
+  d->ScalarBarWidget = scalarBarWidget;
+  this->updateFromScalarBarWidget();
+}
+
+//-----------------------------------------------------------------------------
+vtkScalarBarWidget* ctkVTKScalarBarWidget::scalarBarWidget()const
+{
+  CTK_D(const ctkVTKScalarBarWidget);
+  return d->ScalarBarWidget;
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKScalarBarWidget::updateFromScalarBarWidget()
+{
+  CTK_D(const ctkVTKScalarBarWidget);
+
+  vtkScalarBarActor* actor =
+    d->ScalarBarWidget ? d->ScalarBarWidget->GetScalarBarActor() : 0;
+  this->setEnabled(actor != 0);
+  if (actor == 0)
+    {
+    return;
+    }
+  d->DisplayScalarBarCheckBox->setChecked(d->ScalarBarWidget->GetEnabled() != 0);
+  d->MaxNumberOfColorsSpinBox->setValue(actor->GetMaximumNumberOfColors());
+  d->NumberOfLabelsSpinBox->setValue(actor->GetNumberOfLabels());
+
+  d->TitleTextPropertyWidget->setTextProperty(
+    actor ? actor->GetTitleTextProperty() : 0);
+  d->LabelsTextPropertyWidget->setTextProperty(
+    actor ? actor->GetLabelTextProperty() : 0);
+  d->TitleTextPropertyWidget->setText(actor->GetTitle());
+  d->LabelsTextPropertyWidget->setText(actor->GetLabelFormat());
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKScalarBarWidget::setDisplay(bool visible)
+{
+  CTK_D(ctkVTKScalarBarWidget);
+  if (d->ScalarBarWidget == 0)
+    {
+    return;
+    }
+  d->ScalarBarWidget->SetEnabled(visible);
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKScalarBarWidget::setMaxNumberOfColors(int colorCount)
+{
+  CTK_D(ctkVTKScalarBarWidget);
+  vtkScalarBarActor* actor =
+    d->ScalarBarWidget ? d->ScalarBarWidget->GetScalarBarActor() : 0;
+  if (actor == 0)
+    {
+    return;
+    }
+  actor->SetMaximumNumberOfColors(colorCount);
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKScalarBarWidget::setNumberOfLabels(int labelCount)
+{
+  CTK_D(ctkVTKScalarBarWidget);
+  vtkScalarBarActor* actor =
+    d->ScalarBarWidget ? d->ScalarBarWidget->GetScalarBarActor() : 0;
+  if (actor == 0)
+    {
+    return;
+    }
+  actor->SetNumberOfLabels(labelCount);
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKScalarBarWidget::setTitle(const QString& title)
+{
+  CTK_D(ctkVTKScalarBarWidget);
+  vtkScalarBarActor* actor =
+    d->ScalarBarWidget ? d->ScalarBarWidget->GetScalarBarActor() : 0;
+  if (actor == 0)
+    {
+    return;
+    }
+  actor->SetTitle(title.toStdString().c_str());
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKScalarBarWidget::setLabelsFormat(const QString& format)
+{
+  CTK_D(ctkVTKScalarBarWidget);
+  vtkScalarBarActor* actor =
+    d->ScalarBarWidget ? d->ScalarBarWidget->GetScalarBarActor() : 0;
+  if (actor == 0)
+    {
+    return;
+    }
+  actor->SetLabelFormat(format.toStdString().c_str());
+}

+ 62 - 0
Libs/Visualization/VTK/Widgets/ctkVTKScalarBarWidget.h

@@ -0,0 +1,62 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  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.
+
+=========================================================================*/
+
+#ifndef __ctkVTKScalarBarWidget_h
+#define __ctkVTKScalarBarWidget_h
+
+// Qt includes
+#include <QWidget>
+
+// CTK includes
+#include <ctkPimpl.h>
+#include "CTKVisualizationVTKWidgetsExport.h"
+#include "ctkVTKObject.h"
+
+class ctkVTKScalarBarWidgetPrivate;
+class vtkScalarBarWidget;
+
+class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKScalarBarWidget : public QWidget
+{
+  Q_OBJECT;
+  QVTK_OBJECT;
+
+public:
+  /// Constructors
+  ctkVTKScalarBarWidget(QWidget* parentWidget);
+  ctkVTKScalarBarWidget(vtkScalarBarWidget* scalarBar, QWidget* parentWidget);
+
+  vtkScalarBarWidget* scalarBarWidget()const;
+
+public slots:
+  void setScalarBarWidget(vtkScalarBarWidget* scalarBar);
+  void setDisplay(bool visible);
+  void setMaxNumberOfColors(int colorCount);
+  void setNumberOfLabels(int labelCount);
+  void setTitle(const QString& title);
+  void setLabelsFormat(const QString& format);
+
+protected slots:
+  void updateFromScalarBarWidget();
+
+private:
+  CTK_DECLARE_PRIVATE(ctkVTKScalarBarWidget);
+};
+
+#endif