CustusX  22.04-rc5
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 }
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
QString qstring_cast(const T &val)
virtual DoubleBoundingBox3D boundingBox() const
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
boost::shared_ptr< class DonutMetric > DonutMetricPtr
virtual Vector3D getRefCoord() const
double getThickness() const
static DoubleBoundingBox3D fromCloud(std::vector< Vector3D > cloud)
double getRadius() const
void parseXml(QDomNode &dataNode)
Use a XML node to load data.
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Data class that represents a donut.
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
bool getFlat() const
static DonutMetricPtr create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
virtual ~DonutMetric()
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:42
Vector3D getPosition()
double getHeight() const
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
void setRadius(double val)
void setThickness(double val)
void setHeight(double val)
virtual bool isValid() const
void setFlat(bool val)
Vector3D getDirection()
Namespace for all CustusX production code.