瀏覽代碼

Add ctkVTKScalarsToColorsView::moveAllPoints

and ctkVTKScalarsToColorsView::spreadAllPoints
Julien Finet 13 年之前
父節點
當前提交
cb9915cd0d

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

@@ -71,6 +71,9 @@ int ctkVTKVolumePropertyWidgetTest1(int argc, char * argv [] )
 
   volumeProperty->SetScalarOpacity(otf2);
 
+  widget.moveAllPoints(0.1, -0.1);
+  widget.moveAllPoints(-0.1, 0.1);
+
   widget.show();
 
   if (argc < 2 || QString(argv[1]) != "-I")

+ 2 - 2
Libs/Visualization/VTK/Widgets/ctkVTKChartView.cpp

@@ -168,7 +168,7 @@ void ctkVTKChartViewPrivate::chartBounds(double* bounds)const
 
 // ----------------------------------------------------------------------------
 ctkVTKChartView::ctkVTKChartView(QWidget* parentWidget)
-  :QVTKWidget(parentWidget)
+  :Superclass(parentWidget)
   , d_ptr(new ctkVTKChartViewPrivate(*this))
 {
   Q_D(ctkVTKChartView);
@@ -324,5 +324,5 @@ void ctkVTKChartView::mouseDoubleClickEvent(QMouseEvent* event)
     {
     this->setAxesToChartBounds();
     }
-  this->QVTKWidget::mouseDoubleClickEvent(event);
+  this->Superclass::mouseDoubleClickEvent(event);
 }

+ 1 - 0
Libs/Visualization/VTK/Widgets/ctkVTKChartView.h

@@ -39,6 +39,7 @@ class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKChartView : public QVTKWidget
   Q_PROPERTY(QString title READ title WRITE setTitle)
 
 public:
+  typedef QVTKWidget Superclass;
   ctkVTKChartView(QWidget* parent = 0);
   virtual ~ctkVTKChartView();
 

+ 42 - 0
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.cpp

@@ -33,12 +33,14 @@
 #include <vtkColorTransferFunctionItem.h>
 #include <vtkCompositeControlPointsItem.h>
 #include <vtkCompositeTransferFunctionItem.h>
+#include <vtkIdTypeArray.h>
 #include <vtkLookupTable.h>
 #include <vtkLookupTableItem.h>
 #include <vtkPen.h>
 #include <vtkPiecewiseControlPointsItem.h>
 #include <vtkPiecewiseFunction.h>
 #include <vtkPiecewiseFunctionItem.h>
+#include <vtkSmartPointer.h>
 
 //----------------------------------------------------------------------------
 static ctkLogger logger("org.commontk.visualization.vtk.widgets.ctkVTKScalarsToColorsView");
@@ -271,6 +273,23 @@ QList<vtkPlot*> ctkVTKScalarsToColorsView::plots()const
 }
 
 // ----------------------------------------------------------------------------
+QList<vtkControlPointsItem*> ctkVTKScalarsToColorsView
+::controlPointsItems()const
+{
+  QList<vtkControlPointsItem*> res;
+  foreach(vtkPlot* plot, this->plots())
+    {
+    vtkControlPointsItem* controlPointsItem =
+      vtkControlPointsItem::SafeDownCast(plot);
+    if (controlPointsItem)
+      {
+      res << controlPointsItem;
+      }
+    }
+  return res;
+}
+
+// ----------------------------------------------------------------------------
 QList<vtkPlot*> ctkVTKScalarsToColorsView::lookupTablePlots()const
 {
   QList<vtkPlot*> res;
@@ -537,3 +556,26 @@ void ctkVTKScalarsToColorsView::boundAxesToChartBounds()
     this->setPlotsUserBounds(userBounds);
     }
 }
+
+// ----------------------------------------------------------------------------
+void ctkVTKScalarsToColorsView::moveAllPoints(double xOffset, double yOffset)
+{
+  vtkVector2f offset(xOffset, yOffset);
+  foreach(vtkControlPointsItem* controlPointsItem, this->controlPointsItems())
+    {
+    vtkSmartPointer<vtkIdTypeArray> ids;
+    ids.TakeReference(controlPointsItem->GetControlPointsIds());
+    controlPointsItem->MovePoints(offset, ids.GetPointer());
+    }
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKScalarsToColorsView::spreadAllPoints(double factor)
+{
+  foreach(vtkControlPointsItem* controlPointsItem, this->controlPointsItems())
+    {
+    vtkSmartPointer<vtkIdTypeArray> ids;
+    ids.TakeReference(controlPointsItem->GetControlPointsIds());\
+    controlPointsItem->SpreadPoints(factor, ids.GetPointer());
+    }
+}

+ 13 - 0
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.h

@@ -31,6 +31,7 @@ class ctkVTKScalarsToColorsViewPrivate;
 #include <vtkChartXY.h>
 
 class vtkColorTransferFunction;
+class vtkControlPointsItem;
 class vtkLookupTable;
 class vtkPiecewiseFunction;
 
@@ -67,6 +68,7 @@ public:
   QList<vtkPlot*> plots()const;
   template<class T>
   QList<T*> plots()const;
+  QList<vtkControlPointsItem*> controlPointsItems()const;
   QList<vtkPlot*> lookupTablePlots()const;
   QList<vtkPlot*> lookupTablePlots(vtkLookupTable* lut)const;
   QList<vtkPlot*> colorTransferFunctionPlots()const;
@@ -86,9 +88,20 @@ public:
 
   /// Reimplemented to set the bounds to the plots as well
   virtual void boundAxesToChartBounds();
+
 public slots:
   void editPoint(vtkObject* plot, void * pointId);
 
+  /// Move all the control points by a given offset.
+  /// \sa vtkControlPoints::movePoints()
+  void moveAllPoints(double xOffset, double yOffset = 0.);
+
+  /// Spread all the control points by a given offset.
+  /// A value >0 will space the control points, a value <0. will contract
+  /// them.
+  /// \sa vtkControlPoints::spreadPoints()
+  void spreadAllPoints(double factor = 1.);
+
 protected slots:
   void onBoundsChanged();
 

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

@@ -357,3 +357,21 @@ void ctkVTKVolumePropertyWidget::onAxesModified()
     d->GradientWidget->blockSignals(wasBlocking);
     }
 }
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::moveAllPoints(double xOffset, double yOffset)
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  d->ScalarOpacityWidget->view()->moveAllPoints(xOffset, yOffset);
+  d->ScalarColorWidget->view()->moveAllPoints(xOffset, yOffset);
+  d->GradientWidget->view()->moveAllPoints(xOffset, yOffset);
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::spreadAllPoints(double factor)
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  d->ScalarOpacityWidget->view()->spreadAllPoints(factor);
+  d->ScalarColorWidget->view()->spreadAllPoints(factor);
+  d->GradientWidget->view()->spreadAllPoints(factor);
+}

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

@@ -54,6 +54,18 @@ public:
 public slots:
   void setVolumeProperty(vtkVolumeProperty* volumeProperty);
 
+  /// Move all the control points of the opacity, colors and gradient
+  /// of a give offset.
+  /// \sa vtkControlPoints::movePoints()
+  void moveAllPoints(double xOffset, double yOffset = 0.);
+
+  /// Spread all the control points of the opacity, colors and gradient
+  /// by a given offset.
+  /// A value >0 will space the control points, a value <0. will contract
+  /// them.
+  /// \sa vtkControlPoints::spreadPoints()
+  void spreadAllPoints(double factor = 1.);
+
 protected slots:
   void updateFromVolumeProperty();