Commit 494da115 authored by CABEL Tristan's avatar CABEL Tristan

Merge branch 'feature/decorator_collection' into 'develop'

Feature/decorator collection

See merge request !28
parents 953a89cc 11e8ddc3
......@@ -42,7 +42,9 @@ class dtkVisualizationViewerPrivate
{
public:
dtkVisualizationViewerStack *stack = nullptr;
dtkVisualizationDecoratorCollection collection;
vtkDataSet *dataset = nullptr;
double v_max = 100.;
public:
void createPlot2DData(dtkVisualizationPlot2D *plot);
......@@ -50,20 +52,27 @@ public:
};
void dtkVisualizationViewerPrivate::drunkData(double time)
void dtkVisualizationViewerPrivate::drunkData(double val)
{
if(!dataset) {
qInfo() << "import a dataset before calling this method";
}
qDebug() << "time" << time;
//qDebug() << "val" << val;
if(time == 1.) {
if(val == 1.) {
qDebug() << "nb points array" << dataset->GetPointData()->GetNumberOfArrays();
qDebug() << "nb cells array" << dataset->GetCellData()->GetNumberOfArrays();
}
double new_value[3] = {time, 1.5*time, -1.*time};
vtkIdType nb_points = dataset->GetNumberOfPoints();
vtkIdType nb_cells = dataset->GetNumberOfCells();
double xyz[3];
double new_value[3] = {val, 1.5*val, -1.*val};
double bounds[6]; //x_min , x_max , y_min , y_max , z_min , z_max
dataset->GetBounds(bounds);
{
vtkPointData *point_data = dataset->GetPointData();
......@@ -71,14 +80,24 @@ void dtkVisualizationViewerPrivate::drunkData(double time)
for (vtkIdType i = 0; i < nb_arrays; ++i) {
vtkDataArray *array = point_data->GetArray(i);
int nb_tuples = array->GetNumberOfTuples();
for(int t=0; t < nb_tuples; ++t) {
new_value[0] = time * ((double)t / nb_tuples);
new_value[1] = 1.5 * time * ((double)t / nb_tuples);
new_value[2] = -1. * time * ((double)t / nb_tuples);
array->SetTuple(t, new_value);
vtkIdType nb_tuples = array->GetNumberOfTuples();
vtkIdType nb_cmpts = array->GetNumberOfComponents();
if (nb_cmpts == 1) {
for(vtkIdType t=0; t < nb_tuples; ++t) {
dataset->GetPoint(t, xyz);
double value = val * std::cos(val + ((xyz[0] - bounds[0])/bounds[1]));
array->SetTuple1(t, value);
}
} else if (nb_cmpts == 3) {
for(vtkIdType t=0; t < nb_tuples; ++t) {
dataset->GetPoint(t, xyz);
new_value[0] = val * std::cos(val + ((xyz[0] - bounds[0])/bounds[1]));
new_value[1] = val * std::cos(val + ((xyz[1] - bounds[2])/bounds[3]));
new_value[2] = val * std::cos(val + ((xyz[2] - bounds[4])/bounds[5]));
array->SetTuple3(t, new_value[0], new_value[1], new_value[2]);
}
}
array->Modified();
}
}
{
......@@ -87,14 +106,27 @@ void dtkVisualizationViewerPrivate::drunkData(double time)
for (vtkIdType i = 0; i < nb_arrays; ++i) {
vtkDataArray *array = cell_data->GetArray(i);
int nb_tuples = array->GetNumberOfTuples();
for(int t=0; t < nb_tuples; ++t) {
new_value[0] = time * ((double)t / nb_tuples);
new_value[1] = 1.5 * time * ((double)t / nb_tuples);
new_value[2] = -1. * time * ((double)t / nb_tuples);
array->SetTuple(t, new_value);
vtkIdType nb_tuples = array->GetNumberOfTuples();
vtkIdType nb_cmpts = array->GetNumberOfComponents();
if (nb_cmpts == 1) {
for(vtkIdType t=0; t < nb_tuples; ++t) {
double cell_bounds[6];
dataset->GetCell(t)->GetBounds(cell_bounds);
double value = val * std::cos(val + ((cell_bounds[0] - bounds[0])/bounds[1]));
array->SetTuple1(t, value);
}
} else if (nb_cmpts == 3) {
for(vtkIdType t=0; t < nb_tuples; ++t) {
double cell_bounds[6];
dataset->GetCell(t)->GetBounds(cell_bounds);
new_value[0] = val * std::cos(val + ((cell_bounds[0] - bounds[0])/bounds[1]));
new_value[1] = val * std::cos(val + ((cell_bounds[2] - bounds[2])/bounds[3]));
new_value[2] = val * std::cos(val + ((cell_bounds[4] - bounds[4])/bounds[5]));
array->SetTuple3(t, new_value[0], new_value[1], new_value[2]);
}
}
array->Modified();
}
}
}
......@@ -200,9 +232,9 @@ dtkVisualizationViewer::dtkVisualizationViewer(QWidget *parent) : dtkWidgetsMain
//for animating data
// 20s to go from 0 to 100
// 20s to go from 0 to d->v_max
QTimeLine *timeline = new QTimeLine(20000, this); // 20 s
timeline->setFrameRange(0, 100);
timeline->setFrameRange(0, d->v_max);
connect(timeline, &QTimeLine::frameChanged,
[=](int time) {
d->drunkData(time);
......@@ -232,6 +264,8 @@ dtkVisualizationViewer::~dtkVisualizationViewer(void)
void dtkVisualizationViewer::importDataSet(const QString& path)
{
d->collection.clear();
QFileInfo info(path);
QSettings settings;
......@@ -241,7 +275,8 @@ void dtkVisualizationViewer::importDataSet(const QString& path)
dtkVisualizationCanvas *canvas = dynamic_cast<dtkVisualizationCanvas *>(d->stack->layout()->current()->view());
if(!canvas) return;
if(!canvas)
return;
d->dataset = dtkVisualizationVTKReader(path);
QVariant data = dtk::variantFromValue(d->dataset);
......@@ -255,33 +290,49 @@ void dtkVisualizationViewer::importDataSet(const QString& path)
dtkVisualizationDecoratorSnapshot *decorator_snapshot = new dtkVisualizationDecoratorSnapshot;
dtkVisualizationDecoratorVectorStreamlines *decorator_vector_streamlines = new dtkVisualizationDecoratorVectorStreamlines;
*decorator_info << *decorator_points << *decorator_delaunay_2D << *decorator_scalar_colormap << *decorator_scalar_isolines << *decorator_scalar_glyphs << *decorator_snapshot << *decorator_vector_streamlines;
QList<dtkVisualizationDecorator *> decorators;
decorators << decorator_points
<< decorator_delaunay_2D
<< decorator_scalar_colormap
<< decorator_scalar_isolines
<< decorator_scalar_glyphs
<< decorator_vector_streamlines
<< decorator_snapshot
;
for (auto dec : decorators) {
dec->setData(data);
if (dec->isDecorating()) {
d->collection << dec;
} else {
delete dec;
}
}
decorators.clear();
d->collection.setCanvas(canvas);
// setCanvas and setData on the first decorator.
decorator_info->setCanvas(canvas);
decorator_info->setData(data);
decorator_info->setCanvas(canvas);
decorator_info->setFileInfo(info);
QList<dtkVisualizationDecorator *> decorators;
decorators << decorator_points << decorator_delaunay_2D << decorator_scalar_colormap << decorator_scalar_isolines << decorator_scalar_glyphs << decorator_snapshot << decorator_vector_streamlines;
dtkWidgetsMenuBar *menu_bar = dtkApp->window()->menubar();
dtkWidgetsMenu *canvas_menu = menu_bar->menu("View " + canvas->objectName());
Q_ASSERT(canvas_menu);
for(auto inspector : decorator_info->inspectors()) {
dtkWidgetsMenuItemDIY *item = new dtkWidgetsMenuItemDIY(inspector->objectName(), inspector);
if (decorator_info->isDecorating()) {
for(auto inspector : decorator_info->inspectors()) {
dtkWidgetsMenuItemDIY *item = new dtkWidgetsMenuItemDIY(inspector->objectName(), inspector);
item->setSizePolicy(QSizePolicy::Expanding);
item->setSizePolicy(QSizePolicy::Expanding);
canvas_menu->addItem(item);
canvas_menu->addItem(item);
}
}
for(auto decorator : decorators) {
if (!decorator->isDecorating()) continue;
for(auto decorator : d->collection) {
dtkWidgetsMenu *menu = canvas_menu->menu(decorator->objectName());
......@@ -299,12 +350,13 @@ void dtkVisualizationViewer::importDataSet(const QString& path)
menu_bar->touch();
decorator_scalar_colormap->render();
d->collection.render();
//TODO complete
connect(this, &dtkVisualizationViewer::updated,
[=] (void) {
decorator_scalar_colormap->render();
d->collection.render();
});
}
......
......@@ -7,6 +7,7 @@
"filters": [
"VTK (*.vtk)",
"VTI (*.vti)",
"VTP (*.vtp)",
"VTU (*.vtu)"
],
"type": "dtk::d_path"
......
......@@ -25,14 +25,14 @@ set(${PROJECT_NAME}_HEADERS
dtkVisualizationCanvas.h
dtkVisualizationDecorator
dtkVisualizationDecorator.h
dtkVisualizationDecoratorWithClut
dtkVisualizationDecoratorWithClut.h
dtkVisualizationDecoratorClutEditor
dtkVisualizationDecoratorClutEditor.h
dtkVisualizationDecoratorClutEditorBase
dtkVisualizationDecoratorClutEditorBase.h
dtkVisualizationDecoratorClutEditorSimple
dtkVisualizationDecoratorClutEditorSimple.h
dtkVisualizationDecoratorCollection
dtkVisualizationDecoratorCollection.h
dtkVisualizationDecoratorDelaunay2D
dtkVisualizationDecoratorDelaunay2D.h
dtkVisualizationDecoratorInfo
......@@ -49,6 +49,8 @@ set(${PROJECT_NAME}_HEADERS
dtkVisualizationDecoratorSnapshot.h
dtkVisualizationDecoratorVectorStreamlines
dtkVisualizationDecoratorVectorStreamlines.h
dtkVisualizationDecoratorWithClut
dtkVisualizationDecoratorWithClut.h
dtkVisualizationMetaType
dtkVisualizationMetaType.h
dtkVisualizationMetaType.tpp
......@@ -82,9 +84,9 @@ set(${PROJECT_NAME}_SOURCES
dtkVisualization.cpp
dtkVisualizationCanvas.cpp
dtkVisualizationDecorator.cpp
dtkVisualizationDecoratorWithClut.cpp
dtkVisualizationDecoratorClutEditor.cpp
dtkVisualizationDecoratorClutEditorSimple.cpp
dtkVisualizationDecoratorCollection.cpp
dtkVisualizationDecoratorDelaunay2D.cpp
dtkVisualizationDecoratorInfo.cpp
dtkVisualizationDecoratorPoints.cpp
......@@ -93,6 +95,7 @@ set(${PROJECT_NAME}_SOURCES
dtkVisualizationDecoratorScalarIsolines.cpp
dtkVisualizationDecoratorSnapshot.cpp
dtkVisualizationDecoratorVectorStreamlines.cpp
dtkVisualizationDecoratorWithClut.cpp
dtkVisualizationMetaType.cpp
dtkVisualizationPlot2D.cpp
dtkVisualizationPlot3D.cpp
......@@ -111,6 +114,20 @@ set(${PROJECT_NAME}_SOURCES_QRC dtkVisualization.qrc)
set_property(SOURCE qrc_dtkVisualization.cpp PROPERTY SKIP_AUTOMOC ON)
## ###################################################################
## Config file
## ###################################################################
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.h.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.h")
set(${PROJECT_NAME}_HEADERS
${${PROJECT_NAME}_HEADERS}
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.h")
set(layer_BINARY_DIR "${PROJECT_BINARY_DIR}/..")
## #################################################################
## Build rules
## #################################################################
......@@ -152,6 +169,8 @@ target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${layer_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<BUILD_INTERFACE:${layer_BINARY_DIR}>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
$<INSTALL_INTERFACE:include>)
......
#include "dtkVisualization.h"
#include "dtkVisualizationCanvas.h"
#include "dtkVisualizationDecorator.h"
#include "dtkVisualizationDecoratorWithClut.h"
#include "dtkVisualizationDecoratorClutEditor.h"
#include "dtkVisualizationDecoratorClutEditorBase.h"
#include "dtkVisualizationDecoratorClutEditorSimple.h"
#include "dtkVisualizationDecoratorCollection.h"
#include "dtkVisualizationDecoratorDelaunay2D.h"
#include "dtkVisualizationDecoratorInfo.h"
#include "dtkVisualizationDecoratorPoints.h"
......@@ -13,6 +13,7 @@
#include "dtkVisualizationDecoratorScalarGlyphs.h"
#include "dtkVisualizationDecoratorSnapshot.h"
#include "dtkVisualizationDecoratorVectorStreamlines.h"
#include "dtkVisualizationDecoratorWithClut.h"
#include "dtkVisualizationMetaType.h"
#include "dtkVisualizationPlot2D.h"
#include "dtkVisualizationPlot3D.h"
......
......@@ -16,21 +16,58 @@
#include "dtkVisualizationMetaType.h"
#include <dtkVisualizationConfig.h>
#include <dtkCore>
namespace dtk { namespace visualization {
DTK_DEFINE_LAYER_MANAGER;
void activateObjectManager(void) {
manager().setObjectManager(dtkCoreObjectManager::instance());
}
void initialize(void)
{
initialize(QString());
}
void initialize(const QString& path)
void initialize(const QString& s)
{
dtk::visualization::registerVTKToMetaType();
QString path = s;
QStringList pathslist;
if (path.isEmpty()) {
//per default, it will use
// app->name
// app->organization
// user_space
// ini format since setDefaultFormat is set in dtkApplicationPrivate::initialize
QSettings settings;
path = settings.value("dtk-visualization/plugins").toString();
if (path.isEmpty()) {
path = QDir::cleanPath(DTKVISUALIZATION_INSTALL_PREFIX + "/plugins/dtkVisualization");
dtkDebug() << Q_FUNC_INFO << "No plugin path configured, use default:" << path;
}
}
pathslist = path.split(":");
for (auto p : pathslist) {
manager().initialize(p);
}
}
void uninitialize(void)
{
manager().uninitialize();
}
void setVerboseLoading(bool b)
{
manager().setVerboseLoading(b);
}
} };
......
......@@ -17,6 +17,7 @@
#include <dtkVisualizationExport>
class QString;
class dtkCoreLayerManager;
// ///////////////////////////////////////////////////////////////////
//
......@@ -24,8 +25,13 @@ class QString;
namespace dtk { namespace visualization {
DTKVISUALIZATION_EXPORT void initialize(void);
DTKVISUALIZATION_EXPORT void initialize(const QString& path);
DTKVISUALIZATION_EXPORT dtkCoreLayerManager& manager(void);
DTKVISUALIZATION_EXPORT void activateObjectManager(void);
DTKVISUALIZATION_EXPORT void initialize(void);
DTKVISUALIZATION_EXPORT void initialize(const QString& path);
DTKVISUALIZATION_EXPORT void setVerboseLoading(bool b);
DTKVISUALIZATION_EXPORT void uninitialize(void);
} };
......
......@@ -183,6 +183,23 @@ dtkWidgetsHUD *dtkVisualizationCanvas::hud(void)
return d->hud;
}
void dtkVisualizationCanvas::reset(void)
{
if (d->renderer) {
d->renderer->ResetCamera();
}
}
void dtkVisualizationCanvas::touch(void)
{
if (d->GetInteractor()) {
d->GetInteractor()->Render();
}
if (d->renderer) {
d->renderer->GetRenderWindow()->Render();
}
}
vtkRenderer *dtkVisualizationCanvas::renderer(void)
{
return d->renderer;
......
......@@ -43,6 +43,10 @@ public slots:
public:
dtkWidgetsHUD *hud(void);
public:
void reset(void);
void touch(void);
public:
vtkRenderer *renderer(void);
vtkRenderWindowInteractor *interactor(void);
......
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#define dtkVisualization_VERSION_MAJOR @dtkVisualization_VERSION_MAJOR@
#define dtkVisualization_VERSION_MINOR @dtkVisualization_VERSION_MINOR@
#define dtkVisualization_VERSION_PATCH @dtkVisualization_VERSION_PATCH@
#include <QString>
static const QString DTKVISUALIZATION_INSTALL_PREFIX = "@CMAKE_INSTALL_PREFIX@";
//
// dtkVisualizationConfig.h.in ends here
......@@ -13,116 +13,24 @@
// Code:
#include "dtkVisualizationDecorator.h"
#include "dtkVisualizationDecorator_p.h"
#include "dtkVisualizationCanvas.h"
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include "dtkVisualization.h"
// ///////////////////////////////////////////////////////////////////
// dtkVisualizationDecorator implementation
// Register to dtkVisualization layer
// ///////////////////////////////////////////////////////////////////
dtkVisualizationDecorator::dtkVisualizationDecorator(const QString &name) : d(new dtkVisualizationDecoratorPrivate)
{
d->name = name;
}
namespace dtk { namespace visualization {
DTK_DEFINE_CONCEPT(dtkVisualizationDecorator, decorator, dtk::visualization);
} }
dtkVisualizationDecorator::~dtkVisualizationDecorator(void)
{
delete d;
d = nullptr;
}
// ///////////////////////////////////////////////////////////////////
// dtkVisualizationDecorator implementation
// ///////////////////////////////////////////////////////////////////
void dtkVisualizationDecorator::render(void)
{
auto root = this;
while(root->previous()) {
root = root->previous();
}
root->drawAndForward();
}
void dtkVisualizationDecorator::drawAndForward(void)
{
this->draw();
if (d->next) {
d->next->drawAndForward();
} else {
if(!this->canvas()) return;
this->canvas()->renderer()->GetRenderWindow()->Render();
}
}
void dtkVisualizationDecorator::setData(const QVariant& v)
{
d->data = v;
if (d->next) {
d->next->setData(v);
}
if (!this->canvas()) {
return;
}
this->canvas()->renderer()->ResetCamera();
}
void dtkVisualizationDecorator::setCanvas(dtkVisualizationCanvas *c)
{
d->canvas = c;
if (d->next) {
d->next->setCanvas(c);
}
c->renderer()->ResetCamera();
}
void dtkVisualizationDecorator::unsetCanvas(void)
{
d->canvas = nullptr;
}
QVariant dtkVisualizationDecorator::data(void) const
{
return d->data;
}
dtkVisualizationCanvas *dtkVisualizationDecorator::canvas(void) const
{
return d->canvas;
}
dtkVisualizationDecorator &dtkVisualizationDecorator::operator << (dtkVisualizationDecorator &next)
{
if (d->next) {
d->next->d->previous = &next;
next.d->next = d->next;
}
d->next = &next;
d->next->d->previous = this;
return *this;
}
dtkVisualizationDecorator *dtkVisualizationDecorator::previous(void) const
{
return d->previous;
}
dtkVisualizationDecorator *dtkVisualizationDecorator::next(void) const
{
return d->next;
}
void dtkVisualizationDecorator::reset(void)
{
d->previous = nullptr;
d->next= nullptr;
}
const QList<QWidget *>& dtkVisualizationDecorator::inspectors(void) const
{
return d->inspectors;
}
//
......
......@@ -16,13 +16,15 @@
#include <dtkVisualizationExport>
#include <QtCore>
#include <dtkCore>
#include <QtCore/QObject>
class dtkVisualizationCanvas;
class QWidget;
// ///////////////////////////////////////////////////////////////////
// dtkVisualizationDataDecorator declaration
// dtkVisualizationDecorator declaration
// ///////////////////////////////////////////////////////////////////
class DTKVISUALIZATION_EXPORT dtkVisualizationDecorator : public QObject
......@@ -30,8 +32,8 @@ class DTKVISUALIZATION_EXPORT dtkVisualizationDecorator : public QObject
Q_OBJECT
public:
dtkVisualizationDecorator(const QString& name = QString());
~dtkVisualizationDecorator(void);
dtkVisualizationDecorator(void) = default;
~dtkVisualizationDecorator(void) = default;
public slots:
void render(void);
......@@ -39,33 +41,36 @@ public slots:
public:
virtual bool isDecorating(void) = 0;
public:
virtual void setData(const QVariant&);
virtual void setCanvas(dtkVisualizationCanvas *);
virtual void unsetCanvas(void);
public:
QVariant data(void) const;
dtkVisualizationCanvas *canvas(void) const;
virtual void setData(const QVariant&) = 0;
dtkVisualizationDecorator &operator << (dtkVisualizationDecorator &);
virtual void setCanvas(dtkVisualizationCanvas *) = 0;
virtual void unsetCanvas(void) = 0;
dtkVisualizationDecorator *previous(void) const;
dtkVisualizationDecorator *next(void) const;
virtual QVariant data(void) const = 0;
virtual dtkVisualizationCanvas *canvas(void) const = 0;
void reset(void);
public:
virtual const QList<QWidget *>& inspectors(void) const;
virtual QList<QWidget *> inspectors(void) const = 0;
protected:
virtual void draw(void) = 0;
};
void drawAndForward(void);
// ///////////////////////////////////////////////////////////////////
// Give the concept the plugin machinery
// ///////////////////////////////////////////////////////////////////
protected:
class dtkVisualizationDecoratorPrivate *d = nullptr;
};
DTK_DECLARE_OBJECT (dtkVisualizationDecorator *)
DTK_DECLARE_PLUGIN (dtkVisualizationDecorator, DTKVISUALIZATION_EXPORT)
DTK_DECLARE_PLUGIN_FACTORY(dtkVisualizationDecorator, DTKVISUALIZATION_EXPORT)
DTK_DECLARE_PLUGIN_MANAGER(dtkVisualizationDecorator, DTKVISUALIZATION_EXPORT)
// /////////////////////////////////////////////////////////////////
// Register to dtkVisualization layer
// /////////////////////////////////////////////////////////////////
namespace dtk { namespace visualization {
DTK_DECLARE_CONCEPT(dtkVisualizationDecorator, DTKVISUALIZATION_EXPORT, decorator);
} }
//
// dtkVisualizationDecorator.h ends here
......@@ -14,8 +14,6 @@
#include "dtkVisualizationDecoratorClutEditor.h"
#include "dtkVisualizationDecorator_p.h"
#include "dtkVisualizationCanvas.h"
#include "dtkVisualizationMetaType.h"
#include "dtkVisualizationView2D.h"
......@@ -45,7 +43,11 @@
class dtkVisualizationDecoratorClutEditorPrivate
{