Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use a single camera #2

Open
wants to merge 3 commits into
base: dualspim
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions src/gui/nisettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "spim.h"
#include "tasks.h"

#include <QCheckBox>
#include <QComboBox>
#include <QGridLayout>
#include <QGroupBox>
Expand All @@ -24,6 +25,8 @@ void NISettingsWidget::setupUI()

QComboBox *comboBox;

QCheckBox *checkBox;

CameraTrigger *cameraTrigger = spim().getTasks()->getCameraTrigger();

QStringList terminals = NI::getTerminals().filter("PFI");
Expand All @@ -36,6 +39,7 @@ void NISettingsWidget::setupUI()
QList<QComboBox *> galvoRampComboBoxList;
QList<QComboBox *> blankingComboBoxList;
QList<QComboBox *> cameraTriggerPulseComboBoxList;
QList<QCheckBox *> checkBoxes;

int row = 0;
for (int i = 0; i < SPIM_NCAMS; ++i) {
Expand All @@ -59,12 +63,18 @@ void NISettingsWidget::setupUI()
grid->addWidget(new QLabel("Galvo"), row, i * 2 + 0);
comboBox = new QComboBox();
comboBox->addItems(NI::getAOPhysicalChans());

#ifdef DEMO_MODE
comboBox->addItems({"DemoDev/ao0", "DemoDev/ao1"});
#endif
comboBox->setCurrentText(spim().getTasks()->getGalvoRamp()->getPhysicalChannels().at(i));
grid->addWidget(comboBox, row++, i * 2 + 1);
galvoRampComboBoxList.insert(i, comboBox);

grid->addWidget(new QLabel("Enabled"), row, i * 2 + 0);
checkBox = new QCheckBox();
grid->addWidget(checkBox, row++, i * 2 + 1);
checkBoxes.insert(i, checkBox);
}

QFrame *line = new QFrame;
Expand Down Expand Up @@ -111,4 +121,13 @@ void NISettingsWidget::setupUI()
for (QComboBox *combo : allCombos) {
connect(combo, QOverload<int>::of(&QComboBox::activated), [=]() { apply(); });
}

int i = 0;
for (QCheckBox *checkBox : checkBoxes) {
connect(checkBox, &QCheckBox::toggled, [=](bool checked) {
spim().setCameraEnabled(i, checkBox->QCheckBox::isChecked());
});
checkBox->setChecked(spim().isCameraEnabled(i));
i++;
}
}
13 changes: 9 additions & 4 deletions src/gui/progresswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ void ProgressWidget::setupUI()

connect(timer, &QTimer::timeout, this, [=]() {
for (int i = 0; i < SPIM_NCAMS; ++i) {
stackPbList.at(i)->setRange(0, spim().getSSWorker(i)->getFrameCount());
stackPbList.at(i)->setValue(spim().getSSWorker(i)->getReadFrames());
if (spim().isCameraEnabled(i)) {
stackPbList.at(i)->setRange(0, spim().getSSWorker(i)->getFrameCount());
stackPbList.at(i)->setValue(spim().getSSWorker(i)->getReadFrames());
}
}
});

Expand All @@ -94,7 +96,8 @@ void ProgressWidget::setupUI()
timer->start(1000);
for (int i = 0; i < SPIM_NCAMS; ++i) {
stackPbList.at(i)->reset();
}});
}
});
connect(s, &QState::exited, timer, &QTimer::stop);

connect(s, &QState::exited, this, [=]() {
Expand All @@ -115,7 +118,9 @@ void ProgressWidget::setupUI()
etaLabel->setText(startDateTime->addSecs(remainingSeconds).toString());
progressBar->setValue(currentStep);
for (int i = 0; i < SPIM_NCAMS; ++i) {
stackPbList.at(i)->setValue(spim().getSSWorker(i)->getReadFrames());
if (spim().isCameraEnabled(i)) {
stackPbList.at(i)->setValue(spim().getSSWorker(i)->getReadFrames());
}
}
});
}
23 changes: 22 additions & 1 deletion src/gui/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#define SETTING_EXPTIME "exposureTime"
#define SETTING_RUN_NAME "runName"
#define SETTING_BINNING "binning"
#define SETTING_ENABLED_CAMERAS "CameraEnabled"

