+
+///////////////////////////////////////////////////////////////////////////
+// This program is free software: you can redistribute it and/or modify //
+// it under the terms of the version 3 of the GNU General Public License //
+// as published by the Free Software Foundation. //
+// //
+// This program is distributed in the hope that it will be useful, but //
+// WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
+// General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see <http://www.gnu.org/licenses/>. //
+// //
+// Written by Francois Fleuret, (C) IDIAP //
+// Contact <francois.fleuret@idiap.ch> for comments & bug reports //
+///////////////////////////////////////////////////////////////////////////
+
+#include "sample_set.h"
+
+SampleSet::SampleSet(int nb_features, int nb_samples) {
+ _nb_features = nb_features;
+ _nb_samples = nb_samples;
+ _shared_feature_values = new SharedResponses(_nb_features, _nb_samples);
+ _shared_feature_values->grab();
+
+ _labels = new int[_nb_samples];
+ _feature_values = new scalar_t *[_nb_samples];
+ for(int s = 0; s < _nb_samples; s++)
+ _feature_values[s] = _shared_feature_values->_responses + _nb_features * s;
+
+}
+
+SampleSet::SampleSet(SampleSet *father, int nb, int *indexes) {
+ _nb_features = father->_nb_features;
+ _nb_samples = nb;
+ _shared_feature_values = father->_shared_feature_values;
+ _shared_feature_values->grab();
+
+ _labels = new int[_nb_samples];
+ _feature_values = new scalar_t *[_nb_samples];
+ for(int s = 0; s < _nb_samples; s++) {
+ _feature_values[s] = father->_feature_values[indexes[s]];
+ _labels[s] = father->_labels[indexes[s]];
+ }
+}
+
+SampleSet::~SampleSet() {
+ _shared_feature_values->release();
+ delete[] _feature_values;
+ delete[] _labels;
+}
+
+void SampleSet::set_sample(int n,
+ PiFeatureFamily *pi_feature_family,
+ RichImage *image,
+ PoseCell *cell, int label) {
+ ASSERT(n >= 0 && n < _nb_samples);
+ _labels[n] = label;
+ PiReferential referential(cell);
+ for(int f = 0; f < _nb_features; f++) {
+ _feature_values[n][f] = pi_feature_family->get_feature(f)->response(image, &referential);
+ ASSERT(!isnan(_feature_values[n][f]));
+ }
+}