NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 "cxNavigation.h"
34 #include "cxImage.h"
35 #include "cxBoundingBox3D.h"
36 #include "cxPatientModelService.h"
37 #include "cxTrackingService.h"
38 #include "cxManualTool.h"
39 #include "cxVolumeHelpers.h"
40 #include "cxCameraControl.h"
41 #include "cxVisServices.h"
42 #include "cxViewService.h"
43 #include "cxActiveData.h"
44 
45 namespace cx
46 {
47 
49  mServices(services),
50  mCamera3D(camera3D)
51 {
52 
53 }
54 
55 void Navigation::centerToPosition(Vector3D p_r, QFlags<VIEW_TYPE> viewType)
56 {
57  this->moveManualToolToPosition(p_r);
58 
59  if (viewType.testFlag(v2D))
60  {
61  // set center to calculated position
62  mServices->patient()->setCenter(p_r);
63  }
64 
65  if (viewType.testFlag(v3D))
66  {
67  if (mCamera3D)
68  mCamera3D->translateByFocusTo(p_r);
69  }
70 }
71 
74 void Navigation::centerToData(DataPtr image)
75 {
76  if (!image)
77  return;
78  Vector3D p_r = image->get_rMd().coord(image->boundingBox().center());
79 
80  this->centerToPosition(p_r);
81 }
82 
86 void Navigation::centerToData(const std::vector<DataPtr>& images)
87 {
88  Vector3D p_r = findDataCenter(images);
89  this->centerToPosition(p_r);
90 }
91 
93 {
94  ViewGroupDataPtr activeGroup = mServices->view()->getActiveViewGroup();
95  this->centerToDataInViewGroup(activeGroup, properties);
96 }
97 
99 {
100  if(!group)
101  return;
102 
103  std::vector<DataPtr> visibleData = group->getData(properties);
104  if(visibleData.empty())
105  return;
106 
107  ActiveDataPtr active = mServices->patient()->getActiveData();
108  ImagePtr activeImage = active->getActive<Image>();
109  if(activeImage && std::count(visibleData.begin(), visibleData.end(), activeImage))
110  this->centerToData(activeImage);
111  else
112  this->centerToData(visibleData);
113 }
114 
119 {
120  ToolPtr tool = mServices->tracking()->getActiveTool();
121  Vector3D p_pr = tool->get_prMt().coord(Vector3D(0, 0, tool->getTooltipOffset()));
122  Vector3D p_r = mServices->patient()->get_rMpr().coord(p_pr);
123 
124  this->centerToPosition(p_r);
125 // // set center to calculated position
126 // mBackend->getDataManager()->setCenter(p_r);
127 }
128 
132 Vector3D Navigation::findDataCenter(const std::vector<DataPtr>& data)
133 {
134  DoubleBoundingBox3D bb_sigma = findEnclosingBoundingBox(data, Transform3D::Identity());
135  return bb_sigma.center();
136 }
137 
138 void Navigation::moveManualToolToPosition(Vector3D& p_r)
139 {
140  // move the manual tool to the same position. (this is a side effect... do we want it?)
141  ToolPtr manual = mServices->tracking()->getManualTool();
142  Vector3D p_pr = mServices->patient()->get_rMpr().inv().coord(p_r);
143  Transform3D prM0t = manual->get_prMt(); // modify old pos in order to keep orientation
144  Vector3D t_pr = prM0t.coord(Vector3D(0, 0, manual->getTooltipOffset()));
145  Transform3D prM1t = createTransformTranslate(p_pr - t_pr) * prM0t;
146 
147  if (!similar(prM1t, prM0t))
148  manual->set_prMt(prM1t);
149 // std::cout << "center manual tool" << std::endl;
150 }
151 
152 
153 } // namespace cx
154 
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:50
Navigation(VisServicesPtr services, CameraControlPtr camera3D=CameraControlPtr())
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:42
DoubleBoundingBox3D findEnclosingBoundingBox(std::vector< DataPtr > data, Transform3D qMr)
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
boost::shared_ptr< class Data > DataPtr
void centerToTooltip()
A volumetric data set.
Definition: cxImage.h:66
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:63
boost::shared_ptr< class CameraControl > CameraControlPtr
Definition: cxMainWindow.h:58
void centerToDataInActiveViewGroup(DataViewProperties properties=DataViewProperties::createFull())
Vector3D center() const
void centerToPosition(Vector3D p_r, QFlags< VIEW_TYPE > viewType=vBOTH)
boost::shared_ptr< class Tool > ToolPtr