Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxTemporalCalibrationWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
12 
13 
14 #include <QtWidgets>
15 
16 #include <QVBoxLayout>
17 #include "boost/bind.hpp"
18 #include "cxTrackingService.h"
20 #include <vtkDoubleArray.h>
21 #include <vtkPointData.h>
22 #include "cxDoubleWidgets.h"
23 #include "cxTypeConversions.h"
24 #include "cxRecordSessionWidget.h"
25 #include "cxSettings.h"
26 #include "cxToolProperty.h"
28 #include "cxUtilHelpers.h"
29 #include "cxVolumeHelpers.h"
30 #include "vtkImageCorrelation.h"
31 #include "cxLogger.h"
32 #include "cxPatientModelService.h"
33 #include "cxVisServices.h"
34 
35 typedef vtkSmartPointer<vtkImageCorrelation> vtkImageCorrelationPtr;
36 typedef vtkSmartPointer<vtkDoubleArray> vtkDoubleArrayPtr;
37 
38 
39 namespace cx
40 {
41 
42 typedef unsigned char uchar;
43 
44 
46  BaseWidget(parent, "temporal_calibration_widget", "Temporal Calibration"),
47  mInfoLabel(new QLabel(""))
48 {
49  mServices = services;
50 
51  this->setToolTip("Temporal calibration from a vertical periodic movement of an US probe");
52  mAlgorithm.reset(new TemporalCalibration);
53  connect(mServices->patient().get(), SIGNAL(patientChanged()), this, SLOT(patientChangedSlot()));
54 
55  connect(acquisitionService.get(), SIGNAL(saveDataCompleted(QString)), this, SLOT(selectData(QString)));
56 
58  mRecordSessionWidget = new RecordSessionWidget(acquisitionService, this, context, "temp_cal");
59 
60  QVBoxLayout* topLayout = new QVBoxLayout(this);
61 
62  // add recording widgets
63  QLabel* acqLabel = new QLabel("<b>Acquisition</b>");
64  topLayout->addWidget(acqLabel);
65  acqLabel->setToolTip(this->toolTip());
66  topLayout->addWidget(mInfoLabel);
67  topLayout->addWidget(mRecordSessionWidget);
68  topLayout->addWidget(new LabeledComboBoxWidget(this, StringPropertyActiveProbeConfiguration::New(mServices->tracking())));
69  topLayout->addWidget(new SpinBoxGroupWidget(this, DoublePropertyTimeCalibration::New(mServices->tracking())));
70 
71  topLayout->addWidget(this->createHorizontalLine());
72 
73  // add calibration widgets
74  QLabel* calLabel = new QLabel("<b>Calibration</b>");
75  topLayout->addWidget(calLabel);
76  calLabel->setToolTip(this->toolTip());
77 
78  mFileSelectWidget = new FileSelectWidget(this);
79  connect(mFileSelectWidget, SIGNAL(fileSelected(QString)), this, SLOT(selectData(QString)));
80  mFileSelectWidget->setNameFilter(QStringList() << "*.fts");
81  topLayout->addWidget(mFileSelectWidget);
82 
83  mVerbose = new QCheckBox("Save data to temporal_calib.txt");
84  topLayout->addWidget(mVerbose);
85 
86  QPushButton* calibrateButton = new QPushButton("Calibrate");
87  calibrateButton->setToolTip("Calculate the temporal shift for the selected acqusition."
88  "The shift is not applied in any way."
89  "<p><b>NB:</b>"
90  " The calculation takes a few seconds, and in this time the program will be unresponsive</p>");
91 
92  connect(calibrateButton, SIGNAL(clicked()), this, SLOT(calibrateSlot()));
93  topLayout->addWidget(calibrateButton);
94 
95  mResult = new QLineEdit;
96  mResult->setReadOnly(true);
97  topLayout->addWidget(mResult);
98 
99  topLayout->addStretch();
100 
101  this->patientChangedSlot();
102 }
103 
105 {}
106 
108 {
109  mFileSelectWidget->refresh();
110 }
111 
112 void TemporalCalibrationWidget::patientChangedSlot()
113 {
114  QString filename = mServices->patient()->getActivePatientFolder() + "/US_Acq/";
115  mFileSelectWidget->setPath(filename);
116 }
117 
118 void TemporalCalibrationWidget::selectData(QString filename)
119 {
120  mAlgorithm->selectData(filename, mServices->file());
121  mFileSelectWidget->setFilename(filename);
122  mResult->setText("");
123 }
124 
128 void TemporalCalibrationWidget::calibrateSlot()
129 {
130  if (mVerbose->isChecked())
131  mAlgorithm->setDebugFolder(mServices->patient()->getActivePatientFolder()+"/Logs/");
132  else
133  mAlgorithm->setDebugFolder("");
134 
135  bool success = true;
136  double shift = mAlgorithm->calibrate(&success);
137  if (success)
138  {
139  reportSuccess(QString("Completed temporal calibration, found shift %1 ms").arg(shift,0,'f',0));
140  mResult->setText(QString("Shift = %1 ms").arg(shift, 0, 'f', 0));
141  }
142  else
143  {
144  reportError(QString("Temporal calibration failed"));
145  mResult->setText(QString("failed"));
146  }
147 }
148 
149 
150 }//namespace cx
151 
152 
void setNameFilter(QStringList filter)
vtkSmartPointer< vtkDoubleArray > vtkDoubleArrayPtr
void reportError(QString msg)
Definition: cxLogger.cpp:71
boost::shared_ptr< class AcquisitionService > AcquisitionServicePtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
static DoublePropertyBasePtr New(TrackingServicePtr trackingService)
static StringPropertyActiveProbeConfigurationPtr New(TrackingServicePtr trackingService)
Composite widget for string selection.
static QFrame * createHorizontalLine()
Creates a horizontal line which can be inserted into widgets.
void setFilename(QString name)
void setPath(QString path)
void reportSuccess(QString msg)
Definition: cxLogger.cpp:72
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
Composite widget for scalar data manipulation.
unsigned char uchar
TemporalCalibrationWidget(VisServicesPtr services, AcquisitionServicePtr acquisitionService, QWidget *parent)
vtkSmartPointer< vtkImageCorrelation > vtkImageCorrelationPtr
Widget for displaying and selecting a single file.
Namespace for all CustusX production code.