Commit 3491fec7 authored by LE BRETON Come's avatar LE BRETON Come

Modify methods names, connect overlay widgets to decorator.

parent d38e021b
......@@ -29,7 +29,8 @@
#include <dtkWidgets/dtkWidgetsLayout>
#include <dtkWidgets/dtkWidgetsLayoutItem>
#include <dtkWidgets/dtkWidgetsOverlayRope>
#include <dtkWidgets/dtkWidgetsOverlayPane>
#include <dtkWidgets/dtkWidgetsOverlayPaneItem>
#include <vtkDataSet.h>
#include <vtkUnstructuredGrid.h>
#include <vtkRenderer.h>
......@@ -146,10 +147,43 @@ void dtkVisualizationViewer::importDataSet(const QString& path)
vtkDataSet *dataset = dtkVisualizationVTKReader(path);
dtkVisualizationDecoratorScalarColorMap* decorator = new dtkVisualizationDecoratorScalarColorMap;
decorator->setCanvas(dynamic_cast<dtkVisualizationView3D *>(d->stack->layout()->current()->view()));
dtkVisualizationView3D *view_3d = dynamic_cast<dtkVisualizationView3D *>(d->stack->layout()->current()->view());
if(!view_3d) {
return;
}
dtkWidgetsOverlayPane *view_3d_pane = view_3d->overlay();
view_3d_pane->setBound(500);
dtkVisualizationWidgetsClutEditor *clut_editor = new dtkVisualizationWidgetsClutEditor;
dtkWidgetsOverlayPaneItem *pane_item = new dtkWidgetsOverlayPaneItem;
pane_item->setTitle("toto");
pane_item->addWidget(clut_editor);
view_3d_pane->addWidget(pane_item);
decorator->setCanvas(view_3d);
QVariant data = dtk::variantFromValue(dataset);
decorator->setData(data);
decorator->render();
connect(decorator, &dtkVisualizationDecoratorScalarColorMap::currentRangeChanged, [=] (double min, double max) {
clut_editor->blockSignals(true);
clut_editor->setRange(min, max);
clut_editor->blockSignals(false);
});
connect(decorator, &dtkVisualizationDecoratorScalarColorMap::currentColorTransferFunctionChanged, [=] (vtkColorTransferFunction *color_transfer_function) {
clut_editor->blockSignals(true);
clut_editor->setColorTransferFunction(color_transfer_function);
clut_editor->blockSignals(false);
});
connect(clut_editor, &dtkVisualizationWidgetsClutEditor::updated, [=] () {
decorator->blockSignals(true);
decorator->setCurrentColorTransferFunction(reinterpret_cast<vtkColorTransferFunction *>(clut_editor->colorTransferFunction()));
decorator->blockSignals(false);
});
}
void dtkVisualizationViewer::setRopeSource(QWidget *source)
......
......@@ -95,7 +95,14 @@ void dtkVisualizationDecoratorScalarColorMap::draw(void)
return;
}
if (!d->scalar_bar && this->canvas() && this->canvas()->renderer()) {
if(!this->canvas()) {
qWarning() << Q_FUNC_INFO << "No canvas was set, call setCanvas to call draw on a canvas.";
return;
}
Q_ASSERT(this->canvas()->renderer());
if (!d->scalar_bar) {
d->scalar_bar = vtkSmartPointer<vtkScalarBarActor>::New();
d->scalar_bar->SetWidth(0.08);
d->scalar_bar->SetHeight(0.6);
......@@ -103,12 +110,10 @@ void dtkVisualizationDecoratorScalarColorMap::draw(void)
this->canvas()->renderer()->AddActor2D(d->scalar_bar);
}
d->scalar_bar->SetLookupTable(d->mapper->GetLookupTable());
d->scalar_bar->SetLookupTable(d->color_transfer_functions[d->current_field_name]);
d->scalar_bar->SetTitle(qPrintable(d->current_field_name));
d->scalar_bar->Modified();
if (d->scalar_bar) {
d->scalar_bar->SetTitle(qPrintable(d->current_field_name));
d->scalar_bar->Modified();
}
d->actor->Modified();
if(this->canvas()->interactor()) {
......@@ -194,10 +199,11 @@ void dtkVisualizationDecoratorScalarColorMap::setData(const QVariant& data)
d->eligible_field_names.sort();
if(d->eligible_field_names.size() != 0) {
d->current_field_name = d->eligible_field_names.first();
this->setCurrentFieldName(d->eligible_field_names.first());
}
d->mapper->SetInputData(d->dataset);
d->mapper->Modified();
}
......@@ -238,13 +244,7 @@ vtkSmartPointer<vtkPiecewiseFunction> dtkVisualizationDecoratorScalarColorMap::c
return d->opacity_functions[d->current_field_name];
}
// void dtkVisualizationDecoratorScalarColorMap::setInteractor(void *interactor)
// {
// Q_ASSERT(interactor);
// d->interactor = static_cast<vtkRenderWindowInteractor *>(interactor);
// }
bool dtkVisualizationDecoratorScalarColorMap::setFieldName(const QString& scalar_field_name)
bool dtkVisualizationDecoratorScalarColorMap::setCurrentFieldName(const QString& scalar_field_name)
{
if (scalar_field_name.isEmpty()) {
qWarning() << Q_FUNC_INFO << "Scalar field name is empty, nothing is done.";
......@@ -281,6 +281,11 @@ bool dtkVisualizationDecoratorScalarColorMap::setFieldName(const QString& scalar
d->mapper->Modified();
d->actor->Modified();
if(d->scalar_bar) {
d->scalar_bar->SetLookupTable(d->color_transfer_functions[d->current_field_name]);
d->scalar_bar->Modified();
}
emit this->currentFieldNameChanged(d->current_field_name);
emit this->currentColorTransferFunctionChanged(color_function);
emit this->currentRangeChanged(range.first, range.second);
......@@ -290,7 +295,7 @@ bool dtkVisualizationDecoratorScalarColorMap::setFieldName(const QString& scalar
void dtkVisualizationDecoratorScalarColorMap::setColorTransferFunction(vtkSmartPointer<vtkColorTransferFunction> color_function)
void dtkVisualizationDecoratorScalarColorMap::setCurrentColorTransferFunction(vtkSmartPointer<vtkColorTransferFunction> color_function)
{
d->color_transfer_functions[d->current_field_name] = color_function;
......@@ -298,6 +303,9 @@ void dtkVisualizationDecoratorScalarColorMap::setColorTransferFunction(vtkSmartP
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();
}
......@@ -305,7 +313,7 @@ void dtkVisualizationDecoratorScalarColorMap::setColorTransferFunction(vtkSmartP
emit this->currentColorTransferFunctionChanged(color_function);
}
void dtkVisualizationDecoratorScalarColorMap::setOpacityTransferFunction(vtkSmartPointer<vtkPiecewiseFunction> opacity_function)
void dtkVisualizationDecoratorScalarColorMap::setCurrentOpacityTransferFunction(vtkSmartPointer<vtkPiecewiseFunction> opacity_function)
{
d->opacity_functions[d->current_field_name] = opacity_function;
......@@ -318,7 +326,7 @@ void dtkVisualizationDecoratorScalarColorMap::setOpacityTransferFunction(vtkSmar
emit this->currentOpacityFunctionChanged(d->opacity_functions[d->current_field_name]);
}
void dtkVisualizationDecoratorScalarColorMap::setRange(double min, double max)
void dtkVisualizationDecoratorScalarColorMap::setCurrentRange(double min, double max)
{
d->ranges[d->current_field_name] = qMakePair(min, max);
......
......@@ -46,14 +46,11 @@ public:
vtkSmartPointer<vtkColorTransferFunction> currentColorTransferFunction(void);
vtkSmartPointer<vtkPiecewiseFunction> currentOpacityTransferFunction(void);
// public:
// void setInteractor(void *) override;
public:
bool setFieldName(const QString&);
void setColorTransferFunction(vtkSmartPointer<vtkColorTransferFunction>);
void setOpacityTransferFunction(vtkSmartPointer<vtkPiecewiseFunction>);
void setRange(double min, double max);
bool setCurrentFieldName(const QString&);
void setCurrentColorTransferFunction(vtkSmartPointer<vtkColorTransferFunction>);
void setCurrentOpacityTransferFunction(vtkSmartPointer<vtkPiecewiseFunction>);
void setCurrentRange(double min, double max);
signals:
void currentFieldNameChanged(const QString&);
......
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