Gaia
transformation.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_TRANSFORMATION_H
21 #define GAIA_TRANSFORMATION_H
22 
23 #include <QList>
24 #include <QString>
25 #include "parameter.h"
26 #include "pointlayout.h"
27 
28 namespace gaia2 {
29 
30 class DataSet;
31 class Point;
32 class Analyzer;
33 class Applier;
34 
42  public:
43  QString name; // necessary? or even used?
44  QString analyzerName; // factory name of the analyzer
45  QString applierName; // factory name of the applier
46  ParameterMap analyzerParams; // parameters for the analysis
47  ParameterMap params; // parameters extracted from the analysis
48 
49  ParameterMap info; // used to pass additional, but not necessary,
50  // info to the user
51 
52  PointLayout layout; // original layout of the analyzed dataset
53 
54  protected:
55  mutable Analyzer* _analyzer; // useless?? maybe not, can contain info such as
56  // variance accountability, etc...
57  mutable Applier* _applier;
58 
59  public:
60  Transformation() :
61  name(""), analyzerName(""), applierName(""),
62  _analyzer(0), _applier(0) {}
63 
64  Transformation(const PointLayout& l) :
65  name(""), analyzerName(""), applierName(""), layout(l),
66  _analyzer(0), _applier(0) {}
67 
68  Transformation(const Transformation& rhs);
69  Transformation& operator=(const Transformation& rhs);
70 
71  bool operator==(const Transformation& rhs) const;
72 
73  ~Transformation();
74 
75  const Analyzer* analyzer() const;
76  const Applier* applier() const;
77 
81  DataSet* applyToDataSet(const DataSet* dataset) const;
82 
87  DataSet* retransformDataSet(const DataSet* dataset) const;
88 
89  Point* applyToPoint(const Point* point) const;
90 
91  void load(const QString& filename);
92  void save(const QString& filename);
93 
98  void updateOldTransformation(int version);
99 
100  // serialization methods
101  friend QDataStream& operator<<(QDataStream& out, const Transformation& transfo);
102  friend QDataStream& operator>>(QDataStream& in, Transformation& transfo);
103 };
104 
105 
106 class TransfoChain : public QList<Transformation> {
107  public:
108 
109  Point* mapPoint(const Point* point, bool takeOwnership = false) const;
110  DataSet* mapDataSet(const DataSet* dataset, bool takeOwnership = false) const;
111 
118  DataSet* partialMapDataSet(const DataSet* dataset, int start, int end = 0) const;
119 
124  DataSet* retransformDataSet(const DataSet* dataset, int start, int end = 0) const;
125 
126  void load(const QString& filename);
127  void save(const QString& filename) const;
128 
129  bool contains(const QString& analyzerName) const;
130 
131  bool operator==(const TransfoChain& rhs) const;
132 
133  // serialization methods
134  friend QDataStream& operator<<(QDataStream& out, const TransfoChain& transfo);
135  friend QDataStream& operator>>(QDataStream& in, TransfoChain& transfo);
136 };
137 
138 
139 DataSet* transform(DataSet* ds, const QString& name, const ParameterMap& params = ParameterMap());
140 
141 DataSet* applyTransfoChain(DataSet* ds, const QString& yamlTransfoChain);
142 
143 inline DataSet* applyTransfoChain(DataSet* ds, const std::string& yamlTransfoChain) {
144  return applyTransfoChain(ds, QString::fromStdString(yamlTransfoChain));
145 }
146 
147 } // namespace gaia2
148 
149 #endif // GAIA_TRANSFORMATION_H
Class containing all info pertaining to a specific transformation, ie: the name of the analyzer class...
Definition: transformation.h:41
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
This class represents a dataset and all related information.
Definition: dataset.h:91
DataSet * retransformDataSet(const DataSet *dataset) const
Redo the full analysis+apply to the given dataset.
Definition: transformation.cpp:77
void updateOldTransformation(int version)
Updates (if necessary) the parameters for this transformation from the specified original version to ...
Definition: transformation.cpp:111
This class describes the layout of a point.
Definition: pointlayout.h:60
Main Gaia namespace, which contains all the library functions.
Definition: addfield.cpp:22
The Applier abstract base class.
Definition: applier.h:44
DataSet * applyToDataSet(const DataSet *dataset) const
Apply the current transformation with its parameters to the DataSet.
Definition: transformation.cpp:81
the Analyzer abstract base class.
Definition: analyzer.h:43
Definition: parameter.h:34
Definition: transformation.h:106
Definition: point.h:106