diff --git a/geometry/render_gltf_client/internal_render_engine_gltf_client.cc b/geometry/render_gltf_client/internal_render_engine_gltf_client.cc index e3057edcd3e0..84a317b76c8a 100644 --- a/geometry/render_gltf_client/internal_render_engine_gltf_client.cc +++ b/geometry/render_gltf_client/internal_render_engine_gltf_client.cc @@ -169,63 +169,6 @@ std::unique_ptr RenderEngineGltfClient::DoClone() const { new RenderEngineGltfClient(*this)); } -void RenderEngineGltfClient::UpdateViewpoint( - const math::RigidTransformd& X_WC) { - /* The vtkGLTFExporter populates the camera matrix in "nodes" incorrectly in - VTK 9.1.0. It should be providing the inverted modelview transformation - matrix since the "nodes" array is to contain global transformations. See: - - https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8883 - - When VTK is updated, RenderEngineGltfClient::UpdateViewpoint can be deleted - as RenderEngineVtk::UpdateViewpoint will correctly update the transforms on - the cameras. */ -#if VTK_VERSION_NUMBER > VTK_VERSION_CHECK(9, 1, 0) -#error "UpdateViewpoint can be removed, modified transform no longer needed." -#endif - /* Build the alternate transform, which consists of both an inversion of the - input transformation as well as a coordinate system inversion. For the - coordinate inversion, we must account for: - - 1. VTK and drake have inverted Y axis directions. - 2. The camera Z axis needs to be pointing in the opposite direction. - - RenderEngineVtk::UpdateViewpoint will result in the vtkCamera instance's - SetPosition, SetFocalPoint, and SetViewUp methods being called, followed by - applying the transform from drake. See implementation of vtkCamera in VTK, - the Set{Position,FocalPoint,ViewUp} methods result in the camera internally - recomputing its basis -- users do not have the ability to directly control - the modelview transform. So we engineer a drake transform to pass back to - RenderEngineVtk::UpdateViewpoint that will result in the final vtkCamera - having an inverted modelview transformation than what would be needed to - render so that the vtkGLTFExporter will export the "correct" matrix. - - When performing this coordinate-system "hand-change", we seek to invert both - the y and z axes. The way to do this would be to use the identity matrix - with the axes being changed scaled by -1 (the "hand change") and both pre and - post multiply the matrix being changed: - - | 1 0 0 0 | | a b c d | | 1 0 0 0 | | a -b -c d | - | 0 -1 0 0 | * | e f g h | * | 0 -1 0 0 | = | -e f g -h | - | 0 0 -1 0 | | i j k l | | 0 0 -1 0 | | -i j k -l | - | 0 0 0 1 | | m n o p | | 0 0 0 1 | | m -n -o p | - - which we can build directly, noting that the last row | m -n -o p | will be - | 0 0 0 1 | (homogeneous row) and can therefore be skipped. - - NOTE: Use the inverse of RigidTransformd, which will transpose the rotation - and negate the translation rather than doing a full matrix inverse. */ - Eigen::Matrix4d hacked_matrix{X_WC.inverse().GetAsMatrix4()}; - hacked_matrix(0, 1) *= -1.0; // -b - hacked_matrix(0, 2) *= -1.0; // -c - hacked_matrix(1, 0) *= -1.0; // -e - hacked_matrix(1, 3) *= -1.0; // -h - hacked_matrix(2, 0) *= -1.0; // -i - hacked_matrix(2, 3) *= -1.0; // -l - math::RigidTransformd X_WC_hacked{hacked_matrix}; - RenderEngineVtk::UpdateViewpoint(X_WC_hacked); -} - void RenderEngineGltfClient::DoRenderColorImage( const ColorRenderCamera& camera, ImageRgba8U* color_image_out) const { const int64_t color_scene_id = GetNextSceneId(); diff --git a/geometry/render_gltf_client/internal_render_engine_gltf_client.h b/geometry/render_gltf_client/internal_render_engine_gltf_client.h index aa292ea54513..87f0900d90a6 100644 --- a/geometry/render_gltf_client/internal_render_engine_gltf_client.h +++ b/geometry/render_gltf_client/internal_render_engine_gltf_client.h @@ -16,7 +16,8 @@ namespace internal { /* A RenderEngine that exports glTF scenes, uploads to a render server, and retrieves the renderings back. */ -class RenderEngineGltfClient : public geometry::render::RenderEngineVtk { +class __attribute__((visibility("hidden"))) RenderEngineGltfClient + : public geometry::render::RenderEngineVtk { public: /* @name Does not allow copy, move, or assignment */ //@{ @@ -33,9 +34,6 @@ class RenderEngineGltfClient : public geometry::render::RenderEngineVtk { RenderEngineGltfClient(const RenderEngineGltfClientParams& parameters = RenderEngineGltfClientParams()); - // TODO(svenevs): Remove when VTK is updated, see implementation for details. - void UpdateViewpoint(const math::RigidTransformd& X_WC) override; - const RenderEngineGltfClientParams& get_params() const { return render_client_->get_params(); } diff --git a/geometry/render_gltf_client/test/internal_render_engine_gltf_client_test.cc b/geometry/render_gltf_client/test/internal_render_engine_gltf_client_test.cc index a7e8ab3ea0f7..c20b16a18c8e 100644 --- a/geometry/render_gltf_client/test/internal_render_engine_gltf_client_test.cc +++ b/geometry/render_gltf_client/test/internal_render_engine_gltf_client_test.cc @@ -101,83 +101,6 @@ TEST_F(RenderEngineGltfClientTest, Clone) { EXPECT_NE(engine.temp_directory(), clone_engine->temp_directory()); } -// TODO(svenevs): remove when VTK is updated, see implementation for details. -TEST_F(RenderEngineGltfClientTest, UpdateViewpoint) { - RenderEngineGltfClient engine{params_}; - const Vector3d translation{0.8, 0.0, 0.5}; - const RigidTransformd X_WB(RollPitchYawd{-M_PI * 0.7, 0, M_PI / 2}, - translation); - - // First, use the RenderEngineVtk::UpdateViewpoint and gather matrices. - engine.RenderEngineVtk::UpdateViewpoint(X_WB); - const Matrix4d vtk_color_mat = - engine.CameraModelViewTransformMatrix(ImageType::kColor); - const Matrix4d vtk_depth_mat = - engine.CameraModelViewTransformMatrix(ImageType::kDepth); - const Matrix4d vtk_label_mat = - engine.CameraModelViewTransformMatrix(ImageType::kLabel); - - // Use the RenderEngineGltfClient::UpdateViewpoint and gather new matrices. - engine.UpdateViewpoint(X_WB); - const Matrix4d gltf_color_mat = - engine.CameraModelViewTransformMatrix(ImageType::kColor); - const Matrix4d gltf_depth_mat = - engine.CameraModelViewTransformMatrix(ImageType::kDepth); - const Matrix4d gltf_label_mat = - engine.CameraModelViewTransformMatrix(ImageType::kLabel); - - /* A ModelView transform can be inverted directly by inverting the rotation - via transpose, and using this inverted rotation to rotate the negated - translation. We do not need to be concerned about non-uniform scaling on the - diagonal or the bottom row. */ - auto transform_inverse = [](const Eigen::Matrix4d& mat) { - Matrix4d inverse{mat}; - // Invert the rotation via transpose. - inverse.topLeftCorner<3, 3>().transposeInPlace(); - // Rotate the inverted translation. - const Vector3d t = inverse.topRightCorner<3, 1>(); - const Vector3d t_inv = inverse.topLeftCorner<3, 3>() * (-t); - inverse.topRightCorner<3, 1>() = t_inv; - return inverse; - }; - auto compare = [&](const Matrix4d& vtk, const Matrix4d& gltf) { - constexpr double tolerance = 1e-9; - - /* We expect that the MVT from RenderEngineVtk and RenderEngineGltfClient - the inverse of one another. The RenderEngineGltfClient::UpdateViewpoint - method engineers a hacked matrix to result in the effect of - RenderEngineVtk::UpdateViewpoint modifying the underlying vtkCamera to - produce the inverted matrix. This is because the vtkGLTFExporter was - incorrectly exporting the vtkCamera's ModelViewTransformMatrix, which - transforms objects in the world into the view of the camera. The inverse - of this matrix is what was supposed to be exported, since the "nodes" array - in glTF is for world coordinate transforms. */ - // Compare the rotations. - const Matrix4d vtk_inv = transform_inverse(vtk); - const Matrix3d R_vtk_inv = vtk_inv.topLeftCorner<3, 3>(); - const Matrix3d R_gltf = gltf.topLeftCorner<3, 3>(); - EXPECT_TRUE(R_vtk_inv.isApprox(R_gltf, tolerance)) - << "Rotation matrices not similar enough:\nR_vtk_inv:\n" - << R_vtk_inv << "\nR_gltf:\n" - << R_gltf << '\n'; - - // Compare the translations. - const Vector3d t_vtk_inv = vtk_inv.topRightCorner<3, 1>(); - const Vector3d t_gltf = gltf.topRightCorner<3, 1>(); - EXPECT_TRUE(t_vtk_inv.isApprox(t_gltf, tolerance)) - << "Translation vectors not similar enough:\nt_vtk_inv:\n" - << t_vtk_inv << "\nt_gltf:\n" - << t_gltf << '\n'; - - // For posterity, compare the homogeneous row. - const Vector4d gltf_homogeneous = gltf.bottomRightCorner<1, 4>(); - EXPECT_EQ(gltf_homogeneous, Vector4d(0, 0, 0, 1)); - }; - compare(vtk_color_mat, gltf_color_mat); - compare(vtk_depth_mat, gltf_depth_mat); - compare(vtk_label_mat, gltf_label_mat); -} - class FakeServer : public HttpService { public: FakeServer() = default; diff --git a/geometry/render_vtk/internal_render_engine_vtk.h b/geometry/render_vtk/internal_render_engine_vtk.h index 8781ebe7d7f5..0e77586a2081 100644 --- a/geometry/render_vtk/internal_render_engine_vtk.h +++ b/geometry/render_vtk/internal_render_engine_vtk.h @@ -47,7 +47,8 @@ struct ModuleInitVtkRenderingOpenGL2 { // See also shaders::kDepthFS, this is where the variables are used. // For the detail of VTK's callback mechanism, please refer to: // https://www.vtk.org/doc/nightly/html/classvtkCommand.html#details -class ShaderCallback : public vtkCommand { +class __attribute__((visibility("hidden"))) ShaderCallback + : public vtkCommand { public: DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN(ShaderCallback); @@ -89,8 +90,8 @@ enum ImageType { #endif // !DRAKE_DOXYGEN_CXX /** See documentation of MakeRenderEngineVtk(). */ -class RenderEngineVtk : public RenderEngine, - private internal::ModuleInitVtkRenderingOpenGL2 { +class __attribute__((visibility("hidden"))) RenderEngineVtk + : public RenderEngine, private internal::ModuleInitVtkRenderingOpenGL2 { public: /** @name Does not allow copy, move, or assignment */ //@{ diff --git a/tools/workspace/vtk/build_binaries_with_docker b/tools/workspace/vtk/build_binaries_with_docker index b1408b202083..cc7ae001162f 100755 --- a/tools/workspace/vtk/build_binaries_with_docker +++ b/tools/workspace/vtk/build_binaries_with_docker @@ -48,5 +48,5 @@ rm -f vtk-*.tar.gz{,.sha256} build focal --build-arg PLATFORM=ubuntu:20.04 extract focal -build jammy --build-arg PLATFORM=ubuntu:22.04 -extract jammy +# build jammy --build-arg PLATFORM=ubuntu:22.04 +# extract jammy diff --git a/tools/workspace/vtk/build_mac_binary b/tools/workspace/vtk/build_mac_binary new file mode 100755 index 000000000000..0e8890c94eb4 --- /dev/null +++ b/tools/workspace/vtk/build_mac_binary @@ -0,0 +1,85 @@ +#!/bin/bash + +# This shell script and some files in vtk/image (for docker) are used by +# the project maintainers to create the precompiled vtk binaries that are +# downloaded during the build. They are neither called during the build nor +# expected to be called by most developers or users of the project. + +set -euxo pipefail + +if ! command -v xcrun >/dev/null 2>&1; then + echo '`xcrun` command not found, is Xcode installed?' >&2 + exit 1 +fi + +macosx_sysroot="$(xcrun -sdk macosx -show-sdk-path)" +# TODO(svenevs): this should fail if it points to "command line tools" +# Must point to Contents/Developer under an Xcode.app like folder. + +this_file_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" +vtk_args_path="${this_file_dir}/image/vtk-args" + +if ! [[ -f "${vtk_args_path}" ]]; then + echo "Could not find 'vtk-args' file ${vtk_args_path}." >&2 + exit 1 +fi + +# See also: image/build-vtk.sh. Extract all CMake / VTK configure arguments +# from image/vtk-args, accumulating with `-D` in front for use on the command +# line removing any comment lines that start with '#'. +index=0 +vtk_cmake_args=() +while IFS='' read -r line || [[ -n "${line}" ]]; do + arg="$(sed -e '/^#/d' -e 's/^/-D/' <<< "${line}")" + # If the line was commented out, arg will be the empty string. + if ! [[ -z "${arg}" ]]; then + vtk_cmake_args[index++]="${arg}" + fi +done < "${vtk_args_path}" +vtk_cmake_args+=("-DVTK_USE_COCOA:BOOL=ON") + +# TODO(svenevs): unify this with image/build-vtk.sh. +readonly VTK_VERSION="d706250a1422ae1e7ece0fa09a510186769a5fec" + +# Directory to contain our source and build trees. +container="${this_file_dir}/mac_binary_build" +build_dir="${container}/build" +install_dir="${container}/install" +rm -rf "${container}" +mkdir -p "${container}" +cd "${container}" + +git clone https://gitlab.kitware.com/vtk/vtk.git src +src_dir="${container}/src" +git -C "${src_dir}" checkout "${VTK_VERSION}" + +# TODO(svenevs): macOS install rpath concerns. +# -DCMAKE_INSTALL_NAME_DIR:STRING=/opt/homebrew/Cellar/vtk@9.1.0/9.1.0_4/lib +# -DCMAKE_INSTALL_RPATH:STRING=/opt/homebrew/Cellar/vtk@9.1.0/9.1.0_4/lib +cmake \ + -G Ninja \ + -Wno-dev \ + -DCMAKE_INSTALL_PREFIX="${install_dir}" \ + -DCMAKE_BUILD_TYPE:STRING=Release \ + -DCMAKE_CXX_STANDARD:STRING=20 \ + "-DCMAKE_OSX_ARCHITECTURES:STRING='$(arch)'" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_FIND_FRAMEWORK=LAST \ + -DCMAKE_OSX_SYSROOT="${macosx_sysroot}" \ + -DCMAKE_C_COMPILER="$(xcrun -sdk macosx -find gcc)" \ + -DCMAKE_CXX_COMPILER="$(xcrun -sdk macosx -find g++)" \ + "${vtk_cmake_args[@]}" \ + -B "${build_dir}" \ + -S "${src_dir}" + +cd "${build_dir}" +ninja install/strip + +readonly archive=drake-vtk-mac.tar.gz +cd "${install_dir}" + +tar czf "${archive}" -- * +shasum --algorithm 256 "${archive}" | tee "${archive}.sha256" + +mv "${archive}" "${this_file_dir}" +mv "${archive}.sha256" "${this_file_dir}" diff --git a/tools/workspace/vtk/find_vtk_headers.py b/tools/workspace/vtk/find_vtk_headers.py index 63c60ba6b129..917197ee1401 100644 --- a/tools/workspace/vtk/find_vtk_headers.py +++ b/tools/workspace/vtk/find_vtk_headers.py @@ -62,6 +62,7 @@ "vtkRenderingCore", "vtkRenderingContext2D", "vtkRenderingFreeType", + "vtkRenderingHyperTreeGrid", "vtkRenderingOpenGL2", "vtkRenderingSceneGraph", "vtkRenderingUI", @@ -103,6 +104,7 @@ "vtkRenderingCore": Path("Rendering") / "Core", "vtkRenderingContext2D": Path("Rendering") / "Context2D", "vtkRenderingFreeType": Path("Rendering") / "FreeType", + "vtkRenderingHyperTreeGrid": Path("Rendering") / "HyperTreeGrid", "vtkRenderingOpenGL2": Path("Rendering") / "OpenGL2", "vtkRenderingSceneGraph": Path("Rendering") / "SceneGraph", "vtkRenderingUI": Path("Rendering") / "UI", @@ -145,6 +147,8 @@ def main(): required=True, ) parser.add_argument("--debug", action="store_true") + # TODO(svenevs): add ability to dump all headers for all modules to find a + # header when the module name is not known. parser.add_argument( "module", type=str, help="VTK module to parse.", choices=VTK_MODULES ) diff --git a/tools/workspace/vtk/image/build-vtk.sh b/tools/workspace/vtk/image/build-vtk.sh index 6f9c88b6817b..9fd23405a622 100755 --- a/tools/workspace/vtk/image/build-vtk.sh +++ b/tools/workspace/vtk/image/build-vtk.sh @@ -2,20 +2,39 @@ set -eu -o pipefail -readonly VTK_VERSION=9.1.0 +# Can be a branch, tag, or commit (e.g., 'v9.1.0'). +readonly VTK_VERSION="d706250a1422ae1e7ece0fa09a510186769a5fec" mkdir -p /vtk cd /vtk -git clone \ - --branch v${VTK_VERSION} --depth 1 \ - https://gitlab.kitware.com/vtk/vtk.git src +git clone https://gitlab.kitware.com/vtk/vtk.git src +git -C src checkout "${VTK_VERSION}" mkdir -p /vtk/build cd /vtk/build mapfile -t VTK_CMAKE_ARGS < <(sed -e '/^#/d' -e 's/^/-D/' < /vtk/vtk-args) -cmake "${VTK_CMAKE_ARGS[@]}" -GNinja -Wno-dev /vtk/src +codename="$(lsb_release -cs)" +if [[ "${codename}" == "focal" ]]; then + cxx_std="17" +else # "${code_name}" := "jammy" + cxx_std="20" +fi + +cmake \ + -G Ninja \ + -Wno-dev \ + -DCMAKE_INSTALL_PREFIX:PATH=/opt/vtk \ + -DCMAKE_BUILD_TYPE:STRING=Release \ + "-DCMAKE_CXX_STANDARD:STRING=${cxx_std}" \ + -DCMAKE_C_FLAGS:STRING='-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wno-deprecated-declarations' \ + -DCMAKE_CXX_FLAGS:STRING='-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wno-deprecated-declarations' \ + -DCMAKE_EXE_LINKER_FLAGS:STRING='-Wl,-Bsymbolic-functions -Wl,-z,now -Wl,-z,relro' \ + -DCMAKE_MODULE_LINKER_FLAGS:STRING='-Wl,-Bsymbolic-functions -Wl,-z,now -Wl,-z,relro' \ + -DCMAKE_SHARED_LINKER_FLAGS:STRING='-Wl,-Bsymbolic-functions -Wl,-z,now -Wl,-z,relro' \ + "${VTK_CMAKE_ARGS[@]}" \ + /vtk/src ninja install/strip diff --git a/tools/workspace/vtk/image/package.sh b/tools/workspace/vtk/image/package.sh index 0ab9da97627c..15f26ba9c4b1 100755 --- a/tools/workspace/vtk/image/package.sh +++ b/tools/workspace/vtk/image/package.sh @@ -3,10 +3,10 @@ set -eu -o pipefail # Get various version numbers. -readonly vtk_tag=vtk-9.1.0 +readonly vtk_tag=vtk-9.2.0 # To re-package, increase build_number by 1 and update repository.bzl to avoid # overwriting artifacts thus breaking historical builds. -readonly build_number=3 +readonly build_number=1 readonly platform=$(lsb_release --codename --short)-$(uname --processor) # Create archive named: @@ -17,5 +17,5 @@ readonly platform=$(lsb_release --codename --short)-$(uname --processor) readonly archive=${vtk_tag}-${build_number}-${platform}.tar.gz cd /opt/vtk -tar czf $archive -- * -shasum --algorithm 256 $archive | tee $archive.sha256 +tar czf "${archive}" -- * +shasum --algorithm 256 "${archive}" | tee "${archive}.sha256" diff --git a/tools/workspace/vtk/image/prereqs b/tools/workspace/vtk/image/prereqs index e625927939f9..7ee13e88ed89 100644 --- a/tools/workspace/vtk/image/prereqs +++ b/tools/workspace/vtk/image/prereqs @@ -29,5 +29,6 @@ libxt-dev lsb-release ninja-build python-is-python3 +sqlite3 wget zlib1g-dev diff --git a/tools/workspace/vtk/image/vtk-args b/tools/workspace/vtk/image/vtk-args index 96b1373f29f9..23deb95db8ac 100644 --- a/tools/workspace/vtk/image/vtk-args +++ b/tools/workspace/vtk/image/vtk-args @@ -1,21 +1,15 @@ # Basic build configuration. CMAKE_BUILD_TYPE:STRING=Release -BUILD_SHARED_LIBS:BOOL=ON +BUILD_SHARED_LIBS:BOOL=OFF CMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON -CMAKE_CXX_STANDARD:STRING=17 -CMAKE_INSTALL_PREFIX:PATH=/opt/vtk # VTK by default installs license files to `share/licenses/PROJECT_NAME`, we # want the license files to end up in `share/doc/PROJECT_NAME`. -CMAKE_INSTALL_LICENSEDIR:STRING=share/doc/vtk-9.1 -CMAKE_C_FLAGS:STRING='-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wno-deprecated-declarations' -CMAKE_CXX_FLAGS:STRING='-D_FORTIFY_SOURCE=2 -fstack-protector-strong -Wno-deprecated-declarations' -CMAKE_EXE_LINKER_FLAGS:STRING='-Wl,-Bsymbolic-functions -Wl,-z,now -Wl,-z,relro' -CMAKE_MODULE_LINKER_FLAGS:STRING='-Wl,-Bsymbolic-functions -Wl,-z,now -Wl,-z,relro' -CMAKE_SHARED_LINKER_FLAGS:STRING='-Wl,-Bsymbolic-functions -Wl,-z,now -Wl,-z,relro' +CMAKE_INSTALL_LICENSEDIR:STRING=share/doc/vtk-9.2 # VTK-specific build configuration. BUILD_TESTING:BOOL=OFF VTK_ENABLE_WRAPPING:BOOL=OFF VTK_WRAP_PYTHON:BOOL=OFF +VTK_ABI_NAMESPACE_NAME:STRING='drake_vtk __attribute__ ((visibility ("hidden")))' # Third party libraries. VTK_BUILD_ALL_MODULES:BOOL=OFF VTK_GROUP_ENABLE_Imaging:STRING=YES diff --git a/tools/workspace/vtk/repository.bzl b/tools/workspace/vtk/repository.bzl index 806650326094..0728dcd8e618 100644 --- a/tools/workspace/vtk/repository.bzl +++ b/tools/workspace/vtk/repository.bzl @@ -33,7 +33,7 @@ Argument: load("@drake//tools/workspace:os.bzl", "determine_os") -VTK_MAJOR_MINOR_VERSION = "9.1" +VTK_MAJOR_MINOR_VERSION = "9.2" VTK_MAJOR_MINOR_PATCH_VERSION = "{}.0".format(VTK_MAJOR_MINOR_VERSION) @@ -66,20 +66,9 @@ def _vtk_cc_library( srcs = [] - if os_result.is_macos: - if not header_only: - lib_dir = "{}/opt/vtk@{}/lib".format( - os_result.homebrew_prefix, - VTK_MAJOR_MINOR_PATCH_VERSION, - ) - linkopts = linkopts + [ - "-L{}".format(lib_dir), - "-l{}-{}".format(name, VTK_MAJOR_MINOR_VERSION), - "-Wl,-rpath,{}".format(lib_dir), - ] - elif os_result.is_ubuntu: + if os_result.is_ubuntu or os_result.is_macos: if not header_only: - srcs = ["lib/lib{}-{}.so.1".format(name, VTK_MAJOR_MINOR_VERSION)] + srcs = ["lib/lib{}-{}.a".format(name, VTK_MAJOR_MINOR_VERSION)] elif os_result.is_manylinux or os_result.is_macos_wheel: if not header_only: # TODO(jwnimmer-tri) Ideally, we wouldn't be hard-coding paths when @@ -111,18 +100,18 @@ def _impl(repository_ctx): if os_result.error != None: fail(os_result.error) - if os_result.is_macos: - repository_ctx.symlink("{}/opt/vtk@{}/include".format( - os_result.homebrew_prefix, - VTK_MAJOR_MINOR_PATCH_VERSION, - ), "include") - elif os_result.is_ubuntu: - if os_result.ubuntu_release == "20.04": - archive = "vtk-9.1.0-3-focal-x86_64.tar.gz" - sha256 = "0a899323e7927a7b3e09d1be35bf70df9630f4eba56b9af93c59401cefa227c5" # noqa + if os_result.is_ubuntu or os_result.is_macos: + if os_result.is_macos: + # TODO(svenevs): this is not the final name, and is only arm64. + archive = "drake-vtk-mac.tar.gz" + sha256 = "61132db14ad553c56326e25f7aaa620f950926e275c45d8af8dddaa967d0c3f7" # noqa + elif os_result.ubuntu_release == "20.04": + # TODO(svenevs): change our naming scheme (commit vs version)? + archive = "vtk-9.2.0-1-focal-x86_64.tar.gz" + sha256 = "5dbfeaed79c9762fb44f09f87d8eddc6b3b42ed1a8169d87292bf495c04494ad" # noqa elif os_result.ubuntu_release == "22.04": - archive = "vtk-9.1.0-3-jammy-x86_64.tar.gz" - sha256 = "6ec65fa079f1278f759afd7abea8539b9e2f19ba9056267ae6484c681d3debd1" # noqa + archive = "vtk-9.2.0-1-jammy-x86_64.tar.gz" + sha256 = "f6db640b1564b66afa80a933b9d65472c26057460d50452d69e0e53bfde9cb28" # noqa else: fail("Operating system is NOT supported {}".format(os_result)) @@ -200,18 +189,30 @@ licenses([ deps = ["@zlib"], ) - # NOTE: see homebrew-director, pugixml is installed via brew. - if not os_result.is_macos: - file_content += _vtk_cc_library(os_result, "vtkpugixml") + file_content += _vtk_cc_library(os_result, "vtkpugixml") + vtksys_hdrs = [ + "vtksys/Configure.h", + "vtksys/Configure.hxx", + "vtksys/Status.hxx", + "vtksys/SystemTools.hxx", + ] if os_result.is_manylinux: file_content += _vtk_cc_library( os_result, "vtksys", + hdrs = vtksys_hdrs, linkopts = ["-ldl"], ) else: - file_content += _vtk_cc_library(os_result, "vtksys") + file_content += _vtk_cc_library( + os_result, + "vtksys", + hdrs = vtksys_hdrs, + # TODO(svenevs): this may or may not be needed for macOS. If not, + # above if should allow for ubuntu or manylinux and remove here. + linkopts = ["-ldl"], + ) ########################################################################### # VTK "Public" Libraries (See: tools/workspace/vtk/README.md) @@ -241,6 +242,7 @@ licenses([ "vtkCommonCore", hdrs = [ "vtkABI.h", + "vtkABINamespace.h", "vtkAOSDataArrayTemplate.h", "vtkAbstractArray.h", "vtkAssume.h", @@ -251,6 +253,7 @@ licenses([ "vtkCommand.h", "vtkCommonCoreModule.h", "vtkCompiler.h", + "vtkEventData.h", "vtkDataArray.h", "vtkDataArrayAccessor.h", "vtkDataArrayMeta.h", @@ -324,18 +327,6 @@ licenses([ ], ) - vtk_common_data_model_deps = [ - ":vtkCommonCore", - ":vtkCommonMath", - ":vtkCommonMisc", - ":vtkCommonSystem", - ":vtkCommonTransforms", - ":vtksys", - ] - - # pugixml is included with the brew install. - if not os_result.is_macos: - vtk_common_data_model_deps.append(":vtkpugixml") file_content += _vtk_cc_library( os_result, "vtkCommonDataModel", @@ -362,10 +353,19 @@ licenses([ "vtkPolyData.h", "vtkPolyDataInternals.h", "vtkRect.h", + "vtkSelection.h", "vtkStructuredData.h", "vtkVector.h", ], - deps = vtk_common_data_model_deps, + deps = [ + ":vtkCommonCore", + ":vtkCommonMath", + ":vtkCommonMisc", + ":vtkCommonSystem", + ":vtkCommonTransforms", + ":vtksys", + ":vtkpugixml", + ], ) file_content += _vtk_cc_library( @@ -503,6 +503,21 @@ licenses([ ], ) + # Indirect dependency: omit headers. + file_content += _vtk_cc_library( + os_result, + "vtkFiltersHyperTree", + deps = [ + ":vtkCommonCore", + ":vtkCommonDataModel", + ":vtkCommonExecutionModel", + ":vtkCommonMisc", + ":vtkCommonSystem", + ":vtkFiltersCore", + ":vtkFiltersGeneral", + ], + ) + # Indirect dependency: omit headers. file_content += _vtk_cc_library( os_result, @@ -648,27 +663,6 @@ licenses([ ], ) - vtk_io_image_deps = [ - ":vtkCommonCore", - ":vtkCommonDataModel", - ":vtkCommonExecutionModel", - ":vtkCommonMath", - ":vtkCommonMisc", - ":vtkCommonSystem", - ":vtkCommonTransforms", - ":vtkDICOMParser", - ":vtkImagingCore", - ":vtkmetaio", - ":vtksys", - "@libjpeg", - "@libpng", - "@libtiff", - "@zlib", - ] - - # pugixml is included with the brew install. - if not os_result.is_macos: - vtk_io_image_deps.append(":vtkpugixml") file_content += _vtk_cc_library( os_result, "vtkIOImage", @@ -687,7 +681,24 @@ licenses([ "vtkTIFFReader.h", "vtkTIFFWriter.h", ], - deps = vtk_io_image_deps, + deps = [ + ":vtkCommonCore", + ":vtkCommonDataModel", + ":vtkCommonExecutionModel", + ":vtkCommonMath", + ":vtkCommonMisc", + ":vtkCommonSystem", + ":vtkCommonTransforms", + ":vtkDICOMParser", + ":vtkImagingCore", + ":vtkmetaio", + ":vtksys", + ":vtkpugixml", + "@libjpeg", + "@libpng", + "@libtiff", + "@zlib", + ], ) file_content += _vtk_cc_library( @@ -831,6 +842,12 @@ licenses([ ], ) + # TODO(svenevs): this is clearly wrong... @freetype needed? IIRC needed + # for ubuntu specifically, not sure about ubuntu/macOS wheel. + vtk_rendering_freetype_linkopts = ["-lfreetype"] + if os_result.is_macos: + vtk_rendering_freetype_linkopts = ["-L/opt/homebrew/lib", "-lfreetype"] + file_content += _vtk_cc_library( os_result, "vtkRenderingFreeType", @@ -844,6 +861,24 @@ licenses([ ":vtkFiltersGeneral", ":vtkRenderingCore", ], + linkopts = vtk_rendering_freetype_linkopts, + ) + + file_content += _vtk_cc_library( + os_result, + "vtkRenderingHyperTreeGrid", + hdrs = [ + "vtkRenderingHyperTreeGridModule.h", + ], + deps = [ + ":vtkCommonCore", + ":vtkCommonDataModel", + ":vtkCommonExecutionModel", + ":vtkCommonMath", + ":vtkFiltersHybrid", + ":vtkFiltersHyperTree", + ":vtkRenderingCore", + ], ) vtk_rendering_ui_hdrs = [ @@ -853,21 +888,22 @@ licenses([ if not os_result.is_macos and not os_result.is_macos_wheel: vtk_rendering_ui_hdrs.append("vtkXRenderWindowInteractor.h") - if os_result.is_macos_wheel: + vtk_rendering_ui_deps = [":vtkRenderingCore"] + if os_result.is_macos or os_result.is_macos_wheel: # Normally this would be a private dependency, but no such thing when # VTK is built static. - vtk_ui_linkopts = ["-framework Cocoa"] + vtk_rendering_ui_linkopts = ["-framework Cocoa"] else: - vtk_ui_linkopts = [] + # TODO(svenevs): should this be getting added for wheel? + vtk_rendering_ui_linkopts = [] + vtk_rendering_ui_deps.append("@x11") file_content += _vtk_cc_library( os_result, "vtkRenderingUI", hdrs = vtk_rendering_ui_hdrs, - deps = [ - ":vtkRenderingCore", - ], - linkopts = vtk_ui_linkopts, + deps = vtk_rendering_ui_deps, + linkopts = vtk_rendering_ui_linkopts, ) # Indirect dependency: omit headers. @@ -922,7 +958,9 @@ licenses([ ":vtkCommonSystem", ":vtkCommonTransforms", ":vtkFiltersGeneral", + ":vtkIOImage", ":vtkRenderingCore", + ":vtkRenderingHyperTreeGrid", ":vtkRenderingUI", ":vtksys", vtk_glew_library, @@ -952,12 +990,8 @@ filegroup( ) """ - if os_result.is_macos: - # Use Homebrew VTK. - files_to_install = [] - else: - # Install all files. - files_to_install = [":vtk"] + # Install all files. + files_to_install = [":vtk"] file_content += """ load("@drake//tools/install:install.bzl", "install_files")