#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/PatternRec/DataSet/SampleDiscrete.hh" // This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2001, University of Surrey // This code may be redistributed under the terms of the GNU Lesser // General Public License (LGPL). See the lgpl.licence file for details or // see http://www.gnu.org/copyleft/lesser.html // file-header-ends-here #ifndef RAVL_SAMPLEDISCRETE_HEADER #define RAVL_SAMPLEDISCRETE_HEADER 1 /////////////////////////////////////////////////////////////// //! rcsid="$Id: SampleDiscrete.hh,v 1.3 2002/06/13 18:25:14 craftit Exp $" //! author="Charles Galambos" //! docentry="Ravl.Pattern Recognition.Data Set" //! lib=RavlPatternRec //! file="Ravl/PatternRec/DataSet/SampleDiscrete.hh" #include "Ravl/PatternRec/Sample.hh" #include "Ravl/Histogram.hh" #include "Ravl/DArray1dIter.hh" #include "Ravl/CollectionIter.hh" #include "Ravl/RCHash.hh" namespace RavlN { //! userlevel=Normal //: Sample of discrete objects. template class SampleDiscreteC : public SampleC { public: SampleDiscreteC(SizeT maxSize=10) : SampleC(maxSize) {} //: Create a sample of data with a maximum size SampleDiscreteC(const SArray1dC & dat) : SampleC(dat) {} //: Create a sample of data from an array SampleDiscreteC(const SampleC &sample) : SampleC(sample) {} //: Create from a sample of unsigned integers. HistogramC Histogram() const; //: Compute an occurrence histogram for sample. HistogramC Histogram(const CollectionC &index) const; //: Compute an occurrence histogram of given elements. RCHashC > ListInstancesOfLabels() const; //: List all the instances (by sample no) of each Label in the sample. RCHashC > ListInstancesOfLabels(const CollectionC &index) const; //: List all the instances (by sample no) of each Label in the sample. // If index is set, only search the sample no's given in it. }; template HistogramC SampleDiscreteC::Histogram() const { HistogramC ret; for(DArray1dIterC it(*this);it;it++) ret.Vote(*it); return ret; } template HistogramC SampleDiscreteC::Histogram(const CollectionC &index) const { HistogramC ret; for(CollectionConstIterC it(index);it;it++) ret.Vote((*this)[*it]); return ret; } //: List all the instances (by sample no) of each Label in the sample. // If index is set, only search the sample no's given there. template RCHashC > SampleDiscreteC::ListInstancesOfLabels() const { RCHashC > ret; for(DArray1dIterC it(*this);it;it++) ret[(UIntT) it.Index().V()].Insert(*it); return ret; } //: List all the instances (by sample no) of each Label in the sample. // If index is set, only search the sample no's given there. template RCHashC > SampleDiscreteC::ListInstancesOfLabels(const CollectionC &index) const { RCHashC > ret; for(CollectionConstIterC it(index);it;it++) ret[(*this)[*it]].Insert(*it); return ret; } } #endif