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

VTK 9.0 Support #4096

Closed
wants to merge 18 commits into from
Closed

VTK 9.0 Support #4096

wants to merge 18 commits into from

Conversation

pionex
Copy link

@pionex pionex commented May 14, 2020

This code allows PCL master to compile and generally run with VTK 9.0.0. Some attempt was made to allow this code to be backwards compatible with older versions of VTK, although that has not been fully tested.

The main cmake has been updated to work with the breaking new conventions and has some backwards compatibility. It will not currently work with QT support with an older version of VTK, however.

The visualization cmake has been modified to call the new vtk_module_autoinit functionality. In my testing, so far I have only found that this needs to occur to make the visualizer work, but its possible other vtk modules need to be initialized for additional targets.

The changes made vtkCellArray usage in pcl_visualizer in the add/update polygon mesh functions are still being tested. There was some commented code that I used to make this compile, but I don't know if this fully works or offers the best performance.

The vtkIdType * were changed to vtkIdType const * where necessary to support the new API, although the VTK documentation recommends to use iterators instead if possible.

Version 2 of vtkCellArray deprecates the write pointer and requires const pointers in in some api calls that return pointers to shared memory.  If the VTK_CELL_ARRAY_V2 macro is defined, this code uses the appropriate const pointers and uses alternative methods to insert cells into the cell array.  This commit also adds some missing vtk headers that were causing incomplete type errors.
@kunaltyagi
Copy link
Member

Closes #4095

@kunaltyagi kunaltyagi added this to In progress in Update dependencies via automation May 14, 2020
Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMake not reviewed

