| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 | 
							- /*=========================================================================
 
-   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 <QDebug>
 
- // CTK includes
 
- #include "ctkLogger.h"
 
- #include "ctkVTKScalarsToColorsView.h"
 
- #include "ctkVTKScalarsToColorsWidget.h"
 
- #include "ui_ctkVTKScalarsToColorsWidget.h"
 
- // VTK includes
 
- #include <vtkAxis.h>
 
- #include <vtkChartXY.h>
 
- #include <vtkColorTransferControlPointsItem.h>
 
- #include <vtkColorTransferFunction.h>
 
- #include <vtkColorTransferFunctionItem.h>
 
- #include <vtkCompositeControlPointsItem.h>
 
- #include <vtkCompositeTransferFunctionItem.h>
 
- #include <vtkContextScene.h>
 
- #include <vtkLookupTable.h>
 
- #include <vtkLookupTableItem.h>
 
- #include <vtkPiecewiseControlPointsItem.h>
 
- #include <vtkPiecewiseFunction.h>
 
- #include <vtkPiecewiseFunctionItem.h>
 
- //----------------------------------------------------------------------------
 
- static ctkLogger logger("org.commontk.visualization.vtk.widgets.ctkVTKScalarsToColorsWidget");
 
- //----------------------------------------------------------------------------
 
- class ctkVTKScalarsToColorsWidgetPrivate:
 
-   public Ui_ctkVTKScalarsToColorsWidget
 
- {
 
-    Q_DECLARE_PUBLIC(ctkVTKScalarsToColorsWidget);
 
- protected:
 
-   ctkVTKScalarsToColorsWidget* const q_ptr;
 
- public:
 
-   ctkVTKScalarsToColorsWidgetPrivate(ctkVTKScalarsToColorsWidget& object);
 
-   void setupUi(QWidget* widget);
 
-   vtkControlPointsItem* CurrentControlPointsItem;
 
- };
 
- // ----------------------------------------------------------------------------
 
- // ctkVTKScalarsToColorsWidgetPrivate methods
 
- // ----------------------------------------------------------------------------
 
- ctkVTKScalarsToColorsWidgetPrivate::ctkVTKScalarsToColorsWidgetPrivate(
 
-   ctkVTKScalarsToColorsWidget& object)
 
-   : q_ptr(&object)
 
- {
 
-   this->CurrentControlPointsItem = 0;
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidgetPrivate::setupUi(QWidget* widget)
 
- {
 
-   Q_Q(ctkVTKScalarsToColorsWidget);
 
-   this->Ui_ctkVTKScalarsToColorsWidget::setupUi(widget);
 
-   QObject::connect(this->View, SIGNAL(plotAdded(vtkPlot*)),
 
-                    q, SLOT(onPlotAdded(vtkPlot*)));
 
-   QObject::connect(this->View, SIGNAL(boundsChanged()),
 
-                    q, SLOT(onBoundsChanged()));
 
-   this->PointIdSpinBox->setSpecialValueText("None");
 
-   QObject::connect(this->PointIdSpinBox, SIGNAL(valueChanged(int)),
 
-                    q, SLOT(onCurrentPointChanged(int)));
 
-   this->PointIdSpinBox->setValue(-1);
 
-   QObject::connect(this->ColorPickerButton, SIGNAL(colorChanged(const QColor&)),
 
-                    q, SLOT(onColorChanged(const QColor&)));
 
-   QObject::connect(this->OpacitySpinBox, SIGNAL(valueChanged(double)),
 
-                    q, SLOT(onOpacityChanged(double)));
 
-   QObject::connect(this->MidPointSpinBox, SIGNAL(valueChanged(double)),
 
-                    q, SLOT(onMidPointChanged(double)));
 
-   QObject::connect(this->SharpnessSpinBox, SIGNAL(valueChanged(double)),
 
-                    q, SLOT(onSharpnessChanged(double)));
 
-   this->ColorPickerButton->setVisible(false);
 
-   this->OpacityLabel->setVisible(false);
 
-   this->OpacitySpinBox->setVisible(false);
 
-   QObject::connect(this->XRangeSlider, SIGNAL(valuesChanged(double, double)),
 
-                    q, SLOT(onXRangeChanged(double, double)));
 
-   QObject::connect(this->YRangeSlider, SIGNAL(valuesChanged(double, double)),
 
-                    q, SLOT(onYRangeChanged(double, double)));
 
-   q->qvtkConnect(this->View->chart()->GetAxis(0),vtkCommand::ModifiedEvent,
 
-                     q, SLOT(onAxesModified()));
 
-   q->qvtkConnect(this->View->chart()->GetAxis(1),vtkCommand::ModifiedEvent,
 
-                     q, SLOT(onAxesModified()));
 
- }
 
- // ----------------------------------------------------------------------------
 
- // ctkVTKScalarsToColorsWidget methods
 
- // ----------------------------------------------------------------------------
 
- ctkVTKScalarsToColorsWidget::ctkVTKScalarsToColorsWidget(QWidget* parentWidget)
 
-   :QWidget(parentWidget)
 
-    , d_ptr(new ctkVTKScalarsToColorsWidgetPrivate(*this))
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   d->setupUi(this);
 
- }
 
- // ----------------------------------------------------------------------------
 
- ctkVTKScalarsToColorsWidget::~ctkVTKScalarsToColorsWidget()
 
- {
 
- }
 
- // ----------------------------------------------------------------------------
 
- ctkVTKScalarsToColorsView* ctkVTKScalarsToColorsWidget::view()const
 
- {
 
-   Q_D(const ctkVTKScalarsToColorsWidget);
 
-   return d->View;
 
- }
 
- // ----------------------------------------------------------------------------
 
- bool ctkVTKScalarsToColorsWidget::isHorizontalSliderVisible()const
 
- {
 
-   Q_D(const ctkVTKScalarsToColorsWidget);
 
-   return d->XRangeSlider->isVisibleTo(
 
-     const_cast<ctkVTKScalarsToColorsWidget*>(this));
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::setHorizontalSliderVisible(bool visible)
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   d->XRangeSlider->setVisible(visible);
 
- }
 
- // ----------------------------------------------------------------------------
 
- bool ctkVTKScalarsToColorsWidget::isVerticalSliderVisible()const
 
- {
 
-   Q_D(const ctkVTKScalarsToColorsWidget);
 
-   return d->YRangeSlider->isVisibleTo(
 
-     const_cast<ctkVTKScalarsToColorsWidget*>(this));
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::setVerticalSliderVisible(bool visible)
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   d->YRangeSlider->setVisible(visible);
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::onPlotAdded(vtkPlot* plot)
 
- {
 
-   if (vtkControlPointsItem::SafeDownCast(plot))
 
-     {
 
-     this->qvtkConnect(plot, vtkControlPointsItem::CurrentPointChangedEvent,
 
-                       this, SLOT(setCurrentPoint(vtkObject*, void*)));
 
-     }
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::onBoundsChanged()
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   double bounds[8];
 
-   d->View->chartBounds(bounds);
 
-   d->XRangeSlider->setMinimum(bounds[vtkAxis::BOTTOM * 2]);
 
-   d->XRangeSlider->setMaximum(bounds[vtkAxis::BOTTOM * 2 + 1]);
 
-   d->YRangeSlider->setMinimum(bounds[vtkAxis::LEFT * 2]);
 
-   d->YRangeSlider->setMaximum(bounds[vtkAxis::LEFT * 2 + 1]);
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::setCurrentPoint(vtkObject* caller, void* callData)
 
- {
 
-   vtkControlPointsItem* controlPoints = reinterpret_cast<vtkControlPointsItem*>(caller);
 
-   long newPoint = reinterpret_cast<long>(callData);
 
-   if (!controlPoints || newPoint < -1)
 
-     {
 
-     return;
 
-     }
 
-   this->setCurrentControlPointsItem(controlPoints);
 
-   this->setCurrentPoint(newPoint);
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::setCurrentPoint(int newPoint)
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   d->PointIdSpinBox->setValue(newPoint);
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::setCurrentControlPointsItem(vtkControlPointsItem* item)
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   if (d->CurrentControlPointsItem == item)
 
-     {
 
-     return;
 
-     }
 
-   this->qvtkReconnect(d->CurrentControlPointsItem, item, vtkCommand::ModifiedEvent,
 
-                       this, SLOT(updateCurrentPoint()));
 
-   this->qvtkReconnect(d->CurrentControlPointsItem ?
 
-                       d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(0),
 
-                       item ? item->GetXAxis() : d->View->chart()->GetAxis(0),
 
-                       vtkCommand::ModifiedEvent,
 
-                       this, SLOT(onAxesModified()));
 
-   this->qvtkReconnect(d->CurrentControlPointsItem ?
 
-                       d->CurrentControlPointsItem->GetYAxis() : d->View->chart()->GetAxis(1),
 
-                       item ? item->GetYAxis() : d->View->chart()->GetAxis(1),
 
-                       vtkCommand::ModifiedEvent,
 
-                       this, SLOT(onAxesModified()));
 
-   d->CurrentControlPointsItem = item;
 
-   if (item)
 
-     {
 
-     d->ColorPickerButton->setVisible(
 
-       vtkColorTransferControlPointsItem::SafeDownCast(item) != 0 ||
 
-       vtkCompositeControlPointsItem::SafeDownCast(item) != 0);
 
-     d->OpacityLabel->setVisible(vtkPiecewiseControlPointsItem::SafeDownCast(item) != 0 ||
 
-                                 vtkCompositeControlPointsItem::SafeDownCast(item) != 0);
 
-     d->OpacitySpinBox->setVisible(vtkPiecewiseControlPointsItem::SafeDownCast(item) != 0 ||
 
-                                   vtkCompositeControlPointsItem::SafeDownCast(item) != 0);
 
-     this->onAxesModified();
 
-     }
 
-   d->PointIdSpinBox->setEnabled(item != 0);
 
-   d->PointIdSpinBox->setMaximum((item ? item->GetNumberOfPoints() : 0) - 1);
 
-   d->PointIdSpinBox->setValue(item ? item->GetCurrentPoint() : -1);
 
-   this->updateCurrentPoint();
 
- }
 
- // ----------------------------------------------------------------------------
 
- vtkControlPointsItem* ctkVTKScalarsToColorsWidget::currentControlPointsItem()const
 
- {
 
-   Q_D(const ctkVTKScalarsToColorsWidget);
 
-   return d->CurrentControlPointsItem;
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::onCurrentPointChanged(int currentPoint)
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   if (d->CurrentControlPointsItem)
 
-     {
 
-     d->CurrentControlPointsItem->SetCurrentPoint(currentPoint);
 
-     }
 
-   d->ColorPickerButton->setEnabled(currentPoint != -1);
 
-   d->OpacitySpinBox->setEnabled(currentPoint != -1);
 
-   d->MidPointSpinBox->setEnabled(currentPoint != -1);
 
-   d->SharpnessSpinBox->setEnabled(currentPoint != -1);
 
-   if (d->CurrentControlPointsItem)
 
-     {
 
-     this->updateCurrentPoint();
 
-     }
 
- }
 
- // ----------------------------------------------------------------------------
 
- 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)
 
-     {
 
-     return;
 
-     }
 
-   double point[4];
 
-   d->CurrentControlPointsItem->GetControlPoint(pointId, point);
 
-   d->OpacitySpinBox->setValue(point[1]);
 
-   d->MidPointSpinBox->setValue(point[2]);
 
-   d->SharpnessSpinBox->setValue(point[3]);
 
-   vtkColorTransferControlPointsItem* colorControlPoints =
 
-     vtkColorTransferControlPointsItem::SafeDownCast(d->CurrentControlPointsItem);
 
-   if (colorControlPoints)
 
-     {
 
-     vtkColorTransferFunction* colorTF =
 
-       colorControlPoints->GetColorTransferFunction();
 
-     double xrgbms[6];
 
-     colorTF->GetNodeValue(d->PointIdSpinBox->value(), xrgbms);
 
-     QColor color = QColor::fromRgbF(xrgbms[1], xrgbms[2], xrgbms[3]);
 
-     d->ColorPickerButton->setColor(color);
 
-     }
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::onColorChanged(const QColor& color)
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   if (!color.isValid())
 
-     {
 
-     return;
 
-     }
 
-   Q_ASSERT(d->CurrentControlPointsItem);
 
-   Q_ASSERT(d->PointIdSpinBox->value() != -1);
 
-   Q_ASSERT(d->PointIdSpinBox->value() == d->CurrentControlPointsItem->GetCurrentPoint());
 
-   vtkColorTransferControlPointsItem* colorControlPoints =
 
-     vtkColorTransferControlPointsItem::SafeDownCast(d->CurrentControlPointsItem);
 
-   if (colorControlPoints)
 
-     {
 
-     vtkColorTransferFunction* colorTF =
 
-       colorControlPoints->GetColorTransferFunction();
 
-     double point[6];
 
-     colorTF->GetNodeValue(d->PointIdSpinBox->value(), point);
 
-     point[1] = color.redF();
 
-     point[2] = color.greenF();
 
-     point[3] = color.blueF();
 
-     colorTF->SetNodeValue(d->PointIdSpinBox->value(), point);
 
-     }
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::onOpacityChanged(double opacity)
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   Q_ASSERT(d->CurrentControlPointsItem);
 
-   double point[4];
 
-   d->CurrentControlPointsItem->GetControlPoint(d->PointIdSpinBox->value(), point);
 
-   point[1] = opacity;
 
-   d->CurrentControlPointsItem->SetControlPoint(d->PointIdSpinBox->value(), point);
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::onMidPointChanged(double midPoint)
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   Q_ASSERT(d->CurrentControlPointsItem);
 
-   double point[4];
 
-   d->CurrentControlPointsItem->GetControlPoint(d->PointIdSpinBox->value(), point);
 
-   point[2] = midPoint;
 
-   d->CurrentControlPointsItem->SetControlPoint(d->PointIdSpinBox->value(), point);
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::onSharpnessChanged(double sharpness)
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   Q_ASSERT(d->CurrentControlPointsItem);
 
-   double point[4];
 
-   d->CurrentControlPointsItem->GetControlPoint(d->PointIdSpinBox->value(), point);
 
-   point[3] = sharpness;
 
-   d->CurrentControlPointsItem->SetControlPoint(d->PointIdSpinBox->value(), point);
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::onXRangeChanged(double min, double max)
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   vtkAxis* xAxis = d->CurrentControlPointsItem ?
 
-     d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(vtkAxis::BOTTOM);
 
-   Q_ASSERT(xAxis);
 
-   xAxis->SetRange(min, max);
 
-   d->View->scene()->SetDirty(true);
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::onYRangeChanged(double min, double max)
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   vtkAxis* yAxis = d->CurrentControlPointsItem ?
 
-     d->CurrentControlPointsItem->GetYAxis() : d->View->chart()->GetAxis(vtkAxis::LEFT);
 
-   Q_ASSERT(yAxis);
 
-   yAxis->SetRange(min, max);
 
-   d->View->scene()->SetDirty(true);
 
- }
 
- // ----------------------------------------------------------------------------
 
- void ctkVTKScalarsToColorsWidget::onAxesModified()
 
- {
 
-   Q_D(ctkVTKScalarsToColorsWidget);
 
-   vtkAxis* xAxis = d->CurrentControlPointsItem ?
 
-     d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(vtkAxis::BOTTOM);
 
-   Q_ASSERT(xAxis);
 
-   d->XRangeSlider->setValues(xAxis->GetMinimum(), xAxis->GetMaximum());
 
-   vtkAxis* yAxis = d->CurrentControlPointsItem ?
 
-     d->CurrentControlPointsItem->GetYAxis() : d->View->chart()->GetAxis(vtkAxis::LEFT);
 
-   Q_ASSERT(yAxis);
 
-   d->YRangeSlider->setValues(yAxis->GetMinimum(), yAxis->GetMaximum());
 
- }
 
 
  |