NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxNavigation.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 =========================================================================*/
11 
12 #include "cxNavigation.h"
13 #include "cxImage.h"
14 #include "cxBoundingBox3D.h"
15 #include "cxPatientModelService.h"
16 #include "cxTrackingService.h"
17 #include "cxManualTool.h"
18 #include "cxVolumeHelpers.h"
19 #include "cxCameraControl.h"
20 #include "cxVisServices.h"
21 #include "cxViewService.h"
22 #include "cxActiveData.h"
23 
24 namespace cx
25 {
26 
28  mServices(services),
29  mCamera3D(camera3D)
30 {
31 
32 }
33 
34 void Navigation::centerToPosition(Vector3D p_r, QFlags<VIEW_TYPE> viewType)
35 {
36  this->moveManualToolToPosition(p_r);
37 
38  if (viewType.testFlag(v2D))
39  {
40  // set center to calculated position
41  mServices->patient()->setCenter(p_r);
42  }
43 
44  if (viewType.testFlag(v3D))
45  {
46  if (mCamera3D)
47  mCamera3D->translateByFocusTo(p_r);
48  }
49 }
50 
53 void Navigation::centerToData(DataPtr image)
54 {
55  if (!image)
56  return;
57  Vector3D p_r = image->get_rMd().coord(image->boundingBox().center());
58 
59  this->centerToPosition(p_r);
60 }
61 
65 void Navigation::centerToData(const std::vector<DataPtr>& images)
66 {
67  Vector3D p_r = findDataCenter(images);
68  this->centerToPosition(p_r);
69 }
70 
72 {
73  ViewGroupDataPtr activeGroup = mServices->view()->getActiveViewGroup();
74  this->centerToDataInViewGroup(activeGroup, properties);
75 }
76 
78 {
79  if(!group)
80  return;
81 
82  std::vector<DataPtr> visibleData = group->getData(properties);
83  if(visibleData.empty())
84  return;
85 
86  ActiveDataPtr active = mServices->patient()->getActiveData();
87  ImagePtr activeImage = active->getActive<Image>();
88  if(activeImage && std::count(visibleData.begin(), visibleData.end(), activeImage))
89  this->centerToData(activeImage);
90  else
91  this->centerToData(visibleData);
92 }
93 
98 {
99  ToolPtr tool = mServices->tracking()->getActiveTool();
100  Vector3D p_pr = tool->get_prMt().coord(Vector3D(0, 0, tool->getTooltipOffset()));
101  Vector3D p_r = mServices->patient()->get_rMpr().coord(p_pr);
102 
103  this->centerToPosition(p_r);
104 // // set center to calculated position
105 // mBackend->getDataManager()->setCenter(p_r);
106 }
107 
111 Vector3D Navigation::findDataCenter(const std::vector<DataPtr>& data)
112 {
113  DoubleBoundingBox3D bb_sigma = findEnclosingBoundingBox(data, Transform3D::Identity());
114  return bb_sigma.center();
115 }
116 
117 void Navigation::moveManualToolToPosition(Vector3D& p_r)
118 {
119  // move the manual tool to the same position. (this is a side effect... do we want it?)
120  ToolPtr manual = mServices->tracking()->getManualTool();
121  Vector3D p_pr = mServices->patient()->get_rMpr().inv().coord(p_r);
122  Transform3D prM0t = manual->get_prMt(); // modify old pos in order to keep orientation
123  Vector3D t_pr = prM0t.coord(Vector3D(0, 0, manual->getTooltipOffset()));
124  Transform3D prM1t = createTransformTranslate(p_pr - t_pr) * prM0t;
125 
126  if (!similar(prM1t, prM0t))
127  manual->set_prMt(prM1t);
128 // std::cout << "center manual tool" << std::endl;
129 }
130 
131 
132 } // namespace cx
133 
cxVolumeHelpers.h
cx::Navigation::Navigation
Navigation(VisServicesPtr services, CameraControlPtr camera3D=CameraControlPtr())
Definition: cxNavigation.cpp:27
cx::DoubleBoundingBox3D
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,...
Definition: cxBoundingBox3D.h:63
cx::Navigation::v2D
@ v2D
Definition: cxNavigation.h:32
cx::ViewGroupDataPtr
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:29
cx::DoubleBoundingBox3D::center
Vector3D center() const
Definition: cxBoundingBox3D.cpp:196
cxActiveData.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxImage.h
cx::Navigation::centerToTooltip
void centerToTooltip()
Definition: cxNavigation.cpp:97
cx::VisServicesPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
cx::Navigation::centerToDataInViewGroup
void centerToDataInViewGroup(ViewGroupDataPtr group, DataViewProperties properties=DataViewProperties::createFull())
Definition: cxNavigation.cpp:77
cxBoundingBox3D.h
cxNavigation.h
cxManualTool.h
cx::findEnclosingBoundingBox
DoubleBoundingBox3D findEnclosingBoundingBox(std::vector< DataPtr > data, Transform3D qMr)
Definition: cxVolumeHelpers.cpp:313
cxCameraControl.h
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cxViewService.h
cx::DataPtr
boost::shared_ptr< class Data > DataPtr
Definition: cxRegistrationApplicator.h:22
cx::DataViewProperties
Definition: cxViewGroupData.h:79
cxPatientModelService.h
cx::ImagePtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::Navigation::centerToPosition
void centerToPosition(Vector3D p_r, QFlags< VIEW_TYPE > viewType=vBOTH)
Definition: cxNavigation.cpp:34
cx::CameraControlPtr
boost::shared_ptr< class CameraControl > CameraControlPtr
Definition: cxForwardDeclarations.h:152
cx::Image
A volumetric data set.
Definition: cxImage.h:45
cx::createTransformTranslate
Transform3D createTransformTranslate(const Vector3D &translation)
Definition: cxTransform3D.cpp:164
cx::ActiveDataPtr
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
cx::similar
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
Definition: cxCameraStyleForView.cpp:506
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cxTrackingService.h
cx::Navigation::v3D
@ v3D
Definition: cxNavigation.h:32
cx::Navigation::centerToDataInActiveViewGroup
void centerToDataInActiveViewGroup(DataViewProperties properties=DataViewProperties::createFull())
Definition: cxNavigation.cpp:71
cxVisServices.h