CustusX  15.3.4-beta
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 "cxCoreServices.h"
35 #include "cxData.h"
36 #include "cxBoundingBox3D.h"
37 #include "cxPatientModelService.h"
38 #include "cxTrackingService.h"
39 #include "cxManualTool.h"
40 #include "cxVolumeHelpers.h"
41 #include "cxCameraControl.h"
42 #include "cxCoreServices.h"
43 
44 namespace cx
45 {
46 
48  mBackend(backend),
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  mBackend->patientModelService->setCenter(p_r);
62  }
63 
64  if (viewType.testFlag(v3D))
65  {
66  if (mCamera3D)
67  mCamera3D->translateByFocusTo(p_r);
68  }
69 }
70 
71 
75 {
76  if (!image)
77  return;
78  Vector3D p_r = image->get_rMd().coord(image->boundingBox().center());
79 
80  this->centerToPosition(p_r);
81 // // set center to calculated position
82 // mBackend->getDataManager()->setCenter(p_r);
83 // this->moveManualToolToPosition(p_r);
84 }
85 
89 void Navigation::centerToView(const std::vector<DataPtr>& images)
90 {
91  Vector3D p_r = findViewCenter(images);
92  std::cout << "center ToView: " << images.size() << " - " << p_r << std::endl;
93 
94  this->centerToPosition(p_r);
95 // // set center to calculated position
96 // mBackend->getDataManager()->setCenter(p_r);
97 // this->moveManualToolToPosition(p_r);
98 }
99 
104 {
105  if (mBackend->patientModelService->getData().empty())
106  return;
107 
108  Vector3D p_r = this->findGlobalDataCenter();
109 
110  this->centerToPosition(p_r);
111 // // set center to calculated position
112 // mBackend->getDataManager()->setCenter(p_r);
113 // this->moveManualToolToPosition(p_r);
114 }
115 
120 {
121  ToolPtr tool = mBackend->trackingService->getActiveTool();
122  Vector3D p_pr = tool->get_prMt().coord(Vector3D(0, 0, tool->getTooltipOffset()));
123  Vector3D p_r = mBackend->patientModelService->get_rMpr().coord(p_pr);
124 
125  this->centerToPosition(p_r);
126 // // set center to calculated position
127 // mBackend->getDataManager()->setCenter(p_r);
128 }
129 
133 Vector3D Navigation::findViewCenter(const std::vector<DataPtr>& images)
134 {
135  return this->findDataCenter(images);
136 }
137 
141 Vector3D Navigation::findGlobalDataCenter()
142 {
143  std::map<QString,DataPtr> images = mBackend->patientModelService->getData();
144  if (images.empty())
145  return Vector3D(0, 0, 0);
146 
147  std::map<QString,DataPtr>::iterator iter;
148  std::vector<DataPtr> dataVector;
149 
150  for (iter = images.begin(); iter != images.end(); ++iter)
151  {
152  dataVector.push_back(iter->second);
153  }
154 // std::cout << "findGlobalDataCenter() " << dataVector.size() << std::endl;
155  return findDataCenter(dataVector);
156 }
157 
161 Vector3D Navigation::findDataCenter(std::vector<DataPtr> data)
162 {
163  DoubleBoundingBox3D bb_sigma = findEnclosingBoundingBox(data, Transform3D::Identity());
164  return bb_sigma.center();
165 }
166 
167 void Navigation::moveManualToolToPosition(Vector3D& p_r)
168 {
169  // move the manual tool to the same position. (this is a side effect... do we want it?)
170  ToolPtr manual = mBackend->trackingService->getManualTool();
171  Vector3D p_pr = mBackend->patientModelService->get_rMpr().inv().coord(p_r);
172  Transform3D prM0t = manual->get_prMt(); // modify old pos in order to keep orientation
173  Vector3D t_pr = prM0t.coord(Vector3D(0, 0, manual->getTooltipOffset()));
174  Transform3D prM1t = createTransformTranslate(p_pr - t_pr) * prM0t;
175 
176  if (!similar(prM1t, prM0t))
177  manual->set_prMt(prM1t);
178 // std::cout << "center manual tool" << std::endl;
179 }
180 
181 
182 } // namespace cx
183 
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
void centerToView(const std::vector< DataPtr > &images)
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)
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:57
void centerToPosition(Vector3D p_r, QFlags< VIEW_TYPE > viewType=vBOTH)
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:59
void centerToData(DataPtr image)
Navigation(CoreServicesPtr backend, CameraControlPtr camera3D=CameraControlPtr())
void centerToGlobalDataCenter()
boost::shared_ptr< class Tool > ToolPtr