Building VTK with OpenCascade support

Hello, I am interested in using VTK’s vtkOCCTReader to read Step files in my python project. From reading Difficulty Accessing the vtkOCCTReader through the python modules it seems that the pip installation of VTK does not offer OpenCascade support so I need to build VTK on my own. I was able to build VTK using Cmake-gui which worked with other parts of my project but I still get the error " module ‘vtk’ has no attribute ‘vtkOCCTReader’". My question then is, how exactly do I enable OpenCascade support in my VTK build? I was not able to find “enable OpenCascade module” or something similar in cmake-gui as can be seen in the following image:

Look for VTK_MODULE_ENABLE_VTK_IOOCCT, you will need to install open cascade though.

Thank you for the fast answer Mathieu. I have managed to find VTK_MODULE_ENABLE_VTK_IOOCCT, seems I forgot to click on the “Advanced” checkbox on cmake-gui and that was hiding it. I will attempt to install OpenCascade and then rebuild VTK correctly.

1 Like

I have managed to install OpenCascade but while building VTK without the IOOCCT module works, every attempt at building with the module enabled gives me the error “ImportError: DLL load failed while importing vtkIOOCCT: The specified module could not be found” when running my project and I can’t really understand why that is.

Did you copy the OCCT dlls into your application folder?

I have added the path to the VTK folder to my PYTHONPATH environment variable and that seemed to work for builds without OpenCascade, even now when I look at the folder I can find the vtkIOOCCT dll and pyd files there so I don’t know why I am getting this error.

Hi,
How to install OpenCascade on windows I have downloaded the .zip file provided here . But I don’t find any .exe or .msi for installation

Not a VTK question, however you need to compile it yourself using CMake and visual studio.

Alternatively, you could find a binary version to install or use a tool like vcpkg.

Thank you for the reply…
I figured out the build using CMake, there is a flag USE_VTK, should it be ticked?? Do I need to Tick all INSTALL_XXX and USE_XXX flags…

I am actually trying to use vtkOCCTReader in python and I have never worked with CPP or CMake.

No

Do I need to Tick all INSTALL_XXX and USE_XXX flags…

Let them turned off and turn off a maximum of them.

You can look at VTK (actually ParaView) config for OCCT here:

https://gitlab.kitware.com/paraview/paraview-superbuild/-/blob/master/projects/occt.cmake?ref_type=heads

1 Like

@FrontEnd_Dev You are looking at the CMake config for building OpenCascade which is incorrect.

The first thing you should do is download the VTK source and build it with the default settings. Then check the VTK_MODULE_ENABLE_VTK_IOCCT flag.

Hi, I cloned the VTK repo and building using CMake
VTK_MODULE_ENABLE_VTK_IOOCCT has a DEFAULT value should I make it YES?
Any other settings I need to change

image

That’s what I would do. I expect the default value is NO. When you configure CMake it will then most likely require the OCCT source folder in a new variable.

Hi after I hit configure I got error for OpenCASCADE_DIR
Even I tried giving it the directory OpenCascade dir which I cloned from OpenCascade GitHub…


Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
CMake Deprecation Warning at ThirdParty/tiff/vtktiff/CMakeLists.txt:32 (cmake_policy):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


CMake Warning (dev) at CMake/vtkModule.cmake:4883 (install):
  Policy CMP0177 is not set: install() DESTINATION paths are normalized.  Run
  "cmake --help-policy CMP0177" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.
Call Stack (most recent call first):
  ThirdParty/eigen/vtkeigen/CMakeLists.txt:733 (vtk_module_install_headers)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMake/vtkObjectFactory.cmake:101 (cmake_parse_arguments):
  The INITIAL_CODE keyword was followed by an empty string or no value at
  all.  Policy CMP0174 is not set, so cmake_parse_arguments() will unset the
  _vtk_object_factory_configure_INITIAL_CODE variable rather than setting it
  to an empty string.
Call Stack (most recent call first):
  Rendering/UI/CMakeLists.txt:81 (vtk_object_factory_configure)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning at CMake/vtkModule.cmake:5351 (find_package):
  By not providing "FindOpenCASCADE.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "OpenCASCADE", but CMake did not find one.

  Could not find a package configuration file provided by "OpenCASCADE" with
  any of the following names:

    OpenCASCADEConfig.cmake
    opencascade-config.cmake

  Add the installation prefix of "OpenCASCADE" to CMAKE_PREFIX_PATH or set
  "OpenCASCADE_DIR" to a directory containing one of the above files.  If
  "OpenCASCADE" provides a separate development package or SDK, be sure it
  has been installed.
Call Stack (most recent call first):
  IO/OCCT/CMakeLists.txt:1 (vtk_module_find_package)


CMake Error at CMake/vtkModule.cmake:5357 (message):
  Could not find the OpenCASCADE external dependency.
Call Stack (most recent call first):
  IO/OCCT/CMakeLists.txt:1 (vtk_module_find_package)


Configuring incomplete, errors occurred!

Did you compiled and installed OpenCascade first ?

Hey I just did and gave the build path of OpenCascade and now getting this error

Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
CMake Deprecation Warning at ThirdParty/tiff/vtktiff/CMakeLists.txt:32 (cmake_policy):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


CMake Warning (dev) at CMake/vtkModule.cmake:4883 (install):
  Policy CMP0177 is not set: install() DESTINATION paths are normalized.  Run
  "cmake --help-policy CMP0177" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.
Call Stack (most recent call first):
  ThirdParty/eigen/vtkeigen/CMakeLists.txt:733 (vtk_module_install_headers)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMake/vtkObjectFactory.cmake:101 (cmake_parse_arguments):
  The INITIAL_CODE keyword was followed by an empty string or no value at
  all.  Policy CMP0174 is not set, so cmake_parse_arguments() will unset the
  _vtk_object_factory_configure_INITIAL_CODE variable rather than setting it
  to an empty string.
Call Stack (most recent call first):
  Rendering/UI/CMakeLists.txt:81 (vtk_object_factory_configure)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at D:/Work2/OCCT/build/OpenCASCADEConfig.cmake:47:
  Syntax Warning in cmake code at column 75

  Argument not separated from preceding token by whitespace.
Call Stack (most recent call first):
  CMake/vtkModule.cmake:5351 (find_package)
  IO/OCCT/CMakeLists.txt:1 (vtk_module_find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at D:/Work2/OCCT/build/OpenCASCADEConfig.cmake:102 (include):
  include could not find requested file:

    D:/Work2/OCCT/build/OpenCASCADEFoundationClassesTargets.cmake
Call Stack (most recent call first):
  CMake/vtkModule.cmake:5351 (find_package)
  IO/OCCT/CMakeLists.txt:1 (vtk_module_find_package)


CMake Error at D:/Work2/OCCT/build/OpenCASCADEConfig.cmake:102 (include):
  include could not find requested file:

    D:/Work2/OCCT/build/OpenCASCADEModelingDataTargets.cmake
Call Stack (most recent call first):
  CMake/vtkModule.cmake:5351 (find_package)
  IO/OCCT/CMakeLists.txt:1 (vtk_module_find_package)


CMake Error at D:/Work2/OCCT/build/OpenCASCADEConfig.cmake:102 (include):
  include could not find requested file:

    D:/Work2/OCCT/build/OpenCASCADEModelingAlgorithmsTargets.cmake
Call Stack (most recent call first):
  CMake/vtkModule.cmake:5351 (find_package)
  IO/OCCT/CMakeLists.txt:1 (vtk_module_find_package)


CMake Error at D:/Work2/OCCT/build/OpenCASCADEConfig.cmake:102 (include):
  include could not find requested file:

    D:/Work2/OCCT/build/OpenCASCADEVisualizationTargets.cmake
Call Stack (most recent call first):
  CMake/vtkModule.cmake:5351 (find_package)
  IO/OCCT/CMakeLists.txt:1 (vtk_module_find_package)


CMake Error at D:/Work2/OCCT/build/OpenCASCADEConfig.cmake:102 (include):
  include could not find requested file:

    D:/Work2/OCCT/build/OpenCASCADEApplicationFrameworkTargets.cmake
Call Stack (most recent call first):
  CMake/vtkModule.cmake:5351 (find_package)
  IO/OCCT/CMakeLists.txt:1 (vtk_module_find_package)


CMake Error at D:/Work2/OCCT/build/OpenCASCADEConfig.cmake:102 (include):
  include could not find requested file:

    D:/Work2/OCCT/build/OpenCASCADEDataExchangeTargets.cmake
Call Stack (most recent call first):
  CMake/vtkModule.cmake:5351 (find_package)
  IO/OCCT/CMakeLists.txt:1 (vtk_module_find_package)


CMake Error at D:/Work2/OCCT/build/OpenCASCADEConfig.cmake:102 (include):
  include could not find requested file:

    D:/Work2/OCCT/build/OpenCASCADEDEToolsTargets.cmake
Call Stack (most recent call first):
  CMake/vtkModule.cmake:5351 (find_package)
  IO/OCCT/CMakeLists.txt:1 (vtk_module_find_package)


CMake Error at D:/Work2/OCCT/build/OpenCASCADEConfig.cmake:102 (include):
  include could not find requested file:

    D:/Work2/OCCT/build/OpenCASCADEDrawTargets.cmake
Call Stack (most recent call first):
  CMake/vtkModule.cmake:5351 (find_package)
  IO/OCCT/CMakeLists.txt:1 (vtk_module_find_package)


CMake Error at IO/OCCT/CMakeLists.txt:35 (message):
  Found OpenCASCADE (D:/Work2/OCCT/build) is missing the following required
  targets: TKDESTEP, TKDEIGES, TKernel, TKMath, TKMesh, TKBRep, TKXSBase,
  TKLCAF, TKXCAF


Configuring incomplete, errors occurred!

Make sure to enable these module in your configuration of opencascade, as I suggested above

https://gitlab.kitware.com/paraview/paraview-superbuild/-/blob/master/projects/occt.cmake?ref_type=heads