#define SETTING_TURN_OFF_LASERS_AT_END_OF_ACQUISITION "turnOffLasersAtEndOfAcquisition"

Expand Down Expand Up @@ -144,9 +145,19 @@ void Settings::loadSettings()
SET_VALUE(group, SETTING_EXPTIME, 0.15);
SET_VALUE(group, SETTING_RUN_NAME, QString());
SET_VALUE(group, SETTING_BINNING, 1);

settings.endGroup();

groups.clear();
for (int i = 0; i < SPIM_NCAMS; ++i) {
groups << SETTINGSGROUP_CAMERAS(i);
}

for (const QString &group : groups) {
settings.beginGroup(group);
SET_VALUE(group, SETTING_ENABLED_CAMERAS, false);
settings.endGroup();
}

groups.clear();
for (int i = 0; i < SPIM_NCOBOLT; ++i) {
groups << SETTINGSGROUP_COBOLT(i);
Expand Down Expand Up @@ -255,6 +266,11 @@ void Settings::loadSettings()
spim().setRunName(value(group, SETTING_RUN_NAME).toString());
spim().setBinning(value(group, SETTING_BINNING).toUInt());

for (int i = 0; i < SPIM_NCAMS; ++i) {
group = SETTINGSGROUP_CAMERAS(i);
spim().setCameraEnabled(i, value(group, SETTING_ENABLED_CAMERAS).toBool());
}

#endif

group = SETTINGSGROUP_OTHERSETTINGS;
Expand Down Expand Up @@ -330,6 +346,11 @@ void Settings::saveSettings()
setValue(group, SETTING_EXPTIME, spim().getExposureTime());
setValue(group, SETTING_RUN_NAME, spim().getRunName());
setValue(group, SETTING_BINNING, spim().getBinning());

for (int i = 0; i < SPIM_NCAMS; ++i) {
group = SETTINGSGROUP_CAMERAS(i);
setValue(group, SETTING_ENABLED_CAMERAS, spim().isCameraEnabled(i));
}
#endif
group = SETTINGSGROUP_OTHERSETTINGS;
#ifdef MASTER_SPIM
Expand Down
1 change: 1 addition & 0 deletions src/gui/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define SETTINGSGROUP_OTHERSETTINGS "OtherSettings"

#define SETTINGSGROUP_AXIS(n) QString("AXIS_%1").arg(n)
#define SETTINGSGROUP_CAMERAS(n) QString("CAMERA_%1").arg(n)
#define SETTINGSGROUP_FILTERWHEEL(n) QString("FilterWheel_%1").arg(n)

#define SETTING_LUTPATH "LUTPath"
Expand Down
150 changes: 98 additions & 52 deletions src/gui/spim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <qtlab/hw/serial/cobolt.h>
#include <qtlab/hw/serial/filterwheel.h>
#include <qtlab/hw/serial/serialport.h>

#endif

static Logger *logger = getLogger("SPIM");
Expand Down Expand Up @@ -87,6 +88,10 @@ SPIM::SPIM(QObject *parent)
enabledMosaicStageMap[dev] = false;
}

for (int i = 0; i < SPIM_NCAMS; ++i) {
camEnabled << false;
}

