Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxToolManualCalibrationWidget.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 #include <QLabel>
14 #include <QGroupBox>
15 #include "cxActiveToolWidget.h"
16 #include "cxTrackingService.h"
17 #include "cxHelperWidgets.h"
18 #include "cxVisServices.h"
20 #include "cxLogger.h"
21 
22 namespace cx
23 {
24 
26  BaseWidget(parent, "tool_manual_calibration_widget", "Tool Manual Calibrate"),
27  mServices(services)
28 {
29  //layout
30  QVBoxLayout* mToptopLayout = new QVBoxLayout(this);
31  //toptopLayout->setMargin(0);
32 
33  this->setToolTip("Edit tool calibration matrix sMt");
34  mTool = StringPropertySelectTool::New(mServices->tracking());
35  mToptopLayout->addWidget(sscCreateDataWidget(this, mTool));
36 
37  mToptopLayout->addWidget(new QLabel("<font color=red>Caution: sMt is changed directly by this control.</font>"));
38  mGroup = new QGroupBox(this);
39  mGroup->setTitle("Calibration matrix sMt");
40  mToptopLayout->addWidget(mGroup);
41  QVBoxLayout* groupLayout = new QVBoxLayout;
42  mGroup->setLayout(groupLayout);
43  groupLayout->setMargin(0);
44  mMatrixWidget = new Transform3DWidget(mGroup);
45  groupLayout->addWidget(mMatrixWidget);
46  connect(mMatrixWidget, SIGNAL(changed()), this, SLOT(matrixWidgetChanged()));
47  connect(mTool.get(), SIGNAL(changed()), this, SLOT(toolCalibrationChanged()));
48 
49  this->toolCalibrationChanged();
50  mMatrixWidget->setEditable(true);
51 
52  mToptopLayout->addStretch();
53 
54  connect(mServices->tracking().get(), &TrackingService::stateChanged, this, &ToolManualCalibrationWidget::toolCalibrationChanged);
55 }
56 
57 void ToolManualCalibrationWidget::toolCalibrationChanged()
58 {
59  ToolPtr tool = this->getTool();
60  if (!tool)
61  return;
62 
63 
64  mMatrixWidget->blockSignals(true);
65  mMatrixWidget->setMatrix(tool->getCalibration_sMt());
66  mMatrixWidget->blockSignals(false);
67 }
68 
69 void ToolManualCalibrationWidget::matrixWidgetChanged()
70 {
71  ToolPtr tool = this->getTool();
72  if (!tool)
73  return;
74 
75 
76  Transform3D M = mMatrixWidget->getMatrix();
77  tool->setCalibration_sMt(M);
78 }
79 
80 ToolPtr ToolManualCalibrationWidget::getTool()
81 {
82  ToolPtr tool = mTool->getTool();
83  if (tool)
84  {
85  ToolPtr baseTool = tool->getBaseTool();
86  if (baseTool)
87  tool = baseTool;
88  }
89  return tool;
90 }
91 
92 }
Widget for displaying and manipulating an affine matrix, i.e. a rotation+translation matrix...
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
void setMatrix(const Transform3D &M)
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
static StringPropertySelectToolPtr New(TrackingServicePtr trackingService)
QWidget * sscCreateDataWidget(QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
Transform3D getMatrix() const
ToolManualCalibrationWidget(VisServicesPtr services, QWidget *parent)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr