Gaia
frozeneuclideandistance.h
1 /*
2  * Copyright (C) 2006-2013 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Gaia
5  *
6  * Gaia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef GAIA_FROZENEUCLIDEANDISTANCE_H
21 #define GAIA_FROZENEUCLIDEANDISTANCE_H
22 
23 #include "frozendistance.h"
24 
25 namespace gaia2 {
26 
28 public:
29 
30  FrozenEuclideanDistance(const FrozenDataSet& dataset, int offset, int size)
31  : FrozenDistance(dataset), _offset(offset), _size(size) {}
32 
33 
34  FrozenEuclideanDistance(const FrozenDataSet& dataset, const QString& descriptorName)
35  : FrozenDistance(dataset) {
36  init(descriptorName);
37  }
38 
39  FrozenEuclideanDistance(const FrozenDataSet& dataset, const std::string& descriptorName)
40  : FrozenDistance(dataset) {
41  init(QString::fromStdString(descriptorName));
42  }
43 
44  FrozenEuclideanDistance(const FrozenDataSet& dataset, const char* descriptorName)
45  : FrozenDistance(dataset) {
46  init(QString::fromUtf8(descriptorName));
47  }
48 
49  FrozenEuclideanDistance(const FrozenDataSet& dataset, const ParameterMap& params)
50  : FrozenDistance(dataset) {
51 
52  if (params.contains("descriptorName")) {
53  init(params.value("descriptorName"));
54  }
55  else {
56  init(0, dataset.dimension());
57  }
58 
59  }
60 
61  void init(const QString& descriptorName) {
62  validParams << "descriptorName";
63 
64  QPair<int, int> pos = _dataset.descriptorLocation(descriptorName);
65  init(pos.first, pos.second - pos.first);
66  }
67 
68  void init(int offset, int size) {
69  _offset = offset;
70  _size = size;
71  }
72 
73  Real operator()(int i, const FrozenPoint& query) const {
74  return (_dataset.row(i).segment(_offset, _size) - query.segment(_offset, _size)).norm();
75  }
76 
77 protected:
78  int _offset, _size;
79 
80 };
81 
82 
83 } // namespace gaia2
84 
85 #endif // GAIA_FROZENEUCLIDEANDISTANCE_H
Definition: frozendistance.h:33
int dimension() const
Return the number of dimensions of this dataset.
Definition: frozendataset.cpp:36
Definition: frozeneuclideandistance.h:27
Main Gaia namespace, which contains all the library functions.
Definition: addfield.cpp:22
QPair< int, int > descriptorLocation(const QString &descriptorName) const
Return the column indices of beginning and end fo the region spanning the descriptor.
Definition: frozendataset.cpp:181
Definition: parameter.h:34
A FrozenDataSet is a dataset that has been flagged as immutable.
Definition: frozendataset.h:49