Browse Source

Add ctkVTKVolumePropertyWidget to control vtkVolumeProperty

Julien Finet 14 years ago
parent
commit
8a11d716d0

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

@@ -79,6 +79,8 @@ IF (${CTK_USE_CHARTS})
   SET(KIT_SRCS
       ctkVTKChartView.cpp
       ctkVTKChartView.h
+      ctkVTKVolumePropertyWidget.cpp
+      ctkVTKVolumePropertyWidget.h
       ctkVTKScalarsToColorsView.cpp
       ctkVTKScalarsToColorsView.h
       ctkVTKScalarsToColorsWidget.cpp
@@ -86,11 +88,13 @@ IF (${CTK_USE_CHARTS})
       ${KIT_SRCS})
   SET(KIT_MOC_SRCS 
       ctkVTKChartView.h
+      ctkVTKVolumePropertyWidget.h
       ctkVTKScalarsToColorsView.h
       ctkVTKScalarsToColorsWidget.h
       ${KIT_MOC_SRCS})
   SET(KIT_UI_FORMS
-      Resources/UI/ctkVTKScalarsToColorsWidget.ui 
+      Resources/UI/ctkVTKVolumePropertyWidget.ui
+      Resources/UI/ctkVTKScalarsToColorsWidget.ui
       ${KIT_UI_FORMS})
   SET(VTK_LIBRARIES
       vtkCharts

+ 152 - 0
Libs/Visualization/VTK/Widgets/Resources/UI/ctkVTKVolumePropertyWidget.ui

@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkVTKVolumePropertyWidget</class>
+ <widget class="QWidget" name="ctkVTKVolumePropertyWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>435</width>
+    <height>576</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Volume property</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_3">
+   <property name="margin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="ctkCollapsibleGroupBox" name="ScalarOpacityGroupBox">
+     <property name="title">
+      <string>Scalar Opacity Mapping</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_2">
+      <property name="margin">
+       <number>0</number>
+      </property>
+      <item>
+       <widget class="ctkVTKScalarsToColorsWidget" name="ScalarOpacityWidget">
+        <property name="minimumSize">
+         <size>
+          <width>0</width>
+          <height>120</height>
+         </size>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="ctkCollapsibleGroupBox" name="ScalarColorGroupBox">
+     <property name="title">
+      <string>Scalar Color Mapping</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_4">
+      <property name="margin">
+       <number>0</number>
+      </property>
+      <item>
+       <widget class="ctkVTKScalarsToColorsWidget" name="ScalarColorWidget">
+        <property name="minimumSize">
+         <size>
+          <width>0</width>
+          <height>120</height>
+         </size>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="ctkCollapsibleGroupBox" name="GradientGroupBox">
+     <property name="title">
+      <string>Gradient Opacity</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout">
+      <property name="margin">
+       <number>0</number>
+      </property>
+      <item>
+       <widget class="ctkVTKScalarsToColorsWidget" name="GradientWidget">
+        <property name="minimumSize">
+         <size>
+          <width>0</width>
+          <height>120</height>
+         </size>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="ctkCollapsibleGroupBox" name="AdvancedGroupBox">
+     <property name="title">
+      <string>Advanced</string>
+     </property>
+     <layout class="QFormLayout" name="formLayout">
+      <item row="0" column="0">
+       <widget class="QLabel" name="InterpolationLabel">
+        <property name="text">
+         <string>Interpolation:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QComboBox" name="InterpolationComboBox">
+        <item>
+         <property name="text">
+          <string>Nearest Neighbor</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>Linear</string>
+         </property>
+        </item>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="MaterialLabel">
+        <property name="text">
+         <string>Material:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="ctkMaterialPropertyPreviewLabel" name="MaterialPropertyLabel">
+        <property name="gridOpacity">
+         <double>0.000000000000000</double>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>ctkVTKScalarsToColorsWidget</class>
+   <extends>QWidget</extends>
+   <header>ctkVTKScalarsToColorsWidget.h</header>
+  </customwidget>
+  <customwidget>
+   <class>ctkCollapsibleGroupBox</class>
+   <extends>QGroupBox</extends>
+   <header>ctkCollapsibleGroupBox.h</header>
+   <container>1</container>
+  </customwidget>
+  <customwidget>
+   <class>ctkMaterialPropertyPreviewLabel</class>
+   <extends>QFrame</extends>
+   <header>ctkMaterialPropertyPreviewLabel.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>

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

@@ -24,6 +24,7 @@ SET(TEST_SOURCES
 IF(CTK_USE_CHARTS)
   SET(TEST_SOURCES
       ctkVTKChartViewTest1.cpp
+      ctkVTKVolumePropertyWidgetTest1.cpp
       ctkVTKScalarsToColorsViewTest1.cpp
       ctkVTKScalarsToColorsViewTest2.cpp
       ctkVTKScalarsToColorsViewTest3.cpp
@@ -80,6 +81,7 @@ SIMPLE_TEST( ctkTransferFunctionViewTest4 )
 SIMPLE_TEST( ctkTransferFunctionViewTest5 )
 IF (CTK_USE_CHARTS)
   SIMPLE_TEST( ctkVTKChartViewTest1 )
+  SIMPLE_TEST( ctkVTKVolumePropertyWidgetTest1 )
   SIMPLE_TEST( ctkVTKScalarsToColorsViewTest1 )
   SIMPLE_TEST( ctkVTKScalarsToColorsViewTest2 )
   SIMPLE_TEST( ctkVTKScalarsToColorsViewTest3 )

+ 2 - 3
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKScalarsToColorsViewTest1.cpp

@@ -51,11 +51,10 @@ int ctkVTKScalarsToColorsViewTest1(int argc, char * argv [] )
   view.show();
 
   ctf->AddRGBPoint(0.6, 0.9686,0.0,0.6941);
-  QTimer autoExit;
+
   if (argc < 2 || QString(argv[1]) != "-I")
     {
-    QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
-    autoExit.start(1000);
+    QTimer::singleShot(200, &app, SLOT(quit()));
     }
   return app.exec();
 }

+ 1 - 3
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKScalarsToColorsViewTest2.cpp

@@ -113,11 +113,9 @@ int ctkVTKScalarsToColorsViewTest2(int argc, char * argv [] )
   view.fitAxesToBounds();
   view.show();
 
-  QTimer autoExit;
   if (argc < 2 || QString(argv[1]) != "-I")
     {
-    QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
-    autoExit.start(1000);
+    QTimer::singleShot(200, &app, SLOT(quit()));
     }
   return app.exec();
 }

+ 1 - 3
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKScalarsToColorsViewTest3.cpp

@@ -66,11 +66,9 @@ int ctkVTKScalarsToColorsViewTest3(int argc, char * argv [] )
   view.fitAxesToBounds();
   view.show();
 
-  QTimer autoExit;
   if (argc < 2 || QString(argv[1]) != "-I")
     {
-    QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
-    autoExit.start(1000);
+    QTimer::singleShot(200, &app, SLOT(quit()));
     }
   return app.exec();
 }

