Commit 8662906c authored by LE BRETON Come's avatar LE BRETON Come

Adds show and hide controls.

parent 940f94bb
......@@ -63,6 +63,7 @@ void dtkVisualizationDecorator::drawAndForward(void)
if (d->next) {
d->next->drawAndForward();
} else {
if(!this->canvas()) return;
this->canvas()->renderer()->ResetCamera();
this->canvas()->renderer()->GetRenderWindow()->Render();
}
......@@ -78,6 +79,11 @@ void dtkVisualizationDecorator::setCanvas(dtkVisualizationCanvas *c)
d->canvas = c;
}
void dtkVisualizationDecorator::unsetCanvas(void)
{
d->canvas = nullptr;
}
QVariant dtkVisualizationDecorator::data(void) const
{
return d->data;
......
......@@ -42,7 +42,9 @@ public slots:
public:
virtual void setData(const QVariant&);
virtual void setCanvas(dtkVisualizationCanvas *);
virtual void unsetCanvas(void);
public:
QVariant data(void) const;
dtkVisualizationCanvas *canvas(void) const;
......
......@@ -84,6 +84,7 @@ dtkVisualizationDecoratorScalarColorMap::dtkVisualizationDecoratorScalarColorMap
d->mapper->SetScalarVisibility(true);
d->actor = vtkSmartPointer<vtkActor>::New();
d->actor->GetProperty()->SetOpacity(0.1);
d->actor->SetMapper(d->mapper);
d->actor->SetVisibility(true);
}
......@@ -233,13 +234,28 @@ void dtkVisualizationDecoratorScalarColorMap::setCanvas(dtkVisualizationCanvas *
dtkWidgetsOverlayPane *canvas_pane = canvas->overlay();
canvas_pane->setBound(500);
QCheckBox *show_cb = new QCheckBox;
dtkVisualizationWidgetsClutEditor *clut_editor = new dtkVisualizationWidgetsClutEditor;
QWidget *model_widget = new QWidget;
QFormLayout *form_layout = new QFormLayout(model_widget);
form_layout->addRow("Display", show_cb);
dtkWidgetsOverlayPaneItem *pane_item = new dtkWidgetsOverlayPaneItem;
pane_item->setTitle("Scalar Color Map");
pane_item->addWidget(model_widget);
pane_item->addWidget(clut_editor);
canvas_pane->addWidget(pane_item);
show_cb->setCheckState(Qt::Checked);
// show_cb connections
connect(show_cb, &QCheckBox::stateChanged, [=] (int state) {
if(state == Qt::Checked) this->show();
else this->hide();
});
// clut_editor connections
connect(this, &dtkVisualizationDecoratorScalarColorMap::currentRangeChanged, [=] (double min, double max) {
clut_editor->blockSignals(true);
clut_editor->setRange(min, max);
......@@ -259,6 +275,39 @@ void dtkVisualizationDecoratorScalarColorMap::setCanvas(dtkVisualizationCanvas *
});
}
void dtkVisualizationDecoratorScalarColorMap::unsetCanvas(void)
{
dtkVisualizationCanvas *canvas = this->canvas();
dtkVisualizationView2D *old = dynamic_cast<dtkVisualizationView2D *>(canvas);
if (old) {
old->renderer()->RemoveActor(d->actor);
}
dtkVisualizationView2D *view = dynamic_cast<dtkVisualizationView2D *>(canvas);
if (!view) {
qWarning() << Q_FUNC_INFO << "View 2D or view 3D expected as canvas. Canvas is reset to nullptr.";
dtkVisualizationDecorator::setCanvas(nullptr);
return;
}
}
void dtkVisualizationDecoratorScalarColorMap::show(void) {
d->actor->SetVisibility(true);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
}
}
void dtkVisualizationDecoratorScalarColorMap::hide(void) {
d->actor->SetVisibility(false);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
}
}
QStringList dtkVisualizationDecoratorScalarColorMap::eligibleFieldNames(void)
{
return d->eligible_field_names;
......@@ -363,7 +412,7 @@ void dtkVisualizationDecoratorScalarColorMap::setCurrentOpacityTransferFunction(
d->opacity_functions[d->current_field_name] = opacity_function;
//Need to be implemented, probably requires modifying the lut...
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
......
......@@ -32,12 +32,14 @@ public:
dtkVisualizationDecoratorScalarColorMap(void);
~dtkVisualizationDecoratorScalarColorMap(void);
protected:
void draw(void) override;
public:
void setData(const QVariant&) override;
void setCanvas(dtkVisualizationCanvas *) override;
void unsetCanvas(void) override;
public:
void show(void);
void hide(void);
public:
QStringList eligibleFieldNames(void);
......@@ -58,7 +60,10 @@ signals:
void currentOpacityFunctionChanged(vtkPiecewiseFunction *);
void currentRangeChanged(double, double);
private:
protected:
void draw(void) override;
protected:
class dtkVisualizationDecoratorScalarColorMapPrivate *d;
};
......
......@@ -97,7 +97,7 @@ dtkVisualizationDecoratorScalarIsolines::dtkVisualizationDecoratorScalarIsolines
d->actor = vtkSmartPointer<vtkActor>::New();
d->actor->SetMapper(d->mapper);
d->actor->SetVisibility(true);
d->actor->SetVisibility(false);
}
dtkVisualizationDecoratorScalarIsolines::~dtkVisualizationDecoratorScalarIsolines(void)
......@@ -255,15 +255,28 @@ void dtkVisualizationDecoratorScalarIsolines::setCanvas(dtkVisualizationCanvas *
dtkWidgetsOverlayPane *canvas_pane = canvas->overlay();
canvas_pane->setBound(500);
dtkVisualizationWidgetsClutEditor *clut_editor = new dtkVisualizationWidgetsClutEditor;
QCheckBox *show_cb = new QCheckBox;
QSpinBox *isolines_counts_sb = new QSpinBox;
dtkVisualizationWidgetsClutEditor *clut_editor = new dtkVisualizationWidgetsClutEditor;
QWidget *model_widget = new QWidget;
QFormLayout *form_layout = new QFormLayout(model_widget);
form_layout->addRow("Display", show_cb);
form_layout->addRow("Count", isolines_counts_sb);
dtkWidgetsOverlayPaneItem *pane_item = new dtkWidgetsOverlayPaneItem;
pane_item->setTitle("Scalar Isolines");
pane_item->addWidget(model_widget);
pane_item->addWidget(clut_editor);
pane_item->addWidget(isolines_counts_sb);
canvas_pane->addWidget(pane_item);
// show_cb connections
connect(show_cb, &QCheckBox::stateChanged, [=] (int state) {
if(state == Qt::Checked) this->show();
else this->hide();
});
// clut_editor connections
connect(this, &dtkVisualizationDecoratorScalarIsolines::currentRangeChanged, [=] (double min, double max) {
clut_editor->blockSignals(true);
......@@ -291,6 +304,39 @@ void dtkVisualizationDecoratorScalarIsolines::setCanvas(dtkVisualizationCanvas *
});
}
void dtkVisualizationDecoratorScalarIsolines::unsetCanvas(void)
{
dtkVisualizationCanvas *canvas = this->canvas();
dtkVisualizationView2D *old = dynamic_cast<dtkVisualizationView2D *>(canvas);
if (old) {
old->renderer()->RemoveActor(d->actor);
}
dtkVisualizationView2D *view = dynamic_cast<dtkVisualizationView2D *>(canvas);
if (!view) {
qWarning() << Q_FUNC_INFO << "View 2D or view 3D expected as canvas. Canvas is reset to nullptr.";
dtkVisualizationDecorator::setCanvas(nullptr);
return;
}
}
void dtkVisualizationDecoratorScalarIsolines::show(void) {
d->actor->SetVisibility(true);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
}
}
void dtkVisualizationDecoratorScalarIsolines::hide(void) {
d->actor->SetVisibility(false);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
}
}
QStringList dtkVisualizationDecoratorScalarIsolines::eligibleFieldNames(void)
{
return d->eligible_field_names;
......
......@@ -38,9 +38,11 @@ public:
public:
void setData(const QVariant&) override;
void setCanvas(dtkVisualizationCanvas *) override;
void unsetCanvas(void) override;
protected:
void draw(void) override;
public:
void show(void);
void hide(void);
public:
QStringList eligibleFieldNames(void);
......@@ -65,6 +67,9 @@ signals:
void currentIsolinesRangeChanged(double, double);
void currentIsolinesCountChanged(std::size_t);
protected:
void draw(void) override;
protected:
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