CustusX  15.8
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 
44 namespace cx
45 {
46 
48  mServices(services),
49  mCamera3D(camera3D)
50 {
51 
52 }
53 
54 void Navigation::centerToPosition(Vector3D p_r, QFlags<VIEW_TYPE> viewType)
55 {
56  this->moveManualToolToPosition(p_r);
57 
58  if (viewType.testFlag(v2D))
59  {
60  // set center to calculated position
61  mServices->patientModelService->setCenter(p_r);
62  }
63 
64  if (viewType.testFlag(v3D))
65  {
66  if (mCamera3D)
67  mCamera3D->translateByFocusTo(p_r);
68  }
69 }
70 
73 void Navigation::centerToData(DataPtr image)
74 {
75  if (!image)
76  return;
77  Vector3D p_r = image->get_rMd().coord(image->boundingBox().center());
78 
79  this->centerToPosition(p_r);
80 }
81 
85 void Navigation::centerToData(const std::vector<DataPtr>& images)
86 {
87  Vector3D p_r = findDataCenter(images);
88  this->centerToPosition(p_r);
89 }
90 
92 {
93  ViewGroupDataPtr activeGroup = mServices->visualizationService->getActiveViewGroup();
94  this->centerToDataInViewGroup(activeGroup, properties);
95 }
96 
98 {
99  if(!group)
100  return;
101 
102  std::vector<DataPtr> visibleData = group->getData(properties);
103  if(visibleData.empty())
104  return;
105 
106  ImagePtr activeImage = mServices->patientModelService->getActiveImage();
107  if(activeImage && std::count(visibleData.begin(), visibleData.end(), activeImage))
108  this->centerToData(activeImage);
109  else
110  this->centerToData(visibleData);
111 }
112 
117 {
118  ToolPtr tool = mServices->trackingService->getActiveTool();
119  Vector3D p_pr = tool->get_prMt().coord(Vector3D(0, 0, tool->getTooltipOffset()));
120  Vector3D p_r = mServices->patientModelService->get_rMpr().coord(p_pr);
121 
122  this->centerToPosition(p_r);
123 // // set center to calculated position
124 // mBackend->getDataManager()->setCenter(p_r);
125 }
126 
130 Vector3D Navigation::findDataCenter(const std::vector<DataPtr>& data)
131 {
132  DoubleBoundingBox3D bb_sigma = findEnclosingBoundingBox(data, Transform3D::Identity());
133  return bb_sigma.center();
134 }
135 
136 void Navigation::moveManualToolToPosition(Vector3D& p_r)
137 {
138  // move the manual tool to the same position. (this is a side effect... do we want it?)
139  ToolPtr manual = mServices->trackingService->getManualTool();
140  Vector3D p_pr = mServices->patientModelService->get_rMpr().inv().coord(p_r);
141  Transform3D prM0t = manual->get_prMt(); // modify old pos in order to keep orientation
142  Vector3D t_pr = prM0t.coord(Vector3D(0, 0, manual->getTooltipOffset()));
143  Transform3D prM1t = createTransformTranslate(p_pr - t_pr) * prM0t;
144 
145  if (!similar(prM1t, prM0t))
146  manual->set_prMt(prM1t);
147 // std::cout << "center manual tool" << std::endl;
148 }
149 
150 
151 } // namespace cx
152 
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
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()
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