NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxSphereMetric.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 "cxSphereMetric.h"
34 
35 #include "cxBoundingBox3D.h"
36 #include "cxTypeConversions.h"
37 #include "cxPatientModelService.h"
38 
39 namespace cx
40 {
41 
42 SphereMetric::SphereMetric(const QString& uid, const QString& name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider) :
43  DataMetric(uid, name, dataManager, spaceProvider)
44 {
45  mArguments.reset(new MetricReferenceArgumentList(QStringList() << "position"));
46  connect(mArguments.get(), SIGNAL(argumentsChanged()), this, SIGNAL(transformChanged()));
47  mRadius = 5;
48 }
49 
50 SphereMetricPtr SphereMetric::create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
51 {
52  return SphereMetricPtr(new SphereMetric(uid, name, dataManager, spaceProvider));
53 }
54 
56 {
57 }
58 
59 void SphereMetric::addXml(QDomNode& dataNode)
60 {
61  DataMetric::addXml(dataNode);
62  mArguments->addXml(dataNode);
63  dataNode.toElement().setAttribute("radius", mRadius);
64 }
65 
66 void SphereMetric::parseXml(QDomNode& dataNode)
67 {
68  DataMetric::parseXml(dataNode);
69 
70  mArguments->parseXml(dataNode, mDataManager->getData());
71  mRadius = dataNode.toElement().attribute("radius", qstring_cast(mRadius)).toDouble();
72 }
73 
75 {
76  return !mArguments->getRefCoords().empty();
77 }
78 
80 {
81  return this->boundingBox().center();
82 }
83 
85 {
86  return DoubleBoundingBox3D::fromCloud(mArguments->getRefCoords());
87 }
88 
90 {
91  return QString("%1 %2")
92  .arg(this->getSingleLineHeader())
93  .arg(this->getRadius(), 0, 'f', 1);
94 }
95 
96 void SphereMetric::setRadius(double val)
97 {
98  mRadius = val;
99  emit propertiesChanged();
100 }
101 
103 {
104  return mRadius;
105 }
106 
108 {
109  return QString("%1").arg(this->getRadius(), 0, 'f', 1);
110 }
111 
112 }
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
QString qstring_cast(const T &val)
void setRadius(double val)
virtual QString getValueAsString() const
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
void propertiesChanged()
emitted when one of the metadata properties (uid, name etc) changes
void transformChanged()
emitted when transform is changed
boost::shared_ptr< class SphereMetric > SphereMetricPtr
virtual QString getAsSingleLineString() const
PatientModelServicePtr mDataManager
Definition: cxDataMetric.h:88
static DoubleBoundingBox3D fromCloud(std::vector< Vector3D > cloud)
virtual DoubleBoundingBox3D boundingBox() const
Data class that represents a donut.
static SphereMetricPtr create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
void parseXml(QDomNode &dataNode)
Use a XML node to load data.
virtual void parseXml(QDomNode &dataNode)
Use a XML node to load data.
virtual ~SphereMetric()
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
QString getSingleLineHeader() const
virtual bool isValid() const
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.
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
Vector3D center() const
double getRadius() const
virtual Vector3D getRefCoord() const
virtual void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels