Fraxinus  18.10
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 
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:29
Navigation(VisServicesPtr services, CameraControlPtr camera3D=CameraControlPtr())
boost::shared_ptr< class CameraControl > CameraControlPtr
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 Image > ImagePtr
Definition: cxDicomWidget.h:27
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
DoubleBoundingBox3D findEnclosingBoundingBox(std::vector< DataPtr > data, Transform3D qMr)
boost::shared_ptr< class Data > DataPtr
void centerToTooltip()
A volumetric data set.
Definition: cxImage.h:45
Transform3D createTransformTranslate(const Vector3D &translation)
void centerToDataInViewGroup(ViewGroupDataPtr group, DataViewProperties properties=DataViewProperties::createFull())
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
void centerToDataInActiveViewGroup(DataViewProperties properties=DataViewProperties::createFull())
Vector3D center() const
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
void centerToPosition(Vector3D p_r, QFlags< VIEW_TYPE > viewType=vBOTH)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr