Commit 16c38afd authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud

Revert spurious dynamic_cast into different vtk types.

In fact, cast operations on vtkDataSet subclasses contained in QVariant are OK provided that
`dtk::visualization::registerVTKToMetaType` function is called before
ask for conversions.

This function is embedded into the more generic
`dtk::visualization::initialize` function that initializes the layer of
visualization.

So for any application using dtkVisualization layer, one must initialize
it using this function to ensure such cast operations.

Tests were added to check that the downcast from vtkDataSet to any
subclasses is working even if a pointer of a vtkDataSet is given to the
`dtk::variantFromValue` function.

```cpp
vtkDataSet *data = vtkImageData::New();
QVariant v = dtk::variantFromValue(data);
QVERIFY(v.userType() == QMetaType::type("vtkImageData*"));
```
parent 47e9b191
......@@ -77,6 +77,13 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
## ###################################################################
## Test setup
## ###################################################################
include(CTest)
enable_testing()
## ###################################################################
## Dependencies - cmake
## ###################################################################
......@@ -140,7 +147,7 @@ if(NOT DTKVISUALIZATION_USE_UPCOMING_VTK)
include(${VTK_USE_FILE})
endif(NOT DTKVISUALIZATION_USE_UPCOMING_VTK)
find_package(Qt5 COMPONENTS Core Widgets Gui Xml Multimedia MultimediaWidgets OpenGL REQUIRED)
find_package(Qt5 COMPONENTS Core Widgets Gui Xml Multimedia MultimediaWidgets OpenGL Test REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
......@@ -167,6 +174,7 @@ endif(WIN32)
add_subdirectory(src)
add_subdirectory(app)
add_subdirectory(exp)
add_subdirectory(tst)
## ###################################################################
## Export configuration
......@@ -229,6 +237,7 @@ mark_as_advanced(Qt5MultimediaWidgets_DIR)
mark_as_advanced(Qt5Network_DIR)
mark_as_advanced(Qt5OpenGL_DIR)
mark_as_advanced(Qt5Sql_DIR)
mark_as_advanced(Qt5Test_DIR)
mark_as_advanced(Qt5Widgets_DIR)
mark_as_advanced(Qt5Xml_DIR)
......
......@@ -22,6 +22,8 @@
#include <dtkThemes/dtkThemesEngine>
#include <dtkVisualization/dtkVisualization.h>
#include <dtkWidgets>
#include "dtkVisualizationViewer.h"
......@@ -34,6 +36,7 @@ int main(int argc, char **argv)
{
dtk::core::registerParameters();
dtk::widgets::initialize();
dtk::visualization::initialize();
dtkThemesEngine::instance()->apply();
QSurfaceFormat::setDefaultFormat(QVTKOpenGLNativeWidget::defaultFormat());
......
......@@ -142,18 +142,6 @@ void dtkVisualizationDecoratorAxes::setData(const QVariant& data)
{
d->dataset = data.value<vtkDataSet *>();
if (!d->dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
d->dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
d->dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
d->dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (!d->dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
return;
......
......@@ -210,17 +210,6 @@ bool dtkVisualizationDecoratorClutEditor::isDecorating(void)
void dtkVisualizationDecoratorClutEditor::setData(const QVariant& data)
{
d->dataset = data.value<vtkDataSet *>();
if (!d->dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
d->dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
d->dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
d->dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (!d->dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
......
......@@ -252,17 +252,6 @@ bool dtkVisualizationDecoratorClutEditorSimple::isDecorating(void)
void dtkVisualizationDecoratorClutEditorSimple::setData(const QVariant& data)
{
d->dataset = data.value<vtkDataSet *>();
if (!d->dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
d->dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
d->dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
d->dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (!d->dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
......
......@@ -174,17 +174,6 @@ void dtkVisualizationDecoratorInfo::setVisibility(bool visible)
void dtkVisualizationDecoratorInfo::setData(const QVariant& data)
{
d->dataset = data.value<vtkDataSet *>();
if (!d->dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
d->dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
d->dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
d->dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (d->dataset) {
for (int row = 0; row < d->layout->rowCount(); ++row) {
......
......@@ -217,18 +217,6 @@ void dtkVisualizationDecoratorIsocontours::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
if (!dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (!dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
return;
......
......@@ -223,18 +223,6 @@ void dtkVisualizationDecoratorScalarGlyphs::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
if (!dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (!dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
return;
......
......@@ -304,19 +304,6 @@ void dtkVisualizationDecoratorSlices::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
if (!dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (!dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
return;
......
......@@ -81,18 +81,6 @@ void dtkVisualizationDecoratorSurfaceColor::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
if (!dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (!dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
return;
......
......@@ -315,18 +315,6 @@ void dtkVisualizationDecoratorVectorCurvedGlyphs::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
if (!dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (!dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
return;
......
......@@ -191,18 +191,6 @@ void dtkVisualizationDecoratorVectorGlyphs::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
if (!dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (!dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
return;
......
......@@ -506,18 +506,6 @@ void dtkVisualizationDecoratorVectorStreamTracer::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
if (!dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (!dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
return;
......
......@@ -282,18 +282,6 @@ void dtkVisualizationDecoratorVectorStreamlines::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
if (!dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (!dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
return;
......
......@@ -137,18 +137,6 @@ void dtkVisualizationDecoratorVolume::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
if (!dataset) {
//try to cast from other types of structures
if(dynamic_cast<vtkStructuredGrid *>(data.value<vtkStructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkStructuredGrid *>());
if(dynamic_cast<vtkUnstructuredGrid *>(data.value<vtkUnstructuredGrid *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkUnstructuredGrid *>());
if(dynamic_cast<vtkPolyData *>(data.value<vtkPolyData *>()))
dataset = vtkSmartPointer<vtkDataSet>(data.value<vtkPolyData *>());
}
if (!dataset) {
dtkWarn() << Q_FUNC_INFO << "vtkDataSet is expected. Input data is not stored.";
return;
......
## ###################################################################
include_directories(./)
add_subdirectory(dtkVisualization)
######################################################################
### CMakeLists.txt ends here
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkVisualizationTests)
## ###################################################################
## Build tree setup
## ###################################################################
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
## ###################################################################
## Input
## ###################################################################
set(${PROJECT_NAME}_HEADERS
dtkVisualizationMetaTypeTest.h)
set(${PROJECT_NAME}_SOURCES
dtkVisualizationMetaTypeTest.cpp)
## ###################################################################
## Input - introspected
## ###################################################################
create_test_sourcelist(
${PROJECT_NAME}_SOURCES_TST
${PROJECT_NAME}.cpp
${${PROJECT_NAME}_SOURCES})
## ###################################################################
## Build rules
## ###################################################################
add_executable(${PROJECT_NAME}
${${PROJECT_NAME}_SOURCES_TST}
${${PROJECT_NAME}_SOURCES})
## ###################################################################
## Link rules
## ###################################################################
target_link_libraries(${PROJECT_NAME} dtkCore)
target_link_libraries(${PROJECT_NAME} dtkVisualization)
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Test)
target_link_libraries(${PROJECT_NAME} ${VTK_LIBRARIES})
## ###################################################################
## Test rules
## ###################################################################
add_test(dtkVisualizationMetaTypeTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME} dtkVisualizationMetaTypeTest)
######################################################################
### CMakeLists.txt ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkVisualizationMetaTypeTest.h"
#include <dtkVisualizationTest>
#include <dtkVisualization/dtkVisualizationTypeTraits>
#include <dtkVisualization/dtkVisualizationMetaType>
// ///////////////////////////////////////////////////////////////////
// dtkVisualizationMetaTypeTestCasePrivate declaration
// ///////////////////////////////////////////////////////////////////
class dtkVisualizationMetaTypeTestCasePrivate
{
public:
};
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
dtkVisualizationMetaTypeTestCase::dtkVisualizationMetaTypeTestCase(void) : d(new dtkVisualizationMetaTypeTestCasePrivate)
{
}
dtkVisualizationMetaTypeTestCase::~dtkVisualizationMetaTypeTestCase(void)
{
delete d;
}
void dtkVisualizationMetaTypeTestCase::initTestCase(void)
{
}
void dtkVisualizationMetaTypeTestCase::init(void)
{
}
void dtkVisualizationMetaTypeTestCase::testIsVtkDataSet(void)
{
QVERIFY(dtk::is_vtkdataset<vtkDataSet>::value);
QVERIFY(dtk::is_vtkdataset<vtkDataSet&>::value);
QVERIFY(dtk::is_vtkdataset<const vtkDataSet&>::value);
QVERIFY(dtk::is_vtkdataset<vtkDataSet&&>::value);
QVERIFY(dtk::is_vtkdataset<vtkDataSet *>::value);
QVERIFY(dtk::is_vtkdataset<const vtkDataSet *>::value);
QVERIFY(dtk::is_vtkdataset<vtkDataSet *&>::value);
QVERIFY(dtk::is_vtkdataset<const vtkDataSet *&>::value);
QVERIFY(dtk::is_vtkdataset<volatile vtkDataSet>::value);
QVERIFY(dtk::is_vtkdataset<const volatile vtkDataSet>::value);
QVERIFY(dtk::is_vtkdataset<volatile vtkDataSet *>::value);
QVERIFY(dtk::is_vtkdataset<const volatile vtkDataSet *>::value);
QVERIFY(dtk::is_vtkdataset<vtkImageData>::value);
QVERIFY(dtk::is_vtkdataset<vtkImageData&>::value);
QVERIFY(dtk::is_vtkdataset<const vtkImageData&>::value);
QVERIFY(dtk::is_vtkdataset<vtkImageData&&>::value);
QVERIFY(dtk::is_vtkdataset<vtkImageData *>::value);
QVERIFY(dtk::is_vtkdataset<const vtkImageData *>::value);
QVERIFY(dtk::is_vtkdataset<vtkImageData *&>::value);
QVERIFY(dtk::is_vtkdataset<const vtkImageData *&>::value);
QVERIFY(dtk::is_vtkdataset<volatile vtkImageData>::value);
QVERIFY(dtk::is_vtkdataset<const volatile vtkImageData>::value);
QVERIFY(dtk::is_vtkdataset<volatile vtkImageData *>::value);
QVERIFY(dtk::is_vtkdataset<const volatile vtkImageData *>::value);
QVERIFY(dtk::is_vtkdataset<vtkPolyData>::value);
QVERIFY(dtk::is_vtkdataset<vtkPolyData&>::value);
QVERIFY(dtk::is_vtkdataset<const vtkPolyData&>::value);
QVERIFY(dtk::is_vtkdataset<vtkPolyData&&>::value);
QVERIFY(dtk::is_vtkdataset<vtkPolyData *>::value);
QVERIFY(dtk::is_vtkdataset<const vtkPolyData *>::value);
QVERIFY(dtk::is_vtkdataset<vtkPolyData *&>::value);
QVERIFY(dtk::is_vtkdataset<const vtkPolyData *&>::value);
QVERIFY(dtk::is_vtkdataset<volatile vtkPolyData>::value);
QVERIFY(dtk::is_vtkdataset<const volatile vtkPolyData>::value);
QVERIFY(dtk::is_vtkdataset<volatile vtkPolyData *>::value);
QVERIFY(dtk::is_vtkdataset<const volatile vtkPolyData *>::value);
QVERIFY(dtk::is_vtkdataset<vtkRectilinearGrid>::value);
QVERIFY(dtk::is_vtkdataset<vtkRectilinearGrid&>::value);
QVERIFY(dtk::is_vtkdataset<const vtkRectilinearGrid&>::value);
QVERIFY(dtk::is_vtkdataset<vtkRectilinearGrid&&>::value);
QVERIFY(dtk::is_vtkdataset<vtkRectilinearGrid *>::value);
QVERIFY(dtk::is_vtkdataset<const vtkRectilinearGrid *>::value);
QVERIFY(dtk::is_vtkdataset<vtkRectilinearGrid *&>::value);
QVERIFY(dtk::is_vtkdataset<const vtkRectilinearGrid *&>::value);
QVERIFY(dtk::is_vtkdataset<volatile vtkRectilinearGrid>::value);
QVERIFY(dtk::is_vtkdataset<const volatile vtkRectilinearGrid>::value);
QVERIFY(dtk::is_vtkdataset<volatile vtkRectilinearGrid *>::value);
QVERIFY(dtk::is_vtkdataset<const volatile vtkRectilinearGrid *>::value);
QVERIFY(dtk::is_vtkdataset<vtkStructuredGrid>::value);
QVERIFY(dtk::is_vtkdataset<vtkStructuredGrid&>::value);
QVERIFY(dtk::is_vtkdataset<const vtkStructuredGrid&>::value);
QVERIFY(dtk::is_vtkdataset<vtkStructuredGrid&&>::value);
QVERIFY(dtk::is_vtkdataset<vtkStructuredGrid *>::value);
QVERIFY(dtk::is_vtkdataset<const vtkStructuredGrid *>::value);
QVERIFY(dtk::is_vtkdataset<vtkStructuredGrid *&>::value);
QVERIFY(dtk::is_vtkdataset<const vtkStructuredGrid *&>::value);
QVERIFY(dtk::is_vtkdataset<volatile vtkStructuredGrid>::value);
QVERIFY(dtk::is_vtkdataset<const volatile vtkStructuredGrid>::value);
QVERIFY(dtk::is_vtkdataset<volatile vtkStructuredGrid *>::value);
QVERIFY(dtk::is_vtkdataset<const volatile vtkStructuredGrid *>::value);
QVERIFY(dtk::is_vtkdataset<vtkUnstructuredGrid>::value);
QVERIFY(dtk::is_vtkdataset<vtkUnstructuredGrid&>::value);
QVERIFY(dtk::is_vtkdataset<const vtkUnstructuredGrid&>::value);
QVERIFY(dtk::is_vtkdataset<vtkUnstructuredGrid&&>::value);
QVERIFY(dtk::is_vtkdataset<vtkUnstructuredGrid *>::value);
QVERIFY(dtk::is_vtkdataset<const vtkUnstructuredGrid *>::value);
QVERIFY(dtk::is_vtkdataset<vtkUnstructuredGrid *&>::value);
QVERIFY(dtk::is_vtkdataset<const vtkUnstructuredGrid *&>::value);
QVERIFY(dtk::is_vtkdataset<volatile vtkUnstructuredGrid>::value);
QVERIFY(dtk::is_vtkdataset<const volatile vtkUnstructuredGrid>::value);
QVERIFY(dtk::is_vtkdataset<volatile vtkUnstructuredGrid *>::value);
QVERIFY(dtk::is_vtkdataset<const volatile vtkUnstructuredGrid *>::value);
}
void dtkVisualizationMetaTypeTestCase::testCanConvert(void)
{
// First one needs to register vtk types
dtk::visualization::registerVTKToMetaType();
QList<int> list_of_types_to_convert = {
QMetaType::type("vtkDataSet*"),
QMetaType::type("vtkImageData*"),
QMetaType::type("vtkPolyData*"),
QMetaType::type("vtkRectilinearGrid*"),
QMetaType::type("vtkStructuredGrid*"),
QMetaType::type("vtkUnstructuredGrid*")
};
QVERIFY(!dtk::canConvert<vtkDataSet *>(list_of_types_to_convert));
}
void dtkVisualizationMetaTypeTestCase::testVariantFromValue(void)
{
QVariant v;
{
vtkDataSet *data = vtkImageData::New();
v = dtk::variantFromValue(data);
QVERIFY(v.userType() == QMetaType::type("vtkImageData*"));
data->Delete();
}
{
vtkDataSet *data = vtkPolyData::New();
v = dtk::variantFromValue(data);
QVERIFY(v.userType() == QMetaType::type("vtkPolyData*"));
data->Delete();
}
{
vtkDataSet *data = vtkRectilinearGrid::New();
v = dtk::variantFromValue(data);
QVERIFY(v.userType() == QMetaType::type("vtkRectilinearGrid*"));
data->Delete();
}
{
vtkDataSet *data = vtkStructuredGrid::New();
v = dtk::variantFromValue(data);
QVERIFY(v.userType() == QMetaType::type("vtkStructuredGrid*"));
data->Delete();
}
{
vtkDataSet *data = vtkUnstructuredGrid::New();
v = dtk::variantFromValue(data);
QVERIFY(v.userType() == QMetaType::type("vtkUnstructuredGrid*"));
data->Delete();
}
}
void dtkVisualizationMetaTypeTestCase::cleanupTestCase(void)
{
}
void dtkVisualizationMetaTypeTestCase::cleanup(void)
{
}
DTKVISUALIZATIONTEST_MAIN_NOGUI(dtkVisualizationMetaTypeTest, dtkVisualizationMetaTypeTestCase);
//
// dtkVisualizationMetaTypeTest.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtCore>
class dtkVisualizationMetaTypeTestCase : public QObject
{
Q_OBJECT
public:
dtkVisualizationMetaTypeTestCase(void);
~dtkVisualizationMetaTypeTestCase(void);
private slots:
void initTestCase(void);
void init(void);
private slots:
void testIsVtkDataSet(void);
void testCanConvert(void);
void testVariantFromValue(void);
private slots:
void cleanupTestCase(void);
void cleanup(void);
private:
class dtkVisualizationMetaTypeTestCasePrivate *d;
};
//
// dtkVisualizationMetaTypeTest.h ends here
#include "dtkVisualizationTest.h"
// ///////////////////////////////////////////////////////////////////
#pragma once
#include <QtTest>
#define DTKVISUALIZATIONTEST_MAIN_NOGUI(TestMain, TestObject) \
int TestMain(int argc, char *argv[]) { \
QCoreApplication app(argc, argv); \
TestObject tc; \
return QTest::qExec(&tc, argc, argv); \
}
#define DTKVISUALIZATIONTEST_MAIN_GUI(TestMain, TestObject) \
int TestMain(int argc, char *argv[]) { \
QApplication app(argc, argv); \
TestObject tc; \
return QTest::qExec(&tc, argc, argv); \
}
//
// dtkVisualizationTest.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