Fraxinus  16.5.0-fx-rc9
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->patient().get(), SIGNAL(patientChanged()), this, SLOT(patientChangedSlot()));
75 
76  connect(acquisitionService.get(), SIGNAL(saveDataCompleted(QString)), this, SLOT(selectData(QString)));
77 
79  mRecordSessionWidget = new RecordSessionWidget(acquisitionService, this, context, "temp_cal");
80 
81  QVBoxLayout* topLayout = new QVBoxLayout(this);
82 
83  // add recording widgets
84  QLabel* acqLabel = new QLabel("<b>Acquisition</b>");
85  topLayout->addWidget(acqLabel);
86  acqLabel->setToolTip(this->toolTip());
87  topLayout->addWidget(mInfoLabel);
88  topLayout->addWidget(mRecordSessionWidget);
89  topLayout->addWidget(new LabeledComboBoxWidget(this, StringPropertyActiveProbeConfiguration::New(mServices->tracking())));
90  topLayout->addWidget(new SpinBoxGroupWidget(this, DoublePropertyTimeCalibration::New(mServices->tracking())));
91 
92  topLayout->addWidget(this->createHorizontalLine());
93 
94  // add calibration widgets
95  QLabel* calLabel = new QLabel("<b>Calibration</b>");
96  topLayout->addWidget(calLabel);
97  calLabel->setToolTip(this->toolTip());
98 
99  mFileSelectWidget = new FileSelectWidget(this);
100  connect(mFileSelectWidget, SIGNAL(fileSelected(QString)), this, SLOT(selectData(QString)));
101  mFileSelectWidget->setNameFilter(QStringList() << "*.fts");
102  topLayout->addWidget(mFileSelectWidget);
103 
104  mVerbose = new QCheckBox("Save data to temporal_calib.txt");
105  topLayout->addWidget(mVerbose);
106 
107  QPushButton* calibrateButton = new QPushButton("Calibrate");
108  calibrateButton->setToolTip("Calculate the temporal shift for the selected acqusition."
109  "The shift is not applied in any way."
110  "<p><b>NB:</b>"
111  " The calculation takes a few seconds, and in this time the program will be unresponsive</p>");
112 
113  connect(calibrateButton, SIGNAL(clicked()), this, SLOT(calibrateSlot()));
114  topLayout->addWidget(calibrateButton);
115 
116  mResult = new QLineEdit;
117  mResult->setReadOnly(true);
118  topLayout->addWidget(mResult);
119 
120  topLayout->addStretch();
121 
122  this->patientChangedSlot();
123 }
124 
126 {}
127 
129 {
130  mFileSelectWidget->refresh();
131 }
132 
133 void TemporalCalibrationWidget::patientChangedSlot()
134 {
135  QString filename = mServices->patient()->getActivePatientFolder() + "/US_Acq/";
136  mFileSelectWidget->setPath(filename);
137 }
138 
139 void TemporalCalibrationWidget::selectData(QString filename)
140 {
141  mAlgorithm->selectData(filename);
142  mFileSelectWidget->setFilename(filename);
143  mResult->setText("");
144 }
145 
149 void TemporalCalibrationWidget::calibrateSlot()
150 {
151  if (mVerbose->isChecked())
152  mAlgorithm->setDebugFolder(mServices->patient()->getActivePatientFolder()+"/Logs/");
153  else
154  mAlgorithm->setDebugFolder("");
155 
156  bool success = true;
157  double shift = mAlgorithm->calibrate(&success);
158  if (success)
159  {
160  reportSuccess(QString("Completed temporal calibration, found shift %1 ms").arg(shift,0,'f',0));
161  mResult->setText(QString("Shift = %1 ms").arg(shift, 0, 'f', 0));
162  }
163  else
164  {
165  reportError(QString("Temporal calibration failed"));
166  mResult->setText(QString("failed"));
167  }
168 }
169 
170 
171 }//namespace cx
172 
173 
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.