25 DataMetric(uid, name, dataManager, spaceProvider)
27 mArguments.reset(
new MetricReferenceArgumentList(QStringList() <<
"line endpoint 0" <<
"line endpoint 1"));
30 connect(mArguments.get(), SIGNAL(argumentsChanged()),
this, SLOT(resetCachedValues()));
31 connect(mArguments.get(), SIGNAL(argumentsChanged()),
this, SIGNAL(transformChanged()));
39 DistanceMetric::~DistanceMetric()
45 return this->boundingBox().center();
48 bool DistanceMetric::isValid()
const
50 return this->getEndpoints().size()==2;
53 void DistanceMetric::addXml(QDomNode& dataNode)
55 DataMetric::addXml(dataNode);
56 mArguments->addXml(dataNode);
59 void DistanceMetric::parseXml(QDomNode& dataNode)
61 DataMetric::parseXml(dataNode);
63 mArguments->parseXml(dataNode, mDataManager->getDatas());
64 this->resetCachedValues();
67 void DistanceMetric::resetCachedValues()
69 mCachedEndPoints.reset();
72 std::vector<Vector3D> DistanceMetric::getEndpoints()
const
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::getTypeName()) && (a1->getType() == PointMetric::getTypeName()))
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::getTypeName()) && (a1->getType() == PointMetric::getTypeName()))
115 Plane3D plane = boost::dynamic_pointer_cast<PlaneMetric>(a0)->getRefPlane();
116 Vector3D p = boost::dynamic_pointer_cast<PointMetric>(a1)->getRefCoord();
118 retval[0] = plane.projection(p);
120 dir = plane.normal();
122 else if ((a0->getType() == PointMetric::getTypeName()) && (a1->getType() == PlaneMetric::getTypeName()))
124 Plane3D plane = boost::dynamic_pointer_cast<PlaneMetric>(a1)->getRefPlane();
125 Vector3D p = boost::dynamic_pointer_cast<PointMetric>(a0)->getRefCoord();
127 retval[1] = plane.projection(p);
129 dir = plane.normal();
140 double DistanceMetric::getDistance()
const
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();
157 QString DistanceMetric::getValueAsString()
const
159 return QString(
"%1 mm").arg(this->getDistance(), 0,
'f', 1);
164 return DoubleBoundingBox3D::fromCloud(this->getEndpoints());