Commit 6e812e00 authored by Matt Clarkson's avatar Matt Clarkson

Merge branch '5353-fix-save-calib-data'

parents 59fed8b3 52b90000
......@@ -52,8 +52,11 @@ signals:
protected:
IGIDataSourcePlaybackControlsWidget(const IGIDataSourcePlaybackControlsWidget&); // Purposefully not implemented.
IGIDataSourcePlaybackControlsWidget& operator=(const IGIDataSourcePlaybackControlsWidget&); // Purposefully not implemented.
// Purposefully not implemented.
IGIDataSourcePlaybackControlsWidget(const IGIDataSourcePlaybackControlsWidget&);
// Purposefully not implemented.
IGIDataSourcePlaybackControlsWidget& operator=(const IGIDataSourcePlaybackControlsWidget&);
private slots:
......
......@@ -479,7 +479,8 @@ void IGIDataSourcePlaybackWidget::OnStartPushButtonClicked(bool /*isChecked*/)
//-----------------------------------------------------------------------------
void IGIDataSourcePlaybackWidget::OnSliderReleased()
{
IGIDataSourceI::IGITimeType time = m_Manager->ComputeTimeFromSlider(m_PlaybackControlsWidget->m_PlaybackSlider->value());
IGIDataSourceI::IGITimeType time =
m_Manager->ComputeTimeFromSlider(m_PlaybackControlsWidget->m_PlaybackSlider->value());
m_Manager->SetPlaybackTime(time);
}
......
......@@ -80,7 +80,7 @@ public:
const static bool DefaultUpdateNodes;
const static bool DefaultModelIsStationary;
const static bool DefaultCameraIsStationary;
const static bool DefaultSaveOutputBeforeCalibration;
const static bool DefaultSaveOutputRegardlessOfCalibration;
const static bool DefaultResetCalibrationIfNodeChanges;
mitkClassMacroItkParent(NiftyCalVideoCalibrationManager, itk::Object);
......@@ -115,8 +115,8 @@ public:
itkSetMacro(CameraIsStationary, bool);
itkGetMacro(CameraIsStationary, bool);
itkSetMacro(SaveOutputBeforeCalibration, bool);
itkGetMacro(SaveOutputBeforeCalibration, bool);
itkSetMacro(SaveOutputRegardlessOfCalibration, bool);
itkGetMacro(SaveOutputRegardlessOfCalibration, bool);
itkSetMacro(ResetCalibrationIfNodeChanges, bool);
itkGetMacro(ResetCalibrationIfNodeChanges, bool);
......@@ -168,6 +168,9 @@ public:
void SetModelTransformFileName(const std::string& fileName);
itkGetMacro(ModelTransformFileName, std::string);
itkGetMacro(CalibrationResult, std::string);
itkGetMacro(CalibrationErrorMessage, std::string);
bool isStereo() const;
unsigned int GetNumberOfSnapshots() const;
......@@ -195,15 +198,17 @@ public:
* This can be mono, stereo, iterative and include hand-eye,
* depending on the configuration parameters stored in this class.
*
* \return calibration message with all results in.
* \return bool true if it ran to completion, false otherwise.
*
* Note that even if calibration ran to completion, it doesn't mean its a good calibration.
*/
std::string Calibrate();
bool Calibrate();
/**
* \brief Saves a bunch of standard (from a NifTK perspective)
* calibration files to the output dir, overwriting existing files.
*/
void Save();
void Save(bool isSuccessful);
/**
* \brief To update the camera to world in mitk::DataStorage so
......@@ -353,7 +358,7 @@ private:
bool m_DoClustering;
bool m_ModelIsStationary;
bool m_CameraIsStationary;
bool m_SaveOutputBeforeCalibration;
bool m_SaveOutputRegardlessOfCalibration;
bool m_ResetCalibrationIfNodeChanges;
unsigned int m_NumberOfSnapshotsForCalibrating;
std::string m_ModelFileName;
......@@ -413,6 +418,7 @@ private:
std::vector<cv::Matx44d> m_HandEyeMatrices[2];
cv::Matx44d m_ModelToWorld;
std::string m_CalibrationResult;
std::string m_CalibrationErrorMessage;
}; // end class
......
......@@ -32,6 +32,9 @@
#include <niftkCoordinateAxesData.h>
#include <niftkFileHelper.h>
#include <chrono>
#include <thread>
namespace niftk
{
......@@ -213,8 +216,8 @@ void CameraCalView::RetrievePreferenceValues()
bool cameraIsStationary = prefs->GetBool(CameraCalViewPreferencePage::CAMERA_IS_STATIONARY_NODE_NAME, niftk::NiftyCalVideoCalibrationManager::DefaultCameraIsStationary);
m_Manager->SetCameraIsStationary(cameraIsStationary);
bool saveOutputBeforeCalibration = prefs->GetBool(CameraCalViewPreferencePage::SAVE_OUTPUT_BEFORE_CALIBRATION_NODE_NAME, niftk::NiftyCalVideoCalibrationManager::DefaultSaveOutputBeforeCalibration);
m_Manager->SetSaveOutputBeforeCalibration(saveOutputBeforeCalibration);
bool saveOutputRegardlessOfCalibration = prefs->GetBool(CameraCalViewPreferencePage::SAVE_OUTPUT_REGARDLESS_OF_CALIBRATION_NODE_NAME, niftk::NiftyCalVideoCalibrationManager::DefaultSaveOutputRegardlessOfCalibration);
m_Manager->SetSaveOutputRegardlessOfCalibration(saveOutputRegardlessOfCalibration);
bool resetCalibrationIfNodeChanges = prefs->GetBool(CameraCalViewPreferencePage::RESET_CALIBRATION_IF_NODE_CHANGES_NODE_NAME, niftk::NiftyCalVideoCalibrationManager::DefaultResetCalibrationIfNodeChanges);
m_Manager->SetResetCalibrationIfNodeChanges(resetCalibrationIfNodeChanges);
......@@ -419,9 +422,9 @@ void CameraCalView::OnGrabButtonPressed()
// If there is no model file, calibration will ultimately fail.
// However, if the user just wants to grab data, and hence
// m_Manager->GetSaveOutputBeforeCalibration() is true, then we do NOT need this check.
// So, only do this check if m_Manager->GetSaveOutputBeforeCalibration() is false.
if (m_Manager->GetModelFileName().empty() && !m_Manager->GetSaveOutputBeforeCalibration())
// m_Manager->GetSaveOutputRegardlessOfCalibration() is true, then we do NOT need this check.
// So, only do this check if m_Manager->GetSaveOutputRegardlessOfCalibration() is false.
if (m_Manager->GetModelFileName().empty() && !m_Manager->GetSaveOutputRegardlessOfCalibration())
{
QMessageBox msgBox;
msgBox.setText("An Error Occurred.");
......@@ -449,9 +452,7 @@ void CameraCalView::OnGrabButtonPressed()
//-----------------------------------------------------------------------------
bool CameraCalView::RunGrab()
{
bool isSuccessful = false;
std::string errorMessage = "";
// This happens in a separate thread, so try to catch everything.
// Even if we understand where NiftyCal exceptions come from,
......@@ -464,30 +465,20 @@ bool CameraCalView::RunGrab()
}
catch (niftk::NiftyCalException& e)
{
errorMessage = e.GetDescription();
std::string errorMessage = e.GetDescription();
MITK_ERROR << "CameraCalView::RunGrab() failed:" << e.GetDescription();
}
catch (mitk::Exception& e)
{
errorMessage = e.GetDescription();
std::string errorMessage = e.GetDescription();
MITK_ERROR << "CameraCalView::RunGrab() failed:" << e.GetDescription();
}
catch (std::exception& e)
{
errorMessage = e.what();
std::string errorMessage = e.what();
MITK_ERROR << "CameraCalView::RunGrab() failed:" << e.what();
}
if (!errorMessage.empty())
{
QMessageBox msgBox;
msgBox.setText("An Error Occurred.");
msgBox.setInformativeText(QString::fromStdString(errorMessage));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
}
return isSuccessful;
}
......@@ -505,6 +496,8 @@ void CameraCalView::OnBackgroundGrabProcessFinished()
QPixmap image(":/uk.ac.ucl.cmic.igicameracal/green-tick-300px.png");
m_Controls->m_ImageLabel->setPixmap(image);
m_Controls->m_ImageLabel->show();
m_Controls->m_ImageLabel->update();
std::this_thread::sleep_for(std::chrono::milliseconds(250));
// try calibrating - might not have enough images yet.
this->Calibrate();
......@@ -548,10 +541,9 @@ void CameraCalView::Calibrate()
//-----------------------------------------------------------------------------
std::string CameraCalView::RunCalibration()
bool CameraCalView::RunCalibration()
{
std::string outputMessage = "";
std::string errorMessage = "";
bool isSuccessful = false;
// This happens in a separate thread, so try to catch everything.
// Even if we understand where NiftyCal exceptions come from,
......@@ -560,66 +552,49 @@ std::string CameraCalView::RunCalibration()
try
{
if (m_Manager->GetSaveOutputBeforeCalibration())
{
m_Manager->Save();
}
outputMessage = m_Manager->Calibrate();
isSuccessful = m_Manager->Calibrate();
}
catch (niftk::NiftyCalException& e)
{
errorMessage = e.GetDescription();
std::string errorMessage = e.GetDescription();
MITK_ERROR << "CameraCalView::RunCalibration() failed:" << e.GetDescription();
throw e;
}
catch (mitk::Exception& e)
{
errorMessage = e.GetDescription();
std::string errorMessage = e.GetDescription();
MITK_ERROR << "CameraCalView::RunCalibration() failed:" << e.GetDescription();
throw e;
}
catch (std::exception& e)
{
errorMessage = e.what();
std::string errorMessage = e.what();
MITK_ERROR << "CameraCalView::RunCalibration() failed:" << e.what();
throw e;
}
return outputMessage;
return isSuccessful;
}
//-----------------------------------------------------------------------------
void CameraCalView::OnBackgroundCalibrateProcessFinished()
{
if (m_BackgroundCalibrateProcess.isCanceled()
|| m_BackgroundCalibrateProcess.resultCount() == 0)
bool successfullyCalibrated = m_BackgroundCalibrateProcessWatcher.result();
if (successfullyCalibrated)
{
QPixmap image(":/uk.ac.ucl.cmic.igicameracal/thumb-down-300px.png");
m_Controls->m_ProjectionErrorValue->setText(QString::fromStdString(this->m_Manager->GetCalibrationResult()));
QPixmap image(":/uk.ac.ucl.cmic.igicameracal/1465762629-300px.png");
m_Controls->m_ImageLabel->setPixmap(image);
m_Controls->m_ImageLabel->show();
QMessageBox msgBox;
msgBox.setText("An Error Occurred.");
msgBox.setInformativeText("The calibration itself failed - check log.");
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
m_Manager->UpdateCameraToWorldPosition();
m_Manager->UpdateVisualisedPoints();
}
else
{
std::string calibrationMessage = m_BackgroundCalibrateProcessWatcher.result();
m_Controls->m_ProjectionErrorValue->setText(QString::fromStdString(calibrationMessage));
m_Manager->UpdateCameraToWorldPosition();
m_Manager->UpdateVisualisedPoints();
QPixmap image(":/uk.ac.ucl.cmic.igicameracal/1465762629-300px.png");
m_Controls->m_ProjectionErrorValue->setText(QString::fromStdString(this->m_Manager->GetCalibrationErrorMessage()));
QPixmap image(":/uk.ac.ucl.cmic.igicameracal/thumb-down-300px.png");
m_Controls->m_ImageLabel->setPixmap(image);
m_Controls->m_ImageLabel->show();
if (!m_Manager->GetSaveOutputBeforeCalibration())
{
m_Manager->Save();
}
}
m_Manager->Restart();
......
......@@ -101,9 +101,9 @@ private slots:
private:
bool RunGrab();
void Calibrate();
std::string RunCalibration();
bool RunCalibration();
void Calibrate();
void SetButtonsEnabled(bool isEnabled);
/**
......@@ -120,8 +120,8 @@ private:
niftk::NiftyCalVideoCalibrationManager::Pointer m_Manager;
QFuture<bool> m_BackgroundGrabProcess;
QFutureWatcher<bool> m_BackgroundGrabProcessWatcher;
QFuture<std::string> m_BackgroundCalibrateProcess;
QFutureWatcher<std::string> m_BackgroundCalibrateProcessWatcher;
QFuture<bool> m_BackgroundCalibrateProcess;
QFutureWatcher<bool> m_BackgroundCalibrateProcessWatcher;
};
} // end namespace
......
......@@ -48,7 +48,7 @@ const QString CameraCalViewPreferencePage::PREVIOUS_CALIBRATION_DIR_NODE_NAME("p
const QString CameraCalViewPreferencePage::OUTPUT_DIR_NODE_NAME("output directory");
const QString CameraCalViewPreferencePage::MODEL_IS_STATIONARY_NODE_NAME("model is stationary");
const QString CameraCalViewPreferencePage::CAMERA_IS_STATIONARY_NODE_NAME("camera is stationary");
const QString CameraCalViewPreferencePage::SAVE_OUTPUT_BEFORE_CALIBRATION_NODE_NAME("save output before calibration");
const QString CameraCalViewPreferencePage::SAVE_OUTPUT_REGARDLESS_OF_CALIBRATION_NODE_NAME("save output regardless of calibration");
const QString CameraCalViewPreferencePage::RESET_CALIBRATION_IF_NODE_CHANGES_NODE_NAME("reset if node changes");
//-----------------------------------------------------------------------------
......@@ -393,7 +393,7 @@ bool CameraCalViewPreferencePage::PerformOk()
m_CameraCalViewPreferencesNode->Put(CameraCalViewPreferencePage::OUTPUT_DIR_NODE_NAME, m_Ui->m_OutputDirLineEdit->text());
m_CameraCalViewPreferencesNode->PutBool(CameraCalViewPreferencePage::MODEL_IS_STATIONARY_NODE_NAME, m_Ui->m_ModelIsStationaryCheckBox->isChecked());
m_CameraCalViewPreferencesNode->PutBool(CameraCalViewPreferencePage::CAMERA_IS_STATIONARY_NODE_NAME, m_Ui->m_CameraIsStationaryCheckBox->isChecked());
m_CameraCalViewPreferencesNode->PutBool(CameraCalViewPreferencePage::SAVE_OUTPUT_BEFORE_CALIBRATION_NODE_NAME, m_Ui->m_SaveOutputBeforeCalibrationCheckBox->isChecked());
m_CameraCalViewPreferencesNode->PutBool(CameraCalViewPreferencePage::SAVE_OUTPUT_REGARDLESS_OF_CALIBRATION_NODE_NAME, m_Ui->m_SaveOutputBeforeCalibrationCheckBox->isChecked());
m_CameraCalViewPreferencesNode->PutBool(CameraCalViewPreferencePage::RESET_CALIBRATION_IF_NODE_CHANGES_NODE_NAME, m_Ui->m_ResetCalibrationIfNodeChangesCheckBox->isChecked());
return true;
}
......@@ -435,7 +435,7 @@ void CameraCalViewPreferencePage::Update()
m_Ui->m_OutputDirLineEdit->setText(path);
m_Ui->m_ModelIsStationaryCheckBox->setChecked(m_CameraCalViewPreferencesNode->GetBool(CameraCalViewPreferencePage::MODEL_IS_STATIONARY_NODE_NAME, niftk::NiftyCalVideoCalibrationManager::DefaultModelIsStationary));
m_Ui->m_CameraIsStationaryCheckBox->setChecked(m_CameraCalViewPreferencesNode->GetBool(CameraCalViewPreferencePage::CAMERA_IS_STATIONARY_NODE_NAME, niftk::NiftyCalVideoCalibrationManager::DefaultCameraIsStationary));
m_Ui->m_SaveOutputBeforeCalibrationCheckBox->setChecked(m_CameraCalViewPreferencesNode->GetBool(CameraCalViewPreferencePage::SAVE_OUTPUT_BEFORE_CALIBRATION_NODE_NAME, niftk::NiftyCalVideoCalibrationManager::DefaultSaveOutputBeforeCalibration));
m_Ui->m_SaveOutputBeforeCalibrationCheckBox->setChecked(m_CameraCalViewPreferencesNode->GetBool(CameraCalViewPreferencePage::SAVE_OUTPUT_REGARDLESS_OF_CALIBRATION_NODE_NAME, niftk::NiftyCalVideoCalibrationManager::DefaultSaveOutputRegardlessOfCalibration));
m_Ui->m_ResetCalibrationIfNodeChangesCheckBox->setChecked(m_CameraCalViewPreferencesNode->GetBool(CameraCalViewPreferencePage::RESET_CALIBRATION_IF_NODE_CHANGES_NODE_NAME, niftk::NiftyCalVideoCalibrationManager::DefaultResetCalibrationIfNodeChanges));
}
......
......@@ -65,7 +65,7 @@ public:
static const QString OUTPUT_DIR_NODE_NAME;
static const QString MODEL_IS_STATIONARY_NODE_NAME;
static const QString CAMERA_IS_STATIONARY_NODE_NAME;
static const QString SAVE_OUTPUT_BEFORE_CALIBRATION_NODE_NAME;
static const QString SAVE_OUTPUT_REGARDLESS_OF_CALIBRATION_NODE_NAME;
static const QString RESET_CALIBRATION_IF_NODE_CHANGES_NODE_NAME;
CameraCalViewPreferencePage();
......
0 0 0 0
1 3 0 0
2 6 0 0
3 9 0 0
4 12 0 0
5 15 0 0
6 18 0 0
7 21 0 0
8 24 0 0
9 27 0 0
10 30 0 0
11 33 0 0
12 36 0 0
13 0 3 0
14 3 3 0
15 6 3 0
16 9 3 0
17 12 3 0
18 15 3 0
19 18 3 0
20 21 3 0
21 24 3 0
22 27 3 0
23 30 3 0
24 33 3 0
25 36 3 0
26 0 6 0
27 3 6 0
28 6 6 0
29 9 6 0
30 12 6 0
31 15 6 0
32 18 6 0
33 21 6 0
34 24 6 0
35 27 6 0
36 30 6 0
37 33 6 0
38 36 6 0
39 0 9 0
40 3 9 0
41 6 9 0
42 9 9 0
43 12 9 0
44 15 9 0
45 18 9 0
46 21 9 0
47 24 9 0
48 27 9 0
49 30 9 0
50 33 9 0
51 36 9 0
52 0 12 0
53 3 12 0
54 6 12 0
55 9 12 0
56 12 12 0
57 15 12 0
58 18 12 0
59 21 12 0
60 24 12 0
61 27 12 0
62 30 12 0
63 33 12 0
64 36 12 0
65 0 15 0
66 3 15 0
67 6 15 0
68 9 15 0
69 12 15 0
70 15 15 0
71 18 15 0
72 21 15 0
73 24 15 0
74 27 15 0
75 30 15 0
76 33 15 0
77 36 15 0
78 0 18 0
79 3 18 0
80 6 18 0
81 9 18 0
82 12 18 0
83 15 18 0
84 18 18 0
85 21 18 0
86 24 18 0
87 27 18 0
88 30 18 0
89 33 18 0
90 36 18 0
91 0 21 0
92 3 21 0
93 6 21 0
94 9 21 0
95 12 21 0
96 15 21 0
97 18 21 0
98 21 21 0
99 24 21 0
100 27 21 0
101 30 21 0
102 33 21 0
103 36 21 0
104 0 24 0
105 3 24 0
106 6 24 0
107 9 24 0
108 12 24 0
109 15 24 0
110 18 24 0
111 21 24 0
112 24 24 0
113 27 24 0
114 30 24 0
115 33 24 0
116 36 24 0
117 0 27 0
118 3 27 0
119 6 27 0
120 9 27 0
121 12 27 0
122 15 27 0
123 18 27 0
124 21 27 0
125 24 27 0
126 27 27 0
127 30 27 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment