NorMIT-nav  22.09
An IGT application
cxShapedMetric.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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxShapedMetric.h"
13 
14 #include "cxBoundingBox3D.h"
15 #include "cxTypeConversions.h"
16 #include "cxPatientModelService.h"
17 #include "cxTypeConversions.h"
18 
19 namespace cx
20 {
21 
22 DonutMetric::DonutMetric(const QString& uid, const QString& name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider) :
23  DataMetric(uid, name, dataManager, spaceProvider)
24 {
25  mArguments.reset(new MetricReferenceArgumentList(QStringList() << "position" << "direction"));
26  connect(mArguments.get(), SIGNAL(argumentsChanged()), this, SIGNAL(transformChanged()));
27  mRadius = 5;
28  mThickness = 2;
29  mHeight = 0;
30  mFlat = true;
31 }
32 
33 DonutMetricPtr DonutMetric::create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
34 {
35  return DonutMetricPtr(new DonutMetric(uid, name, dataManager, spaceProvider));
36 }
37 
39 {
40 }
41 
42 void DonutMetric::addXml(QDomNode& dataNode)
43 {
44  DataMetric::addXml(dataNode);
45 
46  mArguments->addXml(dataNode);
47  dataNode.toElement().setAttribute("radius", mRadius);
48  dataNode.toElement().setAttribute("thickness", mThickness);
49  dataNode.toElement().setAttribute("height", mHeight);
50  dataNode.toElement().setAttribute("flat", mFlat);
51 }
52 
53 void DonutMetric::parseXml(QDomNode& dataNode)
54 {
55  DataMetric::parseXml(dataNode);
56 
57  mArguments->parseXml(dataNode, mDataManager->getDatas());
58  mRadius = dataNode.toElement().attribute("radius", qstring_cast(mRadius)).toDouble();
59  mThickness = dataNode.toElement().attribute("thickness", qstring_cast(mThickness)).toDouble();
60  mHeight = dataNode.toElement().attribute("height", qstring_cast(mHeight)).toDouble();
61  mFlat = dataNode.toElement().attribute("flat", qstring_cast(mFlat)).toInt();
62 }
63 
65 {
66  return !mArguments->getRefCoords().empty();
67 }
68 
70 {
71  return mArguments->getRefCoords().front();
72 }
73 
75 {
76  return DoubleBoundingBox3D::fromCloud(mArguments->getRefCoords());
77 }
78 
80 {
81  std::vector<Vector3D> coords = mArguments->getRefCoords();
82  if (coords.empty())
83  return Vector3D::Zero();
84  return coords[0];
85 }
86 
88 {
89  std::vector<Vector3D> coords = mArguments->getRefCoords();
90  if (coords.size()<2)
91  return Vector3D::UnitZ();
92  Vector3D diff = (coords[1]-coords[0]);
93  if (similar(diff.length(), 0.0))
94  return Vector3D(0,1,0);
95  return diff.normal();
96 }
97 
98 void DonutMetric::setRadius(double val)
99 {
100  mRadius = val;
101  emit propertiesChanged();
102 }
103 
105 {
106  return mRadius;
107 }
108 
110 {
111  mThickness = val;
112  emit propertiesChanged();
113 }
114 
116 {
117  return mThickness;
118 }
119 
120 void DonutMetric::setHeight(double val)
121 {
122  mHeight = val;
123  emit propertiesChanged();
124 }
125 
127 {
128  return mHeight;
129 }
130 
131 void DonutMetric::setFlat(bool val)
132 {
133  mFlat = val;
134  emit propertiesChanged();
135 }
136 
138 {
139  return mFlat;
140 }
141 
142 }
qstring_cast
QString qstring_cast(const T &val)
Definition: cxTypeConversions.h:46
cx::DoubleBoundingBox3D
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,...
Definition: cxBoundingBox3D.h:63
cx::DonutMetric::boundingBox
virtual DoubleBoundingBox3D boundingBox() const
Definition: cxShapedMetric.cpp:74
cx::DonutMetric::setFlat
void setFlat(bool val)
Definition: cxShapedMetric.cpp:131
cx::DonutMetric::getFlat
bool getFlat() const
Definition: cxShapedMetric.cpp:137
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::DataMetric::mDataManager
PatientModelServicePtr mDataManager
Definition: cxDataMetric.h:67
cxShapedMetric.h
cx::DonutMetric::parseXml
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxShapedMetric.cpp:53
cx::DonutMetric::setThickness
void setThickness(double val)
Definition: cxShapedMetric.cpp:109
cx::DataMetric::addXml
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxDataMetric.cpp:55
cxBoundingBox3D.h
cx::DonutMetricPtr
boost::shared_ptr< class DonutMetric > DonutMetricPtr
Definition: cxShapedMetric.h:29
cx::DonutMetric::getDirection
Vector3D getDirection()
Definition: cxShapedMetric.cpp:87
cx::DoubleBoundingBox3D::fromCloud
static DoubleBoundingBox3D fromCloud(std::vector< Vector3D > cloud)
Definition: cxBoundingBox3D.cpp:239
cx::DonutMetric::create
static DonutMetricPtr create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
Definition: cxShapedMetric.cpp:33
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cxTypeConversions.h
cxPatientModelService.h
cx::DonutMetric::setRadius
void setRadius(double val)
Definition: cxShapedMetric.cpp:98
cx::DonutMetric::getThickness
double getThickness() const
Definition: cxShapedMetric.cpp:115
cx::DonutMetric
Data class that represents a donut.
Definition: cxShapedMetric.h:40
cx::DonutMetric::getHeight
double getHeight() const
Definition: cxShapedMetric.cpp:126
cx::DonutMetric::getPosition
Vector3D getPosition()
Definition: cxShapedMetric.cpp:79
cx::DonutMetric::getRefCoord
virtual Vector3D getRefCoord() const
Definition: cxShapedMetric.cpp:69
cx::Data::propertiesChanged
void propertiesChanged()
emitted when one of the metadata properties (uid, name etc) changes
cx::DonutMetric::isValid
virtual bool isValid() const
Definition: cxShapedMetric.cpp:64
cx::similar
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
Definition: cxCameraStyleForView.cpp:506
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cx::DataMetric::parseXml
void parseXml(QDomNode &dataNode)
Use a XML node to load data.
Definition: cxDataMetric.cpp:65
cx::DonutMetric::addXml
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Definition: cxShapedMetric.cpp:42
cx::DonutMetric::setHeight
void setHeight(double val)
Definition: cxShapedMetric.cpp:120
cx::DonutMetric::getRadius
double getRadius() const
Definition: cxShapedMetric.cpp:104
cx::SpaceProviderPtr
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
Definition: cxLogicManager.h:23
cx::DonutMetric::~DonutMetric
virtual ~DonutMetric()
Definition: cxShapedMetric.cpp:38