Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support build with vtk89 #934

Merged
merged 2 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion CMake/ctkMacroBuildLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#! \ingroup CMakeAPI
macro(ctkMacroBuildLib)
ctkMacroParseArguments(MY
"NAME;EXPORT_DIRECTIVE;SRCS;MOC_SRCS;GENERATE_MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES;LIBRARY_TYPE"
"NAME;EXPORT_DIRECTIVE;SRCS;MOC_SRCS;GENERATE_MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES;LIBRARY_TYPE;EXPORT_CUSTOM_CONTENT_FROM_VARIABLE"
"ENABLE_QTTESTING"
${ARGN}
)
Expand Down Expand Up @@ -91,6 +91,16 @@ macro(ctkMacroBuildLib)
string(REGEX REPLACE "^CTK" "ctk" MY_EXPORT_HEADER_PREFIX ${MY_EXPORT_HEADER_PREFIX})
set(MY_LIBNAME ${lib_name})

set(CTK_EXPORT_CUSTOM_CONTENT "")
if(MY_EXPORT_CUSTOM_CONTENT_FROM_VARIABLE)
if(DEFINED "${MY_EXPORT_CUSTOM_CONTENT_FROM_VARIABLE}")
set(CTK_EXPORT_CUSTOM_CONTENT "// ------- Expanded from \@CTK_EXPORT_CUSTOM_CONTENT\@ -------
${${MY_EXPORT_CUSTOM_CONTENT_FROM_VARIABLE}}
// ------------------------------------------------
")
endif()
endif()

configure_file(
${CTK_SOURCE_DIR}/Libs/ctkExport.h.in
${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
Expand Down
13 changes: 13 additions & 0 deletions CMakeExternals/VTK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,16 @@ mark_as_superbuild(
VARS VTK_DIR:PATH
LABELS "FIND_PACKAGE"
)

if(VTK_PYTHON_VERSION VERSION_GREATER "2.7")
# Propagate variables expected when VTK searches for python
mark_as_superbuild(
VARS
Python3_INCLUDE_DIR:PATH
Python3_ROOT_DIR:PATH
Python3_LIBRARY:FILEPATH
Python3_LIBRARY_DEBUG:FILEPATH
Python3_LIBRARY_RELEASE:FILEPATH
Python3_EXECUTABLE:FILEPATH
)
endif()
74 changes: 69 additions & 5 deletions Libs/Visualization/VTK/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,41 @@ project(CTKVisualizationVTKCore)
#
# 3rd party dependencies
#
include(${VTK_USE_FILE})

if(${VTK_VERSION} VERSION_LESS "8.90")
include(${VTK_USE_FILE})
else()
# VTK >= 8.90 defines VTK_MAJOR_VERSION
set(VTK_VERSION_MAJOR ${VTK_MAJOR_VERSION})

find_package(VTK
COMPONENTS
ChartsCore
CommonCore
CommonDataModel
FiltersCore
FiltersGeneral
FiltersModeling
FiltersSources
FiltersStatistics
IOLegacy
IOXML
InfovisCore
InfovisLayout
InteractionStyle
RenderingAnnotation
RenderingCore
RenderingFreeType
RenderingOpenGL2
ViewsCore
ViewsInfovis
WrappingPythonCore
ViewsContext2D
OPTIONAL_COMPONENTS
TestingRendering
)
endif()

if(NOT DEFINED VTK_RENDERING_BACKEND)
set(VTK_RENDERING_BACKEND "OpenGL")
endif()
Expand Down Expand Up @@ -62,7 +96,9 @@ if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_
endif()

# Set VTK_LIBRARIES variable
if(${VTK_VERSION_MAJOR} GREATER 5)
if(${VTK_VERSION} VERSION_EQUAL 8.90 OR ${VTK_VERSION} VERSION_GREATER 8.90 )
# VTK_LIBRARIES is automatically set based on selected components
elseif(${VTK_VERSION_MAJOR} GREATER 5)
set(VTK_LIBRARIES
# a few of these have to be specified explicitly to workaround
# underlinked libraries from the debian VTK package
Expand Down Expand Up @@ -126,7 +162,9 @@ if(${CTK_USE_CHARTS})
vtkScalarsToColorsPreviewChart.cpp
vtkScalarsToColorsPreviewChart.h
${KIT_SRCS})
if(${VTK_VERSION_MAJOR} GREATER 5)
if(${VTK_VERSION} VERSION_EQUAL 8.90 OR ${VTK_VERSION} VERSION_GREATER 8.90 )
# VTK_LIBRARIES is automatically set based on selected components
elseif(${VTK_VERSION_MAJOR} GREATER 5)
set(VTK_LIBRARIES
vtkChartsCore
${VTK_LIBRARIES})
Expand All @@ -136,14 +174,20 @@ if(${CTK_USE_CHARTS})
${VTK_LIBRARIES})
endif()
add_definitions(-DCTK_USE_CHARTS)

if(${VTK_VERSION} VERSION_LESS "8.90")
set(VTK_LIBRARIES
vtkViewsContext2D
${VTK_LIBRARIES})
${VTK_LIBRARIES})
if(TARGET vtkRenderingContext${VTK_RENDERING_BACKEND})
list(APPEND VTK_LIBRARIES vtkRenderingContext${VTK_RENDERING_BACKEND})
endif()
endif()

endif()

if(${VTK_VERSION} VERSION_LESS "8.90")

if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
list(APPEND VTK_LIBRARIES ${PYTHON_LIBRARY} ${PYTHONQT_LIBRARIES})
Expand All @@ -163,6 +207,18 @@ if(Q_WS_X11)
list(APPEND VTK_LIBRARIES ${X11_LIBRARIES})
endif()

endif()

# Custom export content
if(${VTK_VERSION} VERSION_LESS "8.90")
set(CTK_VTK_EXPORT_CUSTOM_CONTENT "")
else()
set(CTK_VTK_EXPORT_CUSTOM_CONTENT "#ifndef VTK_OVERRIDE
#define VTK_OVERRIDE override;
#endif
")
endif()

# Target libraries - See CMake/ctkFunctionGetTargetLibraries.cmake
# The following macro will read the target libraries from the file 'target_libraries.cmake'
ctkFunctionGetTargetLibraries(KIT_target_libraries)
Expand All @@ -173,9 +229,10 @@ ctkMacroBuildLib(
SRCS ${KIT_SRCS}
MOC_SRCS ${KIT_MOC_SRCS}
UI_FORMS ${KIT_UI_FORMS}
TARGET_LIBRARIES ${KIT_target_libraries}
TARGET_LIBRARIES ${KIT_target_libraries} ${PYTHONQT_LIBRARIES}
RESOURCES ${KIT_resources}
LIBRARY_TYPE ${CTK_LIBRARY_MODE}
EXPORT_CUSTOM_CONTENT_FROM_VARIABLE "CTK_VTK_EXPORT_CUSTOM_CONTENT"
)

if(CTK_WRAP_PYTHONQT_LIGHT)
Expand All @@ -186,6 +243,13 @@ if(CTK_WRAP_PYTHONQT_LIGHT)
)
endif()

if (NOT VTK_VERSION VERSION_LESS "8.90.0")
vtk_module_autoinit(
TARGETS ${PROJECT_NAME}
MODULES ${VTK_LIBRARIES}
)
endif()

# Plugins
#if(CTK_BUILD_QTDESIGNER_PLUGINS)
# add_subdirectory(Plugins)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ int vtkLightBoxRendererManagerTest1(int argc, char* argv[])

// Read image
imageReader->SetFileName(imageFilename);
#if (VTK_MAJOR_VERSION <= 5)
imageReader->Update();
vtkImageData* image = imageReader->GetOutput();
#else
vtkAlgorithmOutput* imagePort = imageReader->GetOutputPort();
#endif

//----------------------------------------------------------------------------
// Renderer, RenderWindow and Interactor
Expand Down Expand Up @@ -172,18 +167,11 @@ int vtkLightBoxRendererManagerTest1(int argc, char* argv[])
return EXIT_FAILURE;
}

