Skip to content

Commit

Permalink
ENH: Remove use of chart() in ctkVTKScalarsToColorsView/Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
spyridon97 authored and jcfr committed Oct 27, 2023
1 parent 60c3790 commit 0c80e70
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ int ctkVTKScalarsToColorsViewTest2(int argc, char * argv [] )
ctkVTKScalarsToColorsView view(0);
// add transfer function item
vtkPlot* ctfPlot = view.addColorTransferFunction(ctf);
view.chart()->SetPlotCorner(ctfPlot, 1);
view.chartXY()->SetPlotCorner(ctfPlot, 1);
ctfPlot->SetOpacity(0.7);
// add histogram item
view.addPlot(histogramPlot);
view.chart()->SetBarWidthFraction(1.);
view.chartXY()->SetBarWidthFraction(1.);
view.setAxesToChartBounds();
view.show();

Expand Down
19 changes: 12 additions & 7 deletions Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

// VTK includes
#include <vtkAxis.h>
#include <vtkChart.h>
#include <vtkChartXY.h>
#include <vtkColorTransferControlPointsItem.h>
#include <vtkColorTransferFunction.h>
Expand Down Expand Up @@ -75,9 +76,12 @@ ctkVTKScalarsToColorsViewPrivate::ctkVTKScalarsToColorsViewPrivate(ctkVTKScalars
void ctkVTKScalarsToColorsViewPrivate::init()
{
Q_Q(ctkVTKScalarsToColorsView);
vtkChartXY* chart = q->chart();
chart->SetAutoAxes(false);
chart->SetHiddenAxisBorder(0);
vtkChartXY* chart = q->chartXY();
if (chart)
{
chart->SetAutoAxes(false);
chart->SetHiddenAxisBorder(0);
}
this->showBorders(true);
QObject::connect(q, SIGNAL(boundsChanged()), q, SLOT(onBoundsChanged()));
q->onChartUpdated();
Expand All @@ -87,7 +91,7 @@ void ctkVTKScalarsToColorsViewPrivate::init()
void ctkVTKScalarsToColorsViewPrivate::showBorders(bool visible)
{
Q_Q(ctkVTKScalarsToColorsView);
vtkChartXY* chart = q->chart();
vtkChart* chart = q->abstractChart();
for (int i = 0; i < 4; ++i)
{
chart->GetAxis(i)->SetVisible(true);
Expand Down Expand Up @@ -283,10 +287,11 @@ ::addPiecewiseFunctionControlPoints(vtkPiecewiseFunction* piecewiseTF)
QList<vtkPlot*> ctkVTKScalarsToColorsView::plots()const
{
QList<vtkPlot*> res;
const vtkIdType count = this->chart()->GetNumberOfPlots();
vtkChart* chart = this->abstractChart();
const vtkIdType count = chart->GetNumberOfPlots();
for(vtkIdType i = 0; i < count; ++i)
{
res << this->chart()->GetPlot(i);
res << chart->GetPlot(i);
}
return res;
}
Expand Down Expand Up @@ -506,7 +511,7 @@ ::setPiecewiseFunctionToPlots(vtkPiecewiseFunction* piecewiseTF)
bool ctkVTKScalarsToColorsView
::areBordersVisible()const
{
return this->chart()->GetAxis(0)->GetVisible();
return this->abstractChart()->GetAxis(0)->GetVisible();
}

// ----------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ template<class T>
QList<T*> ctkVTKScalarsToColorsView::plots()const
{
QList<T*> res;
const vtkIdType count = this->chart()->GetNumberOfPlots();
vtkChart* chart = this->abstractChart();
const vtkIdType count = chart->GetNumberOfPlots();
for(vtkIdType i = 0; i < count; ++i)
{
vtkPlot* plot = this->chart()->GetPlot(i);
vtkPlot* plot = chart->GetPlot(i);
if (T::SafeDownCast(plot) != 0)
{
res << T::SafeDownCast(plot);
Expand Down
28 changes: 15 additions & 13 deletions Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

// VTK includes
#include <vtkAxis.h>
#include <vtkChart.h>
#include <vtkChartXY.h>
#include <vtkColorTransferControlPointsItem.h>
#include <vtkColorTransferFunction.h>
Expand Down Expand Up @@ -333,14 +334,15 @@ void ctkVTKScalarsToColorsWidget::setCurrentControlPointsItem(vtkControlPointsIt
}
this->qvtkReconnect(d->CurrentControlPointsItem, item, vtkCommand::ModifiedEvent,
this, SLOT(updateCurrentPoint()));
vtkChart* chart = d->View->abstractChart();
this->qvtkReconnect(d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(0),
item ? item->GetXAxis() : d->View->chart()->GetAxis(0),
d->CurrentControlPointsItem->GetXAxis() : chart->GetAxis(0),
item ? item->GetXAxis() : 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),
d->CurrentControlPointsItem->GetYAxis() : chart->GetAxis(1),
item ? item->GetYAxis() : chart->GetAxis(1),
vtkCommand::ModifiedEvent,
this, SLOT(onAxesModified()));
d->CurrentControlPointsItem = item;
Expand Down Expand Up @@ -420,7 +422,7 @@ void ctkVTKScalarsToColorsWidget::updateCurrentPoint()
d->CurrentControlPointsItem->GetControlPoint(pointId, point);

vtkAxis* xAxis = d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(vtkAxis::BOTTOM);
d->CurrentControlPointsItem->GetXAxis() : d->View->abstractChart()->GetAxis(vtkAxis::BOTTOM);
Q_ASSERT(xAxis);
if (xAxis && (xAxis->GetMinimumLimit() > point[0] || xAxis->GetMaximumLimit() < point[0]))
{
Expand Down Expand Up @@ -544,7 +546,7 @@ void ctkVTKScalarsToColorsWidget::xRange(double* range)const
{
Q_D(const ctkVTKScalarsToColorsWidget);
vtkAxis* xAxis = d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(vtkAxis::BOTTOM);
d->CurrentControlPointsItem->GetXAxis() : d->View->abstractChart()->GetAxis(vtkAxis::BOTTOM);
Q_ASSERT(xAxis);
range[0] = xAxis->GetMinimum();
range[1] = xAxis->GetMaximum();
Expand All @@ -555,7 +557,7 @@ void ctkVTKScalarsToColorsWidget::setXRange(double min, double max)
{
Q_D(ctkVTKScalarsToColorsWidget);
vtkAxis* xAxis = d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(vtkAxis::BOTTOM);
d->CurrentControlPointsItem->GetXAxis() : d->View->abstractChart()->GetAxis(vtkAxis::BOTTOM);
Q_ASSERT(xAxis);
if (xAxis->GetMinimum() != min || xAxis->GetMaximum() != max)
{
Expand All @@ -570,7 +572,7 @@ void ctkVTKScalarsToColorsWidget::yRange(double* range)const
{
Q_D(const ctkVTKScalarsToColorsWidget);
vtkAxis* yAxis = d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetYAxis() : d->View->chart()->GetAxis(vtkAxis::LEFT);
d->CurrentControlPointsItem->GetYAxis() : d->View->abstractChart()->GetAxis(vtkAxis::LEFT);
Q_ASSERT(yAxis);
range[0] = yAxis->GetMinimum();
range[1] = yAxis->GetMaximum();
Expand All @@ -581,7 +583,7 @@ void ctkVTKScalarsToColorsWidget::setYRange(double min, double max)
{
Q_D(ctkVTKScalarsToColorsWidget);
vtkAxis* yAxis = d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetYAxis() : d->View->chart()->GetAxis(vtkAxis::LEFT);
d->CurrentControlPointsItem->GetYAxis() : d->View->abstractChart()->GetAxis(vtkAxis::LEFT);
Q_ASSERT(yAxis);
if (yAxis->GetMinimum() != min || yAxis->GetMaximum() != max)
{
Expand All @@ -596,14 +598,14 @@ void ctkVTKScalarsToColorsWidget::resetRange()
{
Q_D(ctkVTKScalarsToColorsWidget);
vtkAxis* xAxis = d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(vtkAxis::BOTTOM);
d->CurrentControlPointsItem->GetXAxis() : d->View->abstractChart()->GetAxis(vtkAxis::BOTTOM);
if (xAxis)
{
this->setXRange(xAxis->GetMinimumLimit(), xAxis->GetMaximumLimit());
}

vtkAxis* yAxis = d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetYAxis() : d->View->chart()->GetAxis(vtkAxis::LEFT);
d->CurrentControlPointsItem->GetYAxis() : d->View->abstractChart()->GetAxis(vtkAxis::LEFT);
if (yAxis)
{
this->setYRange(yAxis->GetMinimumLimit(), yAxis->GetMaximumLimit());
Expand All @@ -615,7 +617,7 @@ void ctkVTKScalarsToColorsWidget::onAxesModified()
{
Q_D(ctkVTKScalarsToColorsWidget);
vtkAxis* xAxis = d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(vtkAxis::BOTTOM);
d->CurrentControlPointsItem->GetXAxis() : d->View->abstractChart()->GetAxis(vtkAxis::BOTTOM);
Q_ASSERT(xAxis);

bool wasBlocking = d->XRangeSlider->blockSignals(true);
Expand All @@ -627,7 +629,7 @@ void ctkVTKScalarsToColorsWidget::onAxesModified()
d->XRangeSlider->blockSignals(wasBlocking);

vtkAxis* yAxis = d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetYAxis() : d->View->chart()->GetAxis(vtkAxis::LEFT);
d->CurrentControlPointsItem->GetYAxis() : d->View->abstractChart()->GetAxis(vtkAxis::LEFT);
Q_ASSERT(yAxis);

wasBlocking = d->YRangeSlider->blockSignals(true);
Expand Down

0 comments on commit 0c80e70

Please sign in to comment.