CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
33 
34 
35 #include <QtWidgets>
36 
37 #include <QVBoxLayout>
38 #include "boost/bind.hpp"
39 #include "cxTrackingService.h"
41 #include <vtkDoubleArray.h>
42 #include <vtkPointData.h>
43 #include "cxDoubleWidgets.h"
44 #include "cxTypeConversions.h"
45 #include "cxRecordSessionWidget.h"
46 #include "cxSettings.h"
47 #include "cxToolProperty.h"
49 #include "cxUtilHelpers.h"
50 #include "cxVolumeHelpers.h"
51 #include "vtkImageCorrelation.h"
52 #include "cxLogger.h"
53 #include "cxPatientModelService.h"
54 #include "cxVisServices.h"
55 
56 typedef vtkSmartPointer<vtkImageCorrelation> vtkImageCorrelationPtr;
57 typedef vtkSmartPointer<vtkDoubleArray> vtkDoubleArrayPtr;
58 
59 
60 namespace cx
61 {
62 
63 typedef unsigned char uchar;
64 
65 
67  BaseWidget(parent, "TemporalCalibrationWidget", "Temporal Calibration"),
68  mInfoLabel(new QLabel(""))
69 {
70  mServices = services;
71 
72  this->setToolTip("Temporal calibration from a vertical periodic movement of an US probe");
73  mAlgorithm.reset(new TemporalCalibration);
74  connect(mServices->getPatientService().get(), SIGNAL(patientChanged()), this, SLOT(patientChangedSlot()));
75 
76  connect(acquisitionService.get(), SIGNAL(saveDataCompleted(QString)), this, SLOT(selectData(QString)));
77 
78  mRecordSessionWidget = new RecordSessionWidget(acquisitionService, this, "temporal_calib");
79 
80  mRecordSessionWidget->setDescriptionVisibility(false);
81 
82  QVBoxLayout* topLayout = new QVBoxLayout(this);
83 
84  // add recording widgets
85  QLabel* acqLabel = new QLabel("<b>Acquisition</b>");
86  topLayout->addWidget(acqLabel);
87  acqLabel->setToolTip(this->toolTip());
88  topLayout->addWidget(mInfoLabel);
89  topLayout->addWidget(mRecordSessionWidget);
90  topLayout->addWidget(new LabeledComboBoxWidget(this, StringPropertyActiveProbeConfiguration::New(mServices->getToolManager())));
91  topLayout->addWidget(new SpinBoxGroupWidget(this, DoublePropertyTimeCalibration::New(mServices->getToolManager())));
92 
93  topLayout->addWidget(this->createHorizontalLine());
94 
95  // add calibration widgets
96  QLabel* calLabel = new QLabel("<b>Calibration</b>");
97  topLayout->addWidget(calLabel);
98  calLabel->setToolTip(this->toolTip());
99 
100  mFileSelectWidget = new FileSelectWidget(this);
101  connect(mFileSelectWidget, SIGNAL(fileSelected(QString)), this, SLOT(selectData(QString)));
102  mFileSelectWidget->setNameFilter(QStringList() << "*.fts");
103  topLayout->addWidget(mFileSelectWidget);
104 
105  mVerbose = new QCheckBox("Save data to temporal_calib.txt");
106  topLayout->addWidget(mVerbose);
107 
108  QPushButton* calibrateButton = new QPushButton("Calibrate");
109  calibrateButton->setToolTip("Calculate the temporal shift for the selected acqusition."
110  "The shift is not applied in any way."
111  "<p><b>NB:</b>"
112  " The calculation takes a few seconds, and in this time the program will be unresponsive</p>");
113 
114  connect(calibrateButton, SIGNAL(clicked()), this, SLOT(calibrateSlot()));
115  topLayout->addWidget(calibrateButton);
116 
117  mResult = new QLineEdit;
118  mResult->setReadOnly(true);
119  topLayout->addWidget(mResult);
120 
121  topLayout->addStretch();
122 
123  this->patientChangedSlot();
124 }
125 
127 {}
128 
130 {
131  mFileSelectWidget->refresh();
132 }
133 
134 void TemporalCalibrationWidget::patientChangedSlot()
135 {
136  QString filename = mServices->getPatientService()->getActivePatientFolder() + "/US_Acq/";
137  mFileSelectWidget->setPath(filename);
138 }
139 
140 void TemporalCalibrationWidget::selectData(QString filename)
141 {
142  mAlgorithm->selectData(filename);
143  mFileSelectWidget->setFilename(filename);
144  mResult->setText("");
145 }
146 
150 void TemporalCalibrationWidget::calibrateSlot()
151 {
152  if (mVerbose->isChecked())
153  mAlgorithm->setDebugFolder(mServices->getPatientService()->getActivePatientFolder()+"/Logs/");
154  else
155  mAlgorithm->setDebugFolder("");
156 
157  bool success = true;
158  double shift = mAlgorithm->calibrate(&success);
159  if (success)
160  {
161  reportSuccess(QString("Completed temporal calibration, found shift %1 ms").arg(shift,0,'f',0));
162  mResult->setText(QString("Shift = %1 ms").arg(shift, 0, 'f', 0));
163  }
164  else
165  {
166  reportError(QString("Temporal calibration failed"));
167  mResult->setText(QString("failed"));
168  }
169 }
170 
171 
172 }//namespace cx
173 
174 
void setNameFilter(QStringList filter)
vtkSmartPointer< vtkDoubleArray > vtkDoubleArrayPtr
void reportError(QString msg)
Definition: cxLogger.cpp:92
boost::shared_ptr< class AcquisitionService > AcquisitionServicePtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
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:93
cxLogicManager_EXPORT AcquisitionServicePtr acquisitionService()
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
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.