+ 1 - 3
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKScalarsToColorsWidgetTest1.cpp

@@ -58,11 +58,9 @@ int ctkVTKScalarsToColorsWidgetTest1(int argc, char * argv [] )
   widget.view()->fitAxesToBounds();
   widget.show();
 
-  QTimer autoExit;
   if (argc < 2 || QString(argv[1]) != "-I")
     {
-    QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
-    autoExit.start(1000);
+    QTimer::singleShot(200, &app, SLOT(quit()));
     }
   return app.exec();
 }

+ 1 - 3
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKScalarsToColorsWidgetTest2.cpp

@@ -67,11 +67,9 @@ int ctkVTKScalarsToColorsWidgetTest2(int argc, char * argv [] )
   widget.view()->fitAxesToBounds();
   widget.show();
 
-  QTimer autoExit;
   if (argc < 2 || QString(argv[1]) != "-I")
     {
-    QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
-    autoExit.start(1000);
+    QTimer::singleShot(200, &app, SLOT(quit()));
     }
   return app.exec();
 }

+ 1 - 3
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKScalarsToColorsWidgetTest3.cpp

@@ -59,11 +59,9 @@ int ctkVTKScalarsToColorsWidgetTest3(int argc, char * argv [] )
   widget.view()->fitAxesToBounds();
   widget.show();
 
-  QTimer autoExit;
   if (argc < 2 || QString(argv[1]) != "-I")
     {
-    QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
-    autoExit.start(1000);
+    QTimer::singleShot(200, &app, SLOT(quit()));
     }
   return app.exec();
 }

+ 78 - 0
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKVolumePropertyWidgetTest1.cpp

