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 //
16 // (C) Idiap Research Institute //
18 // Contact <francois.fleuret@idiap.ch> for comments & bug reports //
19 ///////////////////////////////////////////////////////////////////////////
21 #include "pi_feature_family.h"
23 PiFeatureFamily::PiFeatureFamily() {
28 PiFeatureFamily::~PiFeatureFamily() {
29 delete[] _pi_features;
32 void PiFeatureFamily::read(istream *is) {
33 delete[] _pi_features;
34 read_var(is, &_nb_features);
35 _pi_features = new PiFeature[_nb_features];
36 is->read((char *) _pi_features, sizeof(PiFeature) * _nb_features);
39 void PiFeatureFamily::write(ostream *os) {
40 write_var(os, &_nb_features);
41 os->write((char *) _pi_features, sizeof(PiFeature) * _nb_features);
44 void PiFeatureFamily::resize(int nb_features) {
45 delete[] _pi_features;
46 _nb_features = nb_features;
47 _pi_features = new PiFeature[_nb_features];
50 void PiFeatureFamily::randomize(int level) {
51 for(int f = 0; f < _nb_features; f++) _pi_features[f].randomize(level);
54 void PiFeatureFamily::extract(PiFeatureFamily *pi_feature_family,
55 bool *used_features, int *new_feature_indexes) {
56 delete[] _pi_features;
59 for(int f = 0; f < pi_feature_family->nb_features(); f++)
60 if(used_features[f]) _nb_features++;
62 _pi_features = new PiFeature[_nb_features];
66 for(int f = 0; f < pi_feature_family->nb_features(); f++)
67 if(used_features[f]) {
68 _pi_features[g] = pi_feature_family->_pi_features[f];
69 new_feature_indexes[f] = g;
71 } else new_feature_indexes[f] = -1;