Commit 4fb00ebc authored by CABEL Tristan's avatar CABEL Tristan

scalar_bar in clutEditor decorator

parent 51cd58d5
......@@ -34,6 +34,7 @@
#include <vtkRendererCollection.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkScalarBarActor.h>
// ///////////////////////////////////////////////////////////////////
// dtkVisualizationDecoratorClutEditorPrivate declaration
......@@ -56,6 +57,7 @@ public:
public:
vtkSmartPointer<vtkPiecewiseFunction> opacity;
vtkSmartPointer<vtkScalarBarActor> scalar_bar;
public:
QHash<QString, vtkSmartPointer<vtkColorTransferFunction>> color_transfer_functions;
......@@ -73,6 +75,10 @@ public:
dtkVisualizationDecoratorClutEditor::dtkVisualizationDecoratorClutEditor(void): d(new dtkVisualizationDecoratorClutEditorPrivate())
{
d->scalar_bar = vtkSmartPointer<vtkScalarBarActor>::New();
d->scalar_bar->SetWidth(0.08);
d->scalar_bar->SetHeight(0.6);
d->scalar_bar->SetVisibility(true);
}
dtkVisualizationDecoratorClutEditor::~dtkVisualizationDecoratorClutEditor(void)
......@@ -182,6 +188,10 @@ void dtkVisualizationDecoratorClutEditor::setData(const QVariant& data)
this->setCurrentFieldName(d->eligible_field_names.first());
}
if(this->canvas()) {
this->canvas()->renderer()->AddActor2D(d->scalar_bar);
}
dtkVisualizationDecorator::setData(data);
}
......@@ -217,9 +227,9 @@ void dtkVisualizationDecoratorClutEditor::setCanvas(dtkVisualizationCanvas *canv
// clut_editor connections
connect(this, &dtkVisualizationDecoratorClutEditor::currentRangeChanged, [=] (double min, double max) {
clut_editor->blockSignals(true);
//clut_editor->blockSignals(true);
clut_editor->setRange(min, max);
clut_editor->blockSignals(false);
// clut_editor->blockSignals(false);
});
connect(this, &dtkVisualizationDecoratorClutEditor::currentColorTransferFunctionChanged, [=] (vtkColorTransferFunction *color_transfer_function) {
......@@ -238,12 +248,22 @@ void dtkVisualizationDecoratorClutEditor::setCanvas(dtkVisualizationCanvas *canv
this->canvas()->renderer()->GetRenderWindow()->Render();
});
if(d->dataset) {
view->renderer()->AddActor2D(d->scalar_bar);
}
dtkVisualizationDecorator::setCanvas(view);
}
void dtkVisualizationDecoratorClutEditor::unsetCanvas(void)
{
dtkVisualizationCanvas *canvas = this->canvas();
dtkVisualizationView2D *old = dynamic_cast<dtkVisualizationView2D *>(canvas);
if (old) {
old->renderer()->RemoveActor2D(d->scalar_bar);
}
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.";
......@@ -311,6 +331,11 @@ bool dtkVisualizationDecoratorClutEditor::setCurrentFieldName(const QString& sca
const QPair<double, double>& range = d->ranges[d->current_field_name];
d->scalar_bar->SetTitle(qPrintable(d->current_field_name));
d->scalar_bar->SetLookupTable(color_function);
//TODO range SetMapper2D
d->scalar_bar->Modified();
emit this->currentFieldNameChanged(d->current_field_name);
emit this->currentRangeChanged(range.first, range.second);
//emit this->currentColorTransferFunctionChanged(color_function); // needs to be commented, why?
......@@ -324,6 +349,11 @@ void dtkVisualizationDecoratorClutEditor::setCurrentColorTransferFunction(vtkSma
}
d->color_transfer_functions[d->current_field_name]->DeepCopy(color_function);
d->scalar_bar->SetLookupTable(d->color_transfer_functions[d->current_field_name]);
//TODO range SetMapper2D
d->scalar_bar->Modified();
emit this->currentColorTransferFunctionChanged(color_function);
}
......
......@@ -37,7 +37,7 @@
#include <vtkRendererCollection.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkScalarBarActor.h>
#include <vtkSmartPointer.h>
// ///////////////////////////////////////////////////////////////////
......@@ -66,7 +66,7 @@ public:
public:
vtkSmartPointer<vtkActor> actor;
vtkSmartPointer<vtkDataSetMapper> mapper;
vtkSmartPointer<vtkScalarBarActor> scalar_bar;
public:
QHash<QString, Support> supports;
......@@ -86,10 +86,6 @@ dtkVisualizationDecoratorScalarColorMap::dtkVisualizationDecoratorScalarColorMap
d->actor->SetMapper(d->mapper);
d->actor->SetVisibility(true);
d->scalar_bar = vtkSmartPointer<vtkScalarBarActor>::New();
d->scalar_bar->SetWidth(0.08);
d->scalar_bar->SetHeight(0.6);
d->scalar_bar->SetVisibility(true);
}
dtkVisualizationDecoratorScalarColorMap::~dtkVisualizationDecoratorScalarColorMap(void)
......@@ -171,8 +167,8 @@ void dtkVisualizationDecoratorScalarColorMap::setData(const QVariant& data)
//init colorMap checked and actors on
if(this->canvas()) {
this->canvas()->renderer()->AddActor(d->actor);
this->canvas()->renderer()->AddActor2D(d->scalar_bar);
}
d->mapper->Modified();
dtkVisualizationDecorator::setData(data);
......@@ -219,7 +215,6 @@ void dtkVisualizationDecoratorScalarColorMap::setCanvas(dtkVisualizationCanvas *
show_cb->setCheckState(Qt::Checked);
if(d->mapper->GetInput()) {
view->renderer()->AddActor(d->actor);
view->renderer()->AddActor2D(d->scalar_bar);
}
// show_cb connections
......@@ -244,9 +239,6 @@ void dtkVisualizationDecoratorScalarColorMap::setCanvas(dtkVisualizationCanvas *
d->mapper->Modified();
d->actor->Modified();
d->scalar_bar->SetLookupTable(color_function);
d->scalar_bar->Modified();
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
this->canvas()->renderer()->GetRenderWindow()->Render();
......@@ -283,7 +275,6 @@ void dtkVisualizationDecoratorScalarColorMap::setCanvas(dtkVisualizationCanvas *
d->mapper->Modified();
d->actor->Modified();
//TODO edit scalar_bar or not
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
......@@ -308,7 +299,6 @@ void dtkVisualizationDecoratorScalarColorMap::unsetCanvas(void)
dtkVisualizationView2D *old = dynamic_cast<dtkVisualizationView2D *>(canvas);
if (old) {
old->renderer()->RemoveActor(d->actor);
old->renderer()->RemoveActor2D(d->scalar_bar);
}
dtkVisualizationView2D *view = dynamic_cast<dtkVisualizationView2D *>(canvas);
......@@ -324,10 +314,6 @@ void dtkVisualizationDecoratorScalarColorMap::show(void) {
if(d->clut_editor) {
d->clut_editor->setCurrentFieldName(d->current_field_name);
d->scalar_bar->SetVisibility(true);
d->scalar_bar->SetTitle(qPrintable(d->current_field_name));
d->scalar_bar->SetLookupTable(d->clut_editor->currentColorTransferFunction());
d->scalar_bar->Modified();
}
if (this->canvas() && this->canvas()->interactor()) {
......@@ -338,7 +324,6 @@ void dtkVisualizationDecoratorScalarColorMap::show(void) {
void dtkVisualizationDecoratorScalarColorMap::hide(void) {
d->actor->SetVisibility(false);
d->scalar_bar->SetVisibility(false);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
......@@ -378,18 +363,14 @@ bool dtkVisualizationDecoratorScalarColorMap::setCurrentFieldName(const QString&
d->clut_editor->setCurrentFieldName(scalar_field_name);
color_function = d->clut_editor->currentColorTransferFunction();
d->mapper->SetLookupTable(color_function);
d->scalar_bar->SetLookupTable(color_function);
range = d->clut_editor->currentRange();
d->mapper->SetScalarRange(range.first, range.second);
}
d->mapper->SelectColorArray(qPrintable(d->current_field_name));
d->scalar_bar->SetTitle(qPrintable(d->current_field_name));
d->mapper->Modified();
d->actor->Modified();
d->scalar_bar->Modified();
if(this->canvas())
this->canvas()->renderer()->GetRenderWindow()->Render();
......
......@@ -344,7 +344,7 @@ dtkVisualizationViewVideoGL::dtkVisualizationViewVideoGL(QWidget *parent) : dtkW
{
d = new dtkVisualizationViewVideoGLPrivate(this);
d->q = this;
d->setVersion(4, 3, true);
d->setVersion(4, 3, false);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
......
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