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
180 changes: 180 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
name: CI

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: j178/[email protected]

build:
name: build (${{ matrix.name }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- name: windows-clang-cl
runner: windows-latest
# Meson drops a bare "ccache" prefix for clang-cl but keeps
# "ccache.exe" as part of the compiler command.
cc: ccache.exe clang-cl
cxx: ccache.exe clang-cl
upload: true
platform: windows-x86_64
dal_name: mmgr_dal_SimulatedCamera.dll
- name: windows-msvc
runner: windows-latest
cc: ccache cl
cxx: ccache cl
upload: false
- name: linux-gcc
runner: ubuntu-22.04
cc: ccache gcc
cxx: ccache g++
ldflags: -static-libstdc++ -static-libgcc
upload: true
platform: linux-x86_64
dal_name: mmgr_dal_SimulatedCamera.so.0
strip: strip --strip-unneeded
- name: macos-arm64
runner: macos-15
cc: ccache clang
cxx: ccache clang++
upload: true
platform: macos-arm64
dal_name: mmgr_dal_SimulatedCamera
strip: strip -x
- name: macos-x86_64
runner: macos-15-intel
cc: ccache clang
cxx: ccache clang++
upload: true
platform: macos-x86_64
dal_name: mmgr_dal_SimulatedCamera
strip: strip -x
env:
CC: ${{ matrix.cc }}
CXX: ${{ matrix.cxx }}
MACOSX_DEPLOYMENT_TARGET: "11.0"
BOOST_VERSION: 1.92.0
BOOST_VERSION_UNDERSCORED: 1_92_0
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v7

# Strawberry Perl's bin directories contain tools (including ccache.exe)
# that shadow the ones we want.
- name: Remove Strawberry Perl from PATH (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$path = ($env:PATH -split ';' | Where-Object { $_ -notlike 'C:\Strawberry\*' }) -join ';'
"PATH=$path" >> $env:GITHUB_ENV

# Git Bash puts Git's usr\bin (which has a GNU link.exe) at the front of
# PATH, shadowing MSVC's link.exe. Just recipes run under Git's sh, too.
- name: Remove Git's link.exe (Windows)
if: runner.os == 'Windows'
run: rm /usr/bin/link.exe

- uses: astral-sh/[email protected]

- name: Install Meson and Ninja
run: |
uv tool install meson
uv tool install ninja

- uses: extractions/setup-just@v4

- name: Set up MSVC dev environment (Windows)
if: runner.os == 'Windows'
uses: compnerd/gha-setup-vsdevenv@452f99effa381b81c025ccfbdccaca509bff1b29 # v7

# We only use Boost headers, but Meson's Boost detection fails unless at
# least one compiled Boost library is present. So we also install (on
# Windows, build) Boost.Random, which is not linked.
- name: Install Boost (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libboost-random-dev

- name: Install Boost (macOS)
if: runner.os == 'macOS'
run: brew install boost

- name: Cache Boost (Windows)
if: runner.os == 'Windows'
id: cache-boost
uses: actions/cache@v6
with:
path: ${{ runner.temp }}/boost
key: boost-random-${{ env.BOOST_VERSION }}-windows

- name: Build Boost (Windows)
if: runner.os == 'Windows' && steps.cache-boost.outputs.cache-hit != 'true'
shell: pwsh
working-directory: ${{ runner.temp }}
run: |
$PSNativeCommandUseErrorActionPreference = $true
Remove-Item Env:CC, Env:CXX
curl.exe -fsSL -o boost.tar.gz "https://archives.boost.io/release/$env:BOOST_VERSION/source/boost_$env:BOOST_VERSION_UNDERSCORED.tar.gz"
tar -xzf boost.tar.gz
cd "boost_$env:BOOST_VERSION_UNDERSCORED"
.\bootstrap.bat
.\b2 -j"$env:NUMBER_OF_PROCESSORS" --with-random --layout=system `
--prefix="$env:RUNNER_TEMP\boost" `
link=static runtime-link=shared variant=release address-model=64 `
install

- name: Set BOOST_ROOT (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: '"BOOST_ROOT=$env:RUNNER_TEMP\boost" >> $env:GITHUB_ENV'

- uses: hendrikmuhs/[email protected]
with:
key: ${{ matrix.name }}

- name: Enable ccache depend mode (Windows)
if: startsWith(matrix.runner, 'windows-')
run: ccache --set-config=depend_mode=true

- name: Configure
env:
LDFLAGS: ${{ matrix.ldflags }}
run: just configure-for-release -Dbenchmarks=enabled

- name: Build
run: just build

- name: Test
run: meson test -C builddir --print-errorlogs

- name: Stage artifact
if: matrix.upload
run: |
mkdir dist
cp builddir/SimulatedCamera.mmdev "dist/${{ matrix.dal_name }}"

- name: Strip artifact
if: matrix.upload && matrix.strip
run: ${{ matrix.strip }} "dist/${{ matrix.dal_name }}"

- uses: actions/upload-artifact@v7
if: matrix.upload
with:
name: mmdev-SimulatedCamera-${{ matrix.platform }}
path: dist/
if-no-files-found: error
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
args: ["--allow-multiple-documents"]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v23.1.1
hooks:
- id: clang-format
14 changes: 6 additions & 8 deletions SimCam.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,13 @@ class SimCam : public CCameraBase<SimCam> {
// FOV center is -stagePosition (needed for tiles to align).
const double fovCenterX = xy.first;
const double fovCenterY = -xy.second;
const double x =
fovCenterX - umPerPx * (double(roiX_) - double(sensorWidth_) / 2.0);
const double y =
fovCenterY -
umPerPx * (double(roiY_) - double(sensorHeight_) / 2.0);
const double x = fovCenterX - umPerPx * (double(roiX_) -
double(sensorWidth_) / 2.0);
const double y = fovCenterY - umPerPx * (double(roiY_) -
double(sensorHeight_) / 2.0);
// Derive intensity using epi-illumination formula
const double intensity = 2800.0 * GetExposure() *
GetBinning() * GetBinning() *
(na * na * na * na) /
const double intensity = 2800.0 * GetExposure() * GetBinning() *
GetBinning() * (na * na * na * na) /
(magnification * magnification);
specimen_.Draw(snapBuffer_.get(), x, y, z, roiWidth_, roiHeight_,
umPerPx, na, intensity);
Expand Down
12 changes: 3 additions & 9 deletions SimHub.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,16 @@ class SimHub : public HubBase<SimHub> {
getFocusUmFunc_ = f;
}

template <typename F> void SetGetXYUmFunction(F f) {
getXYUmFunc_ = f;
}
template <typename F> void SetGetXYUmFunction(F f) { getXYUmFunc_ = f; }

template <typename F> void SetGetMagnificationFunction(F f) {
getMagnificationFunc_ = f;
}

template <typename F> void SetGetNAFunction(F f) {
getNAFunc_ = f;
}
template <typename F> void SetGetNAFunction(F f) { getNAFunc_ = f; }

double GetFocusUm() { return getFocusUmFunc_(); }
std::pair<double, double> GetXYUm() {
return getXYUmFunc_();
}
std::pair<double, double> GetXYUm() { return getXYUmFunc_(); }
double GetMagnification() { return getMagnificationFunc_(); }
double GetNA() { return getNAFunc_(); }
};
30 changes: 16 additions & 14 deletions SimObjectiveTurret.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "SimHub.h"
#include "DeviceBase.h"
#include "SimHub.h"

#include <array>
#include <cstddef>
Expand All @@ -26,14 +26,12 @@ class SimObjectiveTurret : public CStateDeviceBase<SimObjectiveTurret> {
{100, 1.4, "Oil"},
}};

public:
SimObjectiveTurret(std::string name): name_(std::move(name)) {
public:
SimObjectiveTurret(std::string name) : name_(std::move(name)) {
InitializeDefaultErrorMessages();
}

~SimObjectiveTurret() {
Shutdown();
}
~SimObjectiveTurret() { Shutdown(); }

int Initialize() final {
int ret{};
Expand All @@ -54,14 +52,15 @@ class SimObjectiveTurret : public CStateDeviceBase<SimObjectiveTurret> {

// State
// -----
CPropertyAction* pAct = new CPropertyAction (this, &SimObjectiveTurret::OnState);
CPropertyAction *pAct =
new CPropertyAction(this, &SimObjectiveTurret::OnState);
ret = CreateIntegerProperty(MM::g_Keyword_State, 0, false, pAct);
if (ret != DEVICE_OK)
return ret;

// Label
// -----
pAct = new CPropertyAction (this, &CStateBase::OnLabel);
pAct = new CPropertyAction(this, &CStateBase::OnLabel);
ret = CreateStringProperty(MM::g_Keyword_Label, "", false, pAct);
if (ret != DEVICE_OK)
return ret;
Expand All @@ -88,21 +87,24 @@ class SimObjectiveTurret : public CStateDeviceBase<SimObjectiveTurret> {
return DEVICE_OK;
}

void GetName(char* name) const final {
void GetName(char *name) const final {
CDeviceUtils::CopyLimitedString(name, name_.c_str());
}

bool Busy() {return false;};
bool Busy() { return false; };

unsigned long GetNumberOfPositions() const {return static_cast<long>(objectives_.size());}
unsigned long GetNumberOfPositions() const {
return static_cast<long>(objectives_.size());
}

int OnState(MM::PropertyBase* pProp, MM::ActionType eAct) {
int OnState(MM::PropertyBase *pProp, MM::ActionType eAct) {
if (eAct == MM::BeforeGet) {
pProp->Set(state_);
} else if (eAct == MM::AfterSet) {
long newState;
pProp->Get(newState);
if (newState >= 0 && newState < static_cast<long>(objectives_.size())) {
if (newState >= 0 &&
newState < static_cast<long>(objectives_.size())) {
state_ = newState;
} else {
pProp->Set(state_);
Expand All @@ -112,7 +114,7 @@ class SimObjectiveTurret : public CStateDeviceBase<SimObjectiveTurret> {
return DEVICE_OK;
}

private:
private:
bool initialized_ = false;
std::string name_;
long state_ = 0;
Expand Down
3 changes: 1 addition & 2 deletions SimXY.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ class SimXY : public CXYStageBase<SimXY<ProcModel>> {

int Shutdown() final {
auto *hub = static_cast<SimHub *>(this->GetParentHub());
hub->SetGetXYUmFunction(
[] { return std::make_pair(0.0, 0.0); });
hub->SetGetXYUmFunction([] { return std::make_pair(0.0, 0.0); });
model_.Halt();
delayer_.CancelAll();
return DEVICE_OK;
Expand Down
3 changes: 2 additions & 1 deletion SimulatedSpecimen.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ template <typename T> class SimulatedSpecimen {
}

// Defocus
const auto sigmaUm = GaussianSigmaForDefocus(float(z_um), float(na), 1.33f);
const auto sigmaUm =
GaussianSigmaForDefocus(float(z_um), float(na), 1.33f);
const auto sigmaPixels = sigmaUm / float(um_per_px);
FastGaussian2D(fImage.data(), width, height, sigmaPixels);

Expand Down
5 changes: 3 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ configure BUILDTYPE *FLAGS:
{{FLAGS}}

# Configure with optional features enabled
configure-for-release:
configure-for-release *FLAGS:
@just configure release \
-Duse_boost=enabled \
-Duse_simd=enabled -Dsimd_dynamic_dispatch=enabled
-Duse_simd=enabled -Dsimd_dynamic_dispatch=enabled \
{{FLAGS}}

_configure_if_not_configured:
#!/usr/bin/env bash
Expand Down
Loading