Commit 65d47800 authored by LE BRETON Come's avatar LE BRETON Come

Provides a way to control the number of isolines.

parent d23218b8
...@@ -50,7 +50,7 @@ public: ...@@ -50,7 +50,7 @@ public:
bool setCurrentFieldName(const QString&); bool setCurrentFieldName(const QString&);
void setCurrentColorTransferFunction(vtkSmartPointer<vtkColorTransferFunction>); void setCurrentColorTransferFunction(vtkSmartPointer<vtkColorTransferFunction>);
void setCurrentOpacityTransferFunction(vtkSmartPointer<vtkPiecewiseFunction>); void setCurrentOpacityTransferFunction(vtkSmartPointer<vtkPiecewiseFunction>);
void setCurrentRange(double min, double max); void setCurrentRange(double, double);
signals: signals:
void currentFieldNameChanged(const QString&); void currentFieldNameChanged(const QString&);
......
...@@ -69,8 +69,11 @@ public: ...@@ -69,8 +69,11 @@ public:
public: public:
vtkSmartPointer<vtkContourFilter> isolines; vtkSmartPointer<vtkContourFilter> isolines;
public:
QHash<QString, QPair<double, double>> isolines_ranges; QHash<QString, QPair<double, double>> isolines_ranges;
// int scalar_iso_count; QHash<QString, std::size_t> isolines_counts;
public: public:
QHash<QString, vtkSmartPointer<vtkColorTransferFunction>> color_transfer_functions; QHash<QString, vtkSmartPointer<vtkColorTransferFunction>> color_transfer_functions;
QHash<QString, vtkSmartPointer<vtkPiecewiseFunction>> opacity_functions; QHash<QString, vtkSmartPointer<vtkPiecewiseFunction>> opacity_functions;
...@@ -154,6 +157,8 @@ void dtkVisualizationDecoratorScalarIsolines::setData(const QVariant& data) ...@@ -154,6 +157,8 @@ void dtkVisualizationDecoratorScalarIsolines::setData(const QVariant& data)
d->opacity_functions.clear(); d->opacity_functions.clear();
d->ranges.clear(); d->ranges.clear();
d->supports.clear(); d->supports.clear();
d->isolines_ranges.clear();
d->isolines_counts.clear();
vtkIdType number_of_point_arrays = d->dataset->GetPointData()->GetNumberOfArrays(); vtkIdType number_of_point_arrays = d->dataset->GetPointData()->GetNumberOfArrays();
for (vtkIdType i = 0; i < number_of_point_arrays; ++i) { for (vtkIdType i = 0; i < number_of_point_arrays; ++i) {
...@@ -182,6 +187,9 @@ void dtkVisualizationDecoratorScalarIsolines::setData(const QVariant& data) ...@@ -182,6 +187,9 @@ void dtkVisualizationDecoratorScalarIsolines::setData(const QVariant& data)
opacity_function->AddPoint(255, 1.); opacity_function->AddPoint(255, 1.);
d->opacity_functions[field_name] = opacity_function; d->opacity_functions[field_name] = opacity_function;
d->isolines_ranges[field_name] = qMakePair(range[0], range[1]);
d->isolines_counts[field_name] = 1;
} }
} }
...@@ -210,6 +218,9 @@ void dtkVisualizationDecoratorScalarIsolines::setData(const QVariant& data) ...@@ -210,6 +218,9 @@ void dtkVisualizationDecoratorScalarIsolines::setData(const QVariant& data)
opacity_function->AddPoint(255, 1.); opacity_function->AddPoint(255, 1.);
d->opacity_functions[field_name] = opacity_function; d->opacity_functions[field_name] = opacity_function;
d->isolines_ranges[field_name] = qMakePair(range[0], range[1]);
d->isolines_counts[field_name] = 1;
} }
} }
...@@ -219,9 +230,7 @@ void dtkVisualizationDecoratorScalarIsolines::setData(const QVariant& data) ...@@ -219,9 +230,7 @@ void dtkVisualizationDecoratorScalarIsolines::setData(const QVariant& data)
} }
d->isolines->SetInputData(d->dataset); d->isolines->SetInputData(d->dataset);
// d->isolines->GenerateValues(d->scalar_iso_count, d->scalar_iso_range[0], d->scalar_iso_range[1]); d->isolines->Modified();
d->isolines->GenerateValues(10, 0, 100);
d->isolines->Update();
d->mapper->Modified(); d->mapper->Modified();
} }
...@@ -246,13 +255,16 @@ void dtkVisualizationDecoratorScalarIsolines::setCanvas(dtkVisualizationCanvas * ...@@ -246,13 +255,16 @@ void dtkVisualizationDecoratorScalarIsolines::setCanvas(dtkVisualizationCanvas *
dtkWidgetsOverlayPane *canvas_pane = canvas->overlay(); dtkWidgetsOverlayPane *canvas_pane = canvas->overlay();
canvas_pane->setBound(500); canvas_pane->setBound(500);
dtkVisualizationWidgetsClutEditor *clut_editor = new dtkVisualizationWidgetsClutEditor; dtkVisualizationWidgetsClutEditor *clut_editor = new dtkVisualizationWidgetsClutEditor;
QSpinBox *isolines_counts_sb = new QSpinBox;
dtkWidgetsOverlayPaneItem *pane_item = new dtkWidgetsOverlayPaneItem; dtkWidgetsOverlayPaneItem *pane_item = new dtkWidgetsOverlayPaneItem;
pane_item->setTitle("Scalar Color Map"); pane_item->setTitle("Scalar Isolines");
pane_item->addWidget(clut_editor); pane_item->addWidget(clut_editor);
canvas_pane->addWidget(pane_item); canvas_pane->addWidget(pane_item);
canvas_pane->addWidget(isolines_counts_sb);
// clut_editor connections
connect(this, &dtkVisualizationDecoratorScalarIsolines::currentRangeChanged, [=] (double min, double max) { connect(this, &dtkVisualizationDecoratorScalarIsolines::currentRangeChanged, [=] (double min, double max) {
clut_editor->blockSignals(true); clut_editor->blockSignals(true);
clut_editor->setRange(min, max); clut_editor->setRange(min, max);
...@@ -270,6 +282,13 @@ void dtkVisualizationDecoratorScalarIsolines::setCanvas(dtkVisualizationCanvas * ...@@ -270,6 +282,13 @@ void dtkVisualizationDecoratorScalarIsolines::setCanvas(dtkVisualizationCanvas *
this->setCurrentColorTransferFunction(reinterpret_cast<vtkColorTransferFunction *>(clut_editor->colorTransferFunction())); this->setCurrentColorTransferFunction(reinterpret_cast<vtkColorTransferFunction *>(clut_editor->colorTransferFunction()));
this->blockSignals(false); this->blockSignals(false);
}); });
// isolines_counts_sb connections
connect(isolines_counts_sb, QOverload<int>::of(&QSpinBox::valueChanged), [=] (int value) {
this->blockSignals(true);
this->setCurrentIsolinesCount(value);
this->blockSignals(false);
});
} }
QStringList dtkVisualizationDecoratorScalarIsolines::eligibleFieldNames(void) QStringList dtkVisualizationDecoratorScalarIsolines::eligibleFieldNames(void)
...@@ -326,6 +345,11 @@ bool dtkVisualizationDecoratorScalarIsolines::setCurrentFieldName(const QString& ...@@ -326,6 +345,11 @@ bool dtkVisualizationDecoratorScalarIsolines::setCurrentFieldName(const QString&
} }
const QPair<double, double>& range = d->ranges[d->current_field_name]; const QPair<double, double>& range = d->ranges[d->current_field_name];
const QPair<double, double>& isolines_range = d->isolines_ranges[d->current_field_name];
std::size_t isolines_count = d->isolines_counts[d->current_field_name];
d->isolines->GenerateValues(isolines_range.first, isolines_range.second, isolines_count);
d->isolines->Modified();
d->mapper->SetLookupTable(d->color_transfer_functions[d->current_field_name]); d->mapper->SetLookupTable(d->color_transfer_functions[d->current_field_name]);
d->mapper->SelectColorArray(qPrintable(d->current_field_name)); d->mapper->SelectColorArray(qPrintable(d->current_field_name));
...@@ -342,6 +366,8 @@ bool dtkVisualizationDecoratorScalarIsolines::setCurrentFieldName(const QString& ...@@ -342,6 +366,8 @@ bool dtkVisualizationDecoratorScalarIsolines::setCurrentFieldName(const QString&
emit this->currentFieldNameChanged(d->current_field_name); emit this->currentFieldNameChanged(d->current_field_name);
emit this->currentColorTransferFunctionChanged(color_function); emit this->currentColorTransferFunctionChanged(color_function);
emit this->currentRangeChanged(range.first, range.second); emit this->currentRangeChanged(range.first, range.second);
emit this->currentIsolinesRangeChanged(isolines_range.first, isolines_range.second);
emit this->currentIsolinesCountChanged(isolines_count);
return true; return true;
} }
...@@ -404,5 +430,49 @@ void dtkVisualizationDecoratorScalarIsolines::setCurrentRange(double min, double ...@@ -404,5 +430,49 @@ void dtkVisualizationDecoratorScalarIsolines::setCurrentRange(double min, double
emit this->currentRangeChanged(min, max); emit this->currentRangeChanged(min, max);
} }
void dtkVisualizationDecoratorScalarIsolines::setCurrentIsolinesRange(double min, double max)
{
if (d->current_field_name.isEmpty()) {
return;
}
d->isolines_ranges[d->current_field_name] = qMakePair(min, max);
d->isolines->SetValue(min, max);
d->isolines->GenerateValues(d->isolines_counts[d->current_field_name], min, max);
d->isolines->Modified();
// d->mapper->SetScalarRange(min, max);
d->mapper->Modified();
d->actor->Modified();
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
}
emit this->currentIsolinesRangeChanged(min, max);
}
void dtkVisualizationDecoratorScalarIsolines::setCurrentIsolinesCount(std::size_t count)
{
if (d->current_field_name.isEmpty()) {
return;
}
QPair<double, double> isoline_range = d->isolines_ranges[d->current_field_name];
d->isolines_counts[d->current_field_name] = count;
d->isolines->GenerateValues(count, isoline_range.first, isoline_range.second);
d->isolines->Modified();
d->mapper->Modified();
d->actor->Modified();
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
}
emit this->currentIsolinesCountChanged(count);
}
// //
// dtkVisualizationDecoratorScalarIsolines.cpp ends here // dtkVisualizationDecoratorScalarIsolines.cpp ends here
...@@ -53,13 +53,17 @@ public: ...@@ -53,13 +53,17 @@ public:
bool setCurrentFieldName(const QString&); bool setCurrentFieldName(const QString&);
void setCurrentColorTransferFunction(vtkSmartPointer<vtkColorTransferFunction>); void setCurrentColorTransferFunction(vtkSmartPointer<vtkColorTransferFunction>);
void setCurrentOpacityTransferFunction(vtkSmartPointer<vtkPiecewiseFunction>); void setCurrentOpacityTransferFunction(vtkSmartPointer<vtkPiecewiseFunction>);
void setCurrentRange(double min, double max); void setCurrentRange(double, double);
void setCurrentIsolinesRange(double, double);
void setCurrentIsolinesCount(std::size_t);
signals: signals:
void currentFieldNameChanged(const QString&); void currentFieldNameChanged(const QString&);
void currentColorTransferFunctionChanged(vtkColorTransferFunction *); void currentColorTransferFunctionChanged(vtkColorTransferFunction *);
void currentOpacityFunctionChanged(vtkPiecewiseFunction *); void currentOpacityFunctionChanged(vtkPiecewiseFunction *);
void currentRangeChanged(double, double); void currentRangeChanged(double, double);
void currentIsolinesRangeChanged(double, double);
void currentIsolinesCountChanged(std::size_t);
protected: protected:
class dtkVisualizationDecoratorScalarIsolinesPrivate *d = nullptr; class dtkVisualizationDecoratorScalarIsolinesPrivate *d = nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment