Commit 6dd2ad97 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

first draft of Volume decorator

parent 9888b5e4
......@@ -211,6 +211,14 @@ dtkVisualizationViewer::dtkVisualizationViewer(QWidget *parent) : dtkWidgetsMain
QHash<QString, dtkCoreParameter *> parameters = menubar_generator.parameters();
// Restore last path used from the settings
QSettings settings;
settings.beginGroup("viewer");
QString default_path = settings.value("last_import_dir").toString();
if (!default_path.isEmpty())
parameters["open"]->setValue(default_path);
settings.endGroup();
dtkCoreParameter *open_parameter = parameters["open"];
if(open_parameter) {
open_parameter->connect([=] (QVariant v) {
......@@ -297,6 +305,7 @@ void dtkVisualizationViewer::importDataSet(const QString& path)
dtkVisualizationDecoratorScalarIsolines *decorator_scalar_isolines = new dtkVisualizationDecoratorScalarIsolines;
dtkVisualizationDecoratorSnapshot *decorator_snapshot = new dtkVisualizationDecoratorSnapshot;
dtkVisualizationDecoratorVectorStreamlines *decorator_vector_streamlines = new dtkVisualizationDecoratorVectorStreamlines;
dtkVisualizationDecoratorVolume *decorator_volume = new dtkVisualizationDecoratorVolume;
QList<dtkVisualizationDecorator *> decorators;
decorators << decorator_points
......@@ -305,6 +314,7 @@ void dtkVisualizationViewer::importDataSet(const QString& path)
<< decorator_scalar_isolines
<< decorator_scalar_glyphs
<< decorator_vector_streamlines
<< decorator_volume
<< decorator_snapshot
;
......
......@@ -15,6 +15,7 @@
#include <QtGui>
#include <QVTKOpenGLWidget.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <dtkCore>
#include <dtkCoreRuntime>
......@@ -36,7 +37,8 @@ int main(int argc, char **argv)
dtkThemesEngine::instance()->apply();
QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
//QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
vtkOpenGLRenderWindow::SetGlobalMaximumNumberOfMultiSamples(0);
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
dtkApplication *application = dtkApplication::create(argc, argv);
application->setApplicationName("dtkVisualizationViewer");
......
......@@ -49,6 +49,8 @@ set(${PROJECT_NAME}_HEADERS
dtkVisualizationDecoratorSnapshot.h
dtkVisualizationDecoratorVectorStreamlines
dtkVisualizationDecoratorVectorStreamlines.h
dtkVisualizationDecoratorVolume
dtkVisualizationDecoratorVolume.h
dtkVisualizationDecoratorWithClut
dtkVisualizationDecoratorWithClut.h
dtkVisualizationMetaType
......@@ -95,6 +97,7 @@ set(${PROJECT_NAME}_SOURCES
dtkVisualizationDecoratorScalarIsolines.cpp
dtkVisualizationDecoratorSnapshot.cpp
dtkVisualizationDecoratorVectorStreamlines.cpp
dtkVisualizationDecoratorVolume.cpp
dtkVisualizationDecoratorWithClut.cpp
dtkVisualizationMetaType.cpp
dtkVisualizationPlot2D.cpp
......
......@@ -13,6 +13,7 @@
#include "dtkVisualizationDecoratorScalarGlyphs.h"
#include "dtkVisualizationDecoratorSnapshot.h"
#include "dtkVisualizationDecoratorVectorStreamlines.h"
#include "dtkVisualizationDecoratorVolume.h"
#include "dtkVisualizationDecoratorWithClut.h"
#include "dtkVisualizationMetaType.h"
#include "dtkVisualizationPlot2D.h"
......
#include "dtkVisualizationDecoratorVolume.h"
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkVisualizationDecoratorVolume.h"
#include "dtkVisualizationDecoratorWithClut_p.h"
#include "dtkVisualizationMetaType.h"
#include "dtkVisualizationView2D.h"
#include <dtkLog>
#include <QtGui>
#include <QtWidgets>
#include <vtkActor.h>
#include <vtkAssembly.h>
#include <vtkAxesActor.h>
#include <vtkAxisActor.h>
#include <vtkCellDataToPointData.h>
#include <vtkColorTransferFunction.h>
#include <vtkCellData.h>
#include <vtkCubeAxesActor.h>
#include <vtkDataSet.h>
#include <vtkDataSetMapper.h>
#include <vtkLookupTable.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkOutlineFilter.h>
#include <vtkPiecewiseFunction.h>
#include <vtkPointData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkSmartPointer.h>
#include <vtkSmartVolumeMapper.h>
#include <vtkTextProperty.h>
#include <vtkTransformFilter.h>
#include <vtkTransformPolyDataFilter.h>
#include <vtkVolumeProperty.h>
// ///////////////////////////////////////////////////////////////////
// dtkVisualizationDecoratorVolumePrivate declaration
// ///////////////////////////////////////////////////////////////////
class dtkVisualizationDecoratorVolumePrivate
{
public:
vtkSmartPointer<vtkAssembly> actor;
vtkSmartPointer<vtkSmartVolumeMapper> mapper;
vtkSmartPointer<vtkVolume> volume;
vtkSmartPointer<vtkVolumeProperty> volume_property;
vtkSmartPointer<vtkPiecewiseFunction> opacity_transfer_function;
vtkSmartPointer<vtkOutlineFilter> outline_contour;
vtkSmartPointer<vtkActor> outline_contour_actor;
vtkSmartPointer<vtkPolyDataMapper> outline_contour_mapper;
vtkSmartPointer<vtkCubeAxesActor> cube_axes_actor;
vtkSmartPointer<vtkAxesActor> axes;
vtkSmartPointer<vtkOrientationMarkerWidget> marker;
vtkSmartPointer<vtkCellDataToPointData> c2p_filter;
public:
QCheckBox *show_actor_cb = nullptr;
QCheckBox *show_axes_cb = nullptr;
QCheckBox *show_cube_axes_cb = nullptr;
public slots:
void onCanvasFocused(void);
};
// ///////////////////////////////////////////////////////////////////
// dtkVisualizationDecoratorVolume implementation
// ///////////////////////////////////////////////////////////////////
dtkVisualizationDecoratorVolume::dtkVisualizationDecoratorVolume(void): dtkVisualizationDecoratorWithClut(), d(new dtkVisualizationDecoratorVolumePrivate())
{
d->c2p_filter = vtkSmartPointer<vtkCellDataToPointData>::New();
d->mapper = vtkSmartPointer<vtkSmartVolumeMapper>::New();
d->mapper->SetRequestedRenderMode(vtkSmartVolumeMapper::DefaultRenderMode);
d->opacity_transfer_function = vtkSmartPointer<vtkPiecewiseFunction>::New();
d->outline_contour = vtkSmartPointer<vtkOutlineFilter>::New();
d->outline_contour_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
d->outline_contour_mapper->SetInputConnection(d->outline_contour->GetOutputPort());
d->outline_contour_actor = vtkSmartPointer<vtkActor>::New();
d->outline_contour_actor->SetMapper(d->outline_contour_mapper);
d->outline_contour_actor->GetProperty()->SetColor(1, 0, 0);
d->outline_contour_actor->SetVisibility(1);
d->volume_property = vtkSmartPointer<vtkVolumeProperty>::New();
d->volume_property->SetInterpolationTypeToLinear();
d->volume_property->SetScalarOpacity(d->opacity_transfer_function);
d->volume_property->ShadeOff();
d->volume_property->SetAmbient(0.1);
d->volume_property->SetDiffuse(0.5);
d->volume_property->SetSpecular(0.4);
d->volume = vtkSmartPointer<vtkVolume>::New();
d->volume->SetMapper(d->mapper);
d->volume->SetProperty(d->volume_property);
d->actor = vtkSmartPointer<vtkAssembly>::New();
d->actor->AddPart(d->volume);
d->actor->AddPart(d->outline_contour_actor);
// d->cube_axes_actor = vtkSmartPointer<vtkCubeAxesActor>::New();
// d->cube_axes_actor->GetTitleTextProperty(0)->SetColor(0.8, 0.0, 0.0);
// d->cube_axes_actor->GetLabelTextProperty(0)->SetColor(0.8, 0.0, 0.0);
// d->cube_axes_actor->GetXAxesLinesProperty()->SetColor(0.2, 0.2, 0.2);
// d->cube_axes_actor->GetTitleTextProperty(1)->SetColor(0.0, 0.5, 0.0);
// d->cube_axes_actor->GetLabelTextProperty(1)->SetColor(0.0, 0.5, 0.0);
// d->cube_axes_actor->GetYAxesLinesProperty()->SetColor(0.2, 0.2, 0.2);
// d->cube_axes_actor->GetTitleTextProperty(2)->SetColor(0.0, 0.5, 1.0);
// d->cube_axes_actor->GetLabelTextProperty(2)->SetColor(0.0, 0.5, 1.0);
// d->cube_axes_actor->GetZAxesLinesProperty()->SetColor(0.2, 0.2, 0.2);
// d->cube_axes_actor->XAxisMinorTickVisibilityOff();
// d->cube_axes_actor->YAxisMinorTickVisibilityOff();
// d->cube_axes_actor->ZAxisMinorTickVisibilityOff();
// d->axes = vtkAxesActor::New();
// d->axes->SetConeRadius(0.3);
// d->axes->SetCylinderRadius(0.005);
// d->axes->SetAxisLabels(true);
// d->marker = vtkOrientationMarkerWidget::New();
// d->marker->SetOutlineColor(0.9300, 0.5700, 0.1300);
// d->marker->SetOrientationMarker(d->axes);
// d->marker->SetInteractor(d_func()->view->renderer()->GetRenderWindow()->GetInteractor());
// d->marker->SetViewport(0.0, 0.0, 0.25, 0.25);
// d->marker->SetEnabled(1);
d->show_actor_cb = new QCheckBox;
//////////
// Inspectors connections
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
this->saveSettings("visibility", state == Qt::Checked);
this->setVisibility(state == Qt::Checked);
this->draw();
});
this->setObjectName("Volume");
d->show_actor_cb->setObjectName("Display");
d_func()->inspectors << d->show_actor_cb;
}
dtkVisualizationDecoratorVolume::~dtkVisualizationDecoratorVolume(void)
{
this->unsetCanvas();
delete d;
d = nullptr;
}
void dtkVisualizationDecoratorVolume::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
if (!dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
return;
}
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.";
d_func()->clear();
return;
}
d_func()->dataset = dataset;
this->restoreSettings();
d->c2p_filter->SetInputData(d_func()->dataset);
d->mapper->SetInputData(d_func()->dataset);
d->outline_contour->SetInputData(d_func()->dataset);
d_func()->sortEligibleFields();
if (this->canvas()) {
this->canvas()->renderer()->AddActor(d->actor);
}
d->mapper->Modified();
d->outline_contour->Modified();
d_func()->enableScalarBar();
}
void dtkVisualizationDecoratorVolume::setCanvas(dtkVisualizationCanvas *canvas)
{
this->unsetCanvas();
d_func()->view = dynamic_cast<dtkVisualizationView2D *>(canvas);
if (!d_func()->view) {
qWarning() << Q_FUNC_INFO << "View 2D or view 3D expected as canvas. Canvas is reset to nullptr.";
return;
}
if (d->mapper->GetInput()) {
d_func()->view->renderer()->AddActor(d->actor);
}
d_func()->enableScalarBar();
}
void dtkVisualizationDecoratorVolume::unsetCanvas(void)
{
if (d_func()->view) {
d_func()->view->renderer()->RemoveActor(d->actor);
}
d_func()->disableScalarBar();
d_func()->view = nullptr;
}
void dtkVisualizationDecoratorVolume::setVisibility(bool visible)
{
d->actor->SetVisibility(visible);
dtkVisualizationDecoratorWithClut::setVisibility(visible);
}
void dtkVisualizationDecoratorVolume::restoreSettings(void)
{
dtkVisualizationDecoratorWithClut::restoreSettings();
d->actor->SetVisibility(d_func()->default_visibility);
d->show_actor_cb->blockSignals(true);
d->show_actor_cb->setChecked(d_func()->default_visibility);
d->show_actor_cb->blockSignals(false);
}
bool dtkVisualizationDecoratorVolume::setCurrentFieldName(const QString& field_name)
{
if (!dtkVisualizationDecoratorWithClut::setCurrentFieldName(field_name)) {
return false;
}
using Support = dtkVisualizationDecoratorWithClut::Support;
int support = d_func()->supports[field_name];
if(support == Support::Cell) {
d->c2p_filter->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_CELLS, qPrintable(field_name));
d->mapper->SetInputConnection(d->c2p_filter->GetOutputPort());
}
d->mapper->SetScalarModeToUsePointFieldData();
d->mapper->SelectScalarArray(qPrintable(field_name));
d->mapper->Modified();
return dtkVisualizationDecoratorWithClut::setCurrentFieldName(field_name);
}
void dtkVisualizationDecoratorVolume::setColorMap(const QMap<double, QColor>& new_colormap)
{
dtkVisualizationDecoratorWithClut::setColorMap(new_colormap);
auto&& range = d_func()->ranges[d_func()->current_field_name];
double min = range[0];
double max = range[1];
double mid = (min + max) / 2.0;
qDebug() << min << max << mid ;
d->volume_property->SetColor(d_func()->color_function);
d->opacity_transfer_function->RemoveAllPoints();
d->opacity_transfer_function->AddPoint(min, 0.01);
d->opacity_transfer_function->AddPoint(mid, 0.1);
d->opacity_transfer_function->AddPoint(max, 0.25);
d->opacity_transfer_function->Modified();
d->volume_property->Modified();
d->mapper->Modified();
d->volume->Update();
}
//
// dtkVisualizationDecoratorVolume.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkVisualizationExport>
#include "dtkVisualizationDecoratorWithClut.h"
class DTKVISUALIZATION_EXPORT dtkVisualizationDecoratorVolume : public dtkVisualizationDecoratorWithClut
{
Q_OBJECT
public:
dtkVisualizationDecoratorVolume(void);
~dtkVisualizationDecoratorVolume(void);
public:
void setData(const QVariant&) override;
void setCanvas(dtkVisualizationCanvas *) override;
void unsetCanvas(void) override;
protected:
bool setCurrentFieldName(const QString&) override;
void setColorMap(const QMap<double, QColor>&) override;
public:
void setVisibility(bool) override;
void restoreSettings(void) override;
protected:
class dtkVisualizationDecoratorVolumePrivate *d = nullptr;
};
//
// dtkVisualizationDecoratorVolumes.h ends here
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