Featuretype.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include <stdlib.h>
  2. #include <assert.h>
  3. #include "vislearning/math/mathbase/Featuretype.h"
  4. using namespace OBJREC;
  5. using namespace NICE;
  6. using namespace std;
  7. FeatureType::FeatureType ( const FeatureType &_ft )
  8. {
  9. sv = _ft.sv;
  10. v = _ft.v;
  11. ft = _ft.ft;
  12. }
  13. FeatureType::FeatureType ( int f, int dim )
  14. {
  15. ft = f;
  16. setDim ( dim );
  17. }
  18. FeatureType::FeatureType ( SparseVector &tsv ) : sv ( tsv )
  19. {
  20. sv = tsv;
  21. ft = SPARSEVECTORFEATURE;
  22. v.clear();
  23. }
  24. FeatureType::FeatureType ( Vector &tv ) //: v(tv)
  25. {
  26. v.resize ( tv.size() );
  27. for ( int i = 0; i < v.size(); i++ )
  28. {
  29. v[i] = tv[i];
  30. }
  31. ft = VECTORFEATURE;
  32. sv.clear();
  33. }
  34. void FeatureType::setDim ( int dim )
  35. {
  36. if ( ft == SPARSEVECTORFEATURE )
  37. {
  38. sv.setDim ( dim );
  39. }
  40. else
  41. {
  42. v.resize ( dim );
  43. }
  44. }
  45. double FeatureType::get ( int pos ) const
  46. {
  47. assert ( pos < getDim() );
  48. if ( ft == SPARSEVECTORFEATURE )
  49. {
  50. return sv.get ( pos );
  51. }
  52. else
  53. {
  54. return v[pos];
  55. }
  56. }
  57. int FeatureType::getType()
  58. {
  59. return ft;
  60. }
  61. int FeatureType::getDim() const
  62. {
  63. if ( ft == SPARSEVECTORFEATURE )
  64. {
  65. return sv.getDim();
  66. }
  67. else
  68. {
  69. return ( int ) v.size();
  70. }
  71. }
  72. const NICE::Vector& FeatureType::getVec() const
  73. {
  74. return v;
  75. }
  76. const SparseVector& FeatureType::getSVec() const
  77. {
  78. return sv;
  79. }