Browse Source

ENH: Add ctkVTKChartView and ctkVTKScalarsToColorsView

The Qt views directly interface with the VTK Charts. It makes the
ctkTransferFunction* obsolete.
Julien Finet 15 years ago
parent
commit
e5d7e59591

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

@@ -25,6 +25,8 @@ SET(KIT_SRCS
   ctkVTKAbstractMatrixWidget.cpp
   ctkVTKAbstractMatrixWidget.h
   ctkVTKAbstractMatrixWidget_p.h
+  ctkVTKChartView.cpp
+  ctkVTKChartView.h
   ctkVTKMatrixWidget.cpp
   ctkVTKMatrixWidget.h
   ctkVTKRenderView.cpp
@@ -32,6 +34,8 @@ SET(KIT_SRCS
   ctkVTKRenderView_p.h
   ctkVTKScalarBarWidget.cpp
   ctkVTKScalarBarWidget.h
+  ctkVTKScalarsToColorsView.cpp
+  ctkVTKScalarsToColorsView.h
   ctkVTKSliceView.cpp
   ctkVTKSliceView.h
   ctkVTKSliceView_p.h
@@ -42,10 +46,12 @@ SET(KIT_SRCS
 # Headers that should run through moc
 SET(KIT_MOC_SRCS
   ctkVTKAbstractMatrixWidget_p.h
+  ctkVTKChartView.h
   ctkVTKMatrixWidget.h
   ctkVTKRenderView.h
   ctkVTKRenderView_p.h
   ctkVTKScalarBarWidget.h
+  ctkVTKScalarsToColorsView.h
   ctkVTKSliceView.h
   ctkVTKSliceView_p.h
   ctkVTKTextPropertyWidget.h
@@ -65,8 +71,9 @@ SET(KIT_resources
 # Set VTK_LIBRARIES variable
 SET(VTK_LIBRARIES
   QVTK
+  vtkCharts
   )
-  
+
 # Target libraries - See CMake/ctkMacroGetTargetLibraries.cmake
 # The following macro will read the target libraries from the file 'target_libraries.cmake'
 ctkMacroGetTargetLibraries(KIT_target_libraries)

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

@@ -10,6 +10,10 @@ SET(TEST_SOURCES
   ctkTransferFunctionViewTest3.cpp
   ctkTransferFunctionViewTest4.cpp
   ctkTransferFunctionViewTest5.cpp
+  ctkVTKChartViewTest1.cpp
+  ctkVTKScalarsToColorsViewTest1.cpp
+  ctkVTKScalarsToColorsViewTest2.cpp
+  ctkVTKScalarsToColorsViewTest3.cpp
   )
 
 #
@@ -55,6 +59,10 @@ SIMPLE_TEST( ctkTransferFunctionViewTest2 )
 SIMPLE_TEST( ctkTransferFunctionViewTest3 )
 SIMPLE_TEST( ctkTransferFunctionViewTest4 )
 SIMPLE_TEST( ctkTransferFunctionViewTest5 )
+SIMPLE_TEST( ctkVTKChartViewTest1 )
+SIMPLE_TEST( ctkVTKScalarsToColorsViewTest1 )
+SIMPLE_TEST( ctkVTKScalarsToColorsViewTest2 )
+SIMPLE_TEST( ctkVTKScalarsToColorsViewTest3 )
 
 #
 # Add Tests expecting CTKData to be set

+ 109 - 0
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKChartViewTest1.cpp

@@ -0,0 +1,109 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  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 "ctkVTKChartView.h"
+
+// VTK includes
+#include "vtkIntArray.h"
+#include <vtkSmartPointer.h>
+#include "vtkTable.h"
+#include <vtkPlotBar.h>
+
+// STD includes
+#include <iostream>
+
+#define VTK_CREATE(type, name) \
+  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
+
+// Monthly circulation data
+static int data_2008[] = {10822, 10941, 9979, 10370, 9460, 11228, 15093, 12231, 10160, 9816, 9384, 7892};
+static int data_2009[] = {9058, 9474, 9979, 9408, 8900, 11569, 14688, 12231, 10294, 9585, 8957, 8590};
+static int data_2010[] = {9058, 10941, 9979, 10270, 8900, 11228, 14688, 12231, 10160, 9585, 9384, 8590};
+
+//-----------------------------------------------------------------------------
+int ctkVTKChartViewTest1(int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+
+  ctkVTKChartView* view = new ctkVTKChartView(0);
+
+  // Create a table with some points in it...
+  VTK_CREATE(vtkTable, table);
+
+  VTK_CREATE(vtkIntArray, arrMonth);
+  arrMonth->SetName("Month");
+  table->AddColumn(arrMonth);
+
+  VTK_CREATE(vtkIntArray, arr2008);
+  arr2008->SetName("2008");
+  table->AddColumn(arr2008);
+
+  VTK_CREATE(vtkIntArray, arr2009);
+  arr2009->SetName("2009");
+  table->AddColumn(arr2009);
+
+  VTK_CREATE(vtkIntArray, arr2010);
+  arr2010->SetName("2010");
+  table->AddColumn(arr2010);
+
+  table->SetNumberOfRows(12);
+  for (int i = 0; i < 12; i++)
+    {
+    table->SetValue(i,0,i+1);
+    table->SetValue(i,1,data_2008[i]);
+    table->SetValue(i,2,data_2009[i]);
+    table->SetValue(i,3,data_2010[i]);
+    }
+
+  // Add multiple line plots, setting the colors etc
+  vtkPlotBar* bar = vtkPlotBar::New();
+  bar->SetInput(table, 0, 1);
+  bar->SetColor(0, 255, 0, 255);
+  view->addPlot(bar);
+  bar->Delete();
+
+  bar = vtkPlotBar::New();
+  bar->SetInput(table, 0, 2);
+  bar->SetColor(255, 0, 0, 255);
+  view->addPlot(bar);
+  bar->Delete();
+
+  bar = vtkPlotBar::New();
+  bar->SetInput(table, 0, 3);
+  bar->SetColor(0, 0, 255, 255);
+  view->addPlot(bar);
+  bar->Delete();
+
+  view->show();
+
+  QTimer autoExit;
+  if (argc < 2 || QString(argv[1]) != "-I")
+    {
+    QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
+    autoExit.start(1000);
+    }
+  return app.exec();
+}

+ 61 - 0
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKScalarsToColorsViewTest1.cpp

@@ -0,0 +1,61 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  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"
+
+// VTK includes
+#include <vtkColorTransferFunction.h>
+#include <vtkSmartPointer.h>
+
+// STD includes
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkVTKScalarsToColorsViewTest1(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.);
+
+  ctkVTKScalarsToColorsView view(0);
+  view.addColorTransferFunction(ctf);
+  view.fitAxesToBounds();
+  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);
+    }
+  return app.exec();
+}

+ 123 - 0
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKScalarsToColorsViewTest2.cpp

@@ -0,0 +1,123 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  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"
+
+// VTK includes
+#include <vtkChartXY.h>
+#include <vtkColorTransferFunction.h>
+#include <vtkImageAccumulate.h>
+#include <vtkImageData.h>
+#include <vtkIntArray.h>
+#include <vtkPointData.h>
+#include <vtkPen.h>
+#include <vtkPlotBar.h>
+#include <vtkSmartPointer.h>
+#include <vtkTable.h>
+
+// STD includes
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkVTKScalarsToColorsViewTest2(int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+
+  // Transfer Function
+  vtkSmartPointer<vtkColorTransferFunction> ctf =
+    vtkSmartPointer<vtkColorTransferFunction>::New();
+  //
+  ctf->AddRGBPoint(0., 0.6941,0.76,0., 0.5, 0.);
+  ctf->AddRGBPoint(85., 0.,0.6941,0.96);
+  ctf->AddRGBPoint(170., 0.9686,0.0,0.6941);
+  ctf->AddRGBPoint(255., 0.9686,0.76,0.);
+
+  // Image
+  vtkSmartPointer<vtkImageData> image =
+    vtkSmartPointer<vtkImageData>::New();
+  image->SetDimensions(256, 256, 1);
+  image->SetScalarTypeToUnsignedChar();
+  image->SetNumberOfScalarComponents(1); // image holds one value intensities
+  image->SetSpacing(20000., 30., 900000000.);
+  image->SetOrigin(-251234568., 0.00001, 40.2);
+  image->AllocateScalars(); // allocate storage for image data
+  unsigned char * ptr = static_cast<unsigned char *>(image->GetScalarPointer());
+  for (int i=0; i<256*256*1; ++i)
+    {
+    *(ptr++)= rand() % 256;
+    }
+
+  // Histogram
+  vtkSmartPointer<vtkImageAccumulate> histogram =
+    vtkSmartPointer<vtkImageAccumulate>::New();
+  histogram->SetInput(image);
+  histogram->SetComponentExtent(0, 255, 0 , 0 , 0, 0);
+  histogram->Update();
+  vtkAbstractArray* bins =
+    histogram->GetOutput()->GetPointData()->GetScalars();
+
+  // Histogram table
+  vtkSmartPointer<vtkTable> table =
+    vtkSmartPointer<vtkTable>::New();
+  vtkSmartPointer<vtkIntArray> intArray =
+    vtkSmartPointer<vtkIntArray>::New();
+  intArray->SetNumberOfComponents(1);
+  intArray->SetNumberOfTuples(256);
+  intArray->SetName("intensities");
+  for (int i = 0; i < 256; ++i)
+    {
+    intArray->SetValue(i, i);
+    }
+  bins->SetName("Histogram");
+  table->AddColumn(intArray);
+  table->AddColumn(histogram->GetOutput()->GetPointData()->GetScalars());
+
+  //Histogram Plot
+  vtkSmartPointer<vtkPlotBar> histogramPlot =
+    vtkSmartPointer<vtkPlotBar>::New();
+  histogramPlot->SetInput(table, 0, 1);
+  histogramPlot->SetColor(0.078, 0.008, 0);//not exactly black...just because.
+  histogramPlot->GetPen()->SetLineType(vtkPen::NO_PEN);
+
+  ctkVTKScalarsToColorsView view(0);
+  // add transfer function item
+  vtkPlot* ctfPlot = view.addColorTransferFunction(ctf);
+  view.chart()->SetPlotCorner(ctfPlot, 1);
+  ctfPlot->SetOpacity(0.7);
+  // add histogram item
+  view.addPlot(histogramPlot);
+  view.chart()->SetBarWidthFraction(1.);
+  view.fitAxesToBounds();
+  view.show();
+
+  QTimer autoExit;
+  if (argc < 2 || QString(argv[1]) != "-I")
+    {
+    QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
+    autoExit.start(1000);
+    }
+  return app.exec();
+}

+ 84 - 0
Libs/Visualization/VTK/Widgets/Testing/Cpp/ctkVTKScalarsToColorsViewTest3.cpp

@@ -0,0 +1,84 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  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"
+
+// VTK includes
+#include <vtkChartXY.h>
+#include <vtkColorTransferFunction.h>
+#include <vtkImageAccumulate.h>
+#include <vtkImageData.h>
+#include <vtkIntArray.h>
+#include <vtkPiecewiseFunction.h>
+#include <vtkPointData.h>
+#include <vtkPen.h>
+#include <vtkPlotBar.h>
+#include <vtkSmartPointer.h>
+#include <vtkTable.h>
+
+// STD includes
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkVTKScalarsToColorsViewTest3(int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+
+  // Transfer Function
+  vtkSmartPointer<vtkColorTransferFunction> ctf =
+    vtkSmartPointer<vtkColorTransferFunction>::New();
+  //
+  ctf->AddRGBPoint(0. , 220./255., 173./255.,   3./255.);
+  ctf->AddRGBPoint(0.2,   1./255., 152./255., 231./255.);
+  ctf->AddRGBPoint(0.4,  79./255., 235./255., 237./255.);
+  ctf->AddRGBPoint(0.6,  52./255., 193./255.,  72./255.);
+  ctf->AddRGBPoint(0.8,  67./255., 136./255., 151./255.);
+  ctf->AddRGBPoint(1. ,  78./255.,  87./255., 179./255.);
+
+  // Opacity function
+  vtkSmartPointer<vtkPiecewiseFunction> opacityFunction =
+    vtkSmartPointer<vtkPiecewiseFunction>::New();
+  opacityFunction->AddPoint(0.,0.3, 0.5, 0.5);
+  opacityFunction->AddPoint(0.2, 0.1, 0.5, 0.5);
+  opacityFunction->AddPoint(0.4,0.87, 0.5, 0.5);
+  opacityFunction->AddPoint(0.6, 1., 0.5, 0.5);
+  opacityFunction->AddPoint(0.8, 0.5, 0.5, 0.5);
+  opacityFunction->AddPoint(1.,0.8, 0.5, 0.5);
+
+  ctkVTKScalarsToColorsView view(0);
+  // add transfer function item
+  view.addCompositeFunction(ctf, opacityFunction);
+  view.fitAxesToBounds();
+  view.show();
+
+  QTimer autoExit;
+  if (argc < 2 || QString(argv[1]) != "-I")
+    {
+    QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
+    autoExit.start(1000);
+    }
+  return app.exec();
+}

+ 199 - 0
Libs/Visualization/VTK/Widgets/ctkVTKChartView.cpp

@@ -0,0 +1,199 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  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
+
+// CTK includes
+#include "ctkLogger.h"
+#include "ctkVTKChartView.h"
+
+// VTK includes
+#include <vtkAxis.h>
+#include <vtkChartXY.h>
+#include <vtkContext2D.h>
+#include <vtkContextScene.h>
+#include <vtkContextView.h>
+#include <vtkOpenGLContextDevice2D.h>
+#include <vtkPlot.h>
+#include <vtkRenderWindow.h>
+
+//----------------------------------------------------------------------------
+static ctkLogger logger("org.commontk.visualization.vtk.widgets.ctkVTKChartView");
+//----------------------------------------------------------------------------
+
+class ctkVTKChartViewPrivate: public ctkPrivate<ctkVTKChartView>
+{
+public:
+  ctkVTKChartViewPrivate();
+  void init();
+
+  vtkSmartPointer<vtkContextView> ContextView;
+  vtkSmartPointer<vtkChartXY> Chart;
+};
+
+// ----------------------------------------------------------------------------
+// ctkVTKChartViewPrivate methods
+
+// ----------------------------------------------------------------------------
+ctkVTKChartViewPrivate::ctkVTKChartViewPrivate()
+{
+  this->ContextView = vtkSmartPointer<vtkContextView>::New();
+  this->Chart = vtkSmartPointer<vtkChartXY>::New();
+  this->ContextView->GetScene()->AddItem(this->Chart);
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKChartViewPrivate::init()
+{
+  CTK_P(ctkVTKChartView);
+  this->ContextView->SetInteractor(p->GetInteractor());
+  p->SetRenderWindow(this->ContextView->GetRenderWindow());
+  // low def for now (faster)
+  //p->GetRenderWindow()->SetMultiSamples(0);
+  //vtkOpenGLContextDevice2D::SafeDownCast(this->ContextView->GetContext()->GetDevice())
+  //                                       ->SetStringRendererToQt();
+}
+
+// ----------------------------------------------------------------------------
+// ctkVTKChartView methods
+
+// ----------------------------------------------------------------------------
+ctkVTKChartView::ctkVTKChartView(QWidget* parentWidget)
+  :QVTKWidget(parentWidget)
+{
+  CTK_INIT_PRIVATE(ctkVTKChartView);
+  CTK_D(ctkVTKChartView);
+  d->init();
+  this->setAutomaticImageCacheEnabled(true);
+}
+
+// ----------------------------------------------------------------------------
+ctkVTKChartView::~ctkVTKChartView()
+{
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKChartView::setTitle(const QString& newTitle)
+{
+  CTK_D(ctkVTKChartView);
+  d->Chart->SetTitle(newTitle.toLatin1());
+}
+
+// ----------------------------------------------------------------------------
+QString ctkVTKChartView::title()const
+{
+  CTK_D(const ctkVTKChartView);
+  return d->Chart->GetTitle();
+}
+
+// ----------------------------------------------------------------------------
+vtkChartXY* ctkVTKChartView::chart()const
+{
+  CTK_D(const ctkVTKChartView);
+  return d->Chart;
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKChartView::addPlot(vtkPlot* plot)
+{
+  CTK_D(ctkVTKChartView);
+  d->Chart->AddPlot(plot);
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKChartView::fitAxesToBounds()
+{
+  vtkChartXY* chart = this->chart();
+  const vtkIdType plotCount = chart->GetNumberOfPlots();
+  double extremaBounds[8] = {VTK_DOUBLE_MAX, VTK_DOUBLE_MIN,
+                             VTK_DOUBLE_MAX, VTK_DOUBLE_MIN,
+                             VTK_DOUBLE_MAX, VTK_DOUBLE_MIN};
+  for (vtkIdType i = 0; i < plotCount; ++i)
+    {
+    vtkPlot* plot = chart->GetPlot(i);
+
+    int corner = chart->GetPlotCorner(plot);
+    double bounds[4];
+    plot->GetBounds(bounds);
+    switch (corner)
+      {
+      // bottom left
+      case 0:
+        // x
+        extremaBounds[2] = extremaBounds[2] > bounds[0] ?
+          bounds[0] : extremaBounds[2];
+        extremaBounds[3] = extremaBounds[3] < bounds[1] ?
+          bounds[1] : extremaBounds[3];
+        // y
+        extremaBounds[0] = extremaBounds[0] > bounds[2] ?
+          bounds[2] : extremaBounds[0];
+        extremaBounds[1] = extremaBounds[1] < bounds[3] ?
+          bounds[3] : extremaBounds[1];
+        break;
+      // bottom right
+      case 1:
+        // x
+        extremaBounds[2] = extremaBounds[2] > bounds[0] ?
+          bounds[0] : extremaBounds[2];
+        extremaBounds[3] = extremaBounds[3] < bounds[1] ?
+          bounds[1] : extremaBounds[3];
+        // y
+        extremaBounds[4] = extremaBounds[4] > bounds[2] ?
+          bounds[2] : extremaBounds[4];
+        extremaBounds[5] = extremaBounds[5] < bounds[3] ?
+          bounds[3] : extremaBounds[5];
+        break;
+      // top right
+      case 2:
+        // x
+        extremaBounds[6] = extremaBounds[6] > bounds[0] ?
+          bounds[0] : extremaBounds[6];
+        extremaBounds[7] = extremaBounds[7] < bounds[1] ?
+          bounds[1] : extremaBounds[7];
+        // y
+        extremaBounds[4] = extremaBounds[4] > bounds[2] ?
+          bounds[2] : extremaBounds[4];
+        extremaBounds[5] = extremaBounds[5] < bounds[3] ?
+          bounds[3] : extremaBounds[5];
+        break;
+      // top left
+      case 3:
+        // x
+        extremaBounds[6] = extremaBounds[6] > bounds[0] ?
+          bounds[0] : extremaBounds[6];
+        extremaBounds[7] = extremaBounds[7] < bounds[1] ?
+          bounds[1] : extremaBounds[7];
+        // y
+        extremaBounds[0] = extremaBounds[0] > bounds[2] ?
+          bounds[2] : extremaBounds[1];
+        extremaBounds[1] = extremaBounds[0] < bounds[3] ?
+          bounds[3] : extremaBounds[1];
+        break;
+      }
+    }
+  for (int i = 0; i < chart->GetNumberOfAxes(); ++i)
+    {
+    if (extremaBounds[2*i] != VTK_DOUBLE_MAX)
+      {
+      chart->GetAxis(i)->SetRange(extremaBounds[2*i], extremaBounds[2*i+1]);
+      chart->GetAxis(i)->SetBehavior(1);
+      }
+    }
+}

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

@@ -0,0 +1,61 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  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 __ctkVTKChartView_h
+#define __ctkVTKChartView_h
+
+// CTK includes
+#include <ctkPimpl.h>
+#include "CTKVisualizationVTKWidgetsExport.h"
+class ctkVTKChartViewPrivate;
+
+// VTK includes
+#include <QVTKWidget.h>
+
+class vtkChartXY;
+class vtkPlot;
+
+class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKChartView : public QVTKWidget
+{
+  Q_OBJECT
+  Q_PROPERTY(QString title READ title WRITE setTitle)
+
+public:
+  ctkVTKChartView(QWidget* parent = 0);
+  virtual ~ctkVTKChartView();
+
+  /// Generic function to add a custom plot. \a plot is added into the chart
+  void addPlot(vtkPlot* plot);
+
+  /// Utility function that returns the view chart. It can be used for customizing
+  /// the chart display options (axes, legend...)
+  vtkChartXY* chart()const;
+
+  /// Title that appears inside the view
+  QString title()const;
+  void setTitle(const QString& title);
+
+  void fitAxesToBounds();
+
+private:
+  CTK_DECLARE_PRIVATE(ctkVTKChartView);
+};
+
+#endif

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

@@ -0,0 +1,154 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  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
+
+// CTK includes
+#include "ctkLogger.h"
+#include "ctkVTKScalarsToColorsView.h"
+
+// VTK includes
+#include <vtkAxis.h>
+#include <vtkChartXY.h>
+#include <vtkColorTransferFunction.h>
+#include <vtkColorTransferFunctionItem.h>
+#include <vtkCompositeTransferFunctionItem.h>
+#include <vtkLookupTable.h>
+#include <vtkLookupTableItem.h>
+#include <vtkPiecewiseControlPointsItem.h>
+#include <vtkPiecewiseFunction.h>
+#include <vtkPiecewiseFunctionItem.h>
+
+//----------------------------------------------------------------------------
+static ctkLogger logger("org.commontk.visualization.vtk.widgets.ctkVTKScalarsToColorsView");
+//----------------------------------------------------------------------------
+
+class ctkVTKScalarsToColorsViewPrivate: public ctkPrivate<ctkVTKScalarsToColorsView>
+{
+public:
+  ctkVTKScalarsToColorsViewPrivate();
+  void init();
+  void updateChart();
+};
+
+// ----------------------------------------------------------------------------
+// ctkVTKScalarsToColorsViewPrivate methods
+
+// ----------------------------------------------------------------------------
+ctkVTKScalarsToColorsViewPrivate::ctkVTKScalarsToColorsViewPrivate()
+{
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKScalarsToColorsViewPrivate::init()
+{
+  CTK_P(ctkVTKScalarsToColorsView);
+  vtkChartXY* chart = p->chart();
+  chart->SetAutoAxes(false);
+  chart->SetHiddenAxisBorder(0);
+  chart->GetAxis(0)->SetVisible(false);
+  chart->GetAxis(1)->SetVisible(false);
+  chart->GetAxis(2)->SetVisible(false);
+  chart->GetAxis(3)->SetVisible(false);
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKScalarsToColorsViewPrivate::updateChart()
+{
+
+}
+
+// ----------------------------------------------------------------------------
+// ctkVTKScalarsToColorsView methods
+
+// ----------------------------------------------------------------------------
+ctkVTKScalarsToColorsView::ctkVTKScalarsToColorsView(QWidget* parentWidget)
+  :ctkVTKChartView(parentWidget)
+{
+  CTK_INIT_PRIVATE(ctkVTKScalarsToColorsView);
+  CTK_D(ctkVTKScalarsToColorsView);
+  d->init();
+}
+
+// ----------------------------------------------------------------------------
+ctkVTKScalarsToColorsView::~ctkVTKScalarsToColorsView()
+{
+}
+
+// ----------------------------------------------------------------------------
+vtkPlot* ctkVTKScalarsToColorsView::addLookupTable(vtkLookupTable* lut)
+{
+  CTK_D(ctkVTKScalarsToColorsView);
+  vtkSmartPointer<vtkLookupTableItem> item =
+    vtkSmartPointer<vtkLookupTableItem>::New();
+  item->SetLookupTable(lut);
+  this->addPlot(item);
+  d->updateChart();
+  return item;
+}
+// ----------------------------------------------------------------------------
+vtkPlot* ctkVTKScalarsToColorsView::addColorTransferFunction(vtkColorTransferFunction* colorTF)
+{
+  CTK_D(ctkVTKScalarsToColorsView);
+  vtkSmartPointer<vtkColorTransferFunctionItem> item =
+    vtkSmartPointer<vtkColorTransferFunctionItem>::New();
+  item->SetColorTransferFunction(colorTF);
+  this->addPlot(item);
+  d->updateChart();
+  return item;
+}
+
+// ----------------------------------------------------------------------------
+vtkPlot* ctkVTKScalarsToColorsView::addOpacityFunction(vtkPiecewiseFunction* opacityTF)
+{
+  CTK_D(ctkVTKScalarsToColorsView);
+  vtkSmartPointer<vtkPiecewiseFunctionItem> item =
+    vtkSmartPointer<vtkPiecewiseFunctionItem>::New();
+  item->SetPiecewiseFunction(opacityTF);
+  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);
+  d->updateChart();
+  return item;
+}
+
+// ----------------------------------------------------------------------------
+vtkPlot* ctkVTKScalarsToColorsView::addCompositeFunction(vtkColorTransferFunction* colorTF, vtkPiecewiseFunction* opacityTF)
+{
+  CTK_D(ctkVTKScalarsToColorsView);
+  vtkSmartPointer<vtkCompositeTransferFunctionItem> item =
+    vtkSmartPointer<vtkCompositeTransferFunctionItem>::New();
+  item->SetColorTransferFunction(colorTF);
+  item->SetOpacityFunction(opacityTF);
+  item->SetMaskAboveCurve(true);
+  this->addPlot(item);
+  vtkSmartPointer<vtkPiecewiseControlPointsItem> controlPointsItem =
+    vtkSmartPointer<vtkPiecewiseControlPointsItem>::New();
+  controlPointsItem->SetPiecewiseFunction(opacityTF);
+  this->addPlot(controlPointsItem);
+
+  d->updateChart();
+  return item;
+}

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

@@ -0,0 +1,53 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) 2010  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 __ctkVTKScalarsToColorsView_h
+#define __ctkVTKScalarsToColorsView_h
+
+// CTK includes
+#include <ctkPimpl.h>
+#include "ctkVTKChartView.h"
+class ctkVTKScalarsToColorsViewPrivate;
+
+// VTK includes
+#include <QVTKWidget.h>
+
+class vtkColorTransferFunction;
+class vtkLookupTable;
+class vtkPiecewiseFunction;
+
+class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKScalarsToColorsView : public ctkVTKChartView
+{
+  Q_OBJECT
+
+public:
+  ctkVTKScalarsToColorsView(QWidget* parent = 0);
+  virtual ~ctkVTKScalarsToColorsView();
+
+  vtkPlot* addLookupTable(vtkLookupTable* lut);
+  vtkPlot* addColorTransferFunction(vtkColorTransferFunction* colorTF);
+  vtkPlot* addOpacityFunction(vtkPiecewiseFunction* opacityTF);
+  vtkPlot* addCompositeFunction(vtkColorTransferFunction* colorTF, vtkPiecewiseFunction* opacityTF);
+
+private:
+  CTK_DECLARE_PRIVATE(ctkVTKScalarsToColorsView);
+};
+
+#endif