VVector.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @file VVector.h
  3. * @brief vector of vector
  4. * @author Erik Rodner
  5. * @date 02/15/2008
  6. */
  7. #ifndef VVECTORINCLUDE
  8. #define VVECTORINCLUDE
  9. #include <vector>
  10. #include <ostream>
  11. #include "VectorT.h"
  12. #include "MatrixT.h"
  13. #include "core/basics/Persistent.h"
  14. namespace NICE {
  15. /** STL vector of NICE vectors */
  16. class VVector : public std::vector<NICE::Vector>, public Persistent
  17. {
  18. protected:
  19. size_t bufsize;
  20. bool ioUntilEndOfFile;
  21. public:
  22. /** possible file formats */
  23. enum {
  24. /** use standard NICE vector I/O */
  25. FILEFORMAT_NICE = 0,
  26. FILEFORMAT_LINE,
  27. /** write binary double values, use this for large-scale datasets */
  28. FILEFORMAT_BINARY_DOUBLE,
  29. /** write values as unsigned char, be careful with truncation */
  30. FILEFORMAT_BINARY_CHAR
  31. };
  32. /** simple constructor */
  33. VVector();
  34. VVector( const std::string & filename );
  35. /**
  36. * constructor creates $count NICE::Vectors of size dim
  37. * @param count number of vectors
  38. * @param dim size of each Vector
  39. */
  40. VVector( int count, int dim);
  41. /**
  42. * resizes the VVector and clear everything
  43. * @param count number of vectors
  44. * @param dim size of each Vector
  45. */
  46. void reSize(int count, int dim);
  47. /** simple destructor */
  48. virtual ~VVector();
  49. virtual void clear ();
  50. virtual void restore ( std::istream & is, int format = 0 );
  51. virtual void store ( std::ostream & os, int format = 0 ) const;
  52. void setBufSize ( size_t bufsize );
  53. void sort ( size_t index );
  54. /** convert this data structure to a non-dynamic nice matrix
  55. * @param dst the destination matrix (will be resized)
  56. * @param rowOriented if true (std) the elements of VVector (of type NICE::Vector)
  57. * are stored as rows in the resulting matrix (otherwise as columns)
  58. * */
  59. void toMatrix ( NICE::Matrix & dst, bool rowOriented = true ) const;
  60. inline void print (std::ostream& output)
  61. {
  62. if (this->size() > 0)
  63. {
  64. output << this->size() << " x " << (*this)[0].size() << std::endl;
  65. for (size_t r = 0; r < this->size(); r++) {
  66. for (size_t c = 0; c < (*this)[r].size(); c++) {
  67. output << (*this)[r][c] << " ";
  68. }
  69. output << std::endl;
  70. }
  71. }
  72. else
  73. {
  74. output << "VVector is empty" << std::endl;
  75. }
  76. }
  77. inline void setIoUntilEndOfFile(const bool & _ioUntilEndOfFile){ ioUntilEndOfFile = _ioUntilEndOfFile;};
  78. inline bool getIoUntilEndOfFile(){return ioUntilEndOfFile;};
  79. };
  80. } // namespace
  81. #endif