Commit 60938e65 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud

Fix glyph problems.

parent 0e4383a9
......@@ -19,7 +19,7 @@
#include <vtkClipPolyData.h>
#include <vtkColorTransferFunction.h>
#include <vtkContourFilter.h>
#include <vtkGlyph3D.h>
#include <vtkGlyph3DMapper.h>
#include <vtkLineRepresentation.h>
#include <vtkLineSource.h>
#include <vtkLineWidget2.h>
......@@ -85,8 +85,7 @@ public:
vtkSmartPointer<vtkStreamTracer> streamtracer;
vtkSmartPointer<vtkContourFilter> contours;
vtkSmartPointer<vtkArrowSource> source_arrows;
vtkSmartPointer<vtkGlyph3D> glyphs;
vtkSmartPointer<vtkPolyDataMapper> arrows_mapper;
vtkSmartPointer<vtkGlyph3DMapper> glyphs_mapper;
vtkSmartPointer<vtkActor> arrows_actor;
vtkSmartPointer<vtkStreamTracer> curves_stream;
vtkSmartPointer<vtkTubeFilter> curves_tube;
......@@ -157,20 +156,18 @@ dtkVisualizationDecoratorVectorCurvedGlyphs::dtkVisualizationDecoratorVectorCurv
d->source_arrows->SetTipLength(1);
d->source_arrows->SetTipRadius(0.2);
d->glyphs = vtkSmartPointer<vtkGlyph3D>::New();
d->glyphs->SetSourceConnection(d->source_arrows->GetOutputPort());
d->glyphs->SetInputConnection(d->contours->GetOutputPort());
d->glyphs->SetVectorModeToUseVector();
d->glyphs->SetScaleModeToDataScalingOff();
d->glyphs->OrientOn();
d->glyphs->SetScaleFactor(1.);
d->arrows_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
d->arrows_mapper->SetInputConnection(d->glyphs->GetOutputPort());
d->arrows_mapper->SetScalarModeToUsePointFieldData();
d->glyphs_mapper = vtkSmartPointer<vtkGlyph3DMapper>::New();
d->glyphs_mapper->SetSourceConnection(d->source_arrows->GetOutputPort());
d->glyphs_mapper->SetInputConnection(d->contours->GetOutputPort());
d->glyphs_mapper->SetOrientationModeToDirection();
d->glyphs_mapper->SetScalarModeToUsePointFieldData();
d->glyphs_mapper->SetScaleMode(vtkGlyph3DMapper::ScaleModes::NO_DATA_SCALING);
d->glyphs_mapper->OrientOn();
d->glyphs_mapper->ScalingOn();
d->glyphs_mapper->SetScaleFactor(1.);
d->arrows_actor = vtkSmartPointer<vtkActor>::New();
d->arrows_actor->SetMapper(d->arrows_mapper);
d->arrows_actor->SetMapper(d->glyphs_mapper);
d->curves_stream = vtkSmartPointer<vtkStreamTracer>::New();
d->curves_stream->SetSourceConnection(d->contours->GetOutputPort());
......@@ -482,6 +479,11 @@ bool dtkVisualizationDecoratorVectorCurvedGlyphs::setCurrentFieldName(const QStr
d->curves_stream->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_CELLS, qPrintable(field_name));
}
d->streamtracer->Modified();
d->curves_stream->Modified();
d->glyphs_mapper->SetOrientationArray(qPrintable(field_name));
d->glyphs_mapper->SetScaleArray(qPrintable(field_name));
d->glyphs_mapper->Modified();
return dtkVisualizationDecoratorWithClut::setCurrentFieldName(field_name);
}
......@@ -490,17 +492,13 @@ void dtkVisualizationDecoratorVectorCurvedGlyphs::setColorMap(const QMap<double,
{
dtkVisualizationDecoratorWithClut::setColorMap(new_colormap);
d->arrows_mapper->SetLookupTable(d_func()->color_function);
d->glyphs_mapper->SetLookupTable(d_func()->color_function);
d->curves_mapper->SetLookupTable(d_func()->color_function);
if (d->glyphs->GetOutput()->GetPointData()->GetVectors()) {
d->arrows_mapper->SelectColorArray(d->glyphs->GetOutput()->GetPointData()->GetVectors()->GetName());
} else {
d->arrows_mapper->SelectColorArray(qPrintable(d_func()->current_field_name));
}
d->glyphs_mapper->SelectColorArray(qPrintable(d_func()->current_field_name));
d->curves_mapper->SelectColorArray(qPrintable(d_func()->current_field_name));
auto&& range = d_func()->ranges[d_func()->current_field_name];
d->arrows_mapper->SetScalarRange(range[0], range[1]);
d->arrows_mapper->Modified();
d->glyphs_mapper->SetScalarRange(range[0], range[1]);
d->glyphs_mapper->Modified();
d->curves_mapper->SetScalarRange(range[0], range[1]);
d->curves_mapper->Modified();
}
......
......@@ -19,7 +19,7 @@
#include <vtkCellCenters.h>
#include <vtkColorTransferFunction.h>
#include <vtkDataArray.h>
#include <vtkGlyph3D.h>
#include <vtkGlyph3DMapper.h>
#include <vtkLookupTable.h>
#include <vtkMaskPoints.h>
#include <vtkPointData.h>
......@@ -34,14 +34,13 @@
class dtkVisualizationDecoratorVectorGlyphsPrivate
{
public:
vtkSmartPointer<vtkPolyDataMapper> mapper;
vtkSmartPointer<vtkActor> actor;
public:
vtkSmartPointer<vtkArrowSource> source_arrow;
vtkSmartPointer<vtkCellCenters> cell_centers;
vtkSmartPointer<vtkMaskPoints> mask_points;
vtkSmartPointer<vtkGlyph3D> glyphs;
vtkSmartPointer<vtkGlyph3DMapper> glyphs_mapper;
public:
QCheckBox *show_actor_cb = nullptr;
......@@ -63,20 +62,19 @@ dtkVisualizationDecoratorVectorGlyphs::dtkVisualizationDecoratorVectorGlyphs(voi
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();
d->glyphs->OrientOn();
d->glyphs->SetScaleFactor(0.1);
d->mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
d->mapper->SetInputConnection(d->glyphs->GetOutputPort());
d->mapper->SetScalarModeToUsePointFieldData();
d->glyphs_mapper = vtkSmartPointer<vtkGlyph3DMapper>::New();
d->glyphs_mapper->SetInputConnection(d->mask_points->GetOutputPort());
d->glyphs_mapper->SetSourceConnection(d->source_arrow->GetOutputPort());
d->glyphs_mapper->SetColorModeToMapScalars();
d->glyphs_mapper->SetOrientationModeToDirection();
d->glyphs_mapper->SetScalarModeToUsePointFieldData();
d->glyphs_mapper->SetScaleMode(vtkGlyph3DMapper::ScaleModes::SCALE_BY_MAGNITUDE);
d->glyphs_mapper->OrientOn();
d->glyphs_mapper->ScalingOn();
d->glyphs_mapper->SetScaleFactor(0.1);
d->actor = vtkSmartPointer<vtkActor>::New();
d->actor->SetMapper(d->mapper);
d->actor->SetMapper(d->glyphs_mapper);
//////////
// Inspectors creation
......@@ -101,7 +99,7 @@ dtkVisualizationDecoratorVectorGlyphs::dtkVisualizationDecoratorVectorGlyphs(voi
// Inspectors connections
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
this->saveSettings("visibility",state == Qt::Checked);
this->saveSettings("visibility", state == Qt::Checked);
this->setVisibility(state == Qt::Checked);
this->draw();
});
......@@ -115,7 +113,7 @@ dtkVisualizationDecoratorVectorGlyphs::dtkVisualizationDecoratorVectorGlyphs(voi
connect(d->glyphs_scale_factor_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double value) {
this->blockSignals(true);
d->glyphs->SetScaleFactor(value);
d->glyphs_mapper->SetScaleFactor(value);
this->blockSignals(false);
this->draw();
});
......@@ -203,7 +201,7 @@ void dtkVisualizationDecoratorVectorGlyphs::setCanvas(dtkVisualizationCanvas *ca
return;
}
if (d->glyphs->GetInput()) {
if (d->glyphs_mapper->GetInput()) {
d_func()->view->renderer()->AddActor(d->actor);
}
......@@ -250,15 +248,16 @@ bool dtkVisualizationDecoratorVectorGlyphs::setCurrentFieldName(const QString& f
int support = d_func()->supports[field_name];
if(support == Support::Point) {
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->cell_centers->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_CELLS, qPrintable(field_name));
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->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, qPrintable(field_name));
d->mask_points->Modified();
d->glyphs->Modified();
d->glyphs_mapper->SetOrientationArray(qPrintable(field_name));
d->glyphs_mapper->SetScaleArray(qPrintable(field_name));
d->glyphs_mapper->Modified();
return dtkVisualizationDecoratorWithClut::setCurrentFieldName(field_name);
}
......@@ -267,18 +266,11 @@ void dtkVisualizationDecoratorVectorGlyphs::setColorMap(const QMap<double, QColo
{
dtkVisualizationDecoratorWithClut::setColorMap(new_colormap);
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()->GetVectors()) {
d->mapper->SelectColorArray(d->glyphs->GetOutput()->GetPointData()->GetVectors()->GetName());
} else {
d->mapper->SelectColorArray(qPrintable(d_func()->current_field_name));
}
d->glyphs_mapper->SetLookupTable(d_func()->color_function);
d->glyphs_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();
d->glyphs_mapper->SetScalarRange(range[0], range[1]);
d->glyphs_mapper->Modified();
}
//
......
......@@ -394,8 +394,14 @@ void dtkVisualizationDecoratorVectorStreamTracer::setData(const QVariant& data)
double pos2[3]; pos2[0] = bounds[3]; pos2[1] = bounds[4]; pos2[2] = bounds[5];
vtkBoundingBox box;
box.SetBounds(bounds);
d->sp_integrator_max_lengths->blockSignals(true);
d->sp_integrator_max_lengths->setValue(box.GetDiagonalLength());
d->streamtracer->SetMaximumPropagation(box.GetDiagonalLength());
d->sp_integrator_max_lengths->blockSignals(false);
d->sp_radius->blockSignals(true);
d->sp_radius->setValue(box.GetDiagonalLength()/500.0);
d->tube_filter->SetRadius(box.GetDiagonalLength()/500.0);
d->sp_radius->blockSignals(false);
d->source_sphere->SetCenter(center);
d->source_sphere->SetRadius(box.GetDiagonalLength()/20.0);
......
......@@ -54,7 +54,7 @@ dtkVisualizationDecoratorWithClutPrivate::dtkVisualizationDecoratorWithClutPriva
this->fields_box = new QComboBox;
this->field_components = new QComboBox;
this->field_components->addItem("None");
this->field_components->addItem("Uniform");
this->field_components->addItem("Magnitude");
this->field_components->addItem("X");
this->field_components->addItem("Y");
......@@ -275,7 +275,6 @@ void dtkVisualizationDecoratorWithClutPrivate::updateRange(void)
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();
......@@ -359,9 +358,12 @@ 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->field_components, QOverload<int>::of(&QComboBox::currentIndexChanged), [=] (int component_id)
{
d->current_field_component = component_id;
this->saveSettings("field_component", component_id);
this->touch();
});
connect(d->min_range, &QLineEdit::editingFinished, [=] () {
d->fixed_range->blockSignals(true);
......@@ -417,6 +419,16 @@ void dtkVisualizationDecoratorWithClut::restoreSettings(void)
settings.beginGroup("canvas");
d->default_visibility = settings.value(name+"_visibility", true).toBool();
d->default_field_name = settings.value(name+"_field_name").toString();
if(!d->eligible_field_names.contains(d->default_field_name)) {
d->default_field_name = QString();
}
d->default_field_component = settings.value(name+"_field_component").toInt();
d->field_components->blockSignals(true);
d->field_components->setCurrentIndex(d->default_field_component);
d->field_components->blockSignals(false);
d->default_color_map = settings.value(name+"_colormap", "inferno").toString();
d->default_show_scalar_bar = settings.value(name+"_show_scalarbar", false).toBool();
double range_min = settings.value(name+"_range_min", -1.).toDouble();
......@@ -503,8 +515,6 @@ bool dtkVisualizationDecoratorWithClut::setCurrentFieldName(const QString& field
d->scalar_bar->SetTitle(qPrintable(this->objectName()+"/"+d->current_field_name));
d->scalar_bar->Modified();
this->touch();
return true;
}
......@@ -522,8 +532,6 @@ void dtkVisualizationDecoratorWithClut::setCurrentRange(double min, double max)
auto&& range = d->ranges[field_name];
range[0] = min;
range[1] = max;
this->touch();
}
void dtkVisualizationDecoratorWithClut::setColorMap(const QMap<double, QColor>& new_colormap)
......
......@@ -76,7 +76,9 @@ public:
public:
QStringList eligible_field_names;
QString current_field_name;
int current_field_component;
QString default_field_name;
int default_field_component;
QString default_color_map;
bool default_visibility;
bool default_show_scalar_bar;
......
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