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

Merge branch 'feature/decorator_collection' into 'develop'

Feature/decorator collection

See merge request !29
parents 494da115 f9ddf83b
......@@ -350,13 +350,13 @@ void dtkVisualizationViewer::importDataSet(const QString& path)
menu_bar->touch();
d->collection.render();
d->collection.draw();
//TODO complete
connect(this, &dtkVisualizationViewer::updated,
[=] (void) {
d->collection.render();
d->collection.draw();
});
}
......
......@@ -5,6 +5,7 @@
"doc": "Open a VTK file.",
"path": ".",
"filters": [
"all VTK (*.vtk *.vti *.vtp *.vtu)",
"VTK (*.vtk)",
"VTI (*.vti)",
"VTP (*.vtp)",
......
......@@ -190,14 +190,14 @@ void dtkVisualizationCanvas::reset(void)
}
}
void dtkVisualizationCanvas::touch(void)
void dtkVisualizationCanvas::draw(void)
{
if (d->GetInteractor()) {
d->GetInteractor()->Render();
}
if (d->renderer) {
d->renderer->GetRenderWindow()->Render();
}
// if (d->renderer) {
// d->renderer->GetRenderWindow()->Render();
// }
}
vtkRenderer *dtkVisualizationCanvas::renderer(void)
......
......@@ -45,7 +45,7 @@ public:
public:
void reset(void);
void touch(void);
void draw(void);
public:
vtkRenderer *renderer(void);
......
......@@ -15,6 +15,7 @@
#include "dtkVisualizationDecorator.h"
#include "dtkVisualization.h"
#include "dtkVisualizationCanvas.h"
// ///////////////////////////////////////////////////////////////////
// Register to dtkVisualization layer
......@@ -28,9 +29,11 @@ namespace dtk { namespace visualization {
// dtkVisualizationDecorator implementation
// ///////////////////////////////////////////////////////////////////
void dtkVisualizationDecorator::render(void)
void dtkVisualizationDecorator::draw(void)
{
this->draw();
if (this->canvas()) {
this->canvas()->draw();
}
}
//
......
......@@ -35,8 +35,11 @@ public:
dtkVisualizationDecorator(void) = default;
~dtkVisualizationDecorator(void) = default;
public slots:
void render(void);
public:
virtual void touch(void) = 0;
protected:
void draw(void);
public:
virtual bool isDecorating(void) = 0;
......@@ -50,9 +53,6 @@ public:
virtual dtkVisualizationCanvas *canvas(void) const = 0;
virtual QList<QWidget *> inspectors(void) const = 0;
protected:
virtual void draw(void) = 0;
};
// ///////////////////////////////////////////////////////////////////
......
......@@ -173,7 +173,7 @@ dtkVisualizationDecoratorClutEditor::~dtkVisualizationDecoratorClutEditor(void)
d = nullptr;
}
void dtkVisualizationDecoratorClutEditor::draw(void)
void dtkVisualizationDecoratorClutEditor::touch(void)
{
if (!d->dataset || d->current_field_name.isEmpty()) {
dtkWarn() << Q_FUNC_INFO << "Set dataset and field name before updating actor.";
......@@ -192,11 +192,9 @@ void dtkVisualizationDecoratorClutEditor::draw(void)
double *range;
if (d->supports[d->current_field_name] == dtkVisualizationDecoratorClutEditorPrivate::Support::Point) {
d->dataset->GetPointData()->SetActiveScalars(qPrintable(d->current_field_name));
range = d->dataset->GetPointData()->GetScalars()->GetRange();
range = d->dataset->GetPointData()->GetArray(qPrintable(d->current_field_name))->GetRange();
} else if (d->supports[d->current_field_name] == dtkVisualizationDecoratorClutEditorPrivate::Support::Cell) {
d->dataset->GetCellData()->SetActiveScalars(qPrintable(d->current_field_name));
range = d->dataset->GetCellData()->GetScalars()->GetRange();
range = d->dataset->GetCellData()->GetArray(qPrintable(d->current_field_name))->GetRange();
}
this->setCurrentRange(range[0], range[1]);
......
......@@ -57,8 +57,8 @@ public:
void setCurrentOpacityTransferFunction(vtkSmartPointer<vtkPiecewiseFunction>);
void setCurrentRange(double, double);
protected:
void draw(void) override;
public:
void touch(void) override;
protected:
class dtkVisualizationDecoratorClutEditorPrivate *d;
......
......@@ -214,7 +214,7 @@ dtkVisualizationDecoratorClutEditorSimple::~dtkVisualizationDecoratorClutEditorS
d = nullptr;
}
void dtkVisualizationDecoratorClutEditorSimple::draw(void)
void dtkVisualizationDecoratorClutEditorSimple::touch(void)
{
if (!d->dataset || d->current_field_name.isEmpty()) {
dtkWarn() << Q_FUNC_INFO << "Set dataset and field name before updating actor.";
......@@ -232,11 +232,9 @@ void dtkVisualizationDecoratorClutEditorSimple::draw(void)
if(!d->fixed_range->isChecked()) {
double *range;
if (d->supports[d->current_field_name] == dtkVisualizationDecoratorClutEditorSimplePrivate::Support::Point) {
d->dataset->GetPointData()->SetActiveScalars(qPrintable(d->current_field_name));
range = d->dataset->GetPointData()->GetScalars()->GetRange();
range = d->dataset->GetPointData()->GetArray(qPrintable(d->current_field_name))->GetRange();
} else if (d->supports[d->current_field_name] == dtkVisualizationDecoratorClutEditorSimplePrivate::Support::Cell) {
d->dataset->GetCellData()->SetActiveScalars(qPrintable(d->current_field_name));
range = d->dataset->GetCellData()->GetScalars()->GetRange();
range = d->dataset->GetCellData()->GetScalars(qPrintable(d->current_field_name))->GetRange();
}
d->min_range->setText(QString::number(range[0]));
......
......@@ -57,8 +57,8 @@ public:
void setCurrentOpacityTransferFunction(vtkSmartPointer<vtkPiecewiseFunction>);
void setCurrentRange(double, double);
protected:
void draw(void) override;
public:
void touch(void) override;
protected:
class dtkVisualizationDecoratorClutEditorSimplePrivate *d;
......
......@@ -239,14 +239,14 @@ dtkVisualizationCanvas *dtkVisualizationDecoratorCollection::canvas(void) const
return nullptr;
}
void dtkVisualizationDecoratorCollection::render(void)
void dtkVisualizationDecoratorCollection::draw(void)
{
for (auto dec : d->collection) {
dec->render();
dec->touch();
}
auto canvas = this->canvas();
if (canvas) {
canvas->touch();
canvas->draw();
}
}
......
......@@ -80,7 +80,7 @@ public:
dtkVisualizationCanvas *canvas(void) const;
public slots:
void render(void);
void draw(void);
private:
class dtkVisualizationDecoratorCollectionPrivate *d = nullptr;
......
......@@ -137,18 +137,14 @@ dtkVisualizationDecoratorDelaunay2D::~dtkVisualizationDecoratorDelaunay2D(void)
d = nullptr;
}
void dtkVisualizationDecoratorDelaunay2D::draw(void)
void dtkVisualizationDecoratorDelaunay2D::touch(void)
{
if(!this->canvas()) {
dtkWarn() << Q_FUNC_INFO << "No canvas was set, call setCanvas to call draw on a canvas.";
return;
}
Q_ASSERT(this->canvas()->renderer());
if (this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
}
this->draw();
}
......@@ -195,10 +191,6 @@ void dtkVisualizationDecoratorDelaunay2D::setCanvas(dtkVisualizationCanvas *canv
if (d->delaunay->GetInput()) {
d->view->renderer()->AddActor(d->actor);
if(d->view->interactor()) {
d->view->interactor()->Render();
}
}
}
......@@ -218,10 +210,7 @@ void dtkVisualizationDecoratorDelaunay2D::show(void)
d->show_actor_cb->setCheckState(Qt::Checked);
d->show_actor_cb->blockSignals(false);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
this->canvas()->renderer()->GetRenderWindow()->Render();
}
this->draw();
}
void dtkVisualizationDecoratorDelaunay2D::hide(void)
......@@ -232,30 +221,21 @@ void dtkVisualizationDecoratorDelaunay2D::hide(void)
d->show_actor_cb->setCheckState(Qt::Unchecked);
d->show_actor_cb->blockSignals(false);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
this->canvas()->renderer()->GetRenderWindow()->Render();
}
this->draw();
}
void dtkVisualizationDecoratorDelaunay2D::setColor(const QColor& color)
{
d->actor->GetProperty()->SetColor(color.red(), color.green(), color.blue());
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
this->canvas()->renderer()->GetRenderWindow()->Render();
}
this->draw();
}
void dtkVisualizationDecoratorDelaunay2D::setOpacity(const double& alpha)
{
d->actor->GetProperty()->SetOpacity(alpha);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
this->canvas()->renderer()->GetRenderWindow()->Render();
}
this->draw();
}
QVariant dtkVisualizationDecoratorDelaunay2D::data(void) const
......
......@@ -46,8 +46,8 @@ public:
virtual void setColor(const QColor&);
virtual void setOpacity(const double&);
protected:
void draw(void) override;
public:
void touch(void) override;
signals:
......
......@@ -222,7 +222,7 @@ void dtkVisualizationDecoratorInfo::setInformation(const QString& key, QWidget *
d->layout->addRow(key, value);
}
void dtkVisualizationDecoratorInfo::draw(void)
void dtkVisualizationDecoratorInfo::touch(void)
{
}
......
......@@ -43,8 +43,7 @@ public:
QList<QWidget *> inspectors(void) const override;
protected:
void draw(void) override;
void touch(void) override;
protected:
class dtkVisualizationDecoratorInfoPrivate *d;
......
......@@ -145,7 +145,7 @@ dtkVisualizationDecoratorPoints::~dtkVisualizationDecoratorPoints(void)
d = nullptr;
}
void dtkVisualizationDecoratorPoints::draw(void)
void dtkVisualizationDecoratorPoints::touch(void)
{
if(!this->canvas()) {
dtkWarn() << Q_FUNC_INFO << "No canvas was set, call setCanvas to call draw on a canvas.";
......
......@@ -38,6 +38,8 @@ public:
QList<QWidget *> inspectors(void) const override;
void touch(void) override;
public:
void show(void);
void hide(void);
......@@ -47,9 +49,6 @@ public:
virtual void setOpacity(const double&);
virtual void setSize(const double&);
protected:
void draw(void) override;
signals:
void updated(void);
......
......@@ -84,6 +84,7 @@ dtkVisualizationDecoratorScalarColorMap::dtkVisualizationDecoratorScalarColorMap
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
this->setVisibility(state == Qt::Checked);
this->draw();
});
d->show_actor_cb->setObjectName("Display");
......@@ -99,11 +100,6 @@ dtkVisualizationDecoratorScalarColorMap::~dtkVisualizationDecoratorScalarColorMa
d = nullptr;
}
void dtkVisualizationDecoratorScalarColorMap::draw(void)
{
dtkVisualizationDecoratorWithClut::draw();
}
void dtkVisualizationDecoratorScalarColorMap::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
......@@ -112,25 +108,25 @@ void dtkVisualizationDecoratorScalarColorMap::setData(const QVariant& data)
return;
}
dtkVisualizationDecoratorWithClut::clear();
dtkVisualizationDecoratorWithClut::d->retrieveScalarPoints(dataset);
dtkVisualizationDecoratorWithClut::d->retrieveScalarCells(dataset);
d_func()->clear();
d_func()->retrieveScalarPoints(dataset);
d_func()->retrieveScalarCells(dataset);
if (!this->isDecorating()) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet has no field to decorate. Nothing is done.";
dtkVisualizationDecoratorWithClut::clear();
d_func()->clear();
return;
}
d_func()->dataset = dataset;
d->mapper->SetInputData(d_func()->dataset);
dtkVisualizationDecoratorWithClut::sortEligibleFields();
d_func()->sortEligibleFields();
if (this->canvas()) {
this->canvas()->renderer()->AddActor(d->actor);
}
dtkVisualizationDecoratorWithClut::enableScalarBar();
d_func()->enableScalarBar();
}
void dtkVisualizationDecoratorScalarColorMap::setCanvas(dtkVisualizationCanvas *canvas)
......@@ -147,7 +143,7 @@ void dtkVisualizationDecoratorScalarColorMap::setCanvas(dtkVisualizationCanvas *
d_func()->view->renderer()->AddActor(d->actor);
}
dtkVisualizationDecoratorWithClut::enableScalarBar();
d_func()->enableScalarBar();
}
void dtkVisualizationDecoratorScalarColorMap::unsetCanvas(void)
......@@ -156,7 +152,7 @@ void dtkVisualizationDecoratorScalarColorMap::unsetCanvas(void)
d_func()->view->renderer()->RemoveActor(d->actor);
}
dtkVisualizationDecoratorWithClut::disableScalarBar();
d_func()->disableScalarBar();
d_func()->view = nullptr;
}
......@@ -167,20 +163,6 @@ void dtkVisualizationDecoratorScalarColorMap::setVisibility(bool visible)
dtkVisualizationDecoratorWithClut::setVisibility(visible);
}
void dtkVisualizationDecoratorScalarColorMap::show(void)
{
d->actor->SetVisibility(true);
if (this->canvas())
this->canvas()->touch();
}
void dtkVisualizationDecoratorScalarColorMap::hide(void)
{
d->actor->SetVisibility(false);
if (this->canvas())
this->canvas()->touch();
}
bool dtkVisualizationDecoratorScalarColorMap::setCurrentFieldName(const QString& field_name)
{
if (!dtkVisualizationDecoratorWithClut::setCurrentFieldName(field_name)) {
......@@ -188,17 +170,14 @@ bool dtkVisualizationDecoratorScalarColorMap::setCurrentFieldName(const QString&
}
using Support = dtkVisualizationDecoratorWithClut::Support;
int support = d_func()->supports[d_func()->current_field_name];
int support = d_func()->supports[field_name];
if(support == Support::Point) {
d->mapper->SetScalarModeToUsePointFieldData();
} else if(support == Support::Cell) {
d->mapper->SetScalarModeToUseCellFieldData();
}
d->mapper->SelectColorArray(qPrintable(field_name));
d->mapper->Modified();
d->actor->Modified();
if (this->canvas())
this->canvas()->touch();
return true;
}
......
......@@ -38,13 +38,6 @@ protected:
public:
void setVisibility(bool) override;
public:
void show(void);
void hide(void);
protected:
void draw(void) override;
protected:
class dtkVisualizationDecoratorScalarColorMapPrivate *d;
};
......
......@@ -36,8 +36,7 @@ protected:
void setColorMap(const QMap<double, QColor>&) override;
public:
void show(void);
void hide(void);
void setVisibility(bool) override;
public:
void setCurrentGlyphsSize(double);
......@@ -47,9 +46,6 @@ signals:
void currentGlyphsSizeChanged(double);
void currentGlyphsSourceChanged(const QString&);
protected:
void draw(void) override;
protected:
class dtkVisualizationDecoratorScalarGlyphsPrivate *d = nullptr;
};
......
......@@ -25,30 +25,25 @@ public:
dtkVisualizationDecoratorScalarIsolines(void);
~dtkVisualizationDecoratorScalarIsolines(void);
public:
void touch(void) override;
public:
void setData(const QVariant&) override;
void setCanvas(dtkVisualizationCanvas *) override;
void unsetCanvas(void) override;
protected:
void setCurrentRange(double, double) override;
bool setCurrentFieldName(const QString&) override;
void setColorMap(const QMap<double, QColor>&) override;
public:
void show(void);
void hide(void);
void setVisibility(bool) override;
public:
void setCurrentIsolinesRange(double, double);
void setCurrentIsolinesCount(std::size_t);
signals:
void currentIsolinesRangeChanged(double, double);
void currentIsolinesCountChanged(std::size_t);
protected:
void draw(void) override;
protected:
class dtkVisualizationDecoratorScalarIsolinesPrivate *d = nullptr;
};
......
......@@ -93,7 +93,7 @@ dtkVisualizationDecoratorSnapshot::~dtkVisualizationDecoratorSnapshot(void)
d = nullptr;
}
void dtkVisualizationDecoratorSnapshot::draw(void)
void dtkVisualizationDecoratorSnapshot::touch(void)
{
}
......
......@@ -34,6 +34,8 @@ public:
QVariant data(void) const override;
dtkVisualizationCanvas *canvas(void) const override;
void touch(void) override;
public:
void setData(const QVariant&) override;
void setCanvas(dtkVisualizationCanvas *) override;
......@@ -43,9 +45,6 @@ public:
void show(void);
void hide(void);
protected:
void draw(void) override;
signals:
void updated(void);
......
......@@ -163,11 +163,6 @@ dtkVisualizationDecoratorVectorStreamlines::~dtkVisualizationDecoratorVectorStre
d = nullptr;
}
void dtkVisualizationDecoratorVectorStreamlines::draw(void)
{
//dtkVisualizationDecoratorWithClut::draw();
}
bool dtkVisualizationDecoratorVectorStreamlines::isCurrentFieldUniform(void)
{
auto r = d_func()->ranges[d_func()->current_field_name];
......@@ -185,13 +180,13 @@ void dtkVisualizationDecoratorVectorStreamlines::setData(const QVariant& data)
return;
}
dtkVisualizationDecoratorWithClut::clear();
dtkVisualizationDecoratorWithClut::d->retrieveVectorPoints(dataset);
dtkVisualizationDecoratorWithClut::d->retrieveVectorCells(dataset);
d_func()->clear();
d_func()->retrieveVectorPoints(dataset);
d_func()->retrieveVectorCells(dataset);
if (!this->isDecorating()) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet has no field to decorate. Nothing is done.";
dtkVisualizationDecoratorWithClut::clear();
d_func()->clear();
return;
}
......@@ -215,14 +210,14 @@ void dtkVisualizationDecoratorVectorStreamlines::setData(const QVariant& data)
d->source->Modified();
dtkVisualizationDecoratorWithClut::sortEligibleFields();
d_func()->sortEligibleFields();
if (this->canvas()) {
this->canvas()->renderer()->AddActor(d->actor);
this->canvas()->renderer()->AddActor(d->source_actor);
}
dtkVisualizationDecoratorWithClut::enableScalarBar();
d_func()->enableScalarBar();
}
void dtkVisualizationDecoratorVectorStreamlines::setCanvas(dtkVisualizationCanvas *canvas)
......@@ -240,7 +235,7 @@ void dtkVisualizationDecoratorVectorStreamlines::setCanvas(dtkVisualizationCanva
d_func()->view->renderer()->AddActor(d->source_actor);
}
dtkVisualizationDecoratorWithClut::enableScalarBar();
d_func()->enableScalarBar();
}
void dtkVisualizationDecoratorVectorStreamlines::unsetCanvas(void)
......@@ -250,7 +245,7 @@ void dtkVisualizationDecoratorVectorStreamlines::unsetCanvas(void)
d_func()->view->renderer()->RemoveActor(d->source_actor);
}
dtkVisualizationDecoratorWithClut::disableScalarBar();
d_func()->disableScalarBar();
d_func()->view = nullptr;
}
......@@ -258,15 +253,13 @@ void dtkVisualizationDecoratorVectorStreamlines::unsetCanvas(void)
void dtkVisualizationDecoratorVectorStreamlines::show(void)
{
d->actor->SetVisibility(true);
if (this->canvas())
this->canvas()->touch();
this->draw();
}
void dtkVisualizationDecoratorVectorStreamlines::hide(void)
{
d->actor->SetVisibility(false);
if (this->canvas())
this->canvas()->touch();
this->draw();
}
bool dtkVisualizationDecoratorVectorStreamlines::setCurrentFieldName(const QString& field_name)
......
......@@ -26,21 +26,18 @@ public:
~dtkVisualizationDecoratorVectorStreamlines(void);
public:
void setData(const QVariant&) override;
void setData(const QVariant&) override;
void setCanvas(dtkVisualizationCanvas *) override;
void unsetCanvas(void) override;
void unsetCanvas(void) override;
protected:
bool setCurrentFieldName(const QString&) override;
bool setCurrentFieldName(const QString&) override;
void setColorMap(const QMap<double, QColor>&) override;
public:
void show(void);
void hide(void);
protected:
void draw(void) override;
protected:
bool isCurrentFieldUniform(void);
......
......@@ -94,6 +94,30 @@ dtkVisualizationDecoratorWithClutPrivate::dtkVisualizationDecoratorWithClutPriva
}
void dtkVisualizationDecoratorWithClutPrivate::clear(void)
{
this->current_field_name.clear();
this->eligible_field_names.clear();
this->color_transfer_functions.clear();
this->opacity_functions.clear();
this->ranges.clear();
this->supports.clear();
}
void dtkVisualizationDecoratorWithClutPrivate::enableScalarBar(void)
{
if (this->view && this->dataset) {
this->view->addScalarBar(this->scalar_bar);
}
}
void dtkVisualizationDecoratorWithClutPrivate::disableScalarBar(void)
{
if (this->view) {
this->view->removeScalarBar(this->scalar_bar);
}
}
void dtkVisualizationDecoratorWithClutPrivate::retrieveScalarData(vtkDataSetAttributes *field_data, Support support)
{
vtkIdType nb_arrays = field_data->GetNumberOfArrays();
......@@ -180,35 +204,17 @@ void dtkVisualizationDecoratorWithClutPrivate::retrieveVectorCells(vtkDataSet *d