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

ctkVTKVolumePropertyWidget now controls shading properties

Julien Finet лет назад: 14
Родитель
Сommit
44daf3a54c

+ 25 - 9
Libs/Visualization/VTK/Widgets/Resources/UI/ctkVTKVolumePropertyWidget.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>435</width>
-    <height>576</height>
+    <width>391</width>
+    <height>699</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -111,16 +111,32 @@
        </widget>
       </item>
       <item row="1" column="0">
+       <widget class="QLabel" name="ShadeLabel">
+        <property name="text">
+         <string>Shade:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="QCheckBox" name="ShadeCheckBox"/>
+      </item>
+      <item row="2" 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>
+      <item row="2" column="1">
+       <widget class="ctkMaterialPropertyWidget" 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>
@@ -142,9 +158,9 @@
    <container>1</container>
   </customwidget>
   <customwidget>
-   <class>ctkMaterialPropertyPreviewLabel</class>
-   <extends>QFrame</extends>
-   <header>ctkMaterialPropertyPreviewLabel.h</header>
+   <class>ctkMaterialPropertyWidget</class>
+   <extends>QWidget</extends>
+   <header>ctkMaterialPropertyWidget.h</header>
   </customwidget>
  </customwidgets>
  <resources/>

+ 94 - 5
Libs/Visualization/VTK/Widgets/ctkVTKVolumePropertyWidget.cpp

@@ -56,6 +56,7 @@ public:
   void setupUi(QWidget* widget);
 
   vtkVolumeProperty* VolumeProperty;
+  int                CurrentComponent;
 };
 
 // ----------------------------------------------------------------------------
@@ -67,12 +68,14 @@ ctkVTKVolumePropertyWidgetPrivate::ctkVTKVolumePropertyWidgetPrivate(
   : q_ptr(&object)
 {
   this->VolumeProperty = 0;
+  this->CurrentComponent = 0;
 }
 
 // ----------------------------------------------------------------------------
 void ctkVTKVolumePropertyWidgetPrivate::setupUi(QWidget* widget)
 {
-  //Q_Q(ctkVTKVolumePropertyWidget);
+  Q_Q(ctkVTKVolumePropertyWidget);
+  Q_ASSERT(q == widget);
   this->Ui_ctkVTKVolumePropertyWidget::setupUi(widget);
 
   this->ScalarOpacityWidget->view()->addCompositeFunction(0, 0, false, true);
@@ -81,6 +84,19 @@ void ctkVTKVolumePropertyWidgetPrivate::setupUi(QWidget* widget)
 
   this->GradientGroupBox->setCollapsed(true);
   this->AdvancedGroupBox->setCollapsed(true);
+  
+  QObject::connect(this->InterpolationComboBox, SIGNAL(currentIndexChanged(int)),
+                   q, SLOT(setInterpolationMode(int)));
+  QObject::connect(this->ShadeCheckBox, SIGNAL(toggled(bool)),
+                   q, SLOT(setShade(bool)));
+  QObject::connect(this->MaterialPropertyWidget, SIGNAL(ambientChanged(double)),
+                   q, SLOT(setAmbient(double)));
+  QObject::connect(this->MaterialPropertyWidget, SIGNAL(diffuseChanged(double)),
+                   q, SLOT(setDiffuse(double)));
+  QObject::connect(this->MaterialPropertyWidget, SIGNAL(specularChanged(double)),
+                   q, SLOT(setSpecular(double)));
+  QObject::connect(this->MaterialPropertyWidget, SIGNAL(specularPowerChanged(double)),
+                   q, SLOT(setSpecularPower(double)));
 }
 
 // ----------------------------------------------------------------------------
@@ -145,12 +161,85 @@ void ctkVTKVolumePropertyWidget::updateFromVolumeProperty()
 
   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);
+    d->ShadeCheckBox->setChecked(
+      d->VolumeProperty->GetShade(d->CurrentComponent));
+    d->MaterialPropertyWidget->setAmbient(
+      d->VolumeProperty->GetAmbient(d->CurrentComponent));
+    d->MaterialPropertyWidget->setDiffuse(
+      d->VolumeProperty->GetDiffuse(d->CurrentComponent));
+    d->MaterialPropertyWidget->setSpecular(
+      d->VolumeProperty->GetSpecular(d->CurrentComponent));
+    d->MaterialPropertyWidget->setSpecularPower(
+      d->VolumeProperty->GetSpecularPower(d->CurrentComponent));
     }
 }
 
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::setInterpolationMode(int mode)
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  if (!d->VolumeProperty)
+    {
+    return;
+    }
+  d->VolumeProperty->SetInterpolationType(mode);
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::setShade(bool enable)
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  if (!d->VolumeProperty)
+    {
+    return;
+    }
+  d->VolumeProperty->SetShade(d->CurrentComponent, enable);
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::setAmbient(double value)
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  if (!d->VolumeProperty)
+    {
+    return;
+    }
+  d->VolumeProperty->SetAmbient(d->CurrentComponent, value);
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::setDiffuse(double value)
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  if (!d->VolumeProperty)
+    {
+    return;
+    }
+  d->VolumeProperty->SetDiffuse(d->CurrentComponent, value);
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::setSpecular(double value)
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  if (!d->VolumeProperty)
+    {
+    return;
+    }
+  d->VolumeProperty->SetSpecular(d->CurrentComponent, value);
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::setSpecularPower(double value)
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  if (!d->VolumeProperty)
+    {
+    return;
+    }
+  d->VolumeProperty->SetSpecularPower(d->CurrentComponent, value);
+}
+
+

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

@@ -49,6 +49,14 @@ public slots:
 
 protected slots:
   void updateFromVolumeProperty();
+
+  void setInterpolationMode(int mode);
+  void setShade(bool);
+  void setAmbient(double value);
+  void setDiffuse(double value);
+  void setSpecular(double value);
+  void setSpecularPower(double value);
+
 protected:
   QScopedPointer<ctkVTKVolumePropertyWidgetPrivate> d_ptr;