Gaia
utils.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_UTILS_H
21 #define GAIA_UTILS_H
22 
23 #include "dataset.h"
24 #include "point.h"
25 #include "pointlayout.h"
26 #include "Eigen/Core"
27 
28 
29 // This file contains some useful functions that were not generic enough to go
30 // inside a class, and that benefit a lot of other classes (most of them are related
31 // to dataset management)
32 
33 namespace gaia2 {
34 
39 inline QString mergeName(const QStringList& name) {
40  return name.join(QString(NAME_SEPARATOR));
41 }
42 
46 inline QStringList splitName(const QString& name, bool includeRootNode = false) {
47  if (includeRootNode) return name.split(NAME_SEPARATOR);
48  return name.split(NAME_SEPARATOR, QString::SkipEmptyParts);
49 }
50 
51 
56 QPair<QString, int> parseDimension(const QString& dimension);
57 
58 
68 void checkIsomorphDataSets(const DataSet* dataset1, const DataSet* dataset2,
69  bool checkOriginalLayout = true);
70 
71 
77 QStringList selectDescriptors(const PointLayout& layout,
78  DescriptorType type = UndefinedType,
79  const QStringList& select = QStringList("*"),
80  const QStringList& exclude = QStringList(),
81  bool failOnUnmatched = true);
82 
83 
84 typedef QList<QPair<Segment, Segment> > IndexMap;
85 
89 void createIndexMappings(const PointLayout& oldLayout,
90  PointLayout& newLayout,
91  const Region& region, IndexMap& realMap,
92  IndexMap& stringMap, IndexMap& enumMap);
93 
94 
98 void transferPointData(const Point* p, Point* result,
99  const IndexMap& realMap, const IndexMap& stringMap,
100  const IndexMap& enumMap);
101 
107 Point* mapPoint(const Point* p, const PointLayout& newLayout,
108  const IndexMap& realMap, const IndexMap& stringMap,
109  const IndexMap& enumMap);
110 
114 RealDescriptor mergeDescriptors(const Point* p, int nseg, const Region& region);
115 
116 
120 PointLayout mergeLayouts(const PointLayout& layout1, const PointLayout& layout2);
121 
126 Point* mergePoints(const Point* ds1, const Point* ds2);
127 
132 DataSet* mergeDataSets(const DataSet* ds1, const DataSet* ds2);
133 
134 
141 QMap<int, QString> mapRegionIndicesToNames(const Region& region,
142  const DataSet* dataset);
143 
150 QList<QPair<double, QString> > dimensionParticipation(const Eigen::VectorXd& values,
151  const QMap<int, QString>& dnames);
152 
157 QList<QPair<double, QString> > dimensionBoost(const Eigen::MatrixXf& featureVector,
158  const Region& region,
159  const DataSet* dataset);
160 
166 QString formatDimensionParticipation(const QList<QPair<double, QString> >& participation,
167  bool ratio = false);
168 
169 
175 QMap<QString, QList<int> > dimensionListToMapping(const QStringList& dims);
176 
181 void setDataStreamVersion(QDataStream& out);
182 
187 void checkValidDataStream(QDataStream& in);
188 
189 enum BinaryFileFormat {
190  Gaia_2_0 = 100,
191  Gaia_2_1 = 101,
192  Gaia_2_3 = 102
193 };
194 
198 int gaiaVersion(const QDataStream& stream);
199 
208 int memoryUsage(QString mtype = "VmSize");
209 
210 } // namespace gaia2
211 
212 #endif // GAIA_UTILS_H
void transferPointData(const Point *p, Point *result, const IndexMap &realMap, const IndexMap &stringMap, const IndexMap &enumMap)
Given a set of mappings, transfers the data from a Point to a new one.
Definition: utils.cpp:207
Definition: descriptor.h:39
A region is a physical location in the point layout which consists in a list of segments.
Definition: region.h:125
QString formatDimensionParticipation(const QList< QPair< double, QString > > &participation, bool ratio)
Formats the results of the dimensionParticipation function into a nicely printable string...
Definition: utils.cpp:594
PointLayout mergeLayouts(const PointLayout &layout1, const PointLayout &layout2)
Merges two PointLayouts together, provided that they don&#39;t overlap.
Definition: utils.cpp:351
Point * mapPoint(const Point *p, const PointLayout &newLayout, const IndexMap &realMap, const IndexMap &stringMap, const IndexMap &enumMap)
Creates a new Point that is a mapping of the given one, copying only those descriptors that are in ne...
Definition: utils.cpp:310
QString mergeName(const QStringList &name)
Utility function that merges a sequence of node names into a single fully-qualified name...
Definition: utils.h:39
Point * mergePoints(const Point *p1, const Point *p2)
Merges two points together, provided that their layout don&#39;t overlap, and return the resulting point...
Definition: utils.cpp:388
QList< QPair< double, QString > > dimensionParticipation(const Eigen::VectorXd &values, const QMap< int, QString > &dnames)
Given a list of values and a map from their indices to their respective names, returns a list of pair...
Definition: utils.cpp:533
This class represents a dataset and all related information.
Definition: dataset.h:91
QList< QPair< double, QString > > dimensionBoost(const Eigen::MatrixXf &featureVector, const Region &region, const DataSet *dataset)
Dimension boost after applying the rotation/scaling defined by the given base vectors.
Definition: utils.cpp:561
QPair< QString, int > parseDimension(const QString &dimension)
Parse a string representing a descriptor + optional dimension as a QPair<QString, int>...
Definition: utils.cpp:32
QStringList splitName(const QString &name, bool includeRootNode=false)
Splits a fully-qualified name into its consecutive node names.
Definition: utils.h:46
This class describes the layout of a point.
Definition: pointlayout.h:60
void setDataStreamVersion(QDataStream &out)
Sets the version of the QDataStream to the current version of Gaia.
Definition: utils.cpp:642
int gaiaVersion(const QDataStream &stream)
Returns the Gaia version of this stream.
Definition: utils.cpp:633
void checkIsomorphDataSets(const DataSet *dataset1, const DataSet *dataset2, bool checkOriginalLayout)
Returns normally if both dataset are isomorph, meaning that they can be linked together, merged together, etc...
Definition: utils.cpp:45
Main Gaia namespace, which contains all the library functions.
Definition: addfield.cpp:22
void createIndexMappings(const PointLayout &oldLayout, PointLayout &newLayout, const Region &region, IndexMap &realMap, IndexMap &stringMap, IndexMap &enumMap)
Creates mappings from indices in the NEW layout to indices in the OLD layout.
Definition: utils.cpp:131
DataSet * mergeDataSets(const DataSet *ds1, const DataSet *ds2)
Merges two datasets together, provided that their layout don&#39;t overlap, and return the resulting data...
Definition: utils.cpp:421
QStringList selectDescriptors(const PointLayout &layout, DescriptorType type, const QStringList &select, const QStringList &exclude, bool failOnUnmatched)
This function returns the region of descriptors from a layout that match the patterns given by the se...
Definition: utils.cpp:90
RealDescriptor mergeDescriptors(const Point *p, int nseg, const Region &region)
Merges the descriptors contained into the given region into a single one.
Definition: utils.cpp:322
DescriptorType
The possible types of descriptors accepted.
Definition: region.h:36
void checkValidDataStream(QDataStream &in)
Checks that the input QDataStream is a valid one (ie: supported by our version of Gaia) and sets its ...
Definition: utils.cpp:658
QMap< int, QString > mapRegionIndicesToNames(const Region &region, const DataSet *dataset)
Given a DataSet (for reference) and a Region, returns the mapping between the region indices and the ...
Definition: utils.cpp:484
QMap< QString, QList< int > > dimensionListToMapping(const QStringList &dims)
Converts a list of dimensions names in the format descriptorName[dim] to a map of descriptor name to ...
Definition: utils.cpp:615
Definition: point.h:106
int memoryUsage(QString mtype)
Returns the memory currently used by this process, in KBs.
Definition: utils.cpp:691