123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #include <stdlib.h>
- #include <assert.h>
- #include "vislearning/math/mathbase/Featuretype.h"
- using namespace OBJREC;
- using namespace NICE;
- using namespace std;
- FeatureType::FeatureType(const FeatureType &_ft)
- {
- sv = _ft.sv;
- v = _ft.v;
- ft = _ft.ft;
- }
- FeatureType::FeatureType(int f, int dim)
- {
- ft = f;
- setDim(dim);
- }
- FeatureType::FeatureType(SparseVector &tsv) : sv(tsv)
- {
- sv = tsv;
- ft = SPARSEVECTORFEATURE;
- v.clear();
- }
- FeatureType::FeatureType(Vector &tv) //: v(tv)
- {
- v.resize(tv.size());
- for(int i = 0; i < v.size(); i++)
- {
- v[i] = tv[i];
- }
- ft = VECTORFEATURE;
- sv.clear();
- }
-
- void FeatureType::setDim(int dim)
- {
- if(ft == SPARSEVECTORFEATURE)
- {
- sv.setDim(dim);
- }
- else
- {
- v.resize(dim);
- }
- }
-
- double FeatureType::get(int pos) const
- {
- assert(pos < getDim());
- if(ft == SPARSEVECTORFEATURE)
- {
- return sv.get(pos);
- }
- else
- {
- return v[pos];
- }
- }
-
- int FeatureType::getType()
- {
- return ft;
- }
- int FeatureType::getDim() const
- {
- if(ft == SPARSEVECTORFEATURE)
- {
- return sv.getDim();
- }
- else
- {
- return (int)v.size();
- }
- }
-
- const NICE::Vector& FeatureType::getVec() const
- {
- return v;
- }
- const SparseVector& FeatureType::getSVec() const
- {
- return sv;
- }
|