Commit 7aaf7eb0 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

Refactoring the way to set the colormap for the vector decorators.

- option to select either uniform color, magnitude color, X, Y or Z
  component color.
- computation of the range with respect to the previous choice
parent 516f7692
......@@ -21,6 +21,7 @@
#include <vtkDataArray.h>
#include <vtkGlyph3D.h>
#include <vtkLookupTable.h>
#include <vtkMaskPoints.h>
#include <vtkPointData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
......@@ -39,10 +40,12 @@ public:
public:
vtkSmartPointer<vtkArrowSource> source_arrow;
vtkSmartPointer<vtkCellCenters> cell_centers;
vtkSmartPointer<vtkMaskPoints> mask_points;
vtkSmartPointer<vtkGlyph3D> glyphs;
public:
QCheckBox *show_actor_cb = nullptr;
QSpinBox *glyphs_stride_sb = nullptr;
QDoubleSpinBox *glyphs_scale_factor_sb = nullptr;
};
......@@ -56,7 +59,12 @@ dtkVisualizationDecoratorVectorGlyphs::dtkVisualizationDecoratorVectorGlyphs(voi
d->cell_centers = vtkSmartPointer<vtkCellCenters>::New();
d->mask_points = vtkSmartPointer<vtkMaskPoints>::New();
d->mask_points->RandomModeOff();
d->mask_points->SetOnRatio(2); // 1 => all points are taken then no masking
d->glyphs = vtkSmartPointer<vtkGlyph3D>::New();
d->glyphs->SetInputConnection(d->mask_points->GetOutputPort());
d->glyphs->SetSourceConnection(d->source_arrow->GetOutputPort());
d->glyphs->SetVectorModeToUseVector();
d->glyphs->SetScaleModeToScaleByVector();
......@@ -74,11 +82,16 @@ dtkVisualizationDecoratorVectorGlyphs::dtkVisualizationDecoratorVectorGlyphs(voi
// Inspectors creation
d->show_actor_cb = new QCheckBox;
d->glyphs_stride_sb = new QSpinBox;
d->glyphs_scale_factor_sb = new QDoubleSpinBox;
//////////
// Inspectors setup
d->glyphs_stride_sb->setValue(2);
d->glyphs_stride_sb->setMaximum(9999999);
d->glyphs_stride_sb->setKeyboardTracking(false);
d->glyphs_scale_factor_sb->setValue(0.1);
d->glyphs_scale_factor_sb->setDecimals(5);
d->glyphs_scale_factor_sb->setMaximum(1000);
......@@ -93,6 +106,13 @@ dtkVisualizationDecoratorVectorGlyphs::dtkVisualizationDecoratorVectorGlyphs(voi
this->draw();
});
connect(d->glyphs_stride_sb, QOverload<int>::of(&QSpinBox::valueChanged), [=] (int value) {
this->blockSignals(true);
d->mask_points->SetOnRatio(value);
this->blockSignals(false);
this->draw();
});
connect(d->glyphs_scale_factor_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double value) {
this->blockSignals(true);
d->glyphs->SetScaleFactor(value);
......@@ -102,9 +122,11 @@ dtkVisualizationDecoratorVectorGlyphs::dtkVisualizationDecoratorVectorGlyphs(voi
this->setObjectName("Vector Glyphs");
d->show_actor_cb->setObjectName("Display");
d->glyphs_stride_sb->setObjectName("Every Nth point");
d->glyphs_scale_factor_sb->setObjectName("Scale Factor");
d_func()->inspectors << d->show_actor_cb << d->glyphs_scale_factor_sb;
d_func()->inspectors << d->show_actor_cb << d_func()->field_components
<< d->glyphs_stride_sb << d->glyphs_scale_factor_sb;
}
dtkVisualizationDecoratorVectorGlyphs::~dtkVisualizationDecoratorVectorGlyphs(void)
......@@ -227,12 +249,15 @@ bool dtkVisualizationDecoratorVectorGlyphs::setCurrentFieldName(const QString& f
using Support = dtkVisualizationDecoratorWithClut::Support;
int support = d_func()->supports[field_name];
if(support == Support::Point) {
d->glyphs->SetInputData(d_func()->dataset);
d->mask_points->SetInputData(d_func()->dataset);
d->mask_points->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, qPrintable(field_name));
d->glyphs->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, qPrintable(field_name));
} else if(support == Support::Cell) {
d->glyphs->SetInputConnection(d->cell_centers->GetOutputPort());
d->mask_points->SetInputConnection(d->cell_centers->GetOutputPort());
d->mask_points->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_CELLS, qPrintable(field_name));
d->glyphs->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_CELLS, qPrintable(field_name));
}
d->mask_points->Modified();
d->glyphs->Modified();
return dtkVisualizationDecoratorWithClut::setCurrentFieldName(field_name);
......@@ -242,17 +267,15 @@ void dtkVisualizationDecoratorVectorGlyphs::setColorMap(const QMap<double, QColo
{
dtkVisualizationDecoratorWithClut::setColorMap(new_colormap);
d_func()->color_function->SetVectorModeToMagnitude(); // Replace d->glyphs->SetColorModeToUseVector()
d->mapper->SetLookupTable(d_func()->color_function);
// The output polydata from the glyph filter hardcodes the name of the array containing vector magnitude
// To avoid the same hardcode, one uses GetPointData()->GetScalars()->GetName() instead.
if (d->glyphs->GetOutput()->GetPointData()->GetScalars()) {
d->mapper->SelectColorArray(d->glyphs->GetOutput()->GetPointData()->GetScalars()->GetName());
if (d->glyphs->GetOutput()->GetPointData()->GetVectors()) {
d->mapper->SelectColorArray(d->glyphs->GetOutput()->GetPointData()->GetVectors()->GetName());
} else {
d->mapper->SelectColorArray(qPrintable(d_func()->current_field_name));
}
auto&& range = d_func()->ranges[d_func()->current_field_name];
d->mapper->SetScalarRange(range[0], range[1]);
d->mapper->Modified();
......
......@@ -337,9 +337,11 @@ dtkVisualizationDecoratorVectorStreamTracer::dtkVisualizationDecoratorVectorStre
d->sp_radius->setObjectName("Tube Radius");
d->sp_resolution->setObjectName("Resolution");
d_func()->inspectors << d->cb_source_type << d->cb_integrator_direction << d->cb_integrator_type << d->sp_integrator_max_steps
<< d->sp_integrator_max_lengths << d->sp_radius << d->sp_resolution
<< d->show_actor_cb << d->show_source_actor_cb;
d_func()->inspectors << d->show_actor_cb << d->show_source_actor_cb
<< d_func()->field_components
<< d->cb_source_type << d->cb_integrator_direction << d->cb_integrator_type << d->sp_integrator_max_steps
<< d->sp_integrator_max_lengths << d->sp_radius << d->sp_resolution;
}
dtkVisualizationDecoratorVectorStreamTracer::~dtkVisualizationDecoratorVectorStreamTracer(void)
......@@ -529,7 +531,6 @@ void dtkVisualizationDecoratorVectorStreamTracer::setColorMap(const QMap<double,
{
dtkVisualizationDecoratorWithClut::setColorMap(new_colormap);
d_func()->color_function->SetVectorModeToMagnitude();
d->mapper->SetLookupTable(d_func()->color_function);
d->mapper->SelectColorArray(qPrintable(d_func()->current_field_name));
auto&& range = d_func()->ranges[d_func()->current_field_name];
......
......@@ -51,12 +51,21 @@ dtkVisualizationDecoratorWithClutPrivate::dtkVisualizationDecoratorWithClutPriva
//////////
// Inspectors creation
this->fields_box = new QComboBox;
this->fields_box = new QComboBox;
this->field_components = new QComboBox;
this->field_components->addItem("None");
this->field_components->addItem("Magnitude");
this->field_components->addItem("X");
this->field_components->addItem("Y");
this->field_components->addItem("Z");
this->field_components->setCurrentIndex(0);
this->fixed_range = new QCheckBox;
this->min_range = new QLineEdit;
this->max_range = new QLineEdit;
this->min_range = new QLineEdit;
this->max_range = new QLineEdit;
this->colormap_editor = new dtkVisualizationWidgetsColorMapEditor;
this->colormap_editor = new dtkVisualizationWidgetsColorMapEditor;
this->show_scalar_bar = new QCheckBox;
......@@ -82,12 +91,12 @@ dtkVisualizationDecoratorWithClutPrivate::dtkVisualizationDecoratorWithClutPriva
this->show_scalar_bar->setChecked(false);
this->fields_box->setObjectName("Field");
this->field_components->setObjectName("Coloring");
range_widget->setObjectName("");
this->colormap_editor->setObjectName("Color Map");
this->show_scalar_bar->setObjectName("Scalar Bar");
this->inspectors << this->fields_box << this->colormap_editor << range_widget << this->show_scalar_bar;
}
void dtkVisualizationDecoratorWithClutPrivate::clear(void)
......@@ -152,9 +161,25 @@ void dtkVisualizationDecoratorWithClutPrivate::retrieveVectorData(vtkDataSetAttr
this->kinds[field_name] = Kind::Vector;
auto&& range = this->ranges[field_name];
field_data->GetArray(i)->GetRange(range.data(), -1);
range[0] = range[1] = 0;
this->color_transfer_functions[field_name] = this->default_color_map;
// auto&& range_magn = this->ranges[field_name + QString("__Magnitude")];
// field_data->GetArray(i)->GetRange(range_magn.data(), -1);
// this->color_transfer_functions[field_name + QString("__Magnitude")] = this->default_color_map;
// auto&& range_x = this->ranges[field_name + QString("__X")];
// field_data->GetArray(i)->GetRange(range_x.data(), 0);
// this->color_transfer_functions[field_name + QString("__X")] = this->default_color_map;
// auto&& range_y = this->ranges[field_name + QString("__Y")];
// field_data->GetArray(i)->GetRange(range_y.data(), 1);
// this->color_transfer_functions[field_name + QString("__Y")] = this->default_color_map;
// auto&& range_z = this->ranges[field_name + QString("__Z")];
// field_data->GetArray(i)->GetRange(range_z.data(), 2);
// this->color_transfer_functions[field_name + QString("__Z")] = this->default_color_map;
auto opacity_function = vtkSmartPointer<vtkPiecewiseFunction>::New();
opacity_function->RemoveAllPoints();
opacity_function->AddPoint(0, 0.);
......@@ -220,6 +245,106 @@ void dtkVisualizationDecoratorWithClutPrivate::sortEligibleFields(void)
}
}
void dtkVisualizationDecoratorWithClutPrivate::updateRange(void)
{
auto&& range = this->ranges[this->current_field_name];
if (!this->fixed_range->isChecked()) {
// The following trick gives directly the right index value
// to extract in the GetRange method for the vector case.
int component_id = this->field_components->currentIndex() - 2;
using Kind = dtkVisualizationDecoratorWithClutPrivate::Kind;
using Support = dtkVisualizationDecoratorWithClutPrivate::Support;
switch (this->kinds[this->current_field_name]) {
case Kind::Scalar:
switch (this->supports[this->current_field_name]) {
case Support::Point:
this->dataset->GetPointData()->GetArray(qPrintable(this->current_field_name))->Modified();
this->dataset->GetPointData()->GetArray(qPrintable(this->current_field_name))->GetRange(range.data(), -1);
break;
case Support::Cell:
this->dataset->GetCellData()->GetArray(qPrintable(this->current_field_name))->Modified();
this->dataset->GetCellData()->GetArray(qPrintable(this->current_field_name))->GetRange(range.data(), -1);
break;
default:
break;
}
break;
case Kind::Vector:
if (component_id > -2) {
switch (this->supports[this->current_field_name]) {
case Support::Point:
this->dataset->GetPointData()->GetArray(qPrintable(this->current_field_name))->Modified();
this->dataset->GetPointData()->GetArray(qPrintable(this->current_field_name))->GetRange(range.data(), component_id);
break;
case Support::Cell:
this->dataset->GetCellData()->GetArray(qPrintable(this->current_field_name))->Modified();
this->dataset->GetCellData()->GetArray(qPrintable(this->current_field_name))->GetRange(range.data(), component_id);
break;
default:
break;
}
} else {
range[0] = range[1] = 0;
}
break;
default:
break;
}
}
this->min_range->blockSignals(true);
this->min_range->setText(QString::number(range[0]));
this->min_range->blockSignals(false);
this->max_range->blockSignals(true);
this->max_range->setText(QString::number(range[1]));
this->max_range->blockSignals(false);
}
void dtkVisualizationDecoratorWithClutPrivate::updateColorTransferFunction(void)
{
using Kind = dtkVisualizationDecoratorWithClutPrivate::Kind;
// The following trick gives directly the right index value
// to extract in the GetRange method for the vector case.
int component_id = this->field_components->currentIndex() - 2;
switch (this->kinds[this->current_field_name]) {
case Kind::Vector:
switch(component_id) {
case -1:
this->color_function->SetVectorModeToMagnitude();
break;
case 0:
this->color_function->SetVectorModeToComponent();
this->color_function->SetVectorComponent(0);
break;
case 1:
this->color_function->SetVectorModeToComponent();
this->color_function->SetVectorComponent(1);
break;
case 2:
this->color_function->SetVectorModeToComponent();
this->color_function->SetVectorComponent(2);
break;
default:
this->color_function->SetVectorModeToMagnitude();
break;
}
break;
default:
break;
}
this->colormap_editor->blockSignals(true);
this->colormap_editor->setValue(this->color_transfer_functions[this->current_field_name]);
this->colormap_editor->blockSignals(false);
}
// ///////////////////////////////////////////////////////////////////
// dtkVisualizationDecoratorWithClut implementation
// ///////////////////////////////////////////////////////////////////
......@@ -234,6 +359,9 @@ dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(void): dtkV
this->saveSettings("field_name", field_name);
this->touch();
});
connect(d->field_components, QOverload<int>::of(&QComboBox::currentIndexChanged), [=] (int component_id) {
this->touch();
});
connect(d->min_range, &QLineEdit::editingFinished, [=] () {
d->fixed_range->blockSignals(true);
......@@ -326,33 +454,9 @@ void dtkVisualizationDecoratorWithClut::touch(void)
}
// Update range
auto&& range = d->ranges[d->current_field_name];
if(!d->fixed_range->isChecked()) {
using Support = dtkVisualizationDecoratorWithClutPrivate::Support;
switch (d->supports[d->current_field_name]) {
case Support::Point:
d->dataset->GetPointData()->GetArray(qPrintable(d->current_field_name))->Modified();
d->dataset->GetPointData()->GetArray(qPrintable(d->current_field_name))->GetRange(range.data(), -1);
break;
case Support::Cell:
d->dataset->GetCellData()->GetArray(qPrintable(d->current_field_name))->Modified();
d->dataset->GetCellData()->GetArray(qPrintable(d->current_field_name))->GetRange(range.data(), -1);
break;
default:
return;
}
}
d->min_range->blockSignals(true);
d->min_range->setText(QString::number(range[0]));
d->min_range->blockSignals(false);
d->max_range->blockSignals(true);
d->max_range->setText(QString::number(range[1]));
d->max_range->blockSignals(false);
d->updateRange();
d->colormap_editor->blockSignals(true);
d->colormap_editor->setValue(d->color_transfer_functions[d->current_field_name]);
d->colormap_editor->blockSignals(false);
d->updateColorTransferFunction();
this->setColorMap(d->colormap_editor->value());
}
......
......@@ -35,6 +35,7 @@ class vtkDataSetAttributes;
class vtkPiecewiseFunction;
class vtkPiecewiseFunction;
class vtkScalarBarActor;
class vtkTransform;
class DTKVISUALIZATION_EXPORT dtkVisualizationDecoratorWithClutPrivate
{
......@@ -63,6 +64,7 @@ public:
QList<QWidget *> inspectors;
QComboBox *fields_box = nullptr;
QComboBox *field_components = nullptr;
QCheckBox *fixed_range = nullptr;
QLineEdit *min_range = nullptr;
QLineEdit *max_range = nullptr;
......@@ -101,6 +103,8 @@ public:
void retrieveVectorPoints(vtkDataSet *);
void retrieveVectorCells(vtkDataSet *);
void sortEligibleFields(void);
void updateRange(void);
void updateColorTransferFunction(void);
private:
void retrieveScalarData(vtkDataSetAttributes *, Support support);
......
Supports Markdown
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