Files
allwpilib/tools/wpical/BUILD.bazel
Gold856 ae84f6d2c5 [wpical] Refactor to use WPILib libraries and modern C++ conventions and improve UX (#7796)
wpical was unable to use wpimath and its dependent libraries because
Ceres was compiled with a different version of Eigen. Now that the Ceres
build has been redone and shipped in #8151, we can now use wpimath and
our C++ apriltag wrapper in wpical, allowing for major refactors. This
includes:
* Using `to_json` and `from_json` specializations to concisely serialize
and deserialize all JSON files instead of manually handling JSON.
* Removal of the `Fieldmap` and `Pose` classes, which were duplicates of
the `AprilTagFieldLayout` and `Pose3d` classes respectively.
* Using `AprilTagDetector` instead of the raw libapriltag library.
* Using `Pose3d` instead of raw Eigen matrices.

In addition, several other refactors were made to make the code more
readable and to fix several UX issues and crashes. This includes:
* Eagerly parsing every JSON file when selected by the user. This means
JSON files are only parsed once on selection, instead of every time a
downstream function wants to use the data. This also means invalid JSON
can be detected upfront and a specific error shown immediately instead
of a catch all error when trying to calibrate.
* Using `std::optional` to indicate a calibration failed instead of
status codes.
* Processing videos on separate threads to not block the UI thread and
take advantage of parallelization for camera calibration. (2x speedup on
my laptop)
* Removing the OpenCV calibration option, since mrcal should be better
in every scenario.
* Showing a progress bar for camera calibration.
* Breaking up the massive `DisplayGui` function into separate functions
which contain code for different popups. This also allowed for better
organization and scoping of static variables.
* Renaming variables to make their purpose more clear.
* Displaying the tags present in a field layout when trying to combine
multiple field layouts.

Fixes #7722.
2025-12-31 09:28:51 -08:00

250 lines
5.9 KiB
Python

load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@rules_pkg//:mappings.bzl", "pkg_files")
load("//shared/bazel/rules:cc_rules.bzl", "wpilib_cc_library")
load("//shared/bazel/rules:packaging.bzl", "package_binary_cc_project")
load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources")
load("//shared/bazel/rules/gen:gen-version-file.bzl", "generate_version_file")
pkg_files(
name = "licenses",
srcs = [
"WPICalThirdPartyNotices.txt",
],
)
generate_resources(
name = "generate-resources",
namespace = "wpical",
prefix = "WPI",
resource_files = glob(["src/main/native/resources/*"]),
)
generate_version_file(
name = "generate-version",
output_file = "WPILibVersion.cpp",
template = "src/main/generate/WPILibVersion.cpp.in",
)
cc_library(
name = "headers",
hdrs = glob([
"src/main/native/include/**/*",
]),
strip_include_prefix = "src/main/native/include",
deps = [
":headers-libdogleg",
":headers-mrcal",
":headers-mrcal-generated",
":headers-mrcal-java",
],
)
cc_library(
name = "headers-libdogleg",
hdrs = glob([
"src/main/native/thirdparty/libdogleg/include/**/*",
]),
strip_include_prefix = "src/main/native/thirdparty/libdogleg/include",
)
cc_library(
name = "headers-mrcal-generated",
hdrs = glob([
"src/main/native/thirdparty/mrcal/generated/**/*",
]),
strip_include_prefix = "src/main/native/thirdparty/mrcal/generated/",
)
cc_library(
name = "headers-mrcal",
hdrs = glob([
"src/main/native/thirdparty/mrcal/include/**/*",
]),
strip_include_prefix = "src/main/native/thirdparty/mrcal/include/",
)
cc_library(
name = "headers-mrcal-java",
hdrs = glob([
"src/main/native/thirdparty/mrcal_java/include/**/*",
]),
strip_include_prefix = "src/main/native/thirdparty/mrcal_java/include/",
)
unix_copts = [
"-Wno-pedantic",
"-Wno-format-nonliteral",
"-Wno-unused-variable",
"-Wno-unused-function",
"-Wno-sign-compare",
]
osx_copts = unix_copts
copts = select({
"@platforms//os:linux": unix_copts + [
"-Wno-maybe-uninitialized",
],
"@platforms//os:osx": osx_copts,
"@platforms//os:windows": [
"/wd4047",
"/wd4098",
"/wd4267",
],
})
unix_cxxopts = [
"-Wno-missing-field-initializers",
"-Wno-pedantic",
"-fpermissive",
"-Wno-deprecated-declarations",
"-Wno-return-type",
"-Wno-missing-braces",
"-Wno-null-conversion",
"-Wno-unused-but-set-variable",
]
osx_cxxopts = unix_cxxopts + [
"-Wno-unused-variable",
"-Wno-unused-function",
"-Wno-sign-compare",
"-Wno-sometimes-uninitialized",
]
cxxopts = select({
"@platforms//os:linux": unix_cxxopts + [
"-Wno-deprecated-enum-enum-conversion",
],
"@platforms//os:osx": osx_cxxopts,
"@platforms//os:windows": [
"/wd4068",
"/wd4101",
"/wd4200",
"/wd4576",
"/wd4715",
],
})
mac_linkopts = [
"-framework",
"Metal",
"-framework",
"MetalKit",
"-framework",
"Cocoa",
"-framework",
"IOKit",
"-framework",
"CoreFoundation",
"-framework",
"CoreVideo",
"-framework",
"QuartzCore",
"-framework",
"Accelerate",
"-framework",
"AVFoundation",
"-framework",
"CoreMedia",
]
linkopts = select({
"@platforms//os:linux": [],
"@platforms//os:osx": mac_linkopts,
"@platforms//os:windows": [
"-DEFAULTLIB:Gdi32.lib",
"-DEFAULTLIB:Shell32.lib",
"-DEFAULTLIB:d3d11.lib",
"-DEFAULTLIB:d3dcompiler.lib",
"-DEFAULTLIB:Comdlg32.lib",
"-DEFAULTLIB:dbghelp.lib",
"-DEFAULTLIB:Advapi32.lib",
],
})
wpilib_cc_library(
name = "wpical_lib",
srcs = glob(
[
"src/main/native/cpp/**/*.cpp",
"src/main/native/thirdparty/libdogleg/src/**/*.cpp",
"src/main/native/thirdparty/mrcal/src/**/*.cpp",
"src/main/native/thirdparty/mrcal/src/**/*.c",
"src/main/native/thirdparty/mrcal_java/src/**/*.cpp",
],
exclude = ["src/main/native/cpp/WPIcal.cpp"],
) + [
":generate-resources",
":generate-version",
],
copts = copts,
cxxopts = cxxopts,
defines = ["OPENCV_DISABLE_EIGEN_TENSOR_SUPPORT"],
include_license_files = True,
linkopts = linkopts,
linkstatic = True,
strip_include_prefix = "include",
visibility = ["//visibility:public"],
deps = [
":headers",
"//apriltag",
"//thirdparty/ceres",
"//wpigui",
"//wpiutil",
"@bzlmodrio-opencv//libraries/cpp/opencv",
],
)
cc_binary(
name = "wpical",
srcs = [
"src/main/native/cpp/WPIcal.cpp",
],
copts = copts,
cxxopts = cxxopts,
linkopts = select({
"@platforms//os:linux": [],
"@platforms//os:osx": [],
"@platforms//os:windows": [
"-SUBSYSTEM:WINDOWS",
],
}),
deps = [
":wpical_lib",
"//glass",
"//thirdparty/imgui_suite",
],
)
cc_test(
name = "wpical_test",
size = "medium",
srcs = glob(["src/test/native/**"]),
copts = copts,
cxxopts = cxxopts,
data = glob(["src/main/native/assets/**"]) + [
"src/main/native/assets",
"src/main/native/assets/altfieldvideo",
"src/main/native/assets/fieldvideo",
],
defines = [
'PROJECT_ROOT_PATH=\\"tools/wpical/src/main/native/assets\\"',
"__BAZEL__=1",
],
deps = [
":wpical_lib",
"//thirdparty/ceres",
"//thirdparty/googletest",
"@bazel_tools//tools/cpp/runfiles",
],
)
package_binary_cc_project(
name = "wpical",
extra_files = [":licenses"],
maven_artifact_name = "wpical",
maven_group_id = "org.wpilib.tools",
)