Commit 2fee7df6549b4612cf2891cf5c7d614332711a7e

Authored by Scott Klum
1 parent c01caf17

Added ListDistance

openbr/plugins/distance/fuse.cpp
... ... @@ -29,11 +29,10 @@ namespace br
29 29 * \author Scott Klum \cite sklum
30 30 * \note Operation: Mean, sum, min, max are supported.
31 31 */
32   -class FuseDistance : public Distance
  32 +class FuseDistance : public ListDistance
33 33 {
34 34 Q_OBJECT
35 35 Q_ENUMS(Operation)
36   - Q_PROPERTY(QList<br::Distance*> distances READ get_distances WRITE set_distances RESET reset_distances)
37 36 Q_PROPERTY(Operation operation READ get_operation WRITE set_operation RESET reset_operation STORED false)
38 37 Q_PROPERTY(QList<float> weights READ get_weights WRITE set_weights RESET reset_weights STORED false)
39 38  
... ... @@ -42,18 +41,9 @@ public:
42 41 enum Operation {Mean, Sum, Max, Min};
43 42  
44 43 private:
45   - BR_PROPERTY(QList<br::Distance*>, distances, QList<br::Distance*>())
46 44 BR_PROPERTY(Operation, operation, Mean)
47 45 BR_PROPERTY(QList<float>, weights, QList<float>())
48 46  
49   - bool trainable()
50   - {
51   - for (int i=0; i<distances.size(); i++)
52   - if (distances[i]->trainable())
53   - return true;
54   - return false;
55   - }
56   -
57 47 void train(const TemplateList &src)
58 48 {
59 49 // Partition the templates by matrix
... ...
openbr/plugins/distance/pipe.cpp
... ... @@ -30,19 +30,9 @@ namespace br
30 30 * If the result of the comparison with any given distance is -FLOAT_MAX then this result is returned early.
31 31 * Otherwise the returned result is the value of comparing the templates using the last br::Distance.
32 32 */
33   -class PipeDistance : public Distance
  33 +class PipeDistance : public ListDistance
34 34 {
35 35 Q_OBJECT
36   - Q_PROPERTY(QList<br::Distance*> distances READ get_distances WRITE set_distances RESET reset_distances)
37   - BR_PROPERTY(QList<br::Distance*>, distances, QList<br::Distance*>())
38   -
39   - bool trainable()
40   - {
41   - for (int i=0; i<distances.size(); i++)
42   - if (distances[i]->trainable())
43   - return true;
44   - return false;
45   - }
46 36  
47 37 void train(const TemplateList &data)
48 38 {
... ...
openbr/plugins/distance/sum.cpp
... ... @@ -26,19 +26,9 @@ namespace br
26 26 * \brief Sum match scores across multiple distances
27 27 * \author Scott Klum \cite sklum
28 28 */
29   -class SumDistance : public Distance
  29 +class SumDistance : public ListDistance
30 30 {
31 31 Q_OBJECT
32   - Q_PROPERTY(QList<br::Distance*> distances READ get_distances WRITE set_distances RESET reset_distances)
33   - BR_PROPERTY(QList<br::Distance*>, distances, QList<br::Distance*>())
34   -
35   - bool trainable()
36   - {
37   - for (int i=0; i<distances.size(); i++)
38   - if (distances[i]->trainable())
39   - return true;
40   - return false;
41   - }
42 32  
43 33 void train(const TemplateList &data)
44 34 {
... ...
openbr/plugins/openbr_internal.h
... ... @@ -485,6 +485,26 @@ private:
485 485 void train(const TemplateList &data) { (void) data; }
486 486 };
487 487  
  488 +/*!
  489 + * \brief A br::Distance that does not require training data.
  490 + */
  491 +class BR_EXPORT ListDistance : public Distance
  492 +{
  493 + Q_OBJECT
  494 +
  495 +public:
  496 + Q_PROPERTY(QList<br::Distance*> distances READ get_distances WRITE set_distances RESET reset_distances)
  497 + BR_PROPERTY(QList<br::Distance*>, distances, QList<br::Distance*>())
  498 +
  499 + bool trainable()
  500 + {
  501 + for (int i=0; i<distances.size(); i++)
  502 + if (distances[i]->trainable())
  503 + return true;
  504 + return false;
  505 + }
  506 +};
  507 +
488 508 }
489 509  
490 510 #endif // OPENBR_INTERNAL_H
... ...