Commit 616ec701210c0f99b1c15ea8f8673579ee330aba
1 parent
cadd9f8c
Add a transform for logging nearest-neighbor data.
Showing
1 changed file
with
44 additions
and
0 deletions
openbr/plugins/cluster.cpp
| @@ -242,6 +242,50 @@ class CollectNNTransform : public UntrainableMetaTransform | @@ -242,6 +242,50 @@ class CollectNNTransform : public UntrainableMetaTransform | ||
| 242 | }; | 242 | }; |
| 243 | BR_REGISTER(Transform, CollectNNTransform) | 243 | BR_REGISTER(Transform, CollectNNTransform) |
| 244 | 244 | ||
| 245 | +class LogNNTransform : public TimeVaryingTransform | ||
| 246 | +{ | ||
| 247 | + Q_OBJECT | ||
| 248 | + | ||
| 249 | + Q_PROPERTY(QString fileName READ get_fileName WRITE set_fileName RESET reset_fileName STORED false) | ||
| 250 | + BR_PROPERTY(QString, fileName, "") | ||
| 251 | + | ||
| 252 | + QFile out; | ||
| 253 | + void projectUpdate(const Template &src, Template &dst) | ||
| 254 | + { | ||
| 255 | + dst = src; | ||
| 256 | + | ||
| 257 | + Neighbors neighbors = dst.file.get<Neighbors>("neighbors"); | ||
| 258 | + if (neighbors.isEmpty() ) | ||
| 259 | + return; | ||
| 260 | + | ||
| 261 | + QString aLine; | ||
| 262 | + aLine.append(QString::number(neighbors[0].first)+":"+QString::number(neighbors[0].second)); | ||
| 263 | + for (int i=1; i < neighbors.size();i++) | ||
| 264 | + aLine.append(","+QString::number(neighbors[i].first)+":"+QString::number(neighbors[i].second)); | ||
| 265 | + | ||
| 266 | + aLine += "\n"; | ||
| 267 | + out.write(qPrintable(aLine)); | ||
| 268 | + } | ||
| 269 | + | ||
| 270 | + void init() | ||
| 271 | + { | ||
| 272 | + if (!fileName.isEmpty()) { | ||
| 273 | + out.setFileName(fileName); | ||
| 274 | + out.open(QIODevice::WriteOnly); | ||
| 275 | + } | ||
| 276 | + } | ||
| 277 | + | ||
| 278 | + void finalize(TemplateList &output) | ||
| 279 | + { | ||
| 280 | + (void) output; | ||
| 281 | + out.close(); | ||
| 282 | + } | ||
| 283 | + | ||
| 284 | +public: | ||
| 285 | + LogNNTransform() : TimeVaryingTransform(false, false) {} | ||
| 286 | +}; | ||
| 287 | +BR_REGISTER(Transform, LogNNTransform) | ||
| 288 | + | ||
| 245 | } // namespace br | 289 | } // namespace br |
| 246 | 290 | ||
| 247 | #include "cluster.moc" | 291 | #include "cluster.moc" |