46 DataMetric(uid, name, dataManager, spaceProvider)
48 mArguments.reset(
new MetricReferenceArgumentList(QStringList() <<
"line endpoint 0" <<
"line endpoint 1"));
49 mArguments->setValidArgumentTypes(QStringList() <<
"pointMetric" <<
"planeMetric");
51 connect(mArguments.get(), SIGNAL(argumentsChanged()),
this, SLOT(resetCachedValues()));
52 connect(mArguments.get(), SIGNAL(argumentsChanged()),
this, SIGNAL(transformChanged()));
66 return this->boundingBox().center();
71 return this->getEndpoints().size()==2;
77 mArguments->addXml(dataNode);
84 mArguments->parseXml(dataNode, mDataManager->getDatas());
85 this->resetCachedValues();
88 void DistanceMetric::resetCachedValues()
90 mCachedEndPoints.reset();
96 return mCachedEndPoints.get();
99 void DistanceMetric::updateCache()
const 101 if (!mCachedEndPoints.isValid())
103 std::vector<Vector3D> endpoints;
105 this->getEndpointsUncached(&endpoints, &direction);
106 mCachedEndPoints.set(endpoints);
107 mCachedDirection.set(direction);
111 void DistanceMetric::getEndpointsUncached(std::vector<Vector3D> *endpoints,
Vector3D* direction)
const 113 DataPtr a0 = mArguments->get(0);
114 DataPtr a1 = mArguments->get(1);
121 std::vector<Vector3D> retval(2);
128 if ((a0->getType() ==
"pointMetric") && (a1->getType() ==
"pointMetric"))
130 retval[0] = boost::dynamic_pointer_cast<
PointMetric>(a0)->getRefCoord();
131 retval[1] = boost::dynamic_pointer_cast<PointMetric>(a1)->getRefCoord();
132 dir = (retval[1] - retval[0]).
normal();
134 else if ((a0->getType() ==
"planeMetric") && (a1->getType() ==
"pointMetric"))
139 retval[0] = plane.projection(p);
141 dir = plane.normal();
143 else if ((a0->getType() ==
"pointMetric") && (a1->getType() ==
"planeMetric"))
148 retval[1] = plane.projection(p);
150 dir = plane.normal();
163 std::vector<Vector3D> endpoints = this->getEndpoints();
164 if (endpoints.size() != 2)
167 Vector3D dir = this->getDirection();
169 return dot(endpoints[1] - endpoints[0], dir);
175 return mCachedDirection.get();
180 return QString(
"%1 mm").arg(this->getDistance(), 0,
'f', 1);
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
virtual ~DistanceMetric()
Vector3D getDirection() const
boost::shared_ptr< class DistanceMetric > DistanceMetricPtr
static DistanceMetricPtr create(QString uid, QString name, PatientModelServicePtr dataManager, SpaceProviderPtr spaceProvider)
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
PlainObject normal() const
virtual DoubleBoundingBox3D boundingBox() const
Data class representing a plane.
virtual QString getValueAsString() const
static DoubleBoundingBox3D fromCloud(std::vector< Vector3D > cloud)
boost::shared_ptr< class Data > DataPtr
void parseXml(QDomNode &dataNode)
Use a XML node to load data.
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
virtual Vector3D getRefCoord() const
double dot(const Vector3D &a, const Vector3D &b)
compute inner product (or dot product) of a and b.
Data class that represents a distance between two points, or a point and a plane. ...
double getDistance() 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.
std::vector< Vector3D > getEndpoints() const
return the two endpoints in reference space. None if invalid.
Data class that represents a single point.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
virtual 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
virtual bool isValid() const
Namespace for all CustusX production code.