2 ///////////////////////////////////////////////////////////////////////////
3 // This program is free software: you can redistribute it and/or modify //
4 // it under the terms of the version 3 of the GNU General Public License //
5 // as published by the Free Software Foundation. //
7 // This program is distributed in the hope that it will be useful, but //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
10 // General Public License for more details. //
12 // You should have received a copy of the GNU General Public License //
13 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
15 // Written by Francois Fleuret, (C) IDIAP //
16 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
17 ///////////////////////////////////////////////////////////////////////////
19 #include "pi_feature_family.h"
21 PiFeatureFamily::PiFeatureFamily() {
26 PiFeatureFamily::~PiFeatureFamily() {
27 delete[] _pi_features;
30 void PiFeatureFamily::read(istream *is) {
31 delete[] _pi_features;
32 read_var(is, &_nb_features);
33 _pi_features = new PiFeature[_nb_features];
34 is->read((char *) _pi_features, sizeof(PiFeature) * _nb_features);
37 void PiFeatureFamily::write(ostream *os) {
38 write_var(os, &_nb_features);
39 os->write((char *) _pi_features, sizeof(PiFeature) * _nb_features);
42 void PiFeatureFamily::resize(int nb_features) {
43 delete[] _pi_features;
44 _nb_features = nb_features;
45 _pi_features = new PiFeature[_nb_features];
48 void PiFeatureFamily::randomize(int level) {
49 for(int f = 0; f < _nb_features; f++) _pi_features[f].randomize(level);
52 void PiFeatureFamily::extract(PiFeatureFamily *pi_feature_family,
53 bool *used_features, int *new_feature_indexes) {
54 delete[] _pi_features;
57 for(int f = 0; f < pi_feature_family->nb_features(); f++)
58 if(used_features[f]) _nb_features++;
60 _pi_features = new PiFeature[_nb_features];
64 for(int f = 0; f < pi_feature_family->nb_features(); f++)
65 if(used_features[f]) {
66 _pi_features[g] = pi_feature_family->_pi_features[f];
67 new_feature_indexes[f] = g;
69 } else new_feature_indexes[f] = -1;