Commit 90d9427a authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud

Enhance isolines.

parent c2d0d09f
......@@ -57,11 +57,8 @@ public:
public:
QCheckBox *show_actor_cb = nullptr;
QSpinBox *isolines_counts_sb = nullptr;
QDoubleSpinBox *isolines_min_sb = nullptr;
QDoubleSpinBox *isolines_max_sb = nullptr;
public:
QHash<QString, QPair<double, double>> isolines_ranges;
QHash<QString, std::size_t> isolines_counts;
};
......@@ -89,13 +86,14 @@ dtkVisualizationDecoratorScalarIsolines::dtkVisualizationDecoratorScalarIsolines
//////////
// Inspectors creation and setup
d->show_actor_cb = new QCheckBox;
d->show_actor_cb = new QCheckBox;
d->isolines_counts_sb = new QSpinBox;
d->isolines_min_sb = new QDoubleSpinBox;
d->isolines_max_sb = new QDoubleSpinBox;
d->show_actor_cb->setChecked(false);
d->isolines_counts_sb->setValue(10);
d->isolines_counts_sb->setMaximum(10000);
//////////
// Inspectors connections
......@@ -111,47 +109,10 @@ dtkVisualizationDecoratorScalarIsolines::dtkVisualizationDecoratorScalarIsolines
this->touch();
});
connect(this, &dtkVisualizationDecoratorScalarIsolines::currentIsolinesCountChanged, [=] (int value) {
d->isolines_counts_sb->blockSignals(true);
d->isolines_counts_sb->setValue(value);
d->isolines_counts_sb->blockSignals(false);
this->touch();
});
connect(d->isolines_min_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (int value) {
this->blockSignals(true);
this->setCurrentIsolinesRange(value, d->isolines_max_sb->value());
this->blockSignals(false);
this->touch();
});
connect(this, &dtkVisualizationDecoratorScalarIsolines::currentIsolinesRangeChanged, [=] (double min, double max) {
d->isolines_min_sb->blockSignals(true);
d->isolines_min_sb->setValue(min);
this->touch();
d->isolines_min_sb->blockSignals(false);
});
connect(d->isolines_max_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (int value) {
this->blockSignals(true);
this->setCurrentIsolinesRange(d->isolines_min_sb->value(), value);
this->touch();
this->blockSignals(false);
});
connect(this, &dtkVisualizationDecoratorScalarIsolines::currentIsolinesRangeChanged, [=] (double min, double max) {
d->isolines_max_sb->blockSignals(true);
d->isolines_max_sb->setValue(max);
d->isolines_max_sb->blockSignals(false);
this->touch();
});
d->show_actor_cb->setObjectName("Display");
d->isolines_counts_sb->setObjectName("Count");
d->isolines_min_sb->setObjectName("Min");
d->isolines_max_sb->setObjectName("Max");
d_func()->inspectors << d->show_actor_cb << d->isolines_counts_sb << d->isolines_min_sb << d->isolines_max_sb;
d_func()->inspectors << d->show_actor_cb << d->isolines_counts_sb;
}
dtkVisualizationDecoratorScalarIsolines::~dtkVisualizationDecoratorScalarIsolines(void)
......@@ -162,6 +123,23 @@ dtkVisualizationDecoratorScalarIsolines::~dtkVisualizationDecoratorScalarIsoline
d = nullptr;
}
void dtkVisualizationDecoratorScalarIsolines::draw(void)
{
dtkVisualizationDecoratorWithClut::draw();
auto field_name = d_func()->current_field_name;
if (field_name.isEmpty() || !d_func()->dataset)
return;
auto&& isoline_range = d_func()->ranges[field_name];
auto count = d->isolines_counts[field_name];
d->isolines->GenerateValues(count, isoline_range[0], isoline_range[1]);
d->isolines->Modified();
}
void dtkVisualizationDecoratorScalarIsolines::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
......@@ -172,6 +150,7 @@ void dtkVisualizationDecoratorScalarIsolines::setData(const QVariant& data)
d_func()->clear();
d_func()->retrieveScalarPoints(dataset);
d_func()->retrieveScalarCells(dataset);
if (!this->isDecorating()) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet has no field to decorate. Nothing is done.";
......@@ -181,16 +160,13 @@ void dtkVisualizationDecoratorScalarIsolines::setData(const QVariant& data)
d_func()->dataset = dataset;
d->isolines_ranges.clear();
d->cell_centers->SetInputData(dataset);
d->isolines_counts.clear();
for (auto field_name : d_func()->eligible_field_names) {
//dataset->GetPointData()->SetActiveScalars(qPrintable(field_name));
double *range = dataset->GetPointData()->GetArray(qPrintable(field_name))->GetRange();
d->isolines_ranges[field_name] = qMakePair(range[0], range[1]);
d->isolines_counts[field_name] = 1;
for (auto field_name : d_func()->eligible_field_names) {
d->isolines_counts[field_name] = 10;
}
d->isolines->SetInputData(dataset);
d->isolines->Modified();
d->mapper->Modified();
......@@ -241,86 +217,66 @@ void dtkVisualizationDecoratorScalarIsolines::setVisibility(bool b)
d->show_actor_cb->blockSignals(false);
}
void dtkVisualizationDecoratorScalarIsolines::setCurrentIsolinesRange(double min, double max)
void dtkVisualizationDecoratorScalarIsolines::setCurrentRange(double min, double max)
{
QString& current_field_name = d_func()->current_field_name;
if (current_field_name.isEmpty()) {
if (d_func()->current_field_name.isEmpty()) {
qWarning() << Q_FUNC_INFO << "Field not selected";
return;
}
if (min >= max) {
qWarning() << Q_FUNC_INFO << " min >= max : " << min << max;
return;
}
d->isolines_ranges[current_field_name] = qMakePair(min, max);
d->isolines->SetValue(min, max);
d->isolines->GenerateValues(d->isolines_counts[current_field_name], min, max);
d->isolines->Modified();
// d->mapper->SetScalarRange(min, max);
d->mapper->Modified();
d->actor->Modified();
if (this->canvas())
this->canvas()->touch();
emit this->currentIsolinesRangeChanged(min, max);
dtkVisualizationDecoratorWithClut::setCurrentRange(min, max);
}
void dtkVisualizationDecoratorScalarIsolines::setCurrentIsolinesCount(std::size_t count)
{
QString& current_field_name = d_func()->current_field_name;
if (current_field_name.isEmpty()) {
QString& field_name = d_func()->current_field_name;
if (field_name.isEmpty()) {
return;
}
d->isolines_counts[field_name] = count;
QPair<double, double> isoline_range = d->isolines_ranges[current_field_name];
d->isolines_counts[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()->touch();
emit this->currentIsolinesCountChanged(count);
this->draw();
}
bool dtkVisualizationDecoratorScalarIsolines::setCurrentFieldName(const QString& field_name)
{
if (!dtkVisualizationDecoratorWithClut::setCurrentFieldName(field_name))
if (field_name.isEmpty()) {
dtkWarn() << Q_FUNC_INFO << "Field name is empty, nothing is done.";
return false;
}
QString& current_field_name = d_func()->current_field_name;
vtkSmartPointer<vtkColorTransferFunction>& color_function = d_func()->color_function;
auto&& range = d_func()->ranges[current_field_name];
vtkDataSet *dataset = d_func()->dataset;
d->mapper->SetLookupTable(color_function);
d->mapper->SetScalarRange(range[0], range[1]);
const QPair<double, double>& isolines_range = d->isolines_ranges[current_field_name];
std::size_t isolines_count = d->isolines_counts[current_field_name];
d->isolines->GenerateValues(isolines_range.first, isolines_range.second, isolines_count);
d->isolines->Modified();
if (!d_func()->dataset) {
dtkWarn() << Q_FUNC_INFO << "Before calling setCurrentFieldName, setDataSet must be called.";
return false;
}
d->mapper->SelectColorArray(qPrintable(current_field_name));
d->mapper->Modified();
d->actor->Modified();
if(!d_func()->eligible_field_names.contains(field_name)) {
dtkWarn() << Q_FUNC_INFO << "The field name :" << field_name << "that was specified doesn't match any of the eligible scalar field names";
emit this->currentIsolinesRangeChanged(isolines_range.first, isolines_range.second);
emit this->currentIsolinesCountChanged(isolines_count);
return false;
}
if (this->canvas())
this->canvas()->touch();
using Support = dtkVisualizationDecoratorWithClut::Support;
int support = d_func()->supports[field_name];
if(support == Support::Point) {
d->isolines->SetInputData(d_func()->dataset);
} else if(support == Support::Cell) {
d->cell_centers->Update();
d->isolines->SetInputData(d->cell_centers->GetOutput());
d->isolines->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, qPrintable(field_name));
}
d->isolines->Modified();
return true;
return dtkVisualizationDecoratorWithClut::setCurrentFieldName(field_name);
}
void dtkVisualizationDecoratorScalarIsolines::setColorMap(const QMap<double, QColor>& new_colormap)
{
dtkVisualizationDecoratorWithClut::setColorMap(new_colormap);
//dtkVisualizationDecoratorWithClut::setColorMap(new_colormap);
d->mapper->SetLookupTable(d_func()->color_function);
d->mapper->SelectColorArray(qPrintable(d_func()->current_field_name));
......@@ -340,8 +296,6 @@ void dtkVisualizationDecoratorScalarIsolines::setColorMap(const QMap<double, QCo
// d->actor->GetProperty()->SetOpacity(opacity_min);
// d->actor->Modified();
this->touch();
}
//
......
......@@ -25,12 +25,16 @@ public:
dtkVisualizationDecoratorScalarIsolines(void);
~dtkVisualizationDecoratorScalarIsolines(void);
public:
void draw(void) override;
public:
void setData(const QVariant&) override;
void setCanvas(dtkVisualizationCanvas *) override;
void unsetCanvas(void) override;
protected:
void setCurrentRange(double, double) override;
bool setCurrentFieldName(const QString&) override;
void setColorMap(const QMap<double, QColor>&) override;
......@@ -38,13 +42,8 @@ public:
void setVisibility(bool) override;
public:
void setCurrentIsolinesRange(double, double);
void setCurrentIsolinesCount(std::size_t);
signals:
void currentIsolinesRangeChanged(double, double);
void currentIsolinesCountChanged(std::size_t);
protected:
class dtkVisualizationDecoratorScalarIsolinesPrivate *d = nullptr;
};
......
......@@ -235,13 +235,17 @@ dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(void): dtkV
});
connect(d->min_range, &QLineEdit::editingFinished, [=] () {
d->fixed_range->blockSignals(true);
d->fixed_range->setChecked(Qt::Checked);
d->fixed_range->blockSignals(false);
this->setCurrentRange(d->min_range->text().toDouble(), d->max_range->text().toDouble());
this->touch();
});
connect(d->max_range, &QLineEdit::editingFinished, [=] () {
d->fixed_range->blockSignals(true);
d->fixed_range->setChecked(Qt::Checked);
d->fixed_range->blockSignals(false);
this->setCurrentRange(d->min_range->text().toDouble(), d->max_range->text().toDouble());
this->touch();
});
......
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