#if (VTK_MAJOR_VERSION <= 5)
lightBoxRendererManager->SetImageData(image);
#else
lightBoxRendererManager->SetImageDataConnection(imagePort);
#endif

if (mtime != lightBoxRendererManager->GetMTime())
{
#if (VTK_MAJOR_VERSION <= 5)
std::cerr << "line " << __LINE__ << " - Problem with SetImageData()" << std::endl;
#else
std::cerr << "line " << __LINE__ << " - Problem with SetImageDataConnection()" << std::endl;
#endif
return EXIT_FAILURE;
}

Expand Down Expand Up @@ -215,12 +203,7 @@ int vtkLightBoxRendererManagerTest1(int argc, char* argv[])
return EXIT_FAILURE;
}


#if (VTK_MAJOR_VERSION <= 5)
lightBoxRendererManager->SetImageData(image);
#else
lightBoxRendererManager->SetImageDataConnection(imagePort);
#endif
lightBoxRendererManager->SetRenderWindowLayout(4, 5);
lightBoxRendererManager->SetHighlighted(2,2,true);
lightBoxRendererManager->SetColorWindowAndLevel(100, 100);
Expand Down
8 changes: 0 additions & 8 deletions Libs/Visualization/VTK/Core/ctkVTKPythonQtWrapperFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ PyObject* ctkVTKPythonQtWrapperFactory::wrap(const QByteArray& classname, void *
{
if (classname.startsWith("vtk"))
{
#if (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION <= 6) || VTK_MAJOR_VERSION < 5
return vtkPythonGetObjectFromPointer(reinterpret_cast<vtkObjectBase*>(ptr));
#else
return vtkPythonUtil::GetObjectFromPointer(reinterpret_cast<vtkObjectBase*>(ptr));
#endif
}
return NULL;
}
Expand All @@ -36,11 +32,7 @@ void* ctkVTKPythonQtWrapperFactory::unwrap(const QByteArray& classname, PyObject
{
if (classname.startsWith("vtk"))
{
#if (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION <= 6) || VTK_MAJOR_VERSION < 5
return vtkPythonGetPointerFromObject(object, classname.data());
#else
return vtkPythonUtil::GetPointerFromObject(object, classname.data());
#endif
}
return NULL;
}
54 changes: 1 addition & 53 deletions Libs/Visualization/VTK/Core/vtkLightBoxRendererManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ RenderWindowItem::RenderWindowItem(const double rendererBackgroundColor[3],
//-----------------------------------------------------------------------------
RenderWindowItem::~RenderWindowItem()
{
#if (VTK_MAJOR_VERSION <= 5)
this->ImageMapper->SetInput(0);
#else
this->ImageMapper->SetInputConnection(0);
#endif
}

//-----------------------------------------------------------------------------
Expand All @@ -136,11 +132,6 @@ void RenderWindowItem::SetupImageMapperActor(double colorWindow, double colorLev
this->ImageActor = vtkSmartPointer<vtkActor2D>::New();
this->ImageActor->SetMapper(this->ImageMapper);
this->ImageActor->GetProperty()->SetDisplayLocationToBackground();

// .. and add it to the renderer
#if VTK_MAJOR_VERSION <= 5
this->Renderer->AddActor2D(this->ImageActor.GetPointer());
#endif
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -201,15 +192,9 @@ void RenderWindowItem::SetupHighlightedBoxActor(const double highlightedBoxColor
coordinate->SetViewport(this->Renderer);

vtkNew<vtkPolyDataMapper2D> polyDataMapper;
#if VTK_MAJOR_VERSION <= 5
polyDataMapper->SetInput(poly.GetPointer());
#else
polyDataMapper->SetInputData(poly.GetPointer());
#endif
polyDataMapper->SetTransformCoordinate(coordinate.GetPointer());
#if ! (VTK_MAJOR_VERSION == 5 && VTK_MINOR_VERSION == 8)
polyDataMapper->SetTransformCoordinateUseDouble(true);
#endif
polyDataMapper->SetTransformCoordinateUseDouble(true);

this->HighlightedBoxActor = vtkSmartPointer<vtkActor2D>::New();
this->HighlightedBoxActor->SetMapper(polyDataMapper.GetPointer());
Expand All @@ -219,10 +204,6 @@ void RenderWindowItem::SetupHighlightedBoxActor(const double highlightedBoxColor
this->HighlightedBoxActor->GetProperty()->SetDisplayLocationToForeground();
this->HighlightedBoxActor->GetProperty()->SetLineWidth(1.0f);
this->HighlightedBoxActor->SetVisibility(visible);

#if VTK_MAJOR_VERSION <= 5
this->Renderer->AddActor2D(this->HighlightedBoxActor);
#endif
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -257,12 +238,7 @@ class vtkLightBoxRendererManager::vtkInternal
vtkWeakPointer<vtkRenderWindowInteractor> CurrentInteractor;
vtkSmartPointer<vtkCornerAnnotation> CornerAnnotation;
std::string CornerAnnotationText;

#if (VTK_MAJOR_VERSION <= 5)
vtkWeakPointer<vtkImageData> ImageData;
#else
vtkWeakPointer<vtkAlgorithmOutput> ImageDataConnection;
#endif
double ColorWindow;
double ColorLevel;
double RendererBackgroundColor[3];
Expand Down Expand Up @@ -418,9 +394,6 @@ void vtkLightBoxRendererManager::vtkInternal::updateRenderWindowItemsZIndex(int
void vtkLightBoxRendererManager::vtkInternal
::SetItemInput(RenderWindowItem* item)
{
#if (VTK_MAJOR_VERSION <= 5)
item->ImageMapper->SetInput(this->ImageData);
#else
item->ImageMapper->SetInputConnection(this->ImageDataConnection);
bool hasViewProp = item->Renderer->HasViewProp(item->ImageActor);
if (!hasViewProp)
Expand All @@ -431,7 +404,6 @@ ::SetItemInput(RenderWindowItem* item)
item->Renderer->AddActor2D(item->HighlightedBoxActor);
}
item->ImageActor->SetVisibility(this->ImageDataConnection != NULL);
#endif
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -506,27 +478,15 @@ bool vtkLightBoxRendererManager::IsInitialized()
}

//----------------------------------------------------------------------------
#if (VTK_MAJOR_VERSION <= 5)
void vtkLightBoxRendererManager::SetImageData(vtkImageData* newImageData)
#else
void vtkLightBoxRendererManager::SetImageDataConnection(vtkAlgorithmOutput* newImageDataConnection)
#endif
{
if (!this->IsInitialized())
{
#if (VTK_MAJOR_VERSION <= 5)
vtkErrorMacro(<< "SetImageData failed - vtkLightBoxRendererManager is NOT initialized");
#else
vtkErrorMacro(<< "SetImageDataConnection failed - vtkLightBoxRendererManager is NOT initialized");
#endif
return;
}

#if (VTK_MAJOR_VERSION <= 5)
this->Internal->ImageData = newImageData;
#else
this->Internal->ImageDataConnection = newImageDataConnection;
#endif

vtkInternal::RenderWindowItemListIt it;
for(it = this->Internal->RenderWindowItemList.begin();
Expand All @@ -536,11 +496,7 @@ void vtkLightBoxRendererManager::SetImageDataConnection(vtkAlgorithmOutput* newI
this->Internal->SetItemInput(*it);
}

#if (VTK_MAJOR_VERSION <= 5)
if (newImageData)
#else
if (newImageDataConnection)
#endif
{
this->Internal->updateRenderWindowItemsZIndex(this->Internal->RenderWindowLayoutType);
}
Expand Down Expand Up @@ -643,11 +599,7 @@ void vtkLightBoxRendererManager::SetRenderWindowLayoutType(int layoutType)
return;
}

#if (VTK_MAJOR_VERSION <= 5)
if (this->Internal->ImageData)
#else
if (this->Internal->ImageDataConnection)
#endif
{
this->Internal->updateRenderWindowItemsZIndex(layoutType);
}
Expand Down Expand Up @@ -722,11 +674,7 @@ void vtkLightBoxRendererManager::SetRenderWindowLayout(int rowCount, int columnC
this->Internal->setupRendering();
this->Internal->SetupCornerAnnotation();

#if (VTK_MAJOR_VERSION <= 5)
if (this->Internal->ImageData)
#else
if (this->Internal->ImageDataConnection)
#endif
{
this->Internal->updateRenderWindowItemsZIndex(this->Internal->RenderWindowLayoutType);
}
Expand Down
Loading