Преглед на файлове

STYLE: Reorder ctkCheckableHeaderViewTest to be alphabetically sorted

Julien Finet преди 15 години
родител
ревизия
4ca6e40379

+ 1 - 0
CMake/ctkMacroSetupQt.cmake

@@ -39,6 +39,7 @@ MACRO(ctkMacroSetupQt)
 
     SET(QT_USE_QTNETWORK ON)
     SET(QT_USE_QTSQL ON)
+	SET(QT_USE_QTOPENGL ON)
     SET(QT_USE_QTTEST ${BUILD_TESTING})
     INCLUDE(${QT_USE_FILE})
 

+ 4 - 1
Libs/Core/CMakeLists.txt

@@ -37,6 +37,8 @@ SET(KIT_SRCS
   ctkDependencyGraph.h
   ctkLogger.cpp
   ctkLogger.h
+  ctkHistogram.cpp
+  ctkHistogram.h
   ctkModelTester.cpp
   ctkModelTester.h
   ctkPimpl.h
@@ -57,9 +59,10 @@ ENDIF()
 # Headers that should run through moc
 SET(KIT_MOC_SRCS
   ctkLogger.h 
+  ctkHistogram.h
   ctkModelTester.h
   ctkTransferFunction.h
-)
+  )
 
 # UI files
 SET(KIT_UI_FORMS

+ 3 - 0
Libs/Visualization/VTK/Core/CMakeLists.txt

@@ -31,6 +31,8 @@ SET(KIT_SRCS
   ctkVTKCompositeFunction.h
   ctkVTKConnection.cpp
   ctkVTKConnection.h
+  ctkVTKHistogram.cpp
+  ctkVTKHistogram.h
   ctkVTKLookupTable.cpp
   ctkVTKLookupTable.h
   ctkVTKObject.h
@@ -46,6 +48,7 @@ SET(KIT_MOC_SRCS
   ctkVTKConnection.h
   ctkVTKCompositeFunction.h
   ctkVTKLookupTable.h
+  ctkVTKHistogram.h
   ctkVTKObjectEventsObserver.h
   ctkVTKPiecewiseFunction.h
   )

+ 218 - 218
Libs/Visualization/VTK/Core/ctkVTKLookupTable.cpp

@@ -1,222 +1,222 @@
-/*=========================================================================
-
-  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 <QColor>
-#include <QDebug>
-
-/// CTK includes
-#include "ctkVTKLookupTable.h"
-
-/// VTK includes
-#include <vtkLookupTable.h>
-#include <vtkSmartPointer.h>
-
-//-----------------------------------------------------------------------------
-class ctkVTKLookupTablePrivate: public ctkPrivate<ctkVTKLookupTable>
-{
-public:
-  vtkSmartPointer<vtkLookupTable> LookupTable;
-};
-
-//-----------------------------------------------------------------------------
-ctkVTKLookupTable::ctkVTKLookupTable(QObject* parentObject)
-  :ctkTransferFunction(parentObject)
-{
-  CTK_INIT_PRIVATE(ctkVTKLookupTable);
-}
-
-//-----------------------------------------------------------------------------
-ctkVTKLookupTable::ctkVTKLookupTable(vtkLookupTable* lookupTable, 
-                                     QObject* parentObject)
-  :ctkTransferFunction(parentObject)
-{
-  CTK_INIT_PRIVATE(ctkVTKLookupTable);
-  this->setLookupTable(lookupTable);
-}
-
-//-----------------------------------------------------------------------------
-ctkVTKLookupTable::~ctkVTKLookupTable()
-{
-}
-
-//-----------------------------------------------------------------------------
-int ctkVTKLookupTable::count()const
-{
-  CTK_D(const ctkVTKLookupTable);
-  if (d->LookupTable.GetPointer() == 0)
-    {
-    Q_ASSERT(d->LookupTable.GetPointer());
-    return -1;
-    }
-  return d->LookupTable->GetNumberOfColors();
-}
-
-//-----------------------------------------------------------------------------
-bool ctkVTKLookupTable::isDiscrete()const
-{
-  return true;
-}
-
-//-----------------------------------------------------------------------------
-bool ctkVTKLookupTable::isEditable()const
-{
-  return true;
-}
-
-//-----------------------------------------------------------------------------
-void ctkVTKLookupTable::range(qreal& minRange, qreal& maxRange)const
-{
-  CTK_D(const ctkVTKLookupTable);
-  if (d->LookupTable.GetPointer() == 0)
-    {
-    Q_ASSERT(d->LookupTable.GetPointer());
-    minRange = 1.; // set incorrect values
-    maxRange = 0.;
-    return;
-    }
-  double rangeValues[2];
-  d->LookupTable->GetTableRange(rangeValues);
-  minRange = rangeValues[0];
-  maxRange = rangeValues[1];
-}
-
-//-----------------------------------------------------------------------------
-QVariant ctkVTKLookupTable::minValue()const
-{
-  CTK_D(const ctkVTKLookupTable);
-  if (d->LookupTable.GetPointer() == 0)
-    {
-    Q_ASSERT(d->LookupTable.GetPointer());
-    return QColor();
-    }
-  QColor minValue = QColor::fromHsvF(
-    d->LookupTable->GetHueRange()[0],
-    d->LookupTable->GetSaturationRange()[0],
-    d->LookupTable->GetValueRange()[0],
-    d->LookupTable->GetAlphaRange()[0]);
-  return minValue;
-}
-
-//-----------------------------------------------------------------------------
-QVariant ctkVTKLookupTable::maxValue()const
-{
-  CTK_D(const ctkVTKLookupTable);
-  if (d->LookupTable.GetPointer() == 0)
-    {
-    Q_ASSERT(d->LookupTable.GetPointer());
-    return QColor();
-    }
-  QColor maxValue = QColor::fromHsvF(
-    d->LookupTable->GetHueRange()[1],
-    d->LookupTable->GetSaturationRange()[1],
-    d->LookupTable->GetValueRange()[1],
-    d->LookupTable->GetAlphaRange()[1]);
-  return maxValue;
-}
-
-//-----------------------------------------------------------------------------
-qreal ctkVTKLookupTable::indexToPos(int index)const
-{
-  CTK_D(const ctkVTKLookupTable);
-  double* range = d->LookupTable->GetRange();
-  return range[0] + index * ((range[1] - range[0]) / (d->LookupTable->GetNumberOfColors() - 1));
-}
-
-//-----------------------------------------------------------------------------
-int ctkVTKLookupTable::posToIndex(qreal pos)const
-{
-  CTK_D(const ctkVTKLookupTable);
-  double* range = d->LookupTable->GetRange();
-  return (pos - range[0]) / ((range[1] - range[0]) / (d->LookupTable->GetNumberOfColors() - 1));
-}
-
-//-----------------------------------------------------------------------------
-ctkControlPoint* ctkVTKLookupTable::controlPoint(int index)const
-{
-  CTK_D(const ctkVTKLookupTable);
-  ctkControlPoint* cp = new ctkControlPoint();
-  cp->P.X = this->indexToPos(index);
-  cp->P.Value = this->value(cp->P.X);
-  return cp;
-}
-
-//-----------------------------------------------------------------------------
-QVariant ctkVTKLookupTable::value(qreal pos)const
-{
-  CTK_D(const ctkVTKLookupTable);
+/*=========================================================================
+
+  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 <QColor>
+#include <QDebug>
+
+/// CTK includes
+#include "ctkVTKLookupTable.h"
+
+/// VTK includes
+#include <vtkLookupTable.h>
+#include <vtkSmartPointer.h>
+
+//-----------------------------------------------------------------------------
+class ctkVTKLookupTablePrivate: public ctkPrivate<ctkVTKLookupTable>
+{
+public:
+  vtkSmartPointer<vtkLookupTable> LookupTable;
+};
+
+//-----------------------------------------------------------------------------
+ctkVTKLookupTable::ctkVTKLookupTable(QObject* parentObject)
+  :ctkTransferFunction(parentObject)
+{
+  CTK_INIT_PRIVATE(ctkVTKLookupTable);
+}
+
+//-----------------------------------------------------------------------------
+ctkVTKLookupTable::ctkVTKLookupTable(vtkLookupTable* lookupTable, 
+                                     QObject* parentObject)
+  :ctkTransferFunction(parentObject)
+{
+  CTK_INIT_PRIVATE(ctkVTKLookupTable);
+  this->setLookupTable(lookupTable);
+}
+
+//-----------------------------------------------------------------------------
+ctkVTKLookupTable::~ctkVTKLookupTable()
+{
+}
+
+//-----------------------------------------------------------------------------
+int ctkVTKLookupTable::count()const
+{
+  CTK_D(const ctkVTKLookupTable);
+  if (d->LookupTable.GetPointer() == 0)
+    {
+    Q_ASSERT(d->LookupTable.GetPointer());
+    return -1;
+    }
+  return d->LookupTable->GetNumberOfColors();
+}
+
+//-----------------------------------------------------------------------------
+bool ctkVTKLookupTable::isDiscrete()const
+{
+  return true;
+}
+
+//-----------------------------------------------------------------------------
+bool ctkVTKLookupTable::isEditable()const
+{
+  return true;
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKLookupTable::range(qreal& minRange, qreal& maxRange)const
+{
+  CTK_D(const ctkVTKLookupTable);
+  if (d->LookupTable.GetPointer() == 0)
+    {
+    Q_ASSERT(d->LookupTable.GetPointer());
+    minRange = 1.; // set incorrect values
+    maxRange = 0.;
+    return;
+    }
+  double rangeValues[2];
+  d->LookupTable->GetTableRange(rangeValues);
+  minRange = rangeValues[0];
+  maxRange = rangeValues[1];
+}
+
+//-----------------------------------------------------------------------------
+QVariant ctkVTKLookupTable::minValue()const
+{
+  CTK_D(const ctkVTKLookupTable);
+  if (d->LookupTable.GetPointer() == 0)
+    {
+    Q_ASSERT(d->LookupTable.GetPointer());
+    return QColor();
+    }
+  QColor minValue = QColor::fromHsvF(
+    d->LookupTable->GetHueRange()[0],
+    d->LookupTable->GetSaturationRange()[0],
+    d->LookupTable->GetValueRange()[0],
+    d->LookupTable->GetAlphaRange()[0]);
+  return minValue;
+}
+
+//-----------------------------------------------------------------------------
+QVariant ctkVTKLookupTable::maxValue()const
+{
+  CTK_D(const ctkVTKLookupTable);
+  if (d->LookupTable.GetPointer() == 0)
+    {
+    Q_ASSERT(d->LookupTable.GetPointer());
+    return QColor();
+    }
+  QColor maxValue = QColor::fromHsvF(
+    d->LookupTable->GetHueRange()[1],
+    d->LookupTable->GetSaturationRange()[1],
+    d->LookupTable->GetValueRange()[1],
+    d->LookupTable->GetAlphaRange()[1]);
+  return maxValue;
+}
+
+//-----------------------------------------------------------------------------
+qreal ctkVTKLookupTable::indexToPos(int index)const
+{
+  CTK_D(const ctkVTKLookupTable);
+  double* range = d->LookupTable->GetRange();
+  return range[0] + index * ((range[1] - range[0]) / (d->LookupTable->GetNumberOfColors() - 1));
+}
+
+//-----------------------------------------------------------------------------
+int ctkVTKLookupTable::posToIndex(qreal pos)const
+{
+  CTK_D(const ctkVTKLookupTable);
+  double* range = d->LookupTable->GetRange();
+  return (pos - range[0]) / ((range[1] - range[0]) / (d->LookupTable->GetNumberOfColors() - 1));
+}
+
+//-----------------------------------------------------------------------------
+ctkControlPoint* ctkVTKLookupTable::controlPoint(int index)const
+{
+  CTK_D(const ctkVTKLookupTable);
+  ctkControlPoint* cp = new ctkControlPoint();
+  cp->P.X = this->indexToPos(index);
+  cp->P.Value = this->value(cp->P.X);
+  return cp;
+}
+
+//-----------------------------------------------------------------------------
+QVariant ctkVTKLookupTable::value(qreal pos)const
+{
+  CTK_D(const ctkVTKLookupTable);
   Q_ASSERT(d->LookupTable.GetPointer());
   double rgb[3];
   d->LookupTable->GetColor(pos, rgb);
   double alpha = d->LookupTable->GetOpacity(pos);
-  return QColor::fromRgbF(rgb[0], rgb[1], rgb[2], alpha);
-}
-
-//-----------------------------------------------------------------------------
-int ctkVTKLookupTable::insertControlPoint(const ctkControlPoint& cp)
-{
-  CTK_D(ctkVTKLookupTable);
-  qDebug() << "ctkVTKLookupTable doesn't support insertControlPoint";
-  return -1;
-}
-
-//-----------------------------------------------------------------------------
-// insert point with value = 0
-int ctkVTKLookupTable::insertControlPoint(qreal pos)
-{
-  // nothing
-  int index = 0;
-
-  return index;
-}
-//-----------------------------------------------------------------------------
-void ctkVTKLookupTable::setControlPointPos(int index, qreal pos)
-{
-  CTK_D(ctkVTKLookupTable);
-  // TODO, inform that nothing is done here.
-  qDebug() << "ctkVTKLookupTable doesn't support setControlPointPos";
-  return;
-}
-
-//-----------------------------------------------------------------------------
-void ctkVTKLookupTable::setControlPointValue(int index, const QVariant& value)
-{
-  CTK_D(ctkVTKLookupTable);
-  Q_ASSERT(value.value<QColor>().isValid());
-  QColor rgba = value.value<QColor>();
-  d->LookupTable->SetTableValue(index, rgba.redF(), rgba.greenF(), rgba.blueF(), rgba.alphaF());
-}
-
-//-----------------------------------------------------------------------------
-void ctkVTKLookupTable::setLookupTable(vtkLookupTable* lookupTable)
-{
-  CTK_D(ctkVTKLookupTable);
-  d->LookupTable = lookupTable;
-  this->qvtkReconnect(d->LookupTable,vtkCommand::ModifiedEvent,
-                      this, SIGNAL(changed()));
-  emit changed();
-}
-
-//-----------------------------------------------------------------------------
-vtkLookupTable* ctkVTKLookupTable::lookupTable()const
-{
-  CTK_D(const ctkVTKLookupTable);
-  return d->LookupTable;
-}
+  return QColor::fromRgbF(rgb[0], rgb[1], rgb[2], alpha);
+}
+
+//-----------------------------------------------------------------------------
+int ctkVTKLookupTable::insertControlPoint(const ctkControlPoint& cp)
+{
+  CTK_D(ctkVTKLookupTable);
+  qDebug() << "ctkVTKLookupTable doesn't support insertControlPoint";
+  return -1;
+}
+
+//-----------------------------------------------------------------------------
+// insert point with value = 0
+int ctkVTKLookupTable::insertControlPoint(qreal pos)
+{
+  // nothing
+  int index = 0;
+
+  return index;
+}
+//-----------------------------------------------------------------------------
+void ctkVTKLookupTable::setControlPointPos(int index, qreal pos)
+{
+  CTK_D(ctkVTKLookupTable);
+  // TODO, inform that nothing is done here.
+  qDebug() << "ctkVTKLookupTable doesn't support setControlPointPos";
+  return;
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKLookupTable::setControlPointValue(int index, const QVariant& value)
+{
+  CTK_D(ctkVTKLookupTable);
+  Q_ASSERT(value.value<QColor>().isValid());
+  QColor rgba = value.value<QColor>();
+  d->LookupTable->SetTableValue(index, rgba.redF(), rgba.greenF(), rgba.blueF(), rgba.alphaF());
+}
+
+//-----------------------------------------------------------------------------
+void ctkVTKLookupTable::setLookupTable(vtkLookupTable* lookupTable)
+{
+  CTK_D(ctkVTKLookupTable);
+  d->LookupTable = lookupTable;
+  this->qvtkReconnect(d->LookupTable,vtkCommand::ModifiedEvent,
+                      this, SIGNAL(changed()));
+  emit changed();
+}
+
+//-----------------------------------------------------------------------------
+vtkLookupTable* ctkVTKLookupTable::lookupTable()const
+{
+  CTK_D(const ctkVTKLookupTable);
+  return d->LookupTable;
+}

+ 3 - 1
Libs/Visualization/VTK/Widgets/Testing/Cpp/CMakeLists.txt

@@ -5,6 +5,7 @@ CREATE_TEST_SOURCELIST(Tests ${KIT}CppTests.cpp
   ctkTransferFunctionWidgetTest2.cpp
   ctkTransferFunctionWidgetTest3.cpp
   ctkTransferFunctionWidgetTest4.cpp
+  ctkTransferFunctionWidgetTest5.cpp
   #EXTRA_INCLUDE TestingMacros.h
   )
 
@@ -34,4 +35,5 @@ ENDMACRO( SIMPLE_TEST  )
 SIMPLE_TEST( ctkTransferFunctionWidgetTest1 )
 SIMPLE_TEST( ctkTransferFunctionWidgetTest2 )
 SIMPLE_TEST( ctkTransferFunctionWidgetTest3 )
-SIMPLE_TEST( ctkTransferFunctionWidgetTest4 )
+SIMPLE_TEST( ctkTransferFunctionWidgetTest4 )
+SIMPLE_TEST( ctkTransferFunctionWidgetTest5 )

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

@@ -59,6 +59,6 @@ int ctkTransferFunctionWidgetTest1(int argc, char * argv [] )
   //ctkTransferFunctionWidget* toto = new ctkTransferFunctionWidget();
   QTimer autoExit;
   QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
-  autoExit.start(1000);
+  //autoExit.start(1000);
   return app.exec();
 }

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

@@ -57,6 +57,6 @@ int ctkTransferFunctionWidgetTest3(int argc, char * argv [] )
 
   QTimer autoExit;
   QObject::connect(&autoExit, SIGNAL(timeout()), &app, SLOT(quit()));
-  autoExit.start(1000);
+  //autoExit.start(1000);
   return app.exec();
 }

+ 3 - 0
Libs/Widgets/CMakeLists.txt

@@ -60,6 +60,8 @@ SET(KIT_SRCS
   ctkTransferFunctionControlPointsItem.h
   ctkTransferFunctionGradientItem.cpp
   ctkTransferFunctionGradientItem.h
+  ctkTransferFunctionHistogramItem.cpp
+  ctkTransferFunctionHistogramItem.h
   ctkTransferFunctionItem.cpp
   ctkTransferFunctionItem.h
   ctkTransferFunctionWidget.cpp
@@ -96,6 +98,7 @@ SET(KIT_MOC_SRCS
   ctkTitleComboBox.h
   ctkTransferFunctionControlPointsItem.h
   ctkTransferFunctionGradientItem.h
+  ctkTransferFunctionHistogramItem.h
   ctkTransferFunctionItem.h
   ctkTransferFunctionControlPointsItem.h
   ctkTransferFunctionWidget.h

+ 2 - 3
Libs/Widgets/Testing/Cpp/CMakeLists.txt

@@ -3,6 +3,7 @@ SET(KIT ${PROJECT_NAME})
 CREATE_TEST_SOURCELIST(Tests ${KIT}CppTests.cxx
   ctkAddRemoveComboBoxTest1.cpp
   ctkButtonGroupTest1.cpp
+  ctkCheckableHeaderViewTest1.cpp
   ctkCollapsibleButtonTest1.cpp
   ctkCollapsibleGroupBoxTest1.cpp
   ctkColorPickerButtonTest1.cpp
@@ -16,8 +17,6 @@ CREATE_TEST_SOURCELIST(Tests ${KIT}CppTests.cxx
   ctkSliderSpinBoxWidgetTest1.cpp
   ctkTitleComboBoxTest1.cpp
   ctkTreeComboBoxTest1.cpp
-  ctkCheckableHeaderViewTest1.cpp
-  #EXTRA_INCLUDE TestingMacros.h
   )
 
 SET (TestsToRun ${Tests})
@@ -44,6 +43,7 @@ ENDMACRO( SIMPLE_TEST  )
 
 SIMPLE_TEST( ctkAddRemoveComboBoxTest1 )
 SIMPLE_TEST( ctkButtonGroupTest1 )
+SIMPLE_TEST( ctkCheckableHeaderViewTest1 )
 SIMPLE_TEST( ctkCollapsibleButtonTest1 )
 SIMPLE_TEST( ctkCollapsibleGroupBoxTest1 )
 SIMPLE_TEST( ctkColorPickerButtonTest1 )
@@ -52,7 +52,6 @@ SIMPLE_TEST( ctkDoubleRangeSliderTest1 )
 SIMPLE_TEST( ctkDoubleSliderTest1 )
 SIMPLE_TEST( ctkFittedTextBrowserTest1 )
 SIMPLE_TEST( ctkMatrixWidgetTest1 )
-SIMPLE_TEST( ctkCheckableHeaderViewTest1 )
 SIMPLE_TEST( ctkRangeSliderTest1 )
 SIMPLE_TEST( ctkRangeWidgetTest1 )
 SIMPLE_TEST( ctkSliderSpinBoxWidgetTest1 )

+ 13 - 7
Libs/Widgets/ctkTransferFunctionControlPointsItem.cpp

@@ -148,7 +148,10 @@ void ctkTransferFunctionControlPointsItem::mousePressEvent(QGraphicsSceneMouseEv
   // returns index
   int index = this->transferFunction()->insertControlPoint( tfPos.x());
   // update value of the point
-  this->transferFunction()->setControlPointValue( index, tfPos.y());
+  if (!QSharedPointer<ctkControlPoint>(this->transferFunction()->controlPoint(index))->value().canConvert<QColor>())
+    {
+    this->transferFunction()->setControlPointValue( index, tfPos.y());
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -170,14 +173,17 @@ void ctkTransferFunctionControlPointsItem::mouseMoveEvent(QGraphicsSceneMouseEve
   if(d->SelectedPoint == 0 || d->SelectedPoint == this->transferFunction()->count() )
     {
     qDebug() << "border" ;
+    return;
+    }
+  else if( this->transferFunction()->controlPoint(d->SelectedPoint - 1)->x() > newPos.x() ||
+      this->transferFunction()->controlPoint(d->SelectedPoint + 1)->x() < newPos.x())
+    {
+    return;
     }
-  else if( this->transferFunction()->controlPoint(d->SelectedPoint - 1)->x() < newPos.x() &&
-      this->transferFunction()->controlPoint(d->SelectedPoint + 1)->x() > newPos.x())
+  this->transferFunction()->setControlPointPos(d->SelectedPoint, newPos.x());
+  if (!QSharedPointer<ctkControlPoint>(this->transferFunction()->controlPoint(d->SelectedPoint))->value().canConvert<QColor>())
     {
-    // update pos of the point
-    this->transferFunction()->setControlPointPos( d->SelectedPoint, newPos.x());
-    // update value of the point
-    this->transferFunction()->setControlPointValue( d->SelectedPoint, newPos.y());
+    this->transferFunction()->setControlPointValue(d->SelectedPoint, newPos.y());
     }
 }
 

+ 16 - 1
Libs/Widgets/ctkTransferFunctionScene.cpp

@@ -176,7 +176,22 @@ void ctkTransferFunctionScene::computeCurve()
   for(int i = 1; i < count; ++i)
     {
     nextCP = d->TransferFunction->controlPoint(i);
-    if (dynamic_cast<ctkNonLinearControlPoint*>(startCP))
+    if (this->transferFunction()->isDiscrete())
+      {
+      QPointF nextPos = this->mapPointToScene(nextCP);
+      qreal midPosX = (startPos.x() + nextPos.x()) / 2.;
+      
+      d->Path.lineTo(QPointF(midPosX, startPos.y()));
+      d->Path.lineTo(QPointF(midPosX, nextPos.y()));
+      
+      d->Points << nextPos;
+      startPos = nextPos;
+      if (i == count -1)
+        {
+        d->Path.lineTo(nextPos);
+        }
+      }
+    else if (dynamic_cast<ctkNonLinearControlPoint*>(startCP))
       {
       QList<ctkPoint> points = this->nonLinearPoints(startCP, nextCP);
       int j;

+ 182 - 169
Libs/Widgets/ctkTransferFunctionWidget.cpp

@@ -1,170 +1,183 @@
-/*=========================================================================
-
-  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 <QDebug>
-//#include <QGLWidget>
-#include <QGraphicsScene>
-#include <QResizeEvent>
-
-/// CTK includes
-#include "ctkTransferFunction.h"
-#include "ctkTransferFunctionWidget.h"
-#include "ctkTransferFunctionScene.h"
-#include "ctkTransferFunctionGradientItem.h"
-#include "ctkTransferFunctionControlPointsItem.h"
-
-//-----------------------------------------------------------------------------
-class ctkTransferFunctionWidgetPrivate: public ctkPrivate<ctkTransferFunctionWidget>
-{
-  CTK_DECLARE_PUBLIC(ctkTransferFunctionWidget);
-public:
-  ctkTransferFunctionWidgetPrivate();
-  void init();
-  ctkTransferFunction* TransferFunction;
-};
-
-//-----------------------------------------------------------------------------
-ctkTransferFunctionWidgetPrivate::ctkTransferFunctionWidgetPrivate()
-{
-  this->TransferFunction = 0;
-}
-
-//-----------------------------------------------------------------------------
-void ctkTransferFunctionWidgetPrivate::init()
-{
-  CTK_P(ctkTransferFunctionWidget);
-  p->setScene(new ctkTransferFunctionScene(p));
-  p->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-  p->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-  //p->setViewport(new QGLWidget);
-  p->setRenderHint(QPainter::Antialiasing);
-}
-
-//-----------------------------------------------------------------------------
-ctkTransferFunctionWidget::ctkTransferFunctionWidget(QWidget* parentWidget)
-  :QGraphicsView(parentWidget)
-{
-  CTK_INIT_PRIVATE(ctkTransferFunctionWidget);
-  ctk_d()->init();
-}
-
-//-----------------------------------------------------------------------------
-ctkTransferFunctionWidget::ctkTransferFunctionWidget(
-  ctkTransferFunction* transferFunction, QWidget* parentWidget)
-  :QGraphicsView(parentWidget)
-{
-  CTK_INIT_PRIVATE(ctkTransferFunctionWidget);
-  ctk_d()->init();
-  this->setTransferFunction(transferFunction);
-}
-//-----------------------------------------------------------------------------
-ctkTransferFunctionWidget::~ctkTransferFunctionWidget()
-{
-}
-
-//-----------------------------------------------------------------------------
-void ctkTransferFunctionWidget::setTransferFunction(ctkTransferFunction* transferFunction)
-{
-  CTK_D(ctkTransferFunctionWidget);
-  d->TransferFunction = transferFunction;
-  ctkTransferFunctionScene* tfScene = dynamic_cast<ctkTransferFunctionScene*>(this->scene());
-  Q_ASSERT(tfScene);
-  tfScene->clear();
-  tfScene->setTransferFunction(transferFunction);
-
-  bool useMask = true;
-  ctkTransferFunctionGradientItem* gradient = 
-    new ctkTransferFunctionGradientItem(transferFunction);
-  //gradient->setRect(tfScene->sceneRect());
-  this->scene()->addItem(gradient);
-
-  ctkTransferFunctionControlPointsItem* controlPoints = 
-    new ctkTransferFunctionControlPointsItem(transferFunction);
-  //controlPoints->setRect(tfScene->sceneRect());
-  this->scene()->addItem(controlPoints);
-}
-
-//-----------------------------------------------------------------------------
-ctkTransferFunction* ctkTransferFunctionWidget::transferFunction()const
-{
-  return ctk_d()->TransferFunction;
-}
-
-//-----------------------------------------------------------------------------
-void ctkTransferFunctionWidget::resizeEvent(QResizeEvent * event)
-{
-  /*
-  QRectF sceneRect(QPointF(0,0),event->size());
-  this->scene()->setSceneRect(sceneRect);
-  foreach(QGraphicsItem * item, this->scene()->items())
-    {
-    ctkTransferFunctionItem* rectItem = 
-      qgraphicsitem_cast<ctkTransferFunctionItem*>(item);
-    if (rectItem)
-      {
-      rectItem->setRect(sceneRect);
-      }
-    }
-  */
+/*=========================================================================
+
+  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 <QDebug>
+//#include <QGLWidget>
+#include <QGraphicsScene>
+#include <QResizeEvent>
+
+/// CTK includes
+#include "ctkHistogram.h"
+#include "ctkTransferFunction.h"
+#include "ctkTransferFunctionWidget.h"
+#include "ctkTransferFunctionScene.h"
+#include "ctkTransferFunctionGradientItem.h"
+#include "ctkTransferFunctionControlPointsItem.h"
+#include "ctkTransferFunctionHistogramItem.h"
+
+//-----------------------------------------------------------------------------
+class ctkTransferFunctionWidgetPrivate: public ctkPrivate<ctkTransferFunctionWidget>
+{
+  CTK_DECLARE_PUBLIC(ctkTransferFunctionWidget);
+public:
+  ctkTransferFunctionWidgetPrivate();
+  void init();
+  ctkTransferFunction* TransferFunction;
+};
+
+//-----------------------------------------------------------------------------
+ctkTransferFunctionWidgetPrivate::ctkTransferFunctionWidgetPrivate()
+{
+  this->TransferFunction = 0;
+}
+
+//-----------------------------------------------------------------------------
+void ctkTransferFunctionWidgetPrivate::init()
+{
+  CTK_P(ctkTransferFunctionWidget);
+  p->setScene(new ctkTransferFunctionScene(p));
+  p->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+  p->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+  //p->setViewport(new QGLWidget);
+  p->setRenderHint(QPainter::Antialiasing);
+}
+
+//-----------------------------------------------------------------------------
+ctkTransferFunctionWidget::ctkTransferFunctionWidget(QWidget* parentWidget)
+  :QGraphicsView(parentWidget)
+{
+  CTK_INIT_PRIVATE(ctkTransferFunctionWidget);
+  ctk_d()->init();
+}
+
+//-----------------------------------------------------------------------------
+ctkTransferFunctionWidget::ctkTransferFunctionWidget(
+  ctkTransferFunction* transferFunction, QWidget* parentWidget)
+  :QGraphicsView(parentWidget)
+{
+  CTK_INIT_PRIVATE(ctkTransferFunctionWidget);
+  ctk_d()->init();
+  this->setTransferFunction(transferFunction);
+}
+//-----------------------------------------------------------------------------
+ctkTransferFunctionWidget::~ctkTransferFunctionWidget()
+{
+}
+
+//-----------------------------------------------------------------------------
+void ctkTransferFunctionWidget::setTransferFunction(ctkTransferFunction* transferFunction)
+{
+  CTK_D(ctkTransferFunctionWidget);
+  d->TransferFunction = transferFunction;
+  ctkTransferFunctionScene* tfScene = dynamic_cast<ctkTransferFunctionScene*>(this->scene());
+  Q_ASSERT(tfScene);
+  tfScene->clear();
+  tfScene->setTransferFunction(transferFunction);
+
+  ctkTransferFunctionGradientItem* gradient = 
+    new ctkTransferFunctionGradientItem(transferFunction);
+  gradient->setRect(tfScene->sceneRect());
+  this->scene()->addItem(gradient);
+
+  if (qobject_cast<ctkHistogram*>(transferFunction) != 0)
+    {
+    gradient->setMask(false);
+    ctkHistogram* histogram = qobject_cast<ctkHistogram*>(transferFunction);
+    ctkTransferFunctionHistogramItem* histogramItem = 
+      new ctkTransferFunctionHistogramItem(histogram);
+    //controlPoints->setRect(tfScene->sceneRect());
+    this->scene()->addItem(histogramItem);
+    }
+  else
+    {
+    ctkTransferFunctionControlPointsItem* controlPoints = 
+      new ctkTransferFunctionControlPointsItem(transferFunction);
+    //controlPoints->setRect(tfScene->sceneRect());
+    this->scene()->addItem(controlPoints);
+    } 
+}
+
+//-----------------------------------------------------------------------------
+ctkTransferFunction* ctkTransferFunctionWidget::transferFunction()const
+{
+  return ctk_d()->TransferFunction;
+}
+
+//-----------------------------------------------------------------------------
+void ctkTransferFunctionWidget::resizeEvent(QResizeEvent * event)
+{
+  /*
+  QRectF sceneRect(QPointF(0,0),event->size());
+  this->scene()->setSceneRect(sceneRect);
+  foreach(QGraphicsItem * item, this->scene()->items())
+    {
+    ctkTransferFunctionItem* rectItem = 
+      qgraphicsitem_cast<ctkTransferFunctionItem*>(item);
+    if (rectItem)
+      {
+      rectItem->setRect(sceneRect);
+      }
+    }
+  */
   QMatrix zoomMatrix;
-  zoomMatrix.scale(event->size().width(), event->size().height());
-  bool blocked = this->blockSignals(true);
-  this->setMatrix(zoomMatrix);
-  this->blockSignals(blocked);
-  this->QGraphicsView::resizeEvent(event);
-  // Control points are resized by the view transform, we want
-  // fixed size control points, lines...
-  //this->fitInView(this->scene()->sceneRect());
-  qDebug() << "resize event caught";
-}
-/*
-//-----------------------------------------------------------------------------
-void ctkTransferFunctionWidget::dragEnterEvent ( QDragEnterEvent * event )
-{
-  qDebug() << "drag event caught";
-
-  this->QGraphicsView::dragEnterEvent(event);
-
-}
-
-//-----------------------------------------------------------------------------
-void ctkTransferFunctionWidget::mousePressEvent ( QMouseEvent * event )
-{
-  qDebug() << "press event caught";
-  //One control point is added to the scene
-  // 1 - get position of the mouse
-  qDebug() << "x position " << event->x();
-  qDebug() << "y position " << event->y();
-
-  this->scene()->items()[1]->;
-
-  // 2nd item are the control points
-
-  this->QGraphicsView::mousePressEvent(event);
-}
-
-//-----------------------------------------------------------------------------
-void ctkTransferFunctionWidget::mouseReleaseEvent ( QMouseEvent * event )
-{
-  qDebug() << "release event caught";
-
-  this->QGraphicsView::mouseReleaseEvent(event);
-}
-*/
+  zoomMatrix.scale(event->size().width(), event->size().height());
+  bool blocked = this->blockSignals(true);
+  this->setMatrix(zoomMatrix);
+  this->blockSignals(blocked);
+  this->QGraphicsView::resizeEvent(event);
+  // Control points are resized by the view transform, we want
+  // fixed size control points, lines...
+  //this->fitInView(this->scene()->sceneRect());
+  qDebug() << "resize event caught";
+}
+/*
+//-----------------------------------------------------------------------------
+void ctkTransferFunctionWidget::dragEnterEvent ( QDragEnterEvent * event )
+{
+  qDebug() << "drag event caught";
+
+  this->QGraphicsView::dragEnterEvent(event);
+
+}
+
+//-----------------------------------------------------------------------------
+void ctkTransferFunctionWidget::mousePressEvent ( QMouseEvent * event )
+{
+  qDebug() << "press event caught";
+  //One control point is added to the scene
+  // 1 - get position of the mouse
+  qDebug() << "x position " << event->x();
+  qDebug() << "y position " << event->y();
+
+  this->scene()->items()[1]->;
+
+  // 2nd item are the control points
+
+  this->QGraphicsView::mousePressEvent(event);
+}
+
+//-----------------------------------------------------------------------------
+void ctkTransferFunctionWidget::mouseReleaseEvent ( QMouseEvent * event )
+{
+  qDebug() << "release event caught";
+
+  this->QGraphicsView::mouseReleaseEvent(event);
+}
+*/