Просмотр исходного кода

Add ctkVTKPropertyWidget, a vtkProperty Qt widget

Julien Finet лет назад: 12
Родитель
Сommit
cfe0b3dd94

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

@@ -34,6 +34,8 @@ set(KIT_SRCS
   ctkVTKMagnifyView_p.h
   ctkVTKMatrixWidget.cpp
   ctkVTKMatrixWidget.h
+  ctkVTKPropertyWidget.cpp
+  ctkVTKPropertyWidget.h
   ctkVTKRenderView.cpp
   ctkVTKRenderView.h
   ctkVTKRenderView_p.h
@@ -66,6 +68,7 @@ set(KIT_MOC_SRCS
   ctkVTKMagnifyView.h
   ctkVTKMagnifyView_p.h
   ctkVTKMatrixWidget.h
+  ctkVTKPropertyWidget.h
   ctkVTKRenderView.h
   ctkVTKRenderView_p.h
   ctkVTKScalarBarWidget.h
@@ -81,6 +84,7 @@ set(KIT_MOC_SRCS
 set(KIT_UI_FORMS
   Resources/UI/ctkVTKScalarBarWidget.ui
   Resources/UI/ctkVTKTextPropertyWidget.ui
+  Resources/UI/ctkVTKPropertyWidget.ui
   Resources/UI/ctkVTKThresholdWidget.ui
 )
 

+ 4 - 1
Libs/Visualization/VTK/Widgets/Plugins/CMakeLists.txt

@@ -17,6 +17,8 @@ set(PLUGIN_SRCS
   ctkVTKDataSetArrayComboBoxPlugin.h
   ctkVTKMagnifyViewPlugin.cpp
   ctkVTKMagnifyViewPlugin.h
+  ctkVTKPropertyWidgetPlugin.cpp
+  ctkVTKPropertyWidgetPlugin.h
   ctkVTKRenderViewPlugin.cpp
   ctkVTKRenderViewPlugin.h
   ctkVTKScalarBarWidgetPlugin.cpp
@@ -37,6 +39,7 @@ set(PLUGIN_MOC_SRCS
 
   ctkVTKDataSetArrayComboBoxPlugin.h
   ctkVTKMagnifyViewPlugin.h
+  ctkVTKPropertyWidgetPlugin.h
   ctkVTKRenderViewPlugin.h
   ctkVTKScalarBarWidgetPlugin.h
   ctkVTKSliceViewPlugin.h
@@ -44,7 +47,7 @@ set(PLUGIN_MOC_SRCS
   ctkVTKTextPropertyWidgetPlugin.h
   ctkVTKThresholdWidgetPlugin.h
   )
-  
+
 if(CTK_USE_CHARTS)
   set(PLUGIN_SRCS
       ctkVTKChartViewPlugin.cpp

+ 65 - 0
Libs/Visualization/VTK/Widgets/Plugins/ctkVTKPropertyWidgetPlugin.cpp

@@ -0,0 +1,65 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 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.apache.org/licenses/LICENSE-2.0.txt
+
+  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 "ctkVTKPropertyWidget.h"
+#include "ctkVTKPropertyWidgetPlugin.h"
+
+//-----------------------------------------------------------------------------
+ctkVTKPropertyWidgetPlugin
+::ctkVTKPropertyWidgetPlugin(QObject* pluginParent)
+ : QObject(pluginParent)
+{
+}
+
+//-----------------------------------------------------------------------------
+QWidget *ctkVTKPropertyWidgetPlugin
+::createWidget(QWidget *parentWidget)
+{
+  ctkVTKPropertyWidget* newWidget =
+    new ctkVTKPropertyWidget(parentWidget);
+  return newWidget;
+}
+
+//-----------------------------------------------------------------------------
+QString ctkVTKPropertyWidgetPlugin::domXml() const
+{
+  return "<widget class=\"ctkVTKPropertyWidget\" \
+          name=\"PropertyWidget\">\n"
+          "</widget>\n";
+}
+
+//-----------------------------------------------------------------------------
+QString ctkVTKPropertyWidgetPlugin::includeFile() const
+{
+  return "ctkVTKPropertyWidget.h";
+}
+
+//-----------------------------------------------------------------------------
+bool ctkVTKPropertyWidgetPlugin::isContainer() const
+{
+  return false;
+}
+
+//-----------------------------------------------------------------------------
+QString ctkVTKPropertyWidgetPlugin::name() const
+{
+  return "ctkVTKPropertyWidget";
+}

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

@@ -0,0 +1,43 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 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.apache.org/licenses/LICENSE-2.0.txt
+
+  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 __ctkVTKPropertyWidgetPlugin_h
+#define __ctkVTKPropertyWidgetPlugin_h
+
+// CTK includes
+#include "ctkVTKWidgetsAbstractPlugin.h"
+
+class CTK_VISUALIZATION_VTK_WIDGETS_PLUGINS_EXPORT ctkVTKPropertyWidgetPlugin
+  : public QObject
+  , public ctkVTKWidgetsAbstractPlugin
+{
+  Q_OBJECT
+
+public:
+  ctkVTKPropertyWidgetPlugin(QObject *_parent = 0);
+
+  QWidget *createWidget(QWidget *_parent);
+  QString domXml() const;
+  QString includeFile() const;
+  bool isContainer() const;
+  QString name() const;
+};
+
+#endif

+ 5 - 2
Libs/Visualization/VTK/Widgets/Plugins/ctkVTKSurfaceMaterialPropertyWidgetPlugin.cpp

@@ -23,12 +23,15 @@
 #include "ctkVTKSurfaceMaterialPropertyWidgetPlugin.h"
 
 //-----------------------------------------------------------------------------
-ctkVTKSurfaceMaterialPropertyWidgetPlugin::ctkVTKSurfaceMaterialPropertyWidgetPlugin(QObject *_parent):QObject(_parent)
+ctkVTKSurfaceMaterialPropertyWidgetPlugin
+::ctkVTKSurfaceMaterialPropertyWidgetPlugin(QObject* pluginParent)
+ : QObject(pluginParent)
 {
 }
 
 //-----------------------------------------------------------------------------
-QWidget *ctkVTKSurfaceMaterialPropertyWidgetPlugin::createWidget(QWidget *parentWidget)
+QWidget *ctkVTKSurfaceMaterialPropertyWidgetPlugin
+::createWidget(QWidget *parentWidget)
 {
   ctkVTKSurfaceMaterialPropertyWidget* newWidget =
     new ctkVTKSurfaceMaterialPropertyWidget(parentWidget);

+ 3 - 3
Libs/Visualization/VTK/Widgets/Plugins/ctkVTKSurfaceMaterialPropertyWidgetPlugin.h

@@ -24,9 +24,9 @@
 // CTK includes
 #include "ctkVTKWidgetsAbstractPlugin.h"
 
-class CTK_VISUALIZATION_VTK_WIDGETS_PLUGINS_EXPORT ctkVTKSurfaceMaterialPropertyWidgetPlugin :
-  public QObject,
-  public ctkVTKWidgetsAbstractPlugin
+class CTK_VISUALIZATION_VTK_WIDGETS_PLUGINS_EXPORT ctkVTKSurfaceMaterialPropertyWidgetPlugin
+  : public QObject
+  , public ctkVTKWidgetsAbstractPlugin
 {
   Q_OBJECT
 

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

@@ -28,6 +28,7 @@
 #include "ctkVisualizationVTKWidgetsPluginsExport.h"
 #include "ctkVTKDataSetArrayComboBoxPlugin.h"
 #include "ctkVTKMagnifyViewPlugin.h"
+#include "ctkVTKPropertyWidgetPlugin.h"
 #include "ctkVTKRenderViewPlugin.h"
 #include "ctkVTKScalarBarWidgetPlugin.h"
 #ifdef CTK_USE_CHARTS
@@ -55,6 +56,7 @@ public:
     QList<QDesignerCustomWidgetInterface *> plugins;
     plugins << new ctkVTKDataSetArrayComboBoxPlugin;
     plugins << new ctkVTKMagnifyViewPlugin;
+    plugins << new ctkVTKPropertyWidgetPlugin;
     plugins << new ctkVTKRenderViewPlugin;
     plugins << new ctkVTKScalarBarWidgetPlugin;
 #ifdef CTK_USE_CHARTS

+ 326 - 0
Libs/Visualization/VTK/Widgets/Resources/UI/ctkVTKPropertyWidget.ui

@@ -0,0 +1,326 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkVTKPropertyWidget</class>
+ <widget class="QWidget" name="ctkVTKPropertyWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>406</width>
+    <height>284</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Property</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="leftMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <property name="topMargin">
+    <number>0</number>
+   </property>
+   <property name="bottomMargin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="ctkCollapsibleGroupBox" name="RepresentationCollapsibleGroupBox">
+     <property name="title">
+      <string>Representation</string>
+     </property>
+     <property name="collapsed">
+      <bool>true</bool>
+     </property>
+     <layout class="QFormLayout" name="formLayout_4">
+      <property name="fieldGrowthPolicy">
+       <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
+      </property>
+      <item row="0" column="0">
+       <widget class="QLabel" name="RepresentationLabel">
+        <property name="text">
+         <string>Representation:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QComboBox" name="RepresentationComboBox">
+        <item>
+         <property name="text">
+          <string>Points</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>Wireframe</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>Surface</string>
+         </property>
+        </item>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="PointSizeLabel">
+        <property name="text">
+         <string>Point Size:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="ctkSliderWidget" name="PointSizeSliderWidget">
+        <property name="decimals">
+         <number>2</number>
+        </property>
+        <property name="minimum">
+         <double>1.000000000000000</double>
+        </property>
+        <property name="maximum">
+         <double>100.000000000000000</double>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="0">
+       <widget class="QLabel" name="LineWidthLabel">
+        <property name="text">
+         <string>Line Width:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="1">
+       <widget class="ctkSliderWidget" name="LineWidthSliderWidget">
+        <property name="decimals">
+         <number>2</number>
+        </property>
+        <property name="minimum">
+         <double>1.000000000000000</double>
+        </property>
+        <property name="maximum">
+         <double>100.000000000000000</double>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="0">
+       <widget class="QLabel" name="CullingLabel">
+        <property name="text">
+         <string>Culling:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="1">
+       <layout class="QHBoxLayout" name="horizontalLayout">
+        <item>
+         <widget class="QCheckBox" name="FrontfaceCullingCheckBox">
+          <property name="text">
+           <string>Frontface</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QCheckBox" name="BackfaceCullingCheckBox">
+          <property name="text">
+           <string>Backface</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="ctkCollapsibleGroupBox" name="ColorCollapsibleGroupBox">
+     <property name="title">
+      <string>Color</string>
+     </property>
+     <layout class="QFormLayout" name="formLayout_3">
+      <property name="fieldGrowthPolicy">
+       <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
+      </property>
+      <item row="0" column="0">
+       <widget class="QLabel" name="ColorLabel">
+        <property name="text">
+         <string>Color:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="ctkColorPickerButton" name="ColorPickerButton">
+        <property name="displayColorName">
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="OpacityLabel">
+        <property name="text">
+         <string>Opacity:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="ctkSliderWidget" name="OpacitySliderWidget">
+        <property name="singleStep">
+         <double>0.100000000000000</double>
+        </property>
+        <property name="pageStep">
+         <double>0.250000000000000</double>
+        </property>
+        <property name="maximum">
+         <double>1.000000000000000</double>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="0">
+       <widget class="QLabel" name="EdgeVisibilityLabel">
+        <property name="text">
+         <string>Edge Visibility:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="1">
+       <widget class="QCheckBox" name="EdgeVisibilityCheckBox">
+        <property name="text">
+         <string/>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="0">
+       <widget class="QLabel" name="EdgeColorLabel">
+        <property name="text">
+         <string>Edge Color:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="1">
+       <widget class="ctkColorPickerButton" name="EdgeColorPickerButton"/>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="ctkCollapsibleGroupBox" name="LightingCollapsibleGroupBox">
+     <property name="title">
+      <string>Lighting</string>
+     </property>
+     <property name="collapsed">
+      <bool>true</bool>
+     </property>
+     <layout class="QFormLayout" name="formLayout_2">
+      <item row="0" column="0">
+       <widget class="QLabel" name="LightingLabel">
+        <property name="text">
+         <string>Lighting:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QCheckBox" name="LightingCheckBox">
+        <property name="text">
+         <string/>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="InterpolationLabel">
+        <property name="text">
+         <string>Interpolation:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="QComboBox" name="InterpolationComboBox">
+        <item>
+         <property name="text">
+          <string>Flat</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>Gouraud</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>Phong</string>
+         </property>
+        </item>
+       </widget>
+      </item>
+      <item row="2" column="0">
+       <widget class="QLabel" name="ShadingLabel">
+        <property name="text">
+         <string>Shading:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="1">
+       <widget class="QCheckBox" name="ShadingCheckBox">
+        <property name="text">
+         <string/>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="ctkCollapsibleGroupBox" name="MaterialCollapsibleGroupBox">
+     <property name="title">
+      <string>Material</string>
+     </property>
+     <property name="collapsed">
+      <bool>true</bool>
+     </property>
+     <layout class="QFormLayout" name="formLayout">
+      <property name="fieldGrowthPolicy">
+       <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
+      </property>
+      <item row="0" column="0" colspan="2">
+       <widget class="ctkVTKSurfaceMaterialPropertyWidget" name="MaterialPropertyWidget">
+        <property name="colorVisible">
+         <bool>false</bool>
+        </property>
+        <property name="opacityVisible">
+         <bool>false</bool>
+        </property>
+        <property name="backfaceCullingVisible">
+         <bool>false</bool>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>ctkCollapsibleGroupBox</class>
+   <extends>QGroupBox</extends>
+   <header>ctkCollapsibleGroupBox.h</header>
+   <container>1</container>
+  </customwidget>
+  <customwidget>
+   <class>ctkColorPickerButton</class>
+   <extends>QPushButton</extends>
+   <header>ctkColorPickerButton.h</header>
+  </customwidget>
+  <customwidget>
+   <class>ctkSliderWidget</class>
+   <extends>QWidget</extends>
+   <header>ctkSliderWidget.h</header>
+  </customwidget>
+  <customwidget>
+   <class>ctkVTKSurfaceMaterialPropertyWidget</class>
+   <extends>QWidget</extends>
+   <header>ctkVTKSurfaceMaterialPropertyWidget.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>

+ 9 - 0
Libs/Visualization/VTK/Widgets/Testing/Cpp/CMakeLists.txt

@@ -16,6 +16,7 @@ set(TEST_SOURCES
   ctkTransferFunctionViewTest3.cpp
   ctkTransferFunctionViewTest4.cpp
   ctkTransferFunctionViewTest5.cpp
+  ctkVTKPropertyWidgetTest.cpp
   ctkVTKRenderViewTest1.cpp
   ctkVTKScalarsToColorsUtilsTest1.cpp
   ctkVTKSliceViewTest1.cpp
@@ -72,6 +73,9 @@ if(CTK_USE_QTTESTING)
     )
 endif()
 
+include_directories(${CMAKE_SOURCE_DIR}/Libs/Testing
+                    ${CMAKE_CURRENT_BINARY_DIR})
+
 create_test_sourcelist(Tests ${KIT}CppTests.cpp
   ${TEST_SOURCES}
   #EXTRA_INCLUDE TestingMacros.h
@@ -93,6 +97,10 @@ set(TEST_MOC_CPP)
 if(TEST_MOC_SOURCES)
   QT4_WRAP_CPP(TEST_MOC_CPP ${TEST_MOC_SOURCES})
 endif()
+QT4_GENERATE_MOCS(
+  ctkVTKPropertyWidgetTest.cpp
+  )
+
 set(TEST_UI_CPP)
 if(TEST_UI_FORMS)
   QT4_WRAP_UI(TEST_UI_CPP ${TEST_UI_FORMS})
@@ -111,6 +119,7 @@ SIMPLE_TEST( ctkVTKDataSetArrayComboBoxTest1 )
 SIMPLE_TEST( ctkVTKDataSetModelTest1 )
 SIMPLE_TEST( ctkVTKMagnifyViewTest1 )
 SIMPLE_TEST( ctkVTKMatrixWidgetTest1 )
+SIMPLE_TEST( ctkVTKPropertyWidgetTest )
 SIMPLE_TEST( ctkVTKScalarBarWidgetTest1 )
 SIMPLE_TEST( ctkVTKScalarsToColorsUtilsTest1 )
 SIMPLE_TEST( ctkVTKThresholdWidgetTest1 )

+ 131 - 0
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKPropertyWidgetTest.cpp

@@ -0,0 +1,131 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 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.apache.org/licenses/LICENSE-2.0.txt
+
+  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
+#include <QApplication>
+#include <QString>
+#include <QStyle>
+#include <QStyleOptionSlider>
+#include <QTimer>
+
+// CTK includes
+#include "ctkVTKPropertyWidget.h"
+#include "ctkTest.h"
+
+// VTK includes
+#include <vtkProperty.h>
+
+// ----------------------------------------------------------------------------
+class ctkVTKPropertyWidgetTester: public QObject
+{
+  Q_OBJECT
+private slots:
+  void testGUIEvents();
+  void testVTKProperty();
+  void testProperties();
+};
+
+// ----------------------------------------------------------------------------
+void ctkVTKPropertyWidgetTester::testGUIEvents()
+{
+  ctkVTKPropertyWidget propertyWidget(0);
+  propertyWidget.show();
+  qApp->processEvents();
+  propertyWidget.resize(100, 100);
+  qApp->processEvents();
+  propertyWidget.resize(1, 100);
+  qApp->processEvents();
+  propertyWidget.resize(100, 1);
+  qApp->processEvents();
+  propertyWidget.hide();
+  qApp->processEvents();
+  propertyWidget.show();
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKPropertyWidgetTester::testVTKProperty()
+{
+  ctkVTKPropertyWidget propertyWidget(0);
+  vtkProperty* property = propertyWidget.property();
+
+  // ctkVTKPropertyWidget -> vtkProperty
+  double newOpacity(0.9);
+  propertyWidget.setOpacity(newOpacity);
+  QCOMPARE(property->GetOpacity(), newOpacity);
+
+  // ctkVTKPropertyWidget <- vtkProperty
+  newOpacity = 0.8;
+  property->SetOpacity(newOpacity);
+  QCOMPARE(propertyWidget.opacity(), newOpacity);
+
+  // new vtkProperty
+  property = vtkProperty::New();
+  newOpacity = 0.7;
+  property->SetOpacity(newOpacity);
+  propertyWidget.setProperty(property);
+  QCOMPARE(propertyWidget.opacity(), newOpacity);
+
+  // ctkVTKPropertyWidget -> vtkProperty
+  newOpacity = 0.6;
+  propertyWidget.setOpacity(newOpacity);
+  QCOMPARE(property->GetOpacity(), newOpacity);
+
+  // ctkVTKPropertyWidget <- vtkProperty
+  newOpacity = 0.5;
+  property->SetOpacity(newOpacity);
+  QCOMPARE(propertyWidget.opacity(), newOpacity);
+
+  property->Delete();
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKPropertyWidgetTester::testProperties()
+{
+  ctkVTKPropertyWidget propertyWidget(0);
+
+  propertyWidget.setRepresentation(0);
+  QCOMPARE(propertyWidget.representation(), 0);
+  propertyWidget.setPointSize(3.5);
+  QCOMPARE(propertyWidget.pointSize(), 3.5);
+  propertyWidget.setLineWidth(10.11);
+  QCOMPARE(propertyWidget.lineWidth(), 10.11);
+  propertyWidget.setFrontfaceCulling(true);
+  QCOMPARE(propertyWidget.frontfaceCulling(), true);
+  propertyWidget.setBackfaceCulling(true);
+  QCOMPARE(propertyWidget.backfaceCulling(), true);
+  propertyWidget.setColor(Qt::red);
+  QCOMPARE(propertyWidget.color(), QColor(Qt::red));
+  propertyWidget.setOpacity(0.1);
+  QCOMPARE(propertyWidget.opacity(), 0.1);
+  propertyWidget.setEdgeVisibility(true);
+  QCOMPARE(propertyWidget.edgeVisibility(), true);
+  propertyWidget.setEdgeColor(Qt::blue);
+  QCOMPARE(propertyWidget.edgeColor(), QColor(Qt::blue));
+  propertyWidget.setLighting(false);
+  QCOMPARE(propertyWidget.lighting(), false);
+  propertyWidget.setInterpolation(0);
+  QCOMPARE(propertyWidget.interpolation(), 0);
+  propertyWidget.setShading(false);
+  QCOMPARE(propertyWidget.shading(), false);
+}
+
+// ----------------------------------------------------------------------------
+CTK_TEST_MAIN(ctkVTKPropertyWidgetTest)
+#include "moc_ctkVTKPropertyWidgetTest.cpp"

+ 446 - 0
Libs/Visualization/VTK/Widgets/ctkVTKPropertyWidget.cpp

@@ -0,0 +1,446 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 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.apache.org/licenses/LICENSE-2.0.txt
+
+  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
+#include <QDebug>
+
+// CTK includes
+#include "ctkVTKPropertyWidget.h"
+#include "ui_ctkVTKPropertyWidget.h"
+
+// VTK includes
+#include <vtkSmartPointer.h>
+#include <vtkProperty.h>
+
+//-----------------------------------------------------------------------------
+class ctkVTKPropertyWidgetPrivate: public Ui_ctkVTKPropertyWidget
+{
+  Q_DECLARE_PUBLIC(ctkVTKPropertyWidget);
+protected:
+  ctkVTKPropertyWidget* const q_ptr;
+public:
+  ctkVTKPropertyWidgetPrivate(ctkVTKPropertyWidget& object);
+
+  virtual void setupUi(QWidget *widget);
+
+  vtkSmartPointer<vtkProperty> Property;
+};
+
+//-----------------------------------------------------------------------------
+ctkVTKPropertyWidgetPrivate::ctkVTKPropertyWidgetPrivate(ctkVTKPropertyWidget& object)
+  : q_ptr(&object)
+{
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKPropertyWidgetPrivate::setupUi(QWidget* widget)
+{
+  Q_Q(ctkVTKPropertyWidget);
+
+  this->Ui_ctkVTKPropertyWidget::setupUi(widget);
+
+  q->connect(this->RepresentationComboBox, SIGNAL(currentIndexChanged(int)),
+             q, SLOT(setRepresentation(int)));
+  q->connect(this->PointSizeSliderWidget, SIGNAL(valueChanged(double)),
+             q, SLOT(setPointSize(double)));
+  q->connect(this->LineWidthSliderWidget, SIGNAL(valueChanged(double)),
+             q, SLOT(setLineWidth(double)));
+  q->connect(this->FrontfaceCullingCheckBox, SIGNAL(toggled(bool)),
+             q, SLOT(setFrontfaceCulling(bool)));
+  q->connect(this->BackfaceCullingCheckBox, SIGNAL(toggled(bool)),
+             q, SLOT(setBackfaceCulling(bool)));
+
+  q->connect(this->ColorPickerButton, SIGNAL(colorChanged(QColor)),
+             q, SLOT(setColor(QColor)));
+  q->connect(this->OpacitySliderWidget, SIGNAL(valueChanged(double)),
+             q, SLOT(setOpacity(double)));
+  q->connect(this->EdgeVisibilityCheckBox, SIGNAL(toggled(bool)),
+             q, SLOT(setEdgeVisibility(bool)));
+  q->connect(this->EdgeColorPickerButton, SIGNAL(colorChanged(QColor)),
+             q, SLOT(setEdgeColor(QColor)));
+
+  q->connect(this->LightingCheckBox, SIGNAL(toggled(bool)),
+             q, SLOT(setLighting(bool)));
+  q->connect(this->InterpolationComboBox, SIGNAL(currentIndexChanged(int)),
+             q, SLOT(setInterpolation(int)));
+  q->connect(this->ShadingCheckBox, SIGNAL(toggled(bool)),
+             q, SLOT(setShading(bool)));
+}
+
+//-----------------------------------------------------------------------------
+ctkVTKPropertyWidget::~ctkVTKPropertyWidget()
+{
+}
+
+//-----------------------------------------------------------------------------
+ctkVTKPropertyWidget::ctkVTKPropertyWidget(QWidget* parentWidget)
+  : Superclass(parentWidget)
+  , d_ptr(new ctkVTKPropertyWidgetPrivate(*this))
+{
+  Q_D(ctkVTKPropertyWidget);
+  d->setupUi(this);
+
+  vtkSmartPointer<vtkProperty> property = vtkSmartPointer<vtkProperty>::New();
+  this->setProperty(property);
+}
+
+//-----------------------------------------------------------------------------
+ctkVTKPropertyWidget::ctkVTKPropertyWidget(vtkProperty* property, QWidget* parentWidget)
+  : Superclass(parentWidget)
+  , d_ptr(new ctkVTKPropertyWidgetPrivate(*this))
+{
+  Q_D(ctkVTKPropertyWidget);
+  d->setupUi(this);
+
+  this->setProperty(property);
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setProperty(vtkProperty* property)
+{
+  Q_D(ctkVTKPropertyWidget);
+  if (d->Property.GetPointer() == property)
+    {
+    return;
+    }
+  qvtkReconnect(d->Property, property, vtkCommand::ModifiedEvent,
+                this, SLOT(updateWidgetFromProperty()));
+  d->Property = property;
+  d->MaterialPropertyWidget->setProperty(property);
+  this->updateWidgetFromProperty();
+}
+
+//-----------------------------------------------------------------------------
+vtkProperty* ctkVTKPropertyWidget::property()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->Property.GetPointer();
+}
+
+//-----------------------------------------------------------------------------
+ctkVTKPropertyWidget::GroupsState ctkVTKPropertyWidget::groupsState()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  ctkVTKPropertyWidget::GroupsState state = 0;
+  ctkVTKPropertyWidget* constThis = const_cast<ctkVTKPropertyWidget*>(this);
+  if (d->RepresentationCollapsibleGroupBox->isVisibleTo(constThis) )
+    {
+    state |= ctkVTKPropertyWidget::RepresentationVisible;
+    }
+  if (d->RepresentationCollapsibleGroupBox->collapsed())
+    {
+    state |= ctkVTKPropertyWidget::RepresentationCollapsed;
+    }
+  if (d->ColorCollapsibleGroupBox->isVisibleTo(constThis) )
+    {
+    state |= ctkVTKPropertyWidget::ColorVisible;
+    }
+  if (d->ColorCollapsibleGroupBox->collapsed())
+    {
+    state |= ctkVTKPropertyWidget::ColorCollapsed;
+    }
+  if (d->LightingCollapsibleGroupBox->isVisibleTo(constThis) )
+    {
+    state |= ctkVTKPropertyWidget::LightingVisible;
+    }
+  if (d->LightingCollapsibleGroupBox->collapsed())
+    {
+    state |= ctkVTKPropertyWidget::LightingCollapsed;
+    }
+  if (d->MaterialCollapsibleGroupBox->isVisibleTo(constThis) )
+    {
+    state |= ctkVTKPropertyWidget::MaterialVisible;
+    }
+  if (d->MaterialCollapsibleGroupBox->collapsed())
+    {
+    state |= ctkVTKPropertyWidget::MaterialCollapsed;
+    }
+  return state;
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setGroupsState(ctkVTKPropertyWidget::GroupsState state)
+{
+  Q_D(ctkVTKPropertyWidget);
+  d->RepresentationCollapsibleGroupBox->setVisible(
+    state & ctkVTKPropertyWidget::RepresentationVisible);
+  d->RepresentationCollapsibleGroupBox->setCollapsed(
+    state & ctkVTKPropertyWidget::RepresentationCollapsed);
+  d->ColorCollapsibleGroupBox->setVisible(
+    state & ctkVTKPropertyWidget::ColorVisible);
+  d->ColorCollapsibleGroupBox->setCollapsed(
+    state & ctkVTKPropertyWidget::ColorCollapsed);
+  d->LightingCollapsibleGroupBox->setVisible(
+    state & ctkVTKPropertyWidget::LightingVisible);
+  d->LightingCollapsibleGroupBox->setCollapsed(
+    state & ctkVTKPropertyWidget::LightingCollapsed);
+  d->MaterialCollapsibleGroupBox->setVisible(
+    state & ctkVTKPropertyWidget::MaterialVisible);
+  d->MaterialCollapsibleGroupBox->setCollapsed(
+    state & ctkVTKPropertyWidget::MaterialCollapsed);
+}
+
+//-----------------------------------------------------------------------------
+ctkColorPickerButton::ColorDialogOptions ctkVTKPropertyWidget
+::colorDialogOptions()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->ColorPickerButton->dialogOptions();
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKPropertyWidget
+::setColorDialogOptions(ctkColorPickerButton::ColorDialogOptions options)
+{
+  Q_D(ctkVTKPropertyWidget);
+  d->ColorPickerButton->setDialogOptions(options);
+  d->EdgeColorPickerButton->setDialogOptions(options);
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKPropertyWidget::updateWidgetFromProperty()
+{
+  Q_D(ctkVTKPropertyWidget);
+  this->setEnabled(d->Property.GetPointer() != 0);
+  if (d->Property.GetPointer() == 0)
+    {
+    return;
+    }
+  // Warning: Valid as long as the representation matches the combobox indexes.
+  d->RepresentationComboBox->setCurrentIndex( d->Property->GetRepresentation() );
+  d->PointSizeSliderWidget->setValue( d->Property->GetPointSize() );
+  d->LineWidthSliderWidget->setValue( d->Property->GetLineWidth() );
+  d->FrontfaceCullingCheckBox->setChecked( d->Property->GetFrontfaceCulling() );
+  d->BackfaceCullingCheckBox->setChecked( d->Property->GetBackfaceCulling() );
+  double* c = d->Property->GetColor();
+  d->ColorPickerButton->setColor(
+    QColor::fromRgbF(qMin(c[0],1.), qMin(c[1], 1.), qMin(c[2],1.)));
+  d->OpacitySliderWidget->setValue( d->Property->GetOpacity() );
+  d->EdgeVisibilityCheckBox->setChecked( d->Property->GetEdgeVisibility() );
+  double* ec = d->Property->GetEdgeColor();
+  d->EdgeColorPickerButton->setColor(
+    QColor::fromRgbF(qMin(ec[0],1.), qMin(ec[1], 1.), qMin(ec[2],1.)));
+  d->LightingCheckBox->setChecked( d->Property->GetLighting() );
+  d->InterpolationComboBox->setCurrentIndex( d->Property->GetInterpolation() );
+  d->ShadingCheckBox->setChecked( d->Property->GetShading() );
+}
+
+// --------------------------------------------------------------------------
+int ctkVTKPropertyWidget::representation()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->RepresentationComboBox->currentIndex();
+}
+
+// --------------------------------------------------------------------------
+double ctkVTKPropertyWidget::pointSize()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->PointSizeSliderWidget->value();
+}
+
+// --------------------------------------------------------------------------
+double ctkVTKPropertyWidget::lineWidth()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->LineWidthSliderWidget->value();
+}
+
+// --------------------------------------------------------------------------
+bool ctkVTKPropertyWidget::frontfaceCulling()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->FrontfaceCullingCheckBox->isChecked();
+}
+
+// --------------------------------------------------------------------------
+bool ctkVTKPropertyWidget::backfaceCulling()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->BackfaceCullingCheckBox->isChecked();
+}
+
+// --------------------------------------------------------------------------
+QColor ctkVTKPropertyWidget::color()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->ColorPickerButton->color();
+}
+
+// --------------------------------------------------------------------------
+double ctkVTKPropertyWidget::opacity()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->OpacitySliderWidget->value();
+}
+
+// --------------------------------------------------------------------------
+bool ctkVTKPropertyWidget::edgeVisibility()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->EdgeVisibilityCheckBox->isChecked();
+}
+
+// --------------------------------------------------------------------------
+QColor ctkVTKPropertyWidget::edgeColor()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->EdgeColorPickerButton->color();
+}
+
+// --------------------------------------------------------------------------
+bool ctkVTKPropertyWidget::lighting()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->LightingCheckBox->isChecked();
+}
+
+// --------------------------------------------------------------------------
+int ctkVTKPropertyWidget::interpolation()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->InterpolationComboBox->currentIndex();
+}
+
+// --------------------------------------------------------------------------
+bool ctkVTKPropertyWidget::shading()const
+{
+  Q_D(const ctkVTKPropertyWidget);
+  return d->ShadingCheckBox->isChecked();
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setRepresentation(int newRepresentation)
+{
+  Q_D(ctkVTKPropertyWidget);
+  if (d->Property.GetPointer() != 0)
+    {
+    d->Property->SetRepresentation(newRepresentation);
+    }
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setPointSize(double newPointSize)
+{
+  Q_D(ctkVTKPropertyWidget);
+  if (d->Property.GetPointer() != 0)
+    {
+    d->Property->SetPointSize(newPointSize);
+    }
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setLineWidth(double newLineWidth)
+{
+  Q_D(ctkVTKPropertyWidget);
+  if (d->Property.GetPointer() != 0)
+    {
+    d->Property->SetLineWidth(newLineWidth);
+    }
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setFrontfaceCulling(bool newFrontfaceCulling)
+{
+  Q_D(ctkVTKPropertyWidget);
+  if (d->Property.GetPointer() != 0)
+    {
+    d->Property->SetFrontfaceCulling(newFrontfaceCulling);
+    }
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setBackfaceCulling(bool newBackfaceCulling)
+{
+  Q_D(ctkVTKPropertyWidget);
+  if (d->Property.GetPointer() != 0)
+    {
+    d->Property->SetBackfaceCulling(newBackfaceCulling);
+    }
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setColor(const QColor& newColor)
+{
+  Q_D(ctkVTKPropertyWidget);
+  d->MaterialPropertyWidget->setColor(newColor);
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setOpacity(double newOpacity)
+{
+  Q_D(ctkVTKPropertyWidget);
+  if (d->Property.GetPointer() != 0)
+    {
+    d->Property->SetOpacity(newOpacity);
+    }
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setEdgeVisibility(bool newEdgeVisibility)
+{
+  Q_D(ctkVTKPropertyWidget);
+  if (d->Property.GetPointer() != 0)
+    {
+    d->Property->SetEdgeVisibility(newEdgeVisibility);
+    }
+}
+
+
+// --------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setEdgeColor(const QColor& newColor)
+{
+  Q_D(ctkVTKPropertyWidget);
+  if (d->Property.GetPointer() != 0)
+    {
+    d->Property->SetEdgeColor(
+      newColor.redF(), newColor.greenF(), newColor.blueF());
+    }
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setLighting(bool newLighting)
+{
+  Q_D(ctkVTKPropertyWidget);
+  if (d->Property.GetPointer() != 0)
+    {
+    d->Property->SetLighting(newLighting);
+    }
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setInterpolation(int newInterpolation)
+{
+  Q_D(ctkVTKPropertyWidget);
+  if (d->Property.GetPointer() != 0)
+    {
+    d->Property->SetInterpolation(newInterpolation);
+    }
+}
+
+// --------------------------------------------------------------------------
+void ctkVTKPropertyWidget::setShading(bool newShading)
+{
+  Q_D(ctkVTKPropertyWidget);
+  if (d->Property.GetPointer() != 0)
+    {
+    d->Property->SetShading(newShading);
+    }
+}

+ 131 - 0
Libs/Visualization/VTK/Widgets/ctkVTKPropertyWidget.h

@@ -0,0 +1,131 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 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.apache.org/licenses/LICENSE-2.0.txt
+
+  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 __ctkVTKPropertyWidget_h
+#define __ctkVTKPropertyWidget_h
+
+// Qt includes
+#include <QWidget>
+
+// CTK includes
+#include "ctkColorPickerButton.h"
+#include "ctkVTKObject.h"
+#include "ctkVisualizationVTKWidgetsExport.h"
+
+class ctkVTKPropertyWidgetPrivate;
+class vtkProperty;
+
+/// \ingroup Visualization_VTK_Widgets
+class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKPropertyWidget
+  : public QWidget
+{
+  Q_OBJECT;
+  QVTK_OBJECT;
+  typedef QWidget Superclass;
+
+  Q_FLAGS(GroupsState)
+
+  /// Show/Hide, expand/collapse groups in the widget.
+  /// Groups are visible by default and Color is the only expanded group.
+  /// \sa groupsState(), setGroupsState()
+  Q_PROPERTY(GroupsState groupsState READ groupsState WRITE setGroupsState )
+
+  /// This property controls the color dialog option of the Color and EdgeColor
+  /// color picker buttons.
+  /// Same default as ctkColorPickerbutton
+  Q_PROPERTY(ctkColorPickerButton::ColorDialogOptions colorDialogOptions READ colorDialogOptions WRITE setColorDialogOptions)
+
+public:
+  enum GroupState {
+    RepresentationVisible = 0x00001,
+    RepresentationCollapsed = 0x00002,
+    ColorVisible          = 0x00010,
+    ColorCollapsed        = 0x00020,
+    LightingVisible       = 0x00100,
+    LightingCollapsed     = 0x00200,
+    MaterialVisible       = 0x01000,
+    MaterialCollapsed     = 0x02000,
+    AllVisible            = RepresentationVisible | ColorVisible | LightingVisible | MaterialVisible,
+    AllCollapsed          = RepresentationCollapsed | ColorCollapsed | LightingCollapsed | MaterialCollapsed
+  };
+  Q_DECLARE_FLAGS(GroupsState, GroupState)
+
+  /// Construct a ctkVTKPropertyWidget with a default vtkProperty.
+  ctkVTKPropertyWidget(QWidget* parentWidget);
+
+  /// Construct a ctkVTKPropertyWidget with the given vtkProperty.
+  ctkVTKPropertyWidget(vtkProperty* property, QWidget* parentWidget);
+  virtual ~ctkVTKPropertyWidget();
+
+  vtkProperty* property()const;
+
+  /// \sa groupsState, setGroupsState()
+  ctkVTKPropertyWidget::GroupsState groupsState()const;
+  /// \sa groupsState, groupsState()
+  void setGroupsState(ctkVTKPropertyWidget::GroupsState state);
+
+  /// \sa colorDialogOptions, setColorDialogOptions()
+  ctkColorPickerButton::ColorDialogOptions colorDialogOptions()const;
+  /// \sa colorDialogOptions, colorDialogOptions()
+  void setColorDialogOptions(ctkColorPickerButton::ColorDialogOptions options);
+
+  virtual int representation()const;
+  virtual double pointSize()const;
+  virtual double lineWidth()const;
+  virtual bool frontfaceCulling()const;
+  virtual bool backfaceCulling()const;
+  virtual QColor color()const;
+  virtual double opacity()const;
+  virtual bool edgeVisibility()const;
+  virtual QColor edgeColor()const;
+  virtual bool lighting()const;
+  virtual int interpolation()const;
+  virtual bool shading()const;
+
+public Q_SLOTS:
+  virtual void setProperty(vtkProperty* property);
+
+  virtual void setRepresentation(int newRepresentation);
+  virtual void setPointSize(double newPointSize);
+  virtual void setLineWidth(double newLineWidth);
+  virtual void setFrontfaceCulling(bool newFrontfaceCulling);
+  virtual void setBackfaceCulling(bool newBackfaceCulling);
+  virtual void setColor(const QColor& newColor);
+  virtual void setOpacity(double newOpacity);
+  virtual void setEdgeVisibility(bool newEdgeVisibility);
+  virtual void setEdgeColor(const QColor& newColor);
+  virtual void setLighting(bool newLighting);
+  virtual void setInterpolation(int newInterpolation);
+  virtual void setShading(bool newShading);
+
+protected Q_SLOTS:
+  void updateWidgetFromProperty();
+
+protected:
+  QScopedPointer<ctkVTKPropertyWidgetPrivate> d_ptr;
+
+private:
+  Q_DECLARE_PRIVATE(ctkVTKPropertyWidget);
+  Q_DISABLE_COPY(ctkVTKPropertyWidget);
+};
+
+Q_DECLARE_OPERATORS_FOR_FLAGS(ctkVTKPropertyWidget::GroupsState)
+
+#endif