25 DataMetric(uid, name, dataManager, spaceProvider)
27 mArguments.reset(
new MetricReferenceArgumentList(QStringList() <<
"line endpoint 0" <<
"line endpoint 1"));
28 mArguments->setValidArgumentTypes(QStringList() <<
"pointMetric" <<
"planeMetric");
30 connect(mArguments.get(), SIGNAL(argumentsChanged()),
this, SLOT(resetCachedValues()));
31 connect(mArguments.get(), SIGNAL(argumentsChanged()),
this, SIGNAL(transformChanged()));
45 return this->boundingBox().center();
50 return this->getEndpoints().size()==2;
56 mArguments->addXml(dataNode);
63 mArguments->parseXml(dataNode, mDataManager->getDatas());
64 this->resetCachedValues();
67 void DistanceMetric::resetCachedValues()
69 mCachedEndPoints.reset();
75 return mCachedEndPoints.get();
78 void DistanceMetric::updateCache()
const 80 if (!mCachedEndPoints.isValid())
82 std::vector<Vector3D> endpoints;
84 this->getEndpointsUncached(&endpoints, &direction);
85 mCachedEndPoints.set(endpoints);
86 mCachedDirection.set(direction);
90 void DistanceMetric::getEndpointsUncached(std::vector<Vector3D> *endpoints,
Vector3D* direction)
const 92 DataPtr a0 = mArguments->get(0);
93 DataPtr a1 = mArguments->get(1);
100 std::vector<Vector3D> retval(2);
107 if ((a0->getType() ==
"pointMetric") && (a1->getType() ==
"pointMetric"))
109 retval[0] = boost::dynamic_pointer_cast<
PointMetric>(a0)->getRefCoord();
110 retval[1] = boost::dynamic_pointer_cast<PointMetric>(a1)->getRefCoord();
111 dir = (retval[1] - retval[0]).
normal();
113 else if ((a0->getType() ==
"planeMetric") && (a1->getType() ==
"pointMetric"))
118 retval[0] = plane.projection(p);
120 dir = plane.normal();
122 else if ((a0->getType() ==
"pointMetric") && (a1->getType() ==
"planeMetric"))
127 retval[1] = plane.projection(p);
129 dir = plane.normal();
142 std::vector<Vector3D> endpoints = this->getEndpoints();
143 if (endpoints.size() != 2)
146 Vector3D dir = this->getDirection();
148 return dot(endpoints[1] - endpoints[0], dir);
154 return mCachedDirection.get();
159 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.