소스 검색

Add test to ctkVTKScalarsToColorsWidget

Test color transfer function
Julien Finet 14 년 전
부모
커밋
63c022ab0a

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

@@ -30,6 +30,7 @@ IF(CTK_USE_CHARTS)
       ctkVTKScalarsToColorsViewTest4.cpp
       ctkVTKScalarsToColorsWidgetTest1.cpp
       ctkVTKScalarsToColorsWidgetTest2.cpp
+      ctkVTKScalarsToColorsWidgetTest3.cpp
       ${TEST_SOURCES})
 ENDIF(CTK_USE_CHARTS)
 
@@ -85,6 +86,7 @@ IF (CTK_USE_CHARTS)
   SIMPLE_TEST( ctkVTKScalarsToColorsViewTest4 )
   SIMPLE_TEST( ctkVTKScalarsToColorsWidgetTest1 )
   SIMPLE_TEST( ctkVTKScalarsToColorsWidgetTest2 )
+  SIMPLE_TEST( ctkVTKScalarsToColorsWidgetTest3 )
 ENDIF(CTK_USE_CHARTS)
 SIMPLE_TEST( ctkVTKRenderViewTest1 )
 SIMPLE_TEST( ctkVTKSliceViewTest1 )

+ 69 - 0
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKScalarsToColorsWidgetTest3.cpp

@@ -0,0 +1,69 @@
+/*=========================================================================
+
+  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 <QSharedPointer>
+#include <QTimer>
+
+// CTK includes
+#include "ctkVTKScalarsToColorsView.h"
+#include "ctkVTKScalarsToColorsWidget.h"
+
+// VTK includes
+#include <vtkChartXY.h>
+#include <vtkColorTransferFunction.h>
+#include <vtkPiecewiseFunction.h>
+#include <vtkPlot.h>
+#include <vtkSmartPointer.h>
+
+// STD includes
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkVTKScalarsToColorsWidgetTest3(int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+
+  // Transfer Function
+  vtkSmartPointer<vtkColorTransferFunction> ctf =
+    vtkSmartPointer<vtkColorTransferFunction>::New();
+  //
+  ctf->AddRGBPoint(0. , 69./255., 199./255.,   186./255.);
+  ctf->AddRGBPoint(0.2,  172./255., 3./255., 57./255.);
+  ctf->AddRGBPoint(0.4,  169./255., 83./255., 58./255.);
+  ctf->AddRGBPoint(0.6,  43./255., 32./255.,  161./255.);
+  ctf->AddRGBPoint(0.8,  247./255., 158./255., 97./255.);
+  ctf->AddRGBPoint(1.,  183./255., 7./255., 140./255.);
+
+  ctkVTKScalarsToColorsWidget widget(0);
+  // add transfer function item
+  widget.view()->addColorTransferFunction(ctf);
+  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);
+    }
+  return app.exec();
+}

+ 2 - 1
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.cpp

@@ -128,10 +128,11 @@ vtkPlot* ctkVTKScalarsToColorsView::addColorTransferFunction(vtkColorTransferFun
   vtkSmartPointer<vtkColorTransferFunctionItem> item =
     vtkSmartPointer<vtkColorTransferFunctionItem>::New();
   item->SetColorTransferFunction(colorTF);
+  this->addPlot(item);
   vtkSmartPointer<vtkColorTransferControlPointsItem> controlPointsItem =
     vtkSmartPointer<vtkColorTransferControlPointsItem>::New();
   controlPointsItem->SetColorTransferFunction(colorTF);
-  this->addPlot(item);
+  this->addPlot(controlPointsItem);
   d->updateChart();
   return item;
 }

+ 5 - 2
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsWidget.cpp

@@ -226,6 +226,10 @@ void ctkVTKScalarsToColorsWidget::updateCurrentPoint()
 {
   Q_D(ctkVTKScalarsToColorsWidget);
   Q_ASSERT(d->CurrentControlPointsItem);
+  Q_ASSERT(d->PointIdSpinBox->value() == d->CurrentControlPointsItem->GetCurrentPoint());
+  d->PointIdSpinBox->setMaximum((d->CurrentControlPointsItem ?
+                                 d->CurrentControlPointsItem->GetNumberOfPoints() : 0) - 1);
+
   int pointId = d->PointIdSpinBox->value();
   if (pointId == -1)
     {
@@ -274,8 +278,7 @@ void ctkVTKScalarsToColorsWidget::onColorChanged(const QColor& color)
     point[1] = color.redF();
     point[2] = color.greenF();
     point[3] = color.blueF();
-    d->CurrentControlPointsItem->SetControlPoint(
-      d->PointIdSpinBox->value(), point);
+    colorTF->SetNodeValue(d->PointIdSpinBox->value(), point);
     }
 }