Skip to content

Commit

Permalink
ENH: Support VTK6 in CTK
Browse files Browse the repository at this point in the history
1) Support vtk6 to build system.
http://www.vtk.org/Wiki/VTK/Build_System_Migration
Give users a build option between vtk5 and vtk6.
Solve vtk library python wrapping for VTK 6

2) Replace SetInput() with SetInputData() and SetInputConnection(), the same kind of functions include SetInput1(), SetInput2(), AddInput() and SetSource().
http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Replacement_of_SetInput

3) Change scalars manipulation functions
http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Changes_to_Scalars_Manipulation_Functions.
http://vtk.org/Wiki/VTK/VTK6/Migration/WikiExamples#Improve.

4) VTK requires #include <vtkVersion.h> to use the VTK_xxx_VERSION preprocessor directives.
http://vtk.org/Wiki/VTK/VTK6/Migration/WikiExamples#Improve

5) Remove deprecated Macro.
The following two macros were deprecated in VTK 5.0 that were still supported, but have now been eliminated:
vtkTypeRevisionMacro has been replaced with vtkTypeMacro; vtkCxxRevisionMacro has been removed.
http://www.visitusers.org/index.php?title=VTK_6.0_Upgrade

6)Refactor functions in vtkMRMLVolumeNode and its subclasses.
Use ImageDataPort instead of ImageData
  • Loading branch information
yuzhengZ committed Mar 5, 2014
1 parent db5a3fa commit c683240
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 19 deletions.
32 changes: 25 additions & 7 deletions Libs/Visualization/VTK/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,34 @@ if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_
endif()

# Set VTK_LIBRARIES variable
set(VTK_LIBRARIES
vtkCommon
vtkFiltering
vtkRendering
vtkHybrid
)
if(${VTK_VERSION_MAJOR} GREATER 5)
set(VTK_LIBRARIES
vtkCommonCore
vtkCommonDataModel
vtkCommonSystem
vtkIOImage
vtkInteractionStyle
vtkRenderingAnnotation
vtkRenderingCore
vtkRenderingFreeTypeFontConfig
vtkRenderingFreeTypeOpenGL
vtkRenderingOpenGL
vtkTestingRendering
)
else()
set(VTK_LIBRARIES
vtkCommon
vtkFiltering
vtkRendering
vtkHybrid
)
endif()

