Fraxinus  16.5.0-fx-rc1
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxToolMetric.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 "cxToolMetric.h"
34 #include "cxTool.h"
35 #include "cxTypeConversions.h"
36 
37 namespace cx
38 {
39 
40 //DataPtr ToolMetricReader::load(const QString& uid, const QString& filename)
41 //{
42 // return DataPtr(new ToolMetric(uid, filename));
43 //}
44 
46 {
47  return ToolMetricPtr(new ToolMetric(uid, name, dataManager, spaceProvider));
48 }
49 
50 //ToolMetricPtr ToolMetric::create(QDomNode node)
51 //{
52 // ToolMetricPtr retval = ToolMetric::create("");
53 // retval->parseXml(node);
54 // return retval;
55 //}
56 
57 ToolMetric::ToolMetric(const QString& uid, const QString& name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider) :
58  cx::FrameMetricBase(uid, name, dataManager, spaceProvider),
59  mToolOffset(0.0)
60 {
61 }
62 
64 {
65 }
66 
68 {
69  return mToolOffset;
70 }
71 
72 void ToolMetric::setToolOffset(double val)
73 {
74  mToolOffset = val;
75  emit propertiesChanged();
76 }
77 
78 QString ToolMetric::getToolName() const
79 {
80  return mToolName;
81 }
82 
83 void ToolMetric::setToolName(const QString& val)
84 {
85  mToolName = val;
86  emit propertiesChanged();
87 }
88 
89 void ToolMetric::addXml(QDomNode& dataNode)
90 {
91  DataMetric::addXml(dataNode);
92 
93  dataNode.toElement().setAttribute("space", mSpace.toString());
94  dataNode.toElement().setAttribute("frame", qstring_cast(mFrame));
95 
96  dataNode.toElement().setAttribute("toolname", mToolName);
97  dataNode.toElement().setAttribute("tooloffset", qstring_cast(mToolOffset));
98 }
99 
100 void ToolMetric::parseXml(QDomNode& dataNode)
101 {
102  DataMetric::parseXml(dataNode);
103 
104  this->setSpace(CoordinateSystem::fromString(dataNode.toElement().attribute("space", mSpace.toString())));
105  this->setFrame(Transform3D::fromString(dataNode.toElement().attribute("frame", qstring_cast(mFrame))));
106  this->setToolName(dataNode.toElement().attribute("toolname", mToolName));
107  this->setToolOffset(dataNode.toElement().attribute("tooloffset", qstring_cast(mToolOffset)).toDouble());
108 }
109 
111 {
112  return QString("%1 \"%2\" %3 \"%4\" %5")
113  .arg(this->getSingleLineHeader())
114  .arg(mToolName)
115  .arg(mToolOffset)
116  .arg(mSpace.toString())
117  .arg(this->matrixAsSingleLineString());
118 }
119 
120 } //namespace cx
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
QString qstring_cast(const T &val)
virtual void setFrame(const Transform3D &qMt)
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
boost::shared_ptr< class ToolMetric > ToolMetricPtr
Definition: cxToolMetric.h:45
CoordinateSystem mSpace
void propertiesChanged()
emitted when one of the metadata properties (uid, name etc) changes
QString getToolName() const
virtual void setSpace(CoordinateSystem space)
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
QString matrixAsSingleLineString() const
static ToolMetricPtr create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Abstract base class for frame metric.
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
QString getSingleLineHeader() const
void setToolName(const QString &val)
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
virtual ~ToolMetric()
double getToolOffset() const
virtual QString getAsSingleLineString() const
void setToolOffset(double val)
static CoordinateSystem fromString(QString text)
Transform3D mFrame
frame qFt described in local space q = mSpace