Commit bdbcd98b authored by Pierre Fernique's avatar Pierre Fernique

Finalize dtkVisualizationDecoratorScalarColorMap

parent 9f216b58
......@@ -59,7 +59,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")
## Build setup
## #################################################################
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(UNIX)
......@@ -80,6 +80,7 @@ find_package(VTK REQUIRED)
find_package(Qt5 COMPONENTS Core Widgets OpenGL Xml Multimedia MultimediaWidgets WebSockets REQUIRED)
find_package(dtkCore 2.2.2 REQUIRED)
find_package(dtkFonts 2.0.0 REQUIRED)
find_package(dtkWidgets 2.1.0 REQUIRED)
find_package(dtkLog 2.1.0 REQUIRED)
......@@ -94,6 +95,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
include(${VTK_USE_FILE})
include_directories(${dtkCore_INCLUDE_DIRS})
include_directories(${dtkLog_INCLUDE_DIRS})
include_directories(${dtkFonts_INCLUDE_DIRS})
include_directories(${dtkWidgets_INCLUDE_DIRS})
......
......@@ -16,8 +16,14 @@
#include "dtkVisualizationViewerSidePane.h"
#include "dtkVisualizationViewerStack.h"
#include <dtkCore>
#include <dtkVisualization/dtkVisualizationView3D>
#include <dtkVisualization/dtkVisualizationActorScalarColorMap>
#include <dtkVisualization/dtkVisualizationDecoratorScalarColorMap>
#include <dtkVisualization/dtkVisualizationVTKReader>
#include <dtkVisualizationWidgets/dtkVisualizationWidgetsClutEditor>
#include <dtkWidgets/dtkWidgetsLayout>
......@@ -131,6 +137,21 @@ void dtkVisualizationViewer::importDataSet(void)
void dtkVisualizationViewer::importDataSet(const QString& path)
{
QFileInfo info(path);
QSettings settings;
settings.beginGroup("viewer");
settings.setValue("last_import_dir", info.absoluteDir().path());
settings.endGroup();
vtkDataSet *dataset = dtkVisualizationVTKReader(path);
dtkVisualizationDecoratorScalarColorMap* decorator = new dtkVisualizationDecoratorScalarColorMap;
decorator->setCanvas(dynamic_cast<dtkVisualizationView3D *>(d->stack->layout()->current()->view()));
QVariant data = dtk::variantFromValue(dataset);
decorator->setData(data);
// decorator->draw();
// qDebug() << __FILE__ << __LINE__;
// QFileInfo info(path);
// QSettings settings;
......
......@@ -34,6 +34,8 @@ set(${PROJECT_NAME}_HEADERS
dtkVisualizationPlot2D.h
dtkVisualizationPlot3D
dtkVisualizationPlot3D.h
dtkVisualizationVTKReader
dtkVisualizationVTKReader.h
dtkVisualizationViewHybrid
dtkVisualizationViewHybrid.h
dtkVisualizationViewOverlay
......@@ -57,6 +59,7 @@ set(${PROJECT_NAME}_SOURCES
dtkVisualizationDecoratorScalarColorMap.cpp
dtkVisualizationPlot2D.cpp
dtkVisualizationPlot3D.cpp
dtkVisualizationVTKReader.cpp
dtkVisualizationViewHybrid.cpp
dtkVisualizationViewOverlay.cpp
dtkVisualizationView2D.cpp
......
#include "dtkVisualizationDecoratorScalarColorMap.h"
\ No newline at end of file
......@@ -37,9 +37,6 @@ public:
public:
vtkDataSet *dataset = nullptr;
public:
vtkRenderWindowInteractor *interactor = nullptr;
public:
vtkSmartPointer<vtkActor> actor;
vtkSmartPointer<vtkDataSetMapper> mapper;
......@@ -64,12 +61,10 @@ dtkVisualizationDecoratorScalarColorMap::dtkVisualizationDecoratorScalarColorMap
d->actor = vtkSmartPointer<vtkActor>::New();
d->actor->SetMapper(d->mapper);
d->actor->SetVisibility(true);
this->canvas()->renderer()->AddActor(d->actor);
}
dtkVisualizationDecoratorScalarColorMap::~dtkVisualizationDecoratorScalarColorMap(void)
{
d->interactor = nullptr;
d->dataset = nullptr;
delete d;
d = nullptr;
......@@ -82,12 +77,12 @@ void dtkVisualizationDecoratorScalarColorMap::draw(void)
return;
}
if (!d->scalar_bar && d->interactor) {
if (!d->scalar_bar && this->canvas() && this->canvas()->interactor()) {
d->scalar_bar = vtkSmartPointer<vtkScalarBarActor>::New();
d->scalar_bar->SetWidth(0.08);
d->scalar_bar->SetHeight(0.6);
d->scalar_bar->SetVisibility(true);
vtkRendererCollection *renderers = d->interactor->GetRenderWindow()->GetRenderers();
vtkRendererCollection *renderers = this->canvas()->interactor()->GetRenderWindow()->GetRenderers();
renderers->InitTraversal();
for (vtkIdType i = 0; i < renderers->GetNumberOfItems(); ++i) {
renderers->GetNextItem()->AddActor2D(d->scalar_bar);
......@@ -102,7 +97,7 @@ void dtkVisualizationDecoratorScalarColorMap::draw(void)
}
d->actor->Modified();
if(d->interactor) d->interactor->Render();
if(this->canvas()->interactor()) this->canvas()->interactor()->Render();
}
void dtkVisualizationDecoratorScalarColorMap::setData(const QVariant& data)
......@@ -121,10 +116,8 @@ void dtkVisualizationDecoratorScalarColorMap::setData(const QVariant& data)
d->opacity_functions.clear();
d->ranges.clear();
d->supports.clear();
vtkIdType number_of_point_arrays = d->dataset->GetPointData()->GetNumberOfArrays();
vtkIdType number_of_cell_arrays = d->dataset->GetCellData()->GetNumberOfArrays();
for(vtkIdType i = 0; i < number_of_point_arrays; ++i) {
if (d->dataset->GetPointData()->GetArray(i)->GetNumberOfComponents() == 1) {
QString field_name = QString::fromUtf8(d->dataset->GetPointData()->GetArrayName(i));
......@@ -187,9 +180,18 @@ void dtkVisualizationDecoratorScalarColorMap::setData(const QVariant& data)
void dtkVisualizationDecoratorScalarColorMap::setCanvas(dtkVisualizationCanvas *canvas)
{
if(dynamic_cast<dtkVisualizationView2D *>(canvas))
{ dtkVisualizationDataDecorator::setCanvas(canvas); }
dtkVisualizationView2D* old = dynamic_cast<dtkVisualizationView2D *>(dtkVisualizationDataDecorator::canvas());
if (old)
{
old->renderer()->RemoveActor(d->actor);
}
if (dynamic_cast<dtkVisualizationView2D *>(canvas))
{
dtkVisualizationDataDecorator::setCanvas(canvas);
dtkVisualizationDataDecorator::canvas()->renderer()->AddActor(d->actor);
}
}
QStringList dtkVisualizationDecoratorScalarColorMap::eligibleFieldNames(void)
{
return d->eligible_field_names;
......@@ -228,7 +230,7 @@ bool dtkVisualizationDecoratorScalarColorMap::setFieldName(const QString& scalar
return false;
}
if(!d->dataset) {
if (!d->dataset) {
qWarning() << Q_FUNC_INFO << "Before calling setScalarFieldName, setDataSet must be called.";
return false;
}
......@@ -280,7 +282,7 @@ void dtkVisualizationDecoratorScalarColorMap::setColorTransferFunction(vtkSmartP
d->actor->Modified();
}
if(d->interactor) d->interactor->Render();
if(this->canvas() && this->canvas()->interactor()) this->canvas()->interactor()->Render();
emit this->currentColorTransferFunctionChanged(color_function);
}
......@@ -291,7 +293,7 @@ void dtkVisualizationDecoratorScalarColorMap::setOpacityTransferFunction(vtkSmar
//Need to be implemented, probably requires modifying the lut...
if (d->interactor) d->interactor->Render();
if (this->canvas() && this->canvas()->interactor()) this->canvas()->interactor()->Render();
emit this->currentOpacityFunctionChanged(d->opacity_functions[d->current_field_name]);
}
......@@ -306,7 +308,7 @@ void dtkVisualizationDecoratorScalarColorMap::setRange(double min, double max)
d->actor->Modified();
}
if(d->interactor) d->interactor->Render();
if (this->canvas() && this->canvas()->interactor()) this->canvas()->interactor()->Render();
emit this->currentRangeChanged(min, max);
}
\ No newline at end of file
#include "dtkVisualizationVTKReader.h"
\ No newline at end of file
......@@ -12,19 +12,25 @@
// Code:
#include "dtkVisualizationVTKReader.h"
vtkDataSet* dtkVisualizationVTKReader(const QString& path)
#include <vtkSmartPointer.h>
#include <vtkDataSet.h>
#include <vtkUnstructuredGrid.h>
#include <vtkXMLUnstructuredGridReader.h>
vtkDataSet* dtkVisualizationVTKReader(QString path)
{
if(!path.startsWith("file://"))
return;
// if(!path.startsWith("file://"))
// return nullptr;
path.remove("file://");
// path.remove("file://");
if (path.endsWith(".vti"))
return dtkVisualizationVTKReaderVTI(path);
if (path.endsWith(".vtp"))
return dtkVisualizationVTKReadertVTP(path);
return dtkVisualizationVTKReaderVTP(path);
if (path.endsWith(".vtr"))
return dtkVisualizationVTKReaderVTR(path);
......@@ -34,6 +40,8 @@ vtkDataSet* dtkVisualizationVTKReader(const QString& path)
if (path.endsWith(".vtu"))
return dtkVisualizationVTKReaderVTU(path);
return nullptr;
}
vtkDataSet* dtkVisualizationVTKReaderVTI(const QString& path)
......@@ -62,9 +70,12 @@ vtkDataSet* dtkVisualizationVTKReaderVTS(const QString& path)
vtkDataSet* dtkVisualizationVTKReaderVTU(const QString& path)
{
vtkDataSet *res = vtkUnstructuredGrid::New();
vtkSmartPointer<vtkXMLUnstructuredGridReader> reader = vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
reader->SetFileName(qPrintable(path));
return reader->GetOuput();
reader->Update();
res->DeepCopy(reader->GetOutput());
return res;
}
// ///////////////////////////////////////////////////////////////////
......
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtCore>
#include <dtkVisualizationExport>
class vtkDataSet;
vtkDataSet* dtkVisualizationVTKReader(QString path);
vtkDataSet* dtkVisualizationVTKReaderVTI(const QString& path);
vtkDataSet* dtkVisualizationVTKReaderVTP(const QString& path);
vtkDataSet* dtkVisualizationVTKReaderVTR(const QString& path);
vtkDataSet* dtkVisualizationVTKReaderVTS(const QString& path);
vtkDataSet* dtkVisualizationVTKReaderVTU(const QString& path);
//
// dtkVisualizationVTKReader.h ends here
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkVisualizationExport>
vtkDataSet* DTKVISUALIZATION_EXPORT dtkVisualizationVTKReader(const QString& path);
vtkDataSet* DTKVISUALIZATION_EXPORT dtkVisualizationVTKReaderVTI(const QString& path)
vtkDataSet* DTKVISUALIZATION_EXPORT dtkVisualizationVTKReaderVTP(const QString& path)
vtkDataSet* DTKVISUALIZATION_EXPORT dtkVisualizationVTKReaderVTR(const QString& path)
vtkDataSet* DTKVISUALIZATION_EXPORT dtkVisualizationVTKReaderVTS(const QString& path)
vtkDataSet* DTKVISUALIZATION_EXPORT dtkVisualizationVTKReaderVTU(const QString& path)
//
// dtkVisualizationVTKReader.h ends here
\ No newline at end of file
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