Commit a783d67e08b576676d5b4f616df06a8578531ae8
1 parent
7add2063
IPD metadataTransform
Showing
1 changed file
with
63 additions
and
0 deletions
openbr/plugins/metadata/ipd.cpp
0 → 100644
| 1 | +#include <openbr/plugins/openbr_internal.h> | ||
| 2 | +#include <cmath> | ||
| 3 | + | ||
| 4 | +namespace br | ||
| 5 | +{ | ||
| 6 | + | ||
| 7 | +/*! | ||
| 8 | + * \ingroup transforms | ||
| 9 | + * \brief Calculate interpupillary distance or the distance between two arbitrary points. | ||
| 10 | + * \author Ben Klein \cite bhklein | ||
| 11 | + * \br_property bool named Are the points named? | ||
| 12 | + * \br_property QString firstEye First point's metadata key. | ||
| 13 | + * \br_property QString secondEye Second point's metadata key. | ||
| 14 | + * \br_property QString key Metadata key for distance. | ||
| 15 | + * \br_property QList<int> indices Indices of points in metadata if not named. | ||
| 16 | + */ | ||
| 17 | +class IPDTransform : public UntrainableMetadataTransform | ||
| 18 | +{ | ||
| 19 | + Q_OBJECT | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + Q_PROPERTY(bool named READ get_named WRITE set_named RESET reset_named STORED false) | ||
| 23 | + Q_PROPERTY(QString firstEye READ get_firstEye WRITE set_firstEye RESET reset_firstEye STORED false) | ||
| 24 | + Q_PROPERTY(QString secondEye READ get_secondEye WRITE set_secondEye RESET reset_secondEye STORED false) | ||
| 25 | + Q_PROPERTY(QString key READ get_key WRITE set_key RESET reset_key STORED false) | ||
| 26 | + Q_PROPERTY(QList<int> indices READ get_indices WRITE set_indices RESET reset_indices STORED false) | ||
| 27 | + BR_PROPERTY(bool, named, true) | ||
| 28 | + BR_PROPERTY(QString, firstEye, "First_Eye") | ||
| 29 | + BR_PROPERTY(QString, secondEye, "Second_Eye") | ||
| 30 | + BR_PROPERTY(QString, key, "IPD") | ||
| 31 | + BR_PROPERTY(QList<int>, indices, QList<int>()) | ||
| 32 | + | ||
| 33 | + void projectMetadata(const File &src, File &dst) const | ||
| 34 | + { | ||
| 35 | + dst = src; | ||
| 36 | + if (!indices.empty()) { | ||
| 37 | + if (indices.size() != 2) { | ||
| 38 | + qDebug() << "Indices must be of length 2 to calculate IPD!"; | ||
| 39 | + return; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + QPointF first = src.points()[indices[0]]; | ||
| 43 | + QPointF second = src.points()[indices[1]]; | ||
| 44 | + float distX = second.x() - first.x(); | ||
| 45 | + float distY = second.y() - first.y(); | ||
| 46 | + float distance = std::sqrt(distX*distX + distY*distY); | ||
| 47 | + dst.set(key, distance); | ||
| 48 | + } else { | ||
| 49 | + QPointF first = src.get<QPointF>(firstEye, QPointF()); | ||
| 50 | + QPointF second = src.get<QPointF>(secondEye, QPointF()); | ||
| 51 | + float distX = second.x() - first.x(); | ||
| 52 | + float distY = second.y() - first.y(); | ||
| 53 | + float distance = std::sqrt(distX*distX + distY*distY); | ||
| 54 | + dst.set(key, distance); | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | +}; | ||
| 58 | + | ||
| 59 | +BR_REGISTER(Transform, IPDTransform) | ||
| 60 | + | ||
| 61 | +} // namespace br | ||
| 62 | + | ||
| 63 | +#include "metadata/ipd.moc" |