Fraxinus  16.5.0-fx-rc5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxToolImpl.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 "cxToolImpl.h"
34 #include "cxTypeConversions.h"
35 #include "cxLogger.h"
36 
37 namespace cx
38 {
39 
40 ToolImpl::ToolImpl(const QString& uid, const QString& name) :
41  Tool(uid, name),
42  mPositionHistory(new TimedTransformMap()),
43  m_prMt(Transform3D::Identity()),
44  mTooltipOffset(0)
45 {
46 }
47 
49 {
50 
51 }
52 
54 {
55  if (mMetadata.empty())
56  return ToolPositionMetadata();
57  return mMetadata.rbegin()->second;
58 }
59 
60 const std::map<double, ToolPositionMetadata>& ToolImpl::getMetadataHistory()
61 {
62  return mMetadata;
63 }
64 
66 {
67  return mTooltipOffset;
68 }
69 
71 {
72  if (similar(val, mTooltipOffset))
73  return;
74  mTooltipOffset = val;
75  emit tooltipOffset(mTooltipOffset);
76 }
77 
79 {
80  return mPositionHistory;
81 }
82 
83 TimedTransformMap ToolImpl::getSessionHistory(double startTime, double stopTime)
84 {
85  TimedTransformMap::iterator startIt = mPositionHistory->lower_bound(startTime);
86  TimedTransformMap::iterator stopIt = mPositionHistory->upper_bound(stopTime);
87 
88  TimedTransformMap retval(startIt, stopIt);
89  return retval;
90 }
91 
93 {
94  return m_prMt;
95 }
96 
97 void ToolImpl::set_prMt(const Transform3D& prMt, double timestamp)
98 {
99  if (mPositionHistory->count(timestamp))
100  {
101  if (similar(mPositionHistory->find(timestamp)->second, prMt))
102  return;
103  }
104 
105  m_prMt = prMt;
106  (*mPositionHistory)[timestamp] = m_prMt;
107  emit toolTransformAndTimestamp(m_prMt, timestamp);
108 }
109 
111 {
112  mTrackingPositionFilter = filter;
113 }
114 
115 } // namespace cx
116 
TimedTransformMapPtr mPositionHistory
Definition: cxToolImpl.h:75
TrackingPositionFilterPtr mTrackingPositionFilter
Definition: cxToolImpl.h:77
virtual ToolPositionMetadata getMetadata() const
Definition: cxToolImpl.cpp:53
Interface to a tool, i.e. a pointer, US probe or similar.
Definition: cxTool.h:82
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
virtual double getTooltipOffset() const
get a virtual offset extending from the tool tip.
Definition: cxToolImpl.cpp:65
void toolTransformAndTimestamp(Transform3D matrix, double timestamp)
virtual void resetTrackingPositionFilter(TrackingPositionFilterPtr filter)
Definition: cxToolImpl.cpp:110
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
virtual const std::map< double, ToolPositionMetadata > & getMetadataHistory()
Definition: cxToolImpl.cpp:60
virtual TimedTransformMap getSessionHistory(double startTime, double stopTime)
Definition: cxToolImpl.cpp:83
virtual ~ToolImpl()
Definition: cxToolImpl.cpp:48
void tooltipOffset(double offset)
boost::shared_ptr< TimedTransformMap > TimedTransformMapPtr
Definition: cxTool.h:57
virtual TimedTransformMapPtr getPositionHistory()
get historical positions
Definition: cxToolImpl.cpp:78
virtual Transform3D get_prMt() const
Definition: cxToolImpl.cpp:92
std::map< double, ToolPositionMetadata > mMetadata
Definition: cxToolImpl.h:78
virtual void set_prMt(const Transform3D &prMt, double timestamp)
if available for this type, set pos, ts<0 means use current time
Definition: cxToolImpl.cpp:97
virtual void setTooltipOffset(double val)
set a virtual offset extending from the tool tip.
Definition: cxToolImpl.cpp:70
boost::shared_ptr< class TrackingPositionFilter > TrackingPositionFilterPtr
Definition: cxTool.h:58
ToolImpl(const QString &uid="", const QString &name="")
Definition: cxToolImpl.cpp:40
std::map< double, Transform3D > TimedTransformMap
Transform3D m_prMt
the transform from the tool to the patient reference
Definition: cxToolImpl.h:76