@@ -3611,7 +3642,12 @@ pcl::visualization::PCLVisualizer::renderViewTesselatedSphere (
// * Compute area of the mesh
//////////////////////////////
vtkSmartPointer<vtkCellArray> cells = mapper->GetInput ()->GetPolys ();
vtkIdType npts = 0, *ptIds = nullptr;
vtkIdType npts = 0;
#ifdef VTK_CELL_ARRAY_V2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract out this type. Sample code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the point of extracting this out to eliminate multiple ifdefs everywhere its used?

I was searching for a good common place to define this type, but there doesn't appear to be any common header file. Should it be (re)defined in each module where its necessary?

I'm assuming you mean something like:

#ifdef VTK_CELL_ARRAY_V2
using vtkCellPtsPtr = vtkIdType const *;
#else
using vtkCellPtsPtr = vtkIdType*;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also looking into using iterators and it seems straightforward, but this change is still required

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I seemed to have missed this conversation.

Is the point of extracting this out to eliminate multiple ifdefs

👍

Should it be (re)defined in each module where its necessary

That wouldn't be ideal. A single new header somewhere would be better, but I also don't know where.

surface/src/vtk_smoothing/vtk_utils.cpp Show resolved Hide resolved
Update dependencies automation moved this from In progress to Review in progress May 14, 2020
@kunaltyagi kunaltyagi added changelog: enhancement Meta-information for changelog generation module: cmake module: visualization needs: code review Specify why not closed/merged yet needs: more work Specify why not closed/merged yet labels May 14, 2020
@pionex pionex marked this pull request as draft May 14, 2020 03:24
@kunaltyagi
Copy link
Member

kunaltyagi commented May 14, 2020

VTK documentation recommends to use iterators instead if possible

Perhaps using iterators is a better way to go forwards. We can split the logic using macros from when iterators first came to VTK API and use the current logic for older VTK. This can allow us to make decisions such as stopping support for old versions: VTK 7 and higher are available on all platforms being targeted.

Ubuntu 16.04 package Ubuntu 18.04 package Vcpkg package Homebrew package

It will not currently work with QT support with an older version of VTK

Should I mark this PR as draft or are you looking for feedback from PCL to add this support?

PS: The CI will be red since we look for VTK 6 and 7 on Ubuntu

I don't know if this fully works or offers the best performance

Note for others: Needs testing

@kunaltyagi kunaltyagi added needs: testing Specify why not closed/merged yet needs: author reply Specify why not closed/merged yet labels May 14, 2020
@larshg
Copy link
Contributor

larshg commented May 14, 2020

Some work was also done here #3637

@pionex
Copy link
Author

pionex commented May 14, 2020

Some work was also done here #3637

How should we collaborate to consolidate these changes?

@larshg
Copy link
Contributor

larshg commented May 16, 2020

Hey Pionex

I'm testing your branch out and I have done a few cmake changes.

But I can't get it to compile. I get a bunch of:
'vtkSmartPointerBase &vtkSmartPointerBase::operator =(const vtkSmartPointerBase &)': cannot convert argument 1 from 'T *' to 'vtkObjectBase *'

Did you get this?

Edit: I'm on win10 using VS2019.

@larshg
Copy link
Contributor

larshg commented May 16, 2020

It was missing includes, that probably was transparently included... VS is not so forgiving 🙄

Added PR to @pionex 's PR.

@kunaltyagi
Copy link
Member

The PR made by @larshg

@kunaltyagi kunaltyagi removed needs: author reply Specify why not closed/merged yet needs: code review Specify why not closed/merged yet labels May 16, 2020
Move RenderingUI as it is not available vtk < 9.0
@larshg
Copy link
Contributor

larshg commented May 21, 2020

@pionex I have tested with my vtk 8.2 system and made a few changes. Please merge it and lets fix the last things mentioned by @kunaltyagi.

@larshg
Copy link
Contributor

larshg commented May 26, 2020

@pionex where is VTK_CELL_ARRAY_V2 defined? - Nm - found it.

@pionex
Copy link
Author

pionex commented May 26, 2020

I can have a look at this in a few. How much longer will you be working on it today? I’m in GMT+12, so day is just starting.

@larshg
Copy link
Contributor

larshg commented May 26, 2020

I'm off to bed now so go ahead. You can look if the ci is green with my latest push to my pr also.

I was thinking of making a compat header in visualization and then those that can use this will(visualization and all that depends on visualization).
The rest ie I/O and surface.. maybe more cant remember I would leave as is with the if defs.

There is no common sub module which imports vtk and it seems overkill to make such project for a few extra if defs.

@larshg larshg mentioned this pull request May 28, 2020
@@ -87,7 +87,9 @@ else()
list(APPEND PCL_VTK_COMPONENTS RenderingContext${VTK_RENDERING_BACKEND})
endif()

message("WITH_QT is:${WITH_QT}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a space after the colon 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was more for 'debugging' - but I guess the information is nice to have, but could probably be consolidated to a single line summerizing most of the VTK settings 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was an issue about producing a full-blown CMake configuration report for PCL, maybe it's the kind of information that could go there when it happens.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's something nice and available in 3.5 too (Ubuntu 16.04's CMake version)

@Morwenn is there a issue for this CMake reporting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kunaltyagi I thought so but apparently it was merely a comment in issue #3603, my memory failed me. Such a summary is definitely something valuable when dealing with build issues (and especially good when users report issues, you don't have to ask again and again for the information). I didn't know that CMake had a built-in feature to report the options, that's nice.

@larshg
Copy link
Contributor

larshg commented Jun 13, 2020

@pionex have you done any work - feel like we are close to make it possible to merge? If you are busy I don't mind picking it up and try to complete it.

@pionex
Copy link
Author

pionex commented Jun 15, 2020

@pionex have you done any work - feel like we are close to make it possible to merge? If you are busy I don't mind picking it up and try to complete it.

Please go ahead. I wasn't sure where to put the new headers.

This warning might also be something to look into:
vtkOpenGLPolyDataMapper::SetFragmentShaderCode was deprecated for VTK 9.0 and will be removed in a future version. Use vtkOpenGLShaderProperty::SetFragmentShaderCode instead

Do I need to do anything on github for you to pick it up?

Comment on lines +15 to +72
#Change to use list Transform when cmake is >= 3.12
if(NOT (${VTK_VERSION} VERSION_LESS 9.0))
set(PCL_VTK_COMPONENTS
ChartsCore
CommonColor
CommonCore
CommonDataModel
CommonExecutionModel
CommonMath
CommonMisc
CommonTransforms
FiltersCore
FiltersExtraction
FiltersGeneral
FiltersGeometry
FiltersModeling
FiltersSources
ImagingCore
ImagingSources
InteractionStyle
InteractionWidgets
IOCore
IOGeometry
IOImage
IOLegacy
IOPLY
RenderingAnnotation
RenderingCore
RenderingContext2D
RenderingLOD
RenderingFreeType
RenderingOpenGL2
ViewsCore
ViewsContext2D
)
else()
set(PCL_VTK_COMPONENTS
vtkChartsCore
vtkCommonCore
vtkCommonDataModel
vtkCommonExecutionModel
vtkFiltersCore
vtkFiltersExtraction
vtkFiltersModeling
vtkImagingCore
vtkImagingSources
vtkInteractionStyle
vtkInteractionWidgets
vtkIOCore
vtkIOGeometry
vtkIOImage
vtkIOLegacy
vtkIOPLY
vtkRenderingAnnotation
vtkRenderingLOD
vtkViewsContext2D
)
endif()
Copy link
Contributor

@SunBlack SunBlack Jun 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation of set is missing.

Is it really necessary to have two lists? I had started more than one moth ago same test (just didn't had time to continue and as this PR also exists)...

I had solved it by:

function(checkVTKComponents)
  cmake_parse_arguments(PARAM "" "MISSING_COMPONENTS" "COMPONENTS" ${ARGN})

  set(vtkMissingComponents)
  if (VTK_VERSION VERSION_GREATER "8.2")
    foreach(vtkComponent ${PARAM_COMPONENTS})
      if (NOT TARGET VTK::${vtkComponent})
        list(APPEND vtkMissingComponents ${vtkComponent})
      endif()
    endforeach()
  else()
    foreach(vtkComponent ${PARAM_COMPONENTS})
      set(vtkComponent "vtk${vtkComponent}")
      if (NOT TARGET ${vtkComponent})
        list(APPEND vtkMissingComponents ${vtkComponent})
      endif()
    endforeach()
  endif()
  set(${PARAM_MISSING_COMPONENTS} ${vtkMissingComponents} PARENT_SCOPE)
endfunction()

set(PCL_VTK_COMPONENTS
  ChartsCore
  CommonCore
  CommonDataModel
  CommonExecutionModel
  FiltersCore
  FiltersExtraction
  FiltersModeling
  ImagingCore
  ImagingSources
  InteractionStyle
  InteractionWidgets
  IOCore
  IOGeometry
  IOImage
  IOLegacy
  IOPLY
  RenderingAnnotation
  RenderingLOD
  ViewsContext2D
)

# Start with a generic call to find any VTK version we are supporting, so we retrieve
# the version of VTK. As the module names were changed from VTK 8.2 to 9.0, we don't
# search explicitly for modules. Furthermore we don't pass required minimum version 6.2
# to find_package because then it only accept versions with same major version.
find_package(VTK)
if(VTK_FOUND AND ("${VTK_VERSION}" VERSION_LESS 6.2))
  message(WARNING "The minimum required version of VTK is 6.2, but found ${VTK_VERSION}")
  set(VTK_FOUND FALSE)
  return()
endif()

# We still require vtkOpenGLExtensionManager and vtkOpenGLRenderWindow
# Before VTK 8.2 they were part of VTK compontent
# Since VTK 8.2 they were part of VTK compontent vtkOpenGLRenderWindow => "OpenGL2", vtkOpenGLExtensionManager => missing
if("${VTK_VERSION}" VERSION_LESS 8.2)
  set(VTK_RENDERING_BACKEND "OpenGL")
else()
  set(VTK_RENDERING_BACKEND "OpenGL2")
endif()

# Check if requested modules are available
checkVTKComponents(COMPONENTS ${PCL_VTK_COMPONENTS} MISSING_COMPONENTS vtkMissingComponents)
message(STATUS "${vtkMissingComponents}")
if (vtkMissingComponents)
  set(VTK_FOUND FALSE)
  message(WARNING "Missing vtk modules: ${vtkMissingComponents}")
  return()
endif()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into using your snippet.

Originally it was using List transform, but that wasn't available. But an "ordinary" foreach could be used ofc.

@tkircher
Copy link

tkircher commented Jul 1, 2020

Thank you for this! It's a strange feeling having a build of PCL that isn't years out of date.


message("WITH_QT is:${WITH_QT}")
if(WITH_QT)
message("VTK_MODULES_ENABLED is: ${VTK_MODULES_ENABLED}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VTK 9.0 has "VTK_AVAILABLE_COMPONENTS" instead of "VTK_MODULES_ENABLED"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for mentioning it. Saw it yesterday as well :-)

@larshg larshg mentioned this pull request Jul 11, 2020
@bpoebiapl
Copy link

any update?

@larshg
Copy link
Contributor

larshg commented Jul 30, 2020

I'm doing slowly progress in #4262 instead of this one.

@larshg larshg closed this in #4262 Feb 16, 2021
Update dependencies automation moved this from Review in progress to Done Feb 16, 2021
@kaitou1419
Copy link

please fix ERROR: pcl\visualiztion is missing when install with vcpkg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: enhancement Meta-information for changelog generation module: cmake module: visualization needs: more work Specify why not closed/merged yet needs: testing Specify why not closed/merged yet
Projects