@@ -0,0 +1,78 @@
+/*=========================================================================
+
+  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.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
+#include <QApplication>
+#include <QDebug>
+#include <QTimer>
+
+// CTK includes
+#include "ctkVTKVolumePropertyWidget.h"
+
+// VTK includes
+#include <vtkColorTransferFunction.h>
+#include <vtkPiecewiseFunction.h>
+#include <vtkSmartPointer.h>
+#include <vtkVolumeProperty.h>
+
+// STD includes
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkVTKVolumePropertyWidgetTest1(int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+
+  vtkSmartPointer<vtkColorTransferFunction> ctf =
+    vtkSmartPointer<vtkColorTransferFunction>::New();
+  ctf->AddRGBPoint(0.2, 0.6941,0.76,0., 0.5, 0.);
+  ctf->AddRGBPoint(0.4, 0.,0.6941,0.96);
+  ctf->AddRGBPoint(0.8, 0.9686,0.76,0.);
+
+  vtkSmartPointer<vtkPiecewiseFunction> otf =
+    vtkSmartPointer<vtkPiecewiseFunction>::New();
+  otf->AddPoint(0.2, 0.6941);
+  otf->AddPoint(0.4, 0.641);
+  otf->AddPoint(0.8, 0.9686);
+
+  vtkSmartPointer<vtkPiecewiseFunction> otf2 =
+    vtkSmartPointer<vtkPiecewiseFunction>::New();
+  otf2->AddPoint(0.0, 0.6941);
+  otf2->AddPoint(0.1, 0.641);
+  otf2->AddPoint(0.7, 0.9686);
+
+  vtkSmartPointer<vtkVolumeProperty> volumeProperty =
+    vtkSmartPointer<vtkVolumeProperty>::New();
+  volumeProperty->SetColor(ctf);
+  volumeProperty->SetScalarOpacity(otf);
+
+  ctkVTKVolumePropertyWidget widget;
+  widget.setVolumeProperty(volumeProperty);
+
+  volumeProperty->SetScalarOpacity(otf2);
+
+  widget.show();
+
+  if (argc < 2 || QString(argv[1]) != "-I")
+    {
+    QTimer::singleShot(200, &app, SLOT(quit()));
+    }
+  return app.exec();
+}

+ 269 - 14
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.cpp

@@ -124,36 +124,48 @@ vtkPlot* ctkVTKScalarsToColorsView::addLookupTable(vtkLookupTable* lut)
   return item;
 }
 // ----------------------------------------------------------------------------
-vtkPlot* ctkVTKScalarsToColorsView::addColorTransferFunction(vtkColorTransferFunction* colorTF)
+vtkPlot* ctkVTKScalarsToColorsView
+::addColorTransferFunction(vtkColorTransferFunction* colorTF,
+                           bool editable)
 {
   Q_D(ctkVTKScalarsToColorsView);
   vtkSmartPointer<vtkColorTransferFunctionItem> item =
     vtkSmartPointer<vtkColorTransferFunctionItem>::New();
   item->SetColorTransferFunction(colorTF);
   this->addPlot(item);
-  vtkSmartPointer<vtkColorTransferControlPointsItem> controlPointsItem =
-    vtkSmartPointer<vtkColorTransferControlPointsItem>::New();
-  controlPointsItem->SetColorTransferFunction(colorTF);
-  this->addPlot(controlPointsItem);
+  if (editable)
+    {
+    this->addColorTransferFunctionControlPoints(colorTF);
+    }
   d->updateChart();
   return item;
 }
 
 // ----------------------------------------------------------------------------
-vtkPlot* ctkVTKScalarsToColorsView::addOpacityFunction(vtkPiecewiseFunction* opacityTF)
+vtkPlot* ctkVTKScalarsToColorsView
+::addOpacityFunction(vtkPiecewiseFunction* opacityTF,
+                     bool editable)
+{
+  return this->addPiecewiseFunction(opacityTF, editable);
+}
+
+// ----------------------------------------------------------------------------
+vtkPlot* ctkVTKScalarsToColorsView
+::addPiecewiseFunction(vtkPiecewiseFunction* piecewiseTF,
+                       bool editable)
 {
   Q_D(ctkVTKScalarsToColorsView);
   vtkSmartPointer<vtkPiecewiseFunctionItem> item =
     vtkSmartPointer<vtkPiecewiseFunctionItem>::New();
-  item->SetPiecewiseFunction(opacityTF);
+  item->SetPiecewiseFunction(piecewiseTF);
   QColor defaultColor = this->palette().highlight().color();
   item->SetColor(defaultColor.redF(), defaultColor.greenF(), defaultColor.blueF());
   item->SetMaskAboveCurve(true);
   this->addPlot(item);
-  vtkSmartPointer<vtkPiecewiseControlPointsItem> controlPointsItem =
-    vtkSmartPointer<vtkPiecewiseControlPointsItem>::New();
-  controlPointsItem->SetPiecewiseFunction(opacityTF);
-  this->addPlot(controlPointsItem);
+  if (editable)
+    {
+    this->addPiecewiseFunctionControlPoints(piecewiseTF);
+    }
   d->updateChart();
   return item;
 }
@@ -161,7 +173,8 @@ vtkPlot* ctkVTKScalarsToColorsView::addOpacityFunction(vtkPiecewiseFunction* opa
 // ----------------------------------------------------------------------------
 vtkPlot* ctkVTKScalarsToColorsView
 ::addCompositeFunction(vtkColorTransferFunction* colorTF,
-                       vtkPiecewiseFunction* opacityTF)
+                       vtkPiecewiseFunction* opacityTF,
+                       bool colorTFEditable, bool opacityTFEditable)
 {
   Q_D(ctkVTKScalarsToColorsView);
   vtkSmartPointer<vtkCompositeTransferFunctionItem> item =
@@ -170,14 +183,256 @@ vtkPlot* ctkVTKScalarsToColorsView
   item->SetOpacityFunction(opacityTF);
   item->SetMaskAboveCurve(true);
   this->addPlot(item);
+  if (colorTFEditable && opacityTFEditable)
+    {
+    this->addCompositeFunctionControlPoints(colorTF, opacityTF);
+    }
+  else if (colorTFEditable)
+    {
+    this->addColorTransferFunctionControlPoints(colorTF);
+    }
+  else if (opacityTFEditable)
+    {
+    this->addOpacityFunctionControlPoints(opacityTF);
+    }
+  d->updateChart();
+  return item;
+}
+
+// ----------------------------------------------------------------------------
+vtkPlot* ctkVTKScalarsToColorsView
+::addColorTransferFunctionControlPoints(vtkColorTransferFunction* colorTF)
+{
+  vtkSmartPointer<vtkColorTransferControlPointsItem> controlPointsItem =
+    vtkSmartPointer<vtkColorTransferControlPointsItem>::New();
+  controlPointsItem->SetColorTransferFunction(colorTF);
+  this->addPlot(controlPointsItem);
+  return controlPointsItem;
+}
+
+// ----------------------------------------------------------------------------
+vtkPlot* ctkVTKScalarsToColorsView
+::addOpacityFunctionControlPoints(vtkPiecewiseFunction* opacityTF)
+{
+  return this->addPiecewiseFunctionControlPoints(opacityTF);
+}
+
+// ----------------------------------------------------------------------------
+vtkPlot* ctkVTKScalarsToColorsView
+::addCompositeFunctionControlPoints(vtkColorTransferFunction* colorTF,
+                                    vtkPiecewiseFunction* opacityTF)
+{
   vtkSmartPointer<vtkCompositeControlPointsItem> controlPointsItem =
     vtkSmartPointer<vtkCompositeControlPointsItem>::New();
   controlPointsItem->SetColorTransferFunction(colorTF);
   controlPointsItem->SetOpacityFunction(opacityTF);
   this->addPlot(controlPointsItem);
+  return controlPointsItem;
+}
 
-  d->updateChart();
-  return item;
+// ----------------------------------------------------------------------------
+vtkPlot* ctkVTKScalarsToColorsView
+::addPiecewiseFunctionControlPoints(vtkPiecewiseFunction* piecewiseTF)
+{
+  vtkSmartPointer<vtkPiecewiseControlPointsItem> controlPointsItem =
+    vtkSmartPointer<vtkPiecewiseControlPointsItem>::New();
+  controlPointsItem->SetPiecewiseFunction(piecewiseTF);
+  this->addPlot(controlPointsItem);
+  return controlPointsItem;
+}
+
+// ----------------------------------------------------------------------------
+QList<vtkPlot*> ctkVTKScalarsToColorsView::plots()const
+{
+  QList<vtkPlot*> res;
+  const vtkIdType count = this->chart()->GetNumberOfPlots();
+  for(vtkIdType i = 0; i < count; ++i)
+    {
+    res << this->chart()->GetPlot(i);
+    }
+  return res;
+}
+
+// ----------------------------------------------------------------------------
+QList<vtkPlot*> ctkVTKScalarsToColorsView::lookupTablePlots()const
+{
+  QList<vtkPlot*> res;
+  foreach(vtkPlot* plot, this->plots())
+    {
+    if (vtkLookupTableItem::SafeDownCast(plot))
+      {
+      res << plot;
+      }
+    }
+  return res;
+}
+
+// ----------------------------------------------------------------------------
+QList<vtkPlot*> ctkVTKScalarsToColorsView::lookupTablePlots(vtkLookupTable* lut)const
+{
+  QList<vtkPlot*> res;
+  foreach(vtkPlot* plot, this->lookupTablePlots())
+    {
+    vtkLookupTableItem* item = vtkLookupTableItem::SafeDownCast(plot);
+    if (item->GetLookupTable() == lut)
+      {
+      res << plot;
+      }
+    }
+  return res;
+}
+
+// ----------------------------------------------------------------------------
+QList<vtkPlot*> ctkVTKScalarsToColorsView::colorTransferFunctionPlots()const
+{
+  QList<vtkPlot*> res;
+  foreach(vtkPlot* plot, this->plots())
+    {
+    if (vtkColorTransferFunctionItem::SafeDownCast(plot) ||
+        vtkColorTransferControlPointsItem::SafeDownCast(plot))
+      {
+      res << plot;
+      }
+    }
+  return res;
+}
+
+// ----------------------------------------------------------------------------
+QList<vtkPlot*> ctkVTKScalarsToColorsView
+::colorTransferFunctionPlots(vtkColorTransferFunction* colorTF)const
+{
+  QList<vtkPlot*> res;
+  foreach(vtkPlot* plot, this->colorTransferFunctionPlots())
+    {
+    vtkColorTransferFunctionItem* item =
+      vtkColorTransferFunctionItem::SafeDownCast(plot);
+    if (item
+        && item->GetColorTransferFunction() == colorTF)
+      {
+      res << plot;
+      }
+    vtkColorTransferControlPointsItem* controlPointsItem =
+      vtkColorTransferControlPointsItem::SafeDownCast(plot);
+    if (controlPointsItem
+        && controlPointsItem->GetColorTransferFunction() == colorTF)
+      {
+      res << plot;
+      }
+    }
+  return res;
+}
+
+// ----------------------------------------------------------------------------
+QList<vtkPlot*> ctkVTKScalarsToColorsView::opacityFunctionPlots()const
+{
+  QList<vtkPlot*> res;
+  foreach(vtkPlot* plot, this->plots())
+    {
+    if (vtkPiecewiseFunctionItem::SafeDownCast(plot) ||
+        vtkPiecewiseControlPointsItem::SafeDownCast(plot))
+      {
+      res << plot;
+      }
+    }
+  return res;
+}
+
+// ----------------------------------------------------------------------------
+QList<vtkPlot*> ctkVTKScalarsToColorsView
+::opacityFunctionPlots(vtkPiecewiseFunction* opacityTF)const
+{
+  QList<vtkPlot*> res;
+  foreach(vtkPlot* plot, this->opacityFunctionPlots())
+    {
+    vtkPiecewiseFunctionItem* item =
+      vtkPiecewiseFunctionItem::SafeDownCast(plot);
+    if (item
+        && item->GetPiecewiseFunction() == opacityTF)
+      {
+      res << plot;
+      }
+    vtkPiecewiseControlPointsItem* controlPointsItem =
+      vtkPiecewiseControlPointsItem::SafeDownCast(plot);
+    if (controlPointsItem
+        && controlPointsItem->GetPiecewiseFunction() == opacityTF)
+      {
+      res << plot;
+      }
+    vtkCompositeTransferFunctionItem* compositeItem =
+      vtkCompositeTransferFunctionItem::SafeDownCast(plot);
+    if (compositeItem
+        && compositeItem->GetOpacityFunction() == opacityTF)
+      {
+      res << plot;
+      }
+    vtkCompositeControlPointsItem* compositeControlPointsItem =
+      vtkCompositeControlPointsItem::SafeDownCast(plot);
+    if (compositeControlPointsItem
+        && compositeControlPointsItem->GetOpacityFunction() == opacityTF)
+      {
+      res << plot;
+      }
+    }
+  return res;
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKScalarsToColorsView::setLookuptTableToPlots(vtkLookupTable* lut)
+{
+  foreach(vtkLookupTableItem* plot,
+          this->plots<vtkLookupTableItem>())
+    {
+    plot->SetLookupTable(lut);
+    }
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKScalarsToColorsView
+::setColorTransferFunctionToPlots(vtkColorTransferFunction* colorTF)
+{
+  foreach(vtkColorTransferFunctionItem* plot,
+          this->plots<vtkColorTransferFunctionItem>())
+    {
+    plot->SetColorTransferFunction(colorTF);
+    }
+  foreach(vtkColorTransferControlPointsItem* plot,
+          this->plots<vtkColorTransferControlPointsItem>())
+    {
+    plot->SetColorTransferFunction(colorTF);
+    }
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKScalarsToColorsView
+::setOpacityFunctionToPlots(vtkPiecewiseFunction* opacityTF)
+{
+  this->setPiecewiseFunctionToPlots(opacityTF);
+  foreach(vtkCompositeTransferFunctionItem* plot,
+          this->plots<vtkCompositeTransferFunctionItem>())
+    {
+    plot->SetOpacityFunction(opacityTF);
+    }
+  foreach(vtkCompositeControlPointsItem* plot,
+          this->plots<vtkCompositeControlPointsItem>())
+    {
+    plot->SetOpacityFunction(opacityTF);
+    }
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKScalarsToColorsView
+::setPiecewiseFunctionToPlots(vtkPiecewiseFunction* piecewiseTF)
+{
+  foreach(vtkPiecewiseFunctionItem* plot,
+          this->plots<vtkPiecewiseFunctionItem>())
+    {
+    plot->SetPiecewiseFunction(piecewiseTF);
+    }
+  foreach(vtkPiecewiseControlPointsItem* plot,
+          this->plots<vtkPiecewiseControlPointsItem>())
+    {
+    plot->SetPiecewiseFunction(piecewiseTF);
+    }
 }
 
 // ----------------------------------------------------------------------------

+ 46 - 3
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.h

@@ -28,6 +28,7 @@ class ctkVTKScalarsToColorsViewPrivate;
 
 // VTK includes
 #include <QVTKWidget.h>
+#include <vtkChartXY.h>
 
 class vtkColorTransferFunction;
 class vtkLookupTable;
@@ -45,10 +46,34 @@ public:
 
   virtual void addPlot(vtkPlot* plot);
   vtkPlot* addLookupTable(vtkLookupTable* lut);
-  vtkPlot* addColorTransferFunction(vtkColorTransferFunction* colorTF);
-  vtkPlot* addOpacityFunction(vtkPiecewiseFunction* opacityTF);
+  vtkPlot* addColorTransferFunction(vtkColorTransferFunction* colorTF, bool editable = true);
+  vtkPlot* addOpacityFunction(vtkPiecewiseFunction* opacityTF, bool editable = true);
   vtkPlot* addCompositeFunction(vtkColorTransferFunction* colorTF,
-                                vtkPiecewiseFunction* opacityTF);
+                                vtkPiecewiseFunction* opacityTF,
+                                bool colorTFEditable = true,
+                                bool opacityTFEditable = true);
+  vtkPlot* addPiecewiseFunction(vtkPiecewiseFunction* piecewiseTF, bool editable = true);
+
+  vtkPlot* addColorTransferFunctionControlPoints(vtkColorTransferFunction* colorTF);
+  vtkPlot* addOpacityFunctionControlPoints(vtkPiecewiseFunction* opacityTF);
+  vtkPlot* addCompositeFunctionControlPoints(vtkColorTransferFunction* colorTF,
+                                             vtkPiecewiseFunction* opacityTF);
+  vtkPlot* addPiecewiseFunctionControlPoints(vtkPiecewiseFunction* piecewiseTF);
+
+  QList<vtkPlot*> plots()const;
+  template<class T>
+  QList<T*> plots()const;
+  QList<vtkPlot*> lookupTablePlots()const;
+  QList<vtkPlot*> lookupTablePlots(vtkLookupTable* lut)const;
+  QList<vtkPlot*> colorTransferFunctionPlots()const;
+  QList<vtkPlot*> colorTransferFunctionPlots(vtkColorTransferFunction* colorTF)const;
+  QList<vtkPlot*> opacityFunctionPlots()const;
+  QList<vtkPlot*> opacityFunctionPlots(vtkPiecewiseFunction* opacityTF)const;
+
+  void setLookuptTableToPlots(vtkLookupTable* lut);
+  void setColorTransferFunctionToPlots(vtkColorTransferFunction* colorTF);
+  void setOpacityFunctionToPlots(vtkPiecewiseFunction* opacityTF);
+  void setPiecewiseFunctionToPlots(vtkPiecewiseFunction* piecewiseTF);
 
 public slots:
   void editPoint(vtkObject* plot, void * pointId);
@@ -61,4 +86,22 @@ private:
   Q_DISABLE_COPY(ctkVTKScalarsToColorsView);
 };
 
+// ----------------------------------------------------------------------------
+template<class T>
+QList<T*> ctkVTKScalarsToColorsView::plots()const
+{
+  QList<T*> res;
+  const vtkIdType count = this->chart()->GetNumberOfPlots();
+  for(vtkIdType i = 0; i < count; ++i)
+    {
+    vtkPlot* plot = this->chart()->GetPlot(i);
+    if (T::SafeDownCast(plot) != 0)
+      {
+      res << T::SafeDownCast(plot);
+      }
+    }
+  return res;
+}
+
+
 #endif

+ 156 - 0
Libs/Visualization/VTK/Widgets/ctkVTKVolumePropertyWidget.cpp

@@ -0,0 +1,156 @@
+/*=========================================================================
+
+  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.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
+#include <QDebug>
+
+// CTK includes
+#include "ctkLogger.h"
+#include "ctkVTKScalarsToColorsView.h"
+#include "ctkVTKVolumePropertyWidget.h"
+#include "ui_ctkVTKVolumePropertyWidget.h"
+
+// VTK includes
+#include <vtkColorTransferControlPointsItem.h>
+#include <vtkColorTransferFunction.h>
+#include <vtkColorTransferFunctionItem.h>
+#include <vtkCompositeControlPointsItem.h>
+#include <vtkCompositeTransferFunctionItem.h>
+#include <vtkContextScene.h>
+#include <vtkLookupTable.h>
+#include <vtkLookupTableItem.h>
+#include <vtkPiecewiseControlPointsItem.h>
+#include <vtkPiecewiseFunction.h>
+#include <vtkPiecewiseFunctionItem.h>
+#include <vtkVolumeProperty.h>
+
+//----------------------------------------------------------------------------
+static ctkLogger logger("org.commontk.visualization.vtk.widgets.ctkVTKVolumePropertyWidget");
+//----------------------------------------------------------------------------
+
+class ctkVTKVolumePropertyWidgetPrivate:
+  public Ui_ctkVTKVolumePropertyWidget
+{
+   Q_DECLARE_PUBLIC(ctkVTKVolumePropertyWidget);
+protected:
+  ctkVTKVolumePropertyWidget* const q_ptr;
+public:
+  ctkVTKVolumePropertyWidgetPrivate(ctkVTKVolumePropertyWidget& object);
+  void setupUi(QWidget* widget);
+
+  vtkVolumeProperty* VolumeProperty;
+};
+
+// ----------------------------------------------------------------------------
+// ctkVTKVolumePropertyWidgetPrivate methods
+
+// ----------------------------------------------------------------------------
+ctkVTKVolumePropertyWidgetPrivate::ctkVTKVolumePropertyWidgetPrivate(
+  ctkVTKVolumePropertyWidget& object)
+  : q_ptr(&object)
+{
+  this->VolumeProperty = 0;
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidgetPrivate::setupUi(QWidget* widget)
+{
+  //Q_Q(ctkVTKVolumePropertyWidget);
+  this->Ui_ctkVTKVolumePropertyWidget::setupUi(widget);
+
+  this->ScalarOpacityWidget->view()->addCompositeFunction(0, 0, false, true);
+  this->ScalarColorWidget->view()->addColorTransferFunction(0);
+  this->GradientWidget->view()->addPiecewiseFunction(0);
+
+  this->GradientGroupBox->setCollapsed(true);
+  this->AdvancedGroupBox->setCollapsed(true);
+}
+
+// ----------------------------------------------------------------------------
+// ctkVTKVolumePropertyWidget methods
+
+// ----------------------------------------------------------------------------
+ctkVTKVolumePropertyWidget::ctkVTKVolumePropertyWidget(QWidget* parentWidget)
+  :QWidget(parentWidget)
+   , d_ptr(new ctkVTKVolumePropertyWidgetPrivate(*this))
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  d->setupUi(this);
+}
+
+// ----------------------------------------------------------------------------
+ctkVTKVolumePropertyWidget::~ctkVTKVolumePropertyWidget()
+{
+}
+
+// ----------------------------------------------------------------------------
+vtkVolumeProperty* ctkVTKVolumePropertyWidget::volumeProperty()const
+{
+  Q_D(const ctkVTKVolumePropertyWidget);
+  return d->VolumeProperty;
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget
+::setVolumeProperty(vtkVolumeProperty* newVolumeProperty)
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  this->qvtkReconnect(d->VolumeProperty, newVolumeProperty, vtkCommand::ModifiedEvent,
+                      this, SLOT(updateFromVolumeProperty()));
+  d->VolumeProperty = newVolumeProperty;
+  this->updateFromVolumeProperty();
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::updateFromVolumeProperty()
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  vtkColorTransferFunction* colorTransferFunction = 0;
+  vtkPiecewiseFunction* opacityFunction = 0;
+  vtkPiecewiseFunction* gradientFunction = 0;
+  if (d->VolumeProperty)
+    {
+    colorTransferFunction =
+      d->VolumeProperty->GetRGBTransferFunction()->GetSize() ?
+      d->VolumeProperty->GetRGBTransferFunction() : 0;
+    opacityFunction =
+      d->VolumeProperty->GetScalarOpacity()->GetSize() ?
+      d->VolumeProperty->GetScalarOpacity() : 0;
+    gradientFunction =
+      d->VolumeProperty->GetGradientOpacity()->GetSize() ?
+      d->VolumeProperty->GetGradientOpacity() : 0;
+    }
+
+  d->ScalarOpacityWidget->view()->setOpacityFunctionToPlots(opacityFunction);
+  d->ScalarOpacityWidget->view()->setColorTransferFunctionToPlots(colorTransferFunction);
+  d->ScalarColorWidget->view()->setColorTransferFunctionToPlots(colorTransferFunction);
+  d->GradientWidget->view()->setPiecewiseFunctionToPlots(gradientFunction);
+
+  if (d->VolumeProperty)
+    {
+    d->MaterialPropertyLabel->setAmbient(d->VolumeProperty->GetAmbient());
+    d->MaterialPropertyLabel->setDiffuse(d->VolumeProperty->GetDiffuse());
+    d->MaterialPropertyLabel->setSpecular(d->VolumeProperty->GetSpecular());
+    d->MaterialPropertyLabel->setSpecularPower(d->VolumeProperty->GetSpecularPower());
+    d->InterpolationComboBox->setCurrentIndex(
+      d->VolumeProperty->GetInterpolationType() == VTK_NEAREST_INTERPOLATION ? 0 : 1);
+    }
+}
+

+ 60 - 0
Libs/Visualization/VTK/Widgets/ctkVTKVolumePropertyWidget.h

@@ -0,0 +1,60 @@
+/*=========================================================================
+
+  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.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 __ctkVTKVolumePropertyWidget_h
+#define __ctkVTKVolumePropertyWidget_h
+
+//Qt includes
+#include <QWidget>
+
+// CTK includes
+#include <ctkVTKObject.h>
+#include "ctkVisualizationVTKWidgetsExport.h"
+class ctkVTKVolumePropertyWidgetPrivate;
+
+// VTK includes
+class vtkVolumeProperty;
+
+class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKVolumePropertyWidget
+  : public QWidget
+{
+  Q_OBJECT
+  QVTK_OBJECT
+
+public:
+  ctkVTKVolumePropertyWidget(QWidget* parent = 0);
+  virtual ~ctkVTKVolumePropertyWidget();
+
+  vtkVolumeProperty* volumeProperty()const;
+
+public slots:
+  void setVolumeProperty(vtkVolumeProperty* volumeProperty);
+
+protected slots:
+  void updateFromVolumeProperty();
+protected:
+  QScopedPointer<ctkVTKVolumePropertyWidgetPrivate> d_ptr;
+
+private:
+  Q_DECLARE_PRIVATE(ctkVTKVolumePropertyWidget);
+  Q_DISABLE_COPY(ctkVTKVolumePropertyWidget);
+};
+
+#endif