if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
list(APPEND VTK_LIBRARIES ${PYTHON_LIBRARY} ${PYTHONQT_LIBRARIES})
if(${VTK_VERSION_MAJOR}.${VTK_VERSION_MINOR} VERSION_GREATER 5.6)
if(${VTK_VERSION_MAJOR} GREATER 5)
list(APPEND VTK_LIBRARIES vtkWrappingPythonCore)
elseif(${VTK_VERSION_MAJOR}.${VTK_VERSION_MINOR} VERSION_GREATER 5.6)
list(APPEND VTK_LIBRARIES vtkPythonCore)
else()
list(APPEND VTK_LIBRARIES vtkCommonPythonD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ int vtkLightBoxRendererManagerTest1(int argc, char* argv[])
// Read image
imageReader->SetFileName(imageFilename);
imageReader->Update();
#if (VTK_MAJOR_VERSION <= 5)
vtkSmartPointer<vtkImageData> image = imageReader->GetOutput();
#else
vtkSmartPointer<vtkAlgorithmOutput> imagePort = imageReader->GetOutputPort();
#endif

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

#if (VTK_MAJOR_VERSION <= 5)
lightBoxRendererManager->SetImageData(image);
#else
lightBoxRendererManager->SetImageDataPort(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 SetImageDataPort()" << std::endl;
#endif
return EXIT_FAILURE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// VTK includes
#include <vtkPythonUtil.h>
#include <vtkObject.h>
#include <vtkVersion.h>

//-----------------------------------------------------------------------------
ctkVTKPythonQtWrapperFactory::ctkVTKPythonQtWrapperFactory():Superclass()
Expand Down
41 changes: 37 additions & 4 deletions Libs/Visualization/VTK/Core/vtkLightBoxRendererManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "vtkLightBoxRendererManager.h"

// VTK includes
#include <vtkAlgorithmOutput.h>
#include <vtkCamera.h>
#include <vtkCellArray.h>
#include <vtkConfigure.h>
Expand All @@ -38,14 +39,14 @@
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkTextProperty.h>
#include <vtkVersion.h>
#include <vtkWeakPointer.h>

// STD includes
#include <vector>
#include <cassert>

//----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkLightBoxRendererManager, "$Revision:$");
vtkStandardNewMacro(vtkLightBoxRendererManager);

namespace
Expand Down Expand Up @@ -99,7 +100,11 @@ RenderWindowItem::RenderWindowItem(const double rendererBackgroundColor[3],
//-----------------------------------------------------------------------------
RenderWindowItem::~RenderWindowItem()
{
#if (VTK_MAJOR_VERSION <= 5)
this->ImageMapper->SetInput(0);
#else
this->ImageMapper->SetInputConnection(0);
#endif
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -242,7 +247,11 @@ class vtkLightBoxRendererManager::vtkInternal
vtkSmartPointer<vtkCornerAnnotation> CornerAnnotation;
std::string CornerAnnotationText;

#if (VTK_MAJOR_VERSION <= 5)
vtkWeakPointer<vtkImageData> ImageData;
#else
vtkWeakPointer<vtkAlgorithmOutput> ImageDataPort;
#endif
double ColorWindow;
double ColorLevel;
double RendererBackgroundColor[3];
Expand Down Expand Up @@ -457,31 +466,47 @@ bool vtkLightBoxRendererManager::IsInitialized()
}

//----------------------------------------------------------------------------
#if (VTK_MAJOR_VERSION <= 5)
void vtkLightBoxRendererManager::SetImageData(vtkImageData* newImageData)
#else
void vtkLightBoxRendererManager::SetImageDataPort(vtkAlgorithmOutput* newImageDataPort)
#endif
{
if (!this->IsInitialized())
{
#if (VTK_MAJOR_VERSION <= 5)
vtkErrorMacro(<< "SetImageData failed - vtkLightBoxRendererManager is NOT initialized");
#else
vtkErrorMacro(<< "SetImageDataPort failed - vtkLightBoxRendererManager is NOT initialized");
#endif
return;
}
vtkInternal::RenderWindowItemListIt it;
for(it = this->Internal->RenderWindowItemList.begin();
it != this->Internal->RenderWindowItemList.end();
++it)
{
#if VTK_MAJOR_VERSION <= 5
#if (VTK_MAJOR_VERSION <= 5)
(*it)->ImageMapper->SetInput(newImageData);
#else
(*it)->ImageMapper->SetInputData(newImageData);
(*it)->ImageMapper->SetInputConnection(newImageDataPort);
#endif
}

#if (VTK_MAJOR_VERSION <= 5)
if (newImageData)
#else
if (newImageDataPort)
#endif
{
this->Internal->updateRenderWindowItemsZIndex(this->Internal->RenderWindowLayoutType);
}

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

this->Modified();
}
Expand Down Expand Up @@ -581,7 +606,11 @@ void vtkLightBoxRendererManager::SetRenderWindowLayoutType(int layoutType)
return;
}

#if (VTK_MAJOR_VERSION <= 5)
if (this->Internal->ImageData)
#else
if (this->Internal->ImageDataPort)
#endif
{
this->Internal->updateRenderWindowItemsZIndex(layoutType);
}
Expand Down Expand Up @@ -635,7 +664,7 @@ void vtkLightBoxRendererManager::SetRenderWindowLayout(int rowCount, int columnC
#if VTK_MAJOR_VERSION <= 5
item->ImageMapper->SetInput(this->Internal->ImageData);
#else
item->ImageMapper->SetInputData(this->Internal->ImageData);
item->ImageMapper->SetInputConnection(this->Internal->ImageDataPort);
#endif
this->Internal->RenderWindowItemList.push_back(item);
--extraItem;
Expand All @@ -659,7 +688,11 @@ 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->ImageDataPort)
#endif
{
this->Internal->updateRenderWindowItemsZIndex(this->Internal->RenderWindowLayoutType);
}
Expand Down
8 changes: 7 additions & 1 deletion Libs/Visualization/VTK/Core/vtkLightBoxRendererManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define __vtkLightBoxRendererManager_h

#include <vtkObject.h>
#include <vtkVersion.h>

#include "ctkVisualizationVTKCoreExport.h"

Expand All @@ -30,11 +31,12 @@ class vtkRenderer;
class vtkImageData;
class vtkCamera;
class vtkCornerAnnotation;
class vtkAlgorithmOutput;

/// \ingroup Visualization_VTK_Core
class CTK_VISUALIZATION_VTK_CORE_EXPORT vtkLightBoxRendererManager : public vtkObject
{
vtkTypeRevisionMacro(vtkLightBoxRendererManager,vtkObject);
vtkTypeMacro(vtkLightBoxRendererManager,vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
static vtkLightBoxRendererManager *New();

Expand All @@ -51,7 +53,11 @@ class CTK_VISUALIZATION_VTK_CORE_EXPORT vtkLightBoxRendererManager : public vtkO
vtkRenderWindow* GetRenderWindow();

/// Set image data
#if (VTK_MAJOR_VERSION <= 5)
void SetImageData(vtkImageData* newImageData);
#else
void SetImageDataPort(vtkAlgorithmOutput* newImageDataPort);
#endif

/// Get active camera
/// Note that the same camera is used with all the renderWindowItem
Expand Down
39 changes: 35 additions & 4 deletions Libs/Visualization/VTK/Widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,34 @@ set(KIT_resources
)

# Set VTK_LIBRARIES variable
set(VTK_LIBRARIES
QVTK
)
if(${VTK_VERSION_MAJOR} GREATER 5)
set(VTK_LIBRARIES
vtkChartsCore
vtkCommonCore
vtkCommonDataModel
vtkCommonMath
vtkCommonSystem
vtkFiltersSources
vtkIOImage
vtkImagingGeneral
vtkImagingStatistics
vtkInteractionStyle
vtkInteractionWidgets
vtkRenderingAnnotation
vtkRenderingContext2D
vtkRenderingCore
vtkRenderingFreeTypeFontConfig
vtkRenderingFreeTypeOpenGL
vtkRenderingOpenGL
vtkViewsContext2D
vtkWrappingPythonCore
vtkGUISupportQt
)
else()
set(VTK_LIBRARIES
QVTK
)
endif()

if(CTK_LIB_Visualization/VTK/Widgets_USE_TRANSFER_FUNCTION_CHARTS)
set(CTK_USE_CHARTS 1)
Expand All @@ -123,9 +148,15 @@ IF (${CTK_USE_CHARTS})
Resources/UI/ctkVTKVolumePropertyWidget.ui
Resources/UI/ctkVTKScalarsToColorsWidget.ui
${KIT_UI_FORMS})
set(VTK_LIBRARIES
if(${VTK_VERSION_MAJOR} GREATER 5)
set(VTK_LIBRARIES
vtkChartsCore
${VTK_LIBRARIES})
else()
set(VTK_LIBRARIES
vtkCharts
${VTK_LIBRARIES})
endif()
add_definitions(-DCTK_USE_CHARTS)
endif()

Expand Down
8 changes: 7 additions & 1 deletion Libs/Visualization/VTK/Widgets/Testing/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ set(Tests_RESOURCES_SRCS)
QT4_ADD_RESOURCES(Tests_RESOURCES_SRCS ${Tests_RESOURCES})

add_executable(${KIT}CppTests ${Tests} ${TEST_MOC_CPP} ${TEST_UI_CPP} ${Tests_RESOURCES_SRCS})
target_link_libraries(${KIT}CppTests ${LIBRARY_NAME} vtkCharts ${CTK_BASE_LIBRARIES})
if(${VTK_VERSION_MAJOR} GREATER 5)
set(VTK_CHARTS_LIB vtkChartsCore)
else()
set(VTK_CHARTS_LIB vtkCharts)
endif()

target_link_libraries(${KIT}CppTests ${LIBRARY_NAME} ${VTK_CHARTS_LIB} ${CTK_BASE_LIBRARIES})

#
# Add Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <vtkNew.h>
#include <vtkPlotBar.h>
#include <vtkTable.h>
#include <vtkVersion.h>

// STD includes
#include <iostream>
Expand Down Expand Up @@ -78,19 +79,31 @@ int ctkVTKChartViewTest1(int argc, char * argv [] )

// Add multiple line plots, setting the colors etc
vtkPlotBar* bar = vtkPlotBar::New();
#if (VTK_MAJOR_VERSION <= 5)
bar->SetInput(table.GetPointer(), 0, 1);
#else
bar->SetInputData(table.GetPointer(), 0, 1);
#endif
bar->SetColor(0, 255, 0, 255);
view.addPlot(bar);
bar->Delete();

bar = vtkPlotBar::New();
#if (VTK_MAJOR_VERSION <= 5)
bar->SetInput(table.GetPointer(), 0, 2);
#else
bar->SetInputData(table.GetPointer(), 0, 2);
#endif
bar->SetColor(255, 0, 0, 255);
view.addPlot(bar);
bar->Delete();

bar = vtkPlotBar::New();
#if (VTK_MAJOR_VERSION <= 5)
bar->SetInput(table.GetPointer(), 0, 3);
#else
bar->SetInputData(table.GetPointer(), 0, 3);
#endif
bar->SetColor(0, 0, 255, 255);
view.addPlot(bar);
bar->Delete();
Expand Down
Loading

0 comments on commit c683240

Please sign in to comment.