PIDevice *xaxis = getPIDevice(PI_DEVICE_X_AXIS);
connect(xaxis, &PIDevice::connected, this, [=]() {
xaxis->setTriggerOutput(PIDevice::OUTPUT_1, PIDevice::Axis, 1);
Expand Down Expand Up @@ -224,6 +229,22 @@ void SPIM::setMosaicStageEnabled(SPIM_PI_DEVICES dev, bool enable)
enabledMosaicStageMap[dev] = enable;
}

bool SPIM::isCameraEnabled(uint camera)
{
return camEnabled[camera];
}

void SPIM::setCameraEnabled(uint camera, bool enable)
{
camEnabled[camera] = enable;
}

int SPIM::nEnabledCameras()
{
int nEnabledCameras = std::count(camEnabled.begin(), camEnabled.end(), true);
return nEnabledCameras;
}

QString SPIM::getRunName() const
{
return runName;
Expand Down Expand Up @@ -292,63 +313,82 @@ OrcaFlash *SPIM::getCamera(int camNumber) const
}
void SPIM::startFreeRun()
{
freeRun = true;
logger->info("Start free run");
_startCapture();
try {
if (nEnabledCameras() == 0) {
throw std::runtime_error(
QString("Can't start free run with no cameras enabled").toStdString());
}
freeRun = true;
logger->info("Start free run");
_startCapture();
} catch (std::runtime_error e) {
onError(e.what());
return;
}
}

bool SPIM::startAcquisition()
{
freeRun = false;
logger->info("Start acquisition");
try {
if (nEnabledCameras() == 0) {
throw std::runtime_error(
QString("Can't start capture with no cameras enabled").toStdString());
}
freeRun = false;
logger->info("Start acquisition");

#ifdef MASTER_SPIM
enabledMosaicStages.clear();
for (const SPIM_PI_DEVICES d_enum : mosaicStages) {
if (enabledMosaicStageMap[d_enum]) {
enabledMosaicStages << d_enum;
enabledMosaicStages.clear();
for (const SPIM_PI_DEVICES d_enum : mosaicStages) {
if (enabledMosaicStageMap[d_enum]) {
enabledMosaicStages << d_enum;
}
}
}

QList<SPIM_PI_DEVICES> stageEnumList;
stageEnumList << enabledMosaicStages << stackStage;
QList<SPIM_PI_DEVICES> stageEnumList;
stageEnumList << enabledMosaicStages << stackStage;

QList<PIDevice *> stageList;
for (const SPIM_PI_DEVICES d_enum : stageEnumList) {
stageList << getPIDevice(d_enum);
QList<PIDevice *> stageList;
for (const SPIM_PI_DEVICES d_enum : stageEnumList) {
stageList << getPIDevice(d_enum);

int from = static_cast<int>(scanRangeMap[d_enum]->at(SPIM_RANGE_FROM_IDX)
* pow(10, SPIM_SCAN_DECIMALS));
int to = static_cast<int>(scanRangeMap[d_enum]->at(SPIM_RANGE_TO_IDX)
* pow(10, SPIM_SCAN_DECIMALS));
int step = static_cast<int>(scanRangeMap[d_enum]->at(SPIM_RANGE_STEP_IDX)
* pow(10, SPIM_SCAN_DECIMALS));

int from = static_cast<int>(scanRangeMap[d_enum]->at(SPIM_RANGE_FROM_IDX)
* pow(10, SPIM_SCAN_DECIMALS));
int to = static_cast<int>(scanRangeMap[d_enum]->at(SPIM_RANGE_TO_IDX)
* pow(10, SPIM_SCAN_DECIMALS));
int step = static_cast<int>(scanRangeMap[d_enum]->at(SPIM_RANGE_STEP_IDX)
* pow(10, SPIM_SCAN_DECIMALS));

if (step == 0) {
nSteps[d_enum] = 1;
} else {
nSteps[d_enum] = static_cast<int>(ceil((to - from) / step) + 1);
if (step == 0) {
nSteps[d_enum] = 1;
} else {
nSteps[d_enum] = static_cast<int>(ceil((to - from) / step) + 1);
}
}
}

totalSteps = 1;
for (const SPIM_PI_DEVICES d_enum : enabledMosaicStages) {
totalSteps *= nSteps[d_enum];
currentSteps[d_enum] = 0;
}
logger->info(QString("Total number of stacks to acquire: %1 (with %2 frames in each)")
.arg(totalSteps)
.arg(nSteps[stackStage]));
totalSteps = 1;
for (const SPIM_PI_DEVICES d_enum : enabledMosaicStages) {
totalSteps *= nSteps[d_enum];
currentSteps[d_enum] = 0;
}
logger->info(QString("Total number of stacks to acquire: %1 (with %2 frames in each)")
.arg(totalSteps)
.arg(nSteps[stackStage]));

currentStep = 0;
currentStep = 0;
#endif

// create output directories
for (int i = 0; i < SPIM_NCAMS; ++i) {
getFullOutputDir(i).mkpath(".");
}
// create output directories
for (int i = 0; i < SPIM_NCAMS; ++i) {
getFullOutputDir(i).mkpath(".");
}

_startCapture();
_startCapture();

} catch (std::runtime_error e) {
onError(e.what());
return false;
}
return true;
}

Expand Down Expand Up @@ -411,8 +451,10 @@ void SPIM::setupStateMachine()
QState *freeRunState = newState(STATE_FREERUN, capturingState);
connect(freeRunState, &QState::entered, this, [=]() {
try {
for (OrcaFlash *orca : camList) {
orca->cap_start();
for (int i = 0; i < SPIM_NCAMS; ++i) {
if (camEnabled[i]) {
camList[i]->cap_start();
}
}

#ifdef MASTER_SPIM
Expand Down Expand Up @@ -580,17 +622,21 @@ void SPIM::setupStateMachine()

// prepare and start acquisition thread
for (int i = 0; i < SPIM_NCAMS; ++i) {
SaveStackWorker *ssWorker = ssWorkerList.at(i);
ssWorker->setTimeout(2 * 1e6 / getTriggerRate());
ssWorker->setOutputPath(getFullOutputDir(i).absolutePath());
ssWorker->setOutputFileName(outputFname + "_cam_" + side.at(i));
ssWorker->setFrameCount(frameCount);
ssWorker->setBinning(binning);
if (camEnabled[i]) {
SaveStackWorker *ssWorker = ssWorkerList.at(i);
ssWorker->setTimeout(2 * 1e6 / getTriggerRate());
ssWorker->setOutputPath(getFullOutputDir(i).absolutePath());
ssWorker->setOutputFileName(outputFname + "_cam_" + side.at(i));
ssWorker->setFrameCount(frameCount);
ssWorker->setBinning(binning);
}
}

for (int i = 0; i < SPIM_NCAMS; ++i) {
camList.at(i)->cap_start();
QMetaObject::invokeMethod(ssWorkerList.at(i), &SaveStackWorker::start);
if (camEnabled[i]) {
camList.at(i)->cap_start();
QMetaObject::invokeMethod(ssWorkerList.at(i), &SaveStackWorker::start);
}
}
#ifdef MASTER_SPIM
tasks->start();
Expand Down Expand Up @@ -686,7 +732,7 @@ void SPIM::_setExposureTime(double expTime)

void SPIM::incrementCompleted(bool ok)
{
#define EXPECTED_N_JOBS SPIM_NCAMS
#define EXPECTED_N_JOBS nEnabledCameras()
if (freeRun) {
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/gui/spim.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class SPIM : public QObject
bool isMosaicStageEnabled(SPIM_PI_DEVICES dev) const;
void setMosaicStageEnabled(SPIM_PI_DEVICES dev, bool enable);

bool isCameraEnabled(uint dev);
void setCameraEnabled(uint camera, bool enable);
int nEnabledCameras();

int getBinning() const;
bool setBinning(uint value);

Expand Down Expand Up @@ -168,6 +172,7 @@ public slots:

QList<OrcaFlash *> camList;
QList<SaveStackWorker *> ssWorkerList;
QList<bool> camEnabled;

QStateMachine *sm = nullptr;

Expand Down