VVector.h 2.5 KB

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