Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/lint-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Lint and Format

on:
# Run on pushes to main and pushed tags, and on pull requests against main
push:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
wpiformat:
name: "wpiformat"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Fetch all history and metadata
run: |
git fetch --prune --unshallow
git checkout -b pr
git branch -f main origin/main
- uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install wpiformat
run: pip3 install wpiformat==2025.79
- name: Run
run: wpiformat
- name: Check output
run: |
set +e
git --no-pager diff --exit-code HEAD
exit_code=$?
if test "$exit_code" -ne "0"; then
echo "::error ::Linting failed. See https://docs.photonvision.org/en/latest/docs/contributing/linting.html"
exit $exit_code
fi
- name: Generate diff
run: git diff HEAD > wpiformat-fixes.patch
if: ${{ failure() }}
- uses: actions/upload-artifact@v4
with:
name: wpiformat fixes
path: wpiformat-fixes.patch
if: ${{ failure() }}
3 changes: 3 additions & 0 deletions .styleguide → .wpiformat
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ modifiableFileExclude {
\.webp$
\.ico$
gradlew
mrcal/
libdogleg/
vnlog/
}

includeProject {
Expand Down
File renamed without changes.
123 changes: 75 additions & 48 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set (WITH_ASAN OFF)
if (WITH_ASAN)
set(WITH_ASAN OFF)
if(WITH_ASAN)
add_compile_options(-fsanitize=address -g -Wall -fsanitize=undefined)
endif ()
endif()

# Keep this in sync with build.gradle and with
# https://github.com/PhotonVision/photonvision/blob/main/build.gradle
Expand All @@ -26,23 +26,26 @@ set(OPENCV_TYPE "")
include(FetchContent)
FetchContent_Declare(
opencv_lib
URL https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-${OPENCV_ARCH}${OPENCV_TYPE}.zip
URL
https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-${OPENCV_ARCH}${OPENCV_TYPE}.zip
)
FetchContent_MakeAvailable(opencv_lib)

# download OpenCV headers
FetchContent_Declare(
opencv_header
URL https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-headers.zip
URL
https://frcmaven.wpi.edu/artifactory/release/edu/wpi/first/thirdparty/${OPENCV_YEAR}/opencv/opencv-cpp/${OPENCV_VERSION}/opencv-cpp-${OPENCV_VERSION}-headers.zip
)
FetchContent_MakeAvailable(opencv_header)

# This probably doesn't work great with shared libraries, but I don't care about those right now
file(GLOB_RECURSE OPENCV_LIB_PATH
"${opencv_lib_SOURCE_DIR}/**/*.lib"
"${opencv_lib_SOURCE_DIR}/**/*.so*"
file(
GLOB_RECURSE OPENCV_LIB_PATH
"${opencv_lib_SOURCE_DIR}/**/*.lib"
"${opencv_lib_SOURCE_DIR}/**/*.so*"
)
SET(OPENCV_INCLUDE_PATH ${opencv_header_SOURCE_DIR})
set(OPENCV_INCLUDE_PATH ${opencv_header_SOURCE_DIR})
message("Depending on opencv ${OPENCV_LIB_PATH}")

# Openblas/suitesparse/friends
Expand All @@ -64,13 +67,13 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Silence OpenBLAS/LAPACK warnings
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
set(BLA_VENDOR OpenBLAS)
fetchcontent_declare(
FetchContent_Declare(
BLAS
GIT_REPOSITORY https://github.com/OpenMathLib/OpenBLAS.git
GIT_TAG v0.3.30
OVERRIDE_FIND_PACKAGE
)
fetchcontent_makeavailable(BLAS)
FetchContent_MakeAvailable(BLAS)

if(TARGET openblas)
set(OPENBLAS_TARGET openblas)
Expand All @@ -83,9 +86,10 @@ elseif(TARGET libopenblas)
message(STATUS "Using libopenblas target")
else()
# Fallback: find the library file manually
find_library(OPENBLAS_LIB
find_library(
OPENBLAS_LIB
NAMES openblas libopenblas
PATHS
PATHS
${openblas_external_BINARY_DIR}
${openblas_external_BINARY_DIR}/lib
${openblas_external_BINARY_DIR}/lib/Release
Expand All @@ -94,7 +98,10 @@ else()
)
message(STATUS "Using OpenBLAS library file: ${OPENBLAS_LIB}")
add_library(openblas_imported STATIC IMPORTED)
set_target_properties(openblas_imported PROPERTIES IMPORTED_LOCATION ${OPENBLAS_LIB})
set_target_properties(
openblas_imported
PROPERTIES IMPORTED_LOCATION ${OPENBLAS_LIB}
)
set(OPENBLAS_TARGET openblas_imported)
endif()

Expand All @@ -107,67 +114,80 @@ set(SUITESPARSE_USE_PYTHON OFF)
set(CHOLMOD_GPL OFF)
set(SUITESPARSE_USE_BLAS ON)

fetchcontent_declare(
FetchContent_Declare(
SuiteSparse
GIT_REPOSITORY https://github.com/DrTimothyAldenDavis/SuiteSparse.git
GIT_TAG v7.11.0
OVERRIDE_FIND_PACKAGE
)
fetchcontent_makeavailable(SuiteSparse)
FetchContent_MakeAvailable(SuiteSparse)

get_target_property(CHOLMOD_LIBS SuiteSparse::CHOLMOD_static INTERFACE_LINK_LIBRARIES)
get_target_property(
CHOLMOD_LIBS
SuiteSparse::CHOLMOD_static
INTERFACE_LINK_LIBRARIES
)
message(STATUS "CHOLMOD links to: ${CHOLMOD_LIBS}")
message(STATUS "BLAS is at: ${OPENBLAS_TARGET}")

# And pull in JNI
find_package(JNI)
if (JNI_FOUND)
if(JNI_FOUND)
# Fixes odd AWT dependency
set (JNI_INCLUDE_DIRS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
set(JNI_INCLUDE_DIRS ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
message(STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
endif()

# headers and sources
set(
INCLUDE_HPP
)
set(INCLUDE_HPP)

set(
SRC_HPP
)
set(
SRC_CPP
set(SRC_HPP)
set(SRC_CPP
src/mrcal_jni.h
src/mrcal_wrapper.cpp
src/mrcal_jni.cpp
libdogleg/dogleg.c
mrcal/mrcal.c mrcal/cahvore.cc mrcal/poseutils-opencv.c mrcal/poseutils-uses-autodiff.cc mrcal/poseutils.c mrcal/poseutils-opencv.c mrcal/mrcal-opencv.c mrcal/triangulation.cc
mrcal/mrcal.c
mrcal/cahvore.cc
mrcal/poseutils-opencv.c
mrcal/poseutils-uses-autodiff.cc
mrcal/poseutils.c
mrcal/poseutils-opencv.c
mrcal/mrcal-opencv.c
mrcal/triangulation.cc
)


# ignore opencv spam
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-deprecated-enum-enum-conversion")


# Gennerate minimath
find_package( Perl REQUIRED )
find_package(Perl REQUIRED)
add_custom_target(
generate_minimath ALL
COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generate.pl > ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generated.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generated.h
COMMENT "Generating minimath"
generate_minimath
ALL
COMMAND
${PERL_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generate.pl >
${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generated.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/mrcal/minimath/minimath_generated.h
COMMENT "Generating minimath"
)

set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# Create shared library
add_library(mrcal_jni SHARED ${INCLUDE_HPP} ${SRC_HPP} ${SRC_CPP})
target_include_directories(mrcal_jni SYSTEM PUBLIC ${JNI_INCLUDE_DIRS} ${OPENCV_INCLUDE_PATH} mrcal libdogleg)
target_include_directories(
mrcal_jni
SYSTEM
PUBLIC ${JNI_INCLUDE_DIRS} ${OPENCV_INCLUDE_PATH} mrcal libdogleg
)
add_dependencies(mrcal_jni generate_minimath)

target_link_libraries(mrcal_jni
target_link_libraries(
mrcal_jni
${OPENCV_LIB_PATH}
SuiteSparse::CHOLMOD_static
SuiteSparse::SuiteSparseConfig_static
Expand All @@ -178,15 +198,22 @@ target_link_libraries(mrcal_jni
# Test script for checking our linker
add_executable(mrcal_jni_test src/mrcal_test.cpp)
target_link_libraries(mrcal_jni_test PUBLIC mrcal_jni)
target_include_directories(mrcal_jni_test SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/vnlog)
target_include_directories(
mrcal_jni_test
SYSTEM
PRIVATE ${PROJECT_SOURCE_DIR}/vnlog
)
# add_dependencies(mrcal_jni_test )
target_link_libraries(mrcal_jni_test PRIVATE
${OpenCV_LIBS}
${PROJECT_SOURCE_DIR}/vnlog/libvnlog.so
target_link_libraries(
mrcal_jni_test
PRIVATE ${OpenCV_LIBS} ${PROJECT_SOURCE_DIR}/vnlog/libvnlog.so
)

if (WITH_ASAN)
target_link_libraries(mrcal_jni_test PRIVATE -fsanitize=address -fsanitize=undefined)
endif ()
if(WITH_ASAN)
target_link_libraries(
mrcal_jni_test
PRIVATE -fsanitize=address -fsanitize=undefined
)
endif()

unset(OPENCV_ARCH CACHE) # Set by Actions usually
10 changes: 7 additions & 3 deletions src/mrcal_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
#include <algorithm>
#include <cstdio>
#include <exception>
#include <iostream>
#include <span>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>

#include "mrcal_wrapper.h"
Expand Down Expand Up @@ -54,10 +56,12 @@ static constexpr std::string_view JNI_DOUBLE{"D"};
static constexpr std::string_view JNI_DOUBLEARR{"[D"};
static constexpr std::string_view JNI_BOOLARR{"[Z"};

template<typename... Args>
constexpr std::string jni_make_method_sig(std::string_view retval, Args&&... args) {
template <typename... Args>
constexpr std::string jni_make_method_sig(std::string_view retval,
Args &&...args) {
std::string result = "(";
((result += std::string_view(args)), ...); // Ensure args are converted to string_view
((result += std::string_view(args)),
...); // Ensure args are converted to string_view
result += ")";
result += retval;
return result;
Expand Down
3 changes: 3 additions & 0 deletions src/mrcal_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
#include <algorithm>
#include <chrono>
#include <cstdio>
#include <iostream>
#include <map>
#include <span>
#include <stdexcept>
#include <string>
#include <vector>

#include "mrcal_jni.h"
Expand Down
23 changes: 20 additions & 3 deletions src/mrcal_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Copyright (C) Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/*
* Copyright (C) Photon Vision.
*
Expand All @@ -21,6 +38,8 @@
#include <algorithm>
#include <chrono>
#include <cstdio>
#include <iostream>
#include <memory>
#include <random>
#include <span>
#include <stdexcept>
Expand Down Expand Up @@ -338,9 +357,7 @@ mrcal_pose_t getSeedPose(const mrcal_point3_t *c_observations_board_pool,
.t = {.x = tvec(0), .y = tvec(1), .z = tvec(2)}};
}

mrcal_result::~mrcal_result() {
return;
}
mrcal_result::~mrcal_result() { return; }

// Code taken from mrcal, license:
// Copyright (c) 2017-2023 California Institute of Technology ("Caltech"). U.S.
Expand Down
17 changes: 17 additions & 0 deletions src/mrcal_wrapper.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Copyright (C) Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/*
* Copyright (C) Photon Vision.
*
Expand Down