CustusX  22.04-rc5
An IGT application
cxVirtualCameraRotationWidget.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 =========================================================================*/
32 
33 #include <cmath>
36 #include "cxHelperWidgets.h"
37 #include "cxTrackingService.h"
38 #include "cxToolProperty.h"
39 #include "cxLogger.h"
40 
41 namespace cx
42 {
43 
45  BaseWidget(parent,"virtual_camera_rotation_widget", "Virtual Camera Rotation"),
46  mVerticalLayout(new QVBoxLayout(this)),
47  mToolSelector(toolSelector)
48 {
49  QLabel *title = new QLabel(tr("Virtual Camera Rotation"));
50  title->setStyleSheet("font-weight: bold");
51  mVerticalLayout->addWidget(title,0,Qt::AlignLeft);
52 
53  //mVerticalLayout->addWidget(sscCreateDataWidget(this, mToolSelector));
54  mVerticalLayout->addWidget(new QLabel("<font color=red>Caution: sMt is changed directly by this control.</font>"));
55 
56  QLabel *labelRot = new QLabel(tr("Rotate (360 deg)"));
57  mRotateDial = new QDial;
58  mRotateDial->setMinimum(-180);
59  mRotateDial->setMaximum(180);
60  mRotateDial->setNotchesVisible(true);
61 
62  mVerticalLayout->addWidget(labelRot,0,Qt::AlignLeft);
63  mVerticalLayout->addWidget(mRotateDial,0,Qt::AlignRight);
64 
65  this->setLayout(mVerticalLayout);
66 
67  connect(mRotateDial, &QDial::valueChanged, this, &VirtualCameraRotationWidget::toolRotationChanged);
68  connect(mToolSelector.get(), SIGNAL(changed()), this, SLOT(toolCalibrationChanged()));
69  connect(services->tracking().get(), &TrackingService::stateChanged, this, &VirtualCameraRotationWidget::toolCalibrationChanged);
70 }
71 
73 {
74 }
75 
77 {
78  return "virtual_camera_rotation_widget";
79 }
80 
81 void VirtualCameraRotationWidget::toolCalibrationChanged()
82 {
83  ToolPtr tool = this->getTool();
84  if (!tool)
85  return;
86 
87  mRotateDial->blockSignals(true);
88 
89  mDecomposition.reset(tool->getCalibration_sMt());
90  Vector3D angles = mDecomposition.getAngles();
91  int zAngle = (int) std::round(angles(2)*180/M_PI);
92  mRotateDial->setValue(zAngle);
93 
94  mRotateDial->blockSignals(false);
95 }
96 
97 void VirtualCameraRotationWidget::toolRotationChanged()
98 {
99  ToolPtr tool = this->getTool();
100  if (!tool)
101  return;
102 
103  Transform3D M = tool->getCalibration_sMt();
104  double zAngleUpdated = mRotateDial->value()*M_PI/180;
105  Vector3D angles = mDecomposition.getAngles();
106  angles(2) = zAngleUpdated;
107  mDecomposition.setAngles(angles);
108  M = mDecomposition.getMatrix();
109  tool->setCalibration_sMt(M);
110 }
111 
112 ToolPtr VirtualCameraRotationWidget::getTool()
113 {
114  ToolPtr tool = mToolSelector->getTool();
115  if (tool)
116  {
117  ToolPtr baseTool = tool->getBaseTool();
118  if (baseTool)
119  tool = baseTool;
120  }
121  return tool;
122 }
123 
124 QString VirtualCameraRotationWidget::defaultWhatsThis() const
125 {
126  return "<html>"
127  "<h3>VirtualCameraRotationWidget.</h3>"
128  "<p>Rotates virtual camera (calibration).</p>"
129  "</html>";
130 }
131 
132 
133 } /* namespace cx */
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class StringPropertySelectTool > StringPropertySelectToolPtr
Vector3D getAngles() const
Definition: cxFrame3D.cpp:82
VirtualCameraRotationWidget(VisServicesPtr services, StringPropertySelectToolPtr toolSelector, QWidget *parent=0)
void reset(Transform3D m)
reinitialize with a fresh matrix.
Definition: cxFrame3D.cpp:35
Transform3D getMatrix() const
Definition: cxFrame3D.cpp:92
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
void setAngles(Vector3D xyz)
Definition: cxFrame3D.cpp:55
Vector3D round(const Vector3D &a)
Definition: cxVector3D.cpp:75
#define M_PI
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr