# -*- python -*-

load(
    "@drake//tools/skylark:drake_cc.bzl",
    "drake_cc_googletest",
    "drake_cc_library",
    "drake_cc_package_library",
)
load("//tools/lint:lint.bzl", "add_lint_tests")
load("//tools/skylark:test_tags.bzl", "vtk_test_tags")

package(default_visibility = ["//visibility:public"])

drake_cc_package_library(
    name = "render",
    visibility = ["//visibility:public"],
    deps = [
        ":render_camera",
        ":render_engine",
        ":render_engine_vtk",
        ":render_engine_vtk_base",
        ":render_label",
        ":vtk_util",
    ],
)

drake_cc_library(
    name = "render_camera",
    srcs = ["render_camera.cc"],
    hdrs = ["render_camera.h"],
    deps = [
        "//common:essential",
        "//math:geometric_transform",
        "//systems/sensors:camera_info",
    ],
)

# A build target for code that wants to interact with the *idea* of a render
# engine but doesn't want any build dependencies on the implementation details.
drake_cc_library(
    name = "render_engine",
    srcs = ["render_engine.cc"],
    hdrs = ["render_engine.h"],
    deps = [
        ":render_camera",
        ":render_label",
        "//common:essential",
        "//geometry:geometry_ids",
        "//geometry:geometry_roles",
        "//geometry:shape_specification",
        "//geometry:utilities",
        "//math:geometric_transform",
        "//systems/sensors:camera_info",
        "//systems/sensors:color_palette",
        "//systems/sensors:image",
    ],
)

# The VTK-OpenGL-based render engine implementation.
drake_cc_library(
    name = "render_engine_vtk",
    srcs = [
        "render_engine_vtk.cc",
        "render_engine_vtk_factory.cc",
    ],
    hdrs = [
        "render_engine_vtk.h",
        "render_engine_vtk_factory.h",
    ],
    # render_engine_vtk.h directly pulls in VTK headers; leave it out of the
    # install.
    install_hdrs_exclude = ["render_engine_vtk.h"],
    deps = [
        ":render_engine",
        ":render_engine_vtk_base",
        ":vtk_util",
        "//common",
        "//geometry/render/shaders:depth_shaders",
        "//systems/sensors:color_palette",
        "@eigen",
        "@vtk//:vtkCommonCore",
        "@vtk//:vtkCommonDataModel",
        "@vtk//:vtkCommonTransforms",
        "@vtk//:vtkFiltersGeneral",
        "@vtk//:vtkFiltersSources",
        "@vtk//:vtkIOGeometry",
        "@vtk//:vtkIOImage",
        "@vtk//:vtkRenderingCore",
        "@vtk//:vtkRenderingOpenGL2",
    ],
)

# Common functionality for VTK-based render engine implementations.
drake_cc_library(
    name = "render_engine_vtk_base",
    srcs = [
        "render_engine_vtk_base.cc",
    ],
    hdrs = [
        "render_engine_vtk_base.h",
    ],
    # render_engine_vtk_base.h directly pulls in VTK headers; leave it out of
    # the install.
    install_hdrs_exclude = [
        "render_engine_vtk_base.h",
    ],
    visibility = ["//visibility:private"],
    deps = [
        "//common:scope_exit",
        "//geometry:geometry_roles",
        "//geometry:shape_specification",
        "//third_party/com_github_finetjul_bender:vtkCapsuleSource",
        "@vtk//:vtkCommonCore",
        "@vtk//:vtkFiltersSources",
    ],
)

drake_cc_library(
    name = "render_label",
    srcs = ["render_label.cc"],
    hdrs = ["render_label.h"],
    deps = [
        "//common:essential",
        "//common:hash",
        "//systems/sensors:image",
    ],
)

drake_cc_library(
    name = "vtk_util",
    srcs = ["vtk_util.cc"],
    hdrs = ["vtk_util.h"],
    # We must not expose `#include <vtk/...>` in any of our installed headers;
    # vtk_util.h is only included internally within this package.
    install_hdrs_exclude = ["vtk_util.h"],
    visibility = ["//visibility:private"],
    deps = [
        "//common:essential",
        "//math:geometric_transform",
        "@eigen",
        "@vtk//:vtkCommonCore",
        "@vtk//:vtkCommonTransforms",
        "@vtk//:vtkFiltersSources",
    ],
)

# === test/ ===

filegroup(
    name = "test_models",
    testonly = 1,
    srcs = ["test/diag_gradient.png"],
)

drake_cc_googletest(
    name = "render_camera_test",
    deps = [
        ":render_camera",
        "//common/test_utilities",
    ],
)

drake_cc_googletest(
    name = "render_engine_test",
    deps = [
        ":render_engine",
        "//common/test_utilities",
        "//geometry:geometry_ids",
        "//geometry/test_utilities:dummy_render_engine",
    ],
)

drake_cc_googletest(
    name = "render_engine_vtk_test",
    data = [
        ":test_models",
        "//systems/sensors:test_models",
    ],
    tags = vtk_test_tags(),
    deps = [
        ":render_engine_vtk",
        "//common:find_resource",
        "//common/test_utilities",
        "//geometry/test_utilities:dummy_render_engine",
        "//math:geometric_transform",
    ],
)

drake_cc_googletest(
    name = "render_label_test",
    deps = [
        ":render_label",
        "//common/test_utilities:expect_no_throw",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "vtk_util_test",
    deps = [":vtk_util"],
)

add_